Bug 41315

Summary: Using patron-homelibrary option for overdue notices may not send notices to all branches
Product: Koha Reporter: Nick Clemens (kidclamp) <nick>
Component: Command-line UtilitiesAssignee: Nick Clemens (kidclamp) <nick>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: major    
Priority: P5 - low CC: andrew, clackman, david, robin
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=10190
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 32740    
Bug Blocks: 41316    
Attachments: Bug 41315: Change only notice branchcode when OverDueNoticeFrom is set to patron-homelibrary
Bug 41315: Remove unecessary conditional
Bug 41315: (follow-up) Rename statements for clarity
Bug 41315: Don't change which branch is used for getting the transports
Bug 41315: Change only notice branchcode when OverDueNoticeFrom is set to patron-homelibrary
Bug 41315: Remove unecessary conditional
Bug 41315: (follow-up) Rename statements for clarity
Bug 41315: Don't change which branch is used for getting the transports

Description Nick Clemens (kidclamp) 2025-11-26 15:31:26 UTC
Bug 32740 added the option to send overdue notices from the patron's homelibrary.

The branchcode variable is used for several purposes, in the new code:
 649                 if ($patron_homelibrary) {
 650                     $branchcode           = $patron->branchcode;
 651                     $library              = Koha::Libraries->find($branchcode);
 652                     $admin_email_address  = $library->from_email_address;
 653                     $branch_email_address = C4::Context->preference('AddressForFailedOverdueNotices')
 654                         || $library->inbound_email_address;
 655                 }


We change that branchcode param based on the patron, however, earlier when getting the list of patrons we limit by issue branch:
 567             my $borrower_sql = <<"END_SQL";
 568 SELECT issues.borrowernumber, firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email, smsalertnumber, phone, cardnumber, date_due
 569 FROM   issues,borrowers,categories,items
 570 WHERE  issues.borrowernumber=borrowers.borrowernumber
 571 AND    borrowers.categorycode=categories.categorycode
 572 AND    issues.itemnumber = items.itemnumber
 573 AND    items.itemlost = 0
 574 AND    TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0
 575 END_SQL
 576             my @borrower_parameters;
 577             if ($branchcode) {
 578                 if ($owning_library) {
 579                     $borrower_sql .= ' AND items.homebranch=? ';
 580                 } else {
 581                     $borrower_sql .= ' AND issues.branchcode=? ';
 582                 }
 583                 push @borrower_parameters, $branchcode;
 584             }

So we may have a patron from a different branch when we go through here, and end up changing the branch we will look at during the next pass of the code above



I recreated by checking out three items to patrons from different branches, 1 day overdue each:
MariaDB [koha_kohadev]> SELECT borrowers.cardnumber, borrowers.surname, borrowers.branchcode, borrowers.categorycode, issues.issue_id,  issues.branchcode, issues.date_due FROM issues JOIN borrowers USING (borrowernumber);
+----------------+---------+------------+--------------+----------+------------+---------------------+
| cardnumber     | surname | branchcode | categorycode | issue_id | branchcode | date_due            |
+----------------+---------+------------+--------------+----------+------------+---------------------+
| 23529001000463 | Acosta  | MPL        | PT           |        1 | CPL        | 2025-11-25 23:59:00 |
| 23529000139858 | Ballard | FFL        | PT           |        2 | CPL        | 2025-11-25 23:59:00 |
| 23529000035676 | Acevedo | IPT        | PT           |        3 | CPL        | 2025-11-25 23:59:00 |
+----------------+---------+------------+--------------+----------+------------+---------------------+
3 rows in set (0.001 sec)


Setting overdue rules to trigger at 1 day, then got this output:

branch 'CPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
Found 3 borrowers with overdues
borrower Acosta, Edna (5) has items triggering level 1.
borrower Acevedo, Henry (19) has items triggering level 1.
borrower Ballard, Ronnie (21) has items triggering level 1.
branch 'FFL', categorycode = PT pass 2
No letter code found for pass 2
branch 'FFL', categorycode = PT pass 3
No letter code found for pass 3
Comment 1 Nick Clemens (kidclamp) 2025-11-26 16:26:23 UTC
Created attachment 189965 [details] [review]
Bug 41315: Change only notice branchcode when OverDueNoticeFrom is set to patron-homelibrary

This patch adds a new variable $notice_branchcode and uses this when getting the patron's
homelibrary to ensure we don't change the branch we are using.

To test:
 1 - At branch A - checkout three items, 1 day overdue to 3 patrons of the same category from different branches (not A)
 2 - Set the system preference OverdueNoticeFrom to 'patron home library'
 3 - Browse to More->Tools->Overdue notice/status triggers
 4 - Set overdue triggers for default library and the category used above to:
     Delay: 1
     Letter: Overdue notice (ODUE)
 5 - From the command line run the overdue notices:
     perl misc/cronjobs/overdue_notices.pl --triggered --library CPL --test --nomail -v -v
 6 - Note that we begin pass 1 with CPL and then use a different branch for passes 2 and 3
 7 - Apply patch
 8 - Repeat
 9 - Confirm branch is consistent
