Lines 46-52
use Koha::Exceptions;
Link Here
|
46 |
use Koha::Exceptions::Password; |
46 |
use Koha::Exceptions::Password; |
47 |
use Koha::Holds; |
47 |
use Koha::Holds; |
48 |
use Koha::Old::Checkouts; |
48 |
use Koha::Old::Checkouts; |
49 |
use Koha::OverdueRules; |
|
|
50 |
use Koha::Patron::Attributes; |
49 |
use Koha::Patron::Attributes; |
51 |
use Koha::Patron::Categories; |
50 |
use Koha::Patron::Categories; |
52 |
use Koha::Patron::Consents; |
51 |
use Koha::Patron::Consents; |
Lines 1171-1193
sub has_overdues {
Link Here
|
1171 |
|
1170 |
|
1172 |
=head3 has_restricting_overdues |
1171 |
=head3 has_restricting_overdues |
1173 |
|
1172 |
|
1174 |
my $has_restricting_overdues = $patron->has_restricting_overdues({ issue_branchcode => $branchcode }); |
1173 |
my $has_restricting_overdues = $patron->has_restricting_overdues(); |
1175 |
|
1174 |
|
1176 |
Returns true if patron has overdues that would result in debarment. |
1175 |
Returns true if patron has overdues that would result in debarment. |
1177 |
|
1176 |
|
1178 |
=cut |
1177 |
=cut |
1179 |
|
1178 |
|
1180 |
sub has_restricting_overdues { |
1179 |
sub has_restricting_overdues { |
1181 |
my ( $self, $params ) = @_; |
1180 |
my ($self) = @_; |
1182 |
$params //= {}; |
1181 |
|
1183 |
my $date = dt_from_string()->truncate( to => 'day' ); |
1182 |
# Fetch overdues |
|
|
1183 |
my $overdues = $self->overdues; |
1184 |
|
1185 |
# Short circuit if no overdues |
1186 |
return 0 unless $overdues->count; |
1184 |
|
1187 |
|
1185 |
# If ignoring unrestricted overdues, calculate which delay value for |
1188 |
my $categorycode = $self->categorycode(); |
1186 |
# overdue messages is set with restrictions. Then only include overdue |
1189 |
my $calendar; |
1187 |
# issues older than that date when counting. |
|
|
1188 |
#TODO: bail out/throw exception if $params->{issue_branchcode} not set? |
1189 |
my $debarred_delay = _get_overdue_debarred_delay( $params->{issue_branchcode}, $self->categorycode() ); |
1190 |
return 0 unless defined $debarred_delay; |
1191 |
|
1190 |
|
1192 |
# Emulate the conditions in overdue_notices.pl. |
1191 |
# Emulate the conditions in overdue_notices.pl. |
1193 |
# The overdue_notices-script effectively truncates both issues.date_due and current date |
1192 |
# The overdue_notices-script effectively truncates both issues.date_due and current date |
Lines 1199-1252
sub has_restricting_overdues {
Link Here
|
1199 |
# the current date or later. We can emulate this query by instead of truncating both to days in the SQL-query, |
1198 |
# the current date or later. We can emulate this query by instead of truncating both to days in the SQL-query, |
1200 |
# using the condition that date_due must be less then the current date truncated to days (time set to 00:00:00) |
1199 |
# using the condition that date_due must be less then the current date truncated to days (time set to 00:00:00) |
1201 |
# offset by one day in the future. |
1200 |
# offset by one day in the future. |
|
|
1201 |
my $date = dt_from_string()->truncate( to => 'day' )->add( days => 1 ); |
1202 |
|
1202 |
|
1203 |
$date->add( days => 1 ); |
1203 |
# Work from oldest overdue to newest |
|
|
1204 |
$overdues = $overdues->search( {}, { order_by => { '-desc' => 'me.date_due' } } ); |
1205 |
my $now = dt_from_string(); |
1204 |
|
1206 |
|
1205 |
my $calendar; |
1207 |
my ( $itemtype, $branchcode ) = ( "", "" ); |
1206 |
if ( C4::Context->preference('OverdueNoticeCalendar') ) { |
1208 |
while ( my $overdue = $overdues->next ) { |
1207 |
$calendar = Koha::Calendar->new( branchcode => $params->{issue_branchcode} ); |
|
|
1208 |
} |
1209 |
|
1209 |
|
1210 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
1210 |
# Short circuit if we're looking at the same branch and itemtype combination as last time as we've |
1211 |
my $issues = $self->_result->issues->search( { date_due => { '<' => $dtf->format_datetime($date) } } ); |
1211 |
# checked the oldest for this combination already |
1212 |
my $now = dt_from_string(); |
1212 |
next if ( ( $overdue->branchcode eq $branchcode ) && ( $overdue->item->itemtype eq $itemtype ) ); |
1213 |
|
|
|
1214 |
while ( my $issue = $issues->next ) { |
1215 |
my $days_between = |
1216 |
C4::Context->preference('OverdueNoticeCalendar') |
1217 |
? $calendar->days_between( dt_from_string( $issue->date_due ), $now )->in_units('days') |
1218 |
: $now->delta_days( dt_from_string( $issue->date_due ) )->in_units('days'); |
1219 |
if ( $days_between >= $debarred_delay ) { |
1220 |
return 1; |
1221 |
} |
1222 |
} |
1223 |
return 0; |
1224 |
} |
1225 |
|
1213 |
|
1226 |
# Fetch first delayX value from overduerules where debarredX is set, or 0 for no delay |
1214 |
# Capture the current branchcode and itemtype |
1227 |
sub _get_overdue_debarred_delay { |
1215 |
$branchcode = $overdue->branchcode; |
1228 |
my ( $branchcode, $categorycode ) = @_; |
1216 |
$itemtype = $overdue->item->itemtype; |
1229 |
my $dbh = C4::Context->dbh(); |
|
|
1230 |
|
1217 |
|
1231 |
# We get default rules if there is no rule for this branch |
1218 |
my $i = 0; |
1232 |
my $rule = Koha::OverdueRules->find( |
1219 |
DELAY: while (1) { |
1233 |
{ |
1220 |
$i++; |
1234 |
branchcode => $branchcode, |
1221 |
my $overdue_rules = Koha::CirculationRules->get_effective_rules( |
1235 |
categorycode => $categorycode |
1222 |
{ |
1236 |
} |
1223 |
rules => [ "overdue_$i" . '_delay', "overdue_$i" . '_restrict' ], |
1237 |
) |
1224 |
categorycode => $categorycode, |
1238 |
|| Koha::OverdueRules->find( |
1225 |
branchcode => $branchcode, |
1239 |
{ |
1226 |
itemtype => $itemtype, |
1240 |
branchcode => q{}, |
1227 |
} |
1241 |
categorycode => $categorycode |
1228 |
); |
1242 |
} |
|
|
1243 |
); |
1244 |
|
1229 |
|
1245 |
if ($rule) { |
1230 |
last DELAY if ( !defined( $overdue_rules->{ "overdue_$i" . '_delay' } ) ); |
1246 |
return $rule->delay1 if $rule->debarred1; |
1231 |
|
1247 |
return $rule->delay2 if $rule->debarred2; |
1232 |
next DELAY unless $overdue_rules->{ "overdue_$i" . '_restrict' }; |
1248 |
return $rule->delay3 if $rule->debarred3; |
1233 |
|
|
|
1234 |
if ( C4::Context->preference('OverdueNoticeCalendar') ) { |
1235 |
$calendar = Koha::Calendar->new( branchcode => $branchcode ); |
1236 |
} |
1237 |
|
1238 |
my $days_between = |
1239 |
C4::Context->preference('OverdueNoticeCalendar') |
1240 |
? $calendar->days_between( dt_from_string( $overdue->date_due ), $now )->in_units('days') |
1241 |
: $now->delta_days( dt_from_string( $overdue->date_due ) )->in_units('days'); |
1242 |
if ( $days_between >= $overdue_rules->{ "overdue_$i" . '_delay' } ) { |
1243 |
return 1; |
1244 |
} |
1245 |
} |
1249 |
} |
1246 |
} |
|
|
1247 |
return 0; |
1250 |
} |
1248 |
} |
1251 |
|
1249 |
|
1252 |
=head3 update_lastseen |
1250 |
=head3 update_lastseen |
1253 |
- |
|
|