From f7cdd9610bb66b42f9b6c8a5d8f2bbf675887026 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Wed, 12 Mar 2025 21:31:35 +0000 Subject: [PATCH] Bug 31698: Add new move_hold_item subroutine to Hold.pm and request.pl --- Koha/Hold.pm | 41 +++++++++++++++++++++++++++++++++++++++ reserve/request.pl | 48 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index b3bf4a02b76..2368e0b53e4 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -178,6 +178,47 @@ sub delete { return $deleted; } +=head3 move_hold_item + +$hold->move_hold_item(); + +=cut + +sub move_hold_item { + my ( $self, $args ) = @_; + + my $new_itemnumber = $args->{new_itemnumber}; + my $new_biblionumber = $args->{new_biblionumber}; + my $original = $self; + + my $patron = Koha::Patrons->find( { borrowernumber => $self->borrowernumber } ); + my $new_item = Koha::Items->find( { itemnumber => $new_itemnumber } ); + + if ($new_itemnumber) { + + #check to see if moving this hold is allowed + my $canReserve = + C4::Reserves::CanItemBeReserved( $patron, $new_item, $self->branchcode, { ignore_hold_counts => 1 } ); + + if ( $canReserve->{status} eq 'OK' ) { + $self->update( + { + itemnumber => $new_item->itemnumber, + biblionumber => $new_item->biblionumber + } + ); + + C4::Log::logaction( 'HOLDS', 'MODIFY', $self->reserve_id, $self, undef, $original ) + if C4::Context->preference('HoldsLog'); + + return { success => 1, hold => $self }; + } else { + return { success => 0, error => $canReserve->{status} }; + } + } + return $self; +} + =head3 set_transfer =cut diff --git a/reserve/request.pl b/reserve/request.pl index c5e354aa7d2..60768041ad0 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -44,6 +44,7 @@ use C4::Search qw( enabled_staff_search_views ); use Koha::Biblios; use Koha::Checkouts; use Koha::Holds; +use Koha::Hold; use Koha::CirculationRules; use Koha::Items; use Koha::ItemTypes; @@ -90,6 +91,7 @@ my $exceeded_maxreserves; my $exceeded_holds_per_record; my @failed_holds = $input->multi_param('failed_holds'); my $form_submitted = $input->param('form_submitted'); +my @biblionumbers = $input->multi_param('biblionumber'); my $op = $input->param('op') || q{}; @@ -109,6 +111,50 @@ if ( $op eq 'cud-move' ) { $next_priority, $first_priority, $last_priority ); } +} elsif ( $op eq 'cud-move_hold_item' ) { + my $new_itemnumber = $input->param('new_itemnumber'); + my $new_biblionumber = $input->param('new_biblionumber'); + my $target_biblio = Koha::Biblios->find($new_biblionumber); + my @hold_ids = $input->multi_param('hold_id'); + + my @success_messages; + my @error_messages; + + foreach my $hold_id (@hold_ids) { + my $hold = Koha::Holds->find($hold_id); + my $original_biblio = Koha::Biblios->find( $hold->biblionumber ); + my $result = $hold->move_hold_item( + { + new_itemnumber => $new_itemnumber, + new_biblionumber => $new_biblionumber, + } + ); + + #push info about successes and errors to the template + if ( $result->{success} ) { + push @success_messages, { + hold_id => $hold_id, + success => 1, + original_biblio => $original_biblio, + target_biblio => $target_biblio, + }; + } else { + push @error_messages, { + hold_id => $hold_id, + success => 0, + original_biblio => $original_biblio, + target_biblio => $target_biblio, + error => $result->{error}, + }; + } + } + + push @biblionumbers, $new_biblionumber; + + $template->param( + hold_move_successes => \@success_messages, + hold_move_failures => \@error_messages, + ); } elsif ( $op eq 'cud-cancel' ) { my $reserve_id = $input->param('reserve_id'); my $cancellation_reason = $input->param("cancellation-reason"); @@ -172,8 +218,6 @@ if ($form_submitted) { } } -my @biblionumbers = $input->multi_param('biblionumber'); - my $multi_hold = @biblionumbers > 1; $template->param( multi_hold => $multi_hold, -- 2.39.5