Lines 58-63
use Koha::RefundLostItemFeeRules;
Link Here
|
58 |
use Koha::Account::Lines; |
58 |
use Koha::Account::Lines; |
59 |
use Koha::Account::Offsets; |
59 |
use Koha::Account::Offsets; |
60 |
use Koha::Config::SysPrefs; |
60 |
use Koha::Config::SysPrefs; |
|
|
61 |
use Koha::Fees; |
61 |
use Carp; |
62 |
use Carp; |
62 |
use List::MoreUtils qw( uniq any ); |
63 |
use List::MoreUtils qw( uniq any ); |
63 |
use Scalar::Util qw( looks_like_number ); |
64 |
use Scalar::Util qw( looks_like_number ); |
Lines 669-681
sub CanBookBeIssued {
Link Here
|
669 |
my $onsite_checkout = $params->{onsite_checkout} || 0; |
670 |
my $onsite_checkout = $params->{onsite_checkout} || 0; |
670 |
my $override_high_holds = $params->{override_high_holds} || 0; |
671 |
my $override_high_holds = $params->{override_high_holds} || 0; |
671 |
|
672 |
|
672 |
my $item = GetItem(undef, $barcode ); |
673 |
my $item_object = Koha::Items->find( { barcode => $barcode } ); |
|
|
674 |
|
673 |
# MANDATORY CHECKS - unless item exists, nothing else matters |
675 |
# MANDATORY CHECKS - unless item exists, nothing else matters |
674 |
unless ( $item ) { |
676 |
unless ( $item_object ) { |
675 |
$issuingimpossible{UNKNOWN_BARCODE} = 1; |
677 |
$issuingimpossible{UNKNOWN_BARCODE} = 1; |
676 |
} |
678 |
} |
677 |
return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible; |
679 |
return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible; |
678 |
|
680 |
|
|
|
681 |
my $item = $item_object->unblessed; |
682 |
$item->{itype} = $item_object->effective_itemtype(); # set the correct itype |
683 |
|
679 |
my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); |
684 |
my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); |
680 |
my $biblio = Koha::Biblios->find( $item->{biblionumber} ); |
685 |
my $biblio = Koha::Biblios->find( $item->{biblionumber} ); |
681 |
my $biblioitem = $biblio->biblioitem; |
686 |
my $biblioitem = $biblio->biblioitem; |
Lines 683-688
sub CanBookBeIssued {
Link Here
|
683 |
my $dbh = C4::Context->dbh; |
688 |
my $dbh = C4::Context->dbh; |
684 |
my $patron_unblessed = $patron->unblessed; |
689 |
my $patron_unblessed = $patron->unblessed; |
685 |
|
690 |
|
|
|
691 |
my $library = Koha::Libraries->find( _GetCircControlBranch($item, $patron_unblessed) ); |
686 |
# |
692 |
# |
687 |
# DUE DATE is OK ? -- should already have checked. |
693 |
# DUE DATE is OK ? -- should already have checked. |
688 |
# |
694 |
# |
Lines 693-704
sub CanBookBeIssued {
Link Here
|
693 |
unless ( $duedate ) { |
699 |
unless ( $duedate ) { |
694 |
my $issuedate = $now->clone(); |
700 |
my $issuedate = $now->clone(); |
695 |
|
701 |
|
696 |
my $branch = _GetCircControlBranch($item, $patron_unblessed); |
702 |
my $branch = $library->id; |
697 |
$duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed ); |
703 |
$duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed ); |
698 |
|
704 |
|
699 |
# Offline circ calls AddIssue directly, doesn't run through here |
705 |
# Offline circ calls AddIssue directly, doesn't run through here |
700 |
# So issuingimpossible should be ok. |
706 |
# So issuingimpossible should be ok. |
701 |
} |
707 |
} |
|
|
708 |
|
709 |
my $fees = Koha::Fees->new( |
710 |
{ |
711 |
patron => $patron, |
712 |
library => $library, |
713 |
item => $item_object, |
714 |
to_date => $duedate, |
715 |
} |
716 |
); |
717 |
|
702 |
if ($duedate) { |
718 |
if ($duedate) { |
703 |
my $today = $now->clone(); |
719 |
my $today = $now->clone(); |
704 |
$today->truncate( to => 'minute'); |
720 |
$today->truncate( to => 'minute'); |
Lines 1311-1316
sub AddIssue {
Link Here
|
1311 |
); |
1327 |
); |
1312 |
} |
1328 |
} |
1313 |
else { |
1329 |
else { |
|
|
1330 |
unless ($datedue) { |
1331 |
my $itype = $item_object->effective_itemtype; |
1332 |
$datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower ); |
1333 |
|
1334 |
} |
1335 |
$datedue->truncate( to => 'minute' ); |
1336 |
|
1337 |
my $patron = Koha::Patrons->find( $borrower ); |
1338 |
my $library = Koha::Libraries->find( $branch ); |
1339 |
my $fees = Koha::Fees->new( |
1340 |
{ |
1341 |
patron => $patron, |
1342 |
library => $library, |
1343 |
item => $item_object, |
1344 |
to_date => $datedue, |
1345 |
} |
1346 |
); |
1347 |
|
1314 |
# it's NOT a renewal |
1348 |
# it's NOT a renewal |
1315 |
if ( $actualissue and not $switch_onsite_checkout ) { |
1349 |
if ( $actualissue and not $switch_onsite_checkout ) { |
1316 |
# This book is currently on loan, but not to the person |
1350 |
# This book is currently on loan, but not to the person |
Lines 1350-1362
sub AddIssue {
Link Here
|
1350 |
} |
1384 |
} |
1351 |
|
1385 |
|
1352 |
# Record in the database the fact that the book was issued. |
1386 |
# Record in the database the fact that the book was issued. |
1353 |
unless ($datedue) { |
|
|
1354 |
my $itype = $item_object->effective_itemtype; |
1355 |
$datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower ); |
1356 |
|
1357 |
} |
1358 |
$datedue->truncate( to => 'minute' ); |
1359 |
|
1360 |
$issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create( |
1387 |
$issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create( |
1361 |
{ |
1388 |
{ |
1362 |
borrowernumber => $borrower->{'borrowernumber'}, |
1389 |
borrowernumber => $borrower->{'borrowernumber'}, |
Lines 1418-1424
sub AddIssue {
Link Here
|
1418 |
|
1445 |
|
1419 |
my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype ); |
1446 |
my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype ); |
1420 |
if ( $itemtype ) { |
1447 |
if ( $itemtype ) { |
1421 |
my $daily_charge = $itemtype->calc_rental_charge_daily( { from => $issuedate, to => $datedue } ); |
1448 |
my $daily_charge = $fees->rental_charge_daily(); |
1422 |
if ( $daily_charge > 0 ) { |
1449 |
if ( $daily_charge > 0 ) { |
1423 |
AddIssuingCharge( $issue, $daily_charge, 'Daily rental' ) if $daily_charge > 0; |
1450 |
AddIssuingCharge( $issue, $daily_charge, 'Daily rental' ) if $daily_charge > 0; |
1424 |
$charge += $daily_charge; |
1451 |
$charge += $daily_charge; |
Lines 2854-2859
sub AddRenewal {
Link Here
|
2854 |
my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return |
2881 |
my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return |
2855 |
my $patron_unblessed = $patron->unblessed; |
2882 |
my $patron_unblessed = $patron->unblessed; |
2856 |
|
2883 |
|
|
|
2884 |
my $library = Koha::Libraries->find( $branch ); |
2885 |
|
2886 |
|
2857 |
if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) { |
2887 |
if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) { |
2858 |
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } ); |
2888 |
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } ); |
2859 |
} |
2889 |
} |
Lines 2871-2876
sub AddRenewal {
Link Here
|
2871 |
$datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal'); |
2901 |
$datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal'); |
2872 |
} |
2902 |
} |
2873 |
|
2903 |
|
|
|
2904 |
|
2905 |
my $fees = Koha::Fees->new( |
2906 |
{ |
2907 |
patron => $patron, |
2908 |
library => $library, |
2909 |
item => $item_object, |
2910 |
to_date => dt_from_string( $datedue ), |
2911 |
} |
2912 |
); |
2913 |
|
2874 |
# Update the issues record to have the new due date, and a new count |
2914 |
# Update the issues record to have the new due date, and a new count |
2875 |
# of how many times it has been renewed. |
2915 |
# of how many times it has been renewed. |
2876 |
my $renews = $issue->renewals + 1; |
2916 |
my $renews = $issue->renewals + 1; |
Lines 2896-2902
sub AddRenewal {
Link Here
|
2896 |
# Charge a new daily rental fee, if applicable |
2936 |
# Charge a new daily rental fee, if applicable |
2897 |
my $itemtype = Koha::ItemTypes->find( $item->{itype} ); # GetItem sets effective itemtype |
2937 |
my $itemtype = Koha::ItemTypes->find( $item->{itype} ); # GetItem sets effective itemtype |
2898 |
if ( $itemtype ) { |
2938 |
if ( $itemtype ) { |
2899 |
my $daily_charge = $itemtype->calc_rental_charge_daily( { from => dt_from_string($lastreneweddate), to => $datedue } ); |
2939 |
my $daily_charge = $fees->rental_charge_daily(); |
2900 |
if ( $daily_charge > 0 ) { |
2940 |
if ( $daily_charge > 0 ) { |
2901 |
my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item->{'barcode'}"; |
2941 |
my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item->{'barcode'}"; |
2902 |
AddIssuingCharge( $issue, $daily_charge, $type_desc ) |
2942 |
AddIssuingCharge( $issue, $daily_charge, $type_desc ) |