Revision 77a5beb7
Von Tamino Steinert vor 11 Monaten hinzugefügt
SL/Controller/EmailJournal.pm | ||
---|---|---|
265 | 265 |
$cv_type_found = 'vendor' if $self->entry->record_type eq 'ap_transaction'; |
266 | 266 |
$self->render( |
267 | 267 |
'email_journal/show', |
268 |
title => $::locale->text('View email'), |
|
269 |
CUSTOMER_VENDOR => , $customer_vendor,
|
|
270 |
CV_TYPE_FOUND => $cv_type_found, |
|
268 |
title => $::locale->text('View email'),
|
|
269 |
CUSTOMER_VENDOR => $customer_vendor,
|
|
270 |
CV_TYPE_FOUND => $cv_type_found,
|
|
271 | 271 |
RECORD_TYPES_WITH_INFO => \@record_types_with_info, |
272 | 272 |
RECORD_TYPES_TO_TEXT => \%record_types_to_text, |
273 | 273 |
back_to => $back_to, |
... | ... | |
399 | 399 |
|
400 | 400 |
sub action_zugferd_import_with_attachment { |
401 | 401 |
my ($self) = @_; |
402 |
|
|
403 |
my $email_journal_id = $::form->{email_journal_id}; |
|
404 |
my $attachment_id = $::form->{attachment_id}; |
|
405 |
|
|
402 |
my $email_journal_id = $::form->{email_journal_id}; |
|
403 |
my $attachment_id = $::form->{attachment_id}; |
|
406 | 404 |
die "no 'email_journal_id' was given" unless $email_journal_id; |
407 |
die "no 'attachment_id' was given" unless $attachment_id;
|
|
405 |
die t8("No attachment is selected") unless $attachment_id;
|
|
408 | 406 |
|
407 |
my $record_id = $::form->{"record_id"}; |
|
408 |
my $record_type = $::form->{"record_type"}; |
|
409 |
die "ZUGFeRD-Import only implemented for ap transaction templates" unless $record_type == 'ap_transaction'; |
|
409 | 410 |
my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load(); |
410 | 411 |
|
411 | 412 |
my $content = $attachment->content; # scalar ref |
... | ... | |
423 | 424 |
die(t8("Could not extract Factur-X/ZUGFeRD data, data and error message:") . " $res{'message'}"); |
424 | 425 |
} |
425 | 426 |
|
426 |
my $form_defaults = SL::Controller::ZUGFeRD->build_ap_transaction_form_defaults(\%res); |
|
427 |
my $vendor; |
|
428 |
if ($record_id) { |
|
429 |
my $ap_template = SL::DB::RecordTemplate->new(id => $record_id)->load(); |
|
430 |
$vendor = $ap_template->vendor; |
|
431 |
} |
|
432 |
|
|
433 |
my $form_defaults = SL::Controller::ZUGFeRD->build_ap_transaction_form_defaults(\%res, vendor => $vendor); |
|
427 | 434 |
$form_defaults->{email_journal_id} = $email_journal_id; |
428 | 435 |
$form_defaults->{email_attachment_id} = $attachment_id; |
429 | 436 |
$form_defaults->{callback} = $::form->{back_to}; |
... | ... | |
431 | 438 |
flash_later('info', |
432 | 439 |
t8("The ZUGFeRD/Factur-X invoice '#1' has been loaded.", $attachment->name)); |
433 | 440 |
$self->redirect_to( |
434 |
controller => 'ap.pl', |
|
435 |
action => 'load_zugferd', |
|
436 |
form_defaults => $form_defaults, |
|
441 |
controller => 'ap.pl', |
|
442 |
action => 'load_zugferd', |
|
443 |
record_template_id => $record_id, |
|
444 |
form_defaults => $form_defaults, |
|
437 | 445 |
); |
438 | 446 |
} |
439 | 447 |
|
... | ... | |
447 | 455 |
id => $attachment_id, |
448 | 456 |
)->load if $attachment_id; |
449 | 457 |
|
450 |
$self->js->hide('#zugferd_import_div'); |
|
451 |
if ($attachment && $attachment->content =~ m/^%PDF|<\?xml/) { |
|
452 |
my $content = $attachment->content; |
|
453 |
my %res; |
|
454 |
if ( $content =~ m/^%PDF/ ) { |
|
455 |
%res = %{SL::ZUGFeRD->extract_from_pdf($content)}; |
|
456 |
} else { |
|
457 |
%res = %{SL::ZUGFeRD->extract_from_xml($content)}; |
|
458 |
} |
|
459 |
if ($res{'result'} == SL::ZUGFeRD::RES_OK()) { |
|
460 |
$self->js->show('#zugferd_import_div'); |
|
461 |
} |
|
462 |
} |
|
463 |
|
|
464 | 458 |
$self->js |
465 | 459 |
->replaceWith('#attachment_preview', |
466 | 460 |
SL::Presenter::EmailJournal::attachment_preview( |
Auch abrufbar als: Unified diff
EmailJournal: ZUGFeRD-Import mit ausgewähter Buchungsvorlage