Bug 31028: Add acknowledgement notice
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 25 Oct 2022 12:50:58 +0000 (13:50 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 6 Mar 2023 14:23:17 +0000 (11:23 -0300)
This patch adds an acknowledgement notice that will be sent to the opac
user upon submission of a catalog concern report.

Test plan
1) Confirm that a new notice template is added to the notices management
   page.
2) If using a sandbox, check the 'email log' from the management UI to
   see the resultant notice has been 'sent'

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Helen Oliver <HOliver@tavi-port.ac.uk>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Letters.pm
Koha/Ticket.pm
installer/data/mysql/atomicupdate/bug_31028.pl
installer/data/mysql/en/mandatory/sample_notices.yml

index 3a58c7e..39818f4 100644 (file)
@@ -738,6 +738,7 @@ sub _parseletter_sth {
     ($table eq 'accountlines' )    ? "SELECT * FROM $table WHERE   accountlines_id = ?"                               :
     ($table eq 'biblio'       )    ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
     ($table eq 'biblioitems'  )    ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
+    ($table eq 'tickets'      )    ? "SELECT * FROM $table WHERE   id = ?"                                            :
     ($table eq 'credits'      )    ? "SELECT * FROM accountlines WHERE   accountlines_id = ?"                         :
     ($table eq 'debits'       )    ? "SELECT * FROM accountlines WHERE   accountlines_id = ?"                         :
     ($table eq 'items'        )    ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
@@ -1619,7 +1620,7 @@ sub _process_tt {
     my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects };
 
     $content = add_tt_filters( $content );
-    $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|;
+    $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %][% PROCESS 'html_helpers.inc' %]$content|;
 
     my $output;
     my $schema = Koha::Database->new->schema;
@@ -1738,6 +1739,12 @@ sub _get_tt_params {
             plural   => 'suggestions',
             pk       => 'suggestionid',
         },
+        tickets => {
+            module   => 'Koha::Tickets',
+            singular => 'ticket',
+            plural   => 'tickets',
+            pk       => 'id',
+        },
         issues => {
             module   => 'Koha::Checkouts',
             singular => 'checkout',
index 55d177d..711bcd9 100644 (file)
@@ -19,6 +19,8 @@ use Modern::Perl;
 
 use base qw(Koha::Object);
 
+use C4::Letters;
+
 use Koha::Ticket::Update;
 use Koha::Ticket::Updates;
 
@@ -97,6 +99,46 @@ sub add_update {
     return Koha::Ticket::Update->_new_from_dbic($rs);
 }
 
+=head2 Core methods
+
+=head3 store
+
+Overloaded I<store> method to trigger notices as required
+
+=cut
+
+sub store {
+    my ($self) = @_;
+
+    my $is_new = !$self->in_storage;
+    $self = $self->SUPER::store;
+
+    if ($is_new) {
+
+        # Send patron acknowledgement
+        my $acknowledgement_letter = C4::Letters::GetPreparedLetter(
+            module      => 'catalog',
+            letter_code => 'TICKET_ACKNOWLEDGEMENT',
+            branchcode  => $self->reporter->branchcode,
+            tables      => { tickets => $self->id }
+        );
+
+        if ($acknowledgement_letter) {
+            my $acknowledgement_message_id = C4::Letters::EnqueueLetter(
+                {
+                    letter                 => $acknowledgement_letter,
+                    message_transport_type => 'email',
+                    borrowernumber         => $self->reporter_id,
+                }
+            );
+            C4::Letters::SendQueuedMessages(
+                { message_id => $acknowledgement_message_id } );
+        }
+    }
+
+    return $self;
+}
+
 =head2 Internal methods
 
 =cut
index 459eaeb..683c920 100644 (file)
@@ -85,5 +85,13 @@ return {
             );
             say $out "`CatalogConcernTemplate` block added to html_customization";
         }
+
+        $dbh->do(
+            q{
+                INSERT IGNORE INTO letter(module,code,branchcode,name,is_html,title,content,message_transport_type)
+                VALUES ( 'catalog', 'TICKET_ACKNOWLEDGEMENT', '', 'Concern acknowledgement', '1', 'Catalog concern acknowledgement', "Dear [% INCLUDE 'patron-title.inc' patron => ticket.reporter %],\r\n\r\nThankyou for your report concerning [% INCLUDE 'biblio-title.inc' biblio=ticket.biblio link = 0 %].\r\n\r\nYou reported: \r\n[% ticket.body %]\r\n\r\nThankyou", 'email' );
+            }
+        );
+        say $out "Added new notice 'TICKET_ACKNOWLEDGEMENT'";
     }
 }
index 230338b..f5478f9 100644 (file)
@@ -43,6 +43,24 @@ tables:
             - ""
             - "Your library."
 
+        - module: catalog
+          code: TICKET_ACKNOWLEDGEMENT
+          branchcode: ""
+          name: "Concern acknowledgement"
+          is_html: 1
+          title: "Catalog concern acknowledgment"
+          message_transport_type: email
+          lang: default
+          content:
+            - "Dear [% INCLUDE 'patron-title.inc' patron => ticket.reporter %],"
+            - ""
+            - "Thankyou for your report concerning [% INCLUDE 'biblio-title.inc' biblio=ticket.biblio link = 0 %]."
+            - ""
+            - "You reported: "
+            - "[% ticket.body %]"
+            - ""
+            - "Thankyou"
+
         - module: circulation
           code: ACCOUNT_CREDIT
           branchcode: ""