From d7522a27c508981f405b003884ee36bf0741db8b Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Mon, 6 May 2024 12:50:01 +0200 Subject: [PATCH] Bug 36789: Transform a booking into checkout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Directly from the bookings list, you can perform a checkout with booked item. Test plan: 1) Got an item booked :) 2) Click on transform to checkout 3) Normally you will be redirected to circulation.pl checkout view with form infos from booking. 4) If issue is confirmed, the booking will be deleted. Sponsored by: Association de Gestion des Ĺ’uvres Sociales d'Inria (AGOS) --- Koha/Booking.pm | 33 ++++++++++--------- bookings/list.pl | 10 ++++-- circ/circulation.pl | 7 ++++ .../prog/en/modules/bookings/list.tt | 2 ++ .../prog/en/modules/circ/circulation.tt | 5 ++- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Koha/Booking.pm b/Koha/Booking.pm index 85b8616898f..c2170f8e54f 100644 --- a/Koha/Booking.pm +++ b/Koha/Booking.pm @@ -336,28 +336,29 @@ $booking->delete(); =cut sub delete { - my ( $self ) = @_; + my ( $self, $params ) = @_; 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 ); + if ( not defined( $params->{'transform_to_checkout'} ) ) { 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, - } - ); + 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( @@ -368,6 +369,8 @@ sub delete { } ); } + } + return $deleted; } diff --git a/bookings/list.pl b/bookings/list.pl index 6333287e041..dcf12bbcfb7 100755 --- a/bookings/list.pl +++ b/bookings/list.pl @@ -21,8 +21,14 @@ use Modern::Perl; use CGI qw ( -utf8 ); +use Koha::Biblios; +use Koha::Bookings; +use Koha::Patrons; +use Koha::Items; +use Koha::CirculationRules; + use C4::Output qw( output_html_with_http_headers ); -use C4::Auth qw( get_template_and_user ); +use C4::Auth qw( get_template_and_user ); my $input = CGI->new; my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user( @@ -35,7 +41,7 @@ my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user( ); my $biblionumber = $input->param('biblionumber'); -my $biblio = Koha::Biblios->find($biblionumber); +my $biblio = Koha::Biblios->find( { biblionumber => $biblionumber } ); $template->param( biblionumber => $biblionumber, diff --git a/circ/circulation.pl b/circ/circulation.pl index d1c2b3b0cfb..c2ef6e56a2a 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -56,6 +56,7 @@ use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::Patron::Modifications; use Koha::Token; +use Koha::Bookings; use List::MoreUtils qw( uniq ); @@ -321,11 +322,13 @@ if ($patron) { # if (@$barcodes && $op eq 'cud-checkout') { my $checkout_infos; + my $from_booking = $query->param('booking_id') ? '1' : '0'; for my $barcode ( @$barcodes ) { my $template_params = { barcode => $barcode, onsite_checkout => $onsite_checkout, + from_booking => $from_booking, }; # always check for blockers on issuing @@ -553,6 +556,10 @@ if (@$barcodes && $op eq 'cud-checkout') { confirmation_needed => $confirmation_needed, ); } + if($from_booking){ + my $booking = Koha::Bookings->find( $query->param('booking_id') ); + $booking->delete( { 'transform_to_checkout' => 1 } ); + } } ################################################################################## diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt index 47740506f89..287c4fce056 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt @@ -73,6 +73,7 @@ var update_success = 0; var bookings_table; var timeline; + var bookings_period_length = "[% bookings_period_length | html %]"; $(document).ready(function(){ var items = $.ajax({ @@ -276,6 +277,7 @@ [% IF CAN_user_circulate_manage_bookings %] result += ''; result += ''; + result += `
`; [% END %] return result; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index d6ebd2a0cfb..cf4611939d4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -1049,7 +1049,10 @@ if ( $("#onsite_checkout").prop('checked') ) { duedatespec_fp.setDate("[% today_due_date_and_time | $KohaDates dateformat => 'iso', with_hours => 1 %]"); } else { - duedatespec_fp.setDate(""); + var from_booking = [% from_booking | html %]; + if (!from_booking) { + duedatespec_fp.setDate(""); + } } } } -- 2.30.2