Lines 26-31
use C4::Circulation qw/AddIssue AddReturn/;
Link Here
|
26 |
use Koha::Account; |
26 |
use Koha::Account; |
27 |
use Koha::Account::Lines; |
27 |
use Koha::Account::Lines; |
28 |
use Koha::Account::Offsets; |
28 |
use Koha::Account::Offsets; |
|
|
29 |
use Koha::DateUtils; |
29 |
use Koha::Items; |
30 |
use Koha::Items; |
30 |
|
31 |
|
31 |
use t::lib::Mocks; |
32 |
use t::lib::Mocks; |
Lines 209-215
subtest 'is_credit() and is_debit() tests' => sub {
Link Here
|
209 |
|
210 |
|
210 |
subtest 'apply() tests' => sub { |
211 |
subtest 'apply() tests' => sub { |
211 |
|
212 |
|
212 |
plan tests => 24; |
213 |
plan tests => 25; |
213 |
|
214 |
|
214 |
$schema->storage->txn_begin; |
215 |
$schema->storage->txn_begin; |
215 |
|
216 |
|
Lines 319-324
subtest 'apply() tests' => sub {
Link Here
|
319 |
is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); |
320 |
is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); |
320 |
is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); |
321 |
is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); |
321 |
is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); |
322 |
is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); |
|
|
323 |
|
324 |
my $loser = $builder->build_object( { class => 'Koha::Patrons' } ); |
325 |
my $loser_account = $loser->account; |
326 |
|
327 |
|
328 |
my $now = dt_from_string(); |
329 |
my $seven_weeks = DateTime::Duration->new(weeks => 7); |
330 |
my $five_weeks = DateTime::Duration->new(weeks => 5); |
331 |
my $seven_weeks_ago = $now - $seven_weeks; |
332 |
my $five_weeks_ago = $now - $five_weeks; |
333 |
|
334 |
my $lost_item = $builder->build_sample_item(); |
335 |
my $lost_checkout = Koha::Checkout->new( |
336 |
{ |
337 |
borrowernumber => $loser->id, |
338 |
itemnumber => $lost_item->id, |
339 |
date_due => $five_weeks_ago, |
340 |
branchcode => $loser->branchcode, |
341 |
issuedate => $seven_weeks_ago |
342 |
} |
343 |
)->store(); |
344 |
|
345 |
$lost_item->itemlost(1)->store; |
346 |
my $processing_fee = Koha::Account::Line->new( |
347 |
{ |
348 |
issue_id => $lost_checkout->id, |
349 |
borrowernumber => $loser->id, |
350 |
itemnumber => $lost_item->id, |
351 |
branchcode => $loser->branchcode, |
352 |
date => \'NOW()', |
353 |
debit_type_code => 'PROCESSING', |
354 |
status => undef, |
355 |
interface => 'intranet', |
356 |
amount => '15', |
357 |
amountoutstanding => '15', |
358 |
} |
359 |
)->store(); |
360 |
my $lost_fee = Koha::Account::Line->new( |
361 |
{ |
362 |
issue_id => $lost_checkout->id, |
363 |
borrowernumber => $loser->id, |
364 |
itemnumber => $lost_item->id, |
365 |
branchcode => $loser->branchcode, |
366 |
date => \'NOW()', |
367 |
debit_type_code => 'LOST', |
368 |
status => undef, |
369 |
interface => 'intranet', |
370 |
amount => '12.63', |
371 |
amountoutstanding => '12.63', |
372 |
} |
373 |
)->store(); |
374 |
my $pay_lost = $loser_account->add_credit({ amount => 27.630000, user_id => $loser->id, interface => 'intranet' }); |
375 |
my $pay_lines = [ $processing_fee, $lost_fee ]; |
376 |
$pay_lost->apply( { debits => $pay_lines, offset_type => 'Credit applied' } ); |
377 |
|
378 |
is( $loser->checkouts->next, undef, "Item has been returned"); |
322 |
|
379 |
|
323 |
$schema->storage->txn_rollback; |
380 |
$schema->storage->txn_rollback; |
324 |
}; |
381 |
}; |
325 |
- |
|
|