Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 9; |
22 |
use Test::More tests => 10; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
|
24 |
|
25 |
use C4::Circulation qw/AddIssue AddReturn/; |
25 |
use C4::Circulation qw/AddIssue AddReturn/; |
Lines 606-609
subtest "void() tests" => sub {
Link Here
|
606 |
$schema->storage->txn_rollback; |
606 |
$schema->storage->txn_rollback; |
607 |
}; |
607 |
}; |
608 |
|
608 |
|
|
|
609 |
subtest "payout() tests" => sub { |
610 |
|
611 |
plan tests => 17; |
612 |
|
613 |
$schema->storage->txn_begin; |
614 |
|
615 |
# Create a borrower |
616 |
my $categorycode = |
617 |
$builder->build( { source => 'Category' } )->{categorycode}; |
618 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
619 |
|
620 |
my $borrower = Koha::Patron->new( |
621 |
{ |
622 |
cardnumber => 'dariahall', |
623 |
surname => 'Hall', |
624 |
firstname => 'Daria', |
625 |
} |
626 |
); |
627 |
$borrower->categorycode($categorycode); |
628 |
$borrower->branchcode($branchcode); |
629 |
$borrower->store; |
630 |
|
631 |
my $staff = Koha::Patron->new( |
632 |
{ |
633 |
cardnumber => 'bobby', |
634 |
surname => 'Bloggs', |
635 |
firstname => 'Bobby', |
636 |
} |
637 |
); |
638 |
$staff->categorycode($categorycode); |
639 |
$staff->branchcode($branchcode); |
640 |
$staff->store; |
641 |
|
642 |
my $account = Koha::Account->new( { patron_id => $borrower->id } ); |
643 |
|
644 |
my $debit1 = Koha::Account::Line->new( |
645 |
{ |
646 |
borrowernumber => $borrower->borrowernumber, |
647 |
amount => 10, |
648 |
amountoutstanding => 10, |
649 |
interface => 'commandline', |
650 |
debit_type_code => 'OVERDUE' |
651 |
} |
652 |
)->store(); |
653 |
my $credit1 = Koha::Account::Line->new( |
654 |
{ |
655 |
borrowernumber => $borrower->borrowernumber, |
656 |
amount => -20, |
657 |
amountoutstanding => -20, |
658 |
interface => 'commandline', |
659 |
credit_type_code => 'CREDIT' |
660 |
} |
661 |
)->store(); |
662 |
|
663 |
is( $account->balance(), -10, "Account balance is -10" ); |
664 |
is( $debit1->amountoutstanding, |
665 |
10, 'Overdue fee has an amount outstanding of 10' ); |
666 |
is( $credit1->amountoutstanding, |
667 |
-20, 'Credit has an amount outstanding of -20' ); |
668 |
|
669 |
my $pay_params = { |
670 |
interface => 'intranet', |
671 |
staff_id => $staff->borrowernumber, |
672 |
branch => $branchcode, |
673 |
payout_type => 'CASH', |
674 |
amount => 20 |
675 |
}; |
676 |
|
677 |
throws_ok { $debit1->payout($pay_params); } |
678 |
'Koha::Exceptions::Account::IsNotCredit', |
679 |
'->payout() can only be used with credits'; |
680 |
|
681 |
my @required = |
682 |
( 'interface', 'staff_id', 'branch', 'payout_type', 'amount' ); |
683 |
for my $required (@required) { |
684 |
my $params = {%$pay_params}; |
685 |
delete( $params->{$required} ); |
686 |
throws_ok { |
687 |
$credit1->payout($params); |
688 |
} |
689 |
'Koha::Exceptions::MissingParameter', |
690 |
"->payout() requires the `$required` parameter is passed"; |
691 |
} |
692 |
|
693 |
throws_ok { |
694 |
$credit1->payout( |
695 |
{ |
696 |
interface => 'intranet', |
697 |
staff_id => $staff->borrowernumber, |
698 |
branch => $branchcode, |
699 |
payout_type => 'CASH', |
700 |
amount => 25 |
701 |
} |
702 |
); |
703 |
} |
704 |
'Koha::Exceptions::ParameterTooHigh', |
705 |
'->payout() cannot pay out more than the amountoutstanding'; |
706 |
|
707 |
t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 ); |
708 |
throws_ok { |
709 |
$credit1->payout( |
710 |
{ |
711 |
interface => 'intranet', |
712 |
staff_id => $staff->borrowernumber, |
713 |
branch => $branchcode, |
714 |
payout_type => 'CASH', |
715 |
amount => 10 |
716 |
} |
717 |
); |
718 |
} |
719 |
'Koha::Exceptions::Account::RegisterRequired', |
720 |
'->payout() requires a cash_register if payout_type is `CASH`'; |
721 |
|
722 |
t::lib::Mocks::mock_preference( 'UseCashRegisters', 0 ); |
723 |
my $payout = $credit1->payout( |
724 |
{ |
725 |
interface => 'intranet', |
726 |
staff_id => $staff->borrowernumber, |
727 |
branch => $branchcode, |
728 |
payout_type => 'CASH', |
729 |
amount => 10 |
730 |
} |
731 |
); |
732 |
|
733 |
is( $payout->amount(), 10, "Payout amount is 10" ); |
734 |
is( $payout->amountoutstanding(), 0, "Payout amountoutstanding is 0" ); |
735 |
is( $account->balance(), 0, "Account balance is 0" ); |
736 |
is( $debit1->amountoutstanding, |
737 |
10, 'Overdue fee still has an amount outstanding of 10' ); |
738 |
is( $credit1->amountoutstanding, |
739 |
-10, 'Credit has an new amount outstanding of -10' ); |
740 |
is( $credit1->status(), 'PAID', "Credit has a new status of PAID" ); |
741 |
|
742 |
$schema->storage->txn_rollback; |
743 |
}; |
744 |
|
609 |
1; |
745 |
1; |
610 |
- |
|
|