[Koha-patches] [PATCH] Bug 2660: Prevent duplication of overdue notices.

Ryan Higgins rch at liblime.com
Wed Oct 8 18:49:52 CEST 2008


This limits generation of notices to days that an overdue item actually
hits the overdue trigger.
---
 misc/cronjobs/overdue_notices.pl |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl
index 225a41f..97f6ae6 100755
--- a/misc/cronjobs/overdue_notices.pl
+++ b/misc/cronjobs/overdue_notices.pl
@@ -285,7 +285,7 @@ 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.*
+SELECT biblio.*, items.*, issues.*, TO_DAYS(NOW())-TO_DAYS(date_due) AS days_overdue
   FROM issues,items,biblio
   WHERE items.itemnumber=issues.itemnumber
     AND biblio.biblionumber   = items.biblionumber
@@ -340,11 +340,12 @@ END_SQL
             push @borrower_parameters, $mindays, $maxdays;
             my $sth = $dbh->prepare($borrower_sql);
             $sth->execute(@borrower_parameters);
-            $verbose and warn $borrower_sql . "\n\n ($mindays, $maxdays)\nreturns " . $sth->rows . " rows";
+            $verbose and warn $borrower_sql . "\n $branchcode | " . $overdue_rules->{'categorycode'} . "\n ($mindays, $maxdays)\nreturns " . $sth->rows . " rows";
 
             while ( my ( $itemcount, $borrowernumber, $firstname, $lastname, $address1, $address2, $city, $postcode, $email ) = $sth->fetchrow ) {
                 warn "borrower $firstname, $lastname ($borrowernumber) has $itemcount items overdue." if $verbose;
 
+                my $notify = 0;
                 my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"} );
                 unless ($letter) {
                     $verbose and warn "Message '$overdue_rules->{letter$i}' content not found";
@@ -365,6 +366,8 @@ END_SQL
                 while ( my $item_info = $sth2->fetchrow_hashref() ) {
                     my @item_info = map { $_ =~ /date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields;
                     $titles .= join("\t", @item_info) . "\n";
+                    # only send the notice if at least one of the items hits the delay trigger.
+                    $notify++ if( ($maxdays != $MAX) && ($item_info->{'days_overdue'} == $mindays) ); 
                 }
                 $sth2->finish;
 
@@ -386,7 +389,8 @@ END_SQL
                 $letter->{'content'} =~ s/\<[^<>]*?\>//g;    # Now that we've warned about them, remove them.
                 $letter->{'content'} =~ s/\<[^<>]*?\>//g;    # 2nd pass for the double nesting.
 
-                if ($nomail) {
+                if($notify) {
+                  if ($nomail) {
 
                     push @output_chunks,
                       prepare_letter_for_printing(
@@ -433,6 +437,7 @@ END_SQL
                             }
                           );
                     }
+                  }
                 }
 
             }
-- 
1.5.5.GIT




More information about the Koha-patches mailing list