Lines 49-55
use Koha::Holds;
Link Here
|
49 |
use Koha::ILL::Requests; |
49 |
use Koha::ILL::Requests; |
50 |
use Koha::ItemTypes; |
50 |
use Koha::ItemTypes; |
51 |
use Koha::Old::Checkouts; |
51 |
use Koha::Old::Checkouts; |
52 |
use Koha::OverdueRules; |
|
|
53 |
use Koha::Patron::Attributes; |
52 |
use Koha::Patron::Attributes; |
54 |
use Koha::Patron::Categories; |
53 |
use Koha::Patron::Categories; |
55 |
use Koha::Patron::Consents; |
54 |
use Koha::Patron::Consents; |
Lines 1251-1273
sub has_overdues {
Link Here
|
1251 |
|
1250 |
|
1252 |
=head3 has_restricting_overdues |
1251 |
=head3 has_restricting_overdues |
1253 |
|
1252 |
|
1254 |
my $has_restricting_overdues = $patron->has_restricting_overdues({ issue_branchcode => $branchcode }); |
1253 |
my $has_restricting_overdues = $patron->has_restricting_overdues(); |
1255 |
|
1254 |
|
1256 |
Returns true if patron has overdues that would result in debarment. |
1255 |
Returns true if patron has overdues that would result in debarment. |
1257 |
|
1256 |
|
1258 |
=cut |
1257 |
=cut |
1259 |
|
1258 |
|
1260 |
sub has_restricting_overdues { |
1259 |
sub has_restricting_overdues { |
1261 |
my ( $self, $params ) = @_; |
1260 |
my ($self) = @_; |
1262 |
$params //= {}; |
1261 |
|
1263 |
my $date = dt_from_string()->truncate( to => 'day' ); |
1262 |
# Fetch overdues |
|
|
1263 |
my $overdues = $self->overdues; |
1264 |
|
1265 |
# Short circuit if no overdues |
1266 |
return 0 unless $overdues->count; |
1264 |
|
1267 |
|
1265 |
# If ignoring unrestricted overdues, calculate which delay value for |
1268 |
my $categorycode = $self->categorycode(); |
1266 |
# overdue messages is set with restrictions. Then only include overdue |
1269 |
my $calendar; |
1267 |
# issues older than that date when counting. |
|
|
1268 |
#TODO: bail out/throw exception if $params->{issue_branchcode} not set? |
1269 |
my $debarred_delay = _get_overdue_debarred_delay( $params->{issue_branchcode}, $self->categorycode() ); |
1270 |
return 0 unless defined $debarred_delay; |
1271 |
|
1270 |
|
1272 |
# Emulate the conditions in overdue_notices.pl. |
1271 |
# Emulate the conditions in overdue_notices.pl. |
1273 |
# The overdue_notices-script effectively truncates both issues.date_due and current date |
1272 |
# The overdue_notices-script effectively truncates both issues.date_due and current date |
Lines 1279-1332
sub has_restricting_overdues {
Link Here
|
1279 |
# the current date or later. We can emulate this query by instead of truncating both to days in the SQL-query, |
1278 |
# the current date or later. We can emulate this query by instead of truncating both to days in the SQL-query, |
1280 |
# using the condition that date_due must be less then the current date truncated to days (time set to 00:00:00) |
1279 |
# using the condition that date_due must be less then the current date truncated to days (time set to 00:00:00) |
1281 |
# offset by one day in the future. |
1280 |
# offset by one day in the future. |
|
|
1281 |
my $date = dt_from_string()->truncate( to => 'day' )->add( days => 1 ); |
1282 |
|
1282 |
|
1283 |
$date->add( days => 1 ); |
1283 |
# Work from oldest overdue to newest |
|
|
1284 |
$overdues = $overdues->search( {}, { order_by => { '-desc' => 'me.date_due' } } ); |
1285 |
my $now = dt_from_string(); |
1284 |
|
1286 |
|
1285 |
my $calendar; |
1287 |
my ( $itemtype, $branchcode ) = ( "", "" ); |
1286 |
if ( C4::Context->preference('OverdueNoticeCalendar') ) { |
1288 |
while ( my $overdue = $overdues->next ) { |
1287 |
$calendar = Koha::Calendar->new( branchcode => $params->{issue_branchcode} ); |
|
|
1288 |
} |
1289 |
|
1289 |
|
1290 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
1290 |
# Short circuit if we're looking at the same branch and itemtype combination as last time as we've |
1291 |
my $issues = $self->_result->issues->search( { date_due => { '<' => $dtf->format_datetime($date) } } ); |
1291 |
# checked the oldest for this combination already |
1292 |
my $now = dt_from_string(); |
1292 |
next if ( ( $overdue->branchcode eq $branchcode ) && ( $overdue->item->itemtype eq $itemtype ) ); |
1293 |
|
|
|
1294 |
while ( my $issue = $issues->next ) { |
1295 |
my $days_between = |
1296 |
C4::Context->preference('OverdueNoticeCalendar') |
1297 |
? $calendar->days_between( dt_from_string( $issue->date_due ), $now )->in_units('days') |
1298 |
: $now->delta_days( dt_from_string( $issue->date_due ) )->in_units('days'); |
1299 |
if ( $days_between >= $debarred_delay ) { |
1300 |
return 1; |
1301 |
} |
1302 |
} |
1303 |
return 0; |
1304 |
} |
1305 |
|
1293 |
|
1306 |
# Fetch first delayX value from overduerules where debarredX is set, or 0 for no delay |
1294 |
# Capture the current branchcode and itemtype |
1307 |
sub _get_overdue_debarred_delay { |
1295 |
$branchcode = $overdue->branchcode; |
1308 |
my ( $branchcode, $categorycode ) = @_; |
1296 |
$itemtype = $overdue->item->itemtype; |
1309 |
my $dbh = C4::Context->dbh(); |
|
|
1310 |
|
1297 |
|
1311 |
# We get default rules if there is no rule for this branch |
1298 |
my $i = 0; |
1312 |
my $rule = Koha::OverdueRules->find( |
1299 |
DELAY: while (1) { |
1313 |
{ |
1300 |
$i++; |
1314 |
branchcode => $branchcode, |
1301 |
my $overdue_rules = Koha::CirculationRules->get_effective_rules( |
1315 |
categorycode => $categorycode |
1302 |
{ |
1316 |
} |
1303 |
rules => [ "overdue_$i" . '_delay', "overdue_$i" . '_restrict' ], |
1317 |
) |
1304 |
categorycode => $categorycode, |
1318 |
|| Koha::OverdueRules->find( |
1305 |
branchcode => $branchcode, |
1319 |
{ |
1306 |
itemtype => $itemtype, |
1320 |
branchcode => q{}, |
1307 |
} |
1321 |
categorycode => $categorycode |
1308 |
); |
1322 |
} |
|
|
1323 |
); |
1324 |
|
1309 |
|
1325 |
if ($rule) { |
1310 |
last DELAY if ( !defined( $overdue_rules->{ "overdue_$i" . '_delay' } ) ); |
1326 |
return $rule->delay1 if $rule->debarred1; |
1311 |
|
1327 |
return $rule->delay2 if $rule->debarred2; |
1312 |
next DELAY unless $overdue_rules->{ "overdue_$i" . '_restrict' }; |
1328 |
return $rule->delay3 if $rule->debarred3; |
1313 |
|
|
|
1314 |
if ( C4::Context->preference('OverdueNoticeCalendar') ) { |
1315 |
$calendar = Koha::Calendar->new( branchcode => $branchcode ); |
1316 |
} |
1317 |
|
1318 |
my $days_between = |
1319 |
C4::Context->preference('OverdueNoticeCalendar') |
1320 |
? $calendar->days_between( dt_from_string( $overdue->date_due ), $now )->in_units('days') |
1321 |
: $now->delta_days( dt_from_string( $overdue->date_due ) )->in_units('days'); |
1322 |
if ( $days_between >= $overdue_rules->{ "overdue_$i" . '_delay' } ) { |
1323 |
return 1; |
1324 |
} |
1325 |
} |
1329 |
} |
1326 |
} |
|
|
1327 |
return 0; |
1330 |
} |
1328 |
} |
1331 |
|
1329 |
|
1332 |
=head3 update_lastseen |
1330 |
=head3 update_lastseen |
1333 |
- |
|
|