From 0e31a3134657d465f5e3f4ca08f21ffd710fe9e7 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 12 May 2020 22:07:56 +0000 Subject: [PATCH] Bug 23781: SMS notices and messaging preferences for recalls This patch adds recalls notices (pick up a waiting recall or return a requested recall) to the messaging preferences. To test: 1) Apply Bug 19532 2) Apply this bug 3) Update database, rebuild dbix files 4) Ensure UseRecalls syspref is enabled and values have been set in the circulation rules for recalls 5) Go to a borrower (Person A) account page in the Intranet or the OPAC 6) Go to messaging preferences 7) Notice there are now preferences for two recalls notices 8) Select email as a preference 9) Find a different borrower (Person B) and set their messaging preferences to SMS 10) Check out any item to Person B 11) Go to the OPAC logged in as Person A and find that item 12) Recall the item 13) In the terminal, look at the message_queue in the database. There should be a 'RETURN_RECALLED_ITEM' recall notice sent to Person B via SMS 14) Go back to the Intranet and check in the item. Confirm the recall when checking in 15) Look at the message_queue in the database again. There should be a 'PICKUP_RECALLED_ITEM' recall notice sent to Person A via email. 16) Confirm tests pass t/db_dependent/Koha/Recall.t t/db_dependent/Koha/Recalls.t Sponsored-by: Toi Ohomai Institute of Technology --- Koha/Recall.pm | 10 ++++++- Koha/Recalls.pm | 11 ++++++- .../bug_23781-recalls_message_attributes.pl | 12 ++++++++ .../bug_23781-recalls_message_transports.pl | 12 ++++++++ .../atomicupdate/bug_23781-recalls_sms_notices.pl | 24 +++++++++++++++ .../data/mysql/en/mandatory/sample_notices.yml | 34 ++++++++++++++++++++++ .../mysql/fr-FR/1-Obligatoire/sample_notices.sql | 16 +++++++++- .../sample_notices_message_attributes.sql | 5 ++-- .../sample_notices_message_transports.sql | 6 +++- .../prog/en/includes/messaging-preference-form.inc | 2 ++ .../bootstrap/en/modules/opac-messaging.tt | 2 ++ t/db_dependent/Koha/Recall.t | 6 ++++ t/db_dependent/Koha/Recalls.t | 8 ++++- 13 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_23781-recalls_message_attributes.pl create mode 100644 installer/data/mysql/atomicupdate/bug_23781-recalls_message_transports.pl create mode 100644 installer/data/mysql/atomicupdate/bug_23781-recalls_sms_notices.pl diff --git a/Koha/Recall.pm b/Koha/Recall.pm index c39e9b946a..dfdd1b174e 100644 --- a/Koha/Recall.pm +++ b/Koha/Recall.pm @@ -358,7 +358,15 @@ sub set_waiting { }, ); - C4::Message->enqueue($letter, $self->patron->unblessed, 'email'); + my $messaging_preferences = C4::Members::Messaging::GetMessagingPreferences({ borrowernumber => $self->borrowernumber, message_name => 'Recall_Waiting' }); + while ( my ( $transport, $letter_code ) = each %{ $messaging_preferences->{transports} } ) { + if ( $transport eq 'email' ){ + C4::Message->enqueue($letter, $self->patron->unblessed, 'email'); + } + if ( $transport eq 'sms' ){ + C4::Message->enqueue($letter, $self->patron->unblessed, 'sms'); + } + } return $self; } diff --git a/Koha/Recalls.pm b/Koha/Recalls.pm index e7e360c2ec..6930cb3ea6 100644 --- a/Koha/Recalls.pm +++ b/Koha/Recalls.pm @@ -160,7 +160,16 @@ sub add_recall { }, ); - C4::Message->enqueue( $letter, $checkout->patron->unblessed, 'email' ); + my $messaging_preferences = C4::Members::Messaging::GetMessagingPreferences({ borrowernumber => $checkout->borrowernumber, message_name => 'Recall_Requested' }); + + while ( my ( $transport, $letter_code ) = each %{ $messaging_preferences->{transports} } ) { + if ( $transport eq 'email' ){ + C4::Message->enqueue($letter, $checkout->patron->unblessed, 'email'); + } + if ( $transport eq 'sms' ){ + C4::Message->enqueue($letter, $checkout->patron->unblessed, 'sms'); + } + } $item = Koha::Items->find( $itemnumber ); # add to statistics table diff --git a/installer/data/mysql/atomicupdate/bug_23781-recalls_message_attributes.pl b/installer/data/mysql/atomicupdate/bug_23781-recalls_message_attributes.pl new file mode 100644 index 0000000000..54d0d45af6 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_23781-recalls_message_attributes.pl @@ -0,0 +1,12 @@ +use Modern::Perl; + +return { + bug_number => "23781", + description => "Adding message attributes for recalls: Recall_Waiting, Recall_Requested", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + $dbh->do(q{ INSERT IGNORE INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (11, 'Recall_Waiting', 0), (12, 'Recall_Requested', 0) }); + }, +}; diff --git a/installer/data/mysql/atomicupdate/bug_23781-recalls_message_transports.pl b/installer/data/mysql/atomicupdate/bug_23781-recalls_message_transports.pl new file mode 100644 index 0000000000..7d9d214f85 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_23781-recalls_message_transports.pl @@ -0,0 +1,12 @@ +use Modern::Perl; + +return { + bug_number => "23781", + description => "Adding message transports for recalls notices", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + $dbh->do(q{ INSERT IGNORE INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code, branchcode) VALUES (11, "email", 0, "circulation", "PICKUP_RECALLED_ITEM", null), (11, "sms", 0, "circulation", "PICKUP_RECALLED_ITEM", null), (12, "email", 0, "circulation", "RETURN_RECALLED_ITEM", null), (12, "sms", 0, "circulation", "RETURN_RECALLED_ITEM", null) }); + }, +}; diff --git a/installer/data/mysql/atomicupdate/bug_23781-recalls_sms_notices.pl b/installer/data/mysql/atomicupdate/bug_23781-recalls_sms_notices.pl new file mode 100644 index 0000000000..61aa730ee9 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_23781-recalls_sms_notices.pl @@ -0,0 +1,24 @@ +use Modern::Perl; + +return { + bug_number => "23781", + description => "Add recalls SMS notices: RETURN_RECALLED_ITEM, PICKUP_RECALLED_ITEM", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + $dbh->do(q{ INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`) VALUES ('circulation','RETURN_RECALLED_ITEM','','Notification to return a recalled item','0','Notification to return a recalled item','Date: <> + +<> <>, + +A recall has been placed on the following item: <> / <> (<>). The due date has been updated, and is now <>. Please return the item before the due date. + +Thank you!','sms'), ('circulation','PICKUP_RECALLED_ITEM','','Recalled item awaiting pickup','0','Recalled item awaiting pickup','Date: <> + +<> <>, + +A recall that you requested on the following item: <> / <> (<>) is now ready for you to pick up at <>. Please pick up your item by <>. + +Thank you!','sms') }); + }, +}; diff --git a/installer/data/mysql/en/mandatory/sample_notices.yml b/installer/data/mysql/en/mandatory/sample_notices.yml index 0af93cd37b..06dedbb4df 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.yml +++ b/installer/data/mysql/en/mandatory/sample_notices.yml @@ -1635,3 +1635,37 @@ tables: - "Callnumber: <>" - "Waiting since: <>" - "Notes: <>" + + - module: circulation + code: RETURN_RECALLED_ITEM + branchcode: "" + name: "Notification to return a recalled item" + is_html: 0 + title: "Notification to return a recalled item" + message_transport_type: sms + lang: default + content: + - "Date: <>" + - "" + - "<> <>," + - "" + - "A recall has been placed on the following item: <> / <> (<>). The due date has been updated, and is now <>. Please return the item before the due date." + - "" + - "Thank you!" + + - module: circulation + code: PICKUP_RECALLED_ITEM + branchcode: "" + name: "Recalled item awaiting pickup" + is_html: 0 + title: "Recalled item awaiting pickup" + message_transport_type: sms + lang: default + content: + - "Date: <>" + - "" + - "<> <>," + - "" + - "A recall that you requested on the following item: <> / <> (<>) is now ready for you to pick up at <>. Please pick up your item by <>." + - "" + - "Thank you!" diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql index e5686f3559..cf1f4a940b 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql @@ -245,7 +245,21 @@ ITEM RECALLED Barcode: <> Callnumber: <> Waiting since: <> -Notes: <>', 'print'); +Notes: <>', 'print'), +('circulation','RETURN_RECALLED_ITEM','','Notification to return a recalled item','0','Notification to return a recalled item','Date: <> + +<> <>, + +A recall has been placed on the following item: <> / <> (<>). The due date has been updated, and is now <>. Please return the item before the due date. + +Thank you!','sms'), +('circulation','PICKUP_RECALLED_ITEM','','Recalled item awaiting pickup','0','Recalled item awaiting pickup','Date: <> + +<> <>, + +A recall that you requested on the following item: <> / <> (<>) is now ready for you to pick up at <>. Please pick up your item by <>. + +Thank you!','sms'); INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES ('circulation', 'ACCOUNT_PAYMENT', '', 'Account payment', 0, 'Account payment', '[%- USE Price -%]\r\nA payment of [% credit.amount * -1 | $Price %] has been applied to your account.\r\n\r\nThis payment affected the following fees:\r\n[%- FOREACH o IN offsets %]\r\nDescription: [% o.debit.description %]\r\nAmount paid: [% o.amount * -1 | $Price %]\r\nAmount remaining: [% o.debit.amountoutstanding | $Price %]\r\n[% END %]', 'email', 'default'), diff --git a/installer/data/mysql/mandatory/sample_notices_message_attributes.sql b/installer/data/mysql/mandatory/sample_notices_message_attributes.sql index 6cabc4e92e..4c84f556b1 100644 --- a/installer/data/mysql/mandatory/sample_notices_message_attributes.sql +++ b/installer/data/mysql/mandatory/sample_notices_message_attributes.sql @@ -9,5 +9,6 @@ values (7, 'Ill_ready', 0), (8, 'Ill_unavailable', 0), (9, 'Auto_Renewals', 0), -(10, 'Hold_Reminder', 0); - +(10, 'Hold_Reminder', 0), +(11, 'Recall_Waiting', 0), +(12, 'Recall_Requested', 0); diff --git a/installer/data/mysql/mandatory/sample_notices_message_transports.sql b/installer/data/mysql/mandatory/sample_notices_message_transports.sql index 2a224996c7..29e4c06eed 100644 --- a/installer/data/mysql/mandatory/sample_notices_message_transports.sql +++ b/installer/data/mysql/mandatory/sample_notices_message_transports.sql @@ -38,4 +38,8 @@ values (10, 'email', 0, 'circulation', 'HOLD_REMINDER'), (10, 'sms', 0, 'circulation', 'HOLD_REMINDER'), (10, 'phone', 0, 'circulation', 'HOLD_REMINDER'), -(10, 'itiva', 0, 'circulation', 'HOLD_REMINDER'); +(10, 'itiva', 0, 'circulation', 'HOLD_REMINDER'), +(11, "email", 0, "circulation", "PICKUP_RECALLED_ITEM"), +(11, "sms", 0, "circulation", "PICKUP_RECALLED_ITEM"), +(12, "email", 0, "circulation", "RETURN_RECALLED_ITEM"), +(12, "sms", 0, "circulation", "RETURN_RECALLED_ITEM"); 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 de6729cc62..67795a56f2 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 @@ -30,6 +30,8 @@ [% ELSIF ( messaging_preference.Ill_ready ) %]Interlibrary loan ready [% ELSIF ( messaging_preference.Ill_unavailable ) %]Interlibrary loan unavailable [% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewal + [% ELSIF ( messaging_preference.Recall_Waiting ) %]Recall awaiting pickup + [% ELSIF ( messaging_preference.Recall_Requested ) %]Return recalled item [% ELSE %]Unknown [% END %] [% IF ( messaging_preference.takes_days ) %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt index c99ff825e0..59afa39137 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt @@ -76,6 +76,8 @@ [% ELSIF ( messaging_preference.Ill_ready ) %]Interlibrary loan ready [% ELSIF ( messaging_preference.Ill_unavailable ) %]Interlibrary loan unavailable [% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewal + [% ELSIF ( messaging_preference.Recall_Waiting ) %]Recall awaiting pickup + [% ELSIF ( messaging_preference.Recall_Requested ) %]Return recalled item [% ELSE %]Unknown [% END %] [% IF ( messaging_preference.takes_days ) %]