Revision b75c6cbb
Von Jan Büren vor mehr als 6 Jahren hinzugefügt
t/bank/bank_transactions.t | ||
---|---|---|
1 |
use Test::More tests => 138;
|
|
1 |
use Test::More tests => 176;
|
|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
... | ... | |
10 | 10 |
use Test::Exception; |
11 | 11 |
use List::Util qw(sum); |
12 | 12 |
|
13 |
use SL::DB::AccTransaction; |
|
13 | 14 |
use SL::DB::Buchungsgruppe; |
14 | 15 |
use SL::DB::Currency; |
15 | 16 |
use SL::DB::Customer; |
... | ... | |
81 | 82 |
test_ap_payment_transaction(); |
82 | 83 |
test_ap_payment_part_transaction(); |
83 | 84 |
test_neg_sales_invoice(); |
84 |
|
|
85 |
test_two_neg_ap_transaction(); |
|
86 |
test_one_inv_and_two_invoices_with_skonto_exact(); |
|
85 | 87 |
test_bt_rule1(); |
86 | 88 |
test_sepa_export(); |
87 | 89 |
|
... | ... | |
316 | 318 |
is($ar_transaction_2->closed , 1 , "$testname: salesinv_2 is closed"); |
317 | 319 |
is($bt->invoice_amount , '238.00000' , "$testname: bt invoice amount was assigned"); |
318 | 320 |
|
319 |
}; |
|
321 |
} |
|
322 |
|
|
323 |
sub test_one_inv_and_two_invoices_with_skonto_exact { |
|
324 |
|
|
325 |
my $testname = 'test_two_invoices_with_skonto_exact'; |
|
326 |
|
|
327 |
my $ar_transaction_1 = test_ar_transaction(invnumber => 'salesinv 1 skonto', |
|
328 |
payment_id => $payment_terms->id, |
|
329 |
); |
|
330 |
my $ar_transaction_2 = test_ar_transaction(invnumber => 'salesinv 2 skonto', |
|
331 |
payment_id => $payment_terms->id, |
|
332 |
); |
|
333 |
my $ar_transaction_3 = test_ar_transaction(invnumber => 'salesinv 3 no skonto'); |
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
my $bt = create_bank_transaction(record => $ar_transaction_1, |
|
338 |
bank_chart_id => $bank->id, |
|
339 |
amount => $ar_transaction_1->amount_less_skonto * 2 + $ar_transaction_3->amount |
|
340 |
) or die "Couldn't create bank_transaction"; |
|
341 |
|
|
342 |
$::form->{invoice_ids} = { |
|
343 |
$bt->id => [ $ar_transaction_1->id, $ar_transaction_3->id, $ar_transaction_2->id] |
|
344 |
}; |
|
345 |
$::form->{invoice_skontos} = { |
|
346 |
$bt->id => [ 'with_skonto_pt', 'without_skonto', 'with_skonto_pt' ] |
|
347 |
}; |
|
348 |
|
|
349 |
save_btcontroller_to_string(); |
|
350 |
|
|
351 |
$ar_transaction_1->load; |
|
352 |
$ar_transaction_2->load; |
|
353 |
$ar_transaction_3->load; |
|
354 |
my $skonto_1 = SL::DB::Manager::AccTransaction->find_by(trans_id => $ar_transaction_1->id, chart_id => 162); |
|
355 |
my $skonto_2 = SL::DB::Manager::AccTransaction->find_by(trans_id => $ar_transaction_2->id, chart_id => 162); |
|
356 |
$bt->load; |
|
357 |
is($skonto_1->amount , '-5.95000' , "$testname: salesinv 1 skonto was booked"); |
|
358 |
is($skonto_2->amount , '-5.95000' , "$testname: salesinv 2 skonto was booked"); |
|
359 |
is($ar_transaction_1->paid , '119.00000' , "$testname: salesinv 1 was paid"); |
|
360 |
is($ar_transaction_2->paid , '119.00000' , "$testname: salesinv 2 was paid"); |
|
361 |
is($ar_transaction_3->paid , '119.00000' , "$testname: salesinv 3 was paid"); |
|
362 |
is($ar_transaction_1->closed , 1 , "$testname: salesinv 1 skonto is closed"); |
|
363 |
is($ar_transaction_2->closed , 1 , "$testname: salesinv 2 skonto is closed"); |
|
364 |
is($ar_transaction_3->closed , 1 , "$testname: salesinv 2 skonto is closed"); |
|
365 |
is($bt->invoice_amount , '345.10000' , "$testname: bt invoice amount was assigned"); |
|
366 |
|
|
367 |
} |
|
320 | 368 |
|
321 | 369 |
sub test_overpayment { |
322 | 370 |
|
... | ... | |
501 | 549 |
|
502 | 550 |
return $invoice; |
503 | 551 |
}; |
552 |
sub test_two_neg_ap_transaction { |
|
553 |
my $testname='test_two_neg_ap_transaction'; |
|
554 |
my $netamount = -20; |
|
555 |
my $amount = $::form->round_amount($netamount * 1.19,2); |
|
556 |
my $invoice = SL::DB::PurchaseInvoice->new( |
|
557 |
invoice => 0, |
|
558 |
invnumber => 'test_neg_ap_transaction', |
|
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 => 'test_neg_ap_transaction', |
|
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, -20 , "$testname: netamount ok"); |
|
579 |
is($invoice->amount , -23.8, "$testname: amount ok"); |
|
580 |
|
|
581 |
my $netamount_two = -1.14; |
|
582 |
my $amount_two = $::form->round_amount($netamount_two * 1.19,2); |
|
583 |
my $invoice_two = SL::DB::PurchaseInvoice->new( |
|
584 |
invoice => 0, |
|
585 |
invnumber => 'test_neg_ap_transaction_two', |
|
586 |
amount => $amount_two, |
|
587 |
netamount => $netamount_two, |
|
588 |
transdate => $transdate1, |
|
589 |
taxincluded => 0, |
|
590 |
vendor_id => $vendor->id, |
|
591 |
taxzone_id => $vendor->taxzone_id, |
|
592 |
currency_id => $currency_id, |
|
593 |
transactions => [], |
|
594 |
notes => 'test_neg_ap_transaction_two', |
|
595 |
); |
|
596 |
$invoice_two->add_ap_amount_row( |
|
597 |
amount => $invoice_two->netamount, |
|
598 |
chart => $ap_amount_chart, |
|
599 |
tax_id => $tax_9->id, |
|
600 |
); |
|
601 |
|
|
602 |
$invoice_two->create_ap_row(chart => $ap_chart); |
|
603 |
$invoice_two->save; |
|
604 |
|
|
605 |
is($invoice_two->netamount, -1.14 , "$testname: netamount ok"); |
|
606 |
is($invoice_two->amount , -1.36, "$testname: amount ok"); |
|
607 |
|
|
608 |
|
|
609 |
my $bt = create_bank_transaction(record => $invoice_two, |
|
610 |
amount => $invoice_two->amount + $invoice->amount, |
|
611 |
bank_chart_id => $bank->id, |
|
612 |
transdate => DateTime->today->add(days => 10), |
|
613 |
); |
|
614 |
# my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($invoice_two); |
|
615 |
# is($agreement, 15, "points for negative ap transaction ok"); |
|
616 |
|
|
617 |
$::form->{invoice_ids} = { |
|
618 |
$bt->id => [ $invoice->id, $invoice_two->id ] |
|
619 |
}; |
|
620 |
|
|
621 |
save_btcontroller_to_string(); |
|
622 |
|
|
623 |
$invoice->load; |
|
624 |
$invoice_two->load; |
|
625 |
$bt->load; |
|
626 |
|
|
627 |
is($invoice->amount , '-23.80000', "$testname: first inv amount ok"); |
|
628 |
is($invoice->netamount, '-20.00000', "$testname: first inv netamount ok"); |
|
629 |
is($invoice->paid , '-23.80000', "$testname: first inv paid ok"); |
|
630 |
is($invoice_two->amount , '-1.36000', "$testname: second inv amount ok"); |
|
631 |
is($invoice_two->netamount, '-1.14000', "$testname: second inv netamount ok"); |
|
632 |
is($invoice_two->paid , '-1.36000', "$testname: second inv paid ok"); |
|
633 |
is($bt->invoice_amount, '25.16000', "$testname: bt invoice amount for both invoices were assigned"); |
|
634 |
|
|
635 |
|
|
636 |
return ($invoice, $invoice_two); |
|
637 |
}; |
|
504 | 638 |
|
505 | 639 |
sub test_ap_payment_transaction { |
506 | 640 |
my (%params) = @_; |
Auch abrufbar als: Unified diff
bank_transactions Testfälle erweitert
für #356 und #355.