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

(-)a/C4/SIP/ILS/Patron.pm (-8 / +24 lines)
Lines 28-37 use Koha::Libraries; Link Here
28
use Koha::Patrons;
28
use Koha::Patrons;
29
use Koha::Checkouts;
29
use Koha::Checkouts;
30
use Koha::TemplateUtils qw( process_tt );
30
use Koha::TemplateUtils qw( process_tt );
31
use Date::Calc qw/Today Date_to_Days/;
32
use Koha::DateUtils qw(dt_from_string output_pref);;
31
33
32
our $kp;    # koha patron
34
our $kp;    # koha patron
33
35
34
=head1 METHODS
36
=head1 Methods
35
37
36
=cut
38
=cut
37
39
Lines 62-75 sub new { Link Here
62
    my $pw        = $kp->{password};
64
    my $pw        = $kp->{password};
63
    my $flags     = C4::Members::patronflags( $kp );
65
    my $flags     = C4::Members::patronflags( $kp );
64
    my $debarred  = $patron->is_debarred;
66
    my $debarred  = $patron->is_debarred;
65
    my ($day, $month, $year) = (localtime)[3,4,5];
67
    siplog("LOG_DEBUG", "Debarred = %s : ", ($debarred||'undef')); # Do we need more debug info here?
66
    my $today    = sprintf '%04d-%02d-%02d', $year+1900, $month+1, $day;
68
    my $expired = 0;
67
    my $expired  = ($today gt $kp->{dateexpiry}) ? 1 : 0;
69
    if ( $kp->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) {
68
    if ($expired) {
70
        my (  $today_year,   $today_month,   $today_day) = Today();
69
        if ($kp->{opacnote} ) {
71
        my ($warning_year, $warning_month, $warning_day) = split /-/, $kp->{'dateexpiry'};
70
            $kp->{opacnote} .= q{ };
72
        my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - Date_to_Days( $today_year, $today_month, $today_day );
73
        my $dt = dt_from_string( $kp->{'dateexpiry'}, 'iso' );
74
        my $dateexpiry = output_pref({ dt => $dt, dateonly => 1});
75
        if ( $days_to_expiry < 0 ) {
76
            #borrower card has expired, warn the borrower
77
            if ($kp->{opacnote} ) {
78
                $kp->{opacnote} .= q{ };
79
            }
80
            $kp->{opacnote} .= "Your account has expired as of $dateexpiry";
81
            $expired = 1;
82
        } elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) {
83
            # borrower card soon to expire, warn the borrower
84
            if ($kp->{opacnote} ) {
85
                $kp->{opacnote} .= q{ };
86
            }
87
            $kp->{opacnote} .= "Your card will expire on $dateexpiry";
71
        }
88
        }
72
        $kp->{opacnote} .= 'PATRON EXPIRED';
73
    }
89
    }
74
    my %ilspatron;
90
    my %ilspatron;
75
    my $adr     = _get_address($kp);
91
    my $adr     = _get_address($kp);
(-)a/t/db_dependent/SIP/Patron.t (-2 / +44 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 274-279 subtest "fine_items tests" => sub { Link Here
274
274
275
$schema->storage->txn_rollback;
275
$schema->storage->txn_rollback;
276
276
277
subtest "Patron expiration tests" => sub {
278
279
    plan tests => 4;
280
281
    $schema->storage->txn_begin;
282
    my $patron = $builder->build_object(
283
    {
284
        class => 'Koha::Patrons',
285
        value =>
286
        {
287
            opacnote => "",
288
          # dateexpiry is today when unspecified
289
        }
290
    });
291
292
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
293
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
294
    like( $sip_patron->screen_msg, qr/^Greetings from Koha. $/, "No message is displayed when NotifyBorrowerDeparture is disabled");
295
296
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 1);
297
    $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
298
    like( $sip_patron->screen_msg, qr/Your card will expire on/, "A message is displayed when the card expires within NotifyBorrowerDeparture days");
299
300
    $patron = $builder->build_object(
301
    {
302
        class => 'Koha::Patrons',
303
        value =>
304
        {
305
            opacnote => "",
306
            dateexpiry    => "1900-01-01",
307
        }
308
    });
309
    $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
310
    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");
311
312
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
313
    $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
314
    like( $sip_patron->screen_msg, qr/^Greetings from Koha. $/, "No message is displayed when the card has expired and NotifyBorrowerDeparture is disabled");
315
316
    $schema->storage->txn_rollback;
317
318
};
319
277
subtest "NoIssuesChargeGuarantees tests" => sub {
320
subtest "NoIssuesChargeGuarantees tests" => sub {
278
321
279
    plan tests => 6;
322
    plan tests => 6;
280
- 

Return to bug 25813