From 6515ee9678c50e24b2957ad292ce313fae3bef07 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 6 Jul 2009 10:13:54 +0200 Subject: [PATCH] (bug #3393) take care of default rules in overdues This fix the overdues notices script, that doesn't take care of default rules. Now if there is no specific rules for a branchcode, the script use the default rule if it exists. Signed-off-by: Henri-Damien LAURENT --- C4/Overdues.pm | 12 ++++++++++++ misc/cronjobs/overdue_notices.pl | 24 +++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 0815386d7b..61ff40fdc6 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -967,8 +967,20 @@ returns a list of branch codes for branches with overdue rules defined. sub GetBranchcodesWithOverdueRules { my $dbh = C4::Context->dbh; my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> ''"); + my $availbranches = C4::Branch::GetBranches(); + $rqoverduebranches->execute; my @branches = map { shift @$_ } @{ $rqoverduebranches->fetchall_arrayref }; + + my $defaultbranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ''"); + $defaultbranches->execute(); + if($defaultbranches->rows > 0){ + foreach my $branch (keys %$availbranches){ + if(not grep{/^$branch$/} @branches){ + push @branches, $branch; + } + } + } $rqoverduebranches->finish; return @branches; } diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 23ce459aa8..1312db953c 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -298,7 +298,6 @@ if ( defined $csvfilename ) { } foreach my $branchcode (@branches) { - my $branch_details = C4::Branch::GetBranchDetail($branchcode); my $admin_email_address = $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress'); my @output_chunks; # may be sent to mail or stdout or csv file. @@ -307,19 +306,25 @@ foreach my $branchcode (@branches) { my $sth2 = $dbh->prepare( <<'END_SQL' ); 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 - AND issues.borrowernumber = ? + FROM issues + LEFT JOIN items USING(itemnumber) + LEFT JOIN biblio USING(biblionumber) + WHERE issues.borrowernumber = ? AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN ? and ? END_SQL my $rqoverduerules = $dbh->prepare("SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? "); $rqoverduerules->execute($branchcode); + + # We get default rules is there is no rule for this branch + if($rqoverduerules->rows == 0){ + $rqoverduerules = $dbh->prepare("SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' "); + $rqoverduerules->execute(); + } + # my $outfile = 'overdues_' . ( $mybranch || $branchcode || 'default' ); while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) { PERIOD: foreach my $i ( 1 .. 3 ) { - $verbose and warn "branch '$branchcode', pass $i\n"; my $mindays = $overdue_rules->{"delay$i"}; # the notice will be sent after mindays days (grace period) my $maxdays = ( @@ -341,9 +346,10 @@ END_SQL my $borrower_sql = <<'END_SQL'; SELECT COUNT(*), issues.borrowernumber, firstname, surname, address, address2, city, zipcode, email, MIN(date_due) as longest_issue -FROM issues,borrowers,categories -WHERE issues.borrowernumber=borrowers.borrowernumber -AND borrowers.categorycode=categories.categorycode +FROM issues +LEFT JOIN borrowers USING (borrowernumber) +LEFT JOIN categories ON (borrowers.categorycode=categories.categorycode) +WHERE 1 END_SQL my @borrower_parameters; if ($branchcode) { -- 2.39.5