From caba5cf369f741356eda32da5601bb1b57531c50 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 3 May 2011 12:13:28 +1200 Subject: [PATCH] Bug 6292 : Overdue notices not being generated when borrower had an overdue older than the max value of the notice triggers Signed-off-by: Katrin Fischer (cherry picked from commit 410975a7f777123d255854ecf3d31541b86ff848) Signed-off-by: Chris Nighswonger (cherry picked from commit f497930d66b18bcbb6676ca698d5f10c4b32fbcc) Signed-off-by: Chris Nighswonger --- misc/cronjobs/overdue_notices.pl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 09d633df72..e6dccda774 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -425,7 +425,7 @@ END_SQL # 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"} ); -- 2.39.5