687a646360edde6af80454249844256c819d6f81
[kivitendo-erp.git] / t / bank / bank_transactions.t
1 use Test::More tests => 100;
2
3 use strict;
4
5 use lib 't';
6 use utf8;
7
8 use Carp;
9 use Support::TestSetup;
10 use Test::Exception;
11 use List::Util qw(sum);
12
13 use SL::DB::Buchungsgruppe;
14 use SL::DB::Currency;
15 use SL::DB::Customer;
16 use SL::DB::Vendor;
17 use SL::DB::Invoice;
18 use SL::DB::Unit;
19 use SL::DB::Part;
20 use SL::DB::TaxZone;
21 use SL::DB::BankAccount;
22 use SL::DB::PaymentTerm;
23 use SL::DB::PurchaseInvoice;
24 use SL::DB::BankTransaction;
25 use SL::Controller::BankTransaction;
26 use SL::Dev::ALL;
27 use Data::Dumper;
28
29 my ($customer, $vendor, $currency_id, $unit, $tax, $tax7, $tax_9, $payment_terms, $bank_account);
30 my ($transdate1, $transdate2, $currency);
31 my ($ar_chart,$bank,$ar_amount_chart, $ap_chart, $ap_amount_chart);
32 my ($ar_transaction, $ap_transaction);
33
34 sub clear_up {
35
36   SL::DB::Manager::BankTransaction->delete_all(all => 1);
37   SL::DB::Manager::InvoiceItem->delete_all(all => 1);
38   SL::DB::Manager::InvoiceItem->delete_all(all => 1);
39   SL::DB::Manager::Invoice->delete_all(all => 1);
40   SL::DB::Manager::PurchaseInvoice->delete_all(all => 1);
41   SL::DB::Manager::Part->delete_all(all => 1);
42   SL::DB::Manager::Customer->delete_all(all => 1);
43   SL::DB::Manager::Vendor->delete_all(all => 1);
44   SL::DB::Manager::BankAccount->delete_all(all => 1);
45   SL::DB::Manager::PaymentTerm->delete_all(all => 1);
46   SL::DB::Manager::Currency->delete_all(where => [ name => 'CUR' ]);
47 };
48
49 sub save_btcontroller_to_string {
50   my $output;
51   open(my $outputFH, '>', \$output) or die;
52   my $oldFH = select $outputFH;
53
54   my $bt_controller = SL::Controller::BankTransaction->new;
55   $bt_controller->action_save_invoices;
56
57   select $oldFH;
58   close $outputFH;
59   return $output;
60 }
61
62 # starting test:
63 Support::TestSetup::login();
64
65 clear_up();
66 reset_state(); # initialise customers/vendors/bank/currency/...
67
68 test1();
69
70 test_overpayment_with_partialpayment();
71 test_overpayment();
72 test_skonto_exact();
73 test_two_invoices();
74 test_partial_payment();
75 test_credit_note();
76 test_ap_transaction();
77 test_neg_ap_transaction();
78 test_ap_payment_transaction();
79 test_ap_payment_part_transaction();
80
81 # remove all created data at end of test
82 clear_up();
83
84 done_testing();
85
86 ###### functions for setting up data
87
88 sub reset_state {
89   my %params = @_;
90
91   $params{$_} ||= {} for qw(unit customer tax vendor);
92
93   clear_up();
94
95   $transdate1 = DateTime->today;
96   $transdate2 = DateTime->today->add(days => 5);
97
98   $tax             = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, %{ $params{tax} }) || croak "No tax";
99   $tax7            = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07)                    || croak "No tax for 7\%";
100   $tax_9           = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, %{ $params{tax} }) || croak "No tax";
101
102   $currency_id     = $::instance_conf->get_currency_id;
103
104   $bank_account     =  SL::DB::BankAccount->new(
105     account_number  => '123',
106     bank_code       => '123',
107     iban            => '123',
108     bic             => '123',
109     bank            => '123',
110     chart_id        => SL::DB::Manager::Chart->find_by(description => 'Bank')->id,
111     name            => SL::DB::Manager::Chart->find_by(description => 'Bank')->description,
112   )->save;
113
114   $customer = SL::Dev::CustomerVendor::create_customer(
115     name                      => 'Test Customer',
116     iban                      => 'DE12500105170648489890',
117     bic                       => 'TESTBIC',
118     account_number            => '648489890',
119     mandate_date_of_signature => $transdate1,
120     mandator_id               => 'foobar',
121     bank                      => 'Geizkasse',
122     bank_code                 => 'G1235',
123     depositor                 => 'Test Customer',
124     customernumber            => 'CUST1704',
125   )->save;
126
127   $payment_terms = SL::Dev::Payment::create_payment_terms;
128
129   $vendor = SL::Dev::CustomerVendor::create_vendor(
130     name           => 'Test Vendor',
131     payment_id     => $payment_terms->id,
132     iban           => 'DE12500105170648489890',
133     bic            => 'TESTBIC',
134     account_number => '648489890',
135     bank           => 'Geizkasse',
136     bank_code      => 'G1235',
137     depositor      => 'Test Vendor',
138     vendornumber   => 'VEND1704',
139   )->save;
140
141   $ar_chart        = SL::DB::Manager::Chart->find_by( accno => '1400' ); # Forderungen
142   $ap_chart        = SL::DB::Manager::Chart->find_by( accno => '1600' ); # Verbindlichkeiten
143   $bank            = SL::DB::Manager::Chart->find_by( accno => '1200' ); # Bank
144   $ar_amount_chart = SL::DB::Manager::Chart->find_by( accno => '8400' ); # Erlöse
145   $ap_amount_chart = SL::DB::Manager::Chart->find_by( accno => '3400' ); # Wareneingang 19%
146
147 }
148
149 sub test_ar_transaction {
150   my (%params) = @_;
151   my $netamount = 100;
152   my $amount    = $params{amount} || $::form->round_amount(100 * 1.19,2);
153   my $invoice   = SL::DB::Invoice->new(
154       invoice      => 0,
155       invnumber    => $params{invnumber} || undef, # let it use its own invnumber
156       amount       => $amount,
157       netamount    => $netamount,
158       transdate    => $transdate1,
159       taxincluded  => 0,
160       customer_id  => $customer->id,
161       taxzone_id   => $customer->taxzone_id,
162       currency_id  => $currency_id,
163       transactions => [],
164       payment_id   => $params{payment_id} || undef,
165       notes        => 'test_ar_transaction',
166   );
167   $invoice->add_ar_amount_row(
168     amount => $invoice->netamount,
169     chart  => $ar_amount_chart,
170     tax_id => $tax->id,
171   );
172
173   $invoice->create_ar_row(chart => $ar_chart);
174   $invoice->save;
175
176   is($invoice->currency_id , $currency_id , 'currency_id has been saved');
177   is($invoice->netamount   , 100          , 'ar amount has been converted');
178   is($invoice->amount      , 119          , 'ar amount has been converted');
179   is($invoice->taxincluded , 0            , 'ar transaction doesn\'t have taxincluded');
180
181   is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_amount_chart->id , trans_id => $invoice->id)->amount , '100.00000'  , $ar_amount_chart->accno . ': has been converted for currency');
182   is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id        , trans_id => $invoice->id)->amount , '-119.00000' , $ar_chart->accno . ': has been converted for currency');
183
184   return $invoice;
185 };
186
187 sub test_ap_transaction {
188   my (%params) = @_;
189   my $testname = 'test_ap_transaction';
190
191   my $netamount = 100;
192   my $amount    = $::form->round_amount($netamount * 1.19,2);
193   my $invoice   = SL::DB::PurchaseInvoice->new(
194     invoice      => 0,
195     invnumber    => $params{invnumber} || $testname,
196     amount       => $amount,
197     netamount    => $netamount,
198     transdate    => $transdate1,
199     taxincluded  => 0,
200     vendor_id    => $vendor->id,
201     taxzone_id   => $vendor->taxzone_id,
202     currency_id  => $currency_id,
203     transactions => [],
204     notes        => 'test_ap_transaction',
205   );
206   $invoice->add_ap_amount_row(
207     amount     => $invoice->netamount,
208     chart      => $ap_amount_chart,
209     tax_id     => $tax_9->id,
210   );
211
212   $invoice->create_ap_row(chart => $ap_chart);
213   $invoice->save;
214
215   is($invoice->currency_id , $currency_id , "$testname: currency_id has been saved");
216   is($invoice->netamount   , 100          , "$testname: ap amount has been converted");
217   is($invoice->amount      , 119          , "$testname: ap amount has been converted");
218   is($invoice->taxincluded , 0            , "$testname: ap transaction doesn\'t have taxincluded");
219
220   is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_amount_chart->id , trans_id => $invoice->id)->amount , '-100.00000' , $ap_amount_chart->accno . ': has been converted for currency');
221   is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_chart->id        , trans_id => $invoice->id)->amount , '119.00000'  , $ap_chart->accno . ': has been converted for currency');
222
223   return $invoice;
224 };
225
226 ###### test cases
227
228 sub test1 {
229
230   my $testname = 'test1';
231
232   $ar_transaction = test_ar_transaction(invnumber => 'salesinv1');
233
234   my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction";
235
236   $::form->{invoice_ids} = {
237     $bt->id => [ $ar_transaction->id ]
238   };
239
240   save_btcontroller_to_string();
241
242   $ar_transaction->load;
243   $bt->load;
244   is($ar_transaction->paid   , '119.00000' , "$testname: salesinv1 was paid");
245   is($ar_transaction->closed , 1           , "$testname: salesinv1 is closed");
246   is($bt->invoice_amount     , '119.00000' , "$testname: bt invoice amount was assigned");
247
248 };
249
250 sub test_skonto_exact {
251
252   my $testname = 'test_skonto_exact';
253
254   $ar_transaction = test_ar_transaction(invnumber => 'salesinv skonto',
255                                         payment_id => $payment_terms->id,
256                                        );
257
258   my $bt = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
259                                                      bank_chart_id => $bank->id,
260                                                      amount        => $ar_transaction->amount_less_skonto
261                                                     ) or die "Couldn't create bank_transaction";
262
263   $::form->{invoice_ids} = {
264     $bt->id => [ $ar_transaction->id ]
265   };
266   $::form->{invoice_skontos} = {
267     $bt->id => [ 'with_skonto_pt' ]
268   };
269
270   save_btcontroller_to_string();
271
272   $ar_transaction->load;
273   $bt->load;
274   is($ar_transaction->paid   , '119.00000' , "$testname: salesinv skonto was paid");
275   is($ar_transaction->closed , 1           , "$testname: salesinv skonto is closed");
276   is($bt->invoice_amount     , '113.05000' , "$testname: bt invoice amount was assigned");
277
278 };
279
280 sub test_two_invoices {
281
282   my $testname = 'test_two_invoices';
283
284   my $ar_transaction_1 = test_ar_transaction(invnumber => 'salesinv_1');
285   my $ar_transaction_2 = test_ar_transaction(invnumber => 'salesinv_2');
286
287   my $bt = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction_1,
288                                                      amount        => ($ar_transaction_1->amount + $ar_transaction_2->amount),
289                                                      purpose       => "Rechnungen " . $ar_transaction_1->invnumber . " und " . $ar_transaction_2->invnumber,
290                                                      bank_chart_id => $bank->id,
291                                                     ) or die "Couldn't create bank_transaction";
292
293   my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($ar_transaction_1);
294   is($agreement, 16, "points for ar_transaction_1 in test_two_invoices ok");
295
296   $::form->{invoice_ids} = {
297     $bt->id => [ $ar_transaction_1->id, $ar_transaction_2->id ]
298   };
299
300   save_btcontroller_to_string();
301
302   $ar_transaction_1->load;
303   $ar_transaction_2->load;
304   $bt->load;
305
306   is($ar_transaction_1->paid   , '119.00000' , "$testname: salesinv_1 was paid");
307   is($ar_transaction_1->closed , 1           , "$testname: salesinv_1 is closed");
308   is($ar_transaction_2->paid   , '119.00000' , "$testname: salesinv_2 was paid");
309   is($ar_transaction_2->closed , 1           , "$testname: salesinv_2 is closed");
310   is($bt->invoice_amount       , '238.00000' , "$testname: bt invoice amount was assigned");
311
312 };
313
314 sub test_overpayment {
315
316   my $testname = 'test_overpayment';
317
318   $ar_transaction = test_ar_transaction(invnumber => 'salesinv overpaid');
319
320   # amount 135 > 119
321   my $bt = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
322                                                      bank_chart_id => $bank->id,
323                                                      amount        => 135
324                                                     ) or die "Couldn't create bank_transaction";
325
326   $::form->{invoice_ids} = {
327     $bt->id => [ $ar_transaction->id ]
328   };
329
330   save_btcontroller_to_string();
331
332   $ar_transaction->load;
333   $bt->load;
334
335   is($ar_transaction->paid                     , '135.00000' , "$testname: 'salesinv overpaid' was overpaid");
336   is($bt->invoice_amount                       , '135.00000' , "$testname: bt invoice amount was assigned overpaid amount");
337 { local $TODO = 'this currently fails because closed ignores over-payments, see commit d90966c7';
338   is($ar_transaction->closed                   , 0           , "$testname: 'salesinv overpaid' is open (via 'closed' method')");
339 }
340   is($ar_transaction->open_amount == 0 ? 1 : 0 , 0           , "$testname: 'salesinv overpaid is open (via amount-paid)");
341
342 };
343
344 sub test_overpayment_with_partialpayment {
345
346   # two payments on different days, 10 and 119. If there is only one invoice we want it be overpaid.
347   my $testname = 'test_overpayment_with_partialpayment';
348
349   $ar_transaction = test_ar_transaction(invnumber => 'salesinv overpaid partial');
350
351   my $bt_1 = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
352                                                        bank_chart_id => $bank->id,
353                                                        amount        =>  10
354                                                       ) or die "Couldn't create bank_transaction";
355   my $bt_2 = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
356                                                        amount        => 119,
357                                                        transdate     => DateTime->today->add(days => 5),
358                                                        bank_chart_id => $bank->id,
359                                                       ) or die "Couldn't create bank_transaction";
360
361   $::form->{invoice_ids} = {
362     $bt_1->id => [ $ar_transaction->id ]
363   };
364   save_btcontroller_to_string();
365
366   $::form->{invoice_ids} = {
367     $bt_2->id => [ $ar_transaction->id ]
368   };
369   save_btcontroller_to_string();
370
371   $ar_transaction->load;
372   $bt_1->load;
373   $bt_2->load;
374
375   is($ar_transaction->paid , '129.00000' , "$testname: 'salesinv overpaid partial' was overpaid");
376   is($bt_1->invoice_amount ,  '10.00000' , "$testname: bt_1 invoice amount was assigned overpaid amount");
377   is($bt_2->invoice_amount , '119.00000' , "$testname: bt_2 invoice amount was assigned overpaid amount");
378
379 };
380
381 sub test_partial_payment {
382
383   my $testname = 'test_partial_payment';
384
385   $ar_transaction = test_ar_transaction(invnumber => 'salesinv partial payment');
386
387   # amount 100 < 119
388   my $bt = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
389                                                      bank_chart_id => $bank->id,
390                                                      amount        => 100
391                                                     ) or die "Couldn't create bank_transaction";
392
393   $::form->{invoice_ids} = {
394     $bt->id => [ $ar_transaction->id ]
395   };
396
397   save_btcontroller_to_string();
398
399   $ar_transaction->load;
400   $bt->load;
401
402   is($ar_transaction->paid , '100.00000' , "$testname: 'salesinv partial payment' was partially paid");
403   is($bt->invoice_amount   , '100.00000' , "$testname: bt invoice amount was assigned partially paid amount");
404
405 };
406
407 sub test_credit_note {
408
409   my $testname = 'test_credit_note';
410
411   my $part1 = SL::Dev::Part::create_part(   partnumber => 'T4254')->save;
412   my $part2 = SL::Dev::Part::create_service(partnumber => 'Serv1')->save;
413   my $credit_note = SL::Dev::Record::create_credit_note(
414     invnumber    => 'cn 1',
415     customer     => $customer,
416     taxincluded  => 0,
417     invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty =>  3, sellprice => 70),
418                       SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50),
419                     ]
420   );
421   my $bt            = SL::Dev::Payment::create_bank_transaction(record        => $credit_note,
422                                                                 amount        => $credit_note->amount,
423                                                                 bank_chart_id => $bank->id,
424                                                                 transdate     => DateTime->today->add(days => 10),
425                                                                );
426   my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($credit_note);
427   is($agreement, 13, "points for credit note ok");
428   is($rule_matches, 'remote_account_number(3) exact_amount(4) wrong_sign(-1) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus14(2) ', "rules_matches for credit note ok");
429
430   $::form->{invoice_ids} = {
431     $bt->id => [ $credit_note->id ]
432   };
433
434   save_btcontroller_to_string();
435
436   $credit_note->load;
437   $bt->load;
438   is($credit_note->amount   , '-844.90000', "$testname: amount ok");
439   is($credit_note->netamount, '-710.00000', "$testname: netamount ok");
440   is($credit_note->paid     , '-844.90000', "$testname: paid ok");
441 }
442
443 sub test_neg_ap_transaction {
444   my (%params) = @_;
445   my $testname = 'test_neg_ap_transaction';
446   my $netamount = -20;
447   my $amount    = $::form->round_amount($netamount * 1.19,2);
448   my $invoice   = SL::DB::PurchaseInvoice->new(
449     invoice      => 0,
450     invnumber    => $params{invnumber} || 'test_neg_ap_transaction',
451     amount       => $amount,
452     netamount    => $netamount,
453     transdate    => $transdate1,
454     taxincluded  => 0,
455     vendor_id    => $vendor->id,
456     taxzone_id   => $vendor->taxzone_id,
457     currency_id  => $currency_id,
458     transactions => [],
459     notes        => 'test_neg_ap_transaction',
460   );
461   $invoice->add_ap_amount_row(
462     amount     => $invoice->netamount,
463     chart      => $ap_amount_chart,
464     tax_id     => $tax_9->id,
465   );
466
467   $invoice->create_ap_row(chart => $ap_chart);
468   $invoice->save;
469
470   is($invoice->netamount, -20  , "$testname: netamount ok");
471   is($invoice->amount   , -23.8, "$testname: amount ok");
472
473   my $bt            = SL::Dev::Payment::create_bank_transaction(record        => $invoice,
474                                                                 amount        => $invoice->amount,
475                                                                 bank_chart_id => $bank->id,
476                                                                 transdate     => DateTime->today->add(days => 10),
477                                                                );
478   my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($invoice);
479   is($agreement, 15, "points for negative ap transaction ok");
480
481   $::form->{invoice_ids} = {
482     $bt->id => [ $invoice->id ]
483   };
484
485   save_btcontroller_to_string();
486
487   $invoice->load;
488   $bt->load;
489
490   is($invoice->amount   , '-23.80000', "$testname: amount ok");
491   is($invoice->netamount, '-20.00000', "$testname: netamount ok");
492   is($invoice->paid     , '-23.80000', "$testname: paid ok");
493   is($bt->invoice_amount, '23.80000', "$testname: bt invoice amount for ap was assigned");
494
495   return $invoice;
496 };
497
498 sub test_ap_payment_transaction {
499   my (%params) = @_;
500   my $testname = 'test_ap_payment_transaction';
501   my $netamount = 115;
502   my $amount    = $::form->round_amount($netamount * 1.19,2);
503   my $invoice   = SL::DB::PurchaseInvoice->new(
504     invoice      => 0,
505     invnumber    => $params{invnumber} || $testname,
506     amount       => $amount,
507     netamount    => $netamount,
508     transdate    => $transdate1,
509     taxincluded  => 0,
510     vendor_id    => $vendor->id,
511     taxzone_id   => $vendor->taxzone_id,
512     currency_id  => $currency_id,
513     transactions => [],
514     notes        => $testname,
515   );
516   $invoice->add_ap_amount_row(
517     amount     => $invoice->netamount,
518     chart      => $ap_amount_chart,
519     tax_id     => $tax_9->id,
520   );
521
522   $invoice->create_ap_row(chart => $ap_chart);
523   $invoice->save;
524
525   is($invoice->netamount, 115  , "$testname: netamount ok");
526   is($invoice->amount   , 136.85, "$testname: amount ok");
527
528   my $bt            = SL::Dev::Payment::create_bank_transaction(record        => $invoice,
529                                                                 amount        => $invoice->amount,
530                                                                 bank_chart_id => $bank->id,
531                                                                 transdate     => DateTime->today->add(days => 10),
532                                                                );
533   $::form->{invoice_ids} = {
534     $bt->id => [ $invoice->id ]
535   };
536
537   save_btcontroller_to_string();
538
539   $invoice->load;
540   $bt->load;
541
542   is($invoice->amount   , '136.85000', "$testname: amount ok");
543   is($invoice->netamount, '115.00000', "$testname: netamount ok");
544   is($bt->amount, '-136.85000', "$testname: bt amount ok");
545   is($invoice->paid     , '136.85000', "$testname: paid ok");
546   is($bt->invoice_amount, '-136.85000', "$testname: bt invoice amount for ap was assigned");
547
548   return $invoice;
549 };
550
551 sub test_ap_payment_part_transaction {
552   my (%params) = @_;
553   my $testname = 'test_ap_payment_p_transaction';
554   my $netamount = 115;
555   my $amount    = $::form->round_amount($netamount * 1.19,2);
556   my $invoice   = SL::DB::PurchaseInvoice->new(
557     invoice      => 0,
558     invnumber    => $params{invnumber} || $testname,
559     amount       => $amount,
560     netamount    => $netamount,
561     transdate    => $transdate1,
562     taxincluded  => 0,
563     vendor_id    => $vendor->id,
564     taxzone_id   => $vendor->taxzone_id,
565     currency_id  => $currency_id,
566     transactions => [],
567     notes        => $testname,
568   );
569   $invoice->add_ap_amount_row(
570     amount     => $invoice->netamount,
571     chart      => $ap_amount_chart,
572     tax_id     => $tax_9->id,
573   );
574
575   $invoice->create_ap_row(chart => $ap_chart);
576   $invoice->save;
577
578   is($invoice->netamount, 115  , "$testname: netamount ok");
579   is($invoice->amount   , 136.85, "$testname: amount ok");
580
581   my $bt            = SL::Dev::Payment::create_bank_transaction(record        => $invoice,
582                                                                 amount        => $invoice->amount-100,
583                                                                 bank_chart_id => $bank->id,
584                                                                 transdate     => DateTime->today->add(days => 10),
585                                                                );
586   $::form->{invoice_ids} = {
587     $bt->id => [ $invoice->id ]
588   };
589
590   save_btcontroller_to_string();
591
592   $invoice->load;
593   $bt->load;
594
595   is($invoice->amount   , '136.85000', "$testname: amount ok");
596   is($invoice->netamount, '115.00000', "$testname: netamount ok");
597   is($bt->amount,         '-36.85000', "$testname: bt amount ok");
598   is($invoice->paid     ,  '36.85000', "$testname: paid ok");
599   is($bt->invoice_amount, '-36.85000', "$testname: bt invoice amount for ap was assigned");
600
601   my $bt2           = SL::Dev::Payment::create_bank_transaction(record        => $invoice,
602                                                                 amount        => 100,
603                                                                 bank_chart_id => $bank->id,
604                                                                 transdate     => DateTime->today->add(days => 10),
605                                                                );
606   $::form->{invoice_ids} = {
607     $bt2->id => [ $invoice->id ]
608   };
609
610   save_btcontroller_to_string();
611   $invoice->load;
612   $bt2->load;
613
614   is($invoice->amount   , '136.85000', "$testname: amount ok");
615   is($invoice->netamount, '115.00000', "$testname: netamount ok");
616   is($bt2->amount,        '-100.00000',"$testname: bt amount ok");
617   is($invoice->paid     , '136.85000', "$testname: paid ok");
618   is($bt2->invoice_amount,'-100.00000', "$testname: bt invoice amount for ap was assigned");
619
620   return $invoice;
621 };
622
623 1;