10 - Run without branch param:
     perl misc/cronjobs/overdue_notices.pl --triggered --library CPL --test --nomail -v -v
11 - Confirm branches are consistent
Comment 2 Nick Clemens (kidclamp) 2025-11-26 16:26:26 UTC
Created attachment 189966 [details] [review]
Bug 41315: Remove unecessary conditional

We are in a loop here:
foreach my $branchcode (@branches) {

branchcode must be defined or something has gone seriously wrong with PERL
Comment 3 Nick Clemens (kidclamp) 2025-11-26 16:26:28 UTC
Created attachment 189967 [details] [review]
Bug 41315: (follow-up) Rename statements for clarity
Comment 4 Nick Clemens (kidclamp) 2025-11-26 16:26:31 UTC
Created attachment 189968 [details] [review]
Bug 41315: Don't change which branch is used for getting the transports

See bug 41316 - the script uses the triggers of the issuing branch when sending
by patron library - we shouldn't change this here, but on the next bug
Comment 5 David Nind 2025-12-26 01:22:46 UTC
I attempted to test, but I don't think I'm seeing what I should see.

Happy to test again if you can point out where I may have gone wrong.

Before the patch
=================

1. I issued three items at Centerville to patrons from three different libraries in the same patron category - I selected the day before 'Yesterday' for the due date when checking out.

2. The Barcodes for items checked out (all the items are from Centerville):
   - 39999000001570
   - 39999000008975
   - 39999000001617

3. The output from the SQL query:

MariaDB [koha_kohadev]> SELECT borrowers.cardnumber, borrowers.surname, borrowers.branchcode, borrowers.categorycode, issues.issue_id,  issues.branchcode, issues.date_due FROM issues JOIN borrowers USING (borrowernumber);
+----------------+---------+------------+--------------+----------+------------+---------------------+
| cardnumber     | surname | branchcode | categorycode | issue_id | branchcode | date_due            |
+----------------+---------+------------+--------------+----------+------------+---------------------+
| 23529000651225 | Burton  | MPL        | PT           |        1 | CPL        | 2025-12-24 23:59:00 |
| 23529000065863 | Hawkins | SPL        | PT           |        2 | CPL        | 2025-12-24 23:59:00 |
| 23529000065863 | Hawkins | SPL        | PT           |        3 | CPL        | 2025-12-24 23:59:00 |
+----------------+---------+------------+--------------+----------+------------+---------------------+
3 rows in set (0.001 sec)

4. For the overdue notice/status triggers:
   - Select library: Default
   - Patron category - Patron: 
     . Delay: 1
     . Letter: Overdue notice (ODUE)
   - Nothing else entered 

5. Steps 5 and 6: 
   - Output for step 5 - Each pass shows as CPL for me. 
   - Is this right/what is expected?
   - Step 6 says I should see different branches - in the description for the bug, the output has different library codes for each pass -- pass 1 = CPL, pass 2 = FFL, and pass 3 = FFL:

perl misc/cronjobs/overdue_notices.pl --triggered --library CPL --test --nomail -v -v
Found 12 branches with first message enabled: 'CPL', 'FFL', 'FPL', 'FRL', 'IPT', 'LPL', 'MPL', 'PVL', 'RPL', 'SPL', 'TPL', 'UPL'
branch CPL passed on parameter
branch CPL have overdue rules
======================================
branchcode : 'CPL' using root@localhost
branch 'CPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 CPL | PT
 (1, 90, 2025-12-26T01:10:19)
--------------------------
Found 3 borrowers with overdues
branch 'CPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'CPL', categorycode = PT pass 3
No letter code found for pass 3


After the patch
===============

Output from step 5 - no change
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

perl misc/cronjobs/overdue_notices.pl --triggered --library CPL --test --nomail -v -v
Found 12 branches with first message enabled: 'CPL', 'FFL', 'FPL', 'FRL', 'IPT', 'LPL', 'MPL', 'PVL', 'RPL', 'SPL', 'TPL', 'UPL'
branch CPL passed on parameter
branch CPL have overdue rules
======================================
branchcode : 'CPL' using root@localhost
branch 'CPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 CPL | PT
 (1, 90, 2025-12-26T01:15:25)
--------------------------
Found 3 borrowers with overdues
branch 'CPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'CPL', categorycode = PT pass 3
No letter code found for pass 3

Steps 9 and 11
~~~~~~~~~~~~~~

I'm not sure what is meant by "Confirm branch is consistent".

Should it be CPL for each pass?

From the output above, it is the same as before the patch - all showing CPL for for each pass.

Output from step 10 - I removed '--libary CPL' from the command (is that correct?)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

perl misc/cronjobs/overdue_notices.pl --triggered --test --nomail -v -v
Found 12 branches with first message enabled: 'CPL', 'FFL', 'FPL', 'FRL', 'IPT', 'LPL', 'MPL', 'PVL', 'RPL', 'SPL', 'TPL', 'UPL'
======================================
branchcode : 'CPL' using root@localhost
branch 'CPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 CPL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 3 borrowers with overdues
branch 'CPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'CPL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'FFL' using root@localhost
branch 'FFL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 FFL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'FFL', categorycode = PT pass 2
No letter code found for pass 2
branch 'FFL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'FPL' using root@localhost
branch 'FPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 FPL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'FPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'FPL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'FRL' using root@localhost
branch 'FRL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 FRL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'FRL', categorycode = PT pass 2
No letter code found for pass 2
branch 'FRL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'IPT' using root@localhost
branch 'IPT', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 IPT | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'IPT', categorycode = PT pass 2
No letter code found for pass 2
branch 'IPT', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'LPL' using root@localhost
branch 'LPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 LPL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'LPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'LPL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'MPL' using root@localhost
branch 'MPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 MPL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'MPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'MPL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'PVL' using root@localhost
branch 'PVL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 PVL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'PVL', categorycode = PT pass 2
No letter code found for pass 2
branch 'PVL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'RPL' using root@localhost
branch 'RPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 RPL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'RPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'RPL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'SPL' using root@localhost
branch 'SPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 SPL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'SPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'SPL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'TPL' using root@localhost
branch 'TPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 TPL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'TPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'TPL', categorycode = PT pass 3
No letter code found for pass 3
======================================
branchcode : 'UPL' using root@localhost
branch 'UPL', categorycode = PT pass 1
Using letter code 'ODUE' for pass 1
--------Borrower 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
WHERE  issues.borrowernumber=borrowers.borrowernumber
AND    borrowers.categorycode=categories.categorycode
AND    issues.itemnumber = items.itemnumber
AND    items.itemlost = 0
AND    TO_DAYS(NOW())-TO_DAYS(issues.date_due) >= 0
 AND issues.branchcode=?  AND borrowers.categorycode=?   AND categories.overduenoticerequired=1 ORDER BY issues.borrowernumber
 UPL | PT
 (1, 90, 2025-12-26T01:18:23)
--------------------------
Found 0 borrowers with overdues
branch 'UPL', categorycode = PT pass 2
No letter code found for pass 2
branch 'UPL', categorycode = PT pass 3
No letter code found for pass 3
Comment 6 Andrew Fuerste-Henry 2026-01-06 19:12:51 UTC
Created attachment 190949 [details] [review]
Bug 41315: Change only notice branchcode when OverDueNoticeFrom is set to patron-homelibrary

This patch adds a new variable $notice_branchcode and uses this when getting the patron's
homelibrary to ensure we don't change the branch we are using.

To test:
 1 - At branch A - checkout three items, 1 day overdue to 3 patrons of the same category from different branches (not A)
 2 - Set the system preference OverdueNoticeFrom to 'patron home library'
 3 - Browse to More->Tools->Overdue notice/status triggers
 4 - Set overdue triggers for default library and the category used above to:
     Delay: 1
     Letter: Overdue notice (ODUE)
 5 - From the command line run the overdue notices:
     perl misc/cronjobs/overdue_notices.pl --triggered --library CPL --test --nomail -v -v
 6 - Note that we begin pass 1 with CPL and then use a different branch for passes 2 and 3
 7 - Apply patch
 8 - Repeat
 9 - Confirm branch is consistent
10 - Run without branch param:
     perl misc/cronjobs/overdue_notices.pl --triggered --library CPL --test --nomail -v -v
11 - Confirm branches are consistent

Signed-off-by: Ben Daeuber <bdaeuber@fargolibrary.org>
Comment 7 Andrew Fuerste-Henry 2026-01-06 19:12:55 UTC
Created attachment 190950 [details] [review]
Bug 41315: Remove unecessary conditional

We are in a loop here:
foreach my $branchcode (@branches) {

branchcode must be defined or something has gone seriously wrong with PERL

Signed-off-by: Ben Daeuber <bdaeuber@fargolibrary.org>
Comment 8 Andrew Fuerste-Henry 2026-01-06 19:12:58 UTC
Created attachment 190951 [details] [review]
Bug 41315: (follow-up) Rename statements for clarity

Signed-off-by: Ben Daeuber <bdaeuber@fargolibrary.org>
Comment 9 Andrew Fuerste-Henry 2026-01-06 19:13:01 UTC
Created attachment 190952 [details] [review]
Bug 41315: Don't change which branch is used for getting the transports

See bug 41316 - the script uses the triggers of the issuing branch when sending
by patron library - we shouldn't change this here, but on the next bug

Signed-off-by: Ben Daeuber <bdaeuber@fargolibrary.org>