From f8caa5eaccc7ac299ab29bf700d12e7c86557613 Mon Sep 17 00:00:00 2001 From: Stefan Berndtsson Date: Wed, 27 Sep 2017 14:30:49 +0200 Subject: [PATCH] Bug 30515: Move Overdue transports to patron messaging preferences Add syspref for using patron specific message preferences for overdue messages instead of patron category level preferences. To test: 1) Set UsePatronPreferencesForOverdueNotices to "individual patron preference" 2) Enable some transport for a patron in the messaging preferences form 2) Check out an item and set a due date that will result in an overdue notice 4) Run the overdue_notices.pl script 5) Verify that messages has been sent for the selected transport(s) 6) Run gather_print_notices.pl and verify a print notice is generated 7) Set UsePatronPreferencesForOverdueNotices to "when no other transport set" 8) Run the overdue_notices.pl and gather_print_notices.pl and verify that no print notice is generated 9) Disable all transports for the patron 10) Run the overdue_notices.pl and gather_print_notices.pl and verify that print notice is generated 11) Set UsePatronPreferencesForOverdueNotices to "never" 12) Run the overdue_notices.pl and gather_print_notices.pl and verify that no print notice is generated 13) Enable some transport(s) for the patron 14) Run the overdue_notices.pl and gather_print_notices.pl and verify that no print notice is generated 15) Set UsePatronPreferencesForOverdueNotices to "patron category" 16) Run the overdue_notices.pl and gather_print_notices.pl and verify the patron category and library setting is used Sponsored-by: Gothenburg University Library --- .../bug_30515-add_system_preferences.pl | 16 +++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 2 ++ .../en/includes/messaging-preference-form.inc | 3 +++ .../prog/en/modules/admin/categories.tt | 3 +++ .../admin/preferences/circulation.pref | 15 ++++++++++++ misc/cronjobs/overdue_notices.pl | 24 +++++++++++++++---- 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_30515-add_system_preferences.pl diff --git a/installer/data/mysql/atomicupdate/bug_30515-add_system_preferences.pl b/installer/data/mysql/atomicupdate/bug_30515-add_system_preferences.pl new file mode 100644 index 00000000000..f72a624e980 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_30515-add_system_preferences.pl @@ -0,0 +1,16 @@ +use Modern::Perl; + +return { + bug_number => "30515", + description => "Add system preferences for patron specific overdue notice preferences", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + $dbh->do(q{INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('UsePatronPreferencesForOverdueNotices', '0', NULL, 'Use patron specific messaging preferences for overdue notices if available', 'YesNo')}); + say $out "UsePatronPreferencesForOverdueNotices system preference added"; + + $dbh->do(q{INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('UsePatronPreferencesForOverdueNoticesPrint', 'always', 'always|fallback|never', 'When to send print notices when using patron specific messaging preferences for overdue notices', 'Choice')}); + say $out "UsePatronPreferencesForOverdueNoticesPrint system preference added"; + }, +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 336f05bd294..35a97e5e1e3 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -854,6 +854,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('UseICUStyleQuotes','0','1','Tell Koha whether to use ICU style quotes ({) or default (") when tracing subjects .','YesNo'), ('UseLocationAsAQInSIP', '0', '', 'Use permanent_location instead of homebranch for AQ in SIP response', 'YesNo'), ('UseOCLCEncodingLevels','0',NULL,'If enabled, include OCLC encoding levels in leader value builder dropdown for position 17.','YesNo'), +('UsePatronPreferencesForOverdueNotices', '0', NULL, 'Use patron specific messaging preferences for overdue notices if available', 'YesNo'), +('UsePatronPreferencesForOverdueNoticesPrint', 'always', 'always|fallback|never', 'When to send print notices when using patron specific messaging preferences for overdue notices', 'Choice'), ('UseRecalls','0',NULL,'Enable or disable recalls','YesNo'), ('UseTransportCostMatrix','0','','Use Transport Cost Matrix when filling holds','YesNo'), ('UseWYSIWYGinSystemPreferences','0','','Show WYSIWYG editor when editing certain HTML system preferences.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc index ecf35310f3f..4e83003f203 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc @@ -37,6 +37,9 @@ [% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewal [% ELSIF ( messaging_preference.Recall_Waiting ) %]Recall awaiting pickup [% ELSIF ( messaging_preference.Recall_Requested ) %]Return recalled item + [% ELSIF ( messaging_preference.Overdue1 ) %]Overdue 1 + [% ELSIF ( messaging_preference.Overdue2 ) %]Overdue 2 + [% ELSIF ( messaging_preference.Overdue3 ) %]Overdue 3 [% ELSE %]Unknown [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt index 8fce83403a2..b8531c939b3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -719,6 +719,9 @@ [% ELSIF ( prefs.Ill_update ) %]Interlibrary loan updated [% ELSIF ( prefs.Auto_Renewals ) %]Auto renewal [% ELSIF ( prefs.Hold_Reminder ) %]Hold reminder + [% ELSIF ( prefs.Overdue1 ) %]Overdue 1 + [% ELSIF ( prefs.Overdue2 ) %]Overdue 2 + [% ELSIF ( prefs.Overdue3 ) %]Overdue 3 [% ELSE %]Unknown [% END %]: [% transport.transport | html %]
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 65cf0b5030f..765c0e2037b 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 @@ -641,6 +641,21 @@ Circulation: source: LOST - "when the outstanding balance is written off." Checkin policy: + - + - Use message preferences based on + - pref: UsePatronPreferencesForOverdueNotices + choices: + 1: individual patron preference + 0: patron category + - when sending overdue notices. + - + - When using individual patron preferences for overdue notices + - pref: UsePatronPreferencesForOverdueNoticesPrint + choices: + always: always + fallback: when no other transport set + never: never + - print notice. - - pref: TrapHoldsOnOrder choices: diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 3a70377e2dc..4977450d7d5 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -25,12 +25,14 @@ use Pod::Usage qw( pod2usage ); use Text::CSV_XS; use DateTime; use DateTime::Duration; +use List::MoreUtils qw( uniq ); use Koha::Script -cron; use C4::Context; use C4::Letters; use C4::Overdues qw( GetOverdueMessageTransportTypes parse_overdues_letter ); use C4::Log qw( cronlogaction ); +use C4::Members::Messaging qw( GetMessagingPreferences ); use Koha::Patron::Debarments qw( AddUniqueDebarment ); use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Calendar; @@ -711,11 +713,25 @@ END_SQL push @items, $item_info; } $sth2->finish; - - my @message_transport_types = @{ GetOverdueMessageTransportTypes( $branchcode, $overdue_rules->{categorycode}, $i) }; - @message_transport_types = @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i) } + my @message_transport_types; + if (C4::Context->preference('UsePatronPreferencesForOverdueNotices')) { + my $patronpref = GetMessagingPreferences( + { borrowernumber => $borrowernumber, message_name => "Overdue$i"}); + if ($patronpref && $patronpref->{'transports'}) { + @message_transport_types = keys %{$patronpref->{'transports'}}; + } + my $print_behavior = C4::Context->preference('UsePatronPreferencesForOverdueNoticesPrint'); + if ( + $print_behavior eq 'always' || + $print_behavior eq 'fallback' && !@message_transport_types + ) { + unshift(@message_transport_types, 'shift'); + } + } else { + @message_transport_types = @{ GetOverdueMessageTransportTypes( $branchcode, $overdue_rules->{categorycode}, $i) }; + @message_transport_types = @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i) } unless @message_transport_types; - + } my $print_sent = 0; # A print notice is not yet sent for this patron for my $mtt ( @message_transport_types ) { -- 2.48.1