Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2019 BibLibre |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
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. |
11 |
# |
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. |
16 |
# |
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>. |
19 |
|
20 |
use Modern::Perl; |
21 |
use CGI qw ( -utf8 ); |
22 |
|
23 |
use C4::Output; |
24 |
use C4::Auth; |
25 |
use Koha::Items; |
26 |
use C4::Reserves; |
27 |
use List::MoreUtils qw/uniq/; |
28 |
|
29 |
|
30 |
my $input = new CGI; |
31 |
my $op = $input->param('op'); |
32 |
my @itemnumbers; |
33 |
|
34 |
my @errors; |
35 |
|
36 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
37 |
{ |
38 |
template_name => "circ/batch_holding.tt", |
39 |
query => $input, |
40 |
type => "intranet", |
41 |
authnotrequired => 0, |
42 |
} |
43 |
); |
44 |
|
45 |
if ($op eq "show"){ |
46 |
my $filefh = $input->upload('uploadfile'); |
47 |
my $filecontent = $input->param('filecontent'); |
48 |
my $borrowernumber = $input->param('borrowernumber'); |
49 |
my $branch = $input->param('branch'); |
50 |
my $action = $input->param('action'); |
51 |
my @notfoundbarcodes; |
52 |
|
53 |
my @contentlist; |
54 |
if ($filefh){ |
55 |
while (my $content=<$filefh>){ |
56 |
$content =~ s/[\r\n]*$//; |
57 |
push @contentlist, $content if $content; |
58 |
} |
59 |
|
60 |
foreach my $barcode (@contentlist) { |
61 |
my $item = Koha::Items->find({ barcode => $barcode }); |
62 |
if ($item) { |
63 |
push @itemnumbers,$item->itemnumber; |
64 |
} else { |
65 |
push @notfoundbarcodes, $barcode; |
66 |
} |
67 |
} |
68 |
} else { |
69 |
if ( my $list=$input->param('barcodelist')){ |
70 |
push my @barcodelist, uniq( split(/\s\n/, $list) ); |
71 |
|
72 |
foreach my $barcode (@barcodelist) { |
73 |
|
74 |
my $item = Koha::Items->find({ barcode => $barcode }); |
75 |
if ($item) { |
76 |
push @itemnumbers,$item->itemnumber; |
77 |
} else { |
78 |
push @notfoundbarcodes, $barcode; |
79 |
} |
80 |
} |
81 |
|
82 |
} |
83 |
} |
84 |
if (@notfoundbarcodes) { |
85 |
my @notfoundbarcodesloop = map{{barcode=>$_}}@notfoundbarcodes; |
86 |
$template->param(notfoundbarcodes => \@notfoundbarcodesloop); |
87 |
} |
88 |
my @holdloop; |
89 |
if (@itemnumbers) { |
90 |
foreach my $itemnumber (@itemnumbers) { |
91 |
my $item = Koha::Items->find({ itemnumber => $itemnumber }); |
92 |
my $holdable = CanItemBeReserved($borrowernumber, $item->itemnumber); |
93 |
push @holdloop, { |
94 |
'itemnumber' => $item->itemnumber, |
95 |
'barcode' => $item->barcode, |
96 |
'holdable' => ($action eq "cancel" || $holdable eq 'OK') ? 1 : 0, |
97 |
}; |
98 |
} |
99 |
|
100 |
} |
101 |
$template->param( |
102 |
show => 1, |
103 |
holdloop => \@holdloop, |
104 |
borrowernumber => $borrowernumber, |
105 |
branch => $branch, |
106 |
action => $action, |
107 |
); |
108 |
} |
109 |
|
110 |
elsif ($op eq "result") { |
111 |
my $branch = $input->param('branch'); |
112 |
my $borrowernumber = $input->param('borrowernumber'); |
113 |
my $action = $input->param('action'); |
114 |
my @itemnumbers = $input->multi_param('holdable'); |
115 |
my @holdloop; |
116 |
foreach my $itemnumber (@itemnumbers) { |
117 |
if ($action eq "place") { |
118 |
my $item = Koha::Items->find({ itemnumber => $itemnumber }); |
119 |
my $biblionumber = $item->biblionumber; |
120 |
my $reserve_id = AddReserve($branch, $borrowernumber, $biblionumber, undef, undef, undef, undef, undef, undef, $itemnumber, undef); |
121 |
push @holdloop, { |
122 |
'itemnumber' => $itemnumber, |
123 |
'reserve_id' => $reserve_id, |
124 |
}; |
125 |
} else { |
126 |
my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber }); |
127 |
if ($holds) { |
128 |
while ( my $hold = $holds->next ) { |
129 |
$hold->cancel; |
130 |
} |
131 |
|
132 |
push @holdloop, { |
133 |
'itemnumber' => $itemnumber, |
134 |
}; |
135 |
} |
136 |
} |
137 |
} |
138 |
|
139 |
$template->param( |
140 |
result => 1, |
141 |
holdloop => \@holdloop, |
142 |
cancel => $action eq "cancel" ? 1 : 0, |
143 |
place => $action eq "place" ? 1 : 0, |
144 |
); |
145 |
|
146 |
} |
147 |
output_html_with_http_headers $input, $cookie, $template->output; |