DATEV:CSV nicht gesetztes Fälligkeitsdatum für Belegfeld2 akzeptieren
[kivitendo-erp.git] / SL / DATEV / CSV.pm
index b7ce84f..9ac29c0 100644 (file)
@@ -22,7 +22,7 @@ my @kivitendo_to_datev = (
                               max_length      => 13,
                               type            => 'Value',
                               required        => 1,
-                              input_check     => sub { my ($input) = @_; return (looks_like_number($input) && length($input) <= 13) },
+                              input_check     => sub { my ($input) = @_; return (looks_like_number($input) && length($input) <= 13 && $input > 0) },
                               formatter       => \&_format_amount,
                               valid_check     => sub { my ($check) = @_; return ($check =~ m/^\d{1,10}(\,\d{1,2})?$/) },
                             },
@@ -106,12 +106,14 @@ my @kivitendo_to_datev = (
                               formatter       => sub { my ($input) = @_; return substr($input, 0, 12) },
                             },
                             {
-                              kivi_datev_name => 'not yet implemented',
+                              kivi_datev_name => 'belegfeld2',
                               csv_header_name => t8('Invoice Field 2'),
                               max_length      => 12,
                               type            => 'Text',
                               default         => '',
-                              valid_check     => sub { my ($check) = @_; return ($check =~ m/[ -~]{1,12}/) },
+                              input_check     => sub { my ($check) = @_; return 1 unless $check; return (ref (DateTime->from_kivitendo($check)) eq 'DateTime') },
+                              formatter       => sub { my ($input) = @_; return DateTime->from_kivitendo($input)->strftime('%d%m%y') },
+                              valid_check     => sub { my ($check) = @_; return ($check =~ m/^[0-9]{6}$/) },
                             },
                             {
                               kivi_datev_name => 'not yet implemented',
@@ -263,11 +265,7 @@ sub check_encoding {
 }
 
 sub _kivitendo_to_datev {
-  my ($self) = @_;
-
-  my $entries = scalar (@kivitendo_to_datev);
-  push @kivitendo_to_datev, { kivi_datev_name => 'not yet implemented' } for 1 .. (116 - $entries);
-  return @kivitendo_to_datev;
+  @kivitendo_to_datev, ({ kivi_datev_name => 'not yet implemented' }) x (116 - @kivitendo_to_datev);
 }
 
 sub header {
@@ -276,8 +274,8 @@ sub header {
   my @header;
 
   # we can safely set these defaults
-  # TODO use Helper::DateTime and get length_of_accounts from DATEV.pm
-  my $today              = DateTime->now(time_zone => "local");
+  # TODO get length_of_accounts from DATEV.pm
+  my $today              = DateTime->now_local;
   my $created_on         = $today->ymd('') . $today->hms('') . '000';
   my $length_of_accounts = length(SL::DB::Manager::Chart->get_first(where => [charttype => 'A'])->accno) // 4;
   my $default_curr       = SL::DB::Default->get_default_currency;
@@ -534,14 +532,7 @@ To add or alter the structure of the data take a look at the C<@kivitendo_to_dat
 
 =head1 TODO CAVEAT
 
-
-Currently no effort has be done that _kivitenod_to_datev is only intializied once:
-Therefore the second call may generate integrity faults:
-
-  my $datev_csv_1 = SL::DATEV::CSV->new(...)->lines;
-  my $datev_csv_2 = SL::DATEV::CSV->new(...)->lines;
-
-Secondly one can circumevent the check of the warnings.quite easily,
+One can circumevent the check of the warnings.quite easily,
 becaus warnings are generated after the call to lines:
 
   # WRONG usage