Bug 23678: Allow cancel holds in bulk

This patch allows staff patrons to cancel multiple holds in bulk.

To test:
1. Apply this patch
2. restart_all
3. In cataloge go to a book and place many holds
CHECK => Holds table shows a column of checkboxes
4. Play with checkboxes (have some fun ;-P)
CHECK => When you manually check all checkboxes, the checkbox in the
header also gets checked.
      => When you uncheck one of the checkboxes, the one in the header also gets unchecked.
      => If no checkbox is checked and you check the one in the header,
all checkboxes get checked.
      => If there are some checkboxes that are checked and others are
not, when you click on the checkbox in the header all checkboxes get
unchecked.
      => If all checkboxes are checked, when you uncheck the one in the
header, all checkboxes get unchecked.
      => Every time you play with checkboxes, the number in the button
"Cancel selected" changes.
5. Check some of the checkboxes and click on cancel selected.
SUCCESS => A background job gets fired to cancel all selected holds.
        => A message should appear with a link to the job.
6. Wait a few seconds and click on the link
SUCCESS => A message appears with the report of the execution of the
background job.
7. Grab a patron and search to hold
8. Select multiple biblios and click on "place hold for <patron>"
CHECK => After holds are confirmed, multiple holds table are shown.. one for
   each record. Checkboxes work exactly the same as before, but scoped
for each individual table. Checkboxes from one table will not affect
checkboxes from other tables.
9. Repeat steps 4 to 6.
10. Check In some of the items so the get in Waiting state.
11. Update expirationdate os some of those holds and set it to
    ReservesMaxPickUpDelay + 1 days earlier
NOTE => ReservesMaxPickUpDelay = 7 days by default, so sql syntax to update would be
     => update reserves set expirationdate = date_sub(expirationdate, interval 8 day) where reserve_id in (...)
12. Repeat steps 4 to 6 but in waitingreserves.pl, in both tabs.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Bug 23678: (QA follow-up) Add missing template filter

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Bug 23678: (QA follow-up) Add missing filters

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Bug 23678: (QA follow-up) Use correct indentation

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

JD amended patch: also Koha/BackgroundJob/BatchCancelHold.pm

JD Amended patch: Full rebase and adjustements made on top of bug 26080.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Agustin Moyano 2021-02-25 13:07:12 -03:00 committed by Jonathan Druart
parent 170020d453
commit 954d2606a8
9 changed files with 418 additions and 36 deletions

View File

@ -28,6 +28,7 @@ use Koha::BackgroundJob::BatchUpdateBiblio;
use Koha::BackgroundJob::BatchUpdateAuthority;
use Koha::BackgroundJob::BatchDeleteBiblio;
use Koha::BackgroundJob::BatchDeleteAuthority;
use Koha::BackgroundJob::BatchCancelHold;
use base qw( Koha::Object );
@ -159,7 +160,6 @@ sub process {
$args ||= {};
return $derived_class->process({job_id => $self->id, %$args});
}
=head3 job_type
@ -256,6 +256,7 @@ sub type_to_class_mapping {
batch_authority_record_modification => 'Koha::BackgroundJob::BatchUpdateAuthority',
batch_biblio_record_deletion => 'Koha::BackgroundJob::BatchDeleteBiblio',
batch_biblio_record_modification => 'Koha::BackgroundJob::BatchUpdateBiblio',
batch_hold_cancel => 'Koha::BackgroundJob::BatchCancelHold',
};
}

View File

