@@ -, +, @@ --- misc/cronjobs/overdue_notices.pl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) --- a/misc/cronjobs/overdue_notices.pl +++ a/misc/cronjobs/overdue_notices.pl @@ -73,7 +73,7 @@ overdue_notices.pl -list-all list all overdues -date emulate overdues run for this date -email type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable. - + -a Create only one message per borrower and delay level including overdues from all branches. =head1 OPTIONS =over 8 @@ -181,6 +181,13 @@ use it in order to send overdues on a specific date and not Now. Format: YYYY-MM Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable. +=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 @@ -302,6 +309,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, @@ -321,6 +329,7 @@ GetOptions( 'borcat=s' => \@myborcat, 'borcatout=s' => \@myborcatout, 'email=s' => \@emails, + 'a|all_in_one=s' => \$all_in_one, ) or pod2usage(2); pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; @@ -442,6 +451,8 @@ elsif ( defined $text_filename ) { } } +my %already_queued; +my %seen = map { $_ => 1 } @branches; foreach my $branchcode (@branches) { if ( C4::Context->preference('OverdueNoticeCalendar') ) { my $calendar = Koha::Calendar->new( branchcode => $branchcode ); @@ -450,7 +461,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->branchemail || C4::Context->preference('KohaAdminEmailAddress'); my @output_chunks; # may be sent to mail or stdout or csv file. @@ -468,6 +479,7 @@ SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, branchname AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0 END_SQL + my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? "; $query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat); $query .= " AND categorycode NOT IN (".join( ',' , ('?') x @myborcatout ).") " if (@myborcatout); @@ -570,6 +582,7 @@ END_SQL next; } $borrowernumber = $data->{'borrowernumber'}; + next if ($all_in_one && $already_queued{"$borrowernumber$i"}); my $borr = $data->{'firstname'} . ', ' . $data->{'surname'} . ' (' @@ -661,6 +674,7 @@ END_SQL $exceededPrintNoticesMaxLines = 1; last; } + next if $all_in_one and ! grep {$seen{$item_info->{branchcode}}} @branches; $j++; my @item_info = map { $_ =~ /^date|date$/ ? eval { output_pref( { dt => dt_from_string( $item_info->{$_} ), dateonly => 1 } ); } @@ -774,6 +788,7 @@ END_SQL } } } + $already_queued{"$borrowernumber$i"} = 1; } $sth->finish; } --