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