X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=misc%2Fcronjobs%2Foverdue_notices.pl;h=8c0bc12d3049493d0ad1371c959336defc1d87fe;hb=8648c21ddf975d9c8b589c8457e73e511077a05b;hp=cb9ffa2ec683a63dd90ffe1215ede6af2a89e3b0;hpb=367c4fb8815bfe4a01869a25bcd8222989c15dcd;p=koha_fer diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index cb9ffa2ec6..8c0bc12d30 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -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 <> 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; } @@ -473,14 +486,14 @@ END_SQL my $titles = ""; my @items = (); - my $i = 0; + my $j = 0; my $exceededPrintNoticesMaxLines = 0; while ( my $item_info = $sth2->fetchrow_hashref() ) { - if ( ( !$email || $nomail ) && $PrintNoticesMaxLines && $i >= $PrintNoticesMaxLines ) { + if ( ( !$email || $nomail ) && $PrintNoticesMaxLines && $j >= $PrintNoticesMaxLines ) { $exceededPrintNoticesMaxLines = 1; last; } - $i++; + $j++; my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; $titles .= join("\t", @item_info) . "\n"; $itemcount++; @@ -644,7 +657,7 @@ substituted keys and values. sub parse_letter { my $params = shift; foreach my $required (qw( letter_code borrowernumber )) { - return unless exists $params->{$required}; + return unless ( exists $params->{$required} && $params->{$required} ); } my $substitute = $params->{'substitute'} || {};