From bd63f3b72cb01004bd64161c99bdd062946fada3 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 | 6 ++++ .../prog/en/modules/admin/categories.tt | 6 ++++ .../admin/preferences/circulation.pref | 15 ++++++++++ misc/cronjobs/overdue_notices.pl | 28 +++++++++++++++---- 6 files changed, 68 insertions(+), 5 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..202c211d2e3 --- /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 45baff7c915..9c3ee48916e 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -872,6 +872,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 cc56c1810c6..b5c47fa2036 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 @@ -57,6 +57,12 @@ 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 e91ba21feb3..370b59ec03e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -761,6 +761,12 @@ Hold reminder [% ELSIF ( prefs.Patron_Expiry ) %] Patron account expiry + [% ELSIF ( prefs.Overdue1 ) %] + Overdue 1 + [% ELSIF ( prefs.Overdue2 ) %] + Overdue 2 + [% ELSIF ( prefs.Overdue3 ) %] + Overdue 3 [% ELSE %] Unknown [% END %]: 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 39978263968..149e8b22911 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 f0ca534e5d6..b8acfec875d 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; @@ -746,11 +748,27 @@ END_SQL } $sth2->finish; - my @message_transport_types = - @{ GetOverdueMessageTransportTypes( $branchcode, $overdue_rules->{categorycode}, $i ) }; - @message_transport_types = - @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i ) } - unless @message_transport_types; + 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 { + my @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.34.1