Revision ffdea081
Von Tamino Steinert vor 11 Monaten hinzugefügt
SL/Helper/EmailProcessing.pm | ||
---|---|---|
31 | 31 |
my ($self, $email_journal, $attachment, %params) = @_; |
32 | 32 |
|
33 | 33 |
my $content = $attachment->content; # scalar ref |
34 |
my $name = $attachment->name; |
|
34 | 35 |
|
35 |
return 0 unless $content =~ m/^%PDF/; |
|
36 |
return 0 unless $content =~ m/^%PDF|<\?xml/;
|
|
36 | 37 |
|
37 |
my $zugferd_info = SL::ZUGFeRD->extract_from_pdf($content); |
|
38 |
return 0 unless $zugferd_info->{result} == SL::ZUGFeRD::RES_OK(); |
|
38 |
my %res; |
|
39 |
if ( $content =~ m/^%PDF/ ) { |
|
40 |
%res = %{SL::ZUGFeRD->extract_from_pdf($content)}; |
|
41 |
} else { |
|
42 |
%res = %{SL::ZUGFeRD->extract_from_xml($content)}; |
|
43 |
} |
|
39 | 44 |
|
40 |
my $zugferd_xml = XML::LibXML->load_xml(string => $zugferd_info->{invoice_xml}); |
|
45 |
unless ($res{'result'} == SL::ZUGFeRD::RES_OK()) { |
|
46 |
my $error = $res{'message'}; |
|
47 |
$email_journal->extended_status( |
|
48 |
join "\n", $email_journal->extended_status, |
|
49 |
"Error processing ZUGFeRD attachment $name: $error" |
|
50 |
)->save; |
|
51 |
return 0; |
|
52 |
} |
|
41 | 53 |
|
42 |
my $purchase_invoice = SL::DB::PurchaseInvoice->create_from_zugferd_xml($zugferd_xml)->save(); |
|
54 |
my $purchase_invoice; |
|
55 |
eval { |
|
56 |
$purchase_invoice = SL::DB::PurchaseInvoice->create_from_zugferd_xml(\%res)->save(); |
|
57 |
1; |
|
58 |
} or do { |
|
59 |
my $error = $@; |
|
60 |
$email_journal->extended_status( |
|
61 |
join "\n", $email_journal->extended_status, |
|
62 |
"Error processing ZUGFeRD attachment $name: $error" |
|
63 |
)->save; |
|
64 |
return 0; |
|
65 |
}; |
|
43 | 66 |
|
44 | 67 |
$self->_add_attachment_to_record($email_journal, $attachment, $purchase_invoice); |
45 | 68 |
|
Auch abrufbar als: Unified diff
ImportRecordEmails: Anpassung nach Rebase: BJ zum importieren von Emails