@ -0,0 +1,154 @@
package Koha::BackgroundJob::BatchCancelHold;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use JSON qw( encode_json decode_json );
use Koha::BackgroundJobs;
use Koha::DateUtils qw( dt_from_string );
use Koha::Holds;
use base 'Koha::BackgroundJob';
=head1 NAME
Koha::BackgroundJob::BatchCancelHold - Batch cancel holds
This is a subclass of Koha::BackgroundJob.
=head1 API
=head2 Class methods
=head3 job_type
Define the job type of this job: batch_hold_cancel
=cut
sub job_type {
return 'batch_hold_cancel';
}
=head3 process
Process the modification.
=cut
sub process {
my ( $self, $args ) = @_;
my $job = Koha::BackgroundJobs->find( $args->{job_id} );
if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
return;
}
my $job_progress = 0;
$job->started_on(dt_from_string)->progress($job_progress)
->status('started')->store;
my @hold_ids = @{ $args->{hold_ids} };
my $report = {
total_holds => scalar @hold_ids,
total_success => 0,
};
my @messages;
HOLD_IDS: for my $hold_id ( sort { $a <=> $b } @hold_ids ) {
next unless $hold_id;
# Authorities
my ( $hold, $patron, $biblio );
$hold = Koha::Holds->find($hold_id);
my $error = eval {
$patron = $hold->patron;
$biblio = $hold->biblio;
$hold->cancel( { cancellation_reason => $args->{reason} } );
};
if ( $error and $error != $hold or $@ ) {
push @messages,
{
type => 'error',
code => 'hold_not_cancelled',
patron_id => defined $patron ? $patron->borrowernumber : '',
patron_name => defined $patron
? ( $patron->firstname ? $patron->firstname . ', ' : '' )
. $patron->surname
: '',
biblio_id => defined $biblio ? $biblio->biblionumber : '',
biblio_title => defined $biblio ? $biblio->title : '',
hold_id => $hold_id,
error => defined $hold
? ( $@ ? $@ : 0 )
: 'No hold with id ' . $hold_id . ' found',
};
}
else {
push @messages,
{
type => 'success',
code => 'hold_cancelled',
patron_id => $patron->borrowernumber,
patron_name =>
( $patron->firstname ? $patron->firstname . ', ' : '' )
. $patron->surname,
biblio_id => $biblio->biblionumber,
biblio_title => $biblio->title,
hold_id => $hold_id,
};
$report->{total_success}++;
}
$job->progress( ++$job_progress )->store;
}
my $job_data = decode_json $job->data;
$job_data->{messages} = \@messages;
$job_data->{report} = $report;
$job->ended_on(dt_from_string)->data( encode_json $job_data);
$job->status('finished') if $job->status ne 'cancelled';
$job->store;
}
=head3 enqueue
Enqueue the new job
=cut
sub enqueue {
my ( $self, $args ) = @_;
# TODO Raise exception instead
return unless exists $args->{hold_ids};
my @hold_ids = @{ $args->{hold_ids} };
$self->SUPER::enqueue(
{
job_size => scalar @hold_ids,
job_args => { hold_ids => \@hold_ids, reason => $args->{reason} }
}
);
}
1;

View File

@ -31,6 +31,7 @@ use Koha::BiblioFrameworks;
use Koha::Items;
use Koha::ItemTypes;
use Koha::Patrons;
use Koha::BackgroundJob::BatchCancelHold;
my $input = CGI->new;
@ -41,6 +42,7 @@ my $tbr = $input->param('tbr') || '';
my $all_branches = $input->param('allbranches') || '';
my $cancelall = $input->param('cancelall');
my $tab = $input->param('tab');
my $cancelBulk = $input->param('cancelBulk');
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
{
@ -71,6 +73,21 @@ if ( C4::Context->preference('IndependentBranches') ) {
}
$template->param( all_branches => 1 ) if $all_branches;
if ($cancelBulk) {
my $reason = $input->param("cancellation-reason");
my @hold_ids = split ',', $input->param("ids");
my $params = {
reason => $reason,
hold_ids => \@hold_ids,
};
my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params);
$template->param(
enqueued => 1,
job_id => $job_id
);
}
my (@reserve_loop, @over_loop);
# FIXME - Is priority => 0 useful? If yes it must be moved to waiting, otherwise we need to remove it from here.
my $holds = Koha::Holds->waiting->search({ priority => 0, ( $all_branches ? () : ( branchcode => $default ) ) }, { order_by => ['waitingdate'] });

View File

