1 use Test::More tests => 48;
2 use Test::Deep qw(cmp_deeply);
9 use Support::TestSetup;
12 use SL::DB::BankTransaction;
13 use SL::DB::BankTransactionAccTrans;
17 use SL::DB::GLTransaction;
18 use SL::DB::AccTransaction;
20 use SL::DB::PaymentTerm;
21 use SL::DBUtils qw(selectall_hashref_query);
22 use SL::Dev::Record qw(:ALL);
23 use SL::Dev::CustomerVendor qw(new_customer new_vendor);
24 use SL::Dev::Part qw(new_part);
25 use SL::Dev::Payment qw(create_payment_terms);
28 Support::TestSetup::login();
29 my $dbh = SL::DB->client->dbh;
33 # TODOs: Storno muß noch korrekt funktionieren
34 # neue Konten für 5% anlegen
35 # Leistungszeitraum vs. Datum Zuord. Steuerperiodest
40 note('checking if all tax entries exist for Konjunkturprogramm');
42 # create dates to test on
43 my $date_2006 = DateTime->new(year => 2006, month => 6, day => 15);
44 my $date_2020_1 = DateTime->new(year => 2020, month => 6, day => 15);
45 my $date_2020_2 = DateTime->new(year => 2020, month => 7, day => 15);
46 my $date_2021 = DateTime->new(year => 2021, month => 1, day => 15);
49 my $bank_account = SL::DB::BankAccount->new(
50 account_number => '123',
55 chart_id => SL::DB::Manager::Chart->find_by( description => 'Bank' )->id,
56 name => SL::DB::Manager::Chart->find_by( description => 'Bank' )->description,
60 my $currency_id = $::instance_conf->get_currency_id;
61 my $bt = SL::DB::BankTransaction->new(
62 local_bank_account_id => $bank_account->id,
63 transdate => $date_2021,
64 valutadate => $date_2021,
67 currency => $currency_id,
72 # The only way to discern the pre-2007 16% tax from the 2020 16% tax is by
73 # their configured automatic tax charts, so look them up here:
75 my ($chart_vst_19, $chart_vst_16, $chart_vst_5, $chart_vst_7);
76 my ($chart_ust_19, $chart_ust_16, $chart_ust_5, $chart_ust_7);
77 my ($income_19_accno, $income_7_accno);
78 my ($ar_accno, $ap_accno);
79 my ($chart_reisekosten_accno, $chart_cash_accno, $chart_bank_accno);
81 my ($skonto_5, $skonto_16, $skonto_7, $skonto_19); # store acc_trans entries during tests
83 my $test_kontenrahmen = $::instance_conf->get_coa eq 'Germany-DATEV-SKR04EU' ? 'skr04' : 'skr03';
85 if ( $test_kontenrahmen eq 'skr03' ) {
87 is(SL::DB::Default->get->coa, 'Germany-DATEV-SKR03EU', "coa SKR03 ok");
89 $chart_ust_19 = '1776';
90 $chart_ust_16 = '1775';
91 $chart_ust_5 = '1773';
92 $chart_ust_7 = '1771';
94 $chart_vst_19 = '1576';
95 $chart_vst_16 = '1575';
96 $chart_vst_5 = '1568';
97 $chart_vst_7 = '1571';
99 $income_19_accno = '8400';
100 $income_7_accno = '8300';
102 $chart_reisekosten_accno = 4660;
103 $chart_cash_accno = 1000;
104 $chart_bank_accno = 1200;
109 } elsif ( $test_kontenrahmen eq 'skr04') { # skr04 - test can be ran manually by running t/000setup_database.t with coa for SKR04
110 is(SL::DB::Default->get->coa, 'Germany-DATEV-SKR04EU', "coa SKR04 ok");
111 $chart_vst_19 = '1406';
112 $chart_vst_16 = '1405';
113 $chart_vst_5 = '1403';
114 $chart_vst_7 = '1401';
116 $chart_ust_19 = '3806';
117 $chart_ust_16 = '3805';
118 $chart_ust_5 = '3803';
119 $chart_ust_7 = '3801';
121 $income_19_accno = '4400';
122 $income_7_accno = '4300';
124 $chart_reisekosten_accno = 6650;
125 $chart_cash_accno = 1600;
126 $chart_bank_accno = 1800;
132 my $tax_vst_19 = SL::DB::Manager::Chart->find_by(accno => $chart_vst_19) or die; # 19%
133 my $tax_vst_16 = SL::DB::Manager::Chart->find_by(accno => $chart_vst_16) or die; # 16%
134 my $tax_vst_5 = SL::DB::Manager::Chart->find_by(accno => $chart_vst_5 ) or die; # 5%
135 my $tax_vst_7 = SL::DB::Manager::Chart->find_by(accno => $chart_vst_7 ) or die; # 7%
137 my $tax_ust_19 = SL::DB::Manager::Chart->find_by(accno => $chart_ust_19) or die; # 19%
138 my $tax_ust_16 = SL::DB::Manager::Chart->find_by(accno => $chart_ust_16) or die; # 16%
139 my $tax_ust_5 = SL::DB::Manager::Chart->find_by(accno => $chart_ust_5) or die; # 5%
140 my $tax_ust_7 = SL::DB::Manager::Chart->find_by(accno => $chart_ust_7) or die; # 7%
142 my $chart_income_19 = SL::DB::Manager::Chart->find_by(accno => $income_19_accno) or die;
143 my $chart_income_7 = SL::DB::Manager::Chart->find_by(accno => $income_7_accno) or die;
145 my $chart_reisekosten = SL::DB::Manager::Chart->find_by(accno => $chart_reisekosten_accno) or die;
146 my $chart_cash = SL::DB::Manager::Chart->find_by(accno => $chart_cash_accno) or die;
147 my $chart_bank = SL::DB::Manager::Chart->find_by(accno => $chart_bank_accno) or die;
149 my $payment_terms = create_payment_terms();
151 is(defined SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.05), 1, "tax for taxkey 2 with 5% was created ok");
152 is(defined SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.16, chart_id => $tax_ust_16->id), 1, "new sales tax for taxkey 3 with 16% exists ok");
153 is(defined SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, chart_id => $tax_ust_19->id), 1, "old sales tax for taxkey 3 with 19% exists ok");
154 # is(defined SL::DB::Manager::Tax->find_by(taxkey => 5, rate => 0.16, chart_id => $tax_ust_16->id), 1, "new sales tax for taxkey 5 with 16% exists ok");
156 # is(defined SL::DB::Manager::Tax->find_by(taxkey => 7, rate => 0.16, chart_id => $tax_ust_16->id), 1, "old purchase tax for taxkey 7 with 16% exists ok");
157 is(defined SL::DB::Manager::Tax->find_by(taxkey => 8, rate => 0.07, chart_id => $tax_vst_7->id ), 1, "purchase tax for taxkey 8 with 7% exists ok");
158 is(defined SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, chart_id => $tax_vst_19->id), 1, "old purchase tax for taxkey 9 with 19% exists ok");
159 is(defined SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.16, chart_id => $tax_vst_16->id), 1, "new purchase tax for taxkey 9 with 16% exists ok");
161 my $vendor = new_vendor( name => 'Testvendor', payment_id => $payment_terms->id)->save;
162 my $customer = new_customer(name => 'Testcustomer', payment_id => $payment_terms->id)->save;
164 cmp_ok($chart_income_7->get_active_taxkey($date_2020_1)->tax->rate, '==', 0.07, "get_active_taxkey rate for 8300 in 2020_1 ok");
165 cmp_ok($chart_income_7->get_active_taxkey($date_2020_2)->tax->rate, '==', 0.05, "get_active_taxkey rate for 8300 in 2020_2 ok");
166 cmp_ok($chart_income_7->get_active_taxkey($date_2021 )->tax->rate, '==', 0.07, "get_active_taxkey rate for 8300 in 2021 ok");
167 cmp_ok($chart_income_7->get_active_taxkey($date_2020_1)->tax->rate, '==', 0.07, "get_active_taxkey rate for $income_7_accno in 2020_1 ok");
168 cmp_ok($chart_income_7->get_active_taxkey($date_2020_2)->tax->rate, '==', 0.05, "get_active_taxkey rate for $income_7_accno in 2020_2 ok");
169 cmp_ok($chart_income_7->get_active_taxkey($date_2021 )->tax->rate, '==', 0.07, "get_active_taxkey rate for $income_7_accno in 2021 ok");
170 cmp_ok($chart_income_7->get_active_taxkey($date_2006 )->tax->rate, '==', 0.07, "get_active_taxkey rate for $income_7_accno in 2016 ok");
172 cmp_ok($chart_income_19->get_active_taxkey($date_2020_1)->tax->rate, '==', 0.19, "get_active_taxkey rate for $income_19_accno in 2020_1 ok");
173 cmp_ok($chart_income_19->get_active_taxkey($date_2020_2)->tax->rate, '==', 0.16, "get_active_taxkey rate for $income_19_accno in 2020_2 ok");
174 cmp_ok($chart_income_19->get_active_taxkey($date_2021 )->tax->rate, '==', 0.19, "get_active_taxkey rate for $income_19_accno in 2021 ok");
175 cmp_ok($chart_income_19->get_active_taxkey($date_2006 )->tax->rate, '==', 0.16, "get_active_taxkey rate for $income_19_accno in 2016 ok");
177 my $bugru19 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') or die "Can't find bugru19";
178 my $bugru7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%' ) or die "Can't find bugru7";
180 my $part1 = new_part(partnumber => '1', description => 'part19', buchungsgruppen_id => $bugru19->id)->save;
181 my $part2 = new_part(partnumber => '2', description => 'part7', buchungsgruppen_id => $bugru7->id )->save;
183 note('sales invoices');
184 my $sales_invoice_2006 = create_invoice_for_date('2006', $date_2006);
185 my $sales_invoice_2020_1 = create_invoice_for_date('2020_1', $date_2020_1);
186 my $sales_invoice_2020_2 = create_invoice_for_date('2020_2', $date_2020_2);
187 my $sales_invoice_2021 = create_invoice_for_date('2021', $date_2021);
189 is($sales_invoice_2006->amount, 223, '2006 sales invoice has 16% and 7% tax ok' ); # 116 + 7
190 is($sales_invoice_2020_1->amount, 226, '2020_01 sales invoice has 19% and 7% tax ok'); # 119 + 7
191 is($sales_invoice_2020_2->amount, 221, '2020_02 sales invoice has 16% and 5% tax ok'); # 116 + 5
192 is($sales_invoice_2021->amount, 226, '2021 sales invoice has 19% and 7% tax ok' ); # 119 + 7
194 &datev_test($sales_invoice_2020_2,
197 'belegfeld1' => 'test is 2020_2',
198 'buchungstext' => 'Testcustomer',
199 'datum' => '15.07.2020',
200 'leistungsdatum' => '15.07.2020', # should leistungsdatum be empty if it doesn't exist?
201 'gegenkonto' => $income_7_accno,
202 'konto' => $ar_accno,
210 'belegfeld1' => 'test is 2020_2',
211 'buchungstext' => 'Testcustomer',
212 'datum' => '15.07.2020',
213 'leistungsdatum' => '15.07.2020',
214 'gegenkonto' => $income_19_accno,
215 'konto' => $ar_accno,
223 "datev check for 16/5 ok, no taxkey"
226 note('sales invoice with differing delivery dates');
227 my $sales_invoice_2020_1_with_delivery_date_2020_2 = create_invoice_for_date('deliverydate 2020_1', $date_2020_1, $date_2020_2);
228 is($sales_invoice_2020_1_with_delivery_date_2020_2->amount, 221, "sales_invoice from 2020_1 with future delivery_date 2020_2 tax ok");
230 my $sales_invoice_2020_2_with_delivery_date_2020_1 = create_invoice_for_date('deliverydate 2020_2', $date_2020_2, $date_2020_1);
231 is($sales_invoice_2020_2_with_delivery_date_2020_1->amount, 226, "sales_invoice from 2020_2 with past delivery_date 2020_1 tax ok");
233 &datev_test($sales_invoice_2020_2_with_delivery_date_2020_1,
236 'belegfeld1' => 'test is deliverydate 2020_2',
237 'buchungstext' => 'Testcustomer',
238 'datum' => '15.07.2020',
239 'gegenkonto' => $income_7_accno,
240 'konto' => $ar_accno,
243 'leistungsdatum' => '15.06.2020',
249 'belegfeld1' => 'test is deliverydate 2020_2',
250 'buchungstext' => 'Testcustomer',
251 'datum' => '15.07.2020',
252 'gegenkonto' => $income_19_accno,
253 'konto' => $ar_accno,
256 'leistungsdatum' => '15.06.2020',
262 "datev check for datev export with delivery_date 19/7 ok, no taxkey"
265 my $sales_invoice_2021_with_delivery_date_2020_2 = create_invoice_for_date('deliverydate 2020_2', $date_2021, $date_2020_2);
266 is($sales_invoice_2021_with_delivery_date_2020_2->amount, 221, "sales_invoice from 2021 with past delivery_date 2020_2 tax ok");
268 my $sales_invoice_2020_2_with_delivery_date_2021 = create_invoice_for_date('deliverydate 2021', $date_2020_2, $date_2021);
269 is($sales_invoice_2020_2_with_delivery_date_2021->amount, 226, "sales_invoice from 2020_2 with future delivery_date 2021 tax ok");
272 note('ap transactions');
273 # in the test we want to test for Reisekosten with 19% and 7%. Normally the user
274 # would select the entries from the dropdown, as they may differ from the
275 # default, so we have to pass the tax we want to create_ap_transaction
277 # my $tax_9_16_old = SL::DB::Manager::Tax->find_by(taxkey => 7, rate => 0.16, chart_id => $tax_vst_16->id);
278 my $tax_9_19 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, chart_id => $tax_vst_19->id) or die "missing 9_19";
279 my $tax_9_16 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.16, chart_id => $tax_vst_16->id) or die "missing 9_16";
280 my $tax_8_7 = SL::DB::Manager::Tax->find_by(taxkey => 8, rate => 0.07, chart_id => $tax_vst_7->id) or die "missing 8_7";
281 my $tax_8_5 = SL::DB::Manager::Tax->find_by(taxkey => 8, rate => 0.05, chart_id => $tax_vst_5->id) or die "missing 8_5";
283 # simulate user selecting the "correct" taxes in dropdown:
284 my $ap_transaction_2006 = create_ap_transaction_for_date('2006', $date_2006, undef, $tax_9_16, $tax_8_7);
285 my $ap_transaction_2020_1 = create_ap_transaction_for_date('2020_1', $date_2020_1, undef, $tax_9_19, $tax_8_7);
286 my $ap_transaction_2020_2 = create_ap_transaction_for_date('2020_2', $date_2020_2, undef, $tax_9_16, $tax_8_5);
287 my $ap_transaction_2021 = create_ap_transaction_for_date('2021', $date_2021, undef, $tax_9_19, $tax_8_7);
290 is($ap_transaction_2006->amount, 223, '2006 ap transaction has 16% and 7% tax ok'); # 116 + 7
291 is($ap_transaction_2020_1->amount, 226, '2020_01 ap transaction has 19% and 7% tax ok'); # 119 + 7
292 is($ap_transaction_2020_2->amount, 221, '2020_02 ap transaction has 16% and 5% tax ok'); # 116 + 5
293 is($ap_transaction_2021->amount, 226, '2021 ap transaction has 19% and 7% tax ok'); # 119 + 7
295 # ap transaction in july, but use old tax
296 my $ap_transaction_2020_2_with_delivery_date_2020_1 = create_ap_transaction_for_date('2020_2 with delivery date 2020_1', $date_2020_2, $date_2020_1, $tax_9_19, $tax_8_7);
297 is($ap_transaction_2020_2_with_delivery_date_2020_1->amount, 226, 'ap transaction 2020_2 with delivery date 2020_1, 19% and 7% tax ok'); # 119 + 7
298 &datev_test($ap_transaction_2020_2_with_delivery_date_2020_1,
301 'belegfeld1' => 'test ap_transaction 2020_2 with delivery date 2020_1',
302 'buchungsschluessel' => 8,
303 'buchungstext' => 'Testvendor',
304 'datum' => '15.07.2020',
305 'gegenkonto' => $ap_accno,
306 'konto' => $chart_reisekosten_accno,
309 'leistungsdatum' => '15.06.2020',
315 'belegfeld1' => 'test ap_transaction 2020_2 with delivery date 2020_1',
316 'buchungsschluessel' => 9,
317 'buchungstext' => 'Testvendor',
318 'datum' => '15.07.2020',
319 'gegenkonto' => $ap_accno,
320 'konto' => $chart_reisekosten_accno,
323 'leistungsdatum' => '15.06.2020',
329 "datev check for ap transaction 2020_2 with delivery date 2020_1, 19% and 7% tax ok"
332 note('ar transactions');
334 my $ar_transaction_2006 = create_ar_transaction_for_date('2006', $date_2006);
335 my $ar_transaction_2020_1 = create_ar_transaction_for_date('2020_1', $date_2020_1);
336 my $ar_transaction_2020_2 = create_ar_transaction_for_date('2020_2', $date_2020_2);
337 my $ar_transaction_2021 = create_ar_transaction_for_date('2021', $date_2021);
339 is($ar_transaction_2006->amount, 223, '2006 ar transaction has 16% and 7% tax ok'); # 116 + 7
340 is($ar_transaction_2020_1->amount, 226, '2020_01 ar transaction has 19% and 7% tax ok'); # 119 + 7
341 is($ar_transaction_2020_2->amount, 221, '2020_02 ar transaction has 16% and 5% tax ok'); # 116 + 5
342 is($ar_transaction_2021->amount, 226, '2021 ar transaction has 19% and 7% tax ok'); # 119 + 7
344 note('gl transactions');
346 my $gl_2006 = create_gl_transaction_for_date('glincome 2006', $date_2006, 223);
347 my $gl_2020_1 = create_gl_transaction_for_date('glincome 2020_1', $date_2020_1, 226);
348 my $gl_2020_2 = create_gl_transaction_for_date('glincome 2020_2', $date_2020_2, 221);
349 my $gl_2021 = create_gl_transaction_for_date('glincome 2021', $date_2021, 226);
351 is(SL::DB::Manager::GLTransaction->get_all_count(), 4, "4 gltransactions created correctly");
353 my $result = &get_account_balances;
354 # print Dumper($result);
355 is_deeply( &get_account_balances,
359 # # 'description' => 'Kasse',
360 # 'sum' => '-896.00000'
364 # # 'description' => 'Ford. a.Lieferungen und Leistungen',
365 # 'sum' => '-2686.00000'
369 # 'description' => 'Abziehbare Vorsteuer 7%',
374 # 'description' => 'Abziehbare Vorsteuer 7%',
379 # 'description' => 'Abziehbare Vorsteuer 16%',
384 # 'description' => 'Abziehbare Vorsteuer 19 %',
389 # # 'description' => 'Verbindlichkeiten aus Lief.u.Leist.',
390 # 'sum' => '896.00000'
394 # 'description' => 'Umsatzsteuer 7%',
399 # 'description' => 'Umsatzsteuer 5 %',
404 # 'description' => 'Umsatzsteuer 16%',
409 # 'description' => 'Umsatzsteuer 19 %',
414 # # 'description' => 'Reisekosten Arbeitnehmer',
415 # 'sum' => '-800.00000'
418 # 'accno' => $income_7_accno,
419 # # 'description' => "Erl\x{f6}se 7%USt",
420 # 'sum' => '1600.00000'
423 # 'accno' => $income_19_accno,
424 # # 'description' => "Erl\x{f6}se 16%/19% USt.",
425 # 'sum' => '1600.00000'
428 'account balances after invoices'
431 note('testing payments with skonto');
433 my %params = ( chart_id => $chart_bank->id,
434 payment_type => 'with_skonto_pt',
438 $sales_invoice_2020_2->pay_invoice( %params,
439 amount => $sales_invoice_2020_2->amount_less_skonto,
440 transdate => $date_2020_2->to_kivitendo,
444 $skonto_5 = SL::DB::Manager::AccTransaction->find_by(trans_id => $sales_invoice_2020_2->id, amount => -5.25);
445 like($skonto_5->chart->description, qr/Skonti.*5/, "sales_invoice 2020_2 paid in 2020_2 - skonto 5% ok");
446 $skonto_16 = SL::DB::Manager::AccTransaction->find_by(trans_id => $sales_invoice_2020_2->id, amount => -5.80);
447 like($skonto_16->chart->description, qr/Skonti.*16/, "sales_invoice 2020_2 paid in 2020_2 - skonto 16% ok");
449 $sales_invoice_2020_1->pay_invoice( %params,
450 amount => $sales_invoice_2020_1->amount_less_skonto,
451 transdate => $date_2020_2->to_kivitendo,
453 $skonto_7 = SL::DB::Manager::AccTransaction->find_by(trans_id => $sales_invoice_2020_1->id, amount => -5.35);
454 like($skonto_7->chart->description, qr/Skonti.*7/, "sales_invoice 2020_1 paid with skonto in 2020_2 - skonto 7% ok");
455 $skonto_19 = SL::DB::Manager::AccTransaction->find_by(trans_id => $sales_invoice_2020_1->id, amount => -5.95);
456 like($skonto_19->chart->description, qr/Skonti.*19/, "sales_invoice 2020_1 paid with skonto in 2020_2 - skonto 19% ok");
458 $ap_transaction_2020_1->pay_invoice( %params,
459 amount => $ap_transaction_2020_1->amount_less_skonto,
460 transdate => $date_2020_2->to_kivitendo,
462 $skonto_7 = SL::DB::Manager::AccTransaction->find_by(trans_id => $ap_transaction_2020_1->id, amount => 5.35);
463 like($skonto_7->chart->description, qr/Skonti.*7/, "ap transaction 2020_1 paid with skonto in 2020_2 - skonto 7% ok");
464 $skonto_19 = SL::DB::Manager::AccTransaction->find_by(trans_id => $ap_transaction_2020_1->id, amount => 5.95);
465 like($skonto_19->chart->description, qr/Skonti.*19/, "ap transaction 2020_1 paid with skonto in 2020_2 - skonto 19% ok");
468 $ap_transaction_2020_2->pay_invoice( %params,
469 amount => $ap_transaction_2020_2->amount_less_skonto,
470 transdate => $date_2021->to_kivitendo,
472 $skonto_5 = SL::DB::Manager::AccTransaction->find_by(trans_id => $ap_transaction_2020_2->id, amount => 5.25);
473 like($skonto_5->chart->description, qr/Skonti.*5/, "ap transaction 2020_2 paid in 2021 - skonto 5% ok");
475 $skonto_16 = SL::DB::Manager::AccTransaction->find_by(trans_id => $ap_transaction_2020_2->id, amount => 5.80);
476 like($skonto_16->chart->description, qr/Skonti.*16/, "sales_invoice 2020_2 paid in 2021 - skonto 16% ok");
482 ###### functions for setting up data
484 sub create_invoice_for_date {
485 my ($invnumber, $transdate, $deliverydate) = @_;
487 $deliverydate = $transdate unless defined $deliverydate;
489 my $sales_invoice = create_sales_invoice(
490 invnumber => 'test is ' . $invnumber,
491 transdate => $transdate,
492 customer => $customer,
493 deliverydate => $deliverydate,
494 payment_terms => $payment_terms,
496 invoiceitems => [ create_invoice_item(part => $part1, qty => 10, sellprice => 10),
497 create_invoice_item(part => $part2, qty => 10, sellprice => 10),
500 return $sales_invoice;
503 sub create_ar_transaction_for_date {
504 my ($invnumber, $transdate) = @_;
506 my $ar_transaction = create_ar_transaction(
507 customer => $customer,
508 invnumber => 'test ar' . $invnumber,
510 transdate => $transdate,
511 ar_chart => SL::DB::Manager::Chart->find_by(accno => $ar_accno), # pass ar_chart, as it is hardcoded for SKR03 in SL::Dev::Record
514 chart => $chart_income_19,
518 chart => $chart_income_7,
523 return $ar_transaction;
526 sub create_ap_transaction_for_date {
527 my ($invnumber, $transdate, $deliverydate, $tax_high, $tax_low) = @_;
529 # printf("invnumber = %s tax_high = %s tax_low = %s\n", $invnumber, $tax_high->accno , $tax_low->accno);
530 my $taxkey_ = $chart_reisekosten->get_active_taxkey($transdate);
532 my $ap_transaction = create_ap_transaction(
534 invnumber => 'test ap_transaction ' . $invnumber,
536 transdate => $transdate,
537 deliverydate => $deliverydate,
538 payment_id => $payment_terms->id,
539 ap_chart => SL::DB::Manager::Chart->find_by(accno => $ap_accno), # pass ap_chart, as it is hardcoded for SKR03 in SL::Dev::Record
542 chart => $chart_reisekosten,
544 tax_id => $tax_high->id,
547 chart => $chart_reisekosten,
549 tax_id => $tax_low->id,
553 return $ap_transaction;
556 sub create_gl_transaction_for_date {
557 my ($reference, $transdate, $debitamount) = @_;
559 my $gl_transaction = create_gl_transaction(
560 reference => $reference,
562 transdate => $transdate,
565 chart => $chart_income_19,
571 chart => $chart_income_7,
577 chart => $chart_cash,
578 debit => $debitamount,
584 return $gl_transaction;
587 sub get_account_balances {
589 select c.accno, sum(a.amount)
591 left join chart c on (c.id = a.chart_id)
592 where c.accno ~ '^17' or c.accno ~ '^15'
593 group by c.accno, c.description
597 my $result = selectall_hashref_query($::form, $dbh, $query);
602 my ($invoice, $expected_data, $msg) = @_;
604 my $datev = SL::DATEV->new(
605 dbh => $invoice->db->dbh,
606 trans_id => $invoice->id,
609 $datev->generate_datev_data;
610 my @data_datev = sort { $a->{umsatz} <=> $b->{umsatz} } @{ $datev->generate_datev_lines() };
612 # print Dumper(\@data_datev);
614 cmp_deeply(\@data_datev, $expected_data, $msg);
618 SL::DB::Manager::BankTransactionAccTrans->delete_all(all => 1);
619 SL::DB::Manager::BankTransaction->delete_all(all => 1);
620 SL::DB::Manager::BankAccount->delete_all(all => 1);
621 SL::DB::Manager::OrderItem->delete_all(all => 1);
622 SL::DB::Manager::Order->delete_all(all => 1);
623 SL::DB::Manager::InvoiceItem->delete_all(all => 1);
624 SL::DB::Manager::Invoice->delete_all(all => 1);
625 SL::DB::Manager::PurchaseInvoice->delete_all(all => 1);
626 SL::DB::Manager::GLTransaction->delete_all(all => 1);
627 SL::DB::Manager::Part->delete_all(all => 1);
628 SL::DB::Manager::Customer->delete_all(all => 1);
629 SL::DB::Manager::Vendor->delete_all(all => 1);
630 SL::DB::Manager::PaymentTerm->delete_all(all => 1);