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

(-)a/C4/Letters.pm (-9 / +2 lines)
Lines 35-40 use Date::Calc qw( Add_Delta_Days ); Link Here
35
use Encode;
35
use Encode;
36
use Carp;
36
use Carp;
37
use Koha::Email;
37
use Koha::Email;
38
use Koha::DateUtils qw( format_sqldatetime );
38
39
39
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
40
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
40
41
Lines 799-813 sub _parseletter { Link Here
799
    my ( $letter, $table, $values ) = @_;
800
    my ( $letter, $table, $values ) = @_;
800
801
801
    if ( $table eq 'borrowers' && $values->{'dateexpiry'} ){
802
    if ( $table eq 'borrowers' && $values->{'dateexpiry'} ){
802
        my @dateexpiry = split /-/, $values->{'dateexpiry'};
803
        $values->{'dateexpiry'} = format_sqldatetime( $values->{'dateexpiry'} );
803
804
        $values->{'dateexpiry'} = C4::Dates->new(
805
            sprintf(
806
                '%04d-%02d-%02d',
807
                Add_Delta_Days( @dateexpiry,0)
808
            ),
809
            'iso'
810
        )->output();
811
    }
804
    }
812
805
813
    if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
806
    if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
(-)a/C4/Members.pm (-3 / +5 lines)
Lines 1495-1510 sub GetExpiryDate { Link Here
1495
1495
1496
sub GetUpcomingMembershipExpires {
1496
sub GetUpcomingMembershipExpires {
1497
    my $dbh = C4::Context->dbh;
1497
    my $dbh = C4::Context->dbh;
1498
    my $days = C4::Context->preference("MembershipExpiryDaysNotice");
1498
    my $days = C4::Context->preference("MembershipExpiryDaysNotice") || 0;
1499
    my $dateexpiry = DateTime->now()->add(days => $days)->ymd();
1500
1499
    my $query = "
1501
    my $query = "
1500
        SELECT borrowers.*, categories.description,
1502
        SELECT borrowers.*, categories.description,
1501
        branches.branchname, branches.branchemail FROM borrowers
1503
        branches.branchname, branches.branchemail FROM borrowers
1502
        LEFT JOIN branches on borrowers.branchcode = branches.branchcode
1504
        LEFT JOIN branches on borrowers.branchcode = branches.branchcode
1503
        LEFT JOIN categories on borrowers.categorycode = categories.categorycode
1505
        LEFT JOIN categories on borrowers.categorycode = categories.categorycode
1504
        WHERE dateexpiry = DATE_ADD(CURDATE(),INTERVAL $days DAY);
1506
        WHERE dateexpiry = ?;
1505
    ";
1507
    ";
1506
    my $sth = $dbh->prepare($query);
1508
    my $sth = $dbh->prepare($query);
1507
    $sth->execute;
1509
    $sth->execute($dateexpiry);
1508
    my $results = $sth->fetchall_arrayref({});
1510
    my $results = $sth->fetchall_arrayref({});
1509
    return $results;
1511
    return $results;
1510
}
1512
}
(-)a/installer/data/mysql/atomicupdate/bug_6810-add_MembershipExpiryDaysNotice_syspref.sql (+1 lines)
Line 0 Link Here
1
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MembershipExpiryDaysNotice',14,'Send an account expiration notice that a patron''s card is about to expire after',NULL,'Integer')
(-)a/installer/data/mysql/sysprefs.sql (-1 / +2 lines)
Lines 490-494 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
490
('XSLTDetailsDisplay','default','','Enable XSL stylesheet control over details page display on intranet','Free'),
490
('XSLTDetailsDisplay','default','','Enable XSL stylesheet control over details page display on intranet','Free'),
491
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
491
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
492
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
492
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
493
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
493
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
494
('MembershipExpiryDaysNotice' ,14,'Send an account expiration notice that a patron\'s card is about to expire after',NULL,'Integer')
494
;
495
;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (-1 / +1 lines)
Lines 84-90 Patrons: Link Here
84
           class: integer
84
           class: integer
85
         - days beforehand.
85
         - days beforehand.
86
     -
86
     -
87
         - Send a membership expiry notice that a patron is about to expire after
87
         - Send an account expiration notice when a patron's card will expire in.
88
         - pref: MembershipExpiryDaysNotice
88
         - pref: MembershipExpiryDaysNotice
89
           class: integer
89
           class: integer
90
         - days.
90
         - days.
(-)a/misc/cronjobs/membership_expiry.pl (+3 lines)
Lines 45-50 BEGIN { Link Here
45
use C4::Context;
45
use C4::Context;
46
use C4::Letters;
46
use C4::Letters;
47
use C4::Dates qw/format_date/;
47
use C4::Dates qw/format_date/;
48
use C4::Log;
49
50
cronlogaction();
48
51
49
# These are defaults for command line options.
52
# These are defaults for command line options.
50
my $confirm;                              # -c: Confirm that the user has read and configured this script.
53
my $confirm;                              # -c: Confirm that the user has read and configured this script.
(-)a/t/Members.t (-1 / +117 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2015 Biblibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use C4::Members;
22
use Test::MockModule;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks qw( mock_preference );
25
26
use Test::More tests => 5;
27
use Test::MockModule;
28
29
BEGIN {
30
    use_ok('C4::Members');
31
}
32
33
my $date_time = new Test::MockModule('DateTime');
34
$date_time->mock(
35
    'now', sub {
36
        return DateTime->new(
37
            year      => 2015,
38
            month     => 6,
39
            day       => 15,
40
        );
41
42
});
43
44
t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', 15);
45
46
my $builder = t::lib::TestBuilder->new();
47
$builder->build({
48
    source => 'Category',
49
    value  => {
50
        categorycode            => 'AD',
51
        description             => 'Adult',
52
        enrolmentperiod         => 18,
53
        upperagelimit           => 99,
54
        category_type           => 'A',
55
    },
56
});
57
58
$builder->build({
59
    source => 'Branch',
60
    value  => {
61
        branchcode              => 'CR',
62
        branchname              => 'My branch',
63
    },
64
});
65
66
$builder->build({
67
    source => 'Borrower',
68
    value  => {
69
        firstname               => 'Vincent',
70
        surname                 => 'Martin',
71
        cardnumber              => '80808081',
72
        categorycode            => 'AD',
73
        branchcode              => 'CR',
74
        dateexpiry              => '2015-06-30'
75
    },
76
});
77
78
$builder->build({
79
    source => 'Borrower',
80
    value  => {
81
        firstname               => 'Claude',
82
        surname                 => 'Dupont',
83
        cardnumber              => '80808082',
84
        categorycode            => 'AD',
85
        branchcode              => 'CR',
86
        dateexpiry              => '2015-06-29'
87
    },
88
});
89
90
$builder->build({
91
    source => 'Borrower',
92
    value  => {
93
        firstname               => 'Gilles',
94
        surname                 => 'Dupond',
95
        cardnumber              => '80808083',
96
        categorycode            => 'AD',
97
        branchcode              => 'CR',
98
        dateexpiry              => '2015-07-02'
99
    },
100
});
101
102
my $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires();
103
is(scalar(@$upcoming_mem_expires), 1, 'Get upcoming membership expires should return 1 borrower.');
104
105
is($upcoming_mem_expires->[0]{surname}, 'Martin', 'Get upcoming membership expires should return borrower "Martin".');
106
107
# Test GetUpcomingMembershipExpires() with MembershipExpiryDaysNotice == 0
108
t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', 0);
109
110
$upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires();
111
is(scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires with 0 MembershipExpiryDaysNotice should return 0.');
112
113
# Test GetUpcomingMembershipExpires() with MembershipExpiryDaysNotice == undef
114
t::lib::Mocks::mock_preference('MembershipExpiryDaysNotice', undef);
115
116
$upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires();
117
is(scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires without MembershipExpiryDaysNotice should return 0.');

Return to bug 6810