From 86063e4a72c246a31ad0fe6e6f0689e9b816db7f 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 | 34 +++++++++++++++++----- t/db_dependent/SIP/Patron.t | 58 ++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 9 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 9bcb1c0124..f3dfea74bd 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -30,10 +30,11 @@ use Koha::Checkouts; use Koha::TemplateUtils qw( process_tt ); use Koha::Patron::Messages; use Koha::DateUtils qw(dt_from_string output_pref); +use Date::Calc qw/Today Date_to_Days/; our $kp; # koha patron -=head1 METHODS +=head1 Methods =cut @@ -64,14 +65,31 @@ sub new { my $pw = $kp->{password}; my $flags = C4::Members::patronflags( $kp ); my $debarred = $patron->is_debarred; - 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{ }; + siplog( "LOG_DEBUG", "Debarred = %s : ", ( $debarred || 'undef' ) ); # Do we need more debug info here? + my $expired = 0; + 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); diff --git a/t/db_dependent/SIP/Patron.t b/t/db_dependent/SIP/Patron.t index 9b6f151644..67e81124bf 100755 --- a/t/db_dependent/SIP/Patron.t +++ b/t/db_dependent/SIP/Patron.t @@ -4,7 +4,7 @@ # This needs to be extended! Your help is appreciated.. use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use t::lib::Mocks; use t::lib::TestBuilder; @@ -252,6 +252,62 @@ subtest "fine_items tests" => sub { $schema->storage->txn_rollback; +subtest "Patron expiration tests" => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + opacnote => "", + + # dateexpiry is today when unspecified + } + } + ); + + t::lib::Mocks::mock_preference( 'NotifyBorrowerDeparture', 0 ); + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + like( + $sip_patron->screen_msg, qr/^Greetings from Koha. $/, + "No message is displayed when NotifyBorrowerDeparture is disabled" + ); + + t::lib::Mocks::mock_preference( 'NotifyBorrowerDeparture', 1 ); + $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + like( + $sip_patron->screen_msg, qr/Your card will expire on/, + "A message is displayed when the card expires within NotifyBorrowerDeparture days" + ); + + $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + opacnote => "", + dateexpiry => "1900-01-01", + } + } + ); + $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + like( + $sip_patron->screen_msg, qr/Your account has expired as of/, + "A message is displayed when the card has expired and NotifyBorrowerDeparture is not disabled" + ); + + t::lib::Mocks::mock_preference( 'NotifyBorrowerDeparture', 0 ); + $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + like( + $sip_patron->screen_msg, qr/^Greetings from Koha. $/, + "No message is displayed when the card has expired and NotifyBorrowerDeparture is disabled" + ); + + $schema->storage->txn_rollback; + +}; + subtest "NoIssuesChargeGuarantees tests" => sub { plan tests => 6; -- 2.30.2