Bug 26846: Fix regressions - Preselect expected and late serials
[koha.git] / course_reserves / batch_rm_items.pl
blobbd78bc41c91f5199a8c9b1dfe8028ae30ab7a675
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
22 use CGI qw( -utf8 );
23 use List::MoreUtils qw( uniq );
25 use C4::Auth;
26 use C4::Output;
27 use C4::CourseReserves qw(GetItemCourseReservesInfo DelCourseReserve GetCourseItem);
29 use Koha::Items;
31 my $cgi = CGI->new;
33 my $action = $cgi->param('action') || q{};
34 my $barcodes = $cgi->param('barcodes') || q{};
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38 template_name => "course_reserves/batch_rm_items.tt",
39 query => $cgi,
40 type => "intranet",
41 flagsrequired => { coursereserves => 'delete_reserves' },
45 if ( !$action ) {
46 $template->param( action => 'display_form' );
49 elsif ( $action eq 'batch_rm' ) {
50 my @barcodes = uniq( split (/\s\n/, $barcodes ) );
51 my @invalid_barcodes;
52 my @item_and_count;
54 foreach my $bar (@barcodes) {
55 my $item = Koha::Items->find( { barcode => $bar } );
56 if($item) {
57 my $courseitem = GetCourseItem(itemnumber => $item->id);
58 if($courseitem) {
60 my $res_info = GetItemCourseReservesInfo(itemnumber => $item->id);
62 my $no_of_res = @$res_info;
64 my $delitemcount = {'delitem' => $item, 'delcount' => $no_of_res};
65 push ( @item_and_count, $delitemcount );
67 foreach my $cr (@$res_info) {
68 if($cr->{cr_id}) {
69 DelCourseReserve('cr_id' => $cr->{cr_id});
73 else {
74 push( @invalid_barcodes, $bar);
77 else {
78 push( @invalid_barcodes, $bar );
83 $template->param(
84 action => 'display_results',
85 invalid_barcodes => \@invalid_barcodes,
86 item_and_count => \@item_and_count,
90 output_html_with_http_headers $cgi, $cookie, $template->output;