3 # This file is part of Koha.
5 # Copyright (C) 2020 Fenway Library Organization
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use List::MoreUtils qw( uniq );
25 use C4::Auth qw( get_template_and_user );
26 use C4::Circulation qw( barcodedecode );
27 use C4::Output qw( output_html_with_http_headers );
28 use C4::CourseReserves qw( GetCourse GetCourseItem GetItemCourseReservesInfo DelCourse DelCourseReserve );
34 my $action = $cgi->param('action') || q{};
35 my $barcodes = $cgi->param('barcodes') || q{};
37 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39 template_name => "course_reserves/batch_rm_items.tt",
42 flagsrequired => { coursereserves => 'delete_reserves' },
47 $template->param( action => 'display_form' );
50 elsif ( $action eq 'batch_rm' ) {
51 my @barcodes = uniq( split (/\s\n/, $barcodes ) );
55 foreach my $bar (@barcodes) {
56 $bar = barcodedecode($bar) if $bar;
57 my $item = Koha::Items->find( { barcode => $bar } );
59 my $courseitem = GetCourseItem(itemnumber => $item->id);
62 my $res_info = GetItemCourseReservesInfo(itemnumber => $item->id);
64 my $no_of_res = @$res_info;
66 my $delitemcount = {'delitem' => $item, 'delcount' => $no_of_res};
67 push ( @item_and_count, $delitemcount );
69 foreach my $cr (@$res_info) {
71 DelCourseReserve('cr_id' => $cr->{cr_id});
76 push( @invalid_barcodes, $bar);
80 push( @invalid_barcodes, $bar );
86 action => 'display_results',
87 invalid_barcodes => \@invalid_barcodes,
88 item_and_count => \@item_and_count,
92 output_html_with_http_headers $cgi, $cookie, $template->output;