Bug 23435: Add multiple copies of an item when receiving in serials
[koha.git] / course_reserves / batch_add_items.pl
blob76d0caa0b546eb8199418b72ee863d2c46920ba0
1 #!/usr/bin/perl
4 # Copyright 2018 Bywater Solutions
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Modern::Perl;
23 use CGI qw( -utf8 );
24 use List::MoreUtils qw( uniq );
26 use C4::Auth;
27 use C4::Output;
28 use C4::CourseReserves qw(ModCourseItem ModCourseReserve GetCourse);
30 use Koha::Items;
32 my $cgi = new CGI;
34 my $action = $cgi->param('action') || q{};
35 my $course_id = $cgi->param('course_id') || q{};
36 my $barcodes = $cgi->param('barcodes') || q{};
38 my $itype = $cgi->param('itype');
39 my $ccode = $cgi->param('ccode');
40 my $holdingbranch = $cgi->param('holdingbranch');
41 my $location = $cgi->param('location');
42 my $staff_note = $cgi->param('staff_note');
43 my $public_note = $cgi->param('public_note');
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47 template_name => "course_reserves/batch_add_items.tt",
48 query => $cgi,
49 type => "intranet",
50 authnotrequired => 0,
51 flagsrequired => { coursereserves => 'add_reserves' },
55 my $course = GetCourse($course_id);
57 if ( $course_id && $course ) {
58 $template->param( course => $course );
60 if ( !$action ) {
61 $template->param( action => 'display_form' );
63 elsif ( $action eq 'add' ) {
64 my @barcodes = uniq( split( /\s\n/, $barcodes ) );
66 my @items;
67 my @invalid_barcodes;
68 for my $b (@barcodes) {
69 my $item = Koha::Items->find( { barcode => $b } );
71 if ($item) {
72 push( @items, $item );
74 else {
75 push( @invalid_barcodes, $b );
79 foreach my $item (@items) {
80 my $ci_id = ModCourseItem(
81 itemnumber => $item->id,
82 itype => $itype,
83 ccode => $ccode,
84 holdingbranch => $holdingbranch,
85 location => $location,
88 my $cr_id = ModCourseReserve(
89 course_id => $course_id,
90 ci_id => $ci_id,
91 staff_note => $staff_note,
92 public_note => $public_note,
96 $template->param(
97 action => 'display_results',
98 items_added => \@items,
99 invalid_barcodes => \@invalid_barcodes,
100 course_id => $course_id,
103 } else {
104 $template->param( action => 'invalid_course' );
107 output_html_with_http_headers $cgi, $cookie, $template->output;