Lines 218-225
warn 'found ' . scalar( @$upcoming_dues ) . ' issues' if $verbose;
Link Here
|
218 |
|
218 |
|
219 |
# hash of borrowernumber to number of items upcoming |
219 |
# hash of borrowernumber to number of items upcoming |
220 |
# for patrons wishing digests only. |
220 |
# for patrons wishing digests only. |
221 |
my $upcoming_digest; |
221 |
my $upcoming_digest = {}; |
222 |
my $due_digest; |
222 |
my $due_digest = {}; |
223 |
|
223 |
|
224 |
my $dbh = C4::Context->dbh(); |
224 |
my $dbh = C4::Context->dbh(); |
225 |
my $sth = $dbh->prepare(<<'END_SQL'); |
225 |
my $sth = $dbh->prepare(<<'END_SQL'); |
Lines 250-257
UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) {
Link Here
|
250 |
|
250 |
|
251 |
if ( $borrower_preferences->{'wants_digest'} ) { |
251 |
if ( $borrower_preferences->{'wants_digest'} ) { |
252 |
# cache this one to process after we've run through all of the items. |
252 |
# cache this one to process after we've run through all of the items. |
253 |
$due_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address; |
253 |
$due_digest->{ $upcoming->{branchcode} }->{ $upcoming->{borrowernumber} }->{email} = $from_address; |
254 |
$due_digest->{ $upcoming->{borrowernumber} }->{count}++; |
254 |
$due_digest->{ $upcoming->{branchcode} }->{ $upcoming->{borrowernumber} }->{count}++; |
255 |
} else { |
255 |
} else { |
256 |
my $item = Koha::Items->find( $upcoming->{itemnumber} ); |
256 |
my $item = Koha::Items->find( $upcoming->{itemnumber} ); |
257 |
my $letter_type = 'DUE'; |
257 |
my $letter_type = 'DUE'; |
Lines 283-290
UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) {
Link Here
|
283 |
|
283 |
|
284 |
if ( $borrower_preferences->{'wants_digest'} ) { |
284 |
if ( $borrower_preferences->{'wants_digest'} ) { |
285 |
# cache this one to process after we've run through all of the items. |
285 |
# cache this one to process after we've run through all of the items. |
286 |
$upcoming_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address; |
286 |
$upcoming_digest->{ $upcoming->{branchcode} }->{ $upcoming->{borrowernumber} }->{email} = $from_address; |
287 |
$upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++; |
287 |
$upcoming_digest->{ $upcoming->{branchcode} }->{ $upcoming->{borrowernumber} }->{count}++; |
288 |
} else { |
288 |
} else { |
289 |
my $item = Koha::Items->find( $upcoming->{itemnumber} ); |
289 |
my $item = Koha::Items->find( $upcoming->{itemnumber} ); |
290 |
my $letter_type = 'PREDUE'; |
290 |
my $letter_type = 'PREDUE'; |
Lines 342-374
SELECT biblio.*, items.*, issues.*
Link Here
|
342 |
AND (TO_DAYS(date_due)-TO_DAYS(NOW()) = ?) |
342 |
AND (TO_DAYS(date_due)-TO_DAYS(NOW()) = ?) |
343 |
END_SQL |
343 |
END_SQL |
344 |
|
344 |
|
345 |
send_digests({ |
345 |
while (my ($branchcode, $digests) = each %$upcoming_digest) { |
346 |
sth => $sth_digest, |
346 |
send_digests({ |
347 |
digests => $upcoming_digest, |
347 |
sth => $sth_digest, |
348 |
letter_code => 'PREDUEDGST', |
348 |
digests => $digests, |
349 |
get_item_info => sub { |
349 |
letter_code => 'PREDUEDGST', |
350 |
my $params = shift; |
350 |
branchcode => $branchcode, |
351 |
$params->{sth}->execute($params->{borrowernumber}, |
351 |
get_item_info => sub { |
352 |
$params->{borrower_preferences}->{'days_in_advance'}); |
352 |
my $params = shift; |
353 |
return sub { |
353 |
$params->{sth}->execute($params->{borrowernumber}, |
354 |
$params->{sth}->fetchrow_hashref; |
354 |
$params->{borrower_preferences}->{'days_in_advance'}); |
355 |
}; |
355 |
return sub { |
356 |
} |
356 |
$params->{sth}->fetchrow_hashref; |
357 |
}); |
357 |
}; |
358 |
|
358 |
} |
359 |
send_digests({ |
359 |
}); |
360 |
sth => $sth_digest, |
360 |
} |
361 |
digest => $due_digest, |
361 |
|
362 |
letter_code => 'DUEGST', |
362 |
while (my ($branchcode, $digests) = each %$due_digest) { |
363 |
get_item_info => sub { |
363 |
send_digests({ |
364 |
my $params = shift; |
364 |
sth => $sth_digest, |
365 |
$params->{sth}->execute($params->{borrowernumber}, 0); |
365 |
digest => $due_digest, |
366 |
return sub { |
366 |
letter_code => 'DUEGST', |
367 |
$params->{sth}->fetchrow_hashref; |
367 |
branchcode => $branchcode, |
368 |
}; |
368 |
get_item_info => sub { |
369 |
} |
369 |
my $params = shift; |
370 |
}); |
370 |
$params->{sth}->execute($params->{borrowernumber}, 0); |
371 |
|
371 |
return sub { |
|
|
372 |
$params->{sth}->fetchrow_hashref; |
373 |
}; |
374 |
} |
375 |
}); |
376 |
} |
377 |
|
372 |
=head1 METHODS |
378 |
=head1 METHODS |
373 |
|
379 |
|
374 |
=head2 parse_letter |
380 |
=head2 parse_letter |
Lines 408-431
sub parse_letter {
Link Here
|
408 |
); |
414 |
); |
409 |
} |
415 |
} |
410 |
|
416 |
|
411 |
=head2 get_branch_info |
|
|
412 |
|
413 |
=cut |
414 |
|
415 |
sub get_branch_info { |
416 |
my ( $borrowernumber ) = @_; |
417 |
|
418 |
## Get branch info for borrowers home library. |
419 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
420 |
my $branch = $patron->library->unblessed; |
421 |
my %branch_info; |
422 |
foreach my $key( keys %$branch ) { |
423 |
$branch_info{"branches.$key"} = $branch->{$key}; |
424 |
} |
425 |
|
426 |
return %branch_info; |
427 |
} |
428 |
|
429 |
=head2 send_digests |
417 |
=head2 send_digests |
430 |
|
418 |
|
431 |
send_digests({ |
419 |
send_digests({ |
Lines 491-499
sub send_digests {
Link Here
|
491 |
$titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } ); |
479 |
$titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } ); |
492 |
} |
480 |
} |
493 |
|
481 |
|
494 |
## Get branch info for borrowers home library. |
|
|
495 |
my %branch_info = get_branch_info( $borrowernumber ); |
496 |
|
497 |
foreach my $transport ( keys %{ $borrower_preferences->{'transports'} } ) { |
482 |
foreach my $transport ( keys %{ $borrower_preferences->{'transports'} } ) { |
498 |
my $letter = parse_letter( |
483 |
my $letter = parse_letter( |
499 |
{ |
484 |
{ |
Lines 502-510
sub send_digests {
Link Here
|
502 |
substitute => { |
487 |
substitute => { |
503 |
count => $count, |
488 |
count => $count, |
504 |
'items.content' => $titles, |
489 |
'items.content' => $titles, |
505 |
%branch_info, |
|
|
506 |
}, |
490 |
}, |
507 |
branchcode => $branch_info{"branches.branchcode"}, |
491 |
branchcode => $params->{branchcode}, |
508 |
message_transport_type => $transport, |
492 |
message_transport_type => $transport, |
509 |
} |
493 |
} |
510 |
) |
494 |
) |