Lines 37-42
use C4::Dates qw/format_date format_date_in_iso/;
Link Here
|
37 |
use C4::Koha; |
37 |
use C4::Koha; |
38 |
use C4::Branch; # GetBranches |
38 |
use C4::Branch; # GetBranches |
39 |
use C4::Circulation; |
39 |
use C4::Circulation; |
|
|
40 |
use C4::Reports::Guided; #_get_column_defs |
41 |
use C4::Charset; |
42 |
use List::MoreUtils qw/none/; |
43 |
|
40 |
|
44 |
|
41 |
my $minlocation=$input->param('minlocation') || ''; |
45 |
my $minlocation=$input->param('minlocation') || ''; |
42 |
my $maxlocation=$input->param('maxlocation'); |
46 |
my $maxlocation=$input->param('maxlocation'); |
Lines 52-77
my $pagesize = $input->param('pagesize');
Link Here
|
52 |
$pagesize=50 unless $pagesize; |
56 |
$pagesize=50 unless $pagesize; |
53 |
my $branchcode = $input->param('branchcode') || ''; |
57 |
my $branchcode = $input->param('branchcode') || ''; |
54 |
my $branch = $input->param('branch'); |
58 |
my $branch = $input->param('branch'); |
55 |
my $op = $input->param('op'); |
59 |
my $op = $input->param('op'); |
56 |
my $res; #contains the results loop |
60 |
my $compareinv2barcd = $input->param('compareinv2barcd'); |
57 |
# warn "uploadbarcodes : ".$uploadbarcodes; |
61 |
my $res; #contains the results loop |
58 |
# use Data::Dumper; warn Dumper($input); |
62 |
|
59 |
|
63 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
60 |
my ($template, $borrowernumber, $cookie) |
64 |
{ template_name => "tools/inventory.tmpl", |
61 |
= get_template_and_user({template_name => "tools/inventory.tmpl", |
65 |
query => $input, |
62 |
query => $input, |
66 |
type => "intranet", |
63 |
type => "intranet", |
67 |
authnotrequired => 0, |
64 |
authnotrequired => 0, |
68 |
flagsrequired => { tools => 'inventory' }, |
65 |
flagsrequired => {tools => 'inventory'}, |
69 |
debug => 1, |
66 |
debug => 1, |
70 |
} |
67 |
}); |
71 |
); |
|
|
72 |
|
68 |
|
73 |
|
69 |
my $branches = GetBranches(); |
74 |
my $branches = GetBranches(); |
70 |
my @branch_loop; |
75 |
my @branch_loop; |
71 |
for my $branch_hash (keys %$branches) { |
76 |
for my $branch_hash (keys %$branches) { |
72 |
push @branch_loop, {value => "$branch_hash", |
77 |
push @branch_loop, {value => "$branch_hash", |
73 |
branchname => $branches->{$branch_hash}->{'branchname'}, |
78 |
branchname => $branches->{$branch_hash}->{'branchname'}, |
74 |
selected => ($branch_hash eq $branchcode?1:0)}; |
79 |
selected => ($branch_hash eq $branchcode?1:0)}; |
75 |
} |
80 |
} |
76 |
|
81 |
|
77 |
@branch_loop = sort {$a->{branchname} cmp $b->{branchname}} @branch_loop; |
82 |
@branch_loop = sort {$a->{branchname} cmp $b->{branchname}} @branch_loop; |
Lines 89-95
for my $fwk (keys %$frameworks){
Link Here
|
89 |
my $data=GetAuthorisedValues($authcode); |
94 |
my $data=GetAuthorisedValues($authcode); |
90 |
foreach my $value (@$data){ |
95 |
foreach my $value (@$data){ |
91 |
$value->{selected}=1 if ($value->{authorised_value} eq ($location)); |
96 |
$value->{selected}=1 if ($value->{authorised_value} eq ($location)); |
92 |
} |
97 |
} |
93 |
push @authorised_value_list,@$data; |
98 |
push @authorised_value_list,@$data; |
94 |
} |
99 |
} |
95 |
} |
100 |
} |
Lines 105-166
for my $statfield (qw/items.notforloan items.itemlost items.wthdrawn items.damag
Link Here
|
105 |
push @$statuses, $hash; |
110 |
push @$statuses, $hash; |
106 |
} |
111 |
} |
107 |
} |
112 |
} |
|
|
113 |
|
114 |
|
108 |
$template->param( statuses => $statuses ); |
115 |
$template->param( statuses => $statuses ); |
109 |
my $staton = {}; #authorized values that are ticked |
116 |
my $staton = {}; #authorized values that are ticked |
110 |
for my $authvfield (@$statuses) { |
117 |
for my $authvfield (@$statuses) { |
111 |
$staton->{$authvfield->{fieldname}} = []; |
118 |
$staton->{$authvfield->{fieldname}} = []; |
112 |
for my $authval (@{$authvfield->{values}}){ |
119 |
for my $authval (@{$authvfield->{values}}){ |
113 |
if ( defined $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{id}) && $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{id}) eq 'on' ){ |
120 |
if ( defined $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{authorised_value}) && $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{authorised_value}) eq 'on' ){ |
114 |
push @{$staton->{$authvfield->{fieldname}}}, $authval->{id}; |
121 |
push @{$staton->{$authvfield->{fieldname}}}, $authval->{authorised_value}; |
115 |
} |
122 |
} |
116 |
} |
123 |
} |
117 |
} |
124 |
} |
118 |
|
125 |
|
|
|
126 |
my $notforloanlist; |
119 |
my $statussth = ''; |
127 |
my $statussth = ''; |
120 |
for my $authvfield (@$statuses) { |
128 |
for my $authvfield (@$statuses) { |
121 |
if ( scalar @{$staton->{$authvfield->{fieldname}}} > 0 ){ |
129 |
if ( scalar @{$staton->{$authvfield->{fieldname}}} > 0 ){ |
122 |
my $joinedvals = join ',', @{$staton->{$authvfield->{fieldname}}}; |
130 |
my $joinedvals = join ',', @{$staton->{$authvfield->{fieldname}}}; |
123 |
$statussth .= "$authvfield->{fieldname} in ($joinedvals) and "; |
131 |
$statussth .= "$authvfield->{fieldname} in ($joinedvals) and "; |
|
|
132 |
$notforloanlist = $joinedvals if ($authvfield->{fieldname} eq "items.notforloan"); |
124 |
} |
133 |
} |
125 |
} |
134 |
} |
126 |
$statussth =~ s, and $,,g; |
135 |
$statussth =~ s, and $,,g; |
127 |
|
136 |
$template->param( |
128 |
$template->param(branchloop => \@branch_loop, |
137 |
branchloop => \@branch_loop, |
129 |
authorised_values=>\@authorised_value_list, |
138 |
authorised_values => \@authorised_value_list, |
130 |
today => C4::Dates->today(), |
139 |
today => C4::Dates->today(), |
131 |
minlocation => $minlocation, |
140 |
minlocation => $minlocation, |
132 |
maxlocation => $maxlocation, |
141 |
maxlocation => $maxlocation, |
133 |
location=>$location, |
142 |
location => $location, |
134 |
ignoreissued=>$ignoreissued, |
143 |
ignoreissued => $ignoreissued, |
135 |
branchcode=>$branchcode, |
144 |
branchcode => $branchcode, |
136 |
branch => $branch, |
145 |
branch => $branch, |
137 |
offset => $offset, |
146 |
offset => $offset, |
138 |
pagesize => $pagesize, |
147 |
pagesize => $pagesize, |
139 |
datelastseen => $datelastseen, |
148 |
datelastseen => $datelastseen, |
140 |
); |
149 |
compareinv2barcd => $compareinv2barcd, |
|
|
150 |
notforloanlist => $notforloanlist |
151 |
); |
152 |
|
153 |
my @notforloans; |
154 |
if (defined $notforloanlist) { |
155 |
@notforloans = split(/,/, $notforloanlist); |
156 |
} |
157 |
|
158 |
|
159 |
|
141 |
my @brcditems; |
160 |
my @brcditems; |
142 |
if ($uploadbarcodes && length($uploadbarcodes)>0){ |
161 |
my $barcodelist; |
143 |
my $dbh=C4::Context->dbh; |
162 |
my @errorloop; |
144 |
my $date = format_date_in_iso($input->param('setdate')) || C4::Dates->today('iso'); |
163 |
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { |
145 |
# warn "$date"; |
164 |
my $dbh = C4::Context->dbh; |
146 |
my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; |
165 |
my $date = format_date_in_iso( $input->param('setdate') ) || C4::Dates->today('iso'); |
|
|
166 |
|
167 |
my $strsth = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; |
147 |
my $qonloan = $dbh->prepare($strsth); |
168 |
my $qonloan = $dbh->prepare($strsth); |
148 |
$strsth="select * from items where items.barcode =? and items.wthdrawn = 1"; |
169 |
$strsth="select * from items where items.barcode =? and items.wthdrawn = 1"; |
149 |
my $qwthdrawn = $dbh->prepare($strsth); |
170 |
my $qwthdrawn = $dbh->prepare($strsth); |
150 |
my @errorloop; |
|
|
151 |
my $count=0; |
152 |
|
171 |
|
|
|
172 |
my $count = 0; |
153 |
# This allows us to handle files where lines are delimited by \r, \n, or \r\n. |
173 |
# This allows us to handle files where lines are delimited by \r, \n, or \r\n. |
154 |
my $file_contents = read_file( $uploadbarcodes ); |
174 |
my $file_contents = read_file( $uploadbarcodes ); |
155 |
my @barcodes = split( /\r\n|\n|\r/, $file_contents ); |
175 |
my @barcodes = split( /\r\n|\n|\r/, $file_contents ); |
156 |
|
176 |
|
157 |
for my $barcode ( @barcodes ){ |
177 |
for my $barcode ( @barcodes ){ |
158 |
if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){ |
178 |
$barcode =~ s/\r?\n$//; |
159 |
push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1}; |
179 |
$barcodelist .= ($barcodelist) ? '|' . $barcode : $barcode; |
160 |
}else{ |
180 |
if ( $qwthdrawn->execute($barcode) && $qwthdrawn->rows ) { |
161 |
my $item = GetItem('', $barcode); |
181 |
push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; |
162 |
if (defined $item && $item->{'itemnumber'}){ |
182 |
} else { |
163 |
ModItem({ datelastseen => $date }, undef, $item->{'itemnumber'}); |
183 |
my $item = GetItem( '', $barcode ); |
|
|
184 |
if ( defined $item && $item->{'itemnumber'} ) { |
185 |
ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} ); |
164 |
push @brcditems, $item; |
186 |
push @brcditems, $item; |
165 |
$count++; |
187 |
$count++; |
166 |
$qonloan->execute($barcode); |
188 |
$qonloan->execute($barcode); |
Lines 177-224
if ($uploadbarcodes && length($uploadbarcodes)>0){
Link Here
|
177 |
push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1}; |
199 |
push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1}; |
178 |
} |
200 |
} |
179 |
} |
201 |
} |
|
|
202 |
|
180 |
} |
203 |
} |
181 |
$qonloan->finish; |
204 |
$qonloan->finish; |
182 |
$qwthdrawn->finish; |
205 |
$qwthdrawn->finish; |
183 |
$template->param(date=>format_date($date),Number=>$count); |
206 |
$template->param( date => format_date($date), Number => $count ); |
184 |
# $template->param(errorfile=>$errorfile) if ($errorfile); |
207 |
$template->param( errorloop => \@errorloop ) if (@errorloop); |
185 |
$template->param(errorloop=>\@errorloop) if (@errorloop); |
208 |
|
|
|
209 |
|
186 |
} |
210 |
} |
187 |
#if we want to compare the results to a list of barcodes, or we have no barcode file |
211 |
$template->param(barcodelist => $barcodelist); |
188 |
if ( ! ($uploadbarcodes && length($uploadbarcodes)>0 ) || ( $input->param('compareinv2barcd') eq 'on' && length($uploadbarcodes)>0) ) { |
212 |
|
189 |
if ($markseen) { |
213 |
# now build the result list: inventoried items if requested, and mis-placed items -always- |
190 |
foreach ($input->param) { |
214 |
my $inventorylist; |
191 |
/SEEN-(.+)/ and &ModDateLastSeen($1); |
215 |
if ( $markseen or $op ) { |
192 |
} |
216 |
# retrieve all items in this range. |
|
|
217 |
my $totalrecords; |
218 |
($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton); |
219 |
|
220 |
# Real copy |
221 |
my @res_copy; |
222 |
foreach (@$inventorylist) { |
223 |
push @res_copy, $_; |
193 |
} |
224 |
} |
194 |
if ($markseen or $op) { |
225 |
$res = \@res_copy; |
195 |
$res = GetItemsForInventory( $minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $branch, $offset, $pagesize, $staton ); |
226 |
} |
196 |
$template->param(loop =>$res, |
227 |
|
197 |
nextoffset => ($offset+$pagesize), |
228 |
# set "missing" flags for all items with a datelastseen before the choosen datelastseen |
198 |
prevoffset => ($offset?$offset-$pagesize:0), |
229 |
foreach (@$res) { $_->{missingitem}=1 if C4::Dates->new($_->{datelastseen})->output('iso') lt C4::Dates->new($datelastseen)->output('iso'); } |
199 |
); |
230 |
|
200 |
} |
231 |
# removing missing items from loop if "Compare barcodes list to results" has not been checked |
201 |
if ( defined $input->param('compareinv2barcd') && ( ( $input->param('compareinv2barcd') eq 'on' ) && ( scalar @brcditems != scalar @$res ) ) && length($uploadbarcodes) > 0 ){ |
232 |
@$res = grep {!$_->{missingitem} == 1 } @$res if (!$input->param('compareinv2barcd')); |
202 |
if ( scalar @brcditems > scalar @$res ){ |
233 |
|
203 |
for my $brcditem (@brcditems) { |
234 |
# insert "wrongplace" to all scanned items that are not supposed to be in this range |
204 |
if (! grep( $_->{barcode} =~ /$brcditem->{barcode}/ , @$res) ){ |
235 |
# note this list is always displayed, whatever the librarian has choosen for comparison |
205 |
$brcditem->{notfoundkoha} = 1; |
236 |
foreach my $temp (@brcditems) { |
206 |
push @$res, $brcditem; |
237 |
|
207 |
} |
238 |
# Saving notforloan code before it's replaced by it's authorised value for later comparison |
208 |
} |
239 |
$temp->{'notforloancode'} = $temp->{'notforloan'}; |
209 |
} else { |
240 |
|
210 |
my @notfound; |
241 |
# Populating with authorised values |
211 |
for my $item (@$res) { |
242 |
foreach (keys %$temp) { |
212 |
if ( ! grep( $_->{barcode} =~ /$item->{barcode}/ , @brcditems) ){ |
243 |
# If the koha field is mapped to a marc field |
213 |
$item->{notfoundbarcode} = 1; |
244 |
my $fc = $temp->{'frameworkcode'} || ''; |
214 |
push @notfound, $item; |
245 |
my ($f, $sf) = GetMarcFromKohaField("items.$_", $fc); |
215 |
} |
246 |
if ($f and $sf) { |
|
|
247 |
# We replace the code with it's description |
248 |
my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $fc); |
249 |
if ($authvals and defined $temp->{$_} and defined $authvals->{$temp->{$_}}) { |
250 |
$temp->{$_} = $authvals->{$temp->{$_}}; |
216 |
} |
251 |
} |
217 |
$res = [@$res, @notfound]; |
|
|
218 |
} |
252 |
} |
219 |
} |
253 |
} |
|
|
254 |
|
255 |
next if $temp->{onloan}; # skip checked out items |
256 |
|
257 |
# If we have scanned items with a non-matching notforloan value |
258 |
if (none { $temp->{'notforloancode'} eq $_ } @notforloans) { |
259 |
$temp->{'changestatus'} = 1; |
260 |
my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); |
261 |
$temp->{title} = $biblio->{title}; |
262 |
$temp->{author} = $biblio->{author}; |
263 |
$temp->{datelastseen} = format_date($temp->{datelastseen}); |
264 |
push @$res, $temp; |
265 |
|
266 |
} |
267 |
if (none { $temp->{barcode} eq $_->{barcode} && !$_->{'onloan'} } @$inventorylist) { |
268 |
my $temp2 = { %$temp }; |
269 |
$temp2->{wrongplace}=1; |
270 |
my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); |
271 |
$temp2->{title} = $biblio->{title}; |
272 |
$temp2->{author} = $biblio->{author}; |
273 |
$temp2->{datelastseen} = format_date($temp->{datelastseen}); |
274 |
push @$res, $temp2; |
275 |
} |
276 |
} |
277 |
|
278 |
# Finally, modifying datelastseen for remaining items |
279 |
my $moddatecount = 0; |
280 |
foreach (@$res) { |
281 |
unless ($_->{'missingitem'}) { |
282 |
ModDateLastSeen($_->{'itemnumber'}); |
283 |
$moddatecount++; |
284 |
} |
220 |
} |
285 |
} |
221 |
|
286 |
|
|
|
287 |
# Removing items that don't have any problems from loop |
288 |
@$res = grep { $_->{missingitem} || $_->{wrongplace} || $_->{changestatus} } @$res; |
289 |
|
290 |
$template->param( |
291 |
moddatecount => $moddatecount, |
292 |
loop => $res, |
293 |
nextoffset => ( $offset + $pagesize ), |
294 |
prevoffset => ( $offset ? $offset - $pagesize : 0 ), |
295 |
op => $op |
296 |
); |
297 |
|
222 |
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ |
298 |
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ |
223 |
eval {use Text::CSV}; |
299 |
eval {use Text::CSV}; |
224 |
my $csv = Text::CSV->new or |
300 |
my $csv = Text::CSV->new or |
Lines 227-240
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){
Link Here
|
227 |
-type => 'text/csv', |
303 |
-type => 'text/csv', |
228 |
-attachment => 'inventory.csv', |
304 |
-attachment => 'inventory.csv', |
229 |
); |
305 |
); |
230 |
for my $re (@$res){ |
306 |
|
|
|
307 |
my $columns_def_hashref = C4::Reports::Guided::_get_column_defs(); |
308 |
foreach my $key ( keys %$columns_def_hashref ) { |
309 |
my $initkey = $key; |
310 |
$key =~ s/[^\.]*\.//; |
311 |
$columns_def_hashref->{$initkey}=NormalizeString($columns_def_hashref->{$initkey}); |
312 |
$columns_def_hashref->{$key} = $columns_def_hashref->{$initkey}; |
313 |
} |
314 |
|
315 |
my @translated_keys; |
316 |
for my $key (qw / biblioitems.title biblio.author |
317 |
items.barcode items.itemnumber |
318 |
items.homebranch items.location |
319 |
items.itemcallnumber items.notforloan |
320 |
items.itemlost items.damaged |
321 |
items.stocknumber |
322 |
/ ) { |
323 |
push @translated_keys, $columns_def_hashref->{$key}; |
324 |
} |
325 |
|
326 |
$csv->combine(@translated_keys); |
327 |
print $csv->string, "\n"; |
328 |
|
329 |
my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /; |
330 |
for my $re (@$res) { |
231 |
my @line; |
331 |
my @line; |
232 |
for my $key (keys %$re) { |
332 |
for my $key (@keys) { |
233 |
push @line, $re->{$key}; |
333 |
push @line, $re->{$key}; |
234 |
} |
334 |
} |
|
|
335 |
if ($re->{wrongplace}) { |
336 |
push @line, "wrong place"; |
337 |
} elsif ($re->{missingitem}) { |
338 |
push @line, "missing item"; |
339 |
} elsif ($re->{changestatus}) { |
340 |
push @line, "change item status"; |
341 |
} |
342 |
$csv->combine(@line); |
343 |
print $csv->string, "\n"; |
344 |
} |
345 |
# Adding not found barcodes |
346 |
foreach my $error (@errorloop) { |
347 |
my @line; |
348 |
if ($error->{'ERR_BARCODE'}) { |
349 |
push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys; |
350 |
push @line, "barcode not found"; |
235 |
$csv->combine(@line); |
351 |
$csv->combine(@line); |
236 |
print $csv->string, "\n"; |
352 |
print $csv->string, "\n"; |
237 |
} |
353 |
} |
|
|
354 |
} |
238 |
exit; |
355 |
exit; |
239 |
} |
356 |
} |
240 |
|
357 |
|
241 |
- |
|
|