|
Lines 25-30
use POSIX qw( floor );
Link Here
|
| 25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
| 26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
| 27 |
|
27 |
|
|
|
28 |
use C4::Accounts; |
| 28 |
use C4::Calendar; |
29 |
use C4::Calendar; |
| 29 |
use C4::Circulation; |
30 |
use C4::Circulation; |
| 30 |
use C4::Biblio; |
31 |
use C4::Biblio; |
|
Lines 1992-1998
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
| 1992 |
|
1993 |
|
| 1993 |
subtest '_FixAccountForLostAndReturned' => sub { |
1994 |
subtest '_FixAccountForLostAndReturned' => sub { |
| 1994 |
|
1995 |
|
| 1995 |
plan tests => 4; |
1996 |
plan tests => 5; |
| 1996 |
|
1997 |
|
| 1997 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
1998 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
| 1998 |
t::lib::Mocks::mock_preference( 'WhenLostForgiveFine', 0 ); |
1999 |
t::lib::Mocks::mock_preference( 'WhenLostForgiveFine', 0 ); |
|
Lines 2288-2293
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2288 |
'The patron balance is the difference between the PF and the credit' |
2289 |
'The patron balance is the difference between the PF and the credit' |
| 2289 |
); |
2290 |
); |
| 2290 |
}; |
2291 |
}; |
|
|
2292 |
|
| 2293 |
subtest 'Partial payement, existing debits and AccountAutoReconcile' => sub { |
| 2294 |
|
| 2295 |
plan tests => 8; |
| 2296 |
|
| 2297 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2298 |
my $barcode = 'KD123456793'; |
| 2299 |
my $replacement_amount = 100; |
| 2300 |
my $processfee_amount = 20; |
| 2301 |
|
| 2302 |
my $item_type = $builder->build_object( |
| 2303 |
{ class => 'Koha::ItemTypes', |
| 2304 |
value => { |
| 2305 |
notforloan => undef, |
| 2306 |
rentalcharge => 0, |
| 2307 |
defaultreplacecost => undef, |
| 2308 |
processfee => 0 |
| 2309 |
} |
| 2310 |
} |
| 2311 |
); |
| 2312 |
my ( undef, undef, $item_id ) = AddItem( |
| 2313 |
{ homebranch => $library->branchcode, |
| 2314 |
holdingbranch => $library->branchcode, |
| 2315 |
barcode => $barcode, |
| 2316 |
replacementprice => $replacement_amount, |
| 2317 |
itype => $item_type->itemtype |
| 2318 |
}, |
| 2319 |
$biblionumber |
| 2320 |
); |
| 2321 |
|
| 2322 |
AddIssue( $patron->unblessed, $barcode ); |
| 2323 |
|
| 2324 |
# Simulate item marked as lost |
| 2325 |
ModItem( { itemlost => 1 }, $biblionumber, $item_id ); |
| 2326 |
LostItem( $item_id, 1 ); |
| 2327 |
|
| 2328 |
my $lost_fee_lines = Koha::Account::Lines->search( |
| 2329 |
{ borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'L' } ); |
| 2330 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 2331 |
my $lost_fee_line = $lost_fee_lines->next; |
| 2332 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
| 2333 |
is( $lost_fee_line->amountoutstanding + 0, |
| 2334 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
| 2335 |
|
| 2336 |
my $account = $patron->account; |
| 2337 |
is( $account->balance, $replacement_amount, 'Balance is L' ); |
| 2338 |
|
| 2339 |
# Partially pay fee |
| 2340 |
my $payment_amount = 27; |
| 2341 |
my $payment = $account->add_credit( |
| 2342 |
{ amount => $payment_amount, |
| 2343 |
type => 'payment' |
| 2344 |
} |
| 2345 |
); |
| 2346 |
$payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' }); |
| 2347 |
|
| 2348 |
is( $account->balance, |
| 2349 |
$replacement_amount - $payment_amount, |
| 2350 |
'Payment applied' |
| 2351 |
); |
| 2352 |
|
| 2353 |
# TODO use add_debit when time comes |
| 2354 |
my $manual_debit_amount = 80; |
| 2355 |
C4::Accounts::manualinvoice( $patron->id, undef, undef, 'FU', $manual_debit_amount ); |
| 2356 |
|
| 2357 |
is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' ); |
| 2358 |
|
| 2359 |
t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 ); |
| 2360 |
|
| 2361 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id ); |
| 2362 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
| 2363 |
|
| 2364 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (CR)' ); |
| 2365 |
|
| 2366 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'FU' })->next; |
| 2367 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
| 2368 |
}; |
| 2291 |
}; |
2369 |
}; |
| 2292 |
|
2370 |
|
| 2293 |
subtest '_FixOverduesOnReturn' => sub { |
2371 |
subtest '_FixOverduesOnReturn' => sub { |
| 2294 |
- |
|
|