From 70d9ec4e7e4fc69fe50db7b0991969671fe6370b Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Wed, 22 May 2024 09:59:51 +0200 Subject: [PATCH] Bug 36915: Send email notification when a booking is cancelled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a booking is cancelled, patron received an email based on specific letter. Test plan: 1) Create a letter with code "BOOKING_CANCELLATION" on "Notices and slips" tool. 2) Add booking or go on item already booked in advance. 3) Cancel it 4) Verify in message_queue table directly or go on patron page and click on "Notices" tab section. Sponsored by: Association de Gestion des Ĺ’uvres Sociales d'Inria (AGOS) --- Koha/REST/V1/Bookings.pm | 35 +++++++++++++++++++ .../prog/en/modules/tools/letter.tt | 7 ++++ tools/letter.pl | 2 ++ 3 files changed, 44 insertions(+) diff --git a/Koha/REST/V1/Bookings.pm b/Koha/REST/V1/Bookings.pm index 44e381ef1b9..5ddd9816f84 100644 --- a/Koha/REST/V1/Bookings.pm +++ b/Koha/REST/V1/Bookings.pm @@ -20,6 +20,11 @@ use Modern::Perl; use Mojo::Base 'Mojolicious::Controller'; use Koha::Bookings; +use Koha::Items; +use Koha::Patrons; +use Koha::Libraries; + +use C4::Letters; use Try::Tiny qw( catch try ); @@ -134,12 +139,42 @@ sub delete { my $c = shift->openapi->valid_input or return; my $booking = Koha::Bookings->find( $c->param('booking_id') ); + my $patron = Koha::Patrons->find( $booking->patron_id ); + my $item = Koha::Items->find( $booking->item_id ); + my $library = Koha::Libraries->find( $booking->pickup_library_id ); + return $c->render_resource_not_found("Booking") unless $booking; return try { $booking->delete; + my $letter = C4::Letters::GetPreparedLetter( + module => 'bookings', + letter_code => 'BOOKING_CANCELLATION', + message_transport_type => 'email', + branchcode => $patron->branchcode, + lang => $patron->lang, + tables => { + branches => $library->branchcode, + borrowers => $patron->borrowernumber, + items => $item->itemnumber, + biblio => $item->biblionumber, + biblioitems => $item->biblionumber, + bookings => $booking->unblessed, + } + ); + + if ($letter) { + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $patron->borrowernumber, + message_transport_type => 'email', + } + ); + } + return $c->render_resource_deleted; } catch { $c->unhandled_exception($_); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt index 22379532e50..eb6e0a3e9d2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -182,6 +182,7 @@
  • Suggestions
  • Point of sale
  • Reports
  • +
  • Bookings
  • @@ -243,6 +244,7 @@ [% CASE 'suggestions' %]Suggestions [% CASE 'pos' %]Point of sale [% CASE 'report' %]Reports + [% CASE 'bookings' %]Bookings [% CASE %][% lette.module | html %] [% END %] @@ -441,6 +443,11 @@ [% ELSE %] [% END %] + [% IF ( module == "bookings" ) %] + + [% ELSE %] + + [% END %]
  • diff --git a/tools/letter.pl b/tools/letter.pl index 9e9b9e386fa..c3ed7e432fd 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -254,6 +254,8 @@ sub add_form { add_fields( 'branches', 'biblio', 'biblioitems', 'borrowers', 'subscription', 'serial' ); } elsif ( $module eq 'suggestions' ) { push @{$field_selection}, add_fields( 'suggestions', 'borrowers', 'biblio' ); + } elsif ( $module eq 'bookings' ) { + push @{$field_selection}, add_fields( 'borrowers', 'bookings', 'biblio', 'biblioitems', 'items' ); } else { push @{$field_selection}, add_fields( 'biblio', 'biblioitems' ), add_fields('items'), -- 2.30.2