View | Details | Raw Unified | Return to bug 25813
Collapse All | Expand All

(-)a/C4/SIP/ILS/Patron.pm (-8 / +26 lines)
Lines 30-39 use Koha::Checkouts; Link Here
30
use Koha::TemplateUtils qw( process_tt );
30
use Koha::TemplateUtils qw( process_tt );
31
use Koha::Patron::Messages;
31
use Koha::Patron::Messages;
32
use Koha::DateUtils qw(dt_from_string output_pref);
32
use Koha::DateUtils qw(dt_from_string output_pref);
33
use Date::Calc qw/Today Date_to_Days/;
33
34
34
our $kp;    # koha patron
35
our $kp;    # koha patron
35
36
36
=head1 METHODS
37
=head1 Methods
37
38
38
=cut
39
=cut
39
40
Lines 64-77 sub new { Link Here
64
    my $pw        = $kp->{password};
65
    my $pw        = $kp->{password};
65
    my $flags     = C4::Members::patronflags( $kp );
66
    my $flags     = C4::Members::patronflags( $kp );
66
    my $debarred  = $patron->is_debarred;
67
    my $debarred  = $patron->is_debarred;
67
    my ($day, $month, $year) = (localtime)[3,4,5];
68
    siplog( "LOG_DEBUG", "Debarred = %s : ", ( $debarred || 'undef' ) );    # Do we need more debug info here?
68
    my $today    = sprintf '%04d-%02d-%02d', $year+1900, $month+1, $day;
69
    my $expired = 0;
69
    my $expired  = ($today gt $kp->{dateexpiry}) ? 1 : 0;
70
    if ( $kp->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) {
70
    if ($expired) {
71
        my ( $today_year,   $today_month,   $today_day )   = Today();
71
        if ($kp->{opacnote} ) {
72
        my ( $warning_year, $warning_month, $warning_day ) = split /-/, $kp->{'dateexpiry'};
72
            $kp->{opacnote} .= q{ };
73
        my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) -
74
            Date_to_Days( $today_year, $today_month, $today_day );
75
        my $dt         = dt_from_string( $kp->{'dateexpiry'}, 'iso' );
76
        my $dateexpiry = output_pref( { dt => $dt, dateonly => 1 } );
77
        if ( $days_to_expiry < 0 ) {
78
79
            #borrower card has expired, warn the borrower
80
            if ( $kp->{opacnote} ) {
81
                $kp->{opacnote} .= q{ };
82
            }
83
            $kp->{opacnote} .= "Your account has expired as of $dateexpiry";
84
            $expired = 1;
85
        } elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) {
86
87
            # borrower card soon to expire, warn the borrower
88
            if ( $kp->{opacnote} ) {
89
                $kp->{opacnote} .= q{ };
90
            }
91
            $kp->{opacnote} .= "Your card will expire on $dateexpiry";
73
        }
92
        }
74
        $kp->{opacnote} .= 'PATRON EXPIRED';
75
    }
93
    }
76
    my %ilspatron;
94
    my %ilspatron;
77
    my $adr     = _get_address($kp);
95
    my $adr     = _get_address($kp);
(-)a/t/db_dependent/SIP/Patron.t (-2 / +57 lines)
Lines 4-10 Link Here
4
# This needs to be extended! Your help is appreciated..
4
# This needs to be extended! Your help is appreciated..
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
use Test::More tests => 10;
7
use Test::More tests => 11;
8
8
9
use t::lib::Mocks;
9
use t::lib::Mocks;
10
use t::lib::TestBuilder;
10
use t::lib::TestBuilder;
Lines 252-257 subtest "fine_items tests" => sub { Link Here
252
252
253
$schema->storage->txn_rollback;
253
$schema->storage->txn_rollback;
254
254
255
subtest "Patron expiration tests" => sub {
256
257
    plan tests => 4;
258
259
    $schema->storage->txn_begin;
260
    my $patron = $builder->build_object(
261
        {
262
            class => 'Koha::Patrons',
263
            value => {
264
                opacnote => "",
265
266
                # dateexpiry is today when unspecified
267
            }
268
        }
269
    );
270
271
    t::lib::Mocks::mock_preference( 'NotifyBorrowerDeparture', 0 );
272
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
273
    like(
274
        $sip_patron->screen_msg, qr/^Greetings from Koha. $/,
275
        "No message is displayed when NotifyBorrowerDeparture is disabled"
276
    );
277
278
    t::lib::Mocks::mock_preference( 'NotifyBorrowerDeparture', 1 );
279
    $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
280
    like(
281
        $sip_patron->screen_msg, qr/Your card will expire on/,
282
        "A message is displayed when the card expires within NotifyBorrowerDeparture days"
283
    );
284
285
    $patron = $builder->build_object(
286
        {
287
            class => 'Koha::Patrons',
288
            value => {
289
                opacnote   => "",
290
                dateexpiry => "1900-01-01",
291
            }
292
        }
293
    );
294
    $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
295
    like(
296
        $sip_patron->screen_msg, qr/Your account has expired as of/,
297
        "A message is displayed when the card has expired and NotifyBorrowerDeparture is not disabled"
298
    );
299
300
    t::lib::Mocks::mock_preference( 'NotifyBorrowerDeparture', 0 );
301
    $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
302
    like(
303
        $sip_patron->screen_msg, qr/^Greetings from Koha. $/,
304
        "No message is displayed when the card has expired and NotifyBorrowerDeparture is disabled"
305
    );
306
307
    $schema->storage->txn_rollback;
308
309
};
310
255
subtest "NoIssuesChargeGuarantees tests" => sub {
311
subtest "NoIssuesChargeGuarantees tests" => sub {
256
312
257
    plan tests => 6;
313
    plan tests => 6;
258
- 

Return to bug 25813