Fixt #348 DatevExport kommt mit bestimmten Zeichen im Buchungstext nicht klar
[kivitendo-erp.git] / SL / DATEV / CSV.pm
index c93241b..e24755b 100644 (file)
@@ -10,6 +10,7 @@ use SL::DB::Datev;
 use SL::DB::Chart;
 use SL::Helper::DateTime;
 use SL::Locale::String qw(t8);
+use SL::Util qw(trim);
 
 use Rose::Object::MakeMethods::Generic (
   scalar => [ qw(datev_lines from to locked warnings) ],
@@ -102,16 +103,21 @@ my @kivitendo_to_datev = (
                               max_length      => 12,
                               type            => 'Text',
                               default         => '',
-                              input_check     => sub { my ($text) = @_; check_encoding($text); },
+                              input_check     => sub { return 1 unless $::instance_conf->get_datev_export_format eq 'cp1252';
+                                                       my ($text) = @_; check_encoding($text); },
+                              valid_check     => sub { return 1 if     $::instance_conf->get_datev_export_format eq 'cp1252';
+                                                       my ($text) = @_; check_encoding($text); },
                               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 '' unless $input; return trim(DateTime->from_kivitendo($input)->strftime('%e%m%y')) },
+                              valid_check     => sub { my ($check) = @_; return 1 unless $check; return ($check =~ m/^[0-9]{5,6}$/) },
                             },
                             {
                               kivi_datev_name => 'not yet implemented',
@@ -124,8 +130,10 @@ my @kivitendo_to_datev = (
                               max_length      => 60,
                               type            => 'Text',
                               default         => '',
-                              input_check     => sub { my ($text) = @_; return 1 unless $text; check_encoding($text);  },
-                              formatter       => sub { my ($input) = @_; return substr($input, 0, 60) },
+                              input_check     => sub { return 1 unless $::instance_conf->get_datev_export_format eq 'cp1252';
+                                                       my ($text) = @_; check_encoding($text); },
+                              valid_check     => sub { return 1 if     $::instance_conf->get_datev_export_format eq 'cp1252';
+                                                       my ($text) = @_; check_encoding($text); },
                             },  # pos 14
                             {
                               kivi_datev_name => 'not yet implemented',
@@ -546,4 +554,3 @@ becaus warnings are generated after the call to lines:
   my $lines = $datev_csv->lines;
   die if @{ $datev_csv->warnings };
   somethin_with($lines);
-