Revision aa38f2e3
Von Tamino Steinert vor 11 Monaten hinzugefügt
SL/Controller/EmailJournal.pm | ||
---|---|---|
397 | 397 |
); |
398 | 398 |
} |
399 | 399 |
|
400 |
sub action_zugferd_import_with_attachment {
|
|
400 |
sub action_ap_transaction_template_with_zugferd_import {
|
|
401 | 401 |
my ($self) = @_; |
402 | 402 |
my $email_journal_id = $::form->{email_journal_id}; |
403 |
my $attachment_id = $::form->{attachment_id}; |
|
404 | 403 |
die "no 'email_journal_id' was given" unless $email_journal_id; |
405 |
die t8("No attachment is selected") unless $attachment_id; |
|
406 | 404 |
|
407 | 405 |
my $record_id = $::form->{"record_id"}; |
408 | 406 |
my $record_type = $::form->{"record_type"}; |
409 | 407 |
die "ZUGFeRD-Import only implemented for ap transaction templates" unless $record_type == 'ap_transaction'; |
410 |
my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load(); |
|
411 | 408 |
|
412 |
my $content = $attachment->content; # scalar ref
|
|
409 |
my $attachment_id = $::form->{attachment_id};
|
|
413 | 410 |
|
414 |
die t8("can only parse a pdf or xml file") unless $content =~ m/^%PDF|<\?xml/; |
|
411 |
my $form_defaults; |
|
412 |
if ($attachment_id) { |
|
413 |
my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load(); |
|
414 |
my $content = $attachment->content; # scalar ref |
|
415 | 415 |
|
416 |
my %res; |
|
417 |
if ( $content =~ m/^%PDF/ ) { |
|
418 |
%res = %{SL::ZUGFeRD->extract_from_pdf($content)}; |
|
419 |
} else { |
|
420 |
%res = %{SL::ZUGFeRD->extract_from_xml($content)}; |
|
421 |
} |
|
416 |
if ($content =~ m/^%PDF|<\?xml/) { |
|
422 | 417 |
|
423 |
unless ($res{'result'} == SL::ZUGFeRD::RES_OK()) { |
|
424 |
die(t8("Could not extract Factur-X/ZUGFeRD data, data and error message:") . " $res{'message'}"); |
|
425 |
} |
|
418 |
my %res; |
|
419 |
if ( $content =~ m/^%PDF/ ) { |
|
420 |
%res = %{SL::ZUGFeRD->extract_from_pdf($content)}; |
|
421 |
} else { |
|
422 |
%res = %{SL::ZUGFeRD->extract_from_xml($content)}; |
|
423 |
} |
|
424 |
|
|
425 |
if ($res{'result'} == SL::ZUGFeRD::RES_OK()) { |
|
426 |
my $ap_template = SL::DB::RecordTemplate->new(id => $record_id)->load(); |
|
427 |
my $vendor = $ap_template->vendor; |
|
426 | 428 |
|
427 |
my $vendor; |
|
428 |
if ($record_id) { |
|
429 |
my $ap_template = SL::DB::RecordTemplate->new(id => $record_id)->load(); |
|
430 |
$vendor = $ap_template->vendor; |
|
429 |
$form_defaults = SL::Controller::ZUGFeRD->build_ap_transaction_form_defaults(\%res, vendor => $vendor); |
|
430 |
flash_later('info', |
|
431 |
t8("The ZUGFeRD/Factur-X invoice '#1' has been loaded.", $attachment->name)); |
|
432 |
} |
|
433 |
} |
|
431 | 434 |
} |
432 | 435 |
|
433 |
my $form_defaults = SL::Controller::ZUGFeRD->build_ap_transaction_form_defaults(\%res, vendor => $vendor); |
|
434 | 436 |
$form_defaults->{email_journal_id} = $email_journal_id; |
435 | 437 |
$form_defaults->{email_attachment_id} = $attachment_id; |
436 | 438 |
$form_defaults->{callback} = $::form->{back_to}; |
437 | 439 |
|
438 |
flash_later('info', |
|
439 |
t8("The ZUGFeRD/Factur-X invoice '#1' has been loaded.", $attachment->name)); |
|
440 | 440 |
$self->redirect_to( |
441 | 441 |
controller => 'ap.pl', |
442 | 442 |
action => 'load_zugferd', |
Auch abrufbar als: Unified diff
EmailJournal: Workflow Kreditoren-BV: immer versuchen ZUGFeRD-Daten zuladen