epic-s6ts
[kivitendo-erp.git] / t / db_helper / price_tax_calculator.t
1 use Test::More;
2
3 use strict;
4
5 use lib 't';
6 use utf8;
7
8 use Carp;
9 use Data::Dumper;
10 use List::MoreUtils qw(uniq);
11 use Support::TestSetup;
12 use Test::Exception;
13 use SL::Dev::ALL qw(:ALL);
14
15 use SL::DB::Buchungsgruppe;
16 use SL::DB::Currency;
17 use SL::DB::Customer;
18 use SL::DB::DeliveryOrder;
19 use SL::DB::Employee;
20 use SL::DB::Invoice;
21 use SL::DB::Order;
22 use SL::DB::Part;
23 use SL::DB::Unit;
24 use SL::DB::TaxZone;
25
26 my ($customer, @parts, $buchungsgruppe, $buchungsgruppe7, $unit, $employee, $tax, $tax7, $taxzone);
27 my ($transdate);
28
29 sub clear_up {
30   SL::DB::Manager::Order->delete_all(all => 1);
31   SL::DB::Manager::DeliveryOrder->delete_all(all => 1);
32   SL::DB::Manager::InvoiceItem->delete_all(all => 1);
33   SL::DB::Manager::Invoice->delete_all(all => 1);
34   SL::DB::Manager::Part->delete_all(all => 1);
35   SL::DB::Manager::Customer->delete_all(all => 1);
36 };
37
38 sub reset_state {
39   my %params = @_;
40
41   $params{$_} ||= {} for qw(buchungsgruppe unit customer part tax);
42
43   clear_up();
44
45   $buchungsgruppe  = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group";
46   $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%')                                || croak "No accounting group for 7\%";
47   $unit            = SL::DB::Manager::Unit->find_by(name => 'kg', %{ $params{unit} })                                      || croak "No unit";
48   $employee        = SL::DB::Manager::Employee->current                                                                    || croak "No employee";
49   $tax             = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, %{ $params{tax} })                           || croak "No tax";
50   $tax7            = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07)                                              || croak "No tax for 7\%";
51   $taxzone         = SL::DB::Manager::TaxZone->find_by( description => 'Inland')                                           || croak "No taxzone";
52
53   $customer     = new_customer(
54     name        => 'Test Customer',
55     taxzone_id  => $taxzone->id,
56     %{ $params{customer} }
57   )->save;
58
59   @parts = ();
60   push @parts, new_part(
61     partnumber         => 'T4254',
62     description        => 'Fourty-two fifty-four',
63     lastcost           => 1.93,
64     sellprice          => 2.34,
65     buchungsgruppen_id => $buchungsgruppe->id,
66     unit               => $unit->name,
67     %{ $params{part1} }
68   )->save;
69
70   push @parts, new_part(
71     partnumber         => 'T0815',
72     description        => 'Zero EIGHT fifteeN @ 7%',
73     lastcost           => 5.473,
74     sellprice          => 9.714,
75     buchungsgruppen_id => $buchungsgruppe7->id,
76     unit               => $unit->name,
77     %{ $params{part2} }
78   )->save;
79
80   push @parts, new_part(
81     partnumber         => 'T888',
82     description        => 'Triple 8',
83     lastcost           => 0,
84     sellprice          => 0.6,
85     buchungsgruppen_id => $buchungsgruppe->id,
86     unit               => $unit->name,
87     %{ $params{part3} }
88   )->save;
89
90 }
91
92 sub new_invoice {
93   my %params  = @_;
94
95   return create_sales_invoice(
96     transdate   => $transdate,
97     taxzone_id  => $taxzone->id,
98     %params,
99   );
100 }
101 sub new_order {
102   my %params  = @_;
103
104   return create_sales_order(
105     transdate   => $transdate,
106     taxzone_id  => $taxzone->id,
107     %params,
108   );
109 }
110
111 sub new_item {
112   my (%params) = @_;
113
114   my $part = delete($params{part}) || $parts[0];
115
116   return create_invoice_item(
117     part => $part,
118     %params,
119   );
120 }
121 sub new_order_item {
122   my (%params) = @_;
123
124   my $part = delete($params{part}) || $parts[0];
125
126   return create_order_item(
127     part => $part,
128     %params,
129   );
130 }
131
132 sub test_default_invoice_one_item_19_tax_not_included() {
133   reset_state();
134
135   my $item = new_item(qty => 2.5);
136   my $invoice = new_invoice(
137     taxincluded  => 0,
138     invoiceitems => [ $item ],
139   );
140
141   my $taxkey = $item->part->get_taxkey(date => $transdate, is_sales => 1, taxzone => $invoice->taxzone_id);
142
143   # sellprice 2.34 * qty 2.5 = 5.85
144   # 19%(5.85) = 1.1115; rounded = 1.11
145   # total rounded = 6.96
146
147   # lastcost 1.93 * qty 2.5 = 4.825; rounded 4.83
148   # line marge_total = 1.02
149   # line marge_percent = 17.4358974358974
150
151   my $title = 'default invoice, one item, 19% tax not included';
152   my %data  = $invoice->calculate_prices_and_taxes;
153
154   is($item->marge_total,        1.02,             "${title}: item marge_total");
155   is($item->marge_percent,      17.4358974358974, "${title}: item marge_percent");
156   is($item->marge_price_factor, 1,                "${title}: item marge_price_factor");
157
158   is($invoice->netamount,       5.85,             "${title}: netamount");
159   is($invoice->amount,          6.96,             "${title}: amount");
160   is($invoice->marge_total,     1.02,             "${title}: marge_total");
161   is($invoice->marge_percent,   17.4358974358974, "${title}: marge_percent");
162
163   is_deeply(\%data, {
164     allocated                                    => {},
165     amounts                                      => {
166       $buchungsgruppe->income_accno_id($taxzone) => {
167         amount                                   => 5.85,
168         tax_id                                   => $tax->id,
169         taxkey                                   => 3,
170       },
171     },
172     amounts_cogs                                 => {},
173     assembly_items                               => [
174       [],
175     ],
176     exchangerate                                 => 1,
177     taxes_by_chart_id                            => {
178       $tax->chart_id                             => 1.11,
179     },
180     taxes_by_tax_id                              => {
181       $tax->id                                   => 1.1115,
182     },
183     items                                        => [
184       { linetotal                                => 5.85,
185         linetotal_cost                           => 4.83,
186         sellprice                                => 2.34,
187         tax_amount                               => 1.1115,
188         taxkey_id                                => $taxkey->id,
189       },
190     ],
191     rounding                                    =>  0,
192   }, "${title}: calculated data");
193 }
194
195 sub test_default_invoice_two_items_19_7_tax_not_included() {
196   reset_state();
197
198   my $item1   = new_item(qty => 2.5);
199   my $item2   = new_item(qty => 1.2, part => $parts[1]);
200   my $invoice = new_invoice(
201     taxincluded  => 0,
202     invoiceitems => [ $item1, $item2 ],
203   );
204
205   my $taxkey1 = $item1->part->get_taxkey(date => $transdate, is_sales => 1, taxzone => $invoice->taxzone_id);
206   my $taxkey2 = $item2->part->get_taxkey(date => $transdate, is_sales => 1, taxzone => $invoice->taxzone_id);
207
208   # item 1:
209   # sellprice 2.34 * qty 2.5 = 5.85
210   # 19%(5.85) = 1.1115; rounded = 1.11
211   # total rounded = 6.96
212
213   # lastcost 1.93 * qty 2.5 = 4.825; rounded 4.83
214   # line marge_total = 1.02
215   # line marge_percent = 17.4358974358974
216
217   # item 2:
218   # sellprice 9.714 * qty 1.2 = 11.6568 rounded 11.66
219   # 7%(11.6568) = 0.815976; rounded = 0.82
220   # 7%(11.66)   = 0.8162
221   # total rounded = 12.48
222
223   # lastcost 5.473 * qty 1.2 = 6.5676; rounded 6.57
224   # line marge_total = 5.09
225   # line marge_percent = 43.6535162950257
226
227   my $title = 'default invoice, two item, 19/7% tax not included';
228   my %data  = $invoice->calculate_prices_and_taxes;
229
230   is($item1->marge_total,        1.02,             "${title}: item1 marge_total");
231   is($item1->marge_percent,      17.4358974358974, "${title}: item1 marge_percent");
232   is($item1->marge_price_factor, 1,                "${title}: item1 marge_price_factor");
233
234   is($item2->marge_total,        5.09,             "${title}: item2 marge_total");
235   is($item2->marge_percent,      43.6535162950257, "${title}: item2 marge_percent");
236   is($item2->marge_price_factor, 1,                "${title}: item2 marge_price_factor");
237
238   is($invoice->netamount,        5.85 + 11.66,     "${title}: netamount");
239   is($invoice->amount,           6.96 + 12.48,     "${title}: amount");
240   is($invoice->marge_total,      1.02 + 5.09,      "${title}: marge_total");
241   is($invoice->marge_percent,    34.8943460879497, "${title}: marge_percent");
242
243   is_deeply(\%data, {
244     allocated                                     => {},
245     amounts                                       => {
246       $buchungsgruppe->income_accno_id($taxzone)  => {
247         amount                                    => 5.85,
248         tax_id                                    => $tax->id,
249         taxkey                                    => 3,
250       },
251       $buchungsgruppe7->income_accno_id($taxzone) => {
252         amount                                    => 11.66,
253         tax_id                                    => $tax7->id,
254         taxkey                                    => 2,
255       },
256     },
257     amounts_cogs                                  => {},
258     assembly_items                                => [
259       [], [],
260     ],
261     exchangerate                                  => 1,
262     taxes_by_chart_id                             => {
263       $tax->chart_id                              => 1.11,
264       $tax7->chart_id                             => 0.82,
265     },
266     taxes_by_tax_id                               => {
267       $tax->id                                    => 1.1115,
268       $tax7->id                                   => 0.8162,
269     },
270     items                                        => [
271       { linetotal                                => 5.85,
272         linetotal_cost                           => 4.83,
273         sellprice                                => 2.34,
274         tax_amount                               => 1.1115,
275         taxkey_id                                => $taxkey1->id,
276       },
277       { linetotal                                => 11.66,
278         linetotal_cost                           => 6.57,
279         sellprice                                => 9.714,
280         tax_amount                               => 0.8162,
281         taxkey_id                                => $taxkey2->id,
282       },
283     ],
284     rounding                                    =>  0,
285   }, "${title}: calculated data");
286 }
287
288 sub test_default_invoice_three_items_sellprice_rounding_discount() {
289   reset_state();
290
291   my $item1   = new_item(qty => 1, sellprice => 5.55, discount => .05);
292   my $item2   = new_item(qty => 1, sellprice => 5.50, discount => .05);
293   my $item3   = new_item(qty => 1, sellprice => 5.00, discount => .05);
294   my $invoice = new_invoice(
295     taxincluded  => 0,
296     invoiceitems => [ $item1, $item2, $item3 ],
297   );
298
299   my %taxkeys = map { ($_->id => $_->get_taxkey(date => $transdate, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item1, $item2, $item3);
300
301   # item 1:
302   # discount = sellprice 5.55 * discount (0.05) = 0.2775; rounded 0.28
303   # linetotal = sellprice 5.55 * (1 - discount 0.05) * qty 1 = 5.2725; rounded 5.27
304   # 19%(5.27) = 1.0013; rounded = 1.00
305   # total rounded = 6.27
306
307   # lastcost 1.93 * qty 1 = 1.93; rounded 1.93
308   # line marge_total = 5.27 - 1.93 = 3.34
309   # line marge_percent = 63.3776091081594
310
311   # item 2:
312   # discount = sellprice 5.50 * discount 0.05 = 0.275; rounded 0.28
313   # linetotal = sellprice 5.50 * (1 - discount 0.05) * qty 1 = 5.225; rounded 5.23
314   # 19%(5.23) = .99370; rounded = 0.99
315   # total rounded = 6.22
316
317   # lastcost 1.93 * qty 1 = 1.93; rounded 1.93
318   # line marge_total = 5.23 - 1.93 = 3.30
319   # line marge_percent = 3.30/5.23 = 0.630975143403442
320
321   # item 3:
322   # discount = sellprice 5.00 * discount 0.05 = 0.05 = 0.25; rounded 0.25
323   # linetotal = sellprice 5.00 (1 - discount 0.05) * qty 1 = 4.75; rounded 4.75
324   # 19%(4.75) = 0.9025; rounded = 0.90
325   # total rounded = 5.65
326
327   # lastcost 1.93 * qty 1 = 1.93; rounded 1.93
328   # line marge_total = 4.75 - 1.93 = 2.82
329   # line marge_percent = 2.82/4.75 = 59.3684210526316
330
331   my $title = 'default invoice, three items, sellprice, rounding, discount';
332   my %data  = $invoice->calculate_prices_and_taxes;
333
334   is($item1->marge_total,        3.34,               "${title}: item1 marge_total");
335   is($item1->marge_percent,      63.3776091081594,   "${title}: item1 marge_percent");
336   is($item1->marge_price_factor, 1,                  "${title}: item1 marge_price_factor");
337
338   is($item2->marge_total,        3.30,               "${title}: item2 marge_total");
339   is($item2->marge_percent,      63.0975143403442,   "${title}: item2 marge_percent");
340   is($item2->marge_price_factor, 1,                  "${title}: item2 marge_price_factor");
341
342   is($item3->marge_total,        2.82,               "${title}: item3 marge_total");
343   is($item3->marge_percent,      59.3684210526316,   "${title}: item3 marge_percent");
344   is($item3->marge_price_factor, 1,                  "${title}: item3 marge_price_factor");
345
346   is($invoice->netamount,        5.27 + 5.23 + 4.75, "${title}: netamount");
347
348   # 6.27 + 6.22 + 5.65 = 18.14
349   # 1.19*(5.27 + 5.23 + 4.75) = 18.1475; rounded 18.15
350   #is($invoice->amount,           6.27 + 6.22 + 5.65, "${title}: amount");
351   is($invoice->amount,           18.15,              "${title}: amount");
352
353   is($invoice->marge_total,      3.34 + 3.30 + 2.82, "${title}: marge_total");
354   is($invoice->marge_percent,    62.0327868852459,   "${title}: marge_percent");
355
356   is_deeply(\%data, {
357     allocated                                    => {},
358     amounts                                      => {
359       $buchungsgruppe->income_accno_id($taxzone) => {
360         amount                                   => 15.25,
361         tax_id                                   => $tax->id,
362         taxkey                                   => 3,
363       },
364     },
365     amounts_cogs                                 => {},
366     assembly_items                               => [
367       [], [], [],
368     ],
369     exchangerate                                 => 1,
370     taxes_by_chart_id                            => {
371       $tax->chart_id                             => 2.9,
372     },
373     taxes_by_tax_id                              => {
374       $tax->id                                   => 2.89750,
375     },
376     items                                        => [
377       { linetotal                                => 5.27,
378         linetotal_cost                           => 1.93,
379         sellprice                                => 5.27,
380         tax_amount                               => 1.0013,
381         taxkey_id                                => $taxkeys{$item1->parts_id}->id,
382       },
383       { linetotal                                => 5.23,
384         linetotal_cost                           => 1.93,
385         sellprice                                => 5.23,
386         tax_amount                               => 0.9937,
387         taxkey_id                                => $taxkeys{$item2->parts_id}->id,
388       },
389       { linetotal                                => 4.75,
390         linetotal_cost                           => 1.93,
391         sellprice                                => 4.75,
392         tax_amount                               => 0.9025,
393         taxkey_id                                => $taxkeys{$item3->parts_id}->id,
394       }
395     ],
396     rounding                                    =>  0,
397   }, "${title}: calculated data");
398 }
399
400 sub test_default_invoice_one_item_19_tax_not_included_rounding_discount() {
401   reset_state();
402
403   my $item   = new_item(qty => 6, part => $parts[2], discount => 0.03);
404   my $invoice = new_invoice(
405     taxincluded  => 0,
406     invoiceitems => [ $item ],
407   );
408
409   my %taxkeys = map { ($_->id => $_->get_taxkey(date => $transdate, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item);
410
411   # 6 parts for 0.60 with 3% discount
412   #
413   # linetotal = sellprice 0.60 * qty 6 * discount (1 - 0.03) = 3.492 rounded 3.49
414   # total = 3.49 + 0.66 = 4.15
415   #
416
417   my $title = 'default invoice, one item, sellprice, rounding, discount';
418   my %data  = $invoice->calculate_prices_and_taxes;
419
420   is($invoice->netamount,         3.49,              "${title}: netamount");
421
422   is($invoice->amount,            4.15,              "${title}: amount");
423
424   is($invoice->marge_total,       3.49,              "${title}: marge_total");
425   is($invoice->marge_percent,      100,              "${title}: marge_percent");
426
427   is_deeply(\%data, {
428     allocated                                    => {},
429     amounts                                      => {
430       $buchungsgruppe->income_accno_id($taxzone) => {
431         amount                                   => 3.49,
432         tax_id                                   => $tax->id,
433         taxkey                                   => 3,
434       },
435     },
436     amounts_cogs                                 => {},
437     assembly_items                               => [
438       [],
439     ],
440     exchangerate                                 => 1,
441     taxes_by_chart_id                            => {
442       $tax->chart_id                             => 0.66,
443     },
444     taxes_by_tax_id                              => {
445       $tax->id                                   => 0.66310,
446     },
447     items                                        => [
448       { linetotal                                => 3.49,
449         linetotal_cost                           => 0,
450         sellprice                                => 0.58,
451         tax_amount                               => 0.6631,
452         taxkey_id                                => $taxkeys{$item->parts_id}->id,
453       },
454     ],
455     rounding                                     =>  0,
456   }, "${title}: calculated data");
457 }
458
459 sub test_default_invoice_one_item_19_tax_not_included_rounding_discount_huge_qty() {
460   reset_state();
461
462   my $item   = new_item(qty => 100000, part => $parts[2], discount => 0.03, sellprice => 0.10);
463   my $invoice = new_invoice(
464     taxincluded  => 0,
465     invoiceitems => [ $item ],
466   );
467
468   my %taxkeys = map { ($_->id => $_->get_taxkey(date => $transdate, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item);
469
470   my $title = 'default invoice, one item, 19% tax not included, rounding, discount, huge qty';
471   my %data  = $invoice->calculate_prices_and_taxes;
472
473   is($invoice->netamount,         9700,              "${title}: netamount");
474
475   is($invoice->amount,           11543,              "${title}: amount");
476
477   is($invoice->marge_total,       9700,              "${title}: marge_total");
478   is($invoice->marge_percent,      100,              "${title}: marge_percent");
479
480   is_deeply(\%data, {
481     allocated                                    => {},
482     amounts                                      => {
483       $buchungsgruppe->income_accno_id($taxzone) => {
484         amount                                   => 9700,
485         tax_id                                   => $tax->id,
486         taxkey                                   => 3,
487       },
488     },
489     amounts_cogs                                 => {},
490     assembly_items                               => [
491       [],
492     ],
493     exchangerate                                 => 1,
494     taxes_by_chart_id                            => {
495       $tax->chart_id                             => 1843,
496     },
497     taxes_by_tax_id                              => {
498       $tax->id                                   => 1843,
499     },
500     items                                        => [
501       { linetotal                                => 9700,
502         linetotal_cost                           => 0,
503         sellprice                                => 0.1,
504         tax_amount                               => 1843,
505         taxkey_id                                => $taxkeys{$item->parts_id}->id,
506       },
507     ],
508     rounding                                    =>  0,
509   }, "${title}: calculated data");
510 }
511
512 sub test_default_invoice_one_item_19_tax_not_included_rounding_discount_big_qty_low_sellprice() {
513   reset_state();
514
515   my $item   = new_item(qty => 10001, sellprice => 0.007, discount => 0.035);
516   my $invoice = new_invoice(
517     taxincluded  => 0,
518     invoiceitems => [ $item ],
519   );
520
521   my %taxkeys = map { ($_->id => $_->get_taxkey(date => $transdate, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item);
522
523   # item 1:
524   # discount = sellprice 0.007 * discount (0.035) = 0.000245; rounded 0.00
525   # sellprice = sellprice 0.007 - discount 0.00 = 0.007
526   # linetotal = sellprice 0.007 * qty 10001 * (1 - 0.035) = 67.556755; rounded 67.56
527   # 19%(67.56) = 12.8364; rounded = 12.84
528   # total rounded = 80.40
529
530   # lastcost 1.93 * qty 10001 = 19301.93; rounded 19301.93
531   # line marge_total = 67.56-19301.93 = -19234.37
532   # line marge_percent = 100*-19234.37/67.56 = -28470.0562462996
533
534   my $title = 'default invoice one item 19 tax not included rounding discount big qty low sellprice';
535   my %data  = $invoice->calculate_prices_and_taxes;
536
537   is($invoice->netamount,                 67.56,    "${title}: netamount");
538
539   is($invoice->amount,                    80.40,    "${title}: amount");
540
541   is($invoice->marge_total,           -19234.37,    "${title}: marge_total");
542   is($invoice->marge_percent, -28470.0562462996,    "${title}: marge_percent");
543
544   is_deeply(\%data, {
545     allocated                                    => {},
546     amounts                                      => {
547       $buchungsgruppe->income_accno_id($taxzone) => {
548         amount                                   => 67.56,
549         tax_id                                   => $tax->id,
550         taxkey                                   => 3,
551       },
552     },
553     amounts_cogs                                 => {},
554     assembly_items                               => [
555       [],
556     ],
557     exchangerate                                 => 1,
558     taxes_by_chart_id                            => {
559       $tax->chart_id                             => 12.84,
560     },
561     taxes_by_tax_id                              => {
562       $tax->id                                   => 12.8364,
563     },
564     items                                        => [
565       { linetotal                                => 67.56,
566         linetotal_cost                           => 19301.93,
567         sellprice                                => 0.007,
568         tax_amount                               => 12.8364,
569         taxkey_id                                => $taxkeys{$item->parts_id}->id,
570       },
571     ],
572     rounding                                    =>  0,
573   }, "${title}: calculated data");
574 }
575 sub test_default_order_two_items_19_one_optional() {
576   reset_state();
577
578   my $item          = new_order_item(qty => 2.5);
579   my $item_optional = new_order_item(qty => 2.5, optional => 1);
580
581   my $order = new_order(
582     taxincluded  => 0,
583     orderitems => [ $item, $item_optional ],
584   );
585
586   my $taxkey = $item->part->get_taxkey(date => $transdate, is_sales => 1, taxzone => $order->taxzone_id);
587
588   # sellprice 2.34 * qty 2.5 = 5.85
589   # 19%(5.85) = 1.1115; rounded = 1.11
590   # total rounded = 6.96
591
592   # lastcost 1.93 * qty 2.5 = 4.825; rounded 4.83
593   # line marge_total = 1.02
594   # line marge_percent = 17.4358974358974
595
596   my $title = 'default order, two item, one item optional, 19% tax not included';
597   my %data  = $order->calculate_prices_and_taxes;
598
599   is($item->marge_total,        1.02,             "${title}: item marge_total");
600   is($item->marge_percent,      17.4358974358974, "${title}: item marge_percent");
601   is($item->marge_price_factor, 1,                "${title}: item marge_price_factor");
602
603   # optional items have a linetotal and marge, but ...
604   is($item_optional->marge_total,        1.02,             "${title}: item optional marge_total");
605   is($item_optional->marge_percent,      17.4358974358974, "${title}: item optional marge_percent");
606   is($item_optional->marge_price_factor, 1,                "${title}: item optional marge_price_factor");
607
608   # ... should not be calculated for the record sum
609   is($order->netamount,       5.85,             "${title}: netamount");
610   is($order->amount,          6.96,             "${title}: amount");
611   is($order->marge_total,     1.02,             "${title}: marge_total");
612   is($order->marge_percent,   17.4358974358974, "${title}: marge_percent");
613   is($order->orderitems->[1]->optional, 1,      "${title}: second order item has attribute optional");
614   # diag explain $order->orderitems->[1]->optional;
615   # diag explain \%data;
616   is_deeply(\%data, {
617     allocated                                    => {},
618     amounts                                      => {
619       $buchungsgruppe->income_accno_id($taxzone) => {
620         amount                                   => 5.85,
621         tax_id                                   => $tax->id,
622         taxkey                                   => 3,
623       },
624     },
625     amounts_cogs                                 => {},
626     assembly_items                               => [
627       [],
628       [],
629     ],
630     exchangerate                                 => 1,
631     taxes_by_chart_id                            => {
632       $tax->chart_id                             => 1.11,
633     },
634     taxes_by_tax_id                              => {
635       $tax->id                                   => 1.1115,
636     },
637     items                                        => [
638       { linetotal                                => 5.85,
639         linetotal_cost                           => 4.83,
640         sellprice                                => 2.34,
641         tax_amount                               => 1.1115,
642         taxkey_id                                => $taxkey->id,
643       },
644       { linetotal                                => 5.85,
645         linetotal_cost                           => 4.83,
646         sellprice                                => 2.34,
647         tax_amount                               => 1.1115,
648         taxkey_id                                => $taxkey->id,
649       },
650     ],
651     rounding                                    =>  0,
652   }, "${title}: calculated data");
653 }
654
655
656 Support::TestSetup::login();
657
658 $transdate = DateTime->today_local;
659 $transdate->set_year(2019) if $transdate->year == 2020; # use year 2019 in 2020, because of tax rate change in Germany
660
661 test_default_invoice_one_item_19_tax_not_included();
662 test_default_invoice_two_items_19_7_tax_not_included();
663 test_default_invoice_three_items_sellprice_rounding_discount();
664 test_default_invoice_one_item_19_tax_not_included_rounding_discount();
665 test_default_invoice_one_item_19_tax_not_included_rounding_discount_huge_qty();
666 test_default_invoice_one_item_19_tax_not_included_rounding_discount_big_qty_low_sellprice();
667 test_default_order_two_items_19_one_optional();
668
669 clear_up();
670 done_testing();
671
672 # vim: ft=perl
673 # set emacs to perl mode
674 # Local Variables:
675 # mode: perl
676 # End: