From 955738ed2413278e8991e09ebb3bd60df162a731 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) Signed-off-by: David Nind --- C4/Circulation.pm | 6 ++++++ Koha/Booking.pm | 4 +++- bookings/list.pl | 10 ++++++++-- circ/circulation.pl | 5 ++++- .../intranet-tmpl/prog/en/modules/bookings/list.tt | 5 +++-- .../prog/en/modules/circ/circulation.tt | 12 ++++++++++-- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 373a614568d..cd63f2573d1 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -63,6 +63,7 @@ use Koha::Exceptions::Checkout; use Koha::Plugins; use Koha::Recalls; use Koha::Library::Hours; +use Koha::Bookings; use Carp qw( carp ); use List::MoreUtils qw( any ); use Scalar::Util qw( looks_like_number blessed ); @@ -1552,6 +1553,7 @@ sub AddIssue { my $auto_renew = $params && $params->{auto_renew}; my $cancel_recall = $params && $params->{cancel_recall}; my $recall_id = $params && $params->{recall_id}; + my $booking_id = $params && $params->{booking_id}; my $dbh = C4::Context->dbh; my $barcodecheck = CheckValidBarcode($barcode); @@ -1733,6 +1735,10 @@ sub AddIssue { q{DELETE tmp_holdsqueue, hold_fill_targets FROM tmp_holdsqueue LEFT JOIN hold_fill_targets USING ( itemnumber ) WHERE itemnumber = ?}, undef, $item_object->id ); + + if ($booking_id) { + Koha::Bookings->find( { booking_id => $booking_id } )->delete({ 'transform_to_checkout' => 1 }); + } } $issue->discard_changes; $patron->update_lastseen('check_out'); diff --git a/Koha/Booking.pm b/Koha/Booking.pm index e5297d8d17b..c5dc283df6a 100644 --- a/Koha/Booking.pm +++ b/Koha/Booking.pm @@ -251,11 +251,12 @@ sub to_api_mapping { =cut sub delete { - my ($self) = @_; + my ( $self, $params ) = @_; my $patron = $self->patron; my $pickup_library = $self->pickup_library; + if ( not defined( $params->{'transform_to_checkout'} ) ) { my $letter = C4::Letters::GetPreparedLetter( module => 'bookings', letter_code => 'BOOKING_CANCELLATION', @@ -277,6 +278,7 @@ sub delete { my $deleted = $self->SUPER::delete($self); return $deleted; + } } =head2 Internal methods 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 9230347ce01..912fbdb2c5b 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -57,6 +57,7 @@ use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::Patron::Modifications; use Koha::Token; +use Koha::Bookings; use List::MoreUtils qw( uniq ); @@ -68,6 +69,7 @@ my $query = CGI->new; my $borrowernumber = $query->param('borrowernumber'); my $barcodes = []; my $barcode = $query->param('barcode'); +my $booking_id = $query->param('booking_id'); # Barcode given by user could be '0' @@ -524,7 +526,7 @@ if (@$barcodes && $op eq 'cud-checkout') { { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall, - recall_id => $recall_id, + recall_id => $recall_id, booking_id => $booking_id } ); $template_params->{issue} = $issue; @@ -765,6 +767,7 @@ $template->param( nopermission => scalar $query->param('nopermission'), autoswitched => $autoswitched, logged_in_user => $logged_in_user, + booking_id => $booking_id || '', ); output_html_with_http_headers $query, $cookie, $template->output; 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 ce2aaeb0062..1485788dcba 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt @@ -310,8 +310,9 @@ "render": function(data, type, row, meta) { let result = ""; [% IF CAN_user_circulate_manage_bookings %] - result += ''; - result += ''; + 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 c31e66bd869..c59393f3044 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -9,6 +9,7 @@ [% USE ItemTypes %] [% USE Price %] [% USE AuthorisedValues %] +[% USE JSON.Escape %] [% PROCESS 'i18n.inc' %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] @@ -282,6 +283,7 @@
+ [% IF (forceallow) %][% END %] @@ -390,6 +392,7 @@ [% INCLUDE 'csrf-token.inc' %] + [% IF (forceallow) %][% END %] @@ -423,7 +426,8 @@ - + + [% END %] @@ -439,6 +443,7 @@ + [% IF CAN_user_circulate_force_checkout or HIGHHOLDS or ADDITIONAL_MATERIALS %] [% IF ( RENEW_ISSUE ) %] @@ -1053,7 +1058,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 booking_id = [% booking_id.json %]; + if (!booking_id) { + duedatespec_fp.setDate(""); + } } } } -- 2.30.2