From 6309c61710215e3755cc8e096ae1f2801e2f6962 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Mon, 9 Aug 2021 11:54:15 +0200 Subject: [PATCH] PayPostingImport: Testfall gegen DATEV-CSV Struktur --- t/pay_posting_import/datev.csv | 14 ++++ t/pay_posting_import/datev_import.t | 103 ++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 t/pay_posting_import/datev.csv create mode 100644 t/pay_posting_import/datev_import.t diff --git a/t/pay_posting_import/datev.csv b/t/pay_posting_import/datev.csv new file mode 100644 index 000000000..7f31ef556 --- /dev/null +++ b/t/pay_posting_import/datev.csv @@ -0,0 +1,14 @@ +"DTVF";700;21;"Buchungsstapel";9;20210705140408955;20210705140408939;"LO";"";"kivitendo";49999;40392;20210101;6;20210601;20210630;"Lohn-Buchungen 06/2021";"LG";1;0;0;"EUR";;"";;55464;"";;;"";"004999940392F08" +Umsatz;S/H;;;;;Konto;Gegenkonto (ohne BU-Schlüssel);;Belegdatum;Belegfeld 1;Belegfeld 2;;Buchungstext;;;;;;;;;;;;;;;;;;;;;;;KOST1;KOST2;KOST Menge;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Festschreibung +2455,11;H;;;;;379000;136900;;3006;202106;;;AAG 06/2021 AOK Baden-Württemberg;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +230;H;;;;;379000;136900;;3006;202106;;;AAG 06/2021 BKK Debeka;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +142,31;H;;;;;379000;136900;;3006;202106;;;AAG 06/2021 IKK classic;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +43872,97;S;;;;;379000;372000;;3006;202106;;;AUSZAHLUNGSVERBINDL.;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +1787,21;S;;;;;379000;372500;;3006;202106;;;Verbindl. Einbehaltung Arbeitn;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +10808,16;S;;;;;379000;373000;;3006;202106;;;VERBINDL.FINANZAMT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +23109,51;S;;;;;379000;374000;;3006;202106;;;VERBINDL.KRANKENKASSEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +40;S;;;;;379000;377000;;3006;202106;;;Verb. aus Vermögensbildung;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +384;S;;;;;379000;494700;;3006;202106;;;KFZ-NUTZUNG;;;;;;;;;;;;;;;;;;;;;;;wisavis;2016;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +623,57;S;;;;;379000;494700;;3006;202106;;;KFZ-NUTZUNG;;;;;;;;;;;;;;;;;;;;;;;wisavis;2018;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +662,65;S;;;;;379000;494700;;3006;202106;;;KFZ-NUTZUNG;;;;;;;;;;;;;;;;;;;;;;;wisavis;2019;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 +298;S;;;;;379000;494700;;3006;202106;;;Diff. USt-MindestBMG (Firmenwagen);;;;;;;;;;;;;;;;;;;;;;;wisavis;2021;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0 diff --git a/t/pay_posting_import/datev_import.t b/t/pay_posting_import/datev_import.t new file mode 100644 index 000000000..0afff356c --- /dev/null +++ b/t/pay_posting_import/datev_import.t @@ -0,0 +1,103 @@ +use strict; +use Test::More; +use Test::Exception; + +use lib 't'; + +use_ok 'Support::TestSetup'; + +use SL::Controller::PayPostingImport; + +use utf8; +use Data::Dumper; +use File::Slurp; +use Text::CSV_XS qw (csv); + +Support::TestSetup::login(); + +my $dbh = SL::DB->client->dbh; +my @charts = qw(379000 136900 372000 372500 373000 374000 377000 494700); +local $::locale = Locale->new('en'); +diag("init csv"); +clear_up(); + +# datev naming convention and expected filename entry in $::form +$::form->{ATTACHMENTS}{file}{filename} = 'DTVF_44979_43392_LOHNBUCHUNGEN_LUG_202106_20210623_0946'; +$::form->{file} = read_file('t/pay_posting_import/datev.csv'); +my $source = $::form->{ATTACHMENTS}{file}{filename}; + +# get data as aoa datev encodes always CP1252 +my $csv_array = csv (in => "t/pay_posting_import/datev.csv", + binary => 0, + auto_diag => 1, sep_char => ";", encoding=> "cp1252"); + +# probably no correct charts in test db +throws_ok{ + SL::Controller::PayPostingImport::parse_and_import(); + } qr/No such Chart 379000/, "Importing Pay Postings without correct charts"; + +# create charts +foreach my $accno (@charts) { + SL::DB::Chart->new( + accno => $accno, + description => 'Löhne mit Gestöhne', + charttype => 'A', + category => 'Q', + link => '', + taxkey_id => '0', + datevautomatik => 'f', + )->save; +} + +# and add department (KOST1 description) + SL::DB::Department->new( + description => 'Wisavis' + )->save; + +SL::Controller::PayPostingImport::parse_and_import(); + +# get all gl imported bookings +my $gl_bookings = SL::DB::Manager::GLTransaction->get_all(where => [imported => 1] ); + +# $i number of real data entries in the array (first two rows are headers) +my $i = 2; +is(scalar @{ $csv_array } - $i, scalar @{ $gl_bookings }, "Correct number of imported Pay Posting Bookings"); + +# check all imported bookings +foreach my $booking (@{ $gl_bookings }) { + my $current_row = $csv_array->[$i]; + + my $accno_credit = $current_row->[1] eq 'S' ? $current_row->[7] : $current_row->[6]; + my $accno_debit = $current_row->[1] eq 'S' ? $current_row->[6] : $current_row->[7]; + my $amount = $::form->parse_amount({ numberformat => '1000,00' }, $current_row->[0]); + + # gl + is ($current_row->[13], $booking->reference, "Buchungstext correct"); + is ("Wisavis", $booking->department->description, "Department correctly assigned"); + is ($source, $booking->transactions->[0]->source, "Source 0 correctly assigned"); + is ($source, $booking->transactions->[1]->source, "Source 1 correctly assigned"); + + # acc_trans + cmp_ok ($amount, '==', $booking->transactions->[0]->amount, "Correct amount Soll"); + cmp_ok ($amount * -1, '==', $booking->transactions->[1]->amount, "Correct amount Haben"); + is (ref $booking->transdate, 'DateTime', "Booking has a Transdate"); + is ($accno_credit, $booking->transactions->[0]->chart->accno, "Sollkonto richtig"); + is ($accno_debit, $booking->transactions->[1]->chart->accno, "Habenkonto richtig"); + + $i++; +} + +clear_up(); + + +done_testing(); + +1; + +sub clear_up { + SL::DB::Manager::AccTransaction->delete_all( all => 1); + SL::DB::Manager::GLTransaction->delete_all( all => 1); + foreach my $accno (@charts) { + SL::DB::Manager::Chart->delete_all(where => [ accno => $accno ] ); + } +}; -- 2.20.1