|
Lines 51-57
use Koha::HoldGroups;
Link Here
|
| 51 |
use Koha::ILL::Requests; |
51 |
use Koha::ILL::Requests; |
| 52 |
use Koha::ItemTypes; |
52 |
use Koha::ItemTypes; |
| 53 |
use Koha::Old::Checkouts; |
53 |
use Koha::Old::Checkouts; |
| 54 |
use Koha::OverdueRules; |
|
|
| 55 |
use Koha::Patron::Attributes; |
54 |
use Koha::Patron::Attributes; |
| 56 |
use Koha::Patron::Categories; |
55 |
use Koha::Patron::Categories; |
| 57 |
use Koha::Patron::Consents; |
56 |
use Koha::Patron::Consents; |
|
Lines 1220-1242
sub has_overdues {
Link Here
|
| 1220 |
|
1219 |
|
| 1221 |
=head3 has_restricting_overdues |
1220 |
=head3 has_restricting_overdues |
| 1222 |
|
1221 |
|
| 1223 |
my $has_restricting_overdues = $patron->has_restricting_overdues({ issue_branchcode => $branchcode }); |
1222 |
my $has_restricting_overdues = $patron->has_restricting_overdues(); |
| 1224 |
|
1223 |
|
| 1225 |
Returns true if patron has overdues that would result in debarment. |
1224 |
Returns true if patron has overdues that would result in debarment. |
| 1226 |
|
1225 |
|
| 1227 |
=cut |
1226 |
=cut |
| 1228 |
|
1227 |
|
| 1229 |
sub has_restricting_overdues { |
1228 |
sub has_restricting_overdues { |
| 1230 |
my ( $self, $params ) = @_; |
1229 |
my ($self) = @_; |
| 1231 |
$params //= {}; |
1230 |
|
| 1232 |
my $date = dt_from_string()->truncate( to => 'day' ); |
1231 |
# Fetch overdues |
|
|
1232 |
my $overdues = $self->overdues; |
| 1233 |
|
| 1234 |
# Short circuit if no overdues |
| 1235 |
return 0 unless $overdues->count; |
| 1233 |
|
1236 |
|
| 1234 |
# If ignoring unrestricted overdues, calculate which delay value for |
1237 |
my $categorycode = $self->categorycode(); |
| 1235 |
# overdue messages is set with restrictions. Then only include overdue |
1238 |
my $calendar; |
| 1236 |
# issues older than that date when counting. |
|
|
| 1237 |
#TODO: bail out/throw exception if $params->{issue_branchcode} not set? |
| 1238 |
my $debarred_delay = _get_overdue_debarred_delay( $params->{issue_branchcode}, $self->categorycode() ); |
| 1239 |
return 0 unless defined $debarred_delay; |
| 1240 |
|
1239 |
|
| 1241 |
# Emulate the conditions in overdue_notices.pl. |
1240 |
# Emulate the conditions in overdue_notices.pl. |
| 1242 |
# The overdue_notices-script effectively truncates both issues.date_due and current date |
1241 |
# The overdue_notices-script effectively truncates both issues.date_due and current date |
|
Lines 1248-1300
sub has_restricting_overdues {
Link Here
|
| 1248 |
# the current date or later. We can emulate this query by instead of truncating both to days in the SQL-query, |
1247 |
# the current date or later. We can emulate this query by instead of truncating both to days in the SQL-query, |
| 1249 |
# using the condition that date_due must be less then the current date truncated to days (time set to 00:00:00) |
1248 |
# using the condition that date_due must be less then the current date truncated to days (time set to 00:00:00) |
| 1250 |
# offset by one day in the future. |
1249 |
# offset by one day in the future. |
|
|
1250 |
my $date = dt_from_string()->truncate( to => 'day' )->add( days => 1 ); |
| 1251 |
|
1251 |
|
| 1252 |
$date->add( days => 1 ); |
1252 |
# Work from oldest overdue to newest |
|
|
1253 |
$overdues = $overdues->search( {}, { order_by => { '-desc' => 'me.date_due' } } ); |
| 1254 |
my $now = dt_from_string(); |
| 1253 |
|
1255 |
|
| 1254 |
my $calendar; |
1256 |
my ( $itemtype, $branchcode ) = ( "", "" ); |
| 1255 |
if ( C4::Context->preference('OverdueNoticeCalendar') ) { |
1257 |
while ( my $overdue = $overdues->next ) { |
| 1256 |
$calendar = Koha::Calendar->new( branchcode => $params->{issue_branchcode} ); |
|
|
| 1257 |
} |
| 1258 |
|
1258 |
|
| 1259 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
1259 |
# Short circuit if we're looking at the same branch and itemtype combination as last time as we've |
| 1260 |
my $issues = $self->_result->issues->search( { date_due => { '<' => $dtf->format_datetime($date) } } ); |
1260 |
# checked the oldest for this combination already |
| 1261 |
my $now = dt_from_string(); |
1261 |
next if ( ( $overdue->branchcode eq $branchcode ) && ( $overdue->item->itemtype eq $itemtype ) ); |
| 1262 |
|
|
|
| 1263 |
while ( my $issue = $issues->next ) { |
| 1264 |
my $days_between = |
| 1265 |
C4::Context->preference('OverdueNoticeCalendar') |
| 1266 |
? $calendar->days_between( dt_from_string( $issue->date_due ), $now )->in_units('days') |
| 1267 |
: $now->delta_days( dt_from_string( $issue->date_due ) )->in_units('days'); |
| 1268 |
if ( $days_between >= $debarred_delay ) { |
| 1269 |
return 1; |
| 1270 |
} |
| 1271 |
} |
| 1272 |
return 0; |
| 1273 |
} |
| 1274 |
|
1262 |
|
| 1275 |
# Fetch first delayX value from overduerules where debarredX is set, or 0 for no delay |
1263 |
# Capture the current branchcode and itemtype |
| 1276 |
sub _get_overdue_debarred_delay { |
1264 |
$branchcode = $overdue->branchcode; |
| 1277 |
my ( $branchcode, $categorycode ) = @_; |
1265 |
$itemtype = $overdue->item->itemtype; |
| 1278 |
|
1266 |
|
| 1279 |
# We get default rules if there is no rule for this branch |
1267 |
my $i = 0; |
| 1280 |
my $rule = Koha::OverdueRules->find( |
1268 |
DELAY: while (1) { |
| 1281 |
{ |
1269 |
$i++; |
| 1282 |
branchcode => $branchcode, |
1270 |
my $overdue_rules = Koha::CirculationRules->get_effective_rules( |
| 1283 |
categorycode => $categorycode |
1271 |
{ |
| 1284 |
} |
1272 |
rules => [ "overdue_$i" . '_delay', "overdue_$i" . '_restrict' ], |
| 1285 |
) |
1273 |
categorycode => $categorycode, |
| 1286 |
|| Koha::OverdueRules->find( |
1274 |
branchcode => $branchcode, |
| 1287 |
{ |
1275 |
itemtype => $itemtype, |
| 1288 |
branchcode => q{}, |
1276 |
} |
| 1289 |
categorycode => $categorycode |
1277 |
); |
| 1290 |
} |
|
|
| 1291 |
); |
| 1292 |
|
1278 |
|
| 1293 |
if ($rule) { |
1279 |
last DELAY if ( !defined( $overdue_rules->{ "overdue_$i" . '_delay' } ) ); |
| 1294 |
return $rule->delay1 if $rule->debarred1; |
1280 |
|
| 1295 |
return $rule->delay2 if $rule->debarred2; |
1281 |
next DELAY unless $overdue_rules->{ "overdue_$i" . '_restrict' }; |
| 1296 |
return $rule->delay3 if $rule->debarred3; |
1282 |
|
|
|
1283 |
if ( C4::Context->preference('OverdueNoticeCalendar') ) { |
| 1284 |
$calendar = Koha::Calendar->new( branchcode => $branchcode ); |
| 1285 |
} |
| 1286 |
|
| 1287 |
my $days_between = |
| 1288 |
C4::Context->preference('OverdueNoticeCalendar') |
| 1289 |
? $calendar->days_between( dt_from_string( $overdue->date_due ), $now )->in_units('days') |
| 1290 |
: $now->delta_days( dt_from_string( $overdue->date_due ) )->in_units('days'); |
| 1291 |
if ( $days_between >= $overdue_rules->{ "overdue_$i" . '_delay' } ) { |
| 1292 |
return 1; |
| 1293 |
} |
| 1294 |
} |
| 1297 |
} |
1295 |
} |
|
|
1296 |
return 0; |
| 1298 |
} |
1297 |
} |
| 1299 |
|
1298 |
|
| 1300 |
=head3 update_lastseen |
1299 |
=head3 update_lastseen |
| 1301 |
- |
|
|