Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e3338e4a

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID e3338e4ac8e8ad5342aad71ef8e3e31c3cffbb1a
  • Vorgänger ef2af60b
  • Nachfolger 9cf32c2d

EmailJournal: Anhang als ZUGFeRD importieren

Unterschiede anzeigen:

SL/Controller/EmailJournal.pm
4 4

  
5 5
use parent qw(SL::Controller::Base);
6 6

  
7
use SL::ZUGFeRD;
8
use SL::Controller::ZUGFeRD;
7 9
use SL::Controller::Helper::GetModels;
8 10
use SL::DB::Employee;
9 11
use SL::DB::EmailJournal;
......
380 382
  );
381 383
}
382 384

  
385
sub action_zugferd_import_with_attachment {
386
  my ($self) = @_;
387

  
388
  my $email_journal_id   = $::form->{email_journal_id};
389
  my $attachment_id      = $::form->{attachment_id};
390

  
391
  die "no 'email_journal_id' was given" unless $email_journal_id;
392
  die "no 'attachment_id' was given"    unless $attachment_id;
393

  
394
  my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load();
395

  
396
  my $content = $attachment->content; # scalar ref
397

  
398
  die t8("can only parse a pdf or xml file") unless $content =~ m/^%PDF|<\?xml/;
399

  
400
  my %res;
401
  if ( $content =~ m/^%PDF/ ) {
402
    %res = %{SL::ZUGFeRD->extract_from_pdf($content)};
403
  } else {
404
    %res = %{SL::ZUGFeRD->extract_from_xml($content)};
405
  }
406

  
407
  unless ($res{'result'} == SL::ZUGFeRD::RES_OK()) {
408
    die(t8("Could not extract Factur-X/ZUGFeRD data, data and error message:") . " $res{'message'}");
409
  }
410

  
411
  my $form_defaults = SL::Controller::ZUGFeRD->build_ap_transaction_form_defaults(\%res);
412
  $form_defaults->{email_journal_id}    = $email_journal_id;
413
  $form_defaults->{email_attachment_id} = $attachment_id;
414
  $form_defaults->{callback}            = $::form->{back_to};
415

  
416
  flash_later('info',
417
    t8("The ZUGFeRD/Factur-X invoice '#1' has been loaded.", $attachment->name));
418
  $self->redirect_to(
419
    controller    => 'ap.pl',
420
    action        => 'load_zugferd',
421
    form_defaults => $form_defaults,
422
  );
423
}
424

  
383 425
sub action_update_attachment_preview {
384 426
  my ($self) = @_;
385 427
  $::auth->assert('email_journal');
......
390 432
    id => $attachment_id,
391 433
  )->load if $attachment_id;
392 434

  
435
  $self->js->hide('#zugferd_import_div');
436
  if ($attachment && $attachment->content =~ m/^%PDF|<\?xml/) {
437
    my $content = $attachment->content;
438
    my %res;
439
    if ( $content =~ m/^%PDF/ ) {
440
      %res = %{SL::ZUGFeRD->extract_from_pdf($content)};
441
    } else {
442
      %res = %{SL::ZUGFeRD->extract_from_xml($content)};
443
    }
444
    if ($res{'result'} == SL::ZUGFeRD::RES_OK()) {
445
      $self->js->show('#zugferd_import_div');
446
    }
447
  }
448

  
393 449
  $self->js
394 450
    ->replaceWith('#attachment_preview',
395 451
      SL::Presenter::EmailJournal::attachment_preview(

Auch abrufbar als: Unified diff