@ -1,8 +1,9 @@
[% USE Koha %]
[% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %]
[% USE AuthorisedValues %]
<table>
<table class="holds_table">
<tr>
<th><input type="checkbox" class="select_hold_all"/></th>
[% IF ( CAN_user_reserveforothers_modify_holds_priority ) %]
<th>Priority</th>
<th>&nbsp;</th>
@ -48,6 +49,7 @@
[%- this_priority = loop.count() - found_holds -%]
[%- END -%]
<tr>
<th><input type="checkbox" class="select_hold" data-id="[% hold.reserve_id | html %]"/></th>
<td>
<input type="hidden" name="reserve_id" value="[% hold.reserve_id | html %]" />
<input type="hidden" name="borrowernumber" value="[% hold.borrowernumber | html %]" />

View File

@ -1,8 +1,11 @@
[% USE ItemTypes %]
[% USE AuthorisedValues %]
<table id="[% table_name | html %]">
<table class="holds_table" id="[% table_name | html %]">
<thead>
<tr>
[% IF select_column %]
<th class="NoSort"><input type="checkbox" class="select_hold_all"/></th>
[% END %]
<th class="title-string">Waiting since</th>
<th class="title-string">Date hold placed</th>
<th class="anti-the">Title</th>
@ -19,6 +22,9 @@
<tbody>
[% FOREACH reserveloo IN reserveloop %]
<tr>
[% IF select_column %]
<th><input type="checkbox" class="select_hold" data-id="[% reserveloo.reserve_id | html %]"/></th>
[% END %]
<td><span title="[% reserveloo.waitingdate | html %]">[% reserveloo.waitingdate | $KohaDates %]</span></td>
<td><span title="[% reserveloo.reservedate | html %]">[% reserveloo.reservedate | $KohaDates %]</span></td>
<td>

View File

