Lines 253-321
warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members'
Link Here
|
253 |
|
253 |
|
254 |
# main loop |
254 |
# main loop |
255 |
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 ); |
255 |
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 ); |
256 |
while ( my $recent = $upcoming_mem_expires->next ) { |
256 |
while ( my $expiring_patron = $upcoming_mem_expires->next ) { |
257 |
if ( $active && !$recent->is_active( { months => $active } ) ) { |
257 |
if ( $active && !$expiring_patron->is_active( { months => $active } ) ) { |
258 |
$count_skipped++; |
258 |
$count_skipped++; |
259 |
next; |
259 |
next; |
260 |
} elsif ( $inactive && $recent->is_active( { months => $inactive } ) ) { |
260 |
} elsif ( $inactive && $expiring_patron->is_active( { months => $inactive } ) ) { |
261 |
$count_skipped++; |
261 |
$count_skipped++; |
262 |
next; |
262 |
next; |
263 |
} |
263 |
} |
264 |
|
264 |
|
|
|
265 |
my $messaging_prefs = C4::Members::Messaging::GetMessagingPreferences( |
266 |
{ |
267 |
borrowernumber => $expiring_patron->borrowernumber, |
268 |
message_name => "Patron_Expiry", |
269 |
} |
270 |
); |
271 |
my @message_transports = ( keys %{ $messaging_prefs->{transports} } ); |
272 |
my $letter_code = $messaging_prefs->{letter_code}; |
273 |
|
274 |
# Skip this patron if they don't want a notification email for card expiry |
275 |
next if !$messaging_prefs; |
276 |
|
265 |
my $which_notice; |
277 |
my $which_notice; |
266 |
if ($renew) { |
278 |
if ($renew) { |
267 |
$recent->renew_account; |
279 |
$expiring_patron->renew_account; |
268 |
$which_notice = $letter_renew; |
280 |
$which_notice = $letter_renew; |
269 |
$count_renewed++; |
281 |
$count_renewed++; |
270 |
} else { |
282 |
} else { |
271 |
$which_notice = $letter_expiry; |
283 |
$which_notice = $letter_code || $letter_expiry; |
272 |
} |
284 |
} |
273 |
|
285 |
|
274 |
my $from_address = $recent->library->from_email_address; |
286 |
my $from_address = $expiring_patron->library->from_email_address; |
275 |
my $letter = C4::Letters::GetPreparedLetter( |
287 |
my $letter_params = { |
276 |
module => 'members', |
288 |
module => 'members', |
277 |
letter_code => $which_notice, |
289 |
letter_code => $which_notice, |
278 |
branchcode => $recent->branchcode, |
290 |
branchcode => $expiring_patron->branchcode, |
279 |
lang => $recent->lang, |
291 |
lang => $expiring_patron->lang, |
|
|
292 |
borrowernumber => $expiring_patron->borrowernumber, |
280 |
tables => { |
293 |
tables => { |
281 |
borrowers => $recent->borrowernumber, |
294 |
borrowers => $expiring_patron->borrowernumber, |
282 |
branches => $recent->branchcode, |
295 |
branches => $expiring_patron->branchcode, |
283 |
}, |
296 |
}, |
284 |
); |
297 |
}; |
285 |
last if !$letter; # Letters.pm already warned, just exit |
|
|
286 |
if ($nomail) { |
287 |
print $letter->{'content'}."\n"; |
288 |
next; |
289 |
} |
290 |
|
298 |
|
291 |
C4::Letters::EnqueueLetter({ |
299 |
my $sending_params = { |
292 |
letter => $letter, |
300 |
letter_params => $letter_params, |
293 |
borrowernumber => $recent->borrowernumber, |
301 |
message_name => 'Patron_Expiry', |
294 |
from_address => $from_address, |
302 |
}; |
295 |
message_transport_type => 'email', |
303 |
|
296 |
}); |
304 |
my $result = $expiring_patron->queue_notice($sending_params); |
297 |
$count_enqueued++; |
305 |
$count_enqueued++ if $result->{sent}; |
298 |
|
|
|
299 |
if ($recent->smsalertnumber) { |
300 |
my $smsletter = C4::Letters::GetPreparedLetter( |
301 |
module => 'members', |
302 |
letter_code => $which_notice, |
303 |
branchcode => $recent->branchcode, |
304 |
lang => $recent->lang, |
305 |
tables => { |
306 |
borrowers => $recent->borrowernumber, |
307 |
branches => $recent->branchcode, |
308 |
}, |
309 |
message_transport_type => 'sms', |
310 |
); |
311 |
if ($smsletter) { |
312 |
C4::Letters::EnqueueLetter({ |
313 |
letter => $smsletter, |
314 |
borrowernumber => $recent->borrowernumber, |
315 |
message_transport_type => 'sms', |
316 |
}); |
317 |
} |
318 |
} |
319 |
} |
306 |
} |
320 |
|
307 |
|
321 |
if ($verbose) { |
308 |
if ($verbose) { |
322 |
- |
|
|