Bug 17952 - Lost items not skipped by overdue_notices.pl
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 20 Jan 2017 14:43:24 +0000 (14:43 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Mon, 8 May 2017 12:55:59 +0000 (08:55 -0400)
If a library does not use --mark-returned when running longoverdue.pl,
all those lost item checkouts are selected by overdue_notices.pl.
This causes much unnecessary overhead. In addition Koha::Calendar is
instantiated many times for each branchcode which is not necessary.

Test Plan:
1) Run overdue_notices.pl, note output
2) Apply this patch
3) Run overdue_notices.pl again, note output is the same

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jane Leven <jleven@camdencountylibrary.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
misc/cronjobs/overdue_notices.pl

index 0aaf22a..cb95ee5 100755 (executable)
@@ -443,8 +443,9 @@ elsif ( defined $text_filename ) {
 }
 
 foreach my $branchcode (@branches) {
+    my $calendar;
     if ( C4::Context->preference('OverdueNoticeCalendar') ) {
-        my $calendar = Koha::Calendar->new( branchcode => $branchcode );
+        $calendar = Koha::Calendar->new( branchcode => $branchcode );
         if ( $calendar->is_holiday($date_to_run) ) {
             next;
         }
@@ -466,7 +467,8 @@ SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, branchname
     AND biblio.biblionumber   = biblioitems.biblionumber
     AND issues.borrowernumber = ?
     AND issues.branchcode = ?
-    AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0
+    AND items.itemlost = 0
+/   AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0
 END_SQL
 
     my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? ";
@@ -514,9 +516,11 @@ END_SQL
 
             my $borrower_sql = <<"END_SQL";
 SELECT issues.borrowernumber, firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email, smsalertnumber, phone, cardnumber, date_due
-FROM   issues,borrowers,categories
+FROM   issues,borrowers,categories,items
 WHERE  issues.borrowernumber=borrowers.borrowernumber
 AND    borrowers.categorycode=categories.categorycode
+AND    issues.itemnumber = items.itemnumber
+AND    items.itemlost = 0
 AND    TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0
 END_SQL
             my @borrower_parameters;
@@ -542,8 +546,6 @@ END_SQL
                 my $days_between;
                 if ( C4::Context->preference('OverdueNoticeCalendar') )
                 {
-                    my $calendar =
-                      Koha::Calendar->new( branchcode => $branchcode );
                     $days_between =
                       $calendar->days_between( dt_from_string($data->{date_due}),
                         $date_to_run );
@@ -626,8 +628,6 @@ END_SQL
                 my $exceededPrintNoticesMaxLines = 0;
                 while ( my $item_info = $sth2->fetchrow_hashref() ) {
                     if ( C4::Context->preference('OverdueNoticeCalendar') ) {
-                        my $calendar =
-                          Koha::Calendar->new( branchcode => $branchcode );
                         $days_between =
                           $calendar->days_between(
                             dt_from_string( $item_info->{date_due} ), $date_to_run );