=head1 NAME
-advance_notices.pl - cron script to put item due reminders into message queue
+advance_notices.pl - prepare messages to be sent to patrons for nearly due, or due, items
=head1 SYNOPSIS
-./advance_notices.pl -c
-
-or, in crontab:
-0 1 * * * advance_notices.pl -c
+ advance_notices.pl
+ [ -n ][ -m <number of days> ][ --itemscontent <comma separated field list> ][ -c ]
=head1 DESCRIPTION
use strict;
use warnings;
-use Getopt::Long;
-use Pod::Usage;
-use Data::Dumper;
-BEGIN {
- # find Koha's Perl modules
- # test carefully before changing this
- use FindBin;
- eval { require "$FindBin::Bin/../kohalib.pl" };
-}
+use Getopt::Long qw( GetOptions );
+use Pod::Usage qw( pod2usage );
use Koha::Script -cron;
-use C4::Biblio;
use C4::Context;
use C4::Letters;
use C4::Members;
use C4::Members::Messaging;
-use C4::Overdues;
-use Koha::DateUtils;
-use C4::Log;
+use C4::Log qw( cronlogaction );
use Koha::Items;
use Koha::Libraries;
use Koha::Patrons;
-=head1 NAME
-
-advance_notices.pl - prepare messages to be sent to patrons for nearly due, or due, items
-
-=head1 SYNOPSIS
-
-advance_notices.pl
- [ -n ][ -m <number of days> ][ --itemscontent <comma separated field list> ][ -c ]
-
=head1 OPTIONS
=over 8
the digested message. It has no effect unless the borrower has
chosen 'Digests only' on the advance messages.
-=back
+=item B<--library>
-=head1 DESCRIPTION
+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<--frombranch>
-This script is designed to alert patrons when items are due, or coming due
+Set the from address for the notice to one of 'item-homebranch' or 'item-issuebranch'.
+
+Defaults to 'item-issuebranch'
+
+=back
=head2 Configuration
my $maxdays = 30; # -e: the End of the time period
my $verbose = 0; # -v: verbose
my $digest_per_branch = 0; # -digest-per-branch: Prepare and send digests per branch
+my @branchcodes; # Branch(es) passed as parameter
+my $frombranch = 'item-issuebranch';
my $itemscontent = join(',',qw( date_due title author barcode ));
my $help = 0;
GetOptions(
'help|?' => \$help,
'man' => \$man,
+ 'library=s' => \@branchcodes,
+ 'frombranch=s' => \$frombranch,
'c' => \$confirm,
'n' => \$nomail,
'm:i' => \$maxdays,
# Since advance notice options are not visible in the web-interface
# unless EnhancedMessagingPreferences is on, let the user know that
# this script probably isn't going to do much
-if ( ! C4::Context->preference('EnhancedMessagingPreferences') ) {
+if ( ! C4::Context->preference('EnhancedMessagingPreferences') && $verbose ) {
warn <<'END_WARN';
The "EnhancedMessagingPreferences" syspref is off.
}
cronlogaction();
+my %branches = ();
+if (@branchcodes) {
+ %branches = map { $_ => 1 } @branchcodes;
+}
+
+die "--frombranch takes item-homebranch or item-issuebranch only"
+ unless ( $frombranch eq 'item-issuebranch'
+ || $frombranch eq 'item-homebranch' );
+my $owning_library = ( $frombranch eq 'item-homebranch' ) ? 1 : 0;
+
# The fields that will be substituted into <<items.content>>
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
$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');
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 },
$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'});
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 },
if ($nomail) {
for my $letter ( @letters ) {
local $, = "\f";
- print $letter->{'content'};
+ print $letter->{'content'}."\n";
}
}
else {