@@ -, +, @@ --- 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 --- a/course_reserves/batch_add_items.pl +++ a/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); + +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; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt +++ a/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' %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt +++ a/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 --