@@ -, +, @@ --- misc/cronjobs/overdue_notices.pl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) --- a/misc/cronjobs/overdue_notices.pl +++ a/misc/cronjobs/overdue_notices.pl @@ -78,6 +78,7 @@ overdue_notices.pl -email Type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable. --frombranch Set the from address for the notice to one of 'item-homebranch' or 'item-issuebranch'. + -a Create only one message per borrower and delay level including overdues from all branches. =head1 OPTIONS @@ -192,6 +193,13 @@ Use the address information from the item homebranch library instead of the issu Defaults to 'item-issuebranch' +=item B<-a> | B<--all_in_one> + +Create only one message per borrower and for each delay level including overdues from all branches. +Branchcode value (branches.branchcode) has to be given to choose which sender address will be set. +It's recommended to use this option only with default notice(s) defined for 'All branches' +in Notices & Slips and no specific ones. + =back =head1 DESCRIPTION @@ -314,6 +322,7 @@ my $itemscontent = join( ',', qw( date_due title barcode author itemnumber ) ); my @myborcat; my @myborcatout; my ( $date_input, $today ); +my $all_in_one; GetOptions( 'help|?' => \$help, @@ -334,6 +343,7 @@ GetOptions( 'borcatout=s' => \@myborcatout, 'email=s' => \@emails, 'frombranch=s' => \$frombranch, + 'a|all_in_one=s' => \$all_in_one, ) or pod2usage(2); pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; @@ -459,6 +469,8 @@ elsif ( defined $text_filename ) { } } +my %already_queued; +my %seen = map { $_ => 1 } @branches; foreach my $branchcode (@branches) { my $calendar; if ( C4::Context->preference('OverdueNoticeCalendar') ) { @@ -468,7 +480,7 @@ foreach my $branchcode (@branches) { } } - my $library = Koha::Libraries->find($branchcode); + my $library = $all_in_one ? Koha::Libraries->find($all_in_one) : Koha::Libraries->find($branchcode); my $admin_email_address = $library->from_email_address; my $branch_email_address = C4::Context->preference('AddressForFailedOverdueNotices') || $library->inbound_email_address; @@ -487,6 +499,8 @@ SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, branchname AND items.itemlost = 0 AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0 END_SQL + $sql2.= " AND issues.branchcode = ?" unless $all_in_one; + my $sth2 = $dbh->prepare($sql2); if($owning_library) { $sql2 .= ' AND items.homebranch = ? '; @@ -601,6 +615,7 @@ END_SQL next; } $borrowernumber = $data->{'borrowernumber'}; + next if ($all_in_one && $already_queued{"$borrowernumber$i"}); my $borr = sprintf( "%s%s%s (%s)", $data->{'surname'} || '', $data->{'firstname'} && $data->{'surname'} ? ', ' : '', @@ -652,7 +667,7 @@ END_SQL ) unless $test_mode; $verbose and warn "debarring $borr\n"; } - my @params = ($borrowernumber,$branchcode); + my @params = $all_in_one ? ($borrowernumber) : ($borrowernumber, $branchcode); $verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber"; $sth2->execute(@params); @@ -698,6 +713,7 @@ END_SQL $exceededPrintNoticesMaxLines = 1; last; } + next if $all_in_one and ! grep {$seen{$item_info->{branchcode}}} @branches; $j++; $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields, dateonly => 1 } ); @@ -819,6 +835,7 @@ END_SQL } } } + $already_queued{"$borrowernumber$i"} = 1; } $sth->finish; } --