3 use Test::Deep qw(cmp_bag);
7 use_ok 'Support::TestSetup';
8 use SL::DATEV qw(:CONSTANTS);
10 use List::Util qw(sum);
11 use SL::DB::Buchungsgruppe;
15 Support::TestSetup::login();
19 my $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%') || die "No accounting group for 7\%";
20 my $bank = SL::DB::Manager::Chart->find_by(description => 'Bank') || die 'Can\'t find chart "Bank"';
21 my $date = DateTime->new(year => 2017, month => 1, day => 1);
22 my $payment_date = DateTime->new(year => 2017, month => 1, day => 5);
24 my $part1 = SL::Dev::Part::create_part(partnumber => '19', description => 'Part 19%')->save;
25 my $part2 = SL::Dev::Part::create_part(
27 description => 'Part 7%',
28 buchungsgruppen_id => $buchungsgruppe7->id,
31 my $invoice = SL::Dev::Record::create_sales_invoice(
32 invnumber => "1 sales invoice",
35 invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70),
36 SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50),
39 $invoice->pay_invoice(chart_id => $bank->id,
40 amount => $invoice->open_amount,
41 transdate => $payment_date->to_kivitendo,
45 my $datev1 = SL::DATEV->new(
46 dbh => $invoice->db->dbh,
47 trans_id => $invoice->id,
49 $datev1->generate_datev_data;
50 my $kne_lines1 = $datev1->generate_datev_lines;
51 cmp_bag $datev1->generate_datev_lines, [
53 'belegfeld1' => '1 sales invoice',
54 'buchungstext' => 'Testcustomer',
55 'datum' => '01.01.2017',
56 'gegenkonto' => '8400',
62 'belegfeld1' => '1 sales invoice',
63 'buchungstext' => 'Testcustomer',
64 'datum' => '01.01.2017',
65 'gegenkonto' => '8300',
71 'belegfeld1' => '1 sales invoice',
72 'buchungstext' => 'Testcustomer',
73 'datum' => '05.01.2017',
74 'gegenkonto' => '1400',
79 ], "trans_id datev check ok";
81 my $invoice2 = SL::Dev::Record::create_sales_invoice(
82 invnumber => "2 sales invoice",
85 invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 6, sellprice => 70),
86 SL::Dev::Record::create_invoice_item(part => $part2, qty => 20, sellprice => 50),
90 my $credit_note = SL::Dev::Record::create_credit_note(
91 invnumber => 'Gutschrift 34',
94 invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70),
95 SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50),
99 my $startdate = DateTime->new(year => 2017, month => 1, day => 1);
100 my $enddate = DateTime->new(year => 2017, month => 12, day => 31);
102 my $datev = SL::DATEV->new(
103 dbh => $credit_note->db->dbh,
107 $datev->generate_datev_data(from_to => $datev->fromto);
108 my $datev_lines = $datev->generate_datev_lines;
109 my $umsatzsumme = sum map { $_->{umsatz} } @{ $datev_lines };
110 is($umsatzsumme, 3924.50, "umsatzsumme ok");
116 SL::DB::Manager::AccTransaction->delete_all(all => 1);
117 SL::DB::Manager::InvoiceItem->delete_all( all => 1);
118 SL::DB::Manager::Invoice->delete_all( all => 1);
119 SL::DB::Manager::Customer->delete_all( all => 1);
120 SL::DB::Manager::Part->delete_all( all => 1);