From 6b7e493448246bd8bcd18415f5f05b7a97788056 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 3 Nov 2023 09:52:15 -0300 Subject: [PATCH] Bug 29002: Tidy Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 11 +++--- Koha/Biblio.pm | 28 +++++++------- Koha/Booking.pm | 8 ++-- Koha/Item.pm | 38 +++++++++---------- Koha/Items.pm | 2 +- Koha/REST/V1/Biblios.pm | 25 +++++------- Koha/REST/V1/Bookings.pm | 24 ++++-------- Koha/REST/V1/Items.pm | 11 ++---- Koha/Template/Plugin/Biblio.pm | 8 +--- catalogue/updateitem.pl | 4 +- circ/circulation.pl | 12 +++--- .../data/mysql/atomicupdate/bug_29002.pl | 24 ++++++++---- .../prog/en/modules/bookings/list.tt | 2 +- 13 files changed, 91 insertions(+), 106 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index ec21a6091c..e11a94e26b 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1228,21 +1228,22 @@ sub CanBookBeIssued { patron_id => $patron->borrowernumber } ) - ) + ) { # Booked to this patron :) if ( $booking->patron_id == $patron->borrowernumber ) { - if ( $now < dt_from_string($booking->start_date) ) { + if ( $now < dt_from_string( $booking->start_date ) ) { $needsconfirmation{'BOOKED_EARLY'} = $booking; - } - else { + } else { $alerts{'BOOKED'} = $booking; } } + # Booking starts before due date, reduce loan? - elsif ( $duedate > dt_from_string($booking->start_date) ) { + elsif ( $duedate > dt_from_string( $booking->start_date ) ) { $needsconfirmation{'BOOKED_TO_ANOTHER'} = $booking; } + # Loan falls inside booking else { $issuingimpossible{'BOOKED_TO_ANOTHER'} = $booking; diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index fdadcc3811..7d0b244085 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -219,6 +219,7 @@ sub can_article_request { } + =head3 check_booking my $bookable = @@ -240,7 +241,7 @@ sub check_booking { my $bookable_items = $self->bookable_items; my $total_bookable = $bookable_items->count; - my $dtf = Koha::Database->new->schema->storage->datetime_parser; + my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $existing_bookings = $self->bookings( [ start_date => { @@ -263,10 +264,9 @@ sub check_booking { ); my $booked_count = - defined($booking_id) - ? $existing_bookings->search( { booking_id => { '!=' => $booking_id } } ) - ->count - : $existing_bookings->count; + defined($booking_id) + ? $existing_bookings->search( { booking_id => { '!=' => $booking_id } } )->count + : $existing_bookings->count; my $checkouts = $self->current_checkouts->search( { date_due => { '>=' => $dtf->format_datetime($start_date) } } ); $booked_count += $checkouts->count; @@ -285,6 +285,7 @@ sub assign_item_for_booking { my $end_date = dt_from_string( $params->{end_date} ); my $dtf = Koha::Database->new->schema->storage->datetime_parser; + my $existing_bookings = $self->bookings( [ start_date => { @@ -311,8 +312,7 @@ sub assign_item_for_booking { my $bookable_items = $self->bookable_items->search( { itemnumber => [ - '-and' => - { '-not_in' => $existing_bookings->_resultset->get_column('item_id')->as_query }, + '-and' => { '-not_in' => $existing_bookings->_resultset->get_column('item_id')->as_query }, { '-not_in' => $checkouts->_resultset->get_column('itemnumber')->as_query } ] }, @@ -344,8 +344,7 @@ sub place_booking { my @mandatory = ( 'start_date', 'end_date', 'patron' ); for my $param (@mandatory) { unless ( defined( $params->{$param} ) ) { - Koha::Exceptions::MissingParameter->throw( - error => "The $param parameter is mandatory" ); + Koha::Exceptions::MissingParameter->throw( error => "The $param parameter is mandatory" ); } } my $patron = $params->{patron}; @@ -353,10 +352,10 @@ sub place_booking { # New booking object my $booking = Koha::Booking->new( { - start_date => $params->{start_date}, - end_date => $params->{end_date}, - patron_id => $patron->borrowernumber, - biblio_id => $self->biblionumber + start_date => $params->{start_date}, + end_date => $params->{end_date}, + patron_id => $patron->borrowernumber, + biblio_id => $self->biblionumber } )->store(); return $booking; @@ -660,7 +659,6 @@ sub bookable_items { return $self->items->filter_by_bookable; } - =head3 host_items my $host_items = $biblio->host_items(); @@ -774,7 +772,7 @@ Returns the bookings attached to this biblio. sub bookings { my ( $self, $params ) = @_; my $bookings_rs = $self->_result->bookings->search($params); - return Koha::Bookings->_new_from_dbic( $bookings_rs ); + return Koha::Bookings->_new_from_dbic($bookings_rs); } =head3 suggestions diff --git a/Koha/Booking.pm b/Koha/Booking.pm index 273d3e9f3f..60dcc88d63 100644 --- a/Koha/Booking.pm +++ b/Koha/Booking.pm @@ -155,21 +155,21 @@ sub intersects { # Start date of comparison booking is after end date of this booking. return 0 - if ( + if ( DateTime->compare( dt_from_string( $comp->start_date ), dt_from_string( $self->end_date ) ) >= 0 - ); + ); # End date of comparison booking is before start date of this booking. return 0 - if ( + if ( DateTime->compare( dt_from_string( $comp->end_date ), dt_from_string( $self->start_date ) ) <= 0 - ); + ); # Bookings must overlap return 1; diff --git a/Koha/Item.pm b/Koha/Item.pm index 1f490b86f5..484de1a054 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -514,7 +514,7 @@ sub holds { =head3 bookings - my $bookings = $item->bookings(); + my $bookings = $item->bookings(); Returns the bookings attached to this item. @@ -523,7 +523,7 @@ Returns the bookings attached to this item. sub bookings { my ( $self, $params ) = @_; my $bookings_rs = $self->_result->bookings->search($params); - return Koha::Bookings->_new_from_dbic( $bookings_rs ); + return Koha::Bookings->_new_from_dbic($bookings_rs); } =head3 find_booking @@ -564,9 +564,7 @@ sub find_booking { end_date => { '>' => $dtf->format_datetime($due_date) } } ], - { - order_by => { '-asc' => 'start_date' } - } + { order_by => { '-asc' => 'start_date' } } ); my $checkouts = {}; @@ -575,8 +573,7 @@ sub find_booking { while ( my $item = $bookable_items->next ) { $loanable_items->{ $item->itemnumber } = 1; if ( my $checkout = $item->checkout ) { - $checkouts->{ $item->itemnumber } = - dt_from_string( $checkout->date_due ); + $checkouts->{ $item->itemnumber } = dt_from_string( $checkout->date_due ); } } @@ -607,8 +604,8 @@ sub find_booking { =head3 check_booking - my $bookable = - $item->check_booking( { start_date => $datetime, end_date => $datetime, [ booking_id => $booking_id ] } ); + my $bookable = + $item->check_booking( { start_date => $datetime, end_date => $datetime, [ booking_id => $booking_id ] } ); Returns a boolean denoting whether the passed booking can be made without clashing. @@ -617,7 +614,7 @@ Optionally, you may pass a booking id to exclude from the checks; This is helpfu =cut sub check_booking { - my ($self, $params) = @_; + my ( $self, $params ) = @_; my $start_date = dt_from_string( $params->{start_date} ); my $end_date = dt_from_string( $params->{end_date} ); @@ -628,6 +625,7 @@ sub check_booking { } my $dtf = Koha::Database->new->schema->storage->datetime_parser; + my $existing_bookings = $self->bookings( [ start_date => { @@ -650,10 +648,9 @@ sub check_booking { ); my $bookings_count = - defined($booking_id) - ? $existing_bookings->search( { booking_id => { '!=' => $booking_id } } ) - ->count - : $existing_bookings->count; + defined($booking_id) + ? $existing_bookings->search( { booking_id => { '!=' => $booking_id } } )->count + : $existing_bookings->count; return $bookings_count ? 0 : 1; } @@ -681,8 +678,7 @@ sub place_booking { my @mandatory = ( 'start_date', 'end_date', 'patron' ); for my $param (@mandatory) { unless ( defined( $params->{$param} ) ) { - Koha::Exceptions::MissingParameter->throw( - error => "The $param parameter is mandatory" ); + Koha::Exceptions::MissingParameter->throw( error => "The $param parameter is mandatory" ); } } my $patron = $params->{patron}; @@ -690,11 +686,11 @@ sub place_booking { # New booking object my $booking = Koha::Booking->new( { - start_date => $params->{start_date}, - end_date => $params->{end_date}, - patron_id => $patron->borrowernumber, - biblio_id => $self->biblionumber, - item_id => $self->itemnumber, + start_date => $params->{start_date}, + end_date => $params->{end_date}, + patron_id => $patron->borrowernumber, + biblio_id => $self->biblionumber, + item_id => $self->itemnumber, } )->store(); return $booking; diff --git a/Koha/Items.pm b/Koha/Items.pm index d95d3f811c..4089068b34 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -171,7 +171,7 @@ sub filter_by_bookable { my $params = { bookable => 1 }; - return $self->search( $params ); + return $self->search($params); } =head3 move_to_biblio diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 8fb58a0a73..846a0fb94d 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -246,6 +246,7 @@ sub get_public { }; } + =head3 get_bookings Controller function that handles retrieving biblio's bookings @@ -257,25 +258,22 @@ sub get_bookings { my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['bookings'] } ); - unless ( $biblio ) { + unless ($biblio) { return $c->render( status => 404, - openapi => { - error => "Object not found." - } + openapi => { error => "Object not found." } ); } return try { my $bookings_rs = $biblio->bookings; - my $bookings = $c->objects->search( $bookings_rs ); + my $bookings = $c->objects->search($bookings_rs); return $c->render( status => 200, openapi => $bookings ); - } - catch { + } catch { $c->unhandled_exception($_); }; } @@ -289,15 +287,13 @@ Controller function that handles retrieving biblio's items sub get_items { my $c = shift->openapi->valid_input or return; - my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['items'] } ); + my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['items'] } ); my $bookable_only = $c->param('bookable'); - unless ( $biblio ) { + unless ($biblio) { return $c->render( status => 404, - openapi => { - error => "Object not found." - } + openapi => { error => "Object not found." } ); } @@ -305,13 +301,12 @@ sub get_items { my $items_rs = $biblio->items; $items_rs = $items_rs->filter_by_bookable if $bookable_only; - my $items = $c->objects->search( $items_rs ); + my $items = $c->objects->search($items_rs); return $c->render( status => 200, openapi => $items ); - } - catch { + } catch { $c->unhandled_exception($_); }; } diff --git a/Koha/REST/V1/Bookings.pm b/Koha/REST/V1/Bookings.pm index cc1ad4a97c..08a772f50e 100644 --- a/Koha/REST/V1/Bookings.pm +++ b/Koha/REST/V1/Bookings.pm @@ -40,8 +40,7 @@ sub list { my $bookings_set = Koha::Bookings->new; my $bookings = $c->objects->search($bookings_set); return $c->render( status => 200, openapi => $bookings ); - } - catch { + } catch { $c->unhandled_exception($_); }; @@ -57,8 +56,7 @@ sub get { my $c = shift->openapi->valid_input or return; return try { - my $booking = - Koha::Bookings->find( $c->validation->param('booking_id') ); + my $booking = Koha::Bookings->find( $c->validation->param('booking_id') ); unless ($booking) { return $c->render( status => 404, @@ -67,8 +65,7 @@ sub get { } return $c->render( status => 200, openapi => $booking->to_api ); - } - catch { + } catch { $c->unhandled_exception($_); } } @@ -83,17 +80,14 @@ sub add { my $c = shift->openapi->valid_input or return; return try { - my $booking = - Koha::Booking->new_from_api( $c->validation->param('body') ); + my $booking = Koha::Booking->new_from_api( $c->validation->param('body') ); $booking->store; - $c->res->headers->location( - $c->req->url->to_string . '/' . $booking->booking_id ); + $c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id ); return $c->render( status => 201, openapi => $booking->to_api ); - } - catch { + } catch { if ( blessed $_ and $_->isa('Koha::Exceptions::Booking::Clash') ) { return $c->render( status => 400, @@ -127,8 +121,7 @@ sub update { $booking->set_from_api( $c->validation->param('body') ); $booking->store(); return $c->render( status => 200, openapi => $booking->to_api ); - } - catch { + } catch { $c->unhandled_exception($_); }; } @@ -156,8 +149,7 @@ sub delete { status => 204, openapi => q{} ); - } - catch { + } catch { $c->unhandled_exception($_); }; } diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm index 795f11ace5..736c0ebef6 100644 --- a/Koha/REST/V1/Items.pm +++ b/Koha/REST/V1/Items.pm @@ -185,25 +185,22 @@ sub get_bookings { my $item = Koha::Items->find( { itemnumber => $c->validation->param('item_id') }, { prefetch => ['bookings'] } ); - unless ( $item ) { + unless ($item) { return $c->render( status => 404, - openapi => { - error => "Object not found." - } + openapi => { error => "Object not found." } ); } return try { my $bookings_rs = $item->bookings; - my $bookings = $c->objects->search( $bookings_rs ); + my $bookings = $c->objects->search($bookings_rs); return $c->render( status => 200, openapi => $bookings ); - } - catch { + } catch { $c->unhandled_exception($_); }; } diff --git a/Koha/Template/Plugin/Biblio.pm b/Koha/Template/Plugin/Biblio.pm index c638c6e251..fb1193065f 100644 --- a/Koha/Template/Plugin/Biblio.pm +++ b/Koha/Template/Plugin/Biblio.pm @@ -71,7 +71,7 @@ sub RecallsCount { sub CanBook { my ( $self, $biblionumber ) = @_; - my $biblio = Koha::Biblios->find( $biblionumber ); + my $biblio = Koha::Biblios->find($biblionumber); return $biblio->bookable_items->count ? 1 : 0; } @@ -82,11 +82,7 @@ sub BookingsCount { my $now = dt_from_string; my $dtf = Koha::Database->new->schema->storage->datetime_parser; - return $biblio->bookings->search( - { - start_date => { '>' => $dtf->format_datetime($now) } - } - )->count; + return $biblio->bookings->search( { start_date => { '>' => $dtf->format_datetime($now) } } )->count; } 1; diff --git a/catalogue/updateitem.pl b/catalogue/updateitem.pl index eab5fdd640..6987cacbd0 100755 --- a/catalogue/updateitem.pl +++ b/catalogue/updateitem.pl @@ -39,7 +39,7 @@ my $itemnotes_nonpublic=$cgi->param('itemnotes_nonpublic'); my $withdrawn=$cgi->param('withdrawn'); my $damaged=$cgi->param('damaged'); my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority'); -my $bookable=$cgi->param('bookable'); +my $bookable = $cgi->param('bookable'); my $confirm=$cgi->param('confirm'); my $dbh = C4::Context->dbh; @@ -76,7 +76,7 @@ elsif ( $op eq "set_public_note" ) { # i.e., itemnotes parameter passed from for } elsif ( $op eq "set_exclude_priority" && $exclude_from_local_holds_priority ne $item_data_hashref->{'exclude_from_local_holds_priority'}) { $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority); $messages = "updated_exclude_from_local_holds_priority=$exclude_from_local_holds_priority&"; -} elsif ( $op eq "set_bookable" && $bookable ne $item_data_hashref->{'bookable'}) { +} elsif ( $op eq "set_bookable" && $bookable ne $item_data_hashref->{'bookable'} ) { $item->bookable($bookable); } elsif ( $op eq "set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) { $item->damaged($damaged); diff --git a/circ/circulation.pl b/circ/circulation.pl index 6a2d610ecb..ad4eeb1952 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -376,8 +376,8 @@ if (@$barcodes) { if ( $error->{BOOKED_TO_ANOTHER} ) { $template_params->{BOOKED_TO_ANOTHER} = $error->{BOOKED_TO_ANOTHER}; - $template_params->{IMPOSSIBLE} = 1; - $blocker = 1; + $template_params->{IMPOSSIBLE} = 1; + $blocker = 1; } foreach my $code ( @blocking_error_codes ) { @@ -409,18 +409,19 @@ if (@$barcodes) { $template_params->{NEEDSCONFIRMATION} = 1; $confirm_required = 1; if ( $needsconfirmation eq 'BOOKED_TO_ANOTHER' ) { - my $reduceddue = dt_from_string($$question{$needsconfirmation}->start_date)->subtract( days => 1 ); + my $reduceddue = + dt_from_string( $$question{$needsconfirmation}->start_date )->subtract( days => 1 ); $template_params->{reduceddue} = $reduceddue; } } } - unless($confirm_required) { + unless ($confirm_required) { my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}; if ( C4::Context->preference('UseRecalls') && !$recall_id ) { my $recall = Koha::Recalls->find( { biblio_id => $item->biblionumber, - item_id => [ undef, $item->itemnumber ], + item_id => [ undef, $item->itemnumber ], status => [ 'requested', 'waiting' ], completed => 0, patron_id => $patron->borrowernumber, @@ -428,6 +429,7 @@ if (@$barcodes) { ); $recall_id = ( $recall and $recall->id ) ? $recall->id : undef; } + # If booked (alerts or confirmation) update datedue to end of booking if ( my $booked = $question->{BOOKED_EARLY} // $alerts->{BOOKED} ) { $datedue = $booked->end_date; diff --git a/installer/data/mysql/atomicupdate/bug_29002.pl b/installer/data/mysql/atomicupdate/bug_29002.pl index dd0a978ddd..59b05e1cbd 100755 --- a/installer/data/mysql/atomicupdate/bug_29002.pl +++ b/installer/data/mysql/atomicupdate/bug_29002.pl @@ -7,7 +7,8 @@ return { my ($args) = @_; my ( $dbh, $out ) = @$args{qw(dbh out)}; if ( !TableExists('bookings') ) { - $dbh->do(q{ + $dbh->do( + q{ CREATE TABLE `bookings` ( `booking_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', `patron_id` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from the borrowers table defining which patron this booking is for', @@ -23,28 +24,35 @@ return { CONSTRAINT `bookings_ibfk_2` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `bookings_ibfk_3` FOREIGN KEY (`item_id`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci - }); + } + ); } if ( !column_exists( 'items', 'bookable' ) ) { - $dbh->do(q{ + $dbh->do( + q{ ALTER TABLE items ADD COLUMN `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean value defining whether this this item is available for bookings or not' AFTER `barcode` - }); + } + ); } if ( !column_exists( 'deleteditems', 'bookable' ) ) { - $dbh->do(q{ + $dbh->do( + q{ ALTER TABLE deleteditems ADD COLUMN `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean value defining whether this this item is available for bookings or not' AFTER `barcode` - }); + } + ); } - $dbh->do(q{ + $dbh->do( + q{ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 1, 'manage_bookings', 'Manage item bookings' ); - }); + } + ); say $out "Added new permissions 'manage_bookings'"; }, 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 07c228412a..6e0cb5e4f4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt @@ -157,7 +157,7 @@ // action events onMove: function (data, callback) { let startDate = dayjs(data.start); - + // set end datetime hours and minutes to the end of the day let endDate = dayjs(data.end).endOf('day'); -- 2.39.5