Skip to content

Commit

Permalink
Bug 29002: Tidy
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Cohen Arazi <[email protected]>
  • Loading branch information
tomascohen committed Nov 3, 2023
1 parent c369f4c commit 6b7e493
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 106 deletions.
11 changes: 6 additions & 5 deletions C4/Circulation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 13 additions & 15 deletions Koha/Biblio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ sub can_article_request {
}



=head3 check_booking
my $bookable =
Expand All @@ -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 => {
Expand All @@ -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;
Expand All @@ -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 => {
Expand All @@ -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 }
]
},
Expand Down Expand Up @@ -344,19 +344,18 @@ 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};

# 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;
Expand Down Expand Up @@ -660,7 +659,6 @@ sub bookable_items {
return $self->items->filter_by_bookable;
}


=head3 host_items
my $host_items = $biblio->host_items();
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Koha/Booking.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 17 additions & 21 deletions Koha/Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ sub holds {

=head3 bookings
my $bookings = $item->bookings();
my $bookings = $item->bookings();
Returns the bookings attached to this item.
Expand All @@ -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
Expand Down Expand Up @@ -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 = {};
Expand All @@ -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 );
}
}

Expand Down Expand Up @@ -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.
Expand All @@ -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} );
Expand All @@ -628,6 +625,7 @@ sub check_booking {
}

my $dtf = Koha::Database->new->schema->storage->datetime_parser;

my $existing_bookings = $self->bookings(
[
start_date => {
Expand All @@ -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;
}
Expand Down Expand Up @@ -681,20 +678,19 @@ 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};

# 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;
Expand Down
2 changes: 1 addition & 1 deletion Koha/Items.pm
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ sub filter_by_bookable {

my $params = { bookable => 1 };

return $self->search( $params );
return $self->search($params);
}

=head3 move_to_biblio
Expand Down
25 changes: 10 additions & 15 deletions Koha/REST/V1/Biblios.pm
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ sub get_public {
};
}


=head3 get_bookings
Controller function that handles retrieving biblio's bookings
Expand All @@ -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($_);
};
}
Expand All @@ -289,29 +287,26 @@ 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." }
);
}

return try {

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($_);
};
}
Expand Down
Loading

0 comments on commit 6b7e493

Please sign in to comment.