Bugzilla – Attachment 183295 Details for
Bug 36135
Add tool to batch modify holds
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36135: Allow using SQL results in batch modify holds tool
Bug-36135-Allow-using-SQL-results-in-batch-modify-.patch (text/plain), 27.86 KB, created by
Lucas Gass (lukeg)
on 2025-06-16 22:09:40 UTC
(
hide
)
Description:
Bug 36135: Allow using SQL results in batch modify holds tool
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2025-06-16 22:09:40 UTC
Size:
27.86 KB
patch
obsolete
>From 12ec80f7afedf8522c6f470b40da519f425282b3 Mon Sep 17 00:00:00 2001 >From: Emmi Takkinen <emmi.takkinen@koha-suomi.fi> >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 @@ >+<!-- Batch modify hold error modal --> >+<div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="errorModalLabel"> >+ <div class="modal-dialog"> >+ <div class="modal-content"> >+ <div class="modal-header"> >+ <h1 class="modal-title" id="errorModalLabel">Errors</h1> >+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> >+ </div> >+ <div class="modal-body"> >+ <ul id="errorList"></ul> >+ </div> >+ <div class="modal-footer"> >+ <button type="button" class="btn btn-primary" data-bs-dismiss="modal">OK</button> >+ </div> >+ </div> >+ </div> >+</div> >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 @@ > > > </form> > >+ <form method="get" action="/cgi-bin/koha/tools/batch_modify_holds.pl" id="batch_modify_holds"> >+ <input type="hidden" name="op" value="list" /> >+ [% 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 %] >+ <input type="hidden" name="reserve_ids" value="[% cells.cell | html %]" /> >+ [% END %] >+ [% END %] >+ [% END %] >+ </form> >+ > [% BLOCK batch_list %] > [%- FOREACH result IN results %] > [%- FOREACH cells IN result.cells %] >@@ -1095,9 +1108,9 @@ > </form> > <!-- /#limitselect --> > >- [% 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 ) %] > <div id="toolbar" class="btn-toolbar"> >- [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_borrowernumbers ) %] >+ [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_borrowernumbers || batch_reserve_ids ) %] > <div class="btn-group"> > <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="batch_mod_menu" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> > Batch operations with [% IF unlimited_total >= limit %][% results.size | html %][% ELSE %][% unlimited_total | html %][% END %] visible records >@@ -1205,12 +1218,26 @@ > > > </li> > [% END %] >+ [% IF header_ro.cell == 'reserve_id' || header_types.item( header_ro.cell ) == 'reserve_id' %] >+ <li class="dropdown-header">Hold records</li> >+ <li> >+ <a >+ href="#" >+ data-submit="batch_modify_holds" >+ data-toggle="tooltip" >+ data-placement="right" >+ title="Send visible results to batch hold modification" >+ class="batch_op send_to_hold_mod" >+ >Batch hold modification</a >+ > >+ </li> >+ [% END %] > [% END # /FOREACH header_ro %] > </ul> > <!-- /.dropdown-menu --> > </div> > <!-- /.dropdown --> >- [% 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 ) %] > <div class="btn-group"> >@@ -1238,7 +1265,7 @@ > </div> > [% END # /IF ( unlimited_total > 10 && limit <= 1000 ) %] > >- [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers ) %] >+ [% IF ( batch_biblionumbers || batch_itemnumbers || batch_cardnumbers || batch_reserve_ids ) %] > <a href="#" class="btn btn-link" id="toggle_auto_links"> > <i class="fa-solid fa-eye autolink" aria-hidden="true" style="display:none"></i> > <i class="fa-solid fa-eye-slash autolink" aria-hidden="true"></i> >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 @@ > </head> > > <body id="tools_batch_extend_due_dates" class="tools"> >- [% WRAPPER 'header.inc' %] >+[% WRAPPER 'header.inc' %] > [% INCLUDE 'cat-search.inc' %] >+ [% INCLUDE modals/batch_modify_hold_errors.inc %] > [% END %] >- >- [% WRAPPER 'sub-header.inc' %] >- <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb"> >- <ol> >- <li> >- <a href="/cgi-bin/koha/mainpage.pl">Home</a> >- </li> >- <li> >- <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> >- </li> >- <li> >- <a href="#" aria-current="page">Batch modify holds</a> >- </li> >- </ol> >- </nav> >- [% END %] >+[% WRAPPER 'sub-header.inc' %] >+ [% WRAPPER breadcrumbs %] >+ [% WRAPPER breadcrumb_item %] >+ <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> >+ [% END %] >+ [% IF ( view == 'form' || view == 'report' ) %] >+ [% WRAPPER breadcrumb_item %] >+ <a href="/cgi-bin/koha/tools/batch_modify_holds.pl">Batch modify holds</a> >+ [% END %] >+ [% ELSE %] >+ [% WRAPPER breadcrumb_item bc_active= 1 %] >+ <span>Batch modify holds</span> >+ [% END %] >+ [% END %] >+ [% END #/ WRAPPER breadcrumbs %] >+[% END #/ WRAPPER sub-header.inc %] > > <div class="main container-fluid"> > <div class="row"> >- <div class="col-sm-10 col-sm-push-2"> >+ <div class="col-sm-10 order-md-2 order-sm-1"> > <main> > > <h1>Batch modify holds</h1> > > [% IF view == 'form' %] >- <form method="post" action="/cgi-bin/koha/tools/batch_modify_holds.pl" id="modify_holds_form"> >+ <form method="get" action="/cgi-bin/koha/tools/batch_modify_holds.pl" id="modify_holds_form"> > <fieldset class="rows"> > <legend>Hold search criteria:</legend> > <span class="hint">NOTE! Column patron_expiration_date is used as a main filter for expiration date field. Otherwise column expirationdate is used.</span> > <ol> > <li> >- <label for="suspend_until">Expiration date:</label> >- <li> >- <label for="expirationdate_from">From</label> >- <input type="text" size="10" id="from" name="expirationdate_from" class="flatpickr" data-date_to="to" /> >- </li> >- <li> >- <label for="expirationdate_to">To</label> >- <input type="text" size="10" id="to" name="expirationdate_to" class="flatpickr"/> >- </li> >+ <label for="expirationdate_from">Expiration date from:</label> >+ <input type="text" size="10" id="expirationdate_from" name="expirationdate_from" class="flatpickr" data-date_to="to" /> >+ </li> >+ <li> >+ <label for="expirationdate_to">Expiration date to:</label> >+ <input type="text" size="10" id="expirationdate_to" name="expirationdate_to" class="flatpickr"/> > </li> > <li> > <label for="branchcodes">Libraries:</label> > <select name="branchcodes" id="branchcodes" multiple="multiple"> >- [% PROCESS options_for_libraries libraries => Branches.all() %] >+ [% PROCESS options_for_libraries libraries => Branches.all(selected => "") %] > </select> > </li> > <li> >@@ -82,15 +80,12 @@ > </select> > </li> > <li> >- <label for="suspend_until">Suspended until:</label> >- <li> >- <label for="suspend_until_from">From</label> >- <input type="text" size="10" id="from" name="suspend_until_from" class="flatpickr" data-date_to="to" /> >- </li> >- <li> >- <label for="suspend_until_to">To</label> >- <input type="text" size="10" id="to" name="suspend_until_to" class="flatpickr"/> >- </li> >+ <label for="suspend_until_from">Suspended until from:</label> >+ <input type="text" size="10" id="suspend_until_from" name="suspend_until_from" class="flatpickr" data-date_to="to" /> >+ </li> >+ <li> >+ <label for="suspend_until_to">Suspended until to:</label> >+ <input type="text" size="10" id="suspend_until_to" name="suspend_until_to" class="flatpickr"/> > </li> > <li> > <label for="reservenotes">Hold note:</label> >@@ -106,7 +101,9 @@ > </form> <!-- /#modify_holds_form --> > [% ELSIF view == 'list' %] > <form action="/cgi-bin/koha/tools/batch_modify_holds.pl" method="post" id="process"> >+ [% INCLUDE 'csrf-token.inc' %] > [% IF holds.count %] >+ <div><p>Found [% holds.count | html %][% IF holds.count > 1 %] holds [% ELSE %] hold [% END %]to modify.</p></div> > <div class="page-section"> > <div class="btn-toolbar selections-toolbar"> > <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a> >@@ -118,6 +115,8 @@ > <th> </th> > <th>Expiration date</th> > <th>Patron expiration date</th> >+ <th>Title</th> >+ <th>Barcode</th> > <th>Status</th> > <th>Hold pickup library</th> > <th>Suspended</th> >@@ -131,6 +130,8 @@ > <td><input type="checkbox" name="hold_id" value="[% hold.reserve_id | html %]"/></td> > <td>[% hold.expirationdate | $KohaDates %]</td> > <td>[% hold.patron_expiration_date | $KohaDates %]</td> >+ <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% hold.biblionumber | uri %]">[% hold.biblio.title | html %]</a></td> >+ <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% hold.itemnumber | uri %]&biblionumber=[% hold.biblionumber | uri %]&bi=[% hold.biblionumber | uri %]#item[% hold.itemnumber | uri %]">[% hold.item.barcode | html %]</a></td> > <td class="found_status" data-found="[% hold.found | html %]"> > [% IF hold.found == "T" %] > In transit >@@ -152,44 +153,47 @@ > </table> <!-- /#holds --> > </div> <!-- /.page-section --> > <h2>Modify holds</h2> >- <table id="hold_modifies"> >- <thead> >- <tr> >- <th>New expiration date</th> >- <th>New pickup library</th> >- <th>Suspend holds</th> >- <th>Suspend until</th> >- <th>New reserve note</th> >- </tr> >- </thead> >- <tbody> >- <tr> >- <td> >- <input type="text" id="new_expiration_date" name="new_expiration_date" class="flatpickr" data-flatpickr-futuredate="true"/> >- </td> >- <td> >- <select name="new_pickup_loc" id="new_pickup_loc"> >- [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ selected => hold.branchcode }) %] >- </select> >- </td> >- <td> >- <select id="new_suspend_status" name="new_suspend_status"> >- <option value="" selected="selected"></option> >- <option value="not_suspended">Not suspended</option> >- <option value="suspend">Suspend</option> >- </select> >- </td> >- <td> >- <input type="text" id="new_suspend_date" name="new_suspend_date" class="flatpickr" data-flatpickr-futuredate="true"/> >- </td> >- <td> >- <input type="text" id="new_reserve_note" name="new_reserve_note"/> >- </td> >- </tr> >- </tbody> >- </table> <!-- /#hold_modifies --> >+ <div class="page-section"> >+ <table id="hold_modifies"> >+ <thead> >+ <tr> >+ <th>New expiration date</th> >+ <th>New pickup library</th> >+ <th>Suspend holds</th> >+ <th>Suspend until</th> >+ <th>New reserve note</th> >+ </tr> >+ </thead> >+ <tbody> >+ <tr> >+ <td> >+ <input type="text" id="new_expiration_date" name="new_expiration_date" class="flatpickr" data-flatpickr-futuredate="true"/> >+ </td> >+ <td> >+ <select id="new_pickup_loc" name="new_pickup_loc"> >+ <option value="" selected="selected"></option> >+ [% PROCESS options_for_libraries libraries => Branches.pickup_locations(selected = "") %] >+ </select> >+ </td> >+ <td> >+ <select id="new_suspend_status" name="new_suspend_status"> >+ <option value="" selected="selected"></option> >+ <option value="not_suspended">Not suspended</option> >+ <option value="suspend">Suspend</option> >+ </select> >+ </td> >+ <td> >+ <input type="text" id="new_suspend_date" name="new_suspend_date" class="flatpickr" data-flatpickr-futuredate="true"/> >+ </td> >+ <td> >+ <input type="text" id="new_reserve_note" name="new_reserve_note"/> >+ </td> >+ </tr> >+ </tbody> >+ </table> <!-- /#hold_modifies --> >+ </div> > <fieldset class="action"> >- <input type="hidden" name="op" value="modify"/> >+ <input type="hidden" name="op" value="cud-modify"/> > <input type="submit" class="btn btn-primary" value="Modify selected holds"/> > <a class="cancel" href="/cgi-bin/koha/tools/batch_modify_holds.pl">Cancel</a> > </fieldset> >@@ -202,17 +206,15 @@ > [% END %] > [% ELSIF view == 'report' %] > <div class="dialog message"> >- Holds have been modified! >+ [% updated_holds.count | html %] holds have been modified! > </div> > <div class="page-section"> >- <div class="btn-toolbar selections-toolbar"> >- <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a> >- <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a> >- </div> > <table id="holds"> > <thead> > <tr> > <th>Expiration date</th> >+ <th>Title</th> >+ <th>Barcode</th> > <th>Hold pickup library</th> > <th>Suspended</th> > <th>Suspended until</th> >@@ -223,6 +225,8 @@ > [% FOREACH hold IN updated_holds %] > <tr> > <td>[% hold.expirationdate | $KohaDates %]</td> >+ <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% hold.biblionumber | uri %]">[% hold.biblio.title | html %]</a></td> >+ <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% hold.itemnumber | uri %]&biblionumber=[% hold.biblionumber | uri %]&bi=[% hold.biblionumber | uri %]#item[% hold.itemnumber | uri %]">[% hold.item.barcode | html %]</a></td> > <td>[% Branches.GetName( hold.branchcode ) | html %]</td> > <td>[% IF hold.suspend == 0 %]No[% ELSE %]Yes[% END %]</td> > <td>[% hold.suspend_until | $KohaDates %]</td> >@@ -244,7 +248,7 @@ > </aside> > </div> <!-- /.col-sm-2 col-sm-pull-10 --> > </div> <!-- /.row --> >- >+ </div> > [% 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 => `<li>${error}</li>`).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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36135
:
163021
|
163022
|
163023
|
163024
|
163529
|
163530
|
163540
|
163541
|
163542
|
163543
|
163544
|
163796
|
164037
|
164051
|
164057
|
164058
|
164059
|
164060
|
164061
|
164062
|
164063
|
177518
|
177519
|
177959
|
177960
|
177961
|
177962
|
177963
|
177964
|
177965
|
177966
|
177967
|
177968
|
177969
|
177975
|
177976
|
177981
|
177982
|
178154
|
178155
|
178156
|
178157
|
178158
|
178159
|
178160
|
178161
|
178162
|
178163
|
178164
|
178165
|
178166
|
178167
|
178954
|
179028
|
179029
|
179030
|
179031
|
179032
|
179033
|
179034
|
179035
|
179036
|
179037
|
179038
|
179039
|
179040
|
179041
|
179042
|
179081
|
179082
|
181049
|
183151
|
183294
|
183295
|
183296
|
183297
|
183298
|
183299
|
183300
|
183305
|
183306
|
183307
|
183308
|
183771