Lines 3002-3008
sub CanBookBeRenewed {
Link Here
|
3002 |
|
3002 |
|
3003 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
3003 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
3004 |
return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; |
3004 |
return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; |
3005 |
$soonest = GetSoonestRenewDate($borrowernumber, $itemnumber); |
3005 |
$soonest = GetSoonestRenewDate($issue); |
3006 |
if ( $soonest > dt_from_string() ){ |
3006 |
if ( $soonest > dt_from_string() ){ |
3007 |
return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit; |
3007 |
return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit; |
3008 |
} |
3008 |
} |
Lines 3282-3295
sub GetRenewCount {
Link Here
|
3282 |
|
3282 |
|
3283 |
=head2 GetSoonestRenewDate |
3283 |
=head2 GetSoonestRenewDate |
3284 |
|
3284 |
|
3285 |
$NoRenewalBeforeThisDate = &GetSoonestRenewDate($borrowernumber, $itemnumber); |
3285 |
$NoRenewalBeforeThisDate = &GetSoonestRenewDate($issue); |
3286 |
|
3286 |
|
3287 |
Find out the soonest possible renew date of a borrowed item. |
3287 |
Find out the soonest possible renew date of a borrowed item. |
3288 |
|
3288 |
|
3289 |
C<$borrowernumber> is the borrower number of the patron who currently |
3289 |
C<$checkout> is the checkout object to renew. |
3290 |
has the item on loan. |
|
|
3291 |
|
3292 |
C<$itemnumber> is the number of the item to renew. |
3293 |
|
3290 |
|
3294 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible |
3291 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible |
3295 |
renew date, based on the value "No renewal before" of the applicable |
3292 |
renew date, based on the value "No renewal before" of the applicable |
Lines 3300-3315
cannot be found.
Link Here
|
3300 |
=cut |
3297 |
=cut |
3301 |
|
3298 |
|
3302 |
sub GetSoonestRenewDate { |
3299 |
sub GetSoonestRenewDate { |
3303 |
my ( $borrowernumber, $itemnumber ) = @_; |
3300 |
my ( $checkout ) = @_; |
3304 |
|
3301 |
|
3305 |
my $dbh = C4::Context->dbh; |
3302 |
my $item = $checkout->item or return; |
3306 |
|
3303 |
my $patron = $checkout->patron or return; |
3307 |
my $item = Koha::Items->find($itemnumber) or return; |
|
|
3308 |
my $itemissue = $item->checkout or return; |
3309 |
|
3310 |
$borrowernumber ||= $itemissue->borrowernumber; |
3311 |
my $patron = Koha::Patrons->find( $borrowernumber ) |
3312 |
or return; |
3313 |
|
3304 |
|
3314 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
3305 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
3315 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
3306 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
Lines 3329-3335
sub GetSoonestRenewDate {
Link Here
|
3329 |
and $issuing_rule->{norenewalbefore} ne "" ) |
3320 |
and $issuing_rule->{norenewalbefore} ne "" ) |
3330 |
{ |
3321 |
{ |
3331 |
my $soonestrenewal = |
3322 |
my $soonestrenewal = |
3332 |
dt_from_string( $itemissue->date_due )->subtract( |
3323 |
dt_from_string( $checkout->date_due )->subtract( |
3333 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
3324 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
3334 |
|
3325 |
|
3335 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3326 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
Lines 3338-3346
sub GetSoonestRenewDate {
Link Here
|
3338 |
$soonestrenewal->truncate( to => 'day' ); |
3329 |
$soonestrenewal->truncate( to => 'day' ); |
3339 |
} |
3330 |
} |
3340 |
return $soonestrenewal if $now < $soonestrenewal; |
3331 |
return $soonestrenewal if $now < $soonestrenewal; |
3341 |
} elsif ( $itemissue->auto_renew && $patron->autorenew_checkouts ) { |
3332 |
} elsif ( $checkout->auto_renew && $patron->autorenew_checkouts ) { |
3342 |
# Checkouts with auto-renewing fall back to due date |
3333 |
# Checkouts with auto-renewing fall back to due date |
3343 |
my $soonestrenewal = dt_from_string( $itemissue->date_due ); |
3334 |
my $soonestrenewal = dt_from_string( $checkout->date_due ); |
3344 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3335 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3345 |
and $issuing_rule->{lengthunit} eq 'days' ) |
3336 |
and $issuing_rule->{lengthunit} eq 'days' ) |
3346 |
{ |
3337 |
{ |
Lines 4462-4468
sub _CanBookBeAutoRenewed {
Link Here
|
4462 |
} |
4453 |
} |
4463 |
} |
4454 |
} |
4464 |
|
4455 |
|
4465 |
my $soonest = GetSoonestRenewDate($patron->id, $item->id); |
4456 |
my $soonest = GetSoonestRenewDate($issue); |
4466 |
if ( $soonest > dt_from_string() ) |
4457 |
if ( $soonest > dt_from_string() ) |
4467 |
{ |
4458 |
{ |
4468 |
return ( "auto_too_soon", $soonest ); |
4459 |
return ( "auto_too_soon", $soonest ); |