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
    }

Auch abrufbar als: Unified diff