3 # Copyright 2015 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Test::More tests => 27;
26 use t::lib::TestBuilder;
30 use Koha::Account::DebitTypes;
31 use Koha::Account::Lines;
32 use Koha::Account::Offsets;
33 use Koha::Notice::Messages;
34 use Koha::Notice::Templates;
35 use Koha::DateUtils qw( dt_from_string );
37 use C4::Circulation qw( MarkIssueReturned );
40 use_ok('C4::Accounts');
41 use_ok('Koha::Object');
42 use_ok('Koha::Patron');
43 use_ok('Data::Dumper');
46 can_ok( 'C4::Accounts',
49 purge_zero_balance_fees )
52 my $schema = Koha::Database->new->schema;
53 $schema->storage->txn_begin;
54 my $dbh = C4::Context->dbh;
56 my $builder = t::lib::TestBuilder->new;
57 my $library = $builder->build( { source => 'Branch' } );
59 my $branchcode = $library->{branchcode};
61 my $context = Test::MockModule->new('C4::Context');
62 $context->mock( 'userenv', sub {
66 branch => $branchcode,
69 $context->mock( 'interface', sub { return "commandline" } );
70 my $userenv_branchcode = $branchcode;
72 # Testing purge_zero_balance_fees
74 # The 3rd value in the insert is 'days ago' --
79 my $sth = $dbh->prepare(
80 "INSERT INTO accountlines (
89 VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ?, ?, ?, ? )"
95 { amount => 0 , days_ago => 0 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today' , delete => 0, credit_type => undef, debit_type => 'OVERDUE' } ,
96 { amount => 0 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day' , delete => 0, credit_type => undef, debit_type => 'OVERDUE' } ,
97 { amount => 0 , days_ago => $days , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day' , delete => 0, credit_type => undef, debit_type => 'OVERDUE' } ,
98 { amount => 0 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day' , delete => 1, credit_type => undef, debit_type => 'OVERDUE' } ,
99 { amount => undef , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete NULL balance fees with date after threshold day' , delete => 1, credit_type => undef, debit_type => 'OVERDUE' } ,
100 { amount => 5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with positive amout owed before threshold day' , delete => 0, credit_type => undef, debit_type => 'OVERDUE' } ,
101 { amount => 5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with positive amout owed on threshold day' , delete => 0, credit_type => undef, debit_type => 'OVERDUE' } ,
102 { amount => 5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with positive amout owed after threshold day' , delete => 0, credit_type => undef, debit_type => 'OVERDUE' } ,
103 { amount => -5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0, credit_type => 'PAYMENT', debit_type => undef } ,
104 { amount => -5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day' , delete => 0, credit_type => 'PAYMENT', debit_type => undef } ,
105 { amount => -5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day' , delete => 0, credit_type => 'PAYMENT', debit_type => undef }
107 my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
108 my $borrower = Koha::Patron->new( { firstname => 'Test', surname => 'Patron', categorycode => $categorycode, branchcode => $branchcode } )->store();
110 for my $data ( @test_data ) {
112 $borrower->borrowernumber,
115 $data->{description},
117 $data->{credit_type},
122 purge_zero_balance_fees( $days );
124 $sth = $dbh->prepare(
125 "select count(*) = 0 as deleted
127 where description = ?"
131 sub is_delete_correct {
132 my $should_delete = shift;
133 my $description = shift;
134 $sth->execute( $description );
135 my $test = $sth->fetchrow_hashref();
136 is( $test->{deleted}, $should_delete, $description )
139 for my $data (@test_data) {
140 is_delete_correct( $data->{delete}, $data->{description});
143 $dbh->do(q|DELETE FROM accountlines|);
145 subtest "Koha::Account::pay tests" => sub {
150 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
151 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
153 my $borrower = Koha::Patron->new( {
154 cardnumber => '1234567890',
156 firstname => 'Marty',
158 $borrower->categorycode( $categorycode );
159 $borrower->branchcode( $branchcode );
162 my $account = Koha::Account->new({ patron_id => $borrower->id });
164 my $line1 = $account->add_debit({ type => 'ACCOUNT', amount => 100, interface => 'commandline' });
165 my $line2 = $account->add_debit({ type => 'ACCOUNT', amount => 200, interface => 'commandline' });
167 $sth = $dbh->prepare("SELECT count(*) FROM accountlines");
169 my $count = $sth->fetchrow_array;
170 is($count, 2, 'There is 2 lines as expected');
172 # There is $100 in the account
173 $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
174 my $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
176 for my $line ( @$amountoutstanding ) {
177 $amountleft += $line;
179 is($amountleft, 300, 'The account has 300$ as expected' );
181 # We make a $20 payment
182 my $borrowernumber = $borrower->borrowernumber;
184 my $payment_note = '$20.00 payment note';
185 my $id = $account->pay( { amount => $data, note => $payment_note, payment_type => "TEST_TYPE" } )->{payment_id};
187 my $accountline = Koha::Account::Lines->find( $id );
188 is( $accountline->payment_type, "TEST_TYPE", "Payment type passed into pay is set in account line correctly" );
190 # There is now $280 in the account
191 $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
192 $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
194 for my $line ( @$amountoutstanding ) {
195 $amountleft += $line;
197 is($amountleft, 280, 'The account has $280 as expected' );
199 # Is the payment note well registered
200 $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
201 $sth->execute($borrower->borrowernumber);
202 my $note = $sth->fetchrow_array;
203 is($note,'$20.00 payment note', '$20.00 payment note is registered');
205 # We attempt to make a -$30 payment (a NEGATIVE payment)
207 $payment_note = '-$30.00 payment note';
208 throws_ok { $account->pay( { amount => $data, note => $payment_note } ) } 'Koha::Exceptions::Account::AmountNotPositive', 'Croaked on call to pay with negative amount';
210 #We make a $150 payment ( > 1stLine )
212 $payment_note = '$150.00 payment note';
213 $account->pay( { amount => $data, note => $payment_note } );
215 # There is now $130 in the account
216 $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
217 $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
219 for my $line ( @$amountoutstanding ) {
220 $amountleft += $line;
222 is($amountleft, 130, 'The account has $130 as expected' );
224 # Is the payment note well registered
225 $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
226 $sth->execute($borrower->borrowernumber);
227 $note = $sth->fetchrow_array;
228 is($note,'$150.00 payment note', '$150.00 payment note is registered');
230 #We make a $200 payment ( > amountleft )
232 $payment_note = '$200.00 payment note';
233 $account->pay( { amount => $data, note => $payment_note } );
235 # There is now -$70 in the account
236 $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
237 $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
239 for my $line ( @$amountoutstanding ) {
240 $amountleft += $line;
242 is($amountleft, -70, 'The account has -$70 as expected, (credit situation)' );
244 # Is the payment note well registered
245 $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
246 $sth->execute($borrower->borrowernumber);
247 $note = $sth->fetchrow_array;
248 is($note,'$200.00 payment note', '$200.00 payment note is registered');
250 my $line3 = $account->add_debit({ type => 'ACCOUNT', amount => 42, interface => 'commandline' });
251 my $payment_id = $account->pay( { lines => [$line3], amount => 42 } )->{payment_id};
252 my $payment = Koha::Account::Lines->find( $payment_id );
253 is( $payment->amount()+0, -42, "Payment paid the specified fine" );
254 $line3 = Koha::Account::Lines->find( $line3->id );
255 is( $line3->amountoutstanding+0, 0, "Specified fine is paid" );
256 is( $payment->branchcode, undef, 'branchcode passed, then undef' );
259 subtest "Koha::Account::pay particular line tests" => sub {
264 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
265 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
267 my $borrower = Koha::Patron->new( {
268 cardnumber => 'kylemhall',
272 $borrower->categorycode( $categorycode );
273 $borrower->branchcode( $branchcode );
276 my $account = Koha::Account->new({ patron_id => $borrower->id });
278 my $line1 = $account->add_debit({ type => 'ACCOUNT', amount => 1, interface => 'commandline' });
279 my $line2 = $account->add_debit({ type => 'ACCOUNT', amount => 2, interface => 'commandline' });
280 my $line3 = $account->add_debit({ type => 'ACCOUNT', amount => 3, interface => 'commandline' });
281 my $line4 = $account->add_debit({ type => 'ACCOUNT', amount => 4, interface => 'commandline' });
283 is( $account->balance(), 10, "Account balance is 10" );
287 lines => [$line2, $line3, $line4],
292 $_->_result->discard_changes foreach ( $line1, $line2, $line3, $line4 );
294 # Line1 is not paid at all, as it was not passed in the lines param
295 is( $line1->amountoutstanding+0, 1, "Line 1 was not paid" );
296 # Line2 was paid in full, as it was the first in the lines list
297 is( $line2->amountoutstanding+0, 0, "Line 2 was paid in full" );
298 # Line3 was paid partially, as the remaining balance did not cover it entirely
299 is( $line3->amountoutstanding+0, 1, "Line 3 was paid to 1.00" );
300 # Line4 was not paid at all, as the payment was all used up by that point
301 is( $line4->amountoutstanding+0, 4, "Line 4 was not paid" );
304 subtest "Koha::Account::pay writeoff tests" => sub {
309 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
310 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
312 my $borrower = Koha::Patron->new( {
313 cardnumber => 'chelseahall',
315 firstname => 'Chelsea',
317 $borrower->categorycode( $categorycode );
318 $borrower->branchcode( $branchcode );
321 my $account = Koha::Account->new({ patron_id => $borrower->id });
323 my $line = $account->add_debit({ type => 'ACCOUNT', amount => 42, interface => 'commandline' });
325 is( $account->balance(), 42, "Account balance is 42" );
327 my $id = $account->pay(
335 $line->_result->discard_changes();
337 is( $line->amountoutstanding+0, 0, "Line was written off" );
339 my $writeoff = Koha::Account::Lines->find( $id );
341 is( $writeoff->credit_type_code, 'WRITEOFF', 'Type is correct for WRITEOFF' );
342 is( $writeoff->description, '', 'Description is correct' );
343 is( $writeoff->amount+0, -42, 'Amount is correct' );
346 subtest "More Koha::Account::pay tests" => sub {
351 my $category = $builder->build({ source => 'Category' })->{ categorycode };
352 my $branch = $builder->build({ source => 'Branch' })->{ branchcode };
353 $branchcode = $branch;
354 my $borrowernumber = $builder->build({
355 source => 'Borrower',
356 value => { categorycode => $category,
357 branchcode => $branch }
358 })->{ borrowernumber };
361 my $accountline = $builder->build(
363 source => 'Accountline',
365 borrowernumber => $borrowernumber,
367 amountoutstanding => $amount,
368 credit_type_code => undef,
373 my $rs = $schema->resultset('Accountline')->search({
374 borrowernumber => $borrowernumber
377 is( $rs->count(), 1, 'Accountline created' );
379 my $account = Koha::Account->new( { patron_id => $borrowernumber } );
380 my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
381 # make the full payment
382 $account->pay({ lines => [$line], amount => $amount, library_id => $branch, note => 'A payment note' });
384 my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->{accountlines_id} })->next();
385 is( $offset->amount+0, -100, 'Offset amount is -100.00' );
386 is( $offset->type(), 'Payment', 'Offset type is Payment' );
388 my $stat = $schema->resultset('Statistic')->search({
391 }, { order_by => { -desc => 'datetime' } })->next();
393 ok( defined $stat, "There's a payment log that matches the branch" );
396 skip "No statistic logged", 4 unless defined $stat;
398 is( $stat->type, 'payment', "Correct statistic type" );
399 is( $stat->branch, $branch, "Correct branch logged to statistics" );
400 is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" );
401 is( $stat->value+0, -$amount, "Correct amount logged to statistics" );
405 subtest "Even more Koha::Account::pay tests" => sub {
410 my $category = $builder->build({ source => 'Category' })->{ categorycode };
411 my $branch = $builder->build({ source => 'Branch' })->{ branchcode };
412 $branchcode = $branch;
413 my $borrowernumber = $builder->build({
414 source => 'Borrower',
415 value => { categorycode => $category,
416 branchcode => $branch }
417 })->{ borrowernumber };
420 my $partialamount = 60;
421 my $accountline = $builder->build(
423 source => 'Accountline',
425 borrowernumber => $borrowernumber,
427 amountoutstanding => $amount,
428 credit_type_code => undef,
433 my $rs = $schema->resultset('Accountline')->search({
434 borrowernumber => $borrowernumber
437 is( $rs->count(), 1, 'Accountline created' );
439 my $account = Koha::Account->new( { patron_id => $borrowernumber } );
440 my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
441 # make the full payment
442 $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' });
444 my $offset = Koha::Account::Offsets->search( { debit_id => $accountline->{ accountlines_id } } )->next();
445 is( $offset->amount+0, -60, 'Offset amount is -60.00' );
446 is( $offset->type, 'Payment', 'Offset type is payment' );
448 my $stat = $schema->resultset('Statistic')->search({
451 }, { order_by => { -desc => 'datetime' } })->next();
453 ok( defined $stat, "There's a payment log that matches the branch" );
456 skip "No statistic logged", 4 unless defined $stat;
458 is( $stat->type, 'payment', "Correct statistic type" );
459 is( $stat->branch, $branch, "Correct branch logged to statistics" );
460 is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" );
461 is( $stat->value+0, -$partialamount, "Correct amount logged to statistics" );
465 subtest 'balance' => sub {
468 my $patron = $builder->build({source => 'Borrower'});
469 $patron = Koha::Patrons->find( $patron->{borrowernumber} );
470 my $account = $patron->account;
471 is( $account->balance, 0, 'balance should return 0 if the patron does not have fines' );
473 my $accountline_1 = $builder->build(
475 source => 'Accountline',
477 borrowernumber => $patron->borrowernumber,
479 amountoutstanding => 42,
480 credit_type_code => undef,
484 my $accountline_2 = $builder->build(
486 source => 'Accountline',
488 borrowernumber => $patron->borrowernumber,
490 amountoutstanding => -13,
491 debit_type_code => undef,
496 my $balance = $patron->account->balance;
497 is( int($balance), 29, 'balance should return the correct value');
502 subtest "C4::Accounts::chargelostitem tests" => sub {
505 my $branch = $builder->build( { source => 'Branch' } );
506 my $branchcode = $branch->{branchcode};
508 my $staff = $builder->build( { source => 'Borrower' } );
509 my $staff_id = $staff->{borrowernumber};
511 my $module = Test::MockModule->new('C4::Context');
518 branch => $branchcode,
523 my $itype_no_replace_no_fee = $builder->build({ source => 'Itemtype', value => {
525 defaultreplacecost => undef,
528 my $itype_replace_no_fee = $builder->build({ source => 'Itemtype', value => {
530 defaultreplacecost => 16.32,
533 my $itype_no_replace_fee = $builder->build({ source => 'Itemtype', value => {
535 defaultreplacecost => undef,
538 my $itype_replace_fee = $builder->build({ source => 'Itemtype', value => {
540 defaultreplacecost => 4.08,
543 my $cli_borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'};
544 my $cli_itemnumber1 = $builder->build_sample_item({ itype => $itype_no_replace_no_fee->{itemtype} })->itemnumber;
545 my $cli_itemnumber2 = $builder->build_sample_item({ itype => $itype_replace_no_fee->{itemtype} })->itemnumber;
546 my $cli_itemnumber3 = $builder->build_sample_item({ itype => $itype_no_replace_fee->{itemtype} })->itemnumber;
547 my $cli_itemnumber4 = $builder->build_sample_item({ itype => $itype_replace_fee->{itemtype} })->itemnumber;
549 my $cli_issue_id_1 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1 } })->{issue_id};
550 my $cli_issue_id_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2 } })->{issue_id};
551 my $cli_issue_id_3 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3 } })->{issue_id};
552 my $cli_issue_id_4 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id};
553 my $cli_issue_id_4X = undef;
558 subtest "fee application tests" => sub {
561 t::lib::Mocks::mock_preference('item-level_itypes', '1');
562 t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
564 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
565 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' });
566 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PROCESSING' });
567 ok( !$lostfine, "No lost fine if no replacementcost or default when pref off");
568 ok( !$procfee, "No processing fee if no processing fee");
569 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
570 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' });
571 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PROCESSING' });
572 ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set");
573 ok( !$procfee, "No processing fee if no processing fee");
576 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
577 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' });
578 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PROCESSING' });
579 ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
580 ok( !$procfee, "No processing fee if no processing fee");
581 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
582 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' });
583 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PROCESSING' });
584 ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
585 ok( !$procfee, "No processing fee if no processing fee");
588 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
589 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' });
590 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PROCESSING' });
591 ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off");
592 ok( $procfee->amount == 8.16, "Processing fee if processing fee");
593 is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
595 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
596 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' });
597 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PROCESSING' });
598 ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set");
599 ok( $procfee->amount == 8.16, "Processing fee if processing fee");
600 is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
604 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
605 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
606 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
607 ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
608 ok( $procfee->amount == 2.04, "Processing fee if processing fee");
609 is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
611 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
612 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
613 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
614 ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
615 ok( $procfee->amount == 2.04, "Processing fee if processing fee");
616 is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
620 t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
622 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
623 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' });
624 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PROCESSING' });
625 ok( !$lostfine, "No lost fine if no replacementcost or default when pref on");
626 ok( !$procfee, "No processing fee if no processing fee");
627 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
628 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' });
629 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PROCESSING' });
630 is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
631 ok( !$procfee, "No processing fee if no processing fee");
633 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
634 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' });
635 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PROCESSING' });
636 is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on");
637 ok( !$procfee, "No processing fee if no processing fee");
639 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
640 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' });
641 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PROCESSING' });
642 is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set");
643 ok( !$procfee, "No processing fee if no processing fee");
645 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
646 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' });
647 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PROCESSING' });
648 ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on");
649 is( $procfee->amount, "8.160000", "Processing fee if processing fee");
650 is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
652 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
653 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' });
654 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PROCESSING' });
655 is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
656 is( $procfee->amount, "8.160000", "Processing fee if processing fee");
657 is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
659 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
660 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
661 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
662 is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on");
663 is( $procfee->amount, "2.040000", "Processing fee if processing fee");
664 is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
667 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
668 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
669 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
670 is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
671 is( $procfee->amount, "2.040000", "Processing fee if processing fee");
672 is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
673 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
674 my $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
675 my $procfees = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
676 ok( $lostfines->count == 1 , "Lost fine cannot be double charged for the same issue_id");
677 ok( $procfees->count == 1, "Processing fee cannot be double charged for the same issue_id");
678 MarkIssueReturned($cli_borrowernumber, $cli_itemnumber4);
679 $cli_issue_id_4X = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id};
680 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
681 $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
682 $procfees = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
683 ok( $lostfines->count == 2 , "Lost fine can be charged twice for the same item if they are distinct issue_id's");
684 ok( $procfees->count == 2, "Processing fee can be charged twice for the same item if they are distinct issue_id's");
685 $lostfines->delete();
689 subtest "basic fields tests" => sub {
692 t::lib::Mocks::mock_preference('ProcessingFeeNote', 'Test Note');
693 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, '1.99', "Perdedor");
696 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
697 ok($lostfine, "Lost fine created");
698 is($lostfine->manager_id, $staff_id, "Lost fine manager_id set correctly");
699 is($lostfine->issue_id, $cli_issue_id_4X, "Lost fine issue_id set correctly");
700 is($lostfine->description, "Perdedor", "Lost fine issue_id set correctly");
701 is($lostfine->note, '', "Lost fine does not contain a note");
702 is($lostfine->branchcode, $branchcode, "Lost fine branchcode set correctly");
705 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
706 ok($procfee, "Processing fee created");
707 is($procfee->manager_id, $staff_id, "Processing fee manager_id set correctly");
708 is($procfee->issue_id, $cli_issue_id_4X, "Processing fee issue_id set correctly");
709 is($procfee->description, "Perdedor", "Processing fee issue_id set correctly");
710 is($procfee->note, C4::Context->preference("ProcessingFeeNote"), "Processing fee contains note matching ProcessingFeeNote");
711 is($procfee->branchcode, $branchcode, "Processing fee branchcode set correctly");
716 subtest "FinesLog tests" => sub {
719 my $action_logs = $schema->resultset('ActionLog')->search()->count;
721 t::lib::Mocks::mock_preference( 'FinesLog', 0 );
722 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
723 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
724 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
725 is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No logs were added' );
729 t::lib::Mocks::mock_preference( 'FinesLog', 1 );
730 C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
731 $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
732 $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PROCESSING' });
733 is( $schema->resultset('ActionLog')->count(), $action_logs + 2, 'Logs were added' );
738 # Cleanup - this must be replaced with a transaction per subtest
739 Koha::Patrons->find($cli_borrowernumber)->checkouts->delete;
742 subtest "Koha::Account::non_issues_charges tests" => sub {
745 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
746 my $account = $patron->account;
753 description => 'a Res fee',
756 interface => 'commandline'
761 description => 'a Rental fee',
764 interface => 'commandline'
767 Koha::Account::DebitTypes->find_or_create(
770 description => 'Fee for copie',
774 Koha::Account::Line->new(
776 borrowernumber => $patron->borrowernumber,
777 description => 'a Manual invoice fee',
778 debit_type_code => 'Copie',
779 amountoutstanding => $manual,
780 interface => 'commandline'
785 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
786 t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
787 t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 );
788 my ( $total, $non_issues_charges ) = ( $account->balance, $account->non_issues_charges );
789 my $other_charges = $total - $non_issues_charges;
792 $res + $rent + $manual,
793 'Total charges should be Res + Rent + Manual'
795 is( $non_issues_charges, 0,
796 'If 0|0|0 there should not have non issues charges' );
797 is( $other_charges, 15, 'If 0|0|0 there should only have other charges' );
799 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
800 t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
801 t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 );
802 ( $total, $non_issues_charges ) = ( $account->balance, $account->non_issues_charges );
803 $other_charges = $total - $non_issues_charges;
806 $res + $rent + $manual,
807 'Total charges should be Res + Rent + Manual'
809 is( $non_issues_charges, $manual,
810 'If 0|0|1 Only Manual should be a non issue charge' );
814 'If 0|0|1 Res + Rent should be other charges'
817 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
818 t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
819 t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 );
820 ( $total, $non_issues_charges ) = ( $account->balance, $account->non_issues_charges );
821 $other_charges = $total - $non_issues_charges;
824 $res + $rent + $manual,
825 'Total charges should be Res + Rent + Manual'
827 is( $non_issues_charges, $rent,
828 'If 0|1|0 Only Rental should be a non issue charge' );
832 'If 0|1|0 Rent + Manual should be other charges'
835 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
836 t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
837 t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 );
838 ( $total, $non_issues_charges ) = ( $account->balance, $account->non_issues_charges );
839 $other_charges = $total - $non_issues_charges;
842 $res + $rent + $manual,
843 'Total charges should be Res + Rent + Manual'
848 'If 0|1|1 Rent + Manual should be non issues charges'
850 is( $other_charges, $res, 'If 0|1|1 there should only have other charges' );
852 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 );
853 t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
854 t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 );
855 ( $total, $non_issues_charges ) = ( $account->balance, $account->non_issues_charges );
856 $other_charges = $total - $non_issues_charges;
859 $res + $rent + $manual,
860 'Total charges should be Res + Rent + Manual'
862 is( $non_issues_charges, $res,
863 'If 1|0|0 Only Res should be non issues charges' );
867 'If 1|0|0 Rent + Manual should be other charges'
870 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 );
871 t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
872 t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 );
873 ( $total, $non_issues_charges ) = ( $account->balance, $account->non_issues_charges );
874 $other_charges = $total - $non_issues_charges;
877 $res + $rent + $manual,
878 'Total charges should be Res + Rent + Manual'
883 'If 1|1|0 Res + Rent should be non issues charges'
885 is( $other_charges, $manual,
886 'If 1|1|0 Only Manual should be other charges' );
888 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 );
889 t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
890 t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 );
891 ( $total, $non_issues_charges ) = ( $account->balance, $account->non_issues_charges );
892 $other_charges = $total - $non_issues_charges;
895 $res + $rent + $manual,
896 'Total charges should be Res + Rent + Manual'
900 $res + $rent + $manual,
901 'If 1|1|1 Res + Rent + Manual should be non issues charges'
903 is( $other_charges, 0, 'If 1|1|1 there should not have any other charges' );
906 subtest "Koha::Account::non_issues_charges tests" => sub {
909 my $patron = $builder->build_object(
911 class => "Koha::Patrons",
915 categorycode => $categorycode,
916 branchcode => $branchcode
921 my $debit = Koha::Account::Line->new(
923 borrowernumber => $patron->id,
924 date => '1970-01-01 00:00:01',
925 amountoutstanding => 0,
926 interface => 'commandline',
927 debit_type_code => 'LOST'
930 my $credit = Koha::Account::Line->new(
932 borrowernumber => $patron->id,
933 date => '1970-01-01 00:00:01',
934 amountoutstanding => -5,
935 interface => 'commandline',
936 credit_type_code => 'PAYMENT'
939 my $offset = Koha::Account::Offset->new(
941 credit_id => $credit->id,
942 debit_id => $debit->id,
947 purge_zero_balance_fees( 1 );
948 my $debit_2 = Koha::Account::Lines->find( $debit->id );
949 my $credit_2 = Koha::Account::Lines->find( $credit->id );
950 ok( $debit_2, 'Debit was correctly not deleted when credit has balance' );
951 ok( $credit_2, 'Credit was correctly not deleted when credit has balance' );
952 is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2, "The 2 account lines still exists" );
954 $debit = Koha::Account::Line->new(
956 borrowernumber => $patron->id,
957 date => '1970-01-01 00:00:01',
958 amountoutstanding => 5,
959 interface => 'commanline',
960 debit_type_code => 'LOST'
963 $credit = Koha::Account::Line->new(
965 borrowernumber => $patron->id,
966 date => '1970-01-01 00:00:01',
967 amountoutstanding => 0,
968 interface => 'commandline',
969 credit_type_code => 'PAYMENT'
972 $offset = Koha::Account::Offset->new(
974 credit_id => $credit->id,
975 debit_id => $debit->id,
980 purge_zero_balance_fees( 1 );
981 $debit_2 = $credit_2 = undef;
982 $debit_2 = Koha::Account::Lines->find( $debit->id );
983 $credit_2 = Koha::Account::Lines->find( $credit->id );
984 ok( $debit_2, 'Debit was correctly not deleted when debit has balance' );
985 ok( $credit_2, 'Credit was correctly not deleted when debit has balance' );
986 is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists" );
988 $debit = Koha::Account::Line->new(
990 borrowernumber => $patron->id,
991 date => '1970-01-01 00:00:01',
992 amountoutstanding => 0,
993 interface => 'commandline',
994 debit_type_code => 'LOST'
997 $credit = Koha::Account::Line->new(
999 borrowernumber => $patron->id,
1000 date => '1970-01-01 00:00:01',
1001 amountoutstanding => 0,
1002 interface => 'commandline',
1003 credit_type_code => 'PAYMENT'
1006 $offset = Koha::Account::Offset->new(
1008 credit_id => $credit->id,
1009 debit_id => $debit->id,
1014 purge_zero_balance_fees( 1 );
1015 $debit_2 = Koha::Account::Lines->find( $debit->id );
1016 $credit_2 = Koha::Account::Lines->find( $credit->id );
1017 ok( !$debit_2, 'Debit was correctly deleted' );
1018 ok( !$credit_2, 'Credit was correctly deleted' );
1019 is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
1023 subtest "Koha::Account::Offset credit & debit tests" => sub {
1028 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
1029 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
1031 my $borrower = Koha::Patron->new( {
1032 cardnumber => 'kyliehall',
1034 firstname => 'Kylie',
1036 $borrower->categorycode( $categorycode );
1037 $borrower->branchcode( $branchcode );
1040 my $account = Koha::Account->new({ patron_id => $borrower->id });
1042 my $line1 = Koha::Account::Line->new(
1044 borrowernumber => $borrower->borrowernumber,
1046 amountoutstanding => 10,
1047 interface => 'commandline',
1048 debit_type_code => 'LOST'
1051 my $line2 = Koha::Account::Line->new(
1053 borrowernumber => $borrower->borrowernumber,
1055 amountoutstanding => 20,
1056 interface => 'commandline',
1057 debit_type_code => 'LOST'
1061 my $id = $account->pay(
1063 lines => [$line1, $line2],
1068 # Test debit and credit methods for Koha::Account::Offset
1069 my $account_offset = Koha::Account::Offsets->find( { credit_id => $id, debit_id => $line1->id } );
1070 is( $account_offset->debit->id, $line1->id, "Koha::Account::Offset->debit gets correct accountline" );
1071 is( $account_offset->credit->id, $id, "Koha::Account::Offset->credit gets correct accountline" );
1073 $account_offset = Koha::Account::Offset->new(
1082 is( $account_offset->debit, undef, "Koha::Account::Offset->debit returns undef if no associated debit" );
1083 is( $account_offset->credit, undef, "Koha::Account::Offset->credit returns undef if no associated credit" );
1086 subtest "Payment notice tests" => sub {
1090 Koha::Notice::Messages->delete();
1092 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
1094 my $manager = $builder->build_object({ class => "Koha::Patrons" });
1095 my $context = Test::MockModule->new('C4::Context');
1096 $context->mock( 'userenv', sub {
1098 number => $manager->borrowernumber,
1099 branch => $manager->branchcode,
1102 my $account = Koha::Account->new({ patron_id => $patron->borrowernumber });
1104 my $line = Koha::Account::Line->new(
1106 borrowernumber => $patron->borrowernumber,
1107 amountoutstanding => 27,
1108 interface => 'commandline',
1109 debit_type_code => 'LOST'
1113 my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } );
1114 $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account. Your [% branch.branchcode %]');
1117 t::lib::Mocks::mock_preference('UseEmailReceipts', '0');
1118 my $id = $account->pay( { amount => 1 } )->{payment_id};
1119 is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' );
1121 $id = $account->pay( { amount => 1, type => 'WRITEOFF' } )->{payment_id};
1122 is( Koha::Notice::Messages->search()->count(), 0, 'Notice for writeoff not sent if UseEmailReceipts is disabled' );
1124 t::lib::Mocks::mock_preference('UseEmailReceipts', '1');
1126 $id = $account->pay( { amount => 12, library_id => $branchcode } )->{payment_id};
1127 my $notice = Koha::Notice::Messages->search()->next();
1128 is( $notice->subject, 'Account payment', 'Notice subject is correct for payment' );
1129 is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' );
1130 is( $notice->content, "A payment of 12.00 has been applied to your account. Your $branchcode", 'Notice content is correct for payment' );
1133 $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_WRITEOFF' } );
1134 $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account. Your [% branch.branchcode %]');
1137 $id = $account->pay( { amount => 13, type => 'WRITEOFF', library_id => $branchcode } )->{payment_id};
1138 $notice = Koha::Notice::Messages->search()->next();
1139 is( $notice->subject, 'Account writeoff', 'Notice subject is correct for payment' );
1140 is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' );
1141 is( $notice->content, "A writeoff of 13.00 has been applied to your account. Your $branchcode", 'Notice content is correct for writeoff' );