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