From 090ab475663dfa487e7d5c60d9c7e01e606217fd Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 16 Aug 2024 14:08:40 +0100 Subject: [PATCH] Bug 10190: Add comments to overdue_notices and rename variable Trying to fully understand how this script operates.. this patch adds some notes to the script for developers and also renames a variable that I found was being re-used. Sponsored-by: Glasgow Colleges Library Group Signed-off-by: George Harkins --- misc/cronjobs/overdue_notices.pl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 6ae5abde36d..5a023a6245d 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -464,6 +464,8 @@ if ( defined $htmlfilename ) { my %already_queued; my %seen = map { $_ => 1 } @branches; + +# Work through branches foreach my $branchcode (@branches) { my $calendar; if ( C4::Context->preference('OverdueNoticeCalendar') ) { @@ -521,17 +523,20 @@ END_SQL @itemtypes = Koha::ItemTypes->search()->get_column('itemtype'); } + # Work through category and itemtype combinations to catch overdue rules for each for my $category (@categories) { for my $itemtype (@itemtypes) { my $i = 0; + + # Work through triggers until we run out of rules PERIOD: while (1) { $i++; - my $j = $i + 1; + my $ii = $i + 1; my $overdue_rules = Koha::CirculationRules->get_effective_rules( { rules => [ "overdue_$i" . '_delay', "overdue_$i" . '_notice', "overdue_$i" . '_mtt', - "overdue_$i" . '_restrict', "overdue_$j" . '_delay' + "overdue_$i" . '_restrict', "overdue_$ii" . '_delay' ], categorycode => $category, branchcode => $branchcode, @@ -548,8 +553,8 @@ END_SQL $overdue_rules->{ "overdue_$i" . '_delay' } ; # the notice will be sent after mindays days (grace period) my $maxdays = ( - $overdue_rules->{ "overdue_$j" . '_delay' } - ? $overdue_rules->{ "overdue_$j" . '_delay' } - 1 + $overdue_rules->{ "overdue_$ii" . '_delay' } + ? $overdue_rules->{ "overdue_$ii" . '_delay' } - 1 : ($MAX) ); # issues being more than maxdays late are managed somewhere else. (borrower probably suspended) @@ -569,6 +574,7 @@ END_SQL # itemcount is interpreted here as the number of items in the overdue range defined by the current notice or all overdues < max if(-list-all). # + # Fetch all overdue issues where the item is not lost and the borrower category wants overdue notices grouping by borrower 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,items @@ -593,7 +599,7 @@ END_SQL } $borrower_sql .= ' AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber'; - # $sth gets borrower info iff at least one overdue item has triggered the overdue action. + # $sth gets borrower info if at least one overdue item has triggered the overdue action. my $sth = $dbh->prepare($borrower_sql); $sth->execute(@borrower_parameters); @@ -608,6 +614,8 @@ END_SQL } $verbose and warn sprintf "Found %s borrowers with overdues\n", $sth->rows; my $borrowernumber; + + # Iterate over all overdue issues while ( my $data = $sth->fetchrow_hashref ) { # check the borrower has at least one item that matches @@ -640,7 +648,10 @@ END_SQL next; } $borrowernumber = $data->{'borrowernumber'}; + + # Skip duplicate borrowers as we'll have already handled them next if ( $patron_homelibrary && $already_queued{"$borrowernumber$i"} ); + my $borr = sprintf( "%s%s%s (%s)", $data->{'surname'} || '', @@ -708,6 +719,8 @@ END_SQL my $j = 0; my $exceededPrintNoticesMaxLines = 0; + + # Get each overdue item for this patron while ( my $item_info = $sth2->fetchrow_hashref() ) { if ( C4::Context->preference('OverdueNoticeCalendar') ) { $days_between = -- 2.48.1