SL::DB::Invoice->new_from: auch Leistungsdatum (tax_point) übernehmen
[kivitendo-erp.git] / bin / mozilla / datev.pl
index 9b9ac50..cca078b 100644 (file)
@@ -31,6 +31,8 @@ use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
 
 use SL::Common;
 use SL::DATEV qw(:CONSTANTS);
+use SL::Locale::String qw(t8);
+use SL::DB::Department;
 
 use strict;
 
@@ -48,6 +50,8 @@ sub export {
 
   my $stamm = SL::DATEV->new->get_datev_stamm;
 
+  setup_datev_export_action_bar();
+
   $::form->header;
   print $::form->parse_html_template('datev/export', $stamm);
 
@@ -70,7 +74,15 @@ sub export_bewegungsdaten {
   $::lxdebug->enter_sub;
   $::auth->assert('datev_export');
 
+  setup_datev_export2_action_bar();
+
   $::form->header;
+  $::form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
+  $::form->{show_pk_option}  = SL::DATEV->new->check_vcnumbers_are_valid_pk_numbers;
+
+  # check if we have mismatching number length domains
+  SL::DATEV->new->check_valid_length_of_accounts;
+
   print $::form->parse_html_template('datev/export_bewegungsdaten');
 
   $::lxdebug->leave_sub;
@@ -80,6 +92,8 @@ sub export_stammdaten {
   $::lxdebug->enter_sub;
   $::auth->assert('datev_export');
 
+  setup_datev_export2_action_bar();
+
   $::form->header;
   print $::form->parse_html_template('datev/export_stammdaten');
 
@@ -92,7 +106,7 @@ sub export3 {
 
   my %data = (
     exporttype => $::form->{exporttype} ? DATEV_ET_STAMM : DATEV_ET_BUCHUNGEN,
-    format     => $::form->{kne}        ? DATEV_FORMAT_KNE : DATEV_FORMAT_OBE,
+    format     => $::form->{exportformat} eq 'kne' ? DATEV_FORMAT_KNE :  DATEV_FORMAT_CSV,
   );
 
   if ($::form->{exporttype} == DATEV_ET_STAMM) {
@@ -103,6 +117,8 @@ sub export3 {
       $::form->{zeitraum}, $::form->{monat}, $::form->{quartal},
       $::form->{transdatefrom}, $::form->{transdateto},
     );
+    $data{use_pk} = $::form->{use_pk};
+    $data{locked} = $::form->{locked};
   } else {
     die 'invalid exporttype';
   }
@@ -115,8 +131,10 @@ sub export3 {
   $datev->export;
 
   if (!$datev->errors) {
+    setup_datev_export3_action_bar(download_token => $datev->download_token);
+
     $::form->header;
-    print $::form->parse_html_template('datev/export3', { datev => $datev });
+    print $::form->parse_html_template('datev/export3', { WARNINGS => $datev->warnings });
   } else {
     $::form->error("Export schlug fehl.\n" . join "\n", $datev->errors);
   }
@@ -182,6 +200,9 @@ sub _get_dates {
 
   if ($mode eq "monat") {
     $fromdate = DateTime->new(day => 1, month => $month, year => DateTime->today->year);
+    # december export is usually in january/february
+    $fromdate = $fromdate->subtract(years => 1) if ($month == 12);
+
     $todate   = $fromdate->clone->add(months => 1)->add(days => -1);
   } elsif ($mode eq "quartal") {
     die 'quarter out of of bounds' if $quarter < 1 || $quarter > 4;
@@ -199,3 +220,52 @@ sub _get_dates {
 
   return ($fromdate, $todate);
 }
+
+sub setup_datev_export_action_bar {
+  my %params = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        t8('Continue'),
+        submit    => [ '#form', { action => 'export2' } ],
+        accesskey => 'enter',
+      ],
+    );
+  }
+}
+
+sub setup_datev_export2_action_bar {
+  my %params = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        t8('Export'),
+        submit    => [ '#form', { action => 'export3' } ],
+        accesskey => 'enter',
+      ],
+      action => [
+        t8('Back'),
+        call => [ 'kivi.history_back' ],
+      ],
+    );
+  }
+}
+
+sub setup_datev_export3_action_bar {
+  my %params = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      link => [
+        t8('Download'),
+        link => [ 'datev.pl?action=download&download_token=' . $::form->escape($params{download_token}) ],
+      ],
+      action => [
+        t8('Back'),
+        call => [ 'kivi.history_back' ],
+      ],
+    );
+  }
+}