Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f5e39f21

Von Jan Büren vor fast 3 Jahren hinzugefügt

  • ID f5e39f21bd5f9c5dd9a8bbbdfa34d0c17a2fc44d
  • Vorgänger fb2cef4d
  • Nachfolger 266e8eb9

S:C:PayPostingImport Bei Erfolg, importierte Buchungen anzeigen

Unterschiede anzeigen:

SL/Controller/PayPostingImport.pm
26 26
  die t8("missing file for action import") unless ($::form->{file});
27 27

  
28 28
  my $filename= $::form->{ATTACHMENTS}{file}{filename};
29

  
30 29
  # check name and first fields of CSV data
31 30
  die t8("Wrong file name, expects name like: DTVF_*_LOHNBUCHUNG*.csv") unless $filename =~ /^DTVF_.*_LOHNBUCHUNGEN_LUG.*\.csv$/;
32 31
  die t8("not a valid DTVF file, expected first field in A1 'DTVF'")   unless ($::form->{file} =~ m/^"DTVF";/);
......
34 33
    unless ($::form->{file} =~ m/Umsatz;S\/H;;;;;Konto;Gegenkonto.*;;Belegdatum;Belegfeld 1;Belegfeld 2;;Buchungstext/);
35 34

  
36 35
  # check if file is already imported
37
  my $acc_trans_doc = SL::DB::Manager::AccTransaction->get_first(source => $filename);
38
  die t8("Already imported") if ref $acc_trans_doc eq 'SL::DB::AccTransaction';
36
  my $acc_trans_doc = SL::DB::Manager::AccTransaction->get_first(query => [ source => $filename ]);
37
  die t8("Already imported: ") . $acc_trans_doc->source if ref $acc_trans_doc eq 'SL::DB::AccTransaction';
39 38

  
40
  if (parse_and_import($::form->{file}, $filename)) {
39
  if (parse_and_import($self)) {
41 40
    flash_later('info', t8("All pay postings successfully imported."));
42 41
  }
43
  # $self->redirect_to("gl.pl?action=search", source => $filename);
42
  $self->setup_pay_posting_action_bar;
43
  $self->render('pay_posting_import/form', title => $::locale->text('Imported Pay Postings'));
44 44
}
45 45

  
46 46
sub parse_and_import {
47
  my $doc      = shift;
47
  my $self     = shift;
48 48

  
49 49
  my $csv = Text::CSV_XS->new ({ binary => 0, auto_diag => 1, sep_char => ";" });
50
  open my $fh, "<:encoding(cp1252)", \$doc;
50
  open (my $fh, "<:encoding(cp1252)", \$::form->{file}) or die "cannot open $::form->{file} $!";
51 51
  # Read/parse CSV
52 52
  # Umsatz S/H Konto Gegenkonto (ohne BU-Schlüssel) Belegdatum Belegfeld 1 Belegfeld 2 Buchungstext
53 53
  my $year = substr($csv->getline($fh)->[12], 0, 4);
......
103 103
          source => $::form->{ATTACHMENTS}{file}{filename},
104 104
      )->post;
105 105

  
106
      # push @rows, $current_transaction->id;
106
      push @{ $self->{gl_trans} }, $current_transaction;
107 107

  
108 108
      if ($::instance_conf->get_doc_storage) {
109 109
        my $file = SL::File->save(object_id   => $current_transaction->id,
......
112 112
                       source      => 'uploaded',
113 113
                       file_type   => 'attachment',
114 114
                       file_name   => $::form->{ATTACHMENTS}{file}{filename},
115
                       file_contents   => $doc
115
                       file_contents   => $::form->{file},
116 116
                      );
117 117
      }
118 118
    }
templates/webpages/pay_posting_import/form.html
4 4
[%- USE T8 %]
5 5
[%- INCLUDE 'common/flash.html' %]
6 6
<div class="listtop">[% FORM.title %]</div>
7

  
8
[% IF (SELF.gl_trans.size) %]
9
  <p>[% SELF.gl_trans.size %][% "entries imported" | $T8 %].</p>
10
<div style="padding-bottom: 15px">
11
 <table id="gl_trans">
12
  <thead>
13
   <tr>
14
    <th class="listheading">[%- LxERP.t8("Date") %]</th>
15
    <th class="listheading">[%- LxERP.t8("Description") %]</th>
16
    <th class="listheading">[%- LxERP.t8("Debit") %]</th>
17
    <th class="listheading">[%- LxERP.t8("Credit") %]</th>
18
    <th class="listheading">[%- LxERP.t8("Amount") %]</th>
19
   </tr>
20
  </thead>
21
  <tbody>
22
  [%- FOREACH gl = SELF.gl_trans %]
23
    <tr class="listrow[% loop.count % 2 %]">
24
    <td>[%- gl.transdate.to_kivitendo -%]</td>
25
    <td align="left">[%- gl.description -%]</td>
26
    <td align="left">[%- gl.transactions.1.chart.accno -%]&nbsp;[%- gl.transactions.1.chart.description -%]</td>
27
    <td align="left">[%- gl.transactions.0.chart.accno -%]&nbsp;[%- gl.transactions.0.chart.description -%]</td>
28
    <td align="right"> [%- LxERP.format_amount(gl.transactions.0.amount    , 2) %]</td>
29
   </tr>
30
  [% END %]
31
     </tbody>
32
 </table>
33
 <div>
34
[% END %]
35

  
7 36
<p>
8 37
 [% "Import a File:" | $T8 %]
9 38
</p>

Auch abrufbar als: Unified diff