X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDATEV%2FCSV.pm;h=e24755b8923ea56a3f9fe1a969a84f5c784694f0;hb=e592e0bc4aaf7ce59e4d5eec9834cb430ab6a33f;hp=69448c49f27519a724149b9d38dd8b7b00ccbb42;hpb=0d082a48b2ee65336d57a99f9f4692bda850b5b3;p=kivitendo-erp.git diff --git a/SL/DATEV/CSV.pm b/SL/DATEV/CSV.pm index 69448c49f..e24755b89 100644 --- a/SL/DATEV/CSV.pm +++ b/SL/DATEV/CSV.pm @@ -3,13 +3,14 @@ package SL::DATEV::CSV; use strict; use Carp; use DateTime; -use Encode qw(decode); +use Encode qw(encode); use Scalar::Util qw(looks_like_number); 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) ], @@ -56,7 +57,7 @@ my @kivitendo_to_datev = ( }, { kivi_datev_name => 'not yet implemented', - sv_header_name => t8('Base Transaction Value'), + csv_header_name => t8('Base Transaction Value'), }, { kivi_datev_name => 'not yet implemented', @@ -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', @@ -260,7 +268,7 @@ sub check_encoding { my ($test) = @_; return undef unless $test; if (eval { - decode('Windows-1252', $test, Encode::FB_CROAK|Encode::LEAVE_SRC); + encode('Windows-1252', $test, Encode::FB_CROAK|Encode::LEAVE_SRC); 1 }) { return 1; @@ -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); -