Revision d3875936
Von Tamino Steinert vor 11 Monaten hinzugefügt
SL/DB/EmailJournal.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
5 |
use SL::Webdav; |
|
6 |
use SL::File; |
|
7 |
|
|
5 | 8 |
use SL::DB::MetaSetup::EmailJournal; |
6 | 9 |
use SL::DB::Manager::EmailJournal; |
7 | 10 |
use SL::DB::Helper::AttrSorted; |
11 |
use SL::DB::Helper::LinkedRecords; |
|
8 | 12 |
|
9 | 13 |
__PACKAGE__->meta->add_relationship( |
10 | 14 |
attachments => { |
... | ... | |
29 | 33 |
return $result || ($self->id <=> $other->id); |
30 | 34 |
} |
31 | 35 |
|
36 |
sub process_attachments_as_purchase_invoices { |
|
37 |
my ($self) = @_; |
|
38 |
|
|
39 |
my $attachments = $self->attachments_sorted; |
|
40 |
foreach my $attachment (@$attachments) { |
|
41 |
my $ap_invoice = $attachment->create_ap_invoice(); |
|
42 |
next unless $ap_invoice; |
|
43 |
|
|
44 |
# link to email journal |
|
45 |
$self->link_to_record($ap_invoice); |
|
46 |
|
|
47 |
# copy file to webdav folder |
|
48 |
if ($::instance_conf->get_webdav_documents) { |
|
49 |
my $webdav = SL::Webdav->new( |
|
50 |
type => 'accounts_payable', |
|
51 |
number => $ap_invoice->invnumber, |
|
52 |
); |
|
53 |
my $webdav_file = SL::Webdav::File->new( |
|
54 |
webdav => $webdav, |
|
55 |
filename => $attachment->name, |
|
56 |
); |
|
57 |
eval { |
|
58 |
$webdav_file->store(data => \$attachment->content); |
|
59 |
1; |
|
60 |
} or do { |
|
61 |
die 'Storing the ZUGFeRD file to the WebDAV folder failed: ' . $@; |
|
62 |
}; |
|
63 |
} |
|
64 |
# copy file to doc storage |
|
65 |
if ($::instance_conf->get_doc_storage) { |
|
66 |
eval { |
|
67 |
SL::File->save( |
|
68 |
object_id => $ap_invoice->id, |
|
69 |
object_type => 'purchase_invoice', |
|
70 |
mime_type => 'application/pdf', |
|
71 |
source => 'uploaded', |
|
72 |
file_type => 'document', |
|
73 |
file_name => $attachment->name, |
|
74 |
file_contents => $attachment->content, |
|
75 |
); |
|
76 |
1; |
|
77 |
} or do { |
|
78 |
die 'Storing the ZUGFeRD file in the storage backend failed: ' . $@; |
|
79 |
}; |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
my $new_ext_status = join('_', $self->extended_status, 'processed'); |
|
84 |
$self->update({ extended_status => $new_ext_status}); |
|
85 |
} |
|
86 |
|
|
32 | 87 |
1; |
33 | 88 |
|
34 | 89 |
__END__ |
Auch abrufbar als: Unified diff
EmailJournal: ZUGFeRD-Emailanhänge in Kreditorenbuchen konvertieren