Ergänzung zu a3b8cfa7b7546 (Mahnungen konfigurierbar machen)
[kivitendo-erp.git] / t / controllers / csvimport / artransactions.t
1 use Test::More tests => 70;
2
3 use strict;
4
5 use lib 't';
6
7 use Carp;
8 use Data::Dumper;
9 use Support::TestSetup;
10 use Test::Exception;
11
12 use List::MoreUtils qw(pairwise);
13 use SL::Controller::CsvImport;
14
15 my $DEBUG = 0;
16
17 use_ok 'SL::Controller::CsvImport::ARTransaction';
18
19 use SL::DB::Buchungsgruppe;
20 use SL::DB::Currency;
21 use SL::DB::Customer;
22 use SL::DB::Employee;
23 use SL::DB::Invoice;
24 use SL::DB::TaxZone;
25 use SL::DB::Chart;
26 use SL::DB::AccTransaction;
27
28 my ($customer, $currency_id, $employee, $taxzone, $project, $department);
29
30 sub reset_state {
31   # Create test data
32   my %params = @_;
33
34   $params{$_} ||= {} for qw(buchungsgruppe customer tax);
35
36   clear_up();
37   $employee        = SL::DB::Manager::Employee->current                          || croak "No employee";
38   $taxzone         = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || croak "No taxzone";
39   $currency_id     = $::instance_conf->get_currency_id;
40
41   $customer     = SL::DB::Customer->new(
42     name        => 'Test Customer',
43     currency_id => $currency_id,
44     taxzone_id  => $taxzone->id,
45     %{ $params{customer} }
46   )->save;
47
48   $project     = SL::DB::Project->new(
49     projectnumber  => 'P1',
50     description    => 'Project X',
51     project_type   => SL::DB::Manager::ProjectType->find_by(description => 'Standard'),
52     project_status => SL::DB::Manager::ProjectStatus->find_by(name => 'running'),
53   )->save;
54
55   $department     = SL::DB::Department->new(
56     description    => 'Department 1',
57   )->save;
58 }
59
60 Support::TestSetup::login();
61
62 reset_state(customer => {id => 960, customernumber => 2});
63
64 #####
65 sub test_import {
66   my $file = shift;
67
68   my $controller = SL::Controller::CsvImport->new(
69     type => 'ar_transactions'
70   );
71   $controller->load_default_profile;
72   $controller->profile->set(
73     charset      => 'utf-8',
74     sep_char     => ',',
75     quote_char   => '"',
76     numberformat => $::myconfig{numberformat},
77   );
78
79   my $csv_artransactions_import = SL::Controller::CsvImport::ARTransaction->new(
80     settings    => {'ar_column'          => 'Rechnung',
81                     'transaction_column' => 'AccTransaction',
82                     'max_amount_diff'    => 0.02
83                   },
84     controller => $controller,
85     file       => $file,
86   );
87
88   # $csv_artransactions_import->init_vc_by;
89   $csv_artransactions_import->run(test => 0);
90
91   # don't try and save objects that have errors
92   $csv_artransactions_import->save_objects unless scalar @{$csv_artransactions_import->controller->data->[0]->{errors}};
93
94  return $csv_artransactions_import->controller->data;
95 }
96
97 ##### manually create an ar transaction from scratch, testing the methods
98 $::myconfig{numberformat} = '1000.00';
99 my $old_locale = $::locale;
100 # set locale to en so we can match errors
101 $::locale = Locale->new('en');
102
103 my $amount = 10;
104
105 my $ar = SL::DB::Invoice->new(
106   invoice      => 0,
107   invnumber    => 'manual invoice',
108   taxzone_id   => $taxzone->id,
109   currency_id  => $currency_id,
110   taxincluded  => 'f',
111   customer_id  => $customer->id,
112   transdate    => DateTime->today,
113   employee_id  => SL::DB::Manager::Employee->current->id,
114   transactions => [],
115 );
116
117 my $tax3 = SL::DB::Manager::Tax->find_by(rate => 0.19, taxkey => 3) || die "can't find tax with taxkey 3";
118 my $income_chart = SL::DB::Manager::Chart->find_by(accno => '8400') || die "can't find income chart";
119
120 $ar->add_ar_amount_row(
121   amount => $amount,
122   chart  => $income_chart,
123   tax_id => $tax3->id,
124 );
125
126 $ar->recalculate_amounts; # set amount and netamount from transactions
127 is $ar->amount, '10', 'amount of manual invoice is 10';
128 is $ar->netamount, '8.4', 'netamount of manual invoice is 10';
129
130 $ar->create_ar_row( chart => SL::DB::Manager::Chart->find_by(accno => '1400', link => 'AR') );
131 my $result = $ar->validate_acc_trans(debug => 0);
132 is $result, 1, 'manual $ar validates';
133
134 $ar->save;
135 is ${ $ar->transactions }[0]->chart->accno, '8400', 'assigned income chart after save ok';
136 is ${ $ar->transactions }[2]->chart->accno, '1400', 'assigned receivable chart after save ok';
137 is scalar @{$ar->transactions}, 3, 'manual invoice has 3 acc_trans entries';
138
139 $ar->pay_invoice(  chart_id      => SL::DB::Manager::Chart->find_by(accno => '1200')->id, # bank
140                    amount        => $ar->open_amount,
141                    transdate     => DateTime->now->to_kivitendo,
142                    payment_type  => 'without_skonto',  # default if not specified
143                   );
144 $result = $ar->validate_acc_trans(debug => 0);
145 is $result, 1, 'manual invoice validates after payment';
146
147 reset_state(customer => {id => 960, customernumber => 2});
148
149 my ($entries, $entry, $file);
150
151 # starting test of csv imports
152 # to debug errors in certain tests, run after test_import:
153 #   die Dumper($entry->{errors});
154 ##### basic test
155 $file = \<<EOL;
156 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
157 datatype,accno,amount,taxkey
158 "Rechnung",960,4,1,"invoice 1",f,1400
159 "AccTransaction",8400,159.48,3
160 EOL
161 $entries = test_import($file);
162 $entry = $entries->[0];
163 $entry->{object}->validate_acc_trans;
164
165 is $entry->{object}->invnumber, 'invoice 1', 'simple invnumber ok (customer)';
166 is $entry->{object}->customer_id, '960', 'simple customer_id ok (customer)';
167 is scalar @{$entry->{object}->transactions}, 3, 'invoice 1 has 3 acc_trans entries';
168 is $::form->round_amount($entry->{object}->transactions->[0]->amount, 2), 159.48, 'invoice 1 ar amount is 159.48';
169 is $entry->{object}->direct_debit, '0', 'no direct debit';
170 is $entry->{object}->taxincluded, '0', 'taxincluded is false';
171 is $entry->{object}->amount, '189.78', 'ar amount tax not included is 189.78';
172 is $entry->{object}->netamount, '159.48', 'ar netamount tax not included is 159.48';
173
174 ##### test for duplicate invnumber
175 $file = \<<EOL;
176 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
177 datatype,accno,amount,taxkey
178 "Rechnung",960,4,1,"invoice 1",f,1400
179 "AccTransaction",8400,159.48,3
180 EOL
181 $entries = test_import($file);
182 $entry = $entries->[0];
183 $entry->{object}->validate_acc_trans;
184 is $entry->{errors}->[0], 'Error: invnumber already exists', 'detects verify_amount differences';
185
186 ##### test for no invnumber given
187 $file = \<<EOL;
188 datatype,customer_id,taxzone_id,currency_id,taxincluded,archart
189 datatype,accno,amount,taxkey
190 "Rechnung",960,4,1,f,1400
191 "AccTransaction",8400,159.48,3
192 EOL
193 $entries = test_import($file);
194 $entry = $entries->[0];
195 $entry->{object}->validate_acc_trans;
196 is $entry->{object}->invnumber =~ /^\d+$/, 1, 'invnumber assigned automatically';
197
198 ##### basic test without amounts in Rechnung, only specified in AccTransaction
199 $file = \<<EOL;
200 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
201 datatype,accno,amount,taxkey
202 "Rechnung",960,4,1,"invoice 1 no amounts",f,1400
203 "AccTransaction",8400,159.48,3
204 EOL
205 $entries = test_import($file);
206 $entry = $entries->[0];
207 $entry->{object}->validate_acc_trans;
208
209 is $entry->{object}->invnumber, 'invoice 1 no amounts', 'simple invnumber ok (customer)';
210 is $entry->{object}->customer_id, '960', 'simple customer_id ok (customer)';
211 is scalar @{$entry->{object}->transactions}, 3, 'invoice 1 has 3 acc_trans entries';
212 is $::form->round_amount($entry->{object}->amount, 2), '189.78', 'not taxincluded ar amount';
213 is $::form->round_amount($entry->{object}->transactions->[0]->amount, 2), '159.48', 'not taxincluded acc_trans netamount';
214 is $::form->round_amount($entry->{object}->transactions->[0]->amount, 2), 159.48, 'invoice 1 ar amount is 159.48';
215
216 ##### basic test: credit_note
217 $file = \<<EOL;
218 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
219 datatype,accno,amount,taxkey
220 "Rechnung",960,4,1,"credit note",f,1400
221 "AccTransaction",8400,-159.48,3
222 EOL
223 $entries = test_import($file);
224 $entry = $entries->[0];
225 $entry->{object}->validate_acc_trans;
226
227 is $entry->{object}->invnumber, 'credit note', 'simple credit note ok';
228 is scalar @{$entry->{object}->transactions}, 3, 'credit note has 3 acc_trans entries';
229 is $::form->round_amount($entry->{object}->amount, 2), '-189.78', 'taxincluded ar amount';
230 is $::form->round_amount($entry->{object}->netamount, 2), '-159.48', 'taxincluded ar net amount';
231 is $::form->round_amount($entry->{object}->transactions->[0]->amount, 2), -159.48, 'credit note ar amount is -159.48';
232 is $entry->{object}->amount, '-189.78', 'credit note amount tax not included is 189.78';
233 is $entry->{object}->netamount, '-159.48', 'credit note netamount tax not included is 159.48';
234
235 #### verify_amount differs: max_amount_diff = 0.02, 189.80 is ok, 189.81 is not
236 $file = \<<EOL;
237 datatype,customer_id,verify_amount,verify_netamount,taxzone_id,currency_id,invnumber,taxincluded,archart
238 datatype,accno,amount,taxkey
239 "Rechnung",960,189.81,159.48,4,1,"invoice amounts differing",f,1400
240 "AccTransaction",8400,159.48,3
241 EOL
242 $entries = test_import($file);
243 $entry = $entries->[0];
244 is $entry->{errors}->[0], 'Amounts differ too much', 'detects verify_amount differences';
245
246 #####  direct debit
247 $file = \<<EOL;
248 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,direct_debit,archart
249 datatype,accno,amount,taxkey
250 "Rechnung",960,4,1,"invoice with direct debit",f,t,1400
251 "AccTransaction",8400,159.48,3
252 EOL
253
254 $entries = test_import($file);
255 $entry = $entries->[0];
256 $entry->{object}->validate_acc_trans;
257 is $entry->{object}->direct_debit, '1', 'direct debit';
258
259 #### tax included
260 $file = \<<EOL;
261 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
262 datatype,accno,amount,taxkey
263 "Rechnung",960,4,1,"invoice 1 tax included no amounts",t,1400
264 "AccTransaction",8400,189.78,3
265 EOL
266
267 $entries = test_import($file);
268 $entry = $entries->[0];
269 $entry->{object}->validate_acc_trans(debug => 0);
270 is $entry->{object}->taxincluded, '1', 'taxincluded is true';
271 is $::form->round_amount($entry->{object}->amount, 2), '189.78', 'taxincluded ar amount';
272 is $::form->round_amount($entry->{object}->netamount, 2), '159.48', 'taxincluded ar net amount';
273 is $::form->round_amount($entry->{object}->transactions->[0]->amount, 2), '159.48', 'taxincluded acc_trans netamount';
274
275 #### multiple tax included
276 $file = \<<EOL;
277 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
278 datatype,accno,amount,taxkey
279 "Rechnung",960,4,1,"invoice multiple tax included",t,1400
280 "AccTransaction",8400,94.89,3
281 "AccTransaction",8400,94.89,3
282 EOL
283
284 $entries = test_import($file);
285 $entry = $entries->[0];
286 $entry->{object}->validate_acc_trans;
287 is $::form->round_amount($entry->{object}->amount, 2),    '189.78', 'taxincluded ar amount';
288 is $::form->round_amount($entry->{object}->netamount, 2), '159.48', 'taxincluded ar netamount';
289 is $::form->round_amount($entry->{object}->transactions->[0]->amount, 2), '79.74', 'taxincluded amount';
290 is $::form->round_amount($entry->{object}->transactions->[1]->amount, 2), '15.15', 'taxincluded tax';
291
292 # different receivables chart
293 $file = \<<EOL;
294 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
295 datatype,accno,amount,taxkey
296 "Rechnung",960,4,1,"invoice mit archart 1448",f,1448
297 "AccTransaction",8400,159.48,3
298 EOL
299 $entries = test_import($file);
300 $entry = $entries->[0];
301 $entry->{object}->validate_acc_trans;
302 is $entry->{object}->transactions->[2]->chart->accno, '1448', 'archart set to 1448';
303
304 # missing customer
305 $file = \<<EOL;
306 datatype,taxzone_id,currency_id,invnumber,taxincluded,archart
307 datatype,accno,amount,taxkey
308 "Rechnung",4,1,"invoice missing customer",f,1400
309 "AccTransaction",8400,159.48,3
310 EOL
311 $entries = test_import($file);
312 $entry = $entries->[0];
313 is $entry->{errors}->[0], 'Error: Customer/vendor missing', 'detects missing customer or vendor';
314
315
316 ##### customer by name
317 $file = \<<EOL;
318 datatype,customer,taxzone_id,currency_id,invnumber,taxincluded,archart
319 datatype,accno,amount,taxkey
320 "Rechnung","Test Customer",4,1,"invoice customer name",f,1400
321 "AccTransaction",8400,159.48,3
322 EOL
323 $entries = test_import($file);
324 $entry = $entries->[0];
325 $entry->{object}->validate_acc_trans;
326 is $entry->{object}->customer->name, "Test Customer", 'detects customer by name';
327
328 ##### detect missing chart
329 $file = \<<EOL;
330 datatype,taxzone_id,currency_id,invnumber,customer,archart
331 datatype,amount,taxkey
332 "Rechnung",4,1,"invoice missing chart","Test Customer",1400
333 "AccTransaction",4,3
334 EOL
335 $entries = test_import($file);
336 $entry = $entries->[1];
337 is $entry->{errors}->[0], 'Error: chart missing', 'detects missing chart (chart_id or accno)';
338
339 ##### detect illegal chart by accno
340 $file = \<<EOL;
341 datatype,taxzone_id,currency_id,invnumber,customer,archart
342 datatype,accno,amount,taxkey
343 "Rechnung",4,1,"invoice illegal chart accno","Test Customer",1400
344 "AccTransaction",9999,4,3
345 EOL
346 $entries = test_import($file);
347 $entry = $entries->[1];
348 is $entry->{errors}->[0], 'Error: invalid chart (accno)', 'detects invalid chart (chart_id or accno)';
349
350 # ##### detect illegal archart
351 $file = \<<EOL;
352 datatype,taxzone_id,currency_id,invnumber,customer,taxincluded,archart
353 datatype,accno,amount,taxkey
354 "Rechnung",4,1,"invoice illegal archart","Test Customer",f,11400
355 "AccTransaction",8400,159.48,3
356 EOL
357 $entries = test_import($file);
358 $entry = $entries->[0];
359 is $entry->{errors}->[0], "Error: can't find ar chart with accno 11400", 'detects illegal receivables chart (archart)';
360
361 ##### detect chart by id
362 $file = \<<EOL;
363 datatype,taxzone_id,currency_id,invnumber,customer,taxincluded,archart
364 datatype,amount,chart_id,taxkey
365 "Rechnung",4,1,"invoice chart_id","Test Customer",f,1400
366 "AccTransaction",159.48,184,3
367 EOL
368 $entries = test_import($file);
369 $entry = $entries->[1]; # acc_trans entry is at entry array pos 1
370 $entries->[0]->{object}->validate_acc_trans;
371 is $entry->{object}->chart->id, "184", 'detects chart by id';
372
373 ##### detect chart by accno
374 $file = \<<EOL;
375 datatype,taxzone_id,currency_id,invnumber,customer,taxincluded,archart
376 datatype,amount,accno,taxkey
377 "Rechnung",4,1,"invoice by chart accno","Test Customer",f,1400
378 "AccTransaction",159.48,8400,3
379 EOL
380 $entries = test_import($file);
381 $entry = $entries->[1];
382 $entries->[0]->{object}->validate_acc_trans;
383 is $entry->{object}->chart->accno, "8400", 'detects chart by accno';
384
385 ##### detect chart isn't an ar_chart
386 $file = \<<EOL;
387 datatype,taxzone_id,currency_id,invnumber,customer,taxincluded,archart
388 datatype,amount,accno,taxkey
389 "Rechnung",4,1,"invoice by chart accno","Test Customer",f,1400
390 "AccTransaction",159.48,1400,3
391 EOL
392 $entries = test_import($file);
393 $entry = $entries->[1];
394 $entries->[0]->{object}->validate_acc_trans;
395 is $entry->{errors}->[0], 'Error: chart isn\'t an ar_amount chart', 'detects valid chart that is not an ar_amount chart';
396
397 # missing taxkey
398 $file = \<<EOL;
399 datatype,taxzone_id,currency_id,invnumber,customer,archart
400 datatype,amount,accno
401 "Rechnung",4,1,"invoice missing taxkey chart accno","Test Customer",1400
402 "AccTransaction",159.48,8400
403 EOL
404 $entries = test_import($file);
405 $entry = $entries->[1];
406 is $entry->{errors}->[0], 'Error: taxkey missing', 'detects missing taxkey (DATEV Steuerschlüssel)';
407
408 # illegal taxkey
409 $file = \<<EOL;
410 datatype,taxzone_id,currency_id,invnumber,customer,archart
411 datatype,amount,accno,taxkey
412 "Rechnung",4,1,"invoice illegal taxkey","Test Customer",1400
413 "AccTransaction",4,8400,123
414 EOL
415 $entries = test_import($file);
416 $entry = $entries->[1];
417 is $entry->{errors}->[0], 'Error: invalid taxkey', 'detects invalid taxkey (DATEV Steuerschlüssel)';
418
419 # taxkey
420 $file = \<<EOL;
421 datatype,customer_id,taxzone_id,currency_id,invnumber,archart
422 datatype,accno,amount,taxkey
423 "Rechnung",960,4,1,"invoice by taxkey",1400
424 "AccTransaction",8400,4,3
425 EOL
426
427 $entries = test_import($file);
428 $entry = $entries->[1];
429 is $entry->{object}->taxkey, 3, 'detects taxkey';
430
431 # acc_trans project
432 $file = \<<EOL;
433 datatype,customer_id,taxzone_id,currency_id,invnumber,archart,taxincluded
434 datatype,accno,amount,taxkey,projectnumber
435 "Rechnung",960,4,1,"invoice with acc_trans project",1400,f
436 "AccTransaction",8400,159.48,3,P1
437 EOL
438
439 $entries = test_import($file);
440 $entry = $entries->[1];
441 # die Dumper($entries->[0]->{errors}) if scalar @{$entries->[0]->{errors}};
442 is $entry->{object}->project->projectnumber, 'P1', 'detects acc_trans project';
443
444 #####  various tests
445 $file = \<<EOL;
446 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart,transdate,duedate,globalprojectnumber,department
447 datatype,accno,amount,taxkey,projectnumber
448 "Rechnung",960,4,1,"invoice various",t,1400,21.04.2016,30.04.2016,P1,Department 1
449 "AccTransaction",8400,119,3,P1
450 "AccTransaction",8300,107,2,P1
451 "AccTransaction",8200,100,0,P1
452 EOL
453
454 $entries = test_import($file);
455 $entry = $entries->[0];
456 $entry->{object}->validate_acc_trans;
457 is $entry->{object}->duedate->to_kivitendo,      '30.04.2016',    'duedate';
458 is $entry->{object}->transdate->to_kivitendo,    '21.04.2016',    'transdate';
459 is $entry->{object}->globalproject->description, 'Project X',     'project';
460 is $entry->{object}->department->description,    'Department 1',  'department';
461 # 8300 is third entry after 8400 and tax for 8400
462 is $::form->round_amount($entry->{object}->transactions->[2]->amount),     '100',        '8300 net amount: 100';
463 is $::form->round_amount($entry->{object}->transactions->[2]->taxkey),     '2',          '8300 has taxkey 2';
464 is $::form->round_amount($entry->{object}->transactions->[2]->project_id), $project->id, 'AccTrans project';
465
466 #####  ar amount test
467 $file = \<<EOL;
468 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart,transdate,duedate,globalprojectnumber,department
469 datatype,accno,amount,taxkey,projectnumber
470 "Rechnung",960,4,1,"invoice various 1",t,1400,21.04.2016,30.04.2016,P1,Department 1
471 "AccTransaction",8400,119,3,P1
472 "AccTransaction",8300,107,2,P1
473 "AccTransaction",8200,100,0,P1
474 "Rechnung",960,4,1,"invoice various 2",t,1400,21.04.2016,30.04.2016,P1,Department 1
475 "AccTransaction",8400,119,3,P1
476 "AccTransaction",8300,107,2,P1
477 "AccTransaction",8200,100,0,P1
478 EOL
479
480 $entries = test_import($file);
481 $entry = $entries->[0];
482 $entry->{object}->validate_acc_trans;
483 is $entry->{object}->duedate->to_kivitendo,      '30.04.2016',    'duedate';
484 is $entry->{info_data}->{amount}, '326', "First invoice amount displayed in info data";
485 is $entries->[4]->{info_data}->{amount}, '326', "Second invoice amount displayed in info data";
486
487 # multiple entries, taxincluded = f
488 $file = \<<EOL;
489 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
490 datatype,accno,amount,taxkey
491 "Rechnung",960,4,1,"invoice 4 acc_trans",f,1400
492 "AccTransaction",8400,39.87,3
493 "AccTransaction",8400,39.87,3
494 "AccTransaction",8400,39.87,3
495 "AccTransaction",8400,39.87,3
496 "Rechnung",960,4,1,"invoice 4 acc_trans 2",f,1400
497 "AccTransaction",8400,39.87,3
498 "AccTransaction",8400,39.87,3
499 "AccTransaction",8400,39.87,3
500 "AccTransaction",8400,39.87,3
501 "Rechnung",960,4,1,"invoice 4 acc_trans 3",f,1400
502 "AccTransaction",8400,39.87,3
503 "AccTransaction",8400,39.87,3
504 "AccTransaction",8400,39.87,3
505 "AccTransaction",8400,39.87,3
506 "Rechnung",960,4,1,"invoice 4 acc_trans 4",f,1448
507 "AccTransaction",8400,39.87,3
508 "AccTransaction",8400,39.87,3
509 "AccTransaction",8400,39.87,3
510 "AccTransaction",8400,39.87,3
511 EOL
512 $entries = test_import($file);
513
514 my $i = 0;
515 foreach my $entry ( @$entries ) {
516   next unless $entry->{object}->isa('SL::DB::Invoice');
517   $i++;
518   is scalar @{$entry->{object}->transactions}, 9, "invoice $i: 'invoice 4 acc_trans' has 9 acc_trans entries";
519   $entry->{object}->validate_acc_trans;
520 };
521
522 ##### missing acc_trans
523 $file = \<<EOL;
524 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart,transdate,duedate,globalprojectnumber,department
525 datatype,accno,amount,taxkey,projectnumber
526 "Rechnung",960,4,1,"invoice acc_trans missing",t,1400,21.04.2016,30.04.2016,P1,Department 1
527 "Rechnung",960,4,1,"invoice various a",t,1400,21.04.2016,30.04.2016,P1,Department 1
528 "AccTransaction",8400,119,3,P1
529 "AccTransaction",8300,107,2,P1
530 EOL
531
532 $entries = test_import($file);
533 $entry = $entries->[0];
534 is $entry->{errors}->[0], "Error: ar transaction doesn't validate", 'detects invalid ar, maybe acc_trans entry missing';
535
536 my $number_of_imported_invoices = SL::DB::Manager::Invoice->get_all_count;
537 is $number_of_imported_invoices, 19, 'All invoices saved';
538
539 #### taxkey differs from active_taxkey
540 $file = \<<EOL;
541 datatype,customer_id,taxzone_id,currency_id,invnumber,taxincluded,archart
542 datatype,accno,amount,taxkey
543 "Rechnung",960,4,1,"invoice 1 tax included no amounts",t,1400
544 "AccTransaction",8400,189.78,2
545 EOL
546
547 $entries = test_import($file);
548 $entry = $entries->[0];
549 $entry->{object}->validate_acc_trans(debug => 0);
550
551 clear_up(); # remove all data at end of tests
552 # end of tests
553
554
555 sub clear_up {
556   SL::DB::Manager::AccTransaction->delete_all(all => 1);
557   SL::DB::Manager::Invoice->delete_all       (all => 1);
558   SL::DB::Manager::Customer->delete_all      (all => 1);
559   SL::DB::Manager::Project->delete_all       (all => 1);
560   SL::DB::Manager::Department->delete_all    (all => 1);
561 };
562
563
564 1;
565
566 #####
567 # vim: ft=perl
568 # set emacs to perl mode
569 # Local Variables:
570 # mode: perl
571 # End: