@@ -, +, @@ instead of issuing library --- C4/Circulation.pm | 19 +++++++++++--- misc/cronjobs/advance_notices.pl | 43 +++++++++++++++++++++++++++++--- misc/cronjobs/overdue_notices.pl | 13 +++++++++- 3 files changed, 68 insertions(+), 7 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2560,8 +2560,21 @@ sub GetUpcomingDueIssues { $params->{'days_in_advance'} = 7 unless exists $params->{'days_in_advance'}; my $dbh = C4::Context->dbh; - - my $statement = <{'owning_library'}) { + $statement = <<"END_SQL"; +SELECT * +FROM ( + SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail + FROM issues + LEFT JOIN items USING (itemnumber) + LEFT OUTER JOIN branches ON (branches.branchcode = items.homebranch) + WHERE returndate is NULL +) tmp +WHERE days_until_due >= 0 AND days_until_due <= ? +END_SQL + } else { + $statement = <<"END_SQL"; SELECT * FROM ( SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail @@ -2572,7 +2585,7 @@ FROM ( ) tmp WHERE days_until_due >= 0 AND days_until_due <= ? END_SQL - + } my @bind_parameters = ( $params->{'days_in_advance'} ); my $sth = $dbh->prepare( $statement ); --- a/misc/cronjobs/advance_notices.pl +++ a/misc/cronjobs/advance_notices.pl @@ -109,6 +109,16 @@ defaults to date_due,title,author,barcode Other possible values come from fields in the biblios, items and issues tables. +=item B<-library> + +select notices for one specific library. Use the value in the +branches.branchcode table. This option can be repeated in order +to select notices for a group of libraries. + +=item B<-owning> + +Use the address information from the item homebranch library instead of the issuing library. + =back =head1 DESCRIPTION @@ -174,6 +184,8 @@ my $nomail; # -n: No mai my $mindays = 0; # -m: Maximum number of days in advance to send notices my $maxdays = 30; # -e: the End of the time period my $verbose = 0; # -v: verbose +my @branchcodes; # Branch(es) passed as parameter +my $owning_library = 0; my $itemscontent = join(',',qw( date_due title author barcode )); my $help = 0; @@ -182,6 +194,8 @@ my $man = 0; GetOptions( 'help|?' => \$help, 'man' => \$man, + 'library=s' => \@branchcodes, + 'owning' => \$owning_library, 'c' => \$confirm, 'n' => \$nomail, 'm:i' => \$maxdays, @@ -209,11 +223,16 @@ unless ($confirm) { cronlogaction(); +my %branches = map { $_ => 1 } @branchcodes if @branchcodes; + # The fields that will be substituted into <> my @item_content_fields = split(/,/,$itemscontent); warn 'getting upcoming due issues' if $verbose; -my $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => $maxdays } ); +my $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { + days_in_advance => $maxdays, + owning_library => $owning_library + } ); warn 'found ' . scalar( @$upcoming_dues ) . ' issues' if $verbose; # hash of borrowernumber to number of items upcoming @@ -253,6 +272,15 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { $due_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address; $due_digest->{ $upcoming->{borrowernumber} }->{count}++; } else { + my $branchcode; + if($owning_library) { + $branchcode = $upcoming->{'homebranch'}; + } else { + $branchcode = $upcoming->{'branchcode'}; + } + # Skip this DUE if we specify list of libraries and this one is not part of it + next if (@branchcodes && !$branches{$branchcode}); + my $item = Koha::Items->find( $upcoming->{itemnumber} ); my $letter_type = 'DUE'; $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0'); @@ -265,7 +293,7 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) { my $letter = parse_letter( { letter_code => $letter_type, borrowernumber => $upcoming->{'borrowernumber'}, - branchcode => $upcoming->{'branchcode'}, + branchcode => $branchcode, biblionumber => $item->biblionumber, itemnumber => $upcoming->{'itemnumber'}, substitute => { 'items.content' => $titles }, @@ -286,6 +314,15 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { $upcoming_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address; $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++; } else { + my $branchcode; + if($owning_library) { + $branchcode = $upcoming->{'homebranch'}; + } else { + $branchcode = $upcoming->{'branchcode'}; + } + # Skip this PREDUE if we specify list of libraries and this one is not part of it + next if (@branchcodes && !$branches{$branchcode}); + my $item = Koha::Items->find( $upcoming->{itemnumber} ); my $letter_type = 'PREDUE'; $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'}); @@ -298,7 +335,7 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) { my $letter = parse_letter( { letter_code => $letter_type, borrowernumber => $upcoming->{'borrowernumber'}, - branchcode => $upcoming->{'branchcode'}, + branchcode => $branchcode, biblionumber => $item->biblionumber, itemnumber => $upcoming->{'itemnumber'}, substitute => { 'items.content' => $titles }, --- a/misc/cronjobs/overdue_notices.pl +++ a/misc/cronjobs/overdue_notices.pl @@ -74,6 +74,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. + -owning Send notices from item homebranch library instead of issuing library =head1 OPTIONS @@ -182,6 +183,10 @@ 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<-owning> + +Use the address information from the item homebranch library instead of the issuing library. + =back =head1 DESCRIPTION @@ -291,6 +296,7 @@ my $verbose = 0; my $nomail = 0; my $MAX = 90; my $test_mode = 0; +my $owning_library = 0; my @branchcodes; # Branch(es) passed as parameter my @emails_to_use; # Emails to use for messaging my @emails; # Emails given in command-line parameters @@ -322,6 +328,7 @@ GetOptions( 'borcat=s' => \@myborcat, 'borcatout=s' => \@myborcatout, 'email=s' => \@emails, + 'owning' => \$owning_library, ) or pod2usage(2); pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; @@ -526,7 +533,11 @@ AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0 END_SQL my @borrower_parameters; if ($branchcode) { - $borrower_sql .= ' AND issues.branchcode=? '; + if($owning_library) { + $borrower_sql .= ' AND items.homebranch=? '; + } else { + $borrower_sql .= ' AND issues.branchcode=? '; + } push @borrower_parameters, $branchcode; } if ( $overdue_rules->{categorycode} ) { --