|
Lines 2871-2877
sub CanBookBeRenewed {
Link Here
|
| 2871 |
|
2871 |
|
| 2872 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
2872 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
| 2873 |
return ( 0, $auto_renew, $soonest ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; |
2873 |
return ( 0, $auto_renew, $soonest ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; |
| 2874 |
$soonest = GetSoonestRenewDate($borrowernumber, $itemnumber); |
2874 |
$soonest = GetSoonestRenewDate($issue); |
| 2875 |
if ( $soonest > dt_from_string() ){ |
2875 |
if ( $soonest > dt_from_string() ){ |
| 2876 |
return (0, "too_soon", $soonest ) unless $override_limit; |
2876 |
return (0, "too_soon", $soonest ) unless $override_limit; |
| 2877 |
} |
2877 |
} |
|
Lines 3151-3164
sub GetRenewCount {
Link Here
|
| 3151 |
|
3151 |
|
| 3152 |
=head2 GetSoonestRenewDate |
3152 |
=head2 GetSoonestRenewDate |
| 3153 |
|
3153 |
|
| 3154 |
$NoRenewalBeforeThisDate = &GetSoonestRenewDate($borrowernumber, $itemnumber); |
3154 |
$NoRenewalBeforeThisDate = &GetSoonestRenewDate($issue); |
| 3155 |
|
3155 |
|
| 3156 |
Find out the soonest possible renew date of a borrowed item. |
3156 |
Find out the soonest possible renew date of a borrowed item. |
| 3157 |
|
3157 |
|
| 3158 |
C<$borrowernumber> is the borrower number of the patron who currently |
3158 |
C<$checkout> is the checkout object to renew. |
| 3159 |
has the item on loan. |
|
|
| 3160 |
|
| 3161 |
C<$itemnumber> is the number of the item to renew. |
| 3162 |
|
3159 |
|
| 3163 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible |
3160 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible |
| 3164 |
renew date, based on the value "No renewal before" of the applicable |
3161 |
renew date, based on the value "No renewal before" of the applicable |
|
Lines 3169-3184
cannot be found.
Link Here
|
| 3169 |
=cut |
3166 |
=cut |
| 3170 |
|
3167 |
|
| 3171 |
sub GetSoonestRenewDate { |
3168 |
sub GetSoonestRenewDate { |
| 3172 |
my ( $borrowernumber, $itemnumber ) = @_; |
3169 |
my ( $checkout ) = @_; |
| 3173 |
|
3170 |
|
| 3174 |
my $dbh = C4::Context->dbh; |
3171 |
my $item = $checkout->item or return; |
| 3175 |
|
3172 |
my $patron = $checkout->patron or return; |
| 3176 |
my $item = Koha::Items->find($itemnumber) or return; |
|
|
| 3177 |
my $itemissue = $item->checkout or return; |
| 3178 |
|
| 3179 |
$borrowernumber ||= $itemissue->borrowernumber; |
| 3180 |
my $patron = Koha::Patrons->find( $borrowernumber ) |
| 3181 |
or return; |
| 3182 |
|
3173 |
|
| 3183 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
3174 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
| 3184 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
3175 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
|
Lines 3198-3204
sub GetSoonestRenewDate {
Link Here
|
| 3198 |
and $issuing_rule->{norenewalbefore} ne "" ) |
3189 |
and $issuing_rule->{norenewalbefore} ne "" ) |
| 3199 |
{ |
3190 |
{ |
| 3200 |
my $soonestrenewal = |
3191 |
my $soonestrenewal = |
| 3201 |
dt_from_string( $itemissue->date_due )->subtract( |
3192 |
dt_from_string( $checkout->date_due )->subtract( |
| 3202 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
3193 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
| 3203 |
|
3194 |
|
| 3204 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3195 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
|
Lines 3207-3215
sub GetSoonestRenewDate {
Link Here
|
| 3207 |
$soonestrenewal->truncate( to => 'day' ); |
3198 |
$soonestrenewal->truncate( to => 'day' ); |
| 3208 |
} |
3199 |
} |
| 3209 |
return $soonestrenewal if $now < $soonestrenewal; |
3200 |
return $soonestrenewal if $now < $soonestrenewal; |
| 3210 |
} elsif ( $itemissue->auto_renew && $patron->autorenew_checkouts ) { |
3201 |
} elsif ( $checkout->auto_renew && $patron->autorenew_checkouts ) { |
| 3211 |
# Checkouts with auto-renewing fall back to due date |
3202 |
# Checkouts with auto-renewing fall back to due date |
| 3212 |
my $soonestrenewal = dt_from_string( $itemissue->date_due ); |
3203 |
my $soonestrenewal = dt_from_string( $checkout->date_due ); |
| 3213 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3204 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 3214 |
and $issuing_rule->{lengthunit} eq 'days' ) |
3205 |
and $issuing_rule->{lengthunit} eq 'days' ) |
| 3215 |
{ |
3206 |
{ |
|
Lines 4333-4339
sub _CanBookBeAutoRenewed {
Link Here
|
| 4333 |
|
4324 |
|
| 4334 |
if ( defined $issuing_rule->{norenewalbefore} |
4325 |
if ( defined $issuing_rule->{norenewalbefore} |
| 4335 |
and $issuing_rule->{norenewalbefore} ne "" ) { |
4326 |
and $issuing_rule->{norenewalbefore} ne "" ) { |
| 4336 |
my $soonest = GetSoonestRenewDate($patron->id, $item->id); |
4327 |
my $soonest = GetSoonestRenewDate($issue); |
| 4337 |
if ( $soonest > dt_from_string()) { |
4328 |
if ( $soonest > dt_from_string()) { |
| 4338 |
return ( "auto_too_soon", $soonest ); |
4329 |
return ( "auto_too_soon", $soonest ); |
| 4339 |
} else { |
4330 |
} else { |