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 786-800 sub _parseletter { Link Here
786
    my ( $letter, $table, $values ) = @_;
787
    my ( $letter, $table, $values ) = @_;
787
788
788
    if ( $table eq 'borrowers' && $values->{'dateexpiry'} ){
789
    if ( $table eq 'borrowers' && $values->{'dateexpiry'} ){
789
        my @dateexpiry = split /-/, $values->{'dateexpiry'};
790
        $values->{'dateexpiry'} = format_sqldatetime( $values->{'dateexpiry'} );
790
791
        $values->{'dateexpiry'} = C4::Dates->new(
792
            sprintf(
793
                '%04d-%02d-%02d',
794
                Add_Delta_Days( @dateexpiry,0)
795
            ),
796
            'iso'
797
        )->output();
798
    }
791
    }
799
792
800
    if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
793
    if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
(-)a/C4/Members.pm (-3 / +5 lines)
Lines 1489-1504 sub GetExpiryDate { Link Here
1489
1489
1490
sub GetUpcomingMembershipExpires {
1490
sub GetUpcomingMembershipExpires {
1491
    my $dbh = C4::Context->dbh;
1491
    my $dbh = C4::Context->dbh;
1492
    my $days = C4::Context->preference("MembershipExpiryDaysNotice");
1492
    my $days = C4::Context->preference("MembershipExpiryDaysNotice") || 0;
1493
    my $dateexpiry = DateTime->now()->add(days => $days)->ymd();
1494
1493
    my $query = "
1495
    my $query = "
1494
        SELECT borrowers.*, categories.description,
1496
        SELECT borrowers.*, categories.description,
1495
        branches.branchname, branches.branchemail FROM borrowers
1497
        branches.branchname, branches.branchemail FROM borrowers
1496
        LEFT JOIN branches on borrowers.branchcode = branches.branchcode
1498
        LEFT JOIN branches on borrowers.branchcode = branches.branchcode
1497
        LEFT JOIN categories on borrowers.categorycode = categories.categorycode
1499
        LEFT JOIN categories on borrowers.categorycode = categories.categorycode
1498
        WHERE dateexpiry = DATE_ADD(CURDATE(),INTERVAL $days DAY);
1500
        WHERE dateexpiry = ?;
1499
    ";
1501
    ";
1500
    my $sth = $dbh->prepare($query);
1502
    my $sth = $dbh->prepare($query);
1501
    $sth->execute;
1503
    $sth->execute($dateexpiry);
1502
    my $results = $sth->fetchall_arrayref({});
1504
    my $results = $sth->fetchall_arrayref({});
1503
    return $results;
1505
    return $results;
1504
}
1506
}
(-)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 480-484 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
480
('XSLTDetailsDisplay','default','','Enable XSL stylesheet control over details page display on intranet','Free'),
480
('XSLTDetailsDisplay','default','','Enable XSL stylesheet control over details page display on intranet','Free'),
481
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
481
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
482
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
482
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
483
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
483
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
484
('MembershipExpiryDaysNotice' ,14,'Send an account expiration notice that a patron\'s card is about to expire after',NULL,'Integer')
484
;
485
;
(-)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