From 8159df2867d6496bafed77128eb7da3be738aa51 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Tue, 6 Sep 2016 16:43:04 +0200 Subject: [PATCH] Bug 23258: Batch holding This patch allows to batch place or cancel holds. Test plan: 1) Apply the patch 2) Go to Circulation -> Batch holding 3) Check that you can either upload a barcode file or use the textarea 4) Check that you can place holds on items 5) Check that you can cancel holds on items --- circ/batch_holding.pl | 152 +++++++++++++++++++ .../prog/en/modules/circ/batch_holding.tt | 165 +++++++++++++++++++++ .../prog/en/modules/circ/circulation-home.tt | 3 + 3 files changed, 320 insertions(+) create mode 100755 circ/batch_holding.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/circ/batch_holding.tt diff --git a/circ/batch_holding.pl b/circ/batch_holding.pl new file mode 100755 index 0000000..dcbed73 --- /dev/null +++ b/circ/batch_holding.pl @@ -0,0 +1,152 @@ +#!/usr/bin/perl + +# Copyright 2019 BibLibre +# +# 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 . + +use Modern::Perl; +use CGI qw ( -utf8 ); + +use C4::Output; +use C4::Auth; +use Koha::Items; +use C4::Reserves; +use List::MoreUtils qw/uniq/; + + +my $input = new CGI; +my $op = $input->param('op'); +my @itemnumbers; + +my @errors; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "circ/batch_holding.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + } +); + +if ($op eq "show"){ + my $filefh = $input->upload('uploadfile'); + my $filecontent = $input->param('filecontent'); + my $borrowernumber = $input->param('borrowernumber'); + my $branch = $input->param('branch'); + my $action = $input->param('action'); + my @notfoundbarcodes; + + my @contentlist; + if ($filefh){ + while (my $content=<$filefh>){ + $content =~ s/[\r\n]*$//; + push @contentlist, $content if $content; + } + + foreach my $barcode (@contentlist) { + my $item = Koha::Items->find({ barcode => $barcode }); + if ($item) { + push @itemnumbers,$item->itemnumber; + } else { + push @notfoundbarcodes, $barcode; + } + } + } else { + if ( my $list=$input->param('barcodelist')){ + push my @barcodelist, uniq( split(/\s\n/, $list) ); + + foreach my $barcode (@barcodelist) { + + my $item = Koha::Items->find({ barcode => $barcode }); + if ($item) { + push @itemnumbers,$item->itemnumber; + } else { + push @notfoundbarcodes, $barcode; + } + } + + } + } + if (@notfoundbarcodes) { + my @notfoundbarcodesloop = map{{barcode=>$_}}@notfoundbarcodes; + $template->param(notfoundbarcodes => \@notfoundbarcodesloop); + } + my @holdloop; + if (@itemnumbers) { + foreach my $itemnumber (@itemnumbers) { + my $item = Koha::Items->find({ itemnumber => $itemnumber }); + my $holdable = CanItemBeReserved($borrowernumber, $item->itemnumber)->{status}; + push @holdloop, { + 'itemnumber' => $item->itemnumber, + 'barcode' => $item->barcode, + 'holdable' => ($action eq "cancel" || $holdable eq 'OK') ? 1 : 0, + }; + } + + } + $template->param( + show => 1, + holdloop => \@holdloop, + borrowernumber => $borrowernumber, + branch => $branch, + action => $action, + ); +} + +elsif ($op eq "result") { + my $branch = $input->param('branch'); + my $borrowernumber = $input->param('borrowernumber'); + my $action = $input->param('action'); + my @itemnumbers = $input->multi_param('holdable'); + my @holdloop; + foreach my $itemnumber (@itemnumbers) { + if ($action eq "place") { + my $item = Koha::Items->find({ itemnumber => $itemnumber }); + my $biblionumber = $item->biblionumber; + my $reserve_id = AddReserve({ + branchcode => $branch, + borrowernumber => $borrowernumber, + biblionumber => $biblionumber, + itemnumber => $itemnumber + }); + push @holdloop, { + 'itemnumber' => $itemnumber, + 'reserve_id' => $reserve_id, + }; + } else { + my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber }); + if ($holds) { + while ( my $hold = $holds->next ) { + $hold->cancel; + } + + push @holdloop, { + 'itemnumber' => $itemnumber, + }; + } + } + } + + $template->param( + result => 1, + holdloop => \@holdloop, + cancel => $action eq "cancel" ? 1 : 0, + place => $action eq "place" ? 1 : 0, + ); + +} +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/batch_holding.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/batch_holding.tt new file mode 100644 index 0000000..9ecc04f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/batch_holding.tt @@ -0,0 +1,165 @@ +[% USE Branches %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Circulation › Batch holding +[% INCLUDE 'doc-head-close.inc' %] + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cataloging-search.inc' %] + + +
+ +
+
+[% IF show %] + [% IF ( notfoundbarcodes ) %] +

Warning, the following barcodes were not found:

+ + + + + + [% FOREACH notfoundbarcode IN notfoundbarcodes %] + + [% END %] + +
Barcodes not found
[% notfoundbarcode.barcode %]
+ [% END %] + + [% IF (holdloop) %] +

[% action %] holds on the following barcodes

+
+
    + [% FOREACH hold IN holdloop %] +
  • + [% IF hold.holdable %] + + [% hold.barcode %] + [% ELSE %] + [% hold.barcode %] (This item cannot be reserved) + [% END %] +
  • + [% END %] +
+ + + + + +
+ [% ELSE %] +

No reservation can be placed or cancelled.

+ Batch place or cancel other items + [% END %] + +[% ELSIF result %] + [% IF (holdloop) %] +

Results

+
    + [% IF place %] + The following items have been reserved: +
      + [% FOREACH hold IN holdloop %] +
    • itemnumber [% hold.itemnumber %], reserve_id [% hold.reserve_id %]
    • + [% END %] +
    + [% END %] + [% IF cancel %] + The following reservations were cancelled: +
      + [% FOREACH hold IN holdloop %] +
    • itemnumber [% hold.itemnumber %]
    • + [% END %] +
    + [% END %] +
+ [% ELSE %] +

No reservation could be placed or cancelled.

+ [% END %] + Batch place or cancel other items +[% ELSE %] +

Batch holding

+
+
+ Use a barcode file + +
+
+ Or scan items one by one +
    +
  1. + + +
  2. +
+
+
+ Holding informations +
    +
  1. + + +
    + +
    +
  2. +
  3. + + + +
  4. +
+
+
+ Action +
    +
  1. + + +
  2. +
  3. + + +
  4. +
+
+ + +
+[% END %] +
+
+
+ +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt index fbabec6..a16f72c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt @@ -69,6 +69,9 @@
  • Hold ratios
  • +
  • + Batch holding +
  • -- 2.7.4