Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 834abeb4

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

ZUGFeRD: speicher ZUGFeRD-Datei zur erstellten Kreditorenbuchung

Unterschiede anzeigen:

SL/Controller/ZUGFeRD.pm
7 7
use SL::Helper::DateTime;
8 8
use SL::VATIDNr;
9 9
use SL::ZUGFeRD;
10
use SL::SessionFile;
10 11

  
11 12
use XML::LibXML;
12 13

  
......
16 17
sub action_upload_zugferd {
17 18
  my ($self, %params) = @_;
18 19

  
19
  $self->setup_zugferd_action_bar;
20
  $self->pre_render();
20 21
  $self->render('zugferd/form', title => $::locale->text('Factur-X/ZUGFeRD import'));
21 22
}
22 23

  
23 24
sub action_import_zugferd {
24 25
  my ($self, %params) = @_;
26
  my $file = $::form->{file};
27
  my $file_name = $::form->{file_name};
25 28

  
26
  die t8("missing file for action import") unless $::form->{file};
27
  die t8("can only parse a pdf file")      unless $::form->{file} =~ m/^%PDF/;
29
  die t8("missing file for action import") unless $file;
30
  die t8("can only parse a pdf file")      unless $file =~ m/^%PDF/;
28 31

  
29
  my $info = SL::ZUGFeRD->extract_from_pdf($::form->{file});
32
  my $info = SL::ZUGFeRD->extract_from_pdf($file);
30 33

  
31 34
  if ($info->{result} != SL::ZUGFeRD::RES_OK()) {
32 35
    # An error occurred; log message from parser:
......
126 129
  my $ibanmessage;
127 130
  $ibanmessage = $iban ne $vendor->iban ? "Record IBAN $iban doesn't match vendor IBAN " . $vendor->iban : $iban if $iban;
128 131

  
129
  my $url = $self->url_for(
132
  # save the zugferd file to session file for reuse in ap.pl
133
  my $session_file = SL::SessionFile->new($file_name, mode => 'w');
134
  $session_file->fh->print($file);
135
  $session_file->fh->close;
136

  
137
  $self->redirect_to(
130 138
    controller                           => 'ap.pl',
131 139
    action                               => 'load_record_template',
132 140
    id                                   => $template_ap->id,
......
138 146
    'form_defaults.paid_1_suggestion'    => $::form->format_amount(\%::myconfig, $total, 2),
139 147
    'form_defaults.notes'                => "ZUGFeRD Import. Type: $type\nIBAN: " . $ibanmessage,
140 148
    'form_defaults.taxincluded'          => 0,
141
    'form_defaults.direct_debit'          => $direct_debit,
149
    'form_defaults.direct_debit'         => $direct_debit,
150
    'form_defaults.zugferd_session_file' => $file_name,
142 151
  );
143 152

  
144
  $self->redirect_to($url);
145

  
146 153
}
147 154

  
148 155
sub check_auth {
......
162 169
  }
163 170
}
164 171

  
172
sub pre_render {
173
  my ($self) = @_;
174

  
175
  $::request->{layout}->use_javascript("${_}.js") for qw(
176
    kivi.ZUGFeRD
177
  );
178

  
179
  $self->setup_zugferd_action_bar;
180
}
181

  
165 182

  
166 183
1;
167 184
__END__
bin/mozilla/ap.pl
910 910
      $form->{what_done} = "invoice";
911 911
      $form->save_history;
912 912
    }
913
    # save zugferd file
914
    my $file_name = delete $form->{zugferd_session_file};
