]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/PayPostingImport.pm
restart apache2 in postinst
[mfinanz.git] / SL / Controller / PayPostingImport.pm
index 5b49a6cb7ee55567eb60848fdf253548696a6875..733dc5d28adad8b03ef98e13728f5c9739559bed 100644 (file)
@@ -17,7 +17,15 @@ sub action_upload_pay_postings {
   my ($self, %params) = @_;
 
   $self->setup_pay_posting_action_bar;
-  $self->render('pay_posting_import/form', title => $::locale->text('Import Pay Postings'));
+
+  # new closedto
+  my $today = DateTime->now();
+  $today->subtract(months => 1);
+
+  my $dt = DateTime->last_day_of_month(year  => $today->year, month => $today->month);
+
+  my $new_closedto = $dt->to_kivitendo();
+  $self->render('pay_posting_import/form', title => $::locale->text('Import Pay Postings'), closedto => $new_closedto);
 }
 
 sub action_import_datev_pay_postings {
@@ -28,7 +36,7 @@ sub action_import_datev_pay_postings {
   my $filename= $::form->{ATTACHMENTS}{file}{filename};
   # check name and first fields of CSV data
   die t8("Wrong file name, expects name like: DTVF_*_LOHNBUCHUNG*.csv") unless $filename =~ /^DTVF_.*_LOHNBUCHUNGEN_LUG.*\.csv$/;
-  die t8("not a valid DTVF file, expected first field in A1 'DTVF': ")  unless ($::form->{file} =~ m/^('|")?DTVF/);
+  die t8("not a valid DTVF file, expected first field in A1 'DTVF'")    unless ($::form->{file} =~ m/^('|")?DTVF/);
   die t8("not a valid DTVF file, expected field header start with 'Umsatz; (..) ;Konto;Gegenkonto'")
     unless ($::form->{file} =~ m/Umsatz;S\/H;;;;;Konto;Gegenkonto.*;;Belegdatum;Belegfeld 1;Belegfeld 2;;Buchungstext/);
 
@@ -39,6 +47,9 @@ sub action_import_datev_pay_postings {
   if (parse_and_import($self)) {
     flash_later('info', t8("All pay postings successfully imported."));
   }
+  if ($::form->{set_closedto} && _set_closedto($self)) {
+    flash_later('info', t8("Books closed until:") . ' ' . $::form->{closedto});
+  }
   $self->setup_pay_posting_action_bar;
   $self->render('pay_posting_import/form', title => $::locale->text('Imported Pay Postings'));
 }
@@ -81,7 +92,9 @@ sub parse_and_import {
 
       # optional KOST1 - KOST2 ?
       $department_name = $row->[36];
-      $department    = SL::DB::Manager::Department->get_first(description => { like =>  $department_name . '%' });
+      if ($department_name) {
+        $department    = SL::DB::Manager::Department->get_first(where => [ description => { ilike =>  $department_name . '%' } ]);
+      }
 
       my $amount = $::form->parse_amount({ numberformat => '1000,00' }, $row->[0]);
 
@@ -122,6 +135,19 @@ sub parse_and_import {
   }) or do { die t8("Cannot add Booking, reason: #1 DB: #2 ", $@, SL::DB->client->error) };
 }
 
+
+sub _set_closedto {
+  my $self     = shift;
+  die "no date:" . $::form->{closedto} unless $::form->{closedto};
+
+  my $defaults   = SL::DB::Default->get;
+
+  $defaults->closedto(DateTime->from_kivitendo($::form->{closedto}));
+  $defaults->save || die "Cannot save closedto!";
+
+  return 1;
+}
+
 sub check_auth {
   $::auth->assert('general_ledger');
 }