From 68c2ac189af17b58f195fc17e636f3eba29f8346 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 23 Mar 2018 01:03:00 +0000 Subject: [PATCH] Bug 20467: Add ability to batch add items to a course MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some librarians have requested the ability to batch add items to a course using the same settings for all items. Test Plan: 1) Apply this patch 2) Create a new course 3) Click the new 'Batch add reserves' button 4) Enter some valid and invalid barcodes in the text box, add some settings 5) Submit the batch, note the results list added items and invalid barcodes 6) Note the valid items were added to the course Signed-off-by: Séverine QUEUNE Signed-off-by: Maksim Sen Signed-off-by: Katrin Fischer Signed-off-by: Katrin Fischer --- course_reserves/batch_add_items.pl | 110 ++++++++++++++++ .../en/modules/course_reserves/batch_add_items.tt | 146 +++++++++++++++++++++ .../en/modules/course_reserves/course-details.tt | 1 + 3 files changed, 257 insertions(+) create mode 100755 course_reserves/batch_add_items.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt diff --git a/course_reserves/batch_add_items.pl b/course_reserves/batch_add_items.pl new file mode 100755 index 0000000..04ce037 --- /dev/null +++ b/course_reserves/batch_add_items.pl @@ -0,0 +1,110 @@ +#!/usr/bin/perl + +# +# Copyright 2018 Bywater Solutions +# +# 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::Auth; +use C4::Output; +use C4::Koha; +use C4::CourseReserves qw(ModCourseItem ModCourseReserve GetCourse); + +use Koha::Items; +use Koha::ItemTypes; + +my $cgi = new CGI; + +my $action = $cgi->param('action') || q{}; +my $course_id = $cgi->param('course_id') || q{}; +my $barcodes = $cgi->param('barcodes') || q{}; + +my $itype = $cgi->param('itype'); +my $ccode = $cgi->param('ccode'); +my $holdingbranch = $cgi->param('holdingbranch'); +my $location = $cgi->param('location'); +my $staff_note = $cgi->param('staff_note'); +my $public_note = $cgi->param('public_note'); + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "course_reserves/batch_add_items.tt", + query => $cgi, + type => "intranet", + authnotrequired => 0, + flagsrequired => { coursereserves => 'add_reserves' }, + } +); + +$template->param( course => GetCourse($course_id) ); + +if ( !$action ) { + + my $itemtypes = Koha::ItemTypes->search; + $template->param( + action => 'display_form', + ccodes => GetAuthorisedValues('CCODE'), + locations => GetAuthorisedValues('LOC'), + itypes => $itemtypes, + ); + +} +elsif ( $action eq 'add' ) { + my @barcodes = split( "\r\n", $barcodes ); + + my @items; + my @invalid_barcodes; + for my $b (@barcodes) { + my $item = Koha::Items->find( { barcode => $b } ); + + if ($item) { + push( @items, $item ); + } + else { + push( @invalid_barcodes, $b ); + } + } + + foreach my $item (@items) { + my $ci_id = ModCourseItem( + itemnumber => $item->id, + itype => $itype, + ccode => $ccode, + holdingbranch => $holdingbranch, + location => $location, + ); + + my $cr_id = ModCourseReserve( + course_id => $course_id, + ci_id => $ci_id, + staff_note => $staff_note, + public_note => $public_note, + ); + } + + $template->param( + action => 'display_results', + items_added => \@items, + invalid_barcodes => \@invalid_barcodes, + course_id => $course_id, + ); +} + +output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt new file mode 100644 index 0000000..68998c2 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt @@ -0,0 +1,146 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Course reserves › Add items +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + + +
+
+
+ + [% IF action == 'display_form' %] +
+ + + +
+ Add items: scan barcodes +
    +
  1. + + +
  2. + [% IF item_level_itypes %] +
  3. + + +
  4. + [% END %] + +
  5. + + +
  6. + +
  7. + + +
  8. + +
  9. + + +
  10. + +
  11. + + +
  12. + +
  13. + + +
  14. +
+
+ +

+ Any items with existing course reserves will have their on reserve values updated. +

+ +
+ + + Cancel +
+
+ [% END %] + + [% IF action == 'display_results' %] +

Results

+ +

Items added

+ [% IF items_added.size > 0 %] +

The following items were added or updated:

+
    + [% FOREACH i IN items_added %] +
  • [% i.biblio.title %] ( [% i.barcode %] )
  • + [% END %] +
+ [% ELSE %] + No valid item barcodes found. + [% END %] + + + [% IF invalid_barcodes.size > 0 %] +

Invalid barcodes

+

The following invalid barcodes were skipped:

+
    + [% FOREACH b IN invalid_barcodes %] +
  • [% b %]
  • + [% END %] +
+ [% END %] + +

+ View course +

+ [% END %] +
+
+ +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt index dec2c5d..c4bd75d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt @@ -24,6 +24,7 @@
[% IF CAN_user_coursereserves_add_reserves %] Add reserves + Batch add reserves [% END %] [% IF ( CAN_user_coursereserves_manage_courses ) %] Edit course -- 2.1.4