From 31a5d0b4a5078ec223bca430673a8674a1b7f7ee Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Tue, 10 Sep 2019 16:59:30 +0200 Subject: [PATCH] Bug 25813: Enhance patron expiration in SIP display Currently, the patron information returned by SIP only shows "PATRON EXPIRED" when the patron card has expired. This patch makes the display more consistant with the Opac display and also complies with the NotifyBorrowerDeparture system preference. Test plan: - apply the patch - set NotifyBorrowerDeparture to 0 - check that nothing is ever displayed about the card expiration - set NotifyBorrowerDeparture to a value greater than 0 - check that the following message will be displayed for a card that will expire within NotifyBorrowerDeparture days: "Your card will expire on {correctly formatted date}" - check that the following message will be displayed for a card that has expired: "Your account has expired as of {correctly formatted date}" You can use src/C4/SIP/interactive_patron_dump.pl for easier testing. --- C4/SIP/ILS/Patron.pm | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 6969c115ed..465f5591b6 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -27,6 +27,9 @@ use C4::Auth qw(checkpw); use Koha::Items; use Koha::Libraries; use Koha::Patrons; +use Date::Calc qw/Today Date_to_Days/; +use Koha::DateUtils; + our $kp; # koha patron @@ -49,15 +52,28 @@ sub new { my $pw = $kp->{password}; my $flags = C4::Members::patronflags( $kp ); my $debarred = $patron->is_debarred; + my $expired = 0; $debug and warn sprintf("Debarred = %s : ", ($debarred||'undef')); # Do we need more debug info here? - my ($day, $month, $year) = (localtime)[3,4,5]; - my $today = sprintf '%04d-%02d-%02d', $year+1900, $month+1, $day; - my $expired = ($today gt $kp->{dateexpiry}) ? 1 : 0; - if ($expired) { - if ($kp->{opacnote} ) { - $kp->{opacnote} .= q{ }; + if ( $kp->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) { + my ( $today_year, $today_month, $today_day) = Today(); + my ($warning_year, $warning_month, $warning_day) = split /-/, $kp->{'dateexpiry'}; + my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - Date_to_Days( $today_year, $today_month, $today_day ); + my $dt = dt_from_string( $kp->{'dateexpiry'}, 'iso' ); + my $dateexpiry = output_pref({ dt => $dt, dateonly => 1}); + if ( $days_to_expiry < 0 ) { + #borrower card has expired, warn the borrower + if ($kp->{opacnote} ) { + $kp->{opacnote} .= q{ }; + } + $kp->{opacnote} .= "Your account has expired as of $dateexpiry"; + $expired = 1; + } elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) { + # borrower card soon to expire, warn the borrower + if ($kp->{opacnote} ) { + $kp->{opacnote} .= q{ }; + } + $kp->{opacnote} .= "Your card will expire on $dateexpiry"; } - $kp->{opacnote} .= 'PATRON EXPIRED'; } my %ilspatron; my $adr = _get_address($kp); -- 2.11.0