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

(-)a/misc/cronjobs/membership_expiry.pl (-9 / +27 lines)
Lines 41-48 Options: Link Here
41
   --before=X               include patrons expiring a number of days BEFORE the date set by the preference
41
   --before=X               include patrons expiring a number of days BEFORE the date set by the preference
42
   --after=X                include patrons expiring a number of days AFTER  the date set by the preference
42
   --after=X                include patrons expiring a number of days AFTER  the date set by the preference
43
   -l --letter <lettercode> use a specific notice rather than the default
43
   -l --letter <lettercode> use a specific notice rather than the default
44
   --active=X               only send notices to active patrons (active within X months)
44
   --active=X               only deal with active patrons (active within X months)
45
   --inactive=X             only send notices to inactive patrons (inactive within X months)
45
   --inactive=X             only deal with inactive patrons (inactive within X months)
46
   --renew                  renew patrons and send notice (instead of expiry notice only)
46
47
47
=head1 DESCRIPTION
48
=head1 DESCRIPTION
48
49
Lines 109-115 Optional parameter to include active patrons only (active within passed number o Link Here
109
=item B<-inactive>
110
=item B<-inactive>
110
111
111
Optional parameter to include inactive patrons only (inactive within passed number of months).
112
Optional parameter to include inactive patrons only (inactive within passed number of months).
112
This allows you to skip active patrons when you renew them automatically (see bug 28688).
113
This allows you to e.g. send expiry warnings only to inactive patrons.
114
115
=item B<-renew>
116
117
Optional parameter to automatically renew patrons instead of sending them an expiry notice.
118
They will be informed by a patron renewal notice.
113
119
114
=back
120
=back
115
121
Lines 171-176 my ( $branch, $letter_type ); Link Here
171
my @where;
177
my @where;
172
my $active;
178
my $active;
173
my $inactive;
179
my $inactive;
180
my $renew;
174
181
175
my $command_line_options = join(" ",@ARGV);
182
my $command_line_options = join(" ",@ARGV);
176
183
Lines 187-192 GetOptions( Link Here
187
    'where=s'        => \@where,
194
    'where=s'        => \@where,
188
    'active:i'       => \$active,
195
    'active:i'       => \$active,
189
    'inactive:i'     => \$inactive,
196
    'inactive:i'     => \$inactive,
197
    'renew'          => \$renew,
190
) or pod2usage(2);
198
) or pod2usage(2);
191
199
192
pod2usage( -verbose => 2 ) if $man;
200
pod2usage( -verbose => 2 ) if $man;
Lines 223-229 warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members' Link Here
223
231
224
# main loop
232
# main loop
225
$letter_type = 'MEMBERSHIP_EXPIRY' if !$letter_type;
233
$letter_type = 'MEMBERSHIP_EXPIRY' if !$letter_type;
226
my ( $count_skipped, $count_enqueued ) = ( 0, 0 );
234
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 );
227
while ( my $recent = $upcoming_mem_expires->next ) {
235
while ( my $recent = $upcoming_mem_expires->next ) {
228
    if ( $active && !$recent->is_active( { months => $active } ) ) {
236
    if ( $active && !$recent->is_active( { months => $active } ) ) {
229
        $count_skipped++;
237
        $count_skipped++;
Lines 232-241 while ( my $recent = $upcoming_mem_expires->next ) { Link Here
232
        $count_skipped++;
240
        $count_skipped++;
233
        next;
241
        next;
234
    }
242
    }
243
244
    my $which_notice;
245
    if ($renew) {
246
        $recent->renew_account;
247
        $which_notice = 'MEMBERSHIP_RENEWED';
248
        $count_renewed++;
249
    } else {
250
        $which_notice = $letter_type;
251
    }
252
235
    my $from_address = $recent->library->from_email_address;
253
    my $from_address = $recent->library->from_email_address;
236
    my $letter =  C4::Letters::GetPreparedLetter(
254
    my $letter =  C4::Letters::GetPreparedLetter(
237
        module      => 'members',
255
        module      => 'members',
238
        letter_code => $letter_type,
256
        letter_code => $which_notice,
239
        branchcode  => $recent->branchcode,
257
        branchcode  => $recent->branchcode,
240
        lang        => $recent->lang,
258
        lang        => $recent->lang,
241
        tables      => {
259
        tables      => {
Lines 243-250 while ( my $recent = $upcoming_mem_expires->next ) { Link Here
243
            branches  => $recent->branchcode,
261
            branches  => $recent->branchcode,
244
        },
262
        },
245
    );
263
    );
246
    last if !$letter; # Letters.pm already warned, just exit
264
    last if !$letter;    # Letters.pm already warned, just exit
247
    if( $nomail ) {
265
    if ($nomail) {
248
        print $letter->{'content'}."\n";
266
        print $letter->{'content'}."\n";
249
        next;
267
        next;
250
    }
268
    }
Lines 260-266 while ( my $recent = $upcoming_mem_expires->next ) { Link Here
260
    if ($recent->smsalertnumber) {
278
    if ($recent->smsalertnumber) {
261
        my $smsletter = C4::Letters::GetPreparedLetter(
279
        my $smsletter = C4::Letters::GetPreparedLetter(
262
            module      => 'members',
280
            module      => 'members',
263
            letter_code => $letter_type,
281
            letter_code => $which_notice,
264
            branchcode  => $recent->branchcode,
282
            branchcode  => $recent->branchcode,
265
            lang        => $recent->lang,
283
            lang        => $recent->lang,
266
            tables      => {
284
            tables      => {
Lines 280-285 while ( my $recent = $upcoming_mem_expires->next ) { Link Here
280
}
298
}
281
299
282
if ($verbose) {
300
if ($verbose) {
301
    print "Membership renewed for $count_renewed patrons\n" if $count_renewed;
283
    print "Enqueued notices for $count_enqueued patrons\n";
302
    print "Enqueued notices for $count_enqueued patrons\n";
284
    print "Skipped $count_skipped inactive patrons\n" if $active;
303
    print "Skipped $count_skipped inactive patrons\n" if $active;
285
    print "Skipped $count_skipped active patrons\n"   if $inactive;
304
    print "Skipped $count_skipped active patrons\n"   if $inactive;
286
- 

Return to bug 28688