@ -4,6 +4,7 @@
[% USE KohaDates %]
[% USE Branches %]
[% USE TablesSettings %]
[% USE AuthorisedValues %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Holds awaiting pickup &rsaquo; Circulation &rsaquo; Koha</title>
@ -72,6 +73,12 @@
[% END %]
[% END %]
[% ELSE %]
[% IF enqueued %]
<div class="dialog message">
<p>The job has been enqueued! It will be processed as soon as possible.</p>
<p><a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]" title="View detail of the enqueued job">View detail of the enqueued job</a></p>
</div>
[% END %]
<div id="resultlist" class="toptabs">
<ul>
<li><a href="#holdswaiting">Holds waiting: [% reservecount | html %]</a></li>
@ -83,7 +90,10 @@
</ul>
<div id="holdswaiting">
[% IF ( reserveloop ) %]
[% INCLUDE waiting_holds.inc table_name='holdst' reserveloop=reserveloop tab='holdwaiting' %]
<div id="toolbar" class="btn-toolbar">
<button class="cancel_selected_holds" data-bulk="true"></button>
</div>
[% INCLUDE waiting_holds.inc select_column='1' table_name='holdst' reserveloop=reserveloop tab='holdwaiting' %]
[% ELSE %]
<div class="dialog message">No holds found.</div>
[% END %]
@ -92,6 +102,7 @@
[% IF ( ReservesMaxPickUpDelay ) %]<p>Holds listed here have been awaiting pickup for more than [% ReservesMaxPickUpDelay | html %] days.</p>[% END %]
[% IF ( overloop ) %]
<span id="holdsover-cancel-all">
<button class="cancel_selected_holds" data-bulk="true"></button>
<form name="cancelAllReserve" action="waitingreserves.pl" method="post">
<input type="hidden" name="cancelall" value="1" />
<input type="hidden" name="allbranches" value="[% allbranches | html %]" />
@ -105,8 +116,9 @@
[% UNLESS TransferWhenCancelAllWaitingHolds %]
Only items that need not be transferred will be cancelled (TransferWhenCancelAllWaitingHolds syspref)
[% END %]
</span>
[% INCLUDE waiting_holds.inc table_name='holdso' reserveloop=overloop tab='holdsover' %]
[% INCLUDE waiting_holds.inc select_column='1' table_name='holdso' reserveloop=overloop tab='holdsover' %]
[% ELSE %]
<div class="dialog message">No holds found.</div>
[% END %]
@ -128,25 +140,128 @@
</div> <!-- /.col-sm-12 -->
</div> <!-- /.row -->
<div id="cancelModal" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Confirm deletion</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to cancel this hold?</p>
<fieldset class="action">
[% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %]
[% IF hold_cancellation %]
<label for="cancellation-reason">Cancellation reason: </label>
<select class="cancellation-reason" name="modal-cancellation-reason" id="modal-cancellation-reason">
<option value="">No reason given</option>
[% FOREACH reason IN hold_cancellation %]
<option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
[% END %]
</select>
[% END %]
</fieldset>
</div>
<div class="modal-footer">
<button id="cancelModalConfirmBtn" type="button" class="btn btn-danger">Confirm cancellation</button>
<a href="#" data-dismiss="modal">Cancel</a>
</div>
</div>
</div>
</div>
[% MACRO jsinclude BLOCK %]
[% INCLUDE 'datatables.inc' %]
[% INCLUDE 'columns_settings.inc' %]
<script>
var MSG_CANCEL_SELECTED = _("Cancel selected (%s)");
var holdst_columns_settings = [% TablesSettings.GetColumns( 'circ', 'holds_awaiting_pickup', 'holdst', 'json' ) | $raw %];
var holdso_columns_settings = [% TablesSettings.GetColumns( 'circ', 'holds_awaiting_pickup', 'holdso', 'json' ) | $raw %];
$(document).ready(function() {
KohaTable("holdst", {
"sPaginationType": "full"
"sPaginationType": "full",
"order": [[1, 'asc']]
}, holdst_columns_settings);
KohaTable("holdso", {
"sPaginationType": "full"
"sPaginationType": "full",
"order": [[1, 'asc']]
}, holdso_columns_settings);
$('#resultlist').tabs();
let cancel_link;
$("#cancelModalConfirmBtn").on("click",function(e) {
var ids = cancel_link.data('ids');
localStorage.selectedWaitingHolds = JSON.stringify(JSON.parse(localStorage.selectedWaitingHolds).filter(id => !ids.includes(id)));
let link = `waitingreserves.pl?cancelBulk=1&amp;ids=${ids.join(',')}`;
let reason = $("#modal-cancellation-reason").val();
if ( reason ) {
link += "&amp;cancellation-reason=" + reason
}
window.location.href = link;
return false;
});
if(!localStorage.selectedWaitingHolds || document.referrer.replace(/\?.*/, '') !== document.location.origin+document.location.pathname) {
localStorage.selectedWaitingHolds = '[]';
}
try {
JSON.parse(localStorage.selectedWaitingHolds);
} catch(e) {
localStorage.selectedWaitingHolds = '[]';
}
$('.holds_table .select_hold').each(function() {
if(JSON.parse(localStorage.selectedWaitingHolds).includes($(this).data('id'))) {
$(this).prop('checked', true);
}
});
$('.holds_table').each(function() {
var table = $(this);
var parent = table.parents('.ui-tabs-panel');
$('.holds_table .select_hold_all', parent).each(function() {
var count = $('.select_hold:not(:checked)', table).length;
$('.select_hold_all', table).prop('checked', !count);
});
$('.cancel_selected_holds', parent).html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked', parent).length));
$('.holds_table .select_hold_all', parent).click(function() {
var count = $('.select_hold:checked', table).length;
$('.select_hold', table).prop('checked', !count);
$(this).prop('checked', !count);
$('.cancel_selected_holds', parent).data('ids', $('.holds_table .select_hold:checked', parent).toArray().map(el => $(el).data('id'))).html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked', parent).length));
localStorage.selectedWaitingHolds = JSON.stringify($('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')));
});
$('.holds_table .select_hold', parent).click(function() {
var count = $('.select_hold:not(:checked)', table).length;
$('.select_hold_all', table).prop('checked', !count);
$('.cancel_selected_holds', parent).data('ids', $('.holds_table .select_hold:checked', parent).toArray().map(el => $(el).data('id'))).html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked', parent).length));
localStorage.selectedWaitingHolds = JSON.stringify($('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')));
});
$('.cancel_selected_holds', parent).click(function(e) {
e.preventDefault();
if($('.select_hold:checked', table).length) {
cancel_link = $(this);
$('#cancelModal').modal();
}
return false;
});
});
});
</script>
[% END %]

