3 use Test::Deep qw(cmp_bag);
7 use_ok 'Support::TestSetup';
8 use SL::DATEV qw(:CONSTANTS);
9 use SL::Dev::ALL qw(:ALL);
10 use List::Util qw(sum);
11 use SL::DB::Buchungsgruppe;
17 Support::TestSetup::login();
19 my $dbh = SL::DB->client->dbh;
22 my $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%') || die "No accounting group for 7\%";
23 my $date = DateTime->new(year => 2017, month => 7, day => 19);
24 my $department = create_department(description => 'Kästchenweiße heiße Preise');
25 my $project = create_project(projectnumber => 2017, description => '299');
27 my $part1 = new_part(partnumber => '19', description => 'Part 19%')->save;
30 description => 'Part 7%',
31 buchungsgruppen_id => $buchungsgruppe7->id,
34 my $invoice = create_sales_invoice(
40 invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 550),
41 create_invoice_item(part => $part2, qty => 10, sellprice => 50),
43 department_id => $department->id,
44 globalproject_id => $project->id,
48 # generate_datev_* doesnt care about encoding but
49 # csv_buchungsexport does! all arabic will be deleted
50 # and no string will be left as invnumber
52 my $datev1 = SL::DATEV->new(
54 trans_id => $invoice->id,
57 my $startdate = DateTime->new(year => 2017, month => 1, day => 1);
58 my $enddate = DateTime->new(year => 2017, month => 12, day => 31);
59 my $today = DateTime->new(year => 2017, month => 3, day => 17);
62 $datev1->from($startdate);
63 $datev1->to($enddate);
65 $datev1->generate_datev_data;
66 $datev1->generate_datev_lines;
68 # check conversion to csv
69 $datev1->from($startdate);
70 $datev1->to($enddate);
71 my ($datev_ref, $warnings_ref) = SL::DATEV::CSV->new(datev_lines => $datev1->generate_datev_lines,
74 locked => $datev1->locked,
76 my @warnings = $warnings_ref;
77 is($warnings[0]->[0]->{untranslated},
78 'Wrong field value \'#1\' for field \'#2\' for the transaction with amount \'#3\'', 'wrong_encoding');
81 # redefine invnumber, we have mixed encodings, should still generate a warning
82 $invoice->invnumber('ݗݘݰݶmuh');
85 my $datev3 = SL::DATEV->new(
87 trans_id => $invoice->id,
90 $datev3->from($startdate);
91 $datev3->to($enddate);
92 $datev3->generate_datev_data;
93 $datev3->generate_datev_lines;
94 my ($datev_ref2, $warnings_ref2) = SL::DATEV::CSV->new(datev_lines => $datev3->generate_datev_lines,
97 locked => $datev3->locked,
103 @warnings = $warnings_ref2;
104 is($warnings[0]->[0]->{untranslated},
105 'Wrong field value \'#1\' for field \'#2\' for the transaction with amount \'#3\'', 'mixed_wrong_encoding');
109 # create one haben buchung with GLTransaction today
111 my $expense_chart = SL::DB::Manager::Chart->find_by(accno => '4660'); # Reisekosten
112 my $cash_chart = SL::DB::Manager::Chart->find_by(accno => '1000'); # Kasse
113 my $tax_chart = SL::DB::Manager::Chart->find_by(accno => '1576'); # Vorsteuer
114 my $tax_9 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19) || die "No tax";
117 push(@acc_trans, SL::DB::AccTransaction->new(
118 chart_id => $expense_chart->id,
119 chart_link => $expense_chart->link,
124 tax_id => $tax_9->id,
125 project_id => $project->id,
127 push(@acc_trans, SL::DB::AccTransaction->new(
128 chart_id => $tax_chart->id,
129 chart_link => $tax_chart->link,
134 tax_id => $tax_9->id,
135 project_id => $project->id,
137 push(@acc_trans, SL::DB::AccTransaction->new(
138 chart_id => $cash_chart->id,
139 chart_link => $cash_chart->link,
147 my $gl_transaction = SL::DB::GLTransaction->new(
148 reference => "Reisekosten März 2018",
149 description => "Reisekonsten März 2018 / Ma Schmidt",
152 employee_id => SL::DB::Manager::Employee->current->id,
159 transactions => \@acc_trans,
161 my $datev2 = SL::DATEV->new(
163 trans_id => $gl_transaction->id,
166 $datev2->from($startdate);
167 $datev2->to($enddate);
168 $datev2->generate_datev_data;
169 $datev2->generate_datev_lines;
171 my ($datev_ref3, $warnings_ref3) = SL::DATEV::CSV->new(datev_lines => $datev2->generate_datev_lines,
174 locked => $datev2->locked,
177 my @data_csv = splice @{ $datev_ref3 }, 2, 5;
178 @data_csv = sort { $a->[0] cmp $b->[0] } @data_csv;
180 my $cp1252_posting_text = SL::Iconv::convert("UTF-8", "CP1252", 'Reisekosten März 2018');
181 cmp_bag($data_csv[0], [ 100, 'H', 'EUR', undef, undef, undef, '4660', '1000', 9, '1703', 'Reisekosten ',
182 undef, undef, $cp1252_posting_text, undef, undef, undef, undef, undef, undef, undef, undef,
183 undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
184 undef, undef, '', undef, undef, undef, undef, undef, undef, undef, undef,
185 undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
186 undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
187 undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
188 undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
189 undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
190 undef, undef, undef, undef, undef ]
198 SL::DB::Manager::AccTransaction->delete_all( all => 1);
199 SL::DB::Manager::GLTransaction->delete_all( all => 1);
200 SL::DB::Manager::InvoiceItem->delete_all( all => 1);
201 SL::DB::Manager::Invoice->delete_all( all => 1);
202 SL::DB::Manager::Customer->delete_all( all => 1);
203 SL::DB::Manager::Part->delete_all( all => 1);
204 SL::DB::Manager::Project->delete_all( all => 1);
205 SL::DB::Manager::Department->delete_all( all => 1);
206 SL::DATEV->clean_temporary_directories;