From: Chris Cormack <chr...@catalyst.net.nz>

Signed-off-by: Katrin Fischer <katrin.fischer...@web.de>
---
 misc/cronjobs/overdue_notices.pl |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl
index e605451..9e5f953 100755
--- a/misc/cronjobs/overdue_notices.pl
+++ b/misc/cronjobs/overdue_notices.pl
@@ -425,7 +425,7 @@ END_SQL
             # <date> <itemcount> <firstname> <lastname> <address1> <address2> 
<address3> <city> <postcode>
 
             my $borrower_sql = <<'END_SQL';
-SELECT COUNT(*), issues.borrowernumber, firstname, surname, address, address2, 
city, zipcode, country, email, MIN(date_due) as longest_issue
+SELECT distinct(issues.borrowernumber), firstname, surname, address, address2, 
city, zipcode, country, email, date_due 
 FROM   issues,borrowers,categories
 WHERE  issues.borrowernumber=borrowers.borrowernumber
 AND    borrowers.categorycode=categories.categorycode
@@ -439,13 +439,12 @@ END_SQL
                 $borrower_sql .= ' AND borrowers.categorycode=? ';
                 push @borrower_parameters, $overdue_rules->{categorycode};
             }
-            $borrower_sql .= '  AND categories.overduenoticerequired=1
-                                GROUP BY issues.borrowernumber ';
+            $borrower_sql .= '  AND categories.overduenoticerequired=1 ';
             if($triggered) {
-                $borrower_sql .= ' HAVING 
TO_DAYS(NOW())-TO_DAYS(longest_issue) = ?';
+                $borrower_sql .= ' HAVING TO_DAYS(NOW())-TO_DAYS(date_due) = 
?';
                 push @borrower_parameters, $mindays;
             } else {
-                $borrower_sql .= ' HAVING 
TO_DAYS(NOW())-TO_DAYS(longest_issue) BETWEEN ? and ? ' ;
+                $borrower_sql .= ' HAVING TO_DAYS(NOW())-TO_DAYS(date_due) 
BETWEEN ? and ? ' ;
                 push @borrower_parameters, $mindays, $maxdays;
             }
 
@@ -454,11 +453,11 @@ END_SQL
             $sth->execute(@borrower_parameters);
             $verbose and warn $borrower_sql . "\n $branchcode | " . 
$overdue_rules->{'categorycode'} . "\n ($mindays, $maxdays)\nreturns " . 
$sth->rows . " rows";
 
-            while ( my ($itemcount, $borrowernumber, $firstname, $lastname,
+            while ( my ( $borrowernumber, $firstname, $lastname,
                     $address1, $address2, $city, $postcode, $country, $email,
-                    $longest_issue ) = $sth->fetchrow )
+                    $date_due ) = $sth->fetchrow )
             {
-                $verbose and warn "borrower $firstname, $lastname 
($borrowernumber) has $itemcount items triggering level $i.";
+                $verbose and warn "borrower $firstname, $lastname 
($borrowernumber) has items triggering level $i.";
     
                 my $letter = C4::Letters::getletter( 'circulation', 
$overdue_rules->{"letter$i"} );
 
-- 
1.7.4.1

_______________________________________________
Koha-patches mailing list
Koha-patches@lists.koha-community.org
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to