From d2edd61ca533431694130644ded7a82229379f70 Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Fri, 27 Jan 2023 21:05:38 +0000 Subject: [PATCH] Bug 32740: Add a new option patron home library to OverdueNoticeFrom This patch add 'patron home library' option to the OverdueNoticeFrom preference. When it's selected notification messages for overdues will be bundled and sent from the borrowing user's home library To Test 1. Create 3 libraries B1, B2 and B3 1.1. Go to Koha administration, click on Libraries 1.2. Click New library 1.3. Fill the Library Code (ex. B1), Name(ex. B1) and email(ex. b1@test.com) fields. 2. Create a user belonging to B1 2.1. Go to patron module, click on New patron and patron 2.2. Fill the Surname,Card number,Primary email,Card number field and select B1 as Library. 3. Create 2 notices : the first belongs to B2 and the second belong to B3 3.1. Go to Cataloging module and click on new 3.2. field the required field (000 subfield 0, 003 subfield 0, 005 subfield 0, 008 subfield 0, 040 subfield c,245 subfield a, and 942 subfield c ) 3.3. Click on save 3.4. In the item form, Select Home library = B2 and Current library = B2 and type a Barcode. 3.5. Repeat 3.1 3.2 3.3 3.4 to create a second notice belong to B3 4. Have (or create) a default notice for all branches in Notices and Slips Module 5. Make sure you connected to branch B2 or Switch to branch B2 6. checkout item I2 (belonging to B2) to the user created in step 2 (specifying as due date the day before (1 day overdue)) 7. switch to branch B3 8. checkout item I3 (belonging to B3) to the user created in step 2 (specifying as due date the day before (1 day overdue)) 9. make sure you have defined 'Overdue notice/status triggers' for that patron category, ie with Delay=1 so that 'Overdue Notice' is selected and 'Email' is checked. Note: we have a user belong to B1, two item: I2 belong to B2, I3 belong to B3 and the user has borrowed I2 from B2 and I3 from B3. 10. Test 10.1. Search for OverdueNoticeFrom in System preferences and select item home library 10.2. from cli run 'perl ./misc/cronjobs/overdue_notices.pl' => Two new entries will be generated in message_queue DB table, coming from different branches that have the SAME list of overdue items. => The sender address is the item home library address for each entry. 11. Apply the patch 12. Search for OverdueNoticeFrom in System preferences => There is now 'patron home library' in the options list 13. Select patron home library 14. from cli run 'perl ./misc/cronjobs/overdue_notices.pl' => You will see that only one message had been created. Its content shows both B2 and B3 overdue items => The sender address matches B1 address (the patron home library). 15. Search for OverdueNoticeFrom in System preferences and select cron 16. from cli run './misc/cronjobs/overdue_notices.pl --frombranch patron-homebranch' => you will get the same result at step 14 --- .../admin/preferences/circulation.pref | 1 + misc/cronjobs/overdue_notices.pl | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index e025fc6e9d..ac2eebbed9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -416,6 +416,7 @@ Circulation: cron: "command-line option" item-issuebranch: "checkout library" item-homebranch: "item home library" + patron-homebranch: "patron home library" - . - - Include up to diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index f8fc79203c..209330b1a2 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -69,7 +69,7 @@ overdue_notices.pl --date Emulate overdues run for this date. --email Type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable. - --frombranch Organize and send overdue notices by home library (item-homebranch) or checkout library (item-issuebranch). + --frombranch Organize and send overdue notices by home library (item-homebranch) or checkout library (item-issuebranch) or patron home library (patron-homebranch). This option is only used, if the OverdueNoticeFrom system preference is set to 'command-line option'. Defaults to item-issuebranch. @@ -184,7 +184,7 @@ Allows to specify which type of email will be used. Can be email, emailpro or B_ =item B<--frombranch> -Organize overdue notices either by checkout library (item-issuebranch) or item home library (item-homebranch). +Organize overdue notices either by checkout library (item-issuebranch) or item home library (item-homebranch) or patron home library (patron-homebranch). This option is only used, if the OverdueNoticeFrom system preference is set to use 'command-line option'. Defaults to checkout library (item-issuebranch). @@ -341,11 +341,12 @@ if ( defined $csvfilename && $csvfilename =~ /^-/ ) { warn qq(using "$csvfilename" as filename, that seems odd); } -die "--frombranch takes item-homebranch or item-issuebranch only" +die "--frombranch takes item-homebranch or item-issuebranch or patron-homebranch only" unless ( $frombranch eq 'item-issuebranch' - || $frombranch eq 'item-homebranch' ); + || $frombranch eq 'item-homebranch' || $frombranch eq 'patron-homebranch'); $frombranch = C4::Context->preference('OverdueNoticeFrom') ne 'cron' ? C4::Context->preference('OverdueNoticeFrom') : $frombranch; my $owning_library = ( $frombranch eq 'item-homebranch' ) ? 1 : 0; +my $patron_homelibrary = ( $frombranch eq 'patron-homebranch' ) ? 1 : 0; my @overduebranches = C4::Overdues::GetBranchcodesWithOverdueRules(); # Branches with overdue rules my @branches; # Branches passed as parameter with overdue rules @@ -457,6 +458,8 @@ elsif ( defined $text_filename ) { } } +my %already_queued; +my %seen = map { $_ => 1 } @branches; foreach my $branchcode (@branches) { my $calendar; if ( C4::Context->preference('OverdueNoticeCalendar') ) { @@ -488,9 +491,9 @@ SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, branchname END_SQL if($owning_library) { - $sql2 .= ' AND items.homebranch = ? '; + $sql2 .= ' AND items.homebranch = ? ' unless($patron_homelibrary); } else { - $sql2 .= ' AND issues.branchcode = ? '; + $sql2 .= ' AND issues.branchcode = ? ' unless($patron_homelibrary); } my $sth2 = $dbh->prepare($sql2); @@ -606,6 +609,7 @@ END_SQL next; } $borrowernumber = $data->{'borrowernumber'}; + next if ($patron_homelibrary && $already_queued{"$borrowernumber$i"}); my $borr = sprintf( "%s%s%s (%s)", $data->{'surname'} || '', $data->{'firstname'} && $data->{'surname'} ? ', ' : '', @@ -614,6 +618,13 @@ END_SQL $verbose and warn "borrower $borr has items triggering level $i.\n"; my $patron = Koha::Patrons->find( $borrowernumber ); + if($patron_homelibrary){ + $branchcode = $patron->branchcode; + $library = Koha::Libraries->find($branchcode); + $admin_email_address = $library->from_email_address; + $branch_email_address = C4::Context->preference('AddressForFailedOverdueNotices') + || $library->inbound_email_address; + } @emails_to_use = (); my $notice_email = $patron->notice_email_address; unless ($nomail) { @@ -656,7 +667,7 @@ END_SQL ) unless $test_mode; $verbose and warn "debarring $borr\n"; } - my @params = ($borrowernumber,$branchcode); + my @params = $patron_homelibrary ? ($borrowernumber) : ($borrowernumber, $branchcode); $sth2->execute(@params); my $itemcount = 0; @@ -701,6 +712,7 @@ END_SQL $exceededPrintNoticesMaxLines = 1; last; } + next if $patron_homelibrary and ! grep {$seen{$item_info->{branchcode}}} @branches; $j++; $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields, dateonly => 1 } ); @@ -824,6 +836,7 @@ END_SQL } } } + $already_queued{"$borrowernumber$i"} = 1; } $sth->finish; } -- 2.34.1