3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 100;
25 use t::lib::TestBuilder;
33 use C4::Overdues qw(UpdateFine CalcFine);
36 use Koha::IssuingRules;
39 use Koha::Subscriptions;
41 my $schema = Koha::Database->schema;
42 $schema->storage->txn_begin;
43 my $builder = t::lib::TestBuilder->new;
44 my $dbh = C4::Context->dbh;
47 $dbh->{RaiseError} = 1;
49 # Start with a clean slate
50 $dbh->do('DELETE FROM issues');
52 my $library = $builder->build({
55 my $library2 = $builder->build({
58 my $itemtype = $builder->build(
59 { source => 'Itemtype',
60 value => { notforloan => undef, rentalcharge => 0 }
63 my $patron_category = $builder->build({ source => 'Category', value => { enrolmentfee => 0 } });
65 my $CircControl = C4::Context->preference('CircControl');
66 my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
69 homebranch => $library2->{branchcode},
70 holdingbranch => $library2->{branchcode}
74 branchcode => $library2->{branchcode}
77 # No userenv, PickupLibrary
78 t::lib::Mocks::mock_preference('IndependentBranches', '0');
79 t::lib::Mocks::mock_preference('CircControl', 'PickupLibrary');
81 C4::Context->preference('CircControl'),
83 'CircControl changed to PickupLibrary'
86 C4::Circulation::_GetCircControlBranch($item, $borrower),
87 $item->{$HomeOrHoldingBranch},
88 '_GetCircControlBranch returned item branch (no userenv defined)'
91 # No userenv, PatronLibrary
92 t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
94 C4::Context->preference('CircControl'),
96 'CircControl changed to PatronLibrary'
99 C4::Circulation::_GetCircControlBranch($item, $borrower),
100 $borrower->{branchcode},
101 '_GetCircControlBranch returned borrower branch'
104 # No userenv, ItemHomeLibrary
105 t::lib::Mocks::mock_preference('CircControl', 'ItemHomeLibrary');
107 C4::Context->preference('CircControl'),
109 'CircControl changed to ItemHomeLibrary'
112 $item->{$HomeOrHoldingBranch},
113 C4::Circulation::_GetCircControlBranch($item, $borrower),
114 '_GetCircControlBranch returned item branch'
118 C4::Context->_new_userenv('xxx');
119 C4::Context->set_userenv(0,0,0,'firstname','surname', $library2->{branchcode}, 'Midway Public Library', '', '', '');
120 is(C4::Context->userenv->{branch}, $library2->{branchcode}, 'userenv set');
122 # Userenv set, PickupLibrary
123 t::lib::Mocks::mock_preference('CircControl', 'PickupLibrary');
125 C4::Context->preference('CircControl'),
127 'CircControl changed to PickupLibrary'
130 C4::Circulation::_GetCircControlBranch($item, $borrower),
131 $library2->{branchcode},
132 '_GetCircControlBranch returned current branch'
135 # Userenv set, PatronLibrary
136 t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
138 C4::Context->preference('CircControl'),
140 'CircControl changed to PatronLibrary'
143 C4::Circulation::_GetCircControlBranch($item, $borrower),
144 $borrower->{branchcode},
145 '_GetCircControlBranch returned borrower branch'
148 # Userenv set, ItemHomeLibrary
149 t::lib::Mocks::mock_preference('CircControl', 'ItemHomeLibrary');
151 C4::Context->preference('CircControl'),
153 'CircControl changed to ItemHomeLibrary'
156 C4::Circulation::_GetCircControlBranch($item, $borrower),
157 $item->{$HomeOrHoldingBranch},
158 '_GetCircControlBranch returned item branch'
161 # Reset initial configuration
162 t::lib::Mocks::mock_preference('CircControl', $CircControl);
164 C4::Context->preference('CircControl'),
166 'CircControl reset to its initial value'
169 # Set a simple circ policy
170 $dbh->do('DELETE FROM issuingrules');
172 q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed,
173 maxissueqty, issuelength, lengthunit,
174 renewalsallowed, renewalperiod,
175 norenewalbefore, auto_renew,
192 # Test C4::Circulation::ProcessOfflinePayment
193 my $sth = C4::Context->dbh->prepare("SELECT COUNT(*) FROM accountlines WHERE amount = '-123.45' AND accounttype = 'Pay'");
195 my ( $original_count ) = $sth->fetchrow_array();
197 C4::Context->dbh->do("INSERT INTO borrowers ( cardnumber, surname, firstname, categorycode, branchcode ) VALUES ( '99999999999', 'Hall', 'Kyle', ?, ? )", undef, $patron_category->{categorycode}, $library2->{branchcode} );
199 C4::Circulation::ProcessOfflinePayment({ cardnumber => '99999999999', amount => '123.45' });
202 my ( $new_count ) = $sth->fetchrow_array();
204 ok( $new_count == $original_count + 1, 'ProcessOfflinePayment makes payment correctly' );
206 C4::Context->dbh->do("DELETE FROM accountlines WHERE borrowernumber IN ( SELECT borrowernumber FROM borrowers WHERE cardnumber = '99999999999' )");
207 C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'");
208 C4::Context->dbh->do("DELETE FROM accountlines");
210 # CanBookBeRenewed tests
212 # Generate test biblio
213 my $biblio = MARC::Record->new();
214 my $title = 'Silence in the library';
215 $biblio->append_fields(
216 MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
217 MARC::Field->new('245', ' ', ' ', a => $title),
220 my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
222 my $barcode = 'R00000342';
223 my $branch = $library2->{branchcode};
225 my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
227 homebranch => $branch,
228 holdingbranch => $branch,
230 replacementprice => 12.00,
236 my $barcode2 = 'R00000343';
237 my ( $item_bibnum2, $item_bibitemnum2, $itemnumber2 ) = AddItem(
239 homebranch => $branch,
240 holdingbranch => $branch,
241 barcode => $barcode2,
242 replacementprice => 23.00,
248 my $barcode3 = 'R00000346';
249 my ( $item_bibnum3, $item_bibitemnum3, $itemnumber3 ) = AddItem(
251 homebranch => $branch,
252 holdingbranch => $branch,
253 barcode => $barcode3,
254 replacementprice => 23.00,
264 my %renewing_borrower_data = (
266 surname => 'Renewal',
267 categorycode => $patron_category->{categorycode},
268 branchcode => $branch,
271 my %reserving_borrower_data = (
272 firstname => 'Katrin',
273 surname => 'Reservation',
274 categorycode => $patron_category->{categorycode},
275 branchcode => $branch,
278 my %hold_waiting_borrower_data = (
280 surname => 'Reservation',
281 categorycode => $patron_category->{categorycode},
282 branchcode => $branch,
285 my %restricted_borrower_data = (
286 firstname => 'Alice',
287 surname => 'Reservation',
288 categorycode => $patron_category->{categorycode},
289 debarred => '3228-01-01',
290 branchcode => $branch,
293 my $renewing_borrowernumber = AddMember(%renewing_borrower_data);
294 my $reserving_borrowernumber = AddMember(%reserving_borrower_data);
295 my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data);
296 my $restricted_borrowernumber = AddMember(%restricted_borrower_data);
298 my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed;
299 my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed;
306 my $checkitem = undef;
309 my $issue = AddIssue( $renewing_borrower, $barcode);
310 my $datedue = dt_from_string( $issue->date_due() );
311 is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() );
313 my $issue2 = AddIssue( $renewing_borrower, $barcode2);
314 $datedue = dt_from_string( $issue->date_due() );
315 is (defined $issue2, 1, "Item 2 checked out, due date: " . $issue2->date_due());
318 my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $itemnumber } )->borrowernumber;
319 is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
321 my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
322 is( $renewokay, 1, 'Can renew, no holds for this title or item');
325 # Biblio-level hold, renewal test
327 $branch, $reserving_borrowernumber, $biblionumber,
328 $bibitems, $priority, $resdate, $expdate, $notes,
329 $title, $checkitem, $found
332 # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
333 C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1");
334 t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 1 );
335 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber);
336 is( $renewokay, 1, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds');
337 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber2);
338 is( $renewokay, 1, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds');
340 # Now let's add an item level hold, we should no longer be able to renew the item
341 my $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
343 borrowernumber => $hold_waiting_borrowernumber,
344 biblionumber => $biblionumber,
345 itemnumber => $itemnumber,
346 branchcode => $branch,
350 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber);
351 is( $renewokay, 0, 'Bug 13919 - Renewal possible with item level hold on item');
354 # Now let's add a waiting hold on the 3rd item, it's no longer available tp check out by just anyone, so we should no longer
355 # be able to renew these items
356 $hold = Koha::Database->new()->schema()->resultset('Reserve')->create(
358 borrowernumber => $hold_waiting_borrowernumber,
359 biblionumber => $biblionumber,
360 itemnumber => $itemnumber3,
361 branchcode => $branch,
366 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber);
367 is( $renewokay, 0, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds');
368 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber2);
369 is( $renewokay, 0, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds');
370 t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 0 );
372 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber);
373 is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
374 is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
376 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber2);
377 is( $renewokay, 0, '(Bug 10663) Cannot renew, reserved');
378 is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
380 my $reserveid = C4::Reserves::GetReserveId({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber});
381 my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
382 AddIssue($reserving_borrower, $barcode3);
383 my $reserve = $dbh->selectrow_hashref(
384 'SELECT * FROM old_reserves WHERE reserve_id = ?',
388 is($reserve->{found}, 'F', 'hold marked completed when checking out item that fills it');
390 # Item-level hold, renewal test
392 $branch, $reserving_borrowernumber, $biblionumber,
393 $bibitems, $priority, $resdate, $expdate, $notes,
394 $title, $itemnumber, $found
397 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
398 is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved');
399 is( $error, 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve)');
401 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber2, 1);
402 is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
404 # Items can't fill hold for reasons
405 ModItem({ notforloan => 1 }, $biblionumber, $itemnumber);
406 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
407 is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
408 ModItem({ notforloan => 0, itype => $itemtype }, $biblionumber, $itemnumber,1);
410 # FIXME: Add more for itemtype not for loan etc.
412 # Restricted users cannot renew when RestrictionBlockRenewing is enabled
413 my $barcode5 = 'R00000347';
414 my ( $item_bibnum5, $item_bibitemnum5, $itemnumber5 ) = AddItem(
416 homebranch => $branch,
417 holdingbranch => $branch,
418 barcode => $barcode5,
419 replacementprice => 23.00,
424 my $datedue5 = AddIssue($restricted_borrower, $barcode5);
425 is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5");
427 t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1');
428 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber2);
429 is( $renewokay, 1, '(Bug 8236), Can renew, user is not restricted');
430 ( $renewokay, $error ) = CanBookBeRenewed($restricted_borrowernumber, $itemnumber5);
431 is( $renewokay, 0, '(Bug 8236), Cannot renew, user is restricted');
433 # Users cannot renew an overdue item
434 my $barcode6 = 'R00000348';
435 my ( $item_bibnum6, $item_bibitemnum6, $itemnumber6 ) = AddItem(
437 homebranch => $branch,
438 holdingbranch => $branch,
439 barcode => $barcode6,
440 replacementprice => 23.00,
446 my $barcode7 = 'R00000349';
447 my ( $item_bibnum7, $item_bibitemnum7, $itemnumber7 ) = AddItem(
449 homebranch => $branch,
450 holdingbranch => $branch,
451 barcode => $barcode7,
452 replacementprice => 23.00,
457 my $datedue6 = AddIssue( $renewing_borrower, $barcode6);
458 is (defined $datedue6, 1, "Item 2 checked out, due date: ".$datedue6->date_due);
460 my $now = dt_from_string();
461 my $five_weeks = DateTime::Duration->new(weeks => 5);
462 my $five_weeks_ago = $now - $five_weeks;
463 t::lib::Mocks::mock_preference('finesMode', 'production');
465 my $passeddatedue1 = AddIssue($renewing_borrower, $barcode7, $five_weeks_ago);
466 is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
468 my ( $fine ) = CalcFine( GetItem(undef, $barcode7), $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
469 C4::Overdues::UpdateFine(
471 issue_id => $passeddatedue1->id(),
472 itemnumber => $itemnumber7,
473 borrowernumber => $renewing_borrower->{borrowernumber},
476 due => Koha::DateUtils::output_pref($five_weeks_ago)
480 t::lib::Mocks::mock_preference('RenewalLog', 0);
481 my $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } );
482 my $old_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } );
483 AddRenewal( $renewing_borrower->{borrowernumber}, $itemnumber7, $branch );
484 my $new_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } );
485 is ($new_log_size, $old_log_size, 'renew log not added because of the syspref RenewalLog');
487 t::lib::Mocks::mock_preference('RenewalLog', 1);
488 $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } );
489 $old_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } );
490 AddRenewal( $renewing_borrower->{borrowernumber}, $itemnumber7, $branch );
491 $new_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } );
492 is ($new_log_size, $old_log_size + 1, 'renew log successfully added');
494 my $fines = Koha::Account::Lines->search( { borrowernumber => $renewing_borrower->{borrowernumber}, itemnumber => $itemnumber7 } );
495 is( $fines->count, 2 );
496 is( $fines->next->accounttype, 'F', 'Fine on renewed item is closed out properly' );
497 is( $fines->next->accounttype, 'F', 'Fine on renewed item is closed out properly' );
501 my $old_issue_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["ISSUE"]) } );
502 my $old_renew_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } );
503 AddIssue( $renewing_borrower,$barcode7,Koha::DateUtils::output_pref({str=>$datedue6->date_due, dateformat =>'iso'}),0,$date, 0, undef );
504 $new_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } );
505 is ($new_log_size, $old_renew_log_size + 1, 'renew log successfully added when renewed via issuing');
506 $new_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["ISSUE"]) } );
507 is ($new_log_size, $old_issue_log_size, 'renew not logged as issue when renewed via issuing');
510 t::lib::Mocks::mock_preference('OverduesBlockRenewing','blockitem');
511 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber6);
512 is( $renewokay, 1, '(Bug 8236), Can renew, this item is not overdue');
513 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber7);
514 is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
517 $reserveid = C4::Reserves::GetReserveId({ biblionumber => $biblionumber, itemnumber => $itemnumber, borrowernumber => $reserving_borrowernumber});
518 CancelReserve({ reserve_id => $reserveid });
521 # Test automatic renewal before value for "norenewalbefore" in policy is set
522 # In this case automatic renewal is not permitted prior to due date
523 my $barcode4 = '11235813';
524 my ( $item_bibnum4, $item_bibitemnum4, $itemnumber4 ) = AddItem(
526 homebranch => $branch,
527 holdingbranch => $branch,
528 barcode => $barcode4,
529 replacementprice => 16.00,
535 $issue = AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
536 ( $renewokay, $error ) =
537 CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
538 is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
539 is( $error, 'auto_too_soon',
540 'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
543 # Test premature manual renewal
544 $dbh->do('UPDATE issuingrules SET norenewalbefore = 7');
546 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber);
547 is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
548 is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
551 # Test 'exact time' setting for syspref NoRenewalBeforePrecision
552 t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' );
554 GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ),
555 $datedue->clone->add( days => -7 ),
556 'Bug 14395: Renewals permitted 7 days before due date, as expected'
560 # Test 'date' setting for syspref NoRenewalBeforePrecision
561 t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
563 GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ),
564 $datedue->clone->add( days => -7 )->truncate( to => 'day' ),
565 'Bug 14395: Renewals permitted 7 days before due date, as expected'
569 # Test premature automatic renewal
570 ( $renewokay, $error ) =
571 CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
572 is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
573 is( $error, 'auto_too_soon',
574 'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
577 # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
578 # and test automatic renewal again
579 $dbh->do('UPDATE issuingrules SET norenewalbefore = 0');
580 ( $renewokay, $error ) =
581 CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
582 is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
583 is( $error, 'auto_too_soon',
584 'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
587 # Change policy so that loans can be renewed 99 days prior to the due date
588 # and test automatic renewal again
589 $dbh->do('UPDATE issuingrules SET norenewalbefore = 99');
590 ( $renewokay, $error ) =
591 CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
592 is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
593 is( $error, 'auto_renew',
594 'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
597 subtest "too_late_renewal / no_auto_renewal_after" => sub {
599 my $item_to_auto_renew = $builder->build(
602 biblionumber => $biblionumber,
603 homebranch => $branch,
604 holdingbranch => $branch,
609 my $ten_days_before = dt_from_string->add( days => -10 );
610 my $ten_days_ahead = dt_from_string->add( days => 10 );
611 AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
613 $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 9');
614 ( $renewokay, $error ) =
615 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
616 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
617 is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
619 $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 10');
620 ( $renewokay, $error ) =
621 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
622 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
623 is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
625 $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 11');
626 ( $renewokay, $error ) =
627 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
628 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
629 is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
631 $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
632 ( $renewokay, $error ) =
633 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
634 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
635 is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
637 $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => -1 ) );
638 ( $renewokay, $error ) =
639 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
640 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
641 is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
643 $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => -1 ) );
644 ( $renewokay, $error ) =
645 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
646 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
647 is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
649 $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 1 ) );
650 ( $renewokay, $error ) =
651 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
652 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
653 is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
656 subtest "auto_too_much_oweing | OPACFineNoRenewalsBlockAutoRenew" => sub {
658 my $item_to_auto_renew = $builder->build({
661 biblionumber => $biblionumber,
662 homebranch => $branch,
663 holdingbranch => $branch,
667 my $ten_days_before = dt_from_string->add( days => -10 );
668 my $ten_days_ahead = dt_from_string->add( days => 10 );
669 AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
671 $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
672 C4::Context->set_preference('OPACFineNoRenewalsBlockAutoRenew','1');
673 C4::Context->set_preference('OPACFineNoRenewals','10');
674 my $fines_amount = 5;
675 C4::Accounts::manualinvoice( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber}, "Some fines", 'F', $fines_amount );
676 ( $renewokay, $error ) =
677 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
678 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
679 is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
681 C4::Accounts::manualinvoice( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber}, "Some fines", 'F', $fines_amount );
682 ( $renewokay, $error ) =
683 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
684 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
685 is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
687 C4::Accounts::manualinvoice( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber}, "Some fines", 'F', $fines_amount );
688 ( $renewokay, $error ) =
689 CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
690 is( $renewokay, 0, 'Do not renew, renewal is automatic' );
691 is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' );
693 $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
696 subtest "GetLatestAutoRenewDate" => sub {
698 my $item_to_auto_renew = $builder->build(
701 biblionumber => $biblionumber,
702 homebranch => $branch,
703 holdingbranch => $branch,
708 my $ten_days_before = dt_from_string->add( days => -10 );
709 my $ten_days_ahead = dt_from_string->add( days => 10 );
710 AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
711 $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = NULL');
712 my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
713 is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' );
714 my $five_days_before = dt_from_string->add( days => -5 );
715 $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL');
716 $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
717 is( $latest_auto_renew_date->truncate( to => 'minute' ),
718 $five_days_before->truncate( to => 'minute' ),
719 'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
721 my $five_days_ahead = dt_from_string->add( days => 5 );
722 $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL');
723 $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
724 is( $latest_auto_renew_date->truncate( to => 'minute' ),
725 $five_days_ahead->truncate( to => 'minute' ),
726 'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
728 my $two_days_ahead = dt_from_string->add( days => 2 );
729 $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) );
730 $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
731 is( $latest_auto_renew_date->truncate( to => 'day' ),
732 $two_days_ahead->truncate( to => 'day' ),
733 'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after'
735 $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) );
736 $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
737 is( $latest_auto_renew_date->truncate( to => 'day' ),
738 $two_days_ahead->truncate( to => 'day' ),
739 'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after'
746 # set policy to forbid renewals
747 $dbh->do('UPDATE issuingrules SET norenewalbefore = NULL, renewalsallowed = 0');
749 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber);
750 is( $renewokay, 0, 'Cannot renew, 0 renewals allowed');
751 is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)');
753 # Test WhenLostForgiveFine and WhenLostChargeReplacementFee
754 t::lib::Mocks::mock_preference('WhenLostForgiveFine','1');
755 t::lib::Mocks::mock_preference('WhenLostChargeReplacementFee','1');
757 C4::Overdues::UpdateFine(
759 issue_id => $issue->id(),
760 itemnumber => $itemnumber,
761 borrowernumber => $renewing_borrower->{borrowernumber},
764 due => Koha::DateUtils::output_pref($datedue)
768 LostItem( $itemnumber, 1 );
770 my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
771 ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
773 my $total_due = $dbh->selectrow_array(
774 'SELECT SUM( amountoutstanding ) FROM accountlines WHERE borrowernumber = ?',
775 undef, $renewing_borrower->{borrowernumber}
778 ok( $total_due == 12, 'Borrower only charged replacement fee with both WhenLostForgiveFine and WhenLostChargeReplacementFee enabled' );
780 C4::Context->dbh->do("DELETE FROM accountlines");
782 t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
783 t::lib::Mocks::mock_preference('WhenLostChargeReplacementFee','0');
785 C4::Overdues::UpdateFine(
787 issue_id => $issue2->id(),
788 itemnumber => $itemnumber2,
789 borrowernumber => $renewing_borrower->{borrowernumber},
792 due => Koha::DateUtils::output_pref($datedue)
796 LostItem( $itemnumber2, 0 );
798 my $item2 = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber2);
799 ok( $item2->onloan(), "Lost item *not* marked as returned has true onloan value" );
801 $total_due = $dbh->selectrow_array(
802 'SELECT SUM( amountoutstanding ) FROM accountlines WHERE borrowernumber = ?',
803 undef, $renewing_borrower->{borrowernumber}
806 ok( $total_due == 15, 'Borrower only charged fine with both WhenLostForgiveFine and WhenLostChargeReplacementFee disabled' );
808 my $future = dt_from_string();
809 $future->add( days => 7 );
810 my $units = C4::Overdues::get_chargeable_units('days', $future, $now, $library2->{branchcode});
811 ok( $units == 0, '_get_chargeable_units returns 0 for items not past due date (Bug 12596)' );
813 # Users cannot renew any item if there is an overdue item
814 t::lib::Mocks::mock_preference('OverduesBlockRenewing','block');
815 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber6);
816 is( $renewokay, 0, '(Bug 8236), Cannot renew, one of the items is overdue');
817 ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber7);
818 is( $renewokay, 0, '(Bug 8236), Cannot renew, one of the items is overdue');
823 # GetUpcomingDueIssues tests
824 my $barcode = 'R00000342';
825 my $barcode2 = 'R00000343';
826 my $barcode3 = 'R00000344';
827 my $branch = $library2->{branchcode};
829 #Create another record
830 my $biblio2 = MARC::Record->new();
831 my $title2 = 'Something is worng here';
832 $biblio2->append_fields(
833 MARC::Field->new('100', ' ', ' ', a => 'Anonymous'),
834 MARC::Field->new('245', ' ', ' ', a => $title2),
836 my ($biblionumber2, $biblioitemnumber2) = AddBiblio($biblio2, '');
841 homebranch => $branch,
842 holdingbranch => $branch,
843 barcode => $barcode3,
850 my %a_borrower_data = (
851 firstname => 'Fridolyn',
853 categorycode => $patron_category->{categorycode},
854 branchcode => $branch,
857 my $a_borrower_borrowernumber = AddMember(%a_borrower_data);
858 my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber )->unblessed;
860 my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
861 my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 );
862 my $today = DateTime->today(time_zone => C4::Context->tz());
864 my $issue = AddIssue( $a_borrower, $barcode, $yesterday );
865 my $datedue = dt_from_string( $issue->date_due() );
866 my $issue2 = AddIssue( $a_borrower, $barcode2, $two_days_ahead );
867 my $datedue2 = dt_from_string( $issue->date_due() );
871 # GetUpcomingDueIssues tests
873 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => $i } );
874 is ( scalar( @$upcoming_dues ), 0, "No items due in less than one day ($i days in advance)" );
877 #days_in_advance needs to be inclusive, so 1 matches items due tomorrow, 0 items due today etc.
878 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => 2 } );
879 is ( scalar ( @$upcoming_dues), 1, "Only one item due in 2 days or less" );
882 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => $i } );
883 is ( scalar( @$upcoming_dues ), 1,
884 "Bug 9362: Only one item due in more than 2 days ($i days in advance)" );
887 # Bug 11218 - Due notices not generated - GetUpcomingDueIssues needs to select due today items as well
889 my $issue3 = AddIssue( $a_borrower, $barcode3, $today );
891 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => -1 } );
892 is ( scalar ( @$upcoming_dues), 0, "Overdues can not be selected" );
894 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => 0 } );
895 is ( scalar ( @$upcoming_dues), 1, "1 item is due today" );
897 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => 1 } );
898 is ( scalar ( @$upcoming_dues), 1, "1 item is due today, none tomorrow" );
900 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => 2 } );
901 is ( scalar ( @$upcoming_dues), 2, "2 items are due withing 2 days" );
903 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => 3 } );
904 is ( scalar ( @$upcoming_dues), 2, "2 items are due withing 2 days" );
906 $upcoming_dues = C4::Circulation::GetUpcomingDueIssues();
907 is ( scalar ( @$upcoming_dues), 2, "days_in_advance is 7 in GetUpcomingDueIssues if not provided" );
912 my $barcode = '1234567890';
913 my $branch = $library2->{branchcode};
915 my $biblio = MARC::Record->new();
916 my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
919 my ( undef, undef, $itemnumber ) = AddItem(
921 homebranch => $branch,
922 holdingbranch => $branch,
930 my %a_borrower_data = (
933 categorycode => $patron_category->{categorycode},
934 branchcode => $branch,
937 my $borrowernumber = AddMember(%a_borrower_data);
939 my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
940 my $issue = AddIssue( $borrower, $barcode );
943 issue_id => $issue->id(),
944 itemnumber => $itemnumber,
945 borrowernumber => $borrowernumber,
951 my $hr = $dbh->selectrow_hashref(q{SELECT COUNT(*) AS count FROM accountlines WHERE borrowernumber = ? AND itemnumber = ?}, undef, $borrowernumber, $itemnumber );
952 my $count = $hr->{count};
954 is ( $count, 0, "Calling UpdateFine on non-existant fine with an amount of 0 does not result in an empty fine" );
958 $dbh->do('DELETE FROM issues');
959 $dbh->do('DELETE FROM items');
960 $dbh->do('DELETE FROM issuingrules');
963 INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
964 norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
973 my $biblio = MARC::Record->new();
974 my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
976 my $barcode1 = '1234';
977 my ( undef, undef, $itemnumber1 ) = AddItem(
979 homebranch => $library2->{branchcode},
980 holdingbranch => $library2->{branchcode},
981 barcode => $barcode1,
986 my $barcode2 = '4321';
987 my ( undef, undef, $itemnumber2 ) = AddItem(
989 homebranch => $library2->{branchcode},
990 holdingbranch => $library2->{branchcode},
991 barcode => $barcode2,
997 my $borrowernumber1 = AddMember(
1000 categorycode => $patron_category->{categorycode},
1001 branchcode => $library2->{branchcode},
1003 my $borrowernumber2 = AddMember(
1004 firstname => 'Chelsea',
1006 categorycode => $patron_category->{categorycode},
1007 branchcode => $library2->{branchcode},
1010 my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed;
1011 my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed;
1013 my $issue = AddIssue( $borrower1, $barcode1 );
1015 my ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1016 is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1019 $library2->{branchcode}, $borrowernumber2, $biblionumber,
1020 '', 1, undef, undef, '',
1024 C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 0");
1025 t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 );
1026 ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1027 is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfholds are disabled' );
1029 C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 0");
1030 t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 );
1031 ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1032 is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled and onshelfholds is disabled' );
1034 C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1");
1035 t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 );
1036 ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1037 is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is disabled and onshelfhold is enabled' );
1039 C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1");
1040 t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 );
1041 ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1042 is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1044 # Setting item not checked out to be not for loan but holdable
1045 ModItem({ notforloan => -1 }, $biblionumber, $itemnumber2);
1047 ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 );
1048 is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' );
1052 # Don't allow renewing onsite checkout
1053 my $barcode = 'R00000XXX';
1054 my $branch = $library->{branchcode};
1056 #Create another record
1057 my $biblio = MARC::Record->new();
1058 $biblio->append_fields(
1059 MARC::Field->new('100', ' ', ' ', a => 'Anonymous'),
1060 MARC::Field->new('245', ' ', ' ', a => 'A title'),
1062 my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
1064 my (undef, undef, $itemnumber) = AddItem(
1066 homebranch => $branch,
1067 holdingbranch => $branch,
1068 barcode => $barcode,
1074 my $borrowernumber = AddMember(
1077 categorycode => $patron_category->{categorycode},
1078 branchcode => $branch,
1081 my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
1083 my $issue = AddIssue( $borrower, $barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1084 my ( $renewed, $error ) = CanBookBeRenewed( $borrowernumber, $itemnumber );
1085 is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1086 is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1090 my $library = $builder->build({ source => 'Branch' });
1092 my $biblio = MARC::Record->new();
1093 my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
1095 my $barcode = 'just a barcode';
1096 my ( undef, undef, $itemnumber ) = AddItem(
1098 homebranch => $library->{branchcode},
1099 holdingbranch => $library->{branchcode},
1100 barcode => $barcode,
1106 my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode} } } );
1108 my $issue = AddIssue( $patron, $barcode );
1111 issue_id => $issue->id(),
1112 itemnumber => $itemnumber,
1113 borrowernumber => $patron->{borrowernumber},
1120 issue_id => $issue->id(),
1121 itemnumber => $itemnumber,
1122 borrowernumber => $patron->{borrowernumber},
1127 is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
1130 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
1133 my $homebranch = $builder->build( { source => 'Branch' } );
1134 my $holdingbranch = $builder->build( { source => 'Branch' } );
1135 my $otherbranch = $builder->build( { source => 'Branch' } );
1136 my $patron_1 = $builder->build( { source => 'Borrower' } );
1137 my $patron_2 = $builder->build( { source => 'Borrower' } );
1139 my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1140 my $item = $builder->build(
1143 homebranch => $homebranch->{branchcode},
1144 holdingbranch => $holdingbranch->{branchcode},
1149 biblionumber => $biblioitem->{biblionumber}
1154 set_userenv($holdingbranch);
1156 my $issue = AddIssue( $patron_1, $item->{barcode} );
1157 is( ref($issue), 'Koha::Schema::Result::Issue' ); # FIXME Should be Koha::Checkout
1159 my ( $error, $question, $alerts );
1161 # AllowReturnToBranch == anywhere
1162 t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
1163 ## Can be issued from homebranch
1164 set_userenv($homebranch);
1165 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1166 is( keys(%$error), 0, 'There should not be any errors (impossible)' );
1167 is( keys(%$alerts), 0, 'There should not be any alerts' );
1168 is( exists $question->{ISSUED_TO_ANOTHER}, 1 );
1169 ## Can be issued from holdingbranch
1170 set_userenv($holdingbranch);
1171 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1172 is( keys(%$error), 0, 'There should not be any errors (impossible)' );
1173 is( keys(%$alerts), 0, 'There should not be any alerts' );
1174 is( exists $question->{ISSUED_TO_ANOTHER}, 1 );
1175 ## Can be issued from another branch
1176 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1177 is( keys(%$error), 0, 'There should not be any errors (impossible)' );
1178 is( keys(%$alerts), 0, 'There should not be any alerts' );
1179 is( exists $question->{ISSUED_TO_ANOTHER}, 1 );
1181 # AllowReturnToBranch == holdingbranch
1182 t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
1183 ## Cannot be issued from homebranch
1184 set_userenv($homebranch);
1185 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1186 is( keys(%$question) + keys(%$alerts), 0 );
1187 is( exists $error->{RETURN_IMPOSSIBLE}, 1 );
1188 is( $error->{branch_to_return}, $holdingbranch->{branchcode} );
1189 ## Can be issued from holdinbranch
1190 set_userenv($holdingbranch);
1191 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1192 is( keys(%$error) + keys(%$alerts), 0 );
1193 is( exists $question->{ISSUED_TO_ANOTHER}, 1 );
1194 ## Cannot be issued from another branch
1195 set_userenv($otherbranch);
1196 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1197 is( keys(%$question) + keys(%$alerts), 0 );
1198 is( exists $error->{RETURN_IMPOSSIBLE}, 1 );
1199 is( $error->{branch_to_return}, $holdingbranch->{branchcode} );
1201 # AllowReturnToBranch == homebranch
1202 t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
1203 ## Can be issued from holdinbranch
1204 set_userenv($homebranch);
1205 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1206 is( keys(%$error) + keys(%$alerts), 0 );
1207 is( exists $question->{ISSUED_TO_ANOTHER}, 1 );
1208 ## Cannot be issued from holdinbranch
1209 set_userenv($holdingbranch);
1210 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1211 is( keys(%$question) + keys(%$alerts), 0 );
1212 is( exists $error->{RETURN_IMPOSSIBLE}, 1 );
1213 is( $error->{branch_to_return}, $homebranch->{branchcode} );
1214 ## Cannot be issued from holdinbranch
1215 set_userenv($otherbranch);
1216 ( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} );
1217 is( keys(%$question) + keys(%$alerts), 0 );
1218 is( exists $error->{RETURN_IMPOSSIBLE}, 1 );
1219 is( $error->{branch_to_return}, $homebranch->{branchcode} );
1221 # TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch');
1224 subtest 'AddIssue & AllowReturnToBranch' => sub {
1227 my $homebranch = $builder->build( { source => 'Branch' } );
1228 my $holdingbranch = $builder->build( { source => 'Branch' } );
1229 my $otherbranch = $builder->build( { source => 'Branch' } );
1230 my $patron_1 = $builder->build( { source => 'Borrower' } );
1231 my $patron_2 = $builder->build( { source => 'Borrower' } );
1233 my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1234 my $item = $builder->build(
1237 homebranch => $homebranch->{branchcode},
1238 holdingbranch => $holdingbranch->{branchcode},
1242 biblionumber => $biblioitem->{biblionumber}
1247 set_userenv($holdingbranch);
1249 my $ref_issue = 'Koha::Schema::Result::Issue'; # FIXME Should be Koha::Checkout
1250 my $issue = AddIssue( $patron_1, $item->{barcode} );
1252 my ( $error, $question, $alerts );
1254 # AllowReturnToBranch == homebranch
1255 t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
1256 ## Can be issued from homebranch
1257 set_userenv($homebranch);
1258 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue );
1259 set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1260 ## Can be issued from holdinbranch
1261 set_userenv($holdingbranch);
1262 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue );
1263 set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1264 ## Can be issued from another branch
1265 set_userenv($otherbranch);
1266 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue );
1267 set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1269 # AllowReturnToBranch == holdinbranch
1270 t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
1271 ## Cannot be issued from homebranch
1272 set_userenv($homebranch);
1273 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '' );
1274 ## Can be issued from holdingbranch
1275 set_userenv($holdingbranch);
1276 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue );
1277 set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1278 ## Cannot be issued from another branch
1279 set_userenv($otherbranch);
1280 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '' );
1282 # AllowReturnToBranch == homebranch
1283 t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
1284 ## Can be issued from homebranch
1285 set_userenv($homebranch);
1286 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue );
1287 set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue
1288 ## Cannot be issued from holdinbranch
1289 set_userenv($holdingbranch);
1290 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '' );
1291 ## Cannot be issued from another branch
1292 set_userenv($otherbranch);
1293 is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '' );
1294 # TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch');
1297 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub {
1300 my $library = $builder->build( { source => 'Branch' } );
1301 my $patron = $builder->build( { source => 'Borrower', value => { gonenoaddress => undef, lost => undef, debarred => undef, borrowernotes => "" } } );
1303 my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
1304 my $item_1 = $builder->build(
1307 homebranch => $library->{branchcode},
1308 holdingbranch => $library->{branchcode},
1313 biblionumber => $biblioitem_1->{biblionumber}
1317 my $biblioitem_2 = $builder->build( { source => 'Biblioitem' } );
1318 my $item_2 = $builder->build(
1321 homebranch => $library->{branchcode},
1322 holdingbranch => $library->{branchcode},
1327 biblionumber => $biblioitem_2->{biblionumber}
1332 my ( $error, $question, $alerts );
1334 # Patron cannot issue item_1, they have overdues
1335 my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
1336 my $issue = AddIssue( $patron, $item_1->{barcode}, $yesterday ); # Add an overdue
1338 t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
1339 ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1340 is( keys(%$error) + keys(%$alerts), 0, 'No key for error and alert ' . keys(%$error) . ' ' . keys(%$alerts) );
1341 is( $question->{USERBLOCKEDOVERDUE}, 1, 'OverduesBlockCirc=confirmation, USERBLOCKEDOVERDUE should be set for question' );
1343 t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'block' );
1344 ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1345 is( keys(%$question) + keys(%$alerts), 0, 'No key for question and alert ' . keys(%$question) . ' ' . keys(%$alerts) );
1346 is( $error->{USERBLOCKEDOVERDUE}, 1, 'OverduesBlockCirc=block, USERBLOCKEDOVERDUE should be set for error' );
1348 # Patron cannot issue item_1, they are debarred
1349 my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
1350 Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->{borrowernumber}, expiration => $tomorrow } );
1351 ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1352 is( keys(%$question) + keys(%$alerts), 0, 'No key for question and alert ' . keys(%$question) . ' ' . keys(%$alerts) );
1353 is( $error->{USERBLOCKEDWITHENDDATE}, output_pref( { dt => $tomorrow, dateformat => 'sql', dateonly => 1 } ), 'USERBLOCKEDWITHENDDATE should be tomorrow' );
1355 Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->{borrowernumber} } );
1356 ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1357 is( keys(%$question) + keys(%$alerts), 0, 'No key for question and alert ' . keys(%$question) . ' ' . keys(%$alerts) );
1358 is( $error->{USERBLOCKEDNOENDDATE}, '9999-12-31', 'USERBLOCKEDNOENDDATE should be 9999-12-31 for unlimited debarments' );
1361 subtest 'MultipleReserves' => sub {
1364 my $biblio = MARC::Record->new();
1365 my $title = 'Silence in the library';
1366 $biblio->append_fields(
1367 MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
1368 MARC::Field->new('245', ' ', ' ', a => $title),
1371 my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
1373 my $branch = $library2->{branchcode};
1375 my $barcode1 = 'R00110001';
1376 my ( $item_bibnum1, $item_bibitemnum1, $itemnumber1 ) = AddItem(
1378 homebranch => $branch,
1379 holdingbranch => $branch,
1380 barcode => $barcode1,
1381 replacementprice => 12.00,
1387 my $barcode2 = 'R00110002';
1388 my ( $item_bibnum2, $item_bibitemnum2, $itemnumber2 ) = AddItem(
1390 homebranch => $branch,
1391 holdingbranch => $branch,
1392 barcode => $barcode2,
1393 replacementprice => 12.00,
1401 my $resdate = undef;
1402 my $expdate = undef;
1404 my $checkitem = undef;
1407 my %renewing_borrower_data = (
1408 firstname => 'John',
1409 surname => 'Renewal',
1410 categorycode => $patron_category->{categorycode},
1411 branchcode => $branch,
1413 my $renewing_borrowernumber = AddMember(%renewing_borrower_data);
1414 my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed;
1415 my $issue = AddIssue( $renewing_borrower, $barcode1);
1416 my $datedue = dt_from_string( $issue->date_due() );
1417 is (defined $issue->date_due(), 1, "item 1 checked out");
1418 my $borrowing_borrowernumber = Koha::Checkouts->find({ itemnumber => $itemnumber1 })->borrowernumber;
1420 my %reserving_borrower_data1 = (
1421 firstname => 'Katrin',
1422 surname => 'Reservation',
1423 categorycode => $patron_category->{categorycode},
1424 branchcode => $branch,
1426 my $reserving_borrowernumber1 = AddMember(%reserving_borrower_data1);
1428 $branch, $reserving_borrowernumber1, $biblionumber,
1429 $bibitems, $priority, $resdate, $expdate, $notes,
1430 $title, $checkitem, $found
1433 my %reserving_borrower_data2 = (
1434 firstname => 'Kirk',
1435 surname => 'Reservation',
1436 categorycode => $patron_category->{categorycode},
1437 branchcode => $branch,
1439 my $reserving_borrowernumber2 = AddMember(%reserving_borrower_data2);
1441 $branch, $reserving_borrowernumber2, $biblionumber,
1442 $bibitems, $priority, $resdate, $expdate, $notes,
1443 $title, $checkitem, $found
1447 my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber1, 1);
1448 is($renewokay, 0, 'Bug 17641 - should cover the case where 2 books are both reserved, so failing');
1451 my $barcode3 = 'R00110003';
1452 my ( $item_bibnum3, $item_bibitemnum3, $itemnumber3 ) = AddItem(
1454 homebranch => $branch,
1455 holdingbranch => $branch,
1456 barcode => $barcode3,
1457 replacementprice => 12.00,
1464 my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber1, 1);
1465 is($renewokay, 1, 'Bug 17641 - should cover the case where 2 books are reserved, but a third one is available');
1469 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub {
1472 my $library = $builder->build( { source => 'Branch' } );
1473 my $patron = $builder->build( { source => 'Borrower' } );
1475 my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1476 my $biblionumber = $biblioitem->{biblionumber};
1477 my $item_1 = $builder->build(
1480 homebranch => $library->{branchcode},
1481 holdingbranch => $library->{branchcode},
1485 biblionumber => $biblionumber,
1489 my $item_2 = $builder->build(
1492 homebranch => $library->{branchcode},
1493 holdingbranch => $library->{branchcode},
1497 biblionumber => $biblionumber,
1502 my ( $error, $question, $alerts );
1503 my $issue = AddIssue( $patron, $item_1->{barcode}, dt_from_string->add( days => 1 ) );
1505 t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1506 ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1507 is( keys(%$error) + keys(%$alerts), 0, 'No error or alert should be raised' );
1508 is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' );
1510 t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1511 ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1512 is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1' );
1514 # Add a subscription
1515 Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1517 t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1518 ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1519 is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' );
1521 t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1522 ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1523 is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' );
1526 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
1529 my $library = $builder->build( { source => 'Branch' } );
1530 my $patron = $builder->build( { source => 'Borrower' } );
1533 my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
1534 my $item_1 = $builder->build(
1538 homebranch => $library->{branchcode},
1539 holdingbranch => $library->{branchcode},
1543 biblionumber => $biblioitem_1->{biblionumber}
1547 my $biblioitem_2 = $builder->build( { source => 'Biblioitem' } );
1548 my $item_2 = $builder->build(
1552 homebranch => $library->{branchcode},
1553 holdingbranch => $library->{branchcode},
1557 biblionumber => $biblioitem_2->{biblionumber}
1562 # And the issuing rule
1563 Koha::IssuingRules->search->delete;
1564 my $rule = Koha::IssuingRule->new(
1566 categorycode => '*',
1571 firstremind => 1, # 1 day of grace
1572 finedays => 2, # 2 days of fine per day of overdue
1573 lengthunit => 'days',
1578 # Patron cannot issue item_1, they have overdues
1579 my $five_days_ago = dt_from_string->subtract( days => 5 );
1580 my $ten_days_ago = dt_from_string->subtract( days => 10 );
1581 AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue
1582 AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
1583 ; # Add another overdue
1585 t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
1586 AddReturn( $item_1->{barcode}, $library->{branchcode},
1587 undef, undef, dt_from_string );
1588 my $debarments = Koha::Patron::Debarments::GetDebarments(
1589 { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1590 is( scalar(@$debarments), 1 );
1592 # FIXME Is it right? I'd have expected 5 * 2 - 1 instead
1593 # Same for the others
1594 my $expected_expiration = output_pref(
1596 dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ),
1597 dateformat => 'sql',
1601 is( $debarments->[0]->{expiration}, $expected_expiration );
1603 AddReturn( $item_2->{barcode}, $library->{branchcode},
1604 undef, undef, dt_from_string );
1605 $debarments = Koha::Patron::Debarments::GetDebarments(
1606 { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1607 is( scalar(@$debarments), 1 );
1608 $expected_expiration = output_pref(
1610 dt => dt_from_string->add( days => ( 10 - 1 ) * 2 ),
1611 dateformat => 'sql',
1615 is( $debarments->[0]->{expiration}, $expected_expiration );
1617 Koha::Patron::Debarments::DelUniqueDebarment(
1618 { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1620 t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' );
1621 AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue
1622 AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
1623 ; # Add another overdue
1624 AddReturn( $item_1->{barcode}, $library->{branchcode},
1625 undef, undef, dt_from_string );
1626 $debarments = Koha::Patron::Debarments::GetDebarments(
1627 { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1628 is( scalar(@$debarments), 1 );
1629 $expected_expiration = output_pref(
1631 dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ),
1632 dateformat => 'sql',
1636 is( $debarments->[0]->{expiration}, $expected_expiration );
1638 AddReturn( $item_2->{barcode}, $library->{branchcode},
1639 undef, undef, dt_from_string );
1640 $debarments = Koha::Patron::Debarments::GetDebarments(
1641 { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1642 is( scalar(@$debarments), 1 );
1643 $expected_expiration = output_pref(
1645 dt => dt_from_string->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ),
1646 dateformat => 'sql',
1650 is( $debarments->[0]->{expiration}, $expected_expiration );
1653 subtest 'AddReturn | is_overdue' => sub {
1656 t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1);
1657 t::lib::Mocks::mock_preference('finesMode', 'production');
1658 t::lib::Mocks::mock_preference('MaxFine', '100');
1660 my $library = $builder->build( { source => 'Branch' } );
1661 my $patron = $builder->build( { source => 'Borrower' } );
1663 my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1664 my $item = $builder->build(
1668 homebranch => $library->{branchcode},
1669 holdingbranch => $library->{branchcode},
1673 biblionumber => $biblioitem->{biblionumber},
1678 Koha::IssuingRules->search->delete;
1679 my $rule = Koha::IssuingRule->new(
1681 categorycode => '*',
1686 lengthunit => 'days',
1687 fine => 1, # Charge 1 every day of overdue
1693 my $one_day_ago = dt_from_string->subtract( days => 1 );
1694 my $five_days_ago = dt_from_string->subtract( days => 5 );
1695 my $ten_days_ago = dt_from_string->subtract( days => 10 );
1696 $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1698 # No date specify, today will be used
1699 AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
1700 AddReturn( $item->{barcode}, $library->{branchcode} );
1701 is( int($patron->account->balance()), 10, 'Patron should have a charge of 10 (10 days x 1)' );
1702 Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1704 # specify return date 5 days before => no overdue
1705 AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
1706 AddReturn( $item->{barcode}, $library->{branchcode}, undef, undef, $ten_days_ago );
1707 is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
1708 Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1710 # specify return date 5 days later => overdue
1711 AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
1712 AddReturn( $item->{barcode}, $library->{branchcode}, undef, undef, $five_days_ago );
1713 is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
1714 Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1716 # specify dropbox date 5 days before => no overdue
1717 AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
1718 AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $ten_days_ago );
1719 is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
1720 Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1722 # specify dropbox date 5 days later => overdue, or... not
1723 AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
1724 AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $five_days_ago );
1725 is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the FU fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature
1726 Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1731 my ( $library ) = @_;
1732 C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');