View File

@ -885,9 +885,16 @@
<input type = "hidden" name="biblionumbers" value="[% biblionumbers | html %]"/>
[% END %]
[% IF enqueued %]
<div class="dialog message">
<p>The job has been enqueued! It will be processed as soon as possible.</p>
<p><a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]" title="View detail of the enqueued job">View detail of the enqueued job</a></p>
</div>
[% END %]
<h2>Existing holds</h2>
<div id="toolbar" class="btn-toolbar">
<input type="submit" name="submit" value="Update hold(s)" />
<input type="submit" name="submit" value="Update hold(s)" /> <button class="cancel_selected_holds" data-bulk="true"></button>
<fieldset id="cancellation-reason-fieldset" class="action">
[% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %]
[% IF hold_cancellation %]
@ -1092,6 +1099,8 @@
cannotBeTransferred: _("Cannot be transferred to pickup library"),
pickupNotInHoldGroup: _("Only pickup locations within the same hold group are allowed")
}
var MSG_CANCEL_SELECTED = _("Cancel selected (%s)");
columns_settings_borrowers_table = [% TablesSettings.GetColumns( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %];
$.fn.select2.defaults.set("width", "100%" );
$.fn.select2.defaults.set("dropdownAutoWidth", true );
@ -1556,11 +1565,20 @@
return false;
});
$("#cancelModalConfirmBtn").on("click",function(e) {
let borrowernumber = cancel_link.data('borrowernumber');
let biblionumber = cancel_link.data('biblionumber');
let reserve_id = cancel_link.data('id');
let link;
if(cancel_link.data('bulk')) {
[% IF biblionumbers %]
link = `request.pl?biblionumbers=[% biblionumbers | url %]&amp;action=cancelBulk&amp;ids=${$('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')).join(',')}`;
[% ELSE %]
link = `request.pl?biblionumber=[% biblionumber | url %]&amp;action=cancelBulk&amp;ids=${$('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')).join(',')}`;
[% END %]
} else {
let borrowernumber = cancel_link.data('borrowernumber');
let biblionumber = cancel_link.data('biblionumber');
let reserve_id = cancel_link.data('id');
link = `request.pl?action=cancel&amp;borrowernumber=${ borrowernumber }&amp;biblionumber=${ biblionumber }&amp;reserve_id=${ reserve_id }`;
}
let reason = $("#modal-cancellation-reason").val();
let link = `request.pl?action=cancel&amp;borrowernumber=${ borrowernumber }&amp;biblionumber=${ biblionumber }&amp;reserve_id=${ reserve_id }`;
if ( reason ) {
link += "&amp;cancellation-reason=" + reason
}
@ -1608,6 +1626,52 @@
stickTo: "#existing_holds",
stickyClass: "floating"
});
if(!localStorage.selectedHolds || document.referrer.replace(/\?.*/, '') !== document.location.origin+document.location.pathname) {
localStorage.selectedHolds = [];
}
$('.holds_table .select_hold').each(function() {
if(localStorage.selectedHolds.includes($(this).data('id'))) {
$(this).prop('checked', true);
}
});
$('.holds_table .select_hold_all').each(function() {
var table = $(this).parents('.holds_table');
var count = $('.select_hold:not(:checked)', table).length;
$('.select_hold_all', table).prop('checked', !count);
});
$('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
$('.holds_table .select_hold_all').click(function() {
var table = $(this).parents('.holds_table');
var count = $('.select_hold:checked', table).length;
$('.select_hold', table).prop('checked', !count);
$(this).prop('checked', !count);
$('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'));
});
$('.holds_table .select_hold').click(function() {
var table = $(this).parents('.holds_table');
var count = $('.select_hold:not(:checked)', table).length;
$('.select_hold_all', table).prop('checked', !count);
$('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'));
});
$('.cancel_selected_holds').click(function(e) {
e.preventDefault();
if($('.holds_table .select_hold:checked').length) {
cancel_link = $(this);
delete localStorage.selectedHolds;
$('#cancelModal').modal();
}
return false;
});
});
</script>
[% END %]

