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 2597-2603
C<$itemnumber> is the number of the item to renew.
Link Here
|
2597 |
|
2604 |
|
2598 |
C<$override_limit>, if supplied with a true value, causes |
2605 |
C<$override_limit>, if supplied with a true value, causes |
2599 |
the limit on the number of times that the loan can be renewed |
2606 |
the limit on the number of times that the loan can be renewed |
2600 |
(as controlled by the item type) to be ignored. |
2607 |
(as controlled by the item type) to be ignored. Overriding also allows |
|
|
2608 |
to renew sooner than "No renewal before" und to manually renew loans |
2609 |
that are automatically renewed. |
2601 |
|
2610 |
|
2602 |
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The |
2611 |
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The |
2603 |
item must currently be on loan to the specified borrower; renewals |
2612 |
item must currently be on loan to the specified borrower; renewals |
Lines 2609-2618
already renewed the loan. $error will contain the reason the renewal can not pro
Link Here
|
2609 |
sub CanBookBeRenewed { |
2618 |
sub CanBookBeRenewed { |
2610 |
my ( $borrowernumber, $itemnumber, $override_limit ) = @_; |
2619 |
my ( $borrowernumber, $itemnumber, $override_limit ) = @_; |
2611 |
|
2620 |
|
2612 |
my $dbh = C4::Context->dbh; |
2621 |
my $dbh = C4::Context->dbh; |
2613 |
my $renews = 1; |
2622 |
my $renews = 1; |
2614 |
my $renewokay = 1; |
|
|
2615 |
my $error; |
2616 |
|
2623 |
|
2617 |
my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); |
2624 |
my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); |
2618 |
my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' ); |
2625 |
my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' ); |
Lines 2621-2662
sub CanBookBeRenewed {
Link Here
|
2621 |
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) |
2628 |
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) |
2622 |
or return; |
2629 |
or return; |
2623 |
|
2630 |
|
2624 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2631 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); |
2625 |
|
2632 |
|
2626 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2633 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
|
|
2634 |
|
2635 |
return ( 1, undef ) if $override_limit; |
2636 |
|
2637 |
my $branchcode = _GetCircControlBranch( $item, $borrower ); |
2638 |
my $issuingrule = |
2639 |
GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode ); |
2640 |
|
2641 |
return ( 0, "too_many" ) |
2642 |
if $issuingrule->{renewalsallowed} <= $itemissue->{renewals}; |
2627 |
|
2643 |
|
2628 |
if ( $issuingrule->{norenewalbefore} ) { |
2644 |
if ( $issuingrule->{norenewalbefore} ) { |
2629 |
|
2645 |
|
2630 |
# Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal. |
2646 |
# Get current time and add norenewalbefore. |
|
|
2647 |
# If this is smaller than date_due, it's too soon for renewal. |
2631 |
if ( |
2648 |
if ( |
2632 |
DateTime->now( time_zone => C4::Context->tz() )->add( |
2649 |
DateTime->now( time_zone => C4::Context->tz() )->add( |
2633 |
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} |
2650 |
$issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} |
2634 |
) < $itemissue->{date_due} |
2651 |
) < $itemissue->{date_due} |
2635 |
) |
2652 |
) |
2636 |
{ |
2653 |
{ |
2637 |
$renewokay = 0; |
2654 |
return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew}; |
2638 |
$error = "too_soon"; |
2655 |
return ( 0, "too_soon" ); |
2639 |
} |
2656 |
} |
2640 |
} |
2657 |
} |
2641 |
|
2658 |
|
2642 |
if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) { |
2659 |
return ( 0, "auto_renew" ) if $itemissue->{auto_renew}; |
2643 |
$renewokay = 0; |
2660 |
return ( 1, undef ); |
2644 |
$error = "too_many"; |
|
|
2645 |
} |
2646 |
|
2647 |
if ( $override_limit ) { |
2648 |
$renewokay = 1; |
2649 |
$error = undef; |
2650 |
} |
2651 |
|
2652 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber ); |
2653 |
|
2654 |
if ( $resfound ) { # '' when no hold was found |
2655 |
$renewokay = 0; |
2656 |
$error = "on_reserve"; |
2657 |
} |
2658 |
|
2659 |
return ( $renewokay, $error ); |
2660 |
} |
2661 |
} |
2661 |
|
2662 |
|
2662 |
=head2 AddRenewal |
2663 |
=head2 AddRenewal |