@@ -, +, @@ --- misc/cronjobs/overdue_notices.pl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) --- a/misc/cronjobs/overdue_notices.pl +++ a/misc/cronjobs/overdue_notices.pl @@ -72,6 +72,7 @@ overdue_notices.pl --frombranch Organize and send overdue notices by home library (item-homebranch) or checkout library (item-issuebranch). This option is only used, if the OverdueNoticeFrom system preference is set to 'command-line option'. Defaults to item-issuebranch. + -a Create only one message per borrower and delay level including overdues from all branches. =head1 OPTIONS @@ -188,6 +189,13 @@ Organize overdue notices either by checkout library (item-issuebranch) or item h This option is only used, if the OverdueNoticeFrom system preference is set to use 'command-line option'. Defaults to checkout library (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 @@ -310,6 +318,7 @@ my $itemscontent = join( ',', qw( date_due title barcode author itemnumber ) ); my @myborcat; my @myborcatout; my ( $date_input, $today ); +my $all_in_one; my $command_line_options = join(" ",@ARGV); @@ -332,6 +341,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; @@ -457,6 +467,8 @@ elsif ( defined $text_filename ) { } } +my %already_queued; +my %seen = map { $_ => 1 } @branches; foreach my $branchcode (@branches) { my $calendar; if ( C4::Context->preference('OverdueNoticeCalendar') ) { @@ -466,7 +478,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; @@ -490,7 +502,7 @@ END_SQL if($owning_library) { $sql2 .= ' AND items.homebranch = ? '; } else { - $sql2 .= ' AND issues.branchcode = ? '; + $sql2 .= ' AND issues.branchcode = ? ' unless $all_in_one; } my $sth2 = $dbh->prepare($sql2); @@ -606,6 +618,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'} ? ', ' : '', @@ -656,7 +669,7 @@ END_SQL ) unless $test_mode; $verbose and warn "debarring $borr\n"; } - my @params = ($borrowernumber,$branchcode); + my @params = $all_in_one ? ($borrowernumber) : ($borrowernumber, $branchcode); $sth2->execute(@params); my $itemcount = 0; @@ -701,6 +714,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 } ); @@ -824,6 +838,7 @@ END_SQL } } } + $already_queued{"$borrowernumber$i"} = 1; } $sth->finish; } --