915
    if ($file_name) {
916
      my $file = SL::SessionFile->new($file_name, mode => '<');
917
      if (!$file->fh) {
918
        SL::Helper::Flash::flash_later('error',
919
          t8('Could not open ZUGFeRD file for reading: #1', $@));
920
      } else {
921

  
922
        # copy file to webdav folder
923
        if ($form->{invnumber} && $::instance_conf->get_webdav_documents) {
924
          my $webdav = SL::Webdav->new(
925
            type     => 'accounts_payable',
926
            number   => $form->{invnumber},
927
          );
928
          my $webdav_file = SL::Webdav::File->new(
929
            webdav => $webdav,
930
            filename => $file_name,
931
          );
932
          eval {
933
            $webdav_file->store(file => $file->file_name());
934
            1;
935
          } or do {
936
            $form->{zugferd_session_file} = $file_name;
937
            SL::Helper::Flash::flash_later('error',
938
              t8('Storing the ZUGFeRD file to the WebDAV folder failed: #1', $@));
939
          };
940
        }
941
        if ($form->{id} && $::instance_conf->get_doc_storage) {
942
          eval {
943
            SL::File->save(
944
              object_id     => $form->{id},
945
              object_type   => 'purchase_invoice',
946
              mime_type     => 'application/pdf',
947
              source        => 'uploaded',
948
              file_type     => 'document',
949
              file_name     => $file_name,
950
              file_path     => $file->file_name(),
951
            );
952
            1;
953
          } or do {
954
            $form->{zugferd_session_file} = $file_name;
955
            SL::Helper::Flash::flash_later('error',
956
              t8('Storing the ZUGFeRD file in the storage backend failed: #1', $@));
957
          };
958
        }
959
      }
960
    }
913 961

  
914 962
    if (!$inline) {
915 963
      my $msg = $locale->text("AP transaction '#1' posted (ID: #2)", $form->{invnumber}, $form->{id});
js/kivi.ZUGFeRD.js
1
namespace('kivi.ZUGFeRD', function(ns) {
2
  ns.update_file_name = function() {
3
    let file = document.getElementById("file").files[0];
4
    if (file) {
5
      document.getElementById("file_name").value = file.name;
6
    }
7
  };
8
});
templates/design40_webpages/ap/form_header.html
32 32
<input type="hidden" name="taxaccounts" value="[% taxaccounts | html %]">
33 33
<input type="hidden" name="rowcount" value="[% rowcount | html %]">
34 34
<input type="hidden" name="paidaccounts" value="[% paidaccounts | html %]">
35
[% L.hidden_tag('zugferd_session_file', zugferd_session_file) %]
35 36

  
36 37
[% P.hidden_tag('convert_from_oe_id', convert_from_oe_id) %]
37 38

  
templates/design40_webpages/zugferd/form.html
12 12
  <p>[% "Import a Factur-X/ZUGFeRD file:" | $T8 %]</p>
13 13

  
14 14
  <form method="post" action="controller.pl" enctype="multipart/form-data" id="form">
15
    [% L.input_tag('file', '', type => 'file', accept => '.pdf') %]
15
    [% L.input_tag('file', '', type => 'file', accept => '.pdf', onchange='kivi.ZUGFeRD.update_file_name();') %]
16
    [% L.hidden_tag('file_name', '') %]
16 17
  </form>
17 18

  
18 19
</div>
templates/webpages/ap/form_header.html
41 41
<input type="hidden" name="rowcount" value="[% rowcount | html %]">
42 42

  
43 43
<input type="hidden" name="paidaccounts" value="[% paidaccounts | html %]">
44
[% L.hidden_tag('zugferd_session_file', zugferd_session_file) %]
44 45

  
45 46
[%- P.hidden_tag('convert_from_oe_id', convert_from_oe_id) -%]
46 47

  
templates/webpages/zugferd/form.html
10 10
 </p>
11 11

  
12 12
 <form method="post" action="controller.pl" enctype="multipart/form-data" id="form">
13
    [% L.input_tag('file', '', type => 'file', accept => '.pdf') %]
13
    [% L.input_tag('file', '', type => 'file', accept => '.pdf', onchange='kivi.ZUGFeRD.update_file_name();') %]
14
    [% L.hidden_tag('file_name', '') %]
14 15
 </form>

Auch abrufbar als: Unified diff