From 0ba56480a57cbe90d8d3eb0daffd9d30f6c0eb9e 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=utf8 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) Signed-off-by: Martin Renvoize Signed-off-by: David Nind Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- Koha/Booking.pm | 47 +++++++++++++++++++ .../prog/en/modules/tools/letter.tt | 7 +++ tools/letter.pl | 2 + 3 files changed, 56 insertions(+) diff --git a/Koha/Booking.pm b/Koha/Booking.pm index f1004ae1f7..0d0d1fc8aa 100644 --- a/Koha/Booking.pm +++ b/Koha/Booking.pm @@ -21,6 +21,11 @@ use Modern::Perl; use Koha::Exceptions::Booking; use Koha::DateUtils qw( dt_from_string ); +use Koha::Items; +use Koha::Patrons; +use Koha::Libraries; + +use C4::Letters; use base qw(Koha::Object); @@ -239,6 +244,48 @@ sub to_api_mapping { return {}; } +=head3 delete + +$booking->delete(); + +=cut + +sub delete { + my ( $self ) = @_; + + my $deleted = $self->SUPER::delete($self); + my $patron = Koha::Patrons->find( $self->patron_id ); + my $item = Koha::Items->find( $self->item_id ); + my $library = Koha::Libraries->find( $self->pickup_library_id ); + + 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 => $self->unblessed, + } + ); + + if ($letter) { + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $patron->borrowernumber, + message_transport_type => 'email', + } + ); + } + return $deleted; +} + =head2 Internal methods =head3 _type 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 603c735252..c8fea2b378 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -203,6 +203,7 @@
  • Suggestions
  • Point of sale
  • Reports
  • +
  • Bookings
  • @@ -264,6 +265,7 @@ [% CASE 'suggestions' %]Suggestions [% CASE 'pos' %]Point of sale [% CASE 'report' %]Reports + [% CASE 'bookings' %]Bookings [% CASE %][% lette.module | html %] [% END %] @@ -460,6 +462,11 @@ [% ELSE %] [% END %] + [% IF ( module == "bookings" ) %] + + [% ELSE %] + + [% END %]
  • diff --git a/tools/letter.pl b/tools/letter.pl index 20472c1810..8a9a6301db 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -267,6 +267,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.39.5