Revision cc5071a6
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/Helper/EmailProcessing.pm | ||
---|---|---|
8 | 8 |
use XML::LibXML; |
9 | 9 |
|
10 | 10 |
use SL::ZUGFeRD; |
11 |
use SL::Webdav; |
|
12 |
use SL::File; |
|
13 | 11 |
|
14 | 12 |
use SL::DB::PurchaseInvoice; |
13 |
use SL::DB::Helper::HardRecordLinks; |
|
15 | 14 |
|
16 | 15 |
sub process_attachments { |
17 | 16 |
my ($self, $function_name, $email_journal, %params) = @_; |
... | ... | |
51 | 50 |
sub _add_attachment_to_record { |
52 | 51 |
my ($self, $email_journal, $attachment, $record) = @_; |
53 | 52 |
|
54 |
# link to email journal |
|
55 |
$email_journal->link_to_record($record); |
|
53 |
$attachment->add_file_to_record($record); |
|
56 | 54 |
|
57 |
# copy file to webdav folder |
|
58 |
if ($::instance_conf->get_webdav_documents) { |
|
59 |
my $record_type = $record->record_type; |
|
60 |
# TODO: file and webdav use different types for ap_transaction |
|
61 |
$record_type = 'accounts_payable' if $record_type eq 'ap_transaction'; |
|
62 |
my $webdav = SL::Webdav->new( |
|
63 |
type => $record_type, |
|
64 |
number => $record->record_number, |
|
65 |
); |
|
66 |
my $webdav_file = SL::Webdav::File->new( |
|
67 |
webdav => $webdav, |
|
68 |
filename => $attachment->name, |
|
69 |
); |
|
70 |
eval { |
|
71 |
$webdav_file->store(data => \$attachment->content); |
|
72 |
1; |
|
73 |
} or do { |
|
74 |
die 'Storing the attachment file to the WebDAV folder failed: ' . $@; |
|
75 |
}; |
|
76 |
} |
|
77 |
# copy file to doc storage |
|
78 |
if ($::instance_conf->get_doc_storage) { |
|
79 |
my $record_type = $record->record_type; |
|
80 |
# TODO: file and webdav use different types for ap_invoice |
|
81 |
$record_type = 'purchase_invoice' if $record_type eq 'ap_transaction'; |
|
82 |
eval { |
|
83 |
SL::File->save( |
|
84 |
object_id => $record->id, |
|
85 |
object_type => $record_type, |
|
86 |
source => 'uploaded', |
|
87 |
file_type => 'document', |
|
88 |
file_name => $attachment->name, |
|
89 |
file_contents => $attachment->content, |
|
90 |
mime_type => $attachment->mime_type, |
|
91 |
); |
|
92 |
1; |
|
93 |
} or do { |
|
94 |
die 'Storing the ZUGFeRD file in the storage backend failed: ' . $@; |
|
95 |
}; |
|
96 |
} |
|
97 |
|
|
98 |
my $new_ext_status = join(' ', $email_journal->extended_status, |
|
99 |
'created_record_' . $record->record_type); |
|
100 |
$email_journal->update_attributes(extended_status => $new_ext_status); |
|
55 |
# soft link |
|
56 |
$email_journal->link_to_record($record); |
|
101 | 57 |
|
102 |
# TODO: hardlink in db to email_journal |
|
58 |
# hard link |
|
59 |
SL::DB::Helper::HardRecordLinks->create_link($record, $email_journal); |
|
103 | 60 |
} |
104 | 61 |
|
105 | 62 |
1; |
Auch abrufbar als: Unified diff
Helper::EmailProcessing: Nutze neue Funktionen