From 12ec80f7afedf8522c6f470b40da519f425282b3 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Fri, 8 Mar 2024 13:47:16 +0200 Subject: [PATCH] Bug 36135: Allow using SQL results in batch modify holds tool Sponsored-by: Koha-Suomi Oy --- .../modals/batch_modify_hold_errors.inc | 17 ++ .../modules/reports/guided_reports_start.tt | 35 +++- .../en/modules/tools/batch_modify_holds.tt | 188 ++++++++++-------- tools/batch_modify_holds.pl | 12 +- 4 files changed, 159 insertions(+), 93 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/modals/batch_modify_hold_errors.inc diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/batch_modify_hold_errors.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/batch_modify_hold_errors.inc new file mode 100644 index 00000000000..ed9d1526228 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/batch_modify_hold_errors.inc @@ -0,0 +1,17 @@ + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index c61553b88b3..406834a8463 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -1071,6 +1071,19 @@ > +
+ + [% FOREACH result IN results %] + [% FOREACH cells IN result.cells %] + [% place = loop.index %] + [% IF header_row.$place.cell == 'reserve_id' || header_types.item(header_row.$place.cell) == 'reserve_id' %] + [% SET batch_reserve_ids = 1 %] + + [% END %] + [% END %] + [% END %] +
+ [% BLOCK batch_list %] [%- FOREACH result IN results %] [%- FOREACH cells IN result.cells %] @@ -1095,9 +1108,9 @@ - [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_borrowernumbers ) || ( unlimited_total > 10 && limit <= 1000 ) %] + [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_borrowernumbers || batch_reserve_ids ) || ( unlimited_total > 10 && limit <= 1000 ) %]
- [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_borrowernumbers ) %] + [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_borrowernumbers || batch_reserve_ids ) %]
- [% END # /IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) %] + [% END # /IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_reserve_ids ) %] [% IF ( unlimited_total > 10 && limit <= 1000 ) %]
@@ -1238,7 +1265,7 @@
[% END # /IF ( unlimited_total > 10 && limit <= 1000 ) %] - [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) %] + [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_reserve_ids ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_modify_holds.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_modify_holds.tt index 7705c36beb1..166bdd04bc9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_modify_holds.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_modify_holds.tt @@ -14,54 +14,52 @@ - [% WRAPPER 'header.inc' %] +[% WRAPPER 'header.inc' %] [% INCLUDE 'cat-search.inc' %] + [% INCLUDE modals/batch_modify_hold_errors.inc %] [% END %] - - [% WRAPPER 'sub-header.inc' %] - - [% END %] +[% WRAPPER 'sub-header.inc' %] + [% WRAPPER breadcrumbs %] + [% WRAPPER breadcrumb_item %] + Tools + [% END %] + [% IF ( view == 'form' || view == 'report' ) %] + [% WRAPPER breadcrumb_item %] + Batch modify holds + [% END %] + [% ELSE %] + [% WRAPPER breadcrumb_item bc_active= 1 %] + Batch modify holds + [% END %] + [% END %] + [% END #/ WRAPPER breadcrumbs %] +[% END #/ WRAPPER sub-header.inc %]
-
+

Batch modify holds

[% IF view == 'form' %] -
+
Hold search criteria: NOTE! Column patron_expiration_date is used as a main filter for expiration date field. Otherwise column expirationdate is used.
  1. - -
  2. - - -
  3. -
  4. - - -
  5. + + + +
  6. + +
  7. @@ -82,15 +80,12 @@
  8. - -
  9. - - -
  10. -
  11. - - -
  12. + + + +
  13. + +
  14. @@ -106,7 +101,9 @@
  15. [% ELSIF view == 'list' %]
    + [% INCLUDE 'csrf-token.inc' %] [% IF holds.count %] +

    Found [% holds.count | html %][% IF holds.count > 1 %] holds [% ELSE %] hold [% END %]to modify.

    Select all @@ -118,6 +115,8 @@   Expiration date Patron expiration date + Title + Barcode Status Hold pickup library Suspended @@ -131,6 +130,8 @@ [% hold.expirationdate | $KohaDates %] [% hold.patron_expiration_date | $KohaDates %] + [% hold.biblio.title | html %] + [% hold.item.barcode | html %] [% IF hold.found == "T" %] In transit @@ -152,44 +153,47 @@

    Modify holds

    - - - - - - - - - - - - - - - - - - - -
    New expiration dateNew pickup librarySuspend holdsSuspend untilNew reserve note
    - - - - - - - - - -
    +
    + + + + + + + + + + + + + + + + + + + +
    New expiration dateNew pickup librarySuspend holdsSuspend untilNew reserve note
    + + + + + + + + + +
    +
    - + Cancel
    @@ -202,17 +206,15 @@ [% END %] [% ELSIF view == 'report' %]
    - Holds have been modified! + [% updated_holds.count | html %] holds have been modified!
    - + + @@ -223,6 +225,8 @@ [% FOREACH hold IN updated_holds %] + + @@ -244,7 +248,7 @@ - + [% MACRO jsinclude BLOCK %] [% Asset.js("js/tools-menu.js") | $raw %] [% INCLUDE 'calendar.inc' %] @@ -279,28 +283,42 @@ })); $("#process").on('submit', function(e) { + var errors = []; var reserve_ids = $("input[type=checkbox][name='hold_id']:checked"); + var new_pickup_loc = $("#new_pickup_loc").val(); var new_suspend_status = $("#new_suspend_status").val(); var new_suspend_date = $("#new_suspend_date").val(); if ( reserve_ids.length == 0 ) { e.preventDefault(); - alert(_("Please select at least one hold to process.")); + errors.push(_("Please select at least one hold to process.")); return false; } - if( new_suspend_status ){ + if( new_pickup_loc || new_suspend_status ){ reserve_ids.each(function(){ if($(this).parents("tr").children(".found_status").data("found") != ""){ e.preventDefault(); - alert(_("One or more holds have found status and can't be suspended.")); + if( new_suspend_status ){ + errors.push(_("One or more holds have found status and can't be suspended.")); + } + if( new_pickup_loc ){ + errors.push(_("One or more holds have found status and their pick up location can't be changed.")); + } return false; } }) } if( ( !new_suspend_status || new_suspend_status == "not_suspended") && new_suspend_date ){ e.preventDefault(); - alert(_('You have to suspend holds if new suspend until date is set.')); + errors.push(_("You have to suspend holds if new suspend until date is set.")); + return false; + } + + if (errors.length > 0) { + e.preventDefault(); + $("#errorList").html(errors.map(error => `
  16. ${error}
  17. `).join("")); + $("#errorModal").modal('show'); return false; } diff --git a/tools/batch_modify_holds.pl b/tools/batch_modify_holds.pl index af37d5500ed..8d3f29a59a8 100755 --- a/tools/batch_modify_holds.pl +++ b/tools/batch_modify_holds.pl @@ -118,7 +118,10 @@ if ( $op eq 'form' ) { } } - my $holds = Koha::Holds->search($search_params); + my $holds = Koha::Holds->search( + $search_params, + { join => [ "item", "biblio" ] } + ); $template->param( holds => $holds, @@ -126,7 +129,7 @@ if ( $op eq 'form' ) { ); } -if ( $op eq 'modify' ) { +if ( $op eq 'cud-modify' ) { my $new_expiration_date = $input->param('new_expiration_date'); my $new_pickup_loc = $input->param('new_pickup_loc'); @@ -136,7 +139,8 @@ if ( $op eq 'modify' ) { @hold_ids = $input->multi_param('hold_id'); - my $holds_to_update = Koha::Holds->search( { reserve_id => { -in => \@hold_ids } } ); + my $holds_to_update = + Koha::Holds->search( { reserve_id => { -in => \@hold_ids } }, { join => [ "item", "biblio" ] } ); while ( my $hold = $holds_to_update->next ) { @@ -144,7 +148,7 @@ if ( $op eq 'modify' ) { $hold->expirationdate($new_expiration_date)->store; } - unless ( $hold->branchcode eq $new_pickup_loc ) { + if ( $new_pickup_loc && ( $hold->branchcode ne $new_pickup_loc ) ) { $hold->branchcode($new_pickup_loc)->store; } -- 2.39.5
    Expiration dateTitleBarcode Hold pickup library Suspended Suspended until
    [% hold.expirationdate | $KohaDates %][% hold.biblio.title | html %][% hold.item.barcode | html %] [% Branches.GetName( hold.branchcode ) | html %] [% IF hold.suspend == 0 %]No[% ELSE %]Yes[% END %] [% hold.suspend_until | $KohaDates %]