Bug 7447 allow to specify a date in overdue_notice.pl

This patch add a new parameter to overdue_notices.pl, that is a date.
If you add --date=YYYY-MM-DD when running overdue_notices, it will generate overdues as if you were on date provided

that's usefull if you want to relaunch an overdue calculation that has failed, of after changing your circ rules

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
This commit is contained in:
Paul Poulain 2012-01-16 17:19:26 +01:00
parent 2102895ab5
commit d094e24af9
1 changed files with 22 additions and 9 deletions

View File

@ -143,6 +143,10 @@ Default items.content lists only those items that fall in the
range of the currently processing notice.
Choose list-all to include all overdue items in the list (limited by B<-max> setting).
=item B<-date>
use it in order to send overdues on a specific date and not Now.
=back
=head1 DESCRIPTION
@ -259,6 +263,7 @@ my $listall = 0;
my $itemscontent = join( ',', qw( date_due title barcode author itemnumber ) );
my @myborcat;
my @myborcatout;
my $date;
GetOptions(
'help|?' => \$help,
@ -268,12 +273,13 @@ GetOptions(
'max=s' => \$MAX,
'library=s' => \@branchcodes,
'csv:s' => \$csvfilename, # this optional argument gets '' if not supplied.
'html:s' => \$htmlfilename, # this optional argument gets '' if not supplied.
'html:s' => \$htmlfilename, # this optional argument gets '' if not supplied.
'itemscontent=s' => \$itemscontent,
'list-all' => \$listall,
't|triggered' => \$triggered,
'borcat=s' => \@myborcat,
'borcatout=s' => \@myborcatout,
'list-all' => \$listall,
't|triggered' => \$triggered,
'date' => \$date,
'borcat=s' => \@myborcat,
'borcatout=s' => \@myborcatout,
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage( -verbose => 2 ) if $man;
@ -320,6 +326,13 @@ if (@branchcodes) {
}
}
if ($date){
$date=$dbh->quote($date);
}
else {
$date="NOW()";
}
# these are the fields that will be substituted into <<item.content>>
my @item_content_fields = split( /,/, $itemscontent );
@ -376,13 +389,13 @@ foreach my $branchcode (@branches) {
$verbose and warn sprintf "branchcode : '%s' using %s\n", $branchcode, $admin_email_address;
my $sth2 = $dbh->prepare( <<'END_SQL' );
SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS(NOW())-TO_DAYS(date_due) AS days_overdue
SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS($date)-TO_DAYS(date_due) AS days_overdue
FROM issues,items,biblio, biblioitems
WHERE items.itemnumber=issues.itemnumber
AND biblio.biblionumber = items.biblionumber
AND biblio.biblionumber = biblioitems.biblionumber
AND issues.borrowernumber = ?
AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN ? and ?
AND TO_DAYS($date)-TO_DAYS(date_due) BETWEEN ? and ?
END_SQL
my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? ";
@ -442,10 +455,10 @@ END_SQL
}
$borrower_sql .= ' AND categories.overduenoticerequired=1 ';
if($triggered) {
$borrower_sql .= ' AND TO_DAYS(NOW())-TO_DAYS(date_due) = ?';
$borrower_sql .= ' AND TO_DAYS($date)-TO_DAYS(date_due) = ?';
push @borrower_parameters, $mindays;
} else {
$borrower_sql .= ' AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN ? and ? ' ;
$borrower_sql .= ' AND TO_DAYS($date)-TO_DAYS(date_due) BETWEEN ? and ? ' ;
push @borrower_parameters, $mindays, $maxdays;
}