Lines 1183-1189
AddIssue does the following things :
Link Here
|
1183 |
=cut |
1183 |
=cut |
1184 |
|
1184 |
|
1185 |
sub AddIssue { |
1185 |
sub AddIssue { |
1186 |
my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode) = @_; |
1186 |
my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $auto_renew ) = @_; |
1187 |
my $dbh = C4::Context->dbh; |
1187 |
my $dbh = C4::Context->dbh; |
1188 |
my $barcodecheck=CheckValidBarcode($barcode); |
1188 |
my $barcodecheck=CheckValidBarcode($barcode); |
1189 |
if ($datedue && ref $datedue ne 'DateTime') { |
1189 |
if ($datedue && ref $datedue ne 'DateTime') { |
Lines 1249-1260
sub AddIssue {
Link Here
|
1249 |
$sth->execute(C4::Context->userenv->{'branch'},$item->{'itemnumber'}); |
1249 |
$sth->execute(C4::Context->userenv->{'branch'},$item->{'itemnumber'}); |
1250 |
} |
1250 |
} |
1251 |
|
1251 |
|
|
|
1252 |
# If automatic renewal wasn't selected while issuing, set the value according to the issuing rule. |
1253 |
unless ($auto_renew) { |
1254 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branch); |
1255 |
$auto_renew = $issuingrule->{auto_renew}; |
1256 |
} |
1257 |
|
1252 |
# Record in the database the fact that the book was issued. |
1258 |
# Record in the database the fact that the book was issued. |
1253 |
my $sth = |
1259 |
my $sth = |
1254 |
$dbh->prepare( |
1260 |
$dbh->prepare( |
1255 |
"INSERT INTO issues |
1261 |
"INSERT INTO issues |
1256 |
(borrowernumber, itemnumber,issuedate, date_due, branchcode) |
1262 |
(borrowernumber, itemnumber,issuedate, date_due, branchcode, auto_renew) |
1257 |
VALUES (?,?,?,?,?)" |
1263 |
VALUES (?,?,?,?,?,?)" |
1258 |
); |
1264 |
); |
1259 |
unless ($datedue) { |
1265 |
unless ($datedue) { |
1260 |
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
1266 |
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
Lines 1267-1273
sub AddIssue {
Link Here
|
1267 |
$item->{'itemnumber'}, # itemnumber |
1273 |
$item->{'itemnumber'}, # itemnumber |
1268 |
$issuedate->strftime('%Y-%m-%d %H:%M:00'), # issuedate |
1274 |
$issuedate->strftime('%Y-%m-%d %H:%M:00'), # issuedate |
1269 |
$datedue->strftime('%Y-%m-%d %H:%M:00'), # date_due |
1275 |
$datedue->strftime('%Y-%m-%d %H:%M:00'), # date_due |
1270 |
C4::Context->userenv->{'branch'} # branchcode |
1276 |
C4::Context->userenv->{'branch'}, # branchcode |
|
|
1277 |
$auto_renew ? 1 : 0 # automatic renewal |
1271 |
); |
1278 |
); |
1272 |
if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart. |
1279 |
if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart. |
1273 |
CartToShelf( $item->{'itemnumber'} ); |
1280 |
CartToShelf( $item->{'itemnumber'} ); |
Lines 2599-2605
C<$itemnumber> is the number of the item to renew.
Link Here
|
2599 |
|
2606 |
|
2600 |
C<$override_limit>, if supplied with a true value, causes |
2607 |
C<$override_limit>, if supplied with a true value, causes |
2601 |
the limit on the number of times that the loan can be renewed |
2608 |
the limit on the number of times that the loan can be renewed |
2602 |
(as controlled by the item type) to be ignored. |
2609 |
(as controlled by the item type) to be ignored. Overriding also allows |
|
|
2610 |
to renew sooner than "No renewal before" and to manually renew loans |
2611 |
that are automatically renewed. |
2603 |
|
2612 |
|
2604 |
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The |
2613 |
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The |
2605 |
item must currently be on loan to the specified borrower; renewals |
2614 |
item must currently be on loan to the specified borrower; renewals |
Lines 2611-2620
already renewed the loan. $error will contain the reason the renewal can not pro
Link Here
|
2611 |
sub CanBookBeRenewed { |
2620 |
sub CanBookBeRenewed { |
2612 |
my ( $borrowernumber, $itemnumber, $override_limit ) = @_; |
2621 |
my ( $borrowernumber, $itemnumber, $override_limit ) = @_; |
2613 |
|
2622 |
|
2614 |
my $dbh = C4::Context->dbh; |
2623 |
my $dbh = C4::Context->dbh; |
2615 |
my $renews = 1; |
2624 |
my $renews = 1; |
2616 |
my $renewokay = 1; |
|
|
2617 |
my $error; |
2618 |
|
2625 |
|
2619 |
my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); |
2626 |
my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); |
2620 |
my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' ); |
2627 |
my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' ); |
Lines 2623-2664
sub CanBookBeRenewed {
Link Here
|
2623 |
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) |
2630 |
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) |
2624 |
or return; |
2631 |
or return; |
2625 |
|
2632 |
|
2626 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2633 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); |
2627 |
|
2634 |
|
2628 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2635 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
|
|
2636 |
|
2637 |
return ( 1, undef ) if $override_limit; |
2638 |
|
2639 |
my $branchcode = _GetCircControlBranch( $item, $borrower ); |
2640 |
my $issuingrule = |
2641 |
GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode ); |
2642 |
|
2643 |
return ( 0, "too_many" ) |
2644 |
if $issuingrule->{renewalsallowed} <= $itemissue->{renewals}; |
2629 |
|
2645 |
|
2630 |
if ( $issuingrule->{norenewalbefore} ) { |
2646 |
if ( $issuingrule->{norenewalbefore} ) { |
2631 |
|
2647 |
|
2632 |
# Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal. |
2648 |
# Get current time and add norenewalbefore. |
|
|
2649 |
# If this is smaller than date_due, it's too soon for renewal. |
2633 |
if ( |
2650 |
if ( |
2634 |
DateTime->now( time_zone => C4::Context->tz() )->add( |
2651 |
DateTime->now( time_zone => C4::Context->tz() )->add( |
2635 |
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} |
2652 |
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} |
2636 |
) < $itemissue->{date_due} |
2653 |
) < $itemissue->{date_due} |
2637 |
) |
2654 |
) |
2638 |
{ |
2655 |
{ |
2639 |
$renewokay = 0; |
2656 |
return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew}; |
2640 |
$error = "too_soon"; |
2657 |
return ( 0, "too_soon" ); |
2641 |
} |
2658 |
} |
2642 |
} |
2659 |
} |
2643 |
|
2660 |
|
2644 |
if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) { |
2661 |
return ( 0, "auto_renew" ) if $itemissue->{auto_renew}; |
2645 |
$renewokay = 0; |
2662 |
return ( 1, undef ); |
2646 |
$error = "too_many"; |
|
|
2647 |
} |
2648 |
|
2649 |
if ( $override_limit ) { |
2650 |
$renewokay = 1; |
2651 |
$error = undef; |
2652 |
} |
2653 |
|
2654 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber ); |
2655 |
|
2656 |
if ( $resfound ) { # '' when no hold was found |
2657 |
$renewokay = 0; |
2658 |
$error = "on_reserve"; |
2659 |
} |
2660 |
|
2661 |
return ( $renewokay, $error ); |
2662 |
} |
2663 |
} |
2663 |
|
2664 |
|
2664 |
=head2 AddRenewal |
2665 |
=head2 AddRenewal |