From 410975a7f777123d255854ecf3d31541b86ff848 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 --- 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 fa13c59236..4feb3eed64 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -426,7 +426,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 @@ -440,13 +440,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; } @@ -455,11 +454,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