Revision 58d7ffe9
Von Jan Büren vor etwa 2 Jahren hinzugefügt
t/db_helper/payment.t | ||
---|---|---|
1 | 1 |
use strict; |
2 |
use Test::More tests => 203;
|
|
2 |
use Test::More tests => 255;
|
|
3 | 3 |
|
4 | 4 |
use strict; |
5 | 5 |
|
... | ... | |
41 | 41 |
Support::TestSetup::login(); |
42 | 42 |
|
43 | 43 |
init_state(); |
44 |
|
|
45 | 44 |
# test cases: without_skonto |
46 | 45 |
test_default_invoice_one_item_19_without_skonto(); |
47 | 46 |
test_default_invoice_two_items_19_7_tax_with_skonto(); |
... | ... | |
318 | 317 |
payment_id => $payment_terms->id, |
319 | 318 |
); |
320 | 319 |
|
321 |
my $ap_transaction = new_ap_transaction(); |
|
322 |
|
|
323 | 320 |
# default values |
324 | 321 |
my %params = ( chart_id => $bank_account->chart_id, |
325 | 322 |
transdate => $transdate1, |
... | ... | |
328 | 325 |
$params{amount} = '6.96'; |
329 | 326 |
$params{payment_type} = 'without_skonto'; |
330 | 327 |
|
331 |
$invoice->pay_invoice( %params ); |
|
332 |
|
|
328 |
my @ret = $invoice->pay_invoice( %params );
|
|
329 |
my $bank_amount = shift @ret; |
|
333 | 330 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
334 | 331 |
my $total = total_amount($invoice); |
335 |
|
|
332 |
my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
336 | 333 |
is($invoice->netamount, 5.85, "${title}: netamount"); |
337 | 334 |
is($invoice->amount, 6.96, "${title}: amount"); |
338 | 335 |
is($paid_amount, -6.96, "${title}: paid amount"); |
339 | 336 |
is($number_of_payments, 1, "${title}: 1 AR_paid booking"); |
340 | 337 |
is($invoice->paid, 6.96, "${title}: paid"); |
341 | 338 |
is($total, 0, "${title}: even balance"); |
342 |
|
|
339 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
340 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
341 |
is($invoice->paid, $bank_amount->{return_bank_amount}, "${title}: paid eq invoice_amount"); |
|
343 | 342 |
} |
344 | 343 |
|
345 | 344 |
sub test_default_invoice_one_item_19_without_skonto_overpaid { |
... | ... | |
363 | 362 |
|
364 | 363 |
$params{amount} = '16.96'; |
365 | 364 |
$params{payment_type} = 'without_skonto'; |
366 |
$invoice->pay_invoice( %params ); |
|
365 |
my @ret = $invoice->pay_invoice( %params ); |
|
366 |
my $bank_amount = shift @ret; |
|
367 |
|
|
368 |
my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
369 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
370 |
is($exp_invoice_amount > 0, 1, "${title}: bank invoice_amount is positive"); |
|
371 |
my $bt_invoice_amount = $exp_invoice_amount; |
|
372 |
|
|
373 |
$params{amount} = -10.00; |
|
374 |
@ret = $invoice->pay_invoice( %params ); |
|
375 |
|
|
376 |
$bank_amount = shift @ret; |
|
377 |
$exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
378 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
379 |
is($exp_invoice_amount < 0, 1, "${title}: bank invoice_amount is negative"); |
|
380 |
$bt_invoice_amount += $exp_invoice_amount; |
|
367 | 381 |
|
368 |
$params{amount} = '-10.00'; |
|
369 |
$invoice->pay_invoice( %params ); |
|
370 | 382 |
|
371 | 383 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
372 | 384 |
my $total = total_amount($invoice); |
... | ... | |
377 | 389 |
is($number_of_payments, 2, "${title}: 1 AR_paid booking"); |
378 | 390 |
is($invoice->paid, 6.96, "${title}: paid"); |
379 | 391 |
is($total, 0, "${title}: even balance"); |
392 |
is($invoice->paid, $bt_invoice_amount, "${title}: invoice paid equals bt invoice_amount"); |
|
380 | 393 |
|
381 | 394 |
} |
382 | 395 |
|
... | ... | |
403 | 416 |
$params{payment_type} = 'with_skonto_pt'; |
404 | 417 |
$params{amount} = $invoice->amount_less_skonto; |
405 | 418 |
|
406 |
$invoice->pay_invoice( %params ); |
|
419 |
my @ret = $invoice->pay_invoice( %params ); |
|
420 |
my $bank_amount = shift @ret; |
|
421 |
my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
422 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
407 | 423 |
|
408 | 424 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
409 | 425 |
my $total = total_amount($invoice); |
... | ... | |
437 | 453 |
$params{payment_type} = 'with_skonto_pt'; |
438 | 454 |
$params{amount} = $invoice->amount_less_skonto; |
439 | 455 |
|
440 |
$invoice->pay_invoice( %params ); |
|
456 |
my @ret = $invoice->pay_invoice( %params ); |
|
457 |
my $bank_amount = shift @ret; |
|
458 |
my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
459 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
460 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
441 | 461 |
|
442 | 462 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
443 | 463 |
my $total = total_amount($invoice); |
... | ... | |
447 | 467 |
is($paid_amount, -17.51, "${title}: paid amount"); |
448 | 468 |
is($invoice->paid, 17.51, "${title}: paid"); |
449 | 469 |
is($number_of_payments, 3, "${title}: 3 AR_paid bookings"); |
470 |
is($invoice->paid != $bank_amount->{return_bank_amount}, 1, "${title}: paid does not equal bank invoice_amount"); |
|
450 | 471 |
|
451 | 472 |
TODO: { |
452 | 473 |
local $TODO = "currently this test fails because the code writing the invoice is buggy, the calculation of skonto is correct"; |
... | ... | |
475 | 496 |
$params{amount} = '19.44'; # pass full amount |
476 | 497 |
$params{payment_type} = 'without_skonto'; |
477 | 498 |
|
478 |
$invoice->pay_invoice( %params ); |
|
499 |
my @ret = $invoice->pay_invoice( %params ); |
|
500 |
my $bank_amount = shift @ret; |
|
501 |
my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
502 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
503 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
479 | 504 |
|
480 | 505 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
481 | 506 |
my $total = total_amount($invoice); |
... | ... | |
486 | 511 |
is($invoice->paid, 19.44, "${title}: paid"); |
487 | 512 |
is($number_of_payments, 1, "${title}: 1 AR_paid bookings"); |
488 | 513 |
is($total, 0, "${title}: even balance"); |
514 |
is($invoice->paid, $bank_amount->{return_bank_amount}, "${title}: paid equals bt.invoice_amount"); |
|
489 | 515 |
} |
490 | 516 |
|
491 | 517 |
# test 4 |
... | ... | |
501 | 527 |
payment_id => $payment_terms->id, |
502 | 528 |
); |
503 | 529 |
|
504 |
$invoice->pay_invoice( amount => '9.44', |
|
505 |
payment_type => 'without_skonto', |
|
506 |
chart_id => $bank_account->chart_id, |
|
507 |
transdate => $transdate1, |
|
508 |
); |
|
530 |
my @ret = $invoice->pay_invoice( amount => '9.44', |
|
531 |
payment_type => 'without_skonto', |
|
532 |
chart_id => $bank_account->chart_id, |
|
533 |
transdate => $transdate1, |
|
534 |
); |
|
535 |
my $bank_amount = shift @ret; |
|
536 |
my $exp_invoice_amount = $invoice->amount > 0 ? 9.44 : 9.44 * -1; |
|
537 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
538 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
509 | 539 |
|
510 | 540 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
511 | 541 |
my $total = total_amount($invoice); |
... | ... | |
516 | 546 |
is($invoice->paid, 9.44, "${title}: paid"); |
517 | 547 |
is($number_of_payments, 1, "${title}: 1 AR_paid bookings"); |
518 | 548 |
is($total, 0, "${title}: even balance"); |
549 |
is($invoice->paid, $bank_amount->{return_bank_amount}, "${title}: paid equals bt.invoice_amount"); |
|
519 | 550 |
} |
520 | 551 |
|
521 | 552 |
# test 5 |
... | ... | |
530 | 561 |
invoiceitems => [ $item1, $item2 ], |
531 | 562 |
payment_id => $payment_terms->id, |
532 | 563 |
); |
533 |
|
|
534 |
$invoice->pay_invoice( amount => '9.44', |
|
535 |
payment_type => 'without_skonto', |
|
536 |
chart_id => $bank_account->chart_id, |
|
537 |
transdate => $transdate1, |
|
564 |
my @ret; |
|
565 |
@ret = $invoice->pay_invoice( amount => '9.44',
|
|
566 |
payment_type => 'without_skonto',
|
|
567 |
chart_id => $bank_account->chart_id,
|
|
568 |
transdate => $transdate1,
|
|
538 | 569 |
); |
539 |
$invoice->pay_invoice( amount => '10.00', |
|
540 |
chart_id => $bank_account->chart_id, |
|
541 |
transdate => $transdate1, |
|
570 |
|
|
571 |
my $bank_amount = shift @ret; |
|
572 |
my $exp_invoice_amount = $invoice->amount > 0 ? 9.44 : 9.44 * -1; |
|
573 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
574 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
575 |
my $bank_invoice_amount = $bank_amount->{return_bank_amount}; |
|
576 |
|
|
577 |
@ret = $invoice->pay_invoice( amount => '10.00', |
|
578 |
chart_id => $bank_account->chart_id, |
|
579 |
transdate => $transdate1, |
|
542 | 580 |
); |
581 |
$bank_amount = shift @ret; |
|
582 |
$exp_invoice_amount = $invoice->amount > 0 ? 10 : 10 * -1; |
|
583 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
584 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
585 |
$bank_invoice_amount += $bank_amount->{return_bank_amount}; |
|
543 | 586 |
|
544 | 587 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
545 | 588 |
my $total = total_amount($invoice); |
... | ... | |
550 | 593 |
is($invoice->paid, 19.44, "${title}: paid"); |
551 | 594 |
is($number_of_payments, 2, "${title}: 2 AR_paid bookings"); |
552 | 595 |
is($total, 0, "${title}: even balance"); |
596 |
is($invoice->paid, $bank_invoice_amount, "${title}: paid eq bank invoice_amount"); |
|
553 | 597 |
|
554 | 598 |
} |
555 | 599 |
|
... | ... | |
566 | 610 |
payment_id => $payment_terms->id, |
567 | 611 |
); |
568 | 612 |
|
569 |
$invoice->pay_invoice( amount => '9.44', |
|
570 |
payment_type => 'without_skonto', |
|
571 |
chart_id => $bank_account->chart_id, |
|
572 |
transdate => $transdate1, |
|
573 |
); |
|
574 |
$invoice->pay_invoice( amount => '8.73', |
|
575 |
payment_type => 'without_skonto', |
|
576 |
chart_id => $bank_account->chart_id, |
|
577 |
transdate => $transdate1, |
|
578 |
); |
|
613 |
my (@ret, $bank_amount, $exp_invoice_amount); |
|
614 |
@ret = $invoice->pay_invoice( amount => '9.44', |
|
615 |
payment_type => 'without_skonto', |
|
616 |
chart_id => $bank_account->chart_id, |
|
617 |
transdate => $transdate1, |
|
618 |
); |
|
619 |
$bank_amount = shift @ret; |
|
620 |
my $amount = 9.44; |
|
621 |
$exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1; |
|
622 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
623 |
|
|
624 |
@ret = $invoice->pay_invoice( amount => '8.73', |
|
625 |
payment_type => 'without_skonto', |
|
626 |
chart_id => $bank_account->chart_id, |
|
627 |
transdate => $transdate1, |
|
628 |
); |
|
629 |
$bank_amount = shift @ret; |
|
630 |
$amount = 8.73; |
|
631 |
$exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1; |
|
632 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
633 |
|
|
579 | 634 |
# free_skonto does: |
580 | 635 |
# my $open_amount = $payment_type eq 'with_skonto_pt' ? $invoice->amount_less_skonto : $invoice->open_amount; |
581 | 636 |
# $open_amount = abs($open_amount); |
582 | 637 |
# $open_amount -= $free_skonto_amount if ($payment_type eq 'free_skonto'); |
583 | 638 |
|
584 |
$invoice->pay_invoice( skonto_amount => $invoice->open_amount, |
|
639 |
@ret = $invoice->pay_invoice( skonto_amount => $invoice->open_amount,
|
|
585 | 640 |
amount => 0, |
586 | 641 |
payment_type => 'free_skonto', |
587 | 642 |
chart_id => $bank_account->chart_id, |
588 | 643 |
transdate => $transdate1, |
589 | 644 |
bt_id => $bt->id, |
590 | 645 |
); |
646 |
$bank_amount = shift @ret; |
|
647 |
$amount = 0; |
|
648 |
$exp_invoice_amount = $invoice->amount < 0 ? $amount : $amount * -1; |
|
649 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
650 |
|
|
591 | 651 |
|
592 | 652 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
593 | 653 |
my $total = total_amount($invoice); |
... | ... | |
619 | 679 |
payment_id => $payment_terms->id, |
620 | 680 |
); |
621 | 681 |
|
622 |
$invoice->pay_invoice( amount => '19.42', |
|
623 |
payment_type => 'without_skonto', |
|
624 |
chart_id => $bank_account->chart_id, |
|
625 |
transdate => $transdate1, |
|
626 |
); |
|
627 |
$invoice->pay_invoice( skonto_amount => $invoice->open_amount, |
|
628 |
amount => 0, |
|
629 |
payment_type => 'free_skonto', |
|
630 |
chart_id => $bank_account->chart_id, |
|
631 |
transdate => $transdate1, |
|
632 |
bt_id => $bt->id, |
|
633 |
); |
|
682 |
my (@ret, $bank_amount, $exp_invoice_amount); |
|
683 |
@ret = $invoice->pay_invoice( amount => '19.42', |
|
684 |
payment_type => 'without_skonto', |
|
685 |
chart_id => $bank_account->chart_id, |
|
686 |
transdate => $transdate1, |
|
687 |
); |
|
688 |
$bank_amount = shift @ret; |
|
689 |
my $amount = 19.42; |
|
690 |
$exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1; |
|
691 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
692 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
693 |
|
|
694 |
@ret = $invoice->pay_invoice( skonto_amount => $invoice->open_amount, |
|
695 |
amount => 0, |
|
696 |
payment_type => 'free_skonto', |
|
697 |
chart_id => $bank_account->chart_id, |
|
698 |
transdate => $transdate1, |
|
699 |
bt_id => $bt->id, |
|
700 |
); |
|
701 |
$bank_amount = shift @ret; |
|
702 |
$amount = 0; |
|
703 |
$exp_invoice_amount = $invoice->amount < 0 ? $amount : $amount * -1; |
|
704 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
705 |
|
|
634 | 706 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
635 | 707 |
my $total = total_amount($invoice); |
636 | 708 |
|
... | ... | |
655 | 727 |
payment_id => $payment_terms->id, |
656 | 728 |
); |
657 | 729 |
|
658 |
$invoice->pay_invoice( amount => '19.42', |
|
730 |
my (@ret, $bank_amount, $exp_invoice_amount); |
|
731 |
@ret = $invoice->pay_invoice( amount => '19.42', |
|
659 | 732 |
payment_type => 'without_skonto', |
660 | 733 |
chart_id => $bank_account->chart_id, |
661 | 734 |
transdate => $transdate1, |
662 | 735 |
); |
663 |
$invoice->pay_invoice( skonto_amount => $invoice->open_amount, |
|
736 |
$bank_amount = shift @ret; |
|
737 |
my $amount = 19.42; |
|
738 |
$exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1; |
|
739 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
740 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
741 |
|
|
742 |
@ret = $invoice->pay_invoice( skonto_amount => $invoice->open_amount, |
|
664 | 743 |
amount => 0, |
665 | 744 |
payment_type => 'free_skonto', |
666 | 745 |
chart_id => $bank_account->chart_id, |
667 | 746 |
transdate => $transdate1, |
668 | 747 |
bt_id => $bt->id, |
669 | 748 |
); |
749 |
$bank_amount = shift @ret; |
|
750 |
$amount = 0; |
|
751 |
$exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1; |
|
752 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
753 |
is($bank_amount->{return_bank_amount} == 0, 1, "${title}: bank invoice_amount is zero"); |
|
670 | 754 |
|
671 | 755 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
672 | 756 |
my $total = total_amount($invoice); |
... | ... | |
699 | 783 |
|
700 | 784 |
$params{amount} = '2.32'; |
701 | 785 |
$params{payment_type} = 'without_skonto'; |
702 |
$invoice->pay_invoice( %params ); |
|
786 |
my @ret = $invoice->pay_invoice( %params ); |
|
787 |
my $bank_amount = shift @ret; |
|
788 |
my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
789 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
790 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
791 |
|
|
703 | 792 |
|
704 | 793 |
$params{amount} = '3.81'; |
705 | 794 |
$params{payment_type} = 'without_skonto'; |
706 |
$invoice->pay_invoice( %params ); |
|
795 |
@ret = $invoice->pay_invoice( %params ); |
|
796 |
$bank_amount = shift @ret; |
|
797 |
$exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
798 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
799 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
800 |
|
|
801 |
|
|
707 | 802 |
|
708 | 803 |
$params{skonto_amount} = $invoice->open_amount; # set amount, otherwise previous 3.81 is used |
709 | 804 |
$params{amount} = 0, |
710 | 805 |
$params{payment_type} = 'free_skonto'; |
711 |
$invoice->pay_invoice( %params ); |
|
806 |
@ret = $invoice->pay_invoice( %params ); |
|
807 |
$bank_amount = shift @ret; |
|
808 |
$exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
809 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
810 |
is($bank_amount->{return_bank_amount} == 0, 1, "${title}: bank invoice_amount is zero"); |
|
811 |
|
|
712 | 812 |
|
713 | 813 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
714 | 814 |
my $total = total_amount($invoice); |
... | ... | |
741 | 841 |
|
742 | 842 |
$params{amount} = '6.95'; |
743 | 843 |
$params{payment_type} = 'without_skonto'; |
744 |
$invoice->pay_invoice( %params ); |
|
844 |
my @ret = $invoice->pay_invoice( %params ); |
|
845 |
my $bank_amount = shift @ret; |
|
846 |
my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
847 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
848 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: bank invoice_amount is positive"); |
|
745 | 849 |
|
746 | 850 |
$params{skonto_amount} = $invoice->open_amount; |
747 | 851 |
$params{amount} = 0, |
748 | 852 |
$params{payment_type} = 'free_skonto'; |
749 |
$invoice->pay_invoice( %params ); |
|
853 |
@ret = $invoice->pay_invoice( %params ); |
|
854 |
$bank_amount = shift @ret; |
|
855 |
$exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
856 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
857 |
|
|
750 | 858 |
|
751 | 859 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
752 | 860 |
my $total = total_amount($invoice); |
... | ... | |
762 | 870 |
|
763 | 871 |
# test 3 : two items, without skonto |
764 | 872 |
sub test_default_ap_transaction_two_charts_19_7_without_skonto { |
765 |
my $title = 'default invoice, two items, 19/7% tax without skonto';
|
|
873 |
my $title = 'default ap_transaction, two items, 19/7% tax without skonto';
|
|
766 | 874 |
|
767 | 875 |
my $ap_transaction = new_ap_transaction(); |
768 | 876 |
|
... | ... | |
770 | 878 |
transdate => $transdate1, |
771 | 879 |
); |
772 | 880 |
|
773 |
$params{amount} = '226'; # pass full amount
|
|
881 |
$params{amount} = 226; # pass full amount
|
|
774 | 882 |
$params{payment_type} = 'without_skonto'; |
775 | 883 |
|
776 |
$ap_transaction->pay_invoice( %params ); |
|
884 |
my @ret = $ap_transaction->pay_invoice( %params ); |
|
885 |
my $bank_amount = shift @ret; |
|
886 |
my $exp_invoice_amount = $ap_transaction->amount < 0 ? $params{amount} : $params{amount} * -1; |
|
887 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
888 |
is($bank_amount->{return_bank_amount} < 0, 1, "${title}: bank invoice_amount is negative"); |
|
777 | 889 |
|
778 | 890 |
my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction); |
779 | 891 |
my $total = total_amount($ap_transaction); |
780 | 892 |
|
781 |
is($paid_amount, 226, "${title}: paid amount"); |
|
782 |
is($number_of_payments, 1, "${title}: 1 AP_paid bookings"); |
|
783 |
is($total, 0, "${title}: even balance"); |
|
893 |
is($paid_amount, 226, "${title}: paid amount"); |
|
894 |
is($ap_transaction->paid, 226, "${title}: ap.paid amount"); |
|
895 |
is($number_of_payments, 1, "${title}: 1 AP_paid bookings"); |
|
896 |
is($total, 0, "${title}: even balance"); |
|
784 | 897 |
|
785 | 898 |
} |
786 | 899 |
|
... | ... | |
799 | 912 |
$params{amount} = $ap_transaction->amount_less_skonto; # pass calculated skonto amount |
800 | 913 |
$params{payment_type} = 'with_skonto_pt'; |
801 | 914 |
|
802 |
$ap_transaction->pay_invoice( %params ); |
|
915 |
my @ret = $ap_transaction->pay_invoice( %params ); |
|
916 |
my $bank_amount = shift @ret; |
|
917 |
my $exp_invoice_amount = $ap_transaction->amount < 0 ? $params{amount} : $params{amount} * -1; |
|
918 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
919 |
is($bank_amount->{return_bank_amount} < 0, 1, "${title}: bank invoice_amount is negative"); |
|
803 | 920 |
|
804 | 921 |
my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction); |
805 | 922 |
my $total = total_amount($ap_transaction); |
806 | 923 |
|
807 |
is($paid_amount, 226, "${title}: paid amount"); |
|
808 |
is($number_of_payments, 3, "${title}: 1 AP_paid bookings"); |
|
809 |
is($total, 0, "${title}: even balance"); |
|
924 |
is($paid_amount, 226, "${title}: paid amount"); |
|
925 |
is($ap_transaction->paid, 226, "${title}: paid amount"); |
|
926 |
is($number_of_payments, 3, "${title}: 1 AP_paid bookings"); |
|
927 |
is($total, 0, "${title}: even balance"); |
|
810 | 928 |
|
811 | 929 |
} |
812 | 930 |
|
... | ... | |
815 | 933 |
|
816 | 934 |
# check whether unrounded amounts passed via $params{amount} are rounded for without_skonto case |
817 | 935 |
my $ap_transaction = new_ap_transaction(); |
818 |
$ap_transaction->pay_invoice( |
|
819 |
amount => ( $ap_transaction->amount / 3 * 2), |
|
820 |
payment_type => 'without_skonto', |
|
821 |
chart_id => $bank_account->chart_id, |
|
822 |
transdate => $transdate1, |
|
823 |
); |
|
936 |
my @ret = $ap_transaction->pay_invoice( |
|
937 |
amount => ( $ap_transaction->amount / 3 * 2), |
|
938 |
payment_type => 'without_skonto', |
|
939 |
chart_id => $bank_account->chart_id, |
|
940 |
transdate => $transdate1, |
|
941 |
); |
|
942 |
my $bank_amount = shift @ret; |
|
943 |
my $amount = $::form->round_amount( $ap_transaction->amount / 3 * 2, 2); |
|
944 |
my $exp_invoice_amount = $ap_transaction->amount < 0 ? $amount : $amount * -1; |
|
945 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
946 |
is($bank_amount->{return_bank_amount} < 0, 1, "${title}: bank invoice_amount is negative"); |
|
947 |
|
|
948 |
|
|
824 | 949 |
my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction); |
825 | 950 |
my $total = total_amount($ap_transaction); |
826 | 951 |
|
827 |
is($paid_amount, 150.67, "${title}: paid amount"); |
|
828 |
is($number_of_payments, 1, "${title}: 1 AP_paid bookings"); |
|
829 |
is($total, 0, "${title}: even balance"); |
|
952 |
is($paid_amount, 150.67, "${title}: paid amount"); |
|
953 |
is($ap_transaction->paid, 150.67, "${title}: paid amount"); |
|
954 |
is($number_of_payments, 1, "${title}: 1 AP_paid bookings"); |
|
955 |
is($total, 0, "${title}: even balance"); |
|
830 | 956 |
}; |
831 | 957 |
|
832 | 958 |
|
... | ... | |
836 | 962 |
my $ap_transaction = new_ap_transaction(); |
837 | 963 |
|
838 | 964 |
# pay 2/3 and 1/5, leaves 3.83% to be used as Skonto |
839 |
$ap_transaction->pay_invoice( |
|
965 |
my @ret = $ap_transaction->pay_invoice(
|
|
840 | 966 |
amount => ( $ap_transaction->amount / 3 * 2), |
841 | 967 |
payment_type => 'without_skonto', |
842 | 968 |
chart_id => $bank_account->chart_id, |
843 | 969 |
transdate => $transdate1, |
844 | 970 |
); |
845 |
$ap_transaction->pay_invoice( |
|
971 |
my $bank_amount = shift @ret; |
|
972 |
my $amount = $::form->round_amount( $ap_transaction->amount / 3 * 2, 2); |
|
973 |
my $exp_invoice_amount = $ap_transaction->amount < 0 ? $amount : $amount * -1; |
|
974 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
975 |
is($bank_amount->{return_bank_amount} < 0, 1, "${title}: bank invoice_amount is negative"); |
|
976 |
|
|
977 |
@ret = $ap_transaction->pay_invoice( |
|
846 | 978 |
amount => ( $ap_transaction->amount / 5 ), |
847 | 979 |
payment_type => 'without_skonto', |
848 | 980 |
chart_id => $bank_account->chart_id, |
849 | 981 |
transdate => $transdate1, |
850 | 982 |
); |
851 |
$ap_transaction->pay_invoice( |
|
983 |
$bank_amount = shift @ret; |
|
984 |
$amount = $ap_transaction->amount / 5; |
|
985 |
$exp_invoice_amount = $ap_transaction->amount < 0 ? $amount : $amount * -1; |
|
986 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
987 |
is($bank_amount->{return_bank_amount} < 0, 1, "${title}: invoice_amount negative"); |
|
988 |
|
|
989 |
@ret = $ap_transaction->pay_invoice( |
|
852 | 990 |
payment_type => 'free_skonto', |
853 | 991 |
skonto_amount => $ap_transaction->open_amount, |
854 | 992 |
amount => 0, |
... | ... | |
856 | 994 |
transdate => $transdate1, |
857 | 995 |
bt_id => $bt->id, |
858 | 996 |
); |
997 |
$bank_amount = shift @ret; |
|
998 |
$amount = 0; |
|
999 |
$exp_invoice_amount = $ap_transaction->amount < 0 ? $amount : $amount * -1; |
|
1000 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
859 | 1001 |
|
860 | 1002 |
my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction); |
861 | 1003 |
my $total = total_amount($ap_transaction); |
862 | 1004 |
|
863 |
is($paid_amount, 226, "${title}: paid amount"); |
|
864 |
is($number_of_payments, 4, "${title}: 4 AP_paid bookings"); |
|
865 |
is($total, 0, "${title}: even balance"); |
|
1005 |
is($paid_amount, 226, "${title}: paid amount"); |
|
1006 |
is($ap_transaction->paid, 226, "${title}: ap.paid amount"); |
|
1007 |
is($number_of_payments, 4, "${title}: 4 AP_paid bookings"); |
|
1008 |
is($total, 0, "${title}: even balance"); |
|
866 | 1009 |
|
867 | 1010 |
} |
868 | 1011 |
|
... | ... | |
888 | 1031 |
$params{amount} = $invoice->amount_less_skonto; |
889 | 1032 |
$params{payment_type} = 'with_skonto_pt'; |
890 | 1033 |
|
891 |
$invoice->pay_invoice( %params ); |
|
1034 |
my @ret = $invoice->pay_invoice( %params ); |
|
1035 |
my $bank_amount = shift @ret; |
|
1036 |
my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1; |
|
1037 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
1038 |
is($bank_amount->{return_bank_amount} > 0, 1, "${title}: invoice_amount positive"); |
|
892 | 1039 |
|
893 | 1040 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
894 | 1041 |
my $total = total_amount($invoice); |
... | ... | |
1019 | 1166 |
my $title = 'test_ar_currency_tax_not_included_and_payment_2'; |
1020 | 1167 |
|
1021 | 1168 |
my $netamount = $::form->round_amount(75 * $exchangerate->sell,2); # 75 in CUR, 100.00 in EUR |
1022 |
my $amount = $::form->round_amount($netamount * 1.19,2); # 100 in CUR, 119.00 in EUR
|
|
1169 |
my $amount = $::form->round_amount($netamount * 1.19,2); # 100 in EUR, 119.00 in EUR incl. tax
|
|
1023 | 1170 |
my $invoice = SL::DB::Invoice->new( |
1024 | 1171 |
invoice => 0, |
1025 | 1172 |
amount => $amount, |
... | ... | |
1048 | 1195 |
is($invoice->taxincluded , 0 , 'ar transaction doesn\'t have taxincluded'); |
1049 | 1196 |
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'); |
1050 | 1197 |
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'); |
1051 |
|
|
1052 | 1198 |
$invoice->pay_invoice(chart_id => $bank->id, |
1053 |
amount => 50, |
|
1199 |
amount => 50, # amount is in default currency -> should be 37.5 in CUR
|
|
1054 | 1200 |
currency => 'CUR', |
1055 | 1201 |
transdate => $transdate1->to_kivitendo, |
1202 |
exchangerate => $exchangerate->sell, |
|
1056 | 1203 |
); |
1057 | 1204 |
$invoice->pay_invoice(chart_id => $bank->id, |
1058 |
amount => 39.25, |
|
1205 |
amount => 39.25, # amount is in default currency -> should be 29.44 in CUR
|
|
1059 | 1206 |
currency => 'CUR', |
1060 | 1207 |
transdate => $transdate1->to_kivitendo, |
1208 |
exchangerate => $exchangerate->sell, |
|
1061 | 1209 |
); |
1062 |
# $invoice->pay_invoice(chart_id => $bank->id, |
|
1063 |
# amount => 30, |
|
1064 |
# transdate => $transdate2->to_kivitendo, |
|
1065 |
# ); |
|
1066 |
is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions (incl. fxtransactions)'); |
|
1210 |
$invoice->pay_invoice(chart_id => $bank->id, |
|
1211 |
amount => 29.75, |
|
1212 |
transdate => $transdate1->to_kivitendo, |
|
1213 |
currency => 'CUR', |
|
1214 |
exchangerate => $exchangerate->sell, |
|
1215 |
); |
|
1216 |
is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions'); |
|
1067 | 1217 |
is($invoice->paid, $invoice->amount, 'ar transaction paid = amount in default currency'); |
1068 |
};
|
|
1218 |
} |
|
1069 | 1219 |
|
1070 | 1220 |
sub test_ar_currency_tax_included { |
1071 | 1221 |
my $title = 'test_ar_currency_tax_included'; |
... | ... | |
1104 | 1254 |
amount => 89.25, |
1105 | 1255 |
currency => 'CUR', |
1106 | 1256 |
transdate => $transdate1->to_kivitendo, |
1257 |
exchangerate => $exchangerate->sell, |
|
1107 | 1258 |
); |
1108 | 1259 |
|
1109 | 1260 |
}; |
... | ... | |
1146 | 1297 |
amount => 50, |
1147 | 1298 |
currency => 'CUR', |
1148 | 1299 |
transdate => $transdate1->to_kivitendo, |
1300 |
exchangerate => $exchangerate->buy, |
|
1149 | 1301 |
); |
1150 | 1302 |
$invoice->pay_invoice(chart_id => $bank->id, |
1151 | 1303 |
amount => 39.25, |
1152 | 1304 |
currency => 'CUR', |
1153 | 1305 |
transdate => $transdate1->to_kivitendo, |
1306 |
exchangerate => $exchangerate->buy, |
|
1307 |
); |
|
1308 |
is($invoice->paid, 89.25, 'ap transaction paid = amount in default currency'); |
|
1309 |
$invoice->pay_invoice(chart_id => $bank->id, |
|
1310 |
amount => 22.31 * $exchangerate2->buy, # 22.31 in fx currency |
|
1311 |
currency => 'CUR', |
|
1312 |
transdate => $transdate2->to_kivitendo, |
|
1313 |
exchangerate => $exchangerate2->buy, |
|
1154 | 1314 |
); |
1155 |
is(scalar @{$invoice->transactions}, 9, 'ap transaction has 9 transactions (incl. fxtransactions)'); |
|
1315 |
|
|
1316 |
is(scalar @{$invoice->transactions}, 10, 'ap transaction has 10 transactions (including fx gain transaction)'); |
|
1156 | 1317 |
is($invoice->paid, $invoice->amount, 'ap transaction paid = amount in default currency'); |
1157 |
}; |
|
1318 |
|
|
1319 |
# check last booking fx rate decreased to 0.8 from 1.33333 |
|
1320 |
my $fxgain_chart = SL::DB::Manager::Chart->find_by(accno => '2660') or die "Can't find fxgain_chart in test"; |
|
1321 |
my $fx_gain_transactions = SL::DB::Manager::AccTransaction->get_all(where => |
|
1322 |
[ trans_id => $invoice->id, chart_id => $fxgain_chart->id ], |
|
1323 |
sort_by => ('acc_trans_id')); |
|
1324 |
|
|
1325 |
is($fx_gain_transactions->[0]->amount, '11.90000', "fx gain amount ok"); |
|
1326 |
|
|
1327 |
# check last bank transaction should be 22.31 * 0.8 |
|
1328 |
my $last_bank_transaction = SL::DB::Manager::AccTransaction->get_all(where => |
|
1329 |
[ trans_id => $invoice->id, chart_id => $bank->id, transdate => $transdate2 ], |
|
1330 |
sort_by => ('acc_trans_id')); |
|
1331 |
|
|
1332 |
is($last_bank_transaction->[0]->amount, '17.85000', "fx bank amount with fx gain ok"); |
|
1333 |
|
|
1334 |
|
|
1335 |
|
|
1336 |
} |
|
1158 | 1337 |
|
1159 | 1338 |
sub test_ap_currency_tax_included { |
1160 | 1339 |
my $title = 'test_ap_currency_tax_included'; |
... | ... | |
1194 | 1373 |
amount => 89.25, |
1195 | 1374 |
currency => 'CUR', |
1196 | 1375 |
transdate => $transdate1->to_kivitendo, |
1376 |
exchangerate => $exchangerate->sell, |
|
1197 | 1377 |
); |
1198 | 1378 |
|
1199 | 1379 |
}; |
... | ... | |
1233 | 1413 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id, trans_id => $invoice->id)->amount, '-119.00000', $title . " " . $ar_chart->accno . ': has been converted for currency'); |
1234 | 1414 |
|
1235 | 1415 |
$invoice->pay_invoice(chart_id => $bank->id, |
1236 |
amount => 123.45, |
|
1416 |
amount => 123.45 * $exchangerate2->sell,
|
|
1237 | 1417 |
currency => 'CUR', |
1238 | 1418 |
transdate => $transdate2->to_kivitendo, |
1419 |
exchangerate => $exchangerate2->sell, |
|
1239 | 1420 |
); |
1240 | 1421 |
$invoice->pay_invoice(chart_id => $bank->id, |
1241 |
amount => 15.30, |
|
1422 |
amount => 15.30 * $exchangerate3->sell,
|
|
1242 | 1423 |
currency => 'CUR', |
1243 | 1424 |
transdate => $transdate3->to_kivitendo, |
1425 |
exchangerate => $exchangerate3->sell, |
|
1244 | 1426 |
); |
1245 | 1427 |
$invoice->pay_invoice(chart_id => $bank->id, |
1246 |
amount => 10.00, |
|
1428 |
amount => 10.00 * $exchangerate4->sell,
|
|
1247 | 1429 |
currency => 'CUR', |
1248 | 1430 |
transdate => $transdate4->to_kivitendo, |
1431 |
exchangerate => $exchangerate4->sell, |
|
1249 | 1432 |
); |
1250 | 1433 |
# $invoice->pay_invoice(chart_id => $bank->id, |
1251 | 1434 |
# amount => 30, |
1252 | 1435 |
# transdate => $transdate2->to_kivitendo, |
1253 | 1436 |
# ); |
1254 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id')); |
|
1255 |
is(scalar @{$fx_transactions}, 3, "$title: ar transaction has 3 fx transactions"); |
|
1256 |
is($fx_transactions->[0]->amount, '24.69000', "$title fx transactions 1: 123.45-(123.45*0.8) = 24.69"); |
|
1437 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 0 ], sort_by => ('acc_trans_id')); |
|
1438 |
is(scalar @{$fx_transactions}, 11, "$title: ar transaction has 11 transaction"); |
|
1257 | 1439 |
|
1258 |
is(scalar @{$invoice->transactions}, 14, "$title ar transaction has 14 transactions (incl. fxtransactions and fx_gain)"); |
|
1259 | 1440 |
is($invoice->paid, $invoice->amount, "$title ar transaction paid = amount in default currency"); |
1260 | 1441 |
}; |
1261 | 1442 |
|
... | ... | |
1294 | 1475 |
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'); |
1295 | 1476 |
|
1296 | 1477 |
$invoice->pay_invoice(chart_id => $bank->id, |
1297 |
amount => -123.45, |
|
1478 |
amount => -123.45 * $exchangerate2->sell,
|
|
1298 | 1479 |
currency => 'CUR', |
1299 | 1480 |
transdate => $transdate2->to_kivitendo, |
1481 |
exchangerate => $exchangerate2->sell, |
|
1300 | 1482 |
); |
1301 | 1483 |
$invoice->pay_invoice(chart_id => $bank->id, |
1302 |
amount => -25.30, |
|
1484 |
amount => -25.30 * $exchangerate2->sell,
|
|
1303 | 1485 |
currency => 'CUR', |
1304 | 1486 |
transdate => $transdate2->to_kivitendo, |
1487 |
exchangerate => $exchangerate2->sell, |
|
1305 | 1488 |
); |
1306 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id')); |
|
1307 |
is(scalar @{$fx_transactions}, 2, 'ar transaction has 2 fx transactions'); |
|
1308 |
is($fx_transactions->[0]->amount, '-24.69000', 'fx transactions 1: 123.45-(123.45*0.8) = 24.69'); |
|
1489 |
#my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
|
|
1490 |
#is(scalar @{$fx_transactions}, 2, 'ar transaction has 2 fx transactions');
|
|
1491 |
#is($fx_transactions->[0]->amount, '-24.69000', 'fx transactions 1: 123.45-(123.45*0.8) = 24.69');
|
|
1309 | 1492 |
|
1310 |
is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions (incl. fxtransactions)');
|
|
1493 |
is(scalar @{$invoice->transactions}, 7, 'ar transaction has 7 transactions (no fxtransactions)');
|
|
1311 | 1494 |
is($invoice->paid, $invoice->amount, 'ar transaction paid = amount in default currency'); |
1312 | 1495 |
}; |
1313 | 1496 |
|
... | ... | |
1346 | 1529 |
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'); |
1347 | 1530 |
|
1348 | 1531 |
$invoice->pay_invoice(chart_id => $bank->id, |
1349 |
amount => 10, |
|
1532 |
amount => 10 * $exchangerate2->sell,
|
|
1350 | 1533 |
currency => 'CUR', |
1351 | 1534 |
transdate => $transdate2->to_kivitendo, |
1535 |
exchangerate => $exchangerate2->sell, |
|
1352 | 1536 |
); |
1353 | 1537 |
$invoice->pay_invoice(chart_id => $bank->id, |
1354 |
amount => 123.45, |
|
1538 |
amount => 123.45 * $exchangerate3->sell,
|
|
1355 | 1539 |
currency => 'CUR', |
1356 | 1540 |
transdate => $transdate3->to_kivitendo, |
1541 |
exchangerate => $exchangerate3->sell, |
|
1357 | 1542 |
); |
1358 | 1543 |
$invoice->pay_invoice(chart_id => $bank->id, |
1359 |
amount => 15.30, |
|
1544 |
amount => 15.30 * $exchangerate4->sell,
|
|
1360 | 1545 |
currency => 'CUR', |
1361 | 1546 |
transdate => $transdate4->to_kivitendo, |
1547 |
exchangerate => $exchangerate4->sell, |
|
1362 | 1548 |
); |
1363 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id')); |
|
1364 |
is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions"); |
|
1365 |
is($fx_transactions->[0]->amount, '-2.00000', "$title: fx transaction 1: 10.00-( 10.00*0.80000) = 2.00000"); |
|
1366 |
is($fx_transactions->[1]->amount, '68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511"); |
|
1367 |
is($fx_transactions->[2]->amount, '-3.40000', "$title: fx transaction 3: 15.30-(15.30 *0.77777) = 3.40012"); |
|
1549 |
#my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
|
|
1550 |
#is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions");
|
|
1551 |
#is($fx_transactions->[0]->amount, '-2.00000', "$title: fx transaction 1: 10.00-( 10.00*0.80000) = 2.00000");
|
|
1552 |
#is($fx_transactions->[1]->amount, '68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511");
|
|
1553 |
#is($fx_transactions->[2]->amount, '-3.40000', "$title: fx transaction 3: 15.30-(15.30 *0.77777) = 3.40012");
|
|
1368 | 1554 |
|
1369 | 1555 |
my $fx_loss_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, chart_id => $fxloss_chart->id ], sort_by => ('acc_trans_id')); |
1370 | 1556 |
my $fx_gain_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, chart_id => $fxgain_chart->id ], sort_by => ('acc_trans_id')); |
1371 | 1557 |
is($fx_gain_transactions->[0]->amount, '0.34000', "$title: fx gain amount ok"); |
1372 | 1558 |
is($fx_loss_transactions->[0]->amount, '-93.28000', "$title: fx loss amount ok"); |
1373 | 1559 |
|
1374 |
is(scalar @{$invoice->transactions}, 14, "$title: ap transaction has 14 transactions (incl. fxtransactions and gain_loss)");
|
|
1560 |
is(scalar @{$invoice->transactions}, 11, "$title: ap transaction has 11 transactions (no fxtransactions and gain_loss)");
|
|
1375 | 1561 |
is($invoice->paid, $invoice->amount, "$title: ap transaction paid = amount in default currency"); |
1376 | 1562 |
is(total_amount($invoice), 0, "$title: even balance"); |
1377 | 1563 |
}; |
... | ... | |
1379 | 1565 |
sub test_ap_currency_tax_not_included_and_payment_2_credit_note { |
1380 | 1566 |
my $title = 'test_ap_currency_tax_not_included_and_payment_2_credit_note'; |
1381 | 1567 |
|
1382 |
my $netamount = $::form->round_amount(-125 * $exchangerate2->sell,2); # 125.00 in CUR, 100.00 in EUR
|
|
1568 |
my $netamount = $::form->round_amount(-125 * $exchangerate2->buy, 2); # 125.00 in CUR, 100.00 in EUR
|
|
1383 | 1569 |
my $amount = $::form->round_amount($netamount * 1.19,2); # 148.75 in CUR, 119.00 in EUR |
1384 | 1570 |
my $invoice = SL::DB::PurchaseInvoice->new( |
1385 | 1571 |
invoice => 0, |
... | ... | |
1411 | 1597 |
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'); |
1412 | 1598 |
|
1413 | 1599 |
$invoice->pay_invoice(chart_id => $bank->id, |
1414 |
amount => -10, |
|
1600 |
amount => -10 * $exchangerate2->buy,
|
|
1415 | 1601 |
currency => 'CUR', |
1416 | 1602 |
transdate => $transdate2->to_kivitendo, |
1603 |
exchangerate => $exchangerate2->buy, |
|
1417 | 1604 |
); |
1418 | 1605 |
$invoice->pay_invoice(chart_id => $bank->id, |
1419 |
amount => -123.45, |
|
1606 |
amount => -123.45 * $exchangerate3->buy,
|
|
1420 | 1607 |
currency => 'CUR', |
1421 | 1608 |
transdate => $transdate3->to_kivitendo, |
1609 |
exchangerate => $exchangerate3->buy, |
|
1422 | 1610 |
); |
1423 | 1611 |
$invoice->pay_invoice(chart_id => $bank->id, |
1424 |
amount => -15.30, |
|
1612 |
amount => -15.30 * $exchangerate4->buy,
|
|
1425 | 1613 |
currency => 'CUR', |
1426 | 1614 |
transdate => $transdate4->to_kivitendo, |
1615 |
exchangerate => $exchangerate4->buy, |
|
1427 | 1616 |
); |
1428 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id')); |
|
1429 |
is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions"); |
|
1430 |
is($fx_transactions->[0]->amount, '2.00000', "$title: fx transaction 1: 10.00-( 10.00*0.80000) = 2.00000"); |
|
1431 |
is($fx_transactions->[1]->amount, '-68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511"); |
|
1432 |
is($fx_transactions->[2]->amount, '3.40000', "$title: fx transaction 3: 15.30-(15.30 *0.77777) = 3.40012"); |
|
1617 |
#my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
|
|
1618 |
#is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions");
|
|
1619 |
#is($fx_transactions->[0]->amount, '2.00000', "$title: fx transaction 1: 10.00-( 10.00*0.80000) = 2.00000");
|
|
1620 |
#is($fx_transactions->[1]->amount, '-68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511");
|
|
1621 |
#is($fx_transactions->[2]->amount, '3.40000', "$title: fx transaction 3: 15.30-(15.30 *0.77777) = 3.40012");
|
|
1433 | 1622 |
|
1434 | 1623 |
my $fx_gain_loss_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, chart_id => $fxgain_chart->id ], sort_by => ('acc_trans_id')); |
1435 | 1624 |
is($fx_gain_loss_transactions->[0]->amount, '93.28000', "$title: fx gain loss amount ok"); |
1436 | 1625 |
|
1437 |
is(scalar @{$invoice->transactions}, 14, "$title: ap transaction has 14 transactions (incl. fxtransactions and gain_loss)");
|
|
1626 |
is(scalar @{$invoice->transactions}, 11, "$title: ap transaction has 11 transactions (no fxtransactions and gain_loss)");
|
|
1438 | 1627 |
is($invoice->paid, $invoice->amount, "$title: ap transaction paid = amount in default currency"); |
1439 | 1628 |
is(total_amount($invoice), 0, "$title: even balance"); |
1440 | 1629 |
}; |
... | ... | |
1458 | 1647 |
|
1459 | 1648 |
$params{amount} = $invoice->amount, |
1460 | 1649 |
|
1461 |
$invoice->pay_invoice( %params ); |
|
1650 |
my @ret = $invoice->pay_invoice( %params ); |
|
1651 |
my $bank_amount = shift @ret; |
|
1652 |
|
|
1653 |
my $exp_invoice_amount = $params{amount}; |
|
1654 |
is($bank_amount->{return_bank_amount}, $exp_invoice_amount, "${title}: invoice_amount"); |
|
1655 |
is($bank_amount->{return_bank_amount} < 0, 1, "${title}: bank invoice_amount is negative (credit note)"); |
|
1462 | 1656 |
|
1463 | 1657 |
my ($number_of_payments, $paid_amount) = number_of_payments($invoice); |
1464 | 1658 |
my $total = total_amount($invoice); |
Auch abrufbar als: Unified diff
Testfälle für payment angepasst