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

(-)a/C4/Letters.pm (-9 / +4 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::Template::Plugin::KohaDates;
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'} = Koha::Template::Plugin::KohaDates
790
791
            ->new()
791
        $values->{'dateexpiry'} = C4::Dates->new(
792
            ->filter($values->{'dateexpiry'});
792
            sprintf(
793
                '%04d-%02d-%02d',
794
                Add_Delta_Days( @dateexpiry,0)
795
            ),
796
            'iso'
797
        )->output();
798
    }
793
    }
799
794
800
    if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
795
    if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
(-)a/C4/Members.pm (-2 / +4 lines)
Lines 1496-1510 sub GetExpiryDate { Link Here
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");
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/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 / +105 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 => 3;
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".');

Return to bug 6810