View File

@ -33,6 +33,7 @@ my @job_types = qw(
batch_authority_record_modification
batch_biblio_record_deletion
batch_authority_record_deletion
batch_hold_cancel
);
if ( $conn ) {

View File

@ -52,6 +52,7 @@ use Koha::ItemTypes;
use Koha::Libraries;
use Koha::Patrons;
use Koha::Clubs;
use Koha::BackgroundJob::BatchCancelHold;
my $dbh = C4::Context->dbh;
my $input = CGI->new;
@ -89,30 +90,51 @@ my $action = $input->param('action');
$action ||= q{};
if ( $action eq 'move' ) {
my $where = $input->param('where');
my $reserve_id = $input->param('reserve_id');
my $prev_priority = $input->param('prev_priority');
my $next_priority = $input->param('next_priority');
my $first_priority = $input->param('first_priority');
my $last_priority = $input->param('last_priority');
my $hold_itemnumber = $input->param('itemnumber');
if ( $prev_priority == 0 && $next_priority == 1 ){
C4::Reserves::RevertWaitingStatus({ itemnumber => $hold_itemnumber });
} else {
AlterPriority( $where, $reserve_id, $prev_priority, $next_priority, $first_priority, $last_priority );
}
} elsif ( $action eq 'cancel' ) {
my $reserve_id = $input->param('reserve_id');
my $cancellation_reason = $input->param("cancellation-reason");
my $hold = Koha::Holds->find( $reserve_id );
$hold->cancel({ cancellation_reason => $cancellation_reason }) if $hold;
} elsif ( $action eq 'setLowestPriority' ) {
my $reserve_id = $input->param('reserve_id');
ToggleLowestPriority( $reserve_id );
} elsif ( $action eq 'toggleSuspend' ) {
my $reserve_id = $input->param('reserve_id');
my $suspend_until = $input->param('suspend_until');
ToggleSuspend( $reserve_id, $suspend_until );
my $where = $input->param('where');
my $reserve_id = $input->param('reserve_id');
my $prev_priority = $input->param('prev_priority');
my $next_priority = $input->param('next_priority');
my $first_priority = $input->param('first_priority');
my $last_priority = $input->param('last_priority');
my $hold_itemnumber = $input->param('itemnumber');
if ( $prev_priority == 0 && $next_priority == 1 ) {
C4::Reserves::RevertWaitingStatus( { itemnumber => $hold_itemnumber } );
}
else {
AlterPriority(
$where, $reserve_id, $prev_priority,
$next_priority, $first_priority, $last_priority
);
}
}
elsif ( $action eq 'cancel' ) {
my $reserve_id = $input->param('reserve_id');
my $cancellation_reason = $input->param("cancellation-reason");
my $hold = Koha::Holds->find($reserve_id);
$hold->cancel( { cancellation_reason => $cancellation_reason } ) if $hold;
}
elsif ( $action eq 'setLowestPriority' ) {
my $reserve_id = $input->param('reserve_id');
ToggleLowestPriority($reserve_id);
}
elsif ( $action eq 'toggleSuspend' ) {
my $reserve_id = $input->param('reserve_id');
my $suspend_until = $input->param('suspend_until');
ToggleSuspend( $reserve_id, $suspend_until );
}
elsif ( $action eq 'cancelBulk' ) {
my $cancellation_reason = $input->param("cancellation-reason");
my @hold_ids = split ',', $input->param("ids");
my $params = {
reason => $cancellation_reason,
hold_ids => \@hold_ids,
};
my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params);
$template->param(
enqueued => 1,
job_id => $job_id
);
}
if ($findborrower) {