3 # This file is part of Koha.
5 # Copyright (C) 2013 Amit Gupta (amitddng135@gmail.com)
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.
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.
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>.
22 membership_expires.pl - cron script to put membership expiry reminders into message queue
26 ./membership_expires.pl -c
30 0 1 * * * membership_expires.pl -c
39 # find Koha's Perl modules
40 # test carefully before changing this
42 eval { require "$FindBin::Bin/../kohalib.pl" };
47 use C4::Dates qw/format_date/;
49 # These are defaults for command line options.
50 my $confirm; # -c: Confirm that the user has read and configured this script.
51 my $nomail; # -n: No mail. Will not send any emails.
52 my $verbose= 0; # -v: verbose
54 GetOptions( 'c' => \$confirm,
60 my $usage = << 'ENDUSAGE';
61 This script prepares for membership expiry reminders to be sent to
62 patrons. It queues them in the message queue, which is processed by
63 the process_message_queue.pl cronjob.
64 See the comments in the script for directions on changing the script.
65 This script has the following parameters :
66 -c Confirm and remove this help & warning
67 -n send No mail. Instead, all mail messages are printed on screen. Usefull for testing purposes.
73 print "Do you wish to continue? (y/n)";
78 my $admin_adress = C4::Context->preference('KohaAdminEmailAddress');
79 warn 'getting upcoming membership expires' if $verbose;
80 my $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires();
81 warn 'found ' . scalar( @$upcoming_mem_expires ) . ' issues' if $verbose;
84 UPCOMINGMEMEXP: foreach my $recent ( @$upcoming_mem_expires ) {
85 my $from_address = $recent->{'branchemail'} || $admin_adress;
86 my $letter_type = 'MEMEXP';
87 my $letter = C4::Letters::getletter( 'members', $letter_type, $recent->{'branchcode'} );
88 die "no letter of type '$letter_type' found. Please see sample_notices.sql" unless $letter;
90 $letter = parse_letter({ letter => $letter,
91 borrowernumber => $recent->{'borrowernumber'},
92 firstname => $recent->{'firstname'},
93 categorycode => $recent->{'categorycode'},
94 branchcode => $recent->{'branchcode'},
98 print $letter->{'content'};
100 C4::Letters::EnqueueLetter( { letter => $letter,
101 borrowernumber => $recent->{'borrowernumber'},
102 from_address => $from_address,
103 message_transport_type => 'email',
118 foreach my $required ( qw( letter borrowernumber ) ) {
119 return unless exists $params->{$required};
121 my $letter = C4::Letters::GetPreparedLetter (
123 letter_code => 'MEMEXP',
124 branchcode => $params->{'branchcode'},
125 tables => {'borrowers', $params->{'borrowernumber'},},