|
Lines 28-33
use t::lib::Mocks;
Link Here
|
| 28 |
use Koha::Account; |
28 |
use Koha::Account; |
| 29 |
use Koha::Account::Lines; |
29 |
use Koha::Account::Lines; |
| 30 |
use Koha::Account::Offsets; |
30 |
use Koha::Account::Offsets; |
|
|
31 |
use Koha::Notice::Messages; |
| 32 |
use Koha::Notice::Templates; |
| 31 |
use Koha::DateUtils qw( dt_from_string ); |
33 |
use Koha::DateUtils qw( dt_from_string ); |
| 32 |
|
34 |
|
| 33 |
BEGIN { |
35 |
BEGIN { |
|
Lines 904-943
subtest "Koha::Account::Line::void tests" => sub {
Link Here
|
| 904 |
is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' ); |
906 |
is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' ); |
| 905 |
}; |
907 |
}; |
| 906 |
|
908 |
|
| 907 |
subtest "Koha::Account::Offset tests" => sub { |
909 |
subtest "Payment notice tests" => sub { |
| 908 |
|
910 |
|
| 909 |
plan tests => 2; |
911 |
plan tests => 6; |
| 910 |
|
912 |
|
| 911 |
Koha::Account::Lines->delete(); |
913 |
Koha::Account::Lines->delete(); |
| 912 |
Koha::Patrons->delete(); |
914 |
Koha::Patrons->delete(); |
| 913 |
|
915 |
Koha::Notice::Messages->delete(); |
| 914 |
# Create a borrower |
916 |
# Create a borrower |
| 915 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
917 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
| 916 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
918 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
| 917 |
|
919 |
|
| 918 |
my $borrower = Koha::Patron->new( { |
920 |
my $borrower = Koha::Patron->new( |
| 919 |
cardnumber => 'chelseahall', |
921 |
{ |
| 920 |
surname => 'Hall', |
922 |
cardnumber => 'chelseahall', |
| 921 |
firstname => 'Chelsea', |
923 |
surname => 'Hall', |
| 922 |
} ); |
924 |
firstname => 'Chelsea', |
| 923 |
$borrower->categorycode( $categorycode ); |
925 |
email => 'chelsea@example.com', |
| 924 |
$borrower->branchcode( $branchcode ); |
926 |
categorycode => $categorycode, |
| 925 |
$borrower->store; |
927 |
branchcode => $branchcode, |
|
|
928 |
} |
| 929 |
)->store(); |
| 926 |
|
930 |
|
| 927 |
my $account = Koha::Account->new({ patron_id => $borrower->id }); |
931 |
my $account = Koha::Account->new({ patron_id => $borrower->id }); |
| 928 |
|
932 |
|
| 929 |
my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store(); |
933 |
my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store(); |
| 930 |
|
934 |
|
| 931 |
my $id = $account->pay( |
935 |
my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } ); |
| 932 |
{ |
936 |
$letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.'); |
| 933 |
amount => 13, |
937 |
$letter->store(); |
| 934 |
} |
938 |
|
| 935 |
); |
939 |
my $id = $account->pay( { amount => 13 } ); |
| 936 |
|
940 |
my $notice = Koha::Notice::Messages->search()->next(); |
| 937 |
my $offset = Koha::Account::Offsets->find( { credit_id => $id } ); |
941 |
is( $notice->subject, 'Account Payment', 'Notice subject is correct for payment' ); |
| 938 |
|
942 |
is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' ); |
| 939 |
is( $offset->credit->id, $id, 'Got correct credit for account offset' ); |
943 |
is( $notice->content, 'A payment of 13.00 has been applied to your account.', 'Notice content is correct for payment' ); |
| 940 |
is( $offset->debit->id, $line->id, 'Got correct debit for account offset' ); |
944 |
$notice->delete(); |
|
|
945 |
|
| 946 |
$letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_WRITEOFF' } ); |
| 947 |
$letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.'); |
| 948 |
$letter->store(); |
| 949 |
|
| 950 |
$id = $account->pay( { amount => 14, type => 'writeoff' } ); |
| 951 |
$notice = Koha::Notice::Messages->search()->next(); |
| 952 |
is( $notice->subject, 'Account Writeoff', 'Notice subject is correct for payment' ); |
| 953 |
is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' ); |
| 954 |
is( $notice->content, 'A writeoff of 14.00 has been applied to your account.', 'Notice content is correct for writeoff' ); |
| 941 |
}; |
955 |
}; |
| 942 |
|
956 |
|
| 943 |
1; |
957 |
1; |
| 944 |
- |
|
|