Lines 35-40
use C4::Dates qw/format_date format_date_in_iso/;
Link Here
|
35 |
use C4::Koha; |
35 |
use C4::Koha; |
36 |
use C4::Branch; # GetBranches |
36 |
use C4::Branch; # GetBranches |
37 |
use C4::Circulation; |
37 |
use C4::Circulation; |
|
|
38 |
use C4::Reports::Guided; #_get_column_defs |
39 |
use C4::Charset; |
40 |
|
38 |
|
41 |
|
39 |
my $minlocation=$input->param('minlocation') || ''; |
42 |
my $minlocation=$input->param('minlocation') || ''; |
40 |
my $maxlocation=$input->param('maxlocation'); |
43 |
my $maxlocation=$input->param('maxlocation'); |
Lines 50-68
my $pagesize = $input->param('pagesize');
Link Here
|
50 |
$pagesize=50 unless $pagesize; |
53 |
$pagesize=50 unless $pagesize; |
51 |
my $branchcode = $input->param('branchcode') || ''; |
54 |
my $branchcode = $input->param('branchcode') || ''; |
52 |
my $branch = $input->param('branch'); |
55 |
my $branch = $input->param('branch'); |
53 |
my $op = $input->param('op'); |
56 |
my $op = $input->param('op'); |
54 |
my $res; #contains the results loop |
57 |
my $compareinv2barcd = $input->param('compareinv2barcd'); |
55 |
# warn "uploadbarcodes : ".$uploadbarcodes; |
58 |
my $res; #contains the results loop |
56 |
# use Data::Dumper; warn Dumper($input); |
59 |
|
57 |
|
60 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
58 |
my ($template, $borrowernumber, $cookie) |
61 |
{ template_name => "tools/inventory.tmpl", |
59 |
= get_template_and_user({template_name => "tools/inventory.tmpl", |
62 |
query => $input, |
60 |
query => $input, |
63 |
type => "intranet", |
61 |
type => "intranet", |
64 |
authnotrequired => 0, |
62 |
authnotrequired => 0, |
65 |
flagsrequired => { tools => 'inventory' }, |
63 |
flagsrequired => {tools => 'inventory'}, |
66 |
debug => 1, |
64 |
debug => 1, |
67 |
} |
65 |
}); |
68 |
); |
|
|
69 |
|
66 |
|
70 |
|
67 |
my $branches = GetBranches(); |
71 |
my $branches = GetBranches(); |
68 |
my @branch_loop; |
72 |
my @branch_loop; |
Lines 114-161
for my $authvfield (@$statuses) {
Link Here
|
114 |
} |
118 |
} |
115 |
} |
119 |
} |
116 |
|
120 |
|
|
|
121 |
my $notforloanlist; |
117 |
my $statussth = ''; |
122 |
my $statussth = ''; |
118 |
for my $authvfield (@$statuses) { |
123 |
for my $authvfield (@$statuses) { |
119 |
if ( scalar @{$staton->{$authvfield->{fieldname}}} > 0 ){ |
124 |
if ( scalar @{$staton->{$authvfield->{fieldname}}} > 0 ){ |
120 |
my $joinedvals = join ',', @{$staton->{$authvfield->{fieldname}}}; |
125 |
my $joinedvals = join ',', @{$staton->{$authvfield->{fieldname}}}; |
121 |
$statussth .= "$authvfield->{fieldname} in ($joinedvals) and "; |
126 |
$statussth .= "$authvfield->{fieldname} in ($joinedvals) and "; |
|
|
127 |
$notforloanlist = $joinedvals if ($authvfield->{fieldname} eq "items.notforloan"); |
122 |
} |
128 |
} |
123 |
} |
129 |
} |
124 |
$statussth =~ s, and $,,g; |
130 |
$statussth =~ s, and $,,g; |
125 |
|
131 |
$template->param( |
126 |
$template->param(branchloop => \@branch_loop, |
132 |
branchloop => \@branch_loop, |
127 |
authorised_values=>\@authorised_value_list, |
133 |
authorised_values => \@authorised_value_list, |
128 |
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), |
134 |
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), |
129 |
today => C4::Dates->today(), |
135 |
today => C4::Dates->today(), |
130 |
minlocation => $minlocation, |
136 |
minlocation => $minlocation, |
131 |
maxlocation => $maxlocation, |
137 |
maxlocation => $maxlocation, |
132 |
location=>$location, |
138 |
location => $location, |
133 |
ignoreissued=>$ignoreissued, |
139 |
ignoreissued => $ignoreissued, |
134 |
branchcode=>$branchcode, |
140 |
branchcode => $branchcode, |
135 |
branch => $branch, |
141 |
branch => $branch, |
136 |
offset => $offset, |
142 |
offset => $offset, |
137 |
pagesize => $pagesize, |
143 |
pagesize => $pagesize, |
138 |
datelastseen => $datelastseen, |
144 |
datelastseen => $datelastseen, |
139 |
); |
145 |
compareinv2barcd => $compareinv2barcd, |
|
|
146 |
notforloanlist => $notforloanlist |
147 |
); |
148 |
|
149 |
my @notforloans; |
150 |
if (defined $notforloanlist) { |
151 |
@notforloans = split(/,/, $notforloanlist); |
152 |
} |
153 |
|
154 |
|
155 |
|
140 |
my @brcditems; |
156 |
my @brcditems; |
141 |
if ($uploadbarcodes && length($uploadbarcodes)>0){ |
157 |
my $barcodelist; |
142 |
my $dbh=C4::Context->dbh; |
158 |
my @errorloop; |
143 |
my $date = format_date_in_iso($input->param('setdate')) || C4::Dates->today('iso'); |
159 |
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { |
144 |
# warn "$date"; |
160 |
my $dbh = C4::Context->dbh; |
145 |
my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; |
161 |
my $date = format_date_in_iso( $input->param('setdate') ) || C4::Dates->today('iso'); |
|
|
162 |
|
163 |
my $strsth = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; |
146 |
my $qonloan = $dbh->prepare($strsth); |
164 |
my $qonloan = $dbh->prepare($strsth); |
147 |
$strsth="select * from items where items.barcode =? and items.wthdrawn = 1"; |
165 |
$strsth="select * from items where items.barcode =? and items.wthdrawn = 1"; |
148 |
my $qwthdrawn = $dbh->prepare($strsth); |
166 |
my $qwthdrawn = $dbh->prepare($strsth); |
149 |
my @errorloop; |
167 |
my $count = 0; |
150 |
my $count=0; |
168 |
|
151 |
while (my $barcode=<$uploadbarcodes>){ |
169 |
while ( my $barcode = <$uploadbarcodes> ) { |
152 |
$barcode =~ s/\r?\n$//; |
170 |
$barcode =~ s/\r?\n$//; |
153 |
if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){ |
171 |
$barcodelist .= ($barcodelist) ? '|' . $barcode : $barcode; |
154 |
push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1}; |
172 |
if ( $qwthdrawn->execute($barcode) && $qwthdrawn->rows ) { |
155 |
}else{ |
173 |
push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; |
156 |
my $item = GetItem('', $barcode); |
174 |
} else { |
157 |
if (defined $item && $item->{'itemnumber'}){ |
175 |
my $item = GetItem( '', $barcode ); |
158 |
ModItem({ datelastseen => $date }, undef, $item->{'itemnumber'}); |
176 |
if ( defined $item && $item->{'itemnumber'} ) { |
|
|
177 |
ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} ); |
159 |
push @brcditems, $item; |
178 |
push @brcditems, $item; |
160 |
$count++; |
179 |
$count++; |
161 |
$qonloan->execute($barcode); |
180 |
$qonloan->execute($barcode); |
Lines 172-219
if ($uploadbarcodes && length($uploadbarcodes)>0){
Link Here
|
172 |
push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1}; |
191 |
push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1}; |
173 |
} |
192 |
} |
174 |
} |
193 |
} |
|
|
194 |
|
175 |
} |
195 |
} |
176 |
$qonloan->finish; |
196 |
$qonloan->finish; |
177 |
$qwthdrawn->finish; |
197 |
$qwthdrawn->finish; |
178 |
$template->param(date=>format_date($date),Number=>$count); |
198 |
$template->param( date => format_date($date), Number => $count ); |
179 |
# $template->param(errorfile=>$errorfile) if ($errorfile); |
199 |
$template->param( errorloop => \@errorloop ) if (@errorloop); |
180 |
$template->param(errorloop=>\@errorloop) if (@errorloop); |
200 |
|
|
|
201 |
|
202 |
} |
203 |
$template->param(barcodelist => $barcodelist); |
204 |
|
205 |
# now build the result list: inventoried items if requested, and mis-placed items -always- |
206 |
my $inventorylist; |
207 |
if ( $markseen or $op ) { |
208 |
# retrieve all items in this range. |
209 |
my $totalrecords; |
210 |
($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton); |
211 |
|
212 |
$res = $inventorylist ; |
181 |
} |
213 |
} |
182 |
#if we want to compare the results to a list of barcodes, or we have no barcode file |
214 |
|
183 |
if ( ! ($uploadbarcodes && length($uploadbarcodes)>0 ) || ( $input->param('compareinv2barcd') eq 'on' && length($uploadbarcodes)>0) ) { |
215 |
# set "missing" flags for all items with a datelastseen before the choosen datelastseen |
184 |
if ($markseen) { |
216 |
foreach (@$res) {$_->{missingitem}=1 if C4::Dates->new($_->{datelastseen})->output('iso') lt C4::Dates->new($datelastseen)->output('iso')} |
185 |
foreach ($input->param) { |
217 |
|
186 |
/SEEN-(.+)/ and &ModDateLastSeen($1); |
218 |
# removing missing items from loop if "Compare barcodes list to results" has not been checked |
|
|
219 |
@$res = grep {!$_->{missingitem} == 1 } @$res if (!$input->param('compareinv2barcd')); |
220 |
|
221 |
# insert "wrongplace" to all scanned items that are not supposed to be in this range |
222 |
# note this list is always displayed, whatever the librarian has choosen for comparison |
223 |
foreach my $temp (@brcditems) { |
224 |
next if $temp->{onloan}; # skip checked out items |
225 |
|
226 |
# If we have scanned items with a non-matching notforloan value |
227 |
if (none { $temp->{'notforloan'} eq $_ } @notforloans) { |
228 |
$temp->{'changestatus'} = 1; |
229 |
if ($input->param('CSVexport') eq 'on') { |
230 |
my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); |
231 |
$temp->{title} = $biblio->{title}; |
232 |
$temp->{author} = $biblio->{author}; |
233 |
$temp->{datelastseen} = format_date($temp->{datelastseen}); |
187 |
} |
234 |
} |
|
|
235 |
push @$res, $temp; |
236 |
|
188 |
} |
237 |
} |
189 |
if ($markseen or $op) { |
238 |
|
190 |
$res = GetItemsForInventory( $minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $branch, $offset, $pagesize, $staton ); |
239 |
if (none { $temp->{barcode} eq $_->{barcode} && !$_->{onloan} } @$inventorylist) { |
191 |
$template->param(loop =>$res, |
240 |
$temp->{wrongplace}=1; |
192 |
nextoffset => ($offset+$pagesize), |
241 |
if ($input->param('CSVexport') eq 'on') { |
193 |
prevoffset => ($offset?$offset-$pagesize:0), |
242 |
my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); |
194 |
); |
243 |
$temp->{title} = $biblio->{title}; |
195 |
} |
244 |
$temp->{author} = $biblio->{author}; |
196 |
if ( defined $input->param('compareinv2barcd') && ( ( $input->param('compareinv2barcd') eq 'on' ) && ( scalar @brcditems != scalar @$res ) ) && length($uploadbarcodes) > 0 ){ |
245 |
$temp->{datelastseen} = format_date($temp->{datelastseen}); |
197 |
if ( scalar @brcditems > scalar @$res ){ |
|
|
198 |
for my $brcditem (@brcditems) { |
199 |
if (! grep( $_->{barcode} =~ /$brcditem->{barcode}/ , @$res) ){ |
200 |
$brcditem->{notfoundkoha} = 1; |
201 |
push @$res, $brcditem; |
202 |
} |
203 |
} |
204 |
} else { |
205 |
my @notfound; |
206 |
for my $item (@$res) { |
207 |
if ( ! grep( $_->{barcode} =~ /$item->{barcode}/ , @brcditems) ){ |
208 |
$item->{notfoundbarcode} = 1; |
209 |
push @notfound, $item; |
210 |
} |
211 |
} |
212 |
$res = [@$res, @notfound]; |
213 |
} |
246 |
} |
|
|
247 |
push @$res, $temp; |
248 |
} |
249 |
} |
250 |
|
251 |
# Finally, modifying datelastseen for remaining items |
252 |
my $moddatecount = 0; |
253 |
foreach (@$res) { |
254 |
unless ($_->{'missingitem'}) { |
255 |
ModDateLastSeen($_->{'itemnumber'}); |
256 |
$moddatecount++; |
214 |
} |
257 |
} |
215 |
} |
258 |
} |
216 |
|
259 |
|
|
|
260 |
# Removing items that don't have any problems from loop |
261 |
@$res = grep { $_->{missingitem} || $_->{wrongplace} || $_->{changestatus} } @$res; |
262 |
|
263 |
$template->param( |
264 |
moddatecount => $moddatecount, |
265 |
loop => $res, |
266 |
nextoffset => ( $offset + $pagesize ), |
267 |
prevoffset => ( $offset ? $offset - $pagesize : 0 ), |
268 |
op => $op |
269 |
); |
270 |
|
217 |
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ |
271 |
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ |
218 |
eval {use Text::CSV}; |
272 |
eval {use Text::CSV}; |
219 |
my $csv = Text::CSV->new or |
273 |
my $csv = Text::CSV->new or |
Lines 222-235
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){
Link Here
|
222 |
-type => 'text/csv', |
276 |
-type => 'text/csv', |
223 |
-attachment => 'inventory.csv', |
277 |
-attachment => 'inventory.csv', |
224 |
); |
278 |
); |
225 |
for my $re (@$res){ |
279 |
|
|
|
280 |
my $columns_def_hashref = C4::Reports::Guided::_get_column_defs(); |
281 |
foreach my $key ( keys %$columns_def_hashref ) { |
282 |
my $initkey = $key; |
283 |
$key =~ s/[^\.]*\.//; |
284 |
$columns_def_hashref->{$initkey}=NormalizeString($columns_def_hashref->{$initkey}); |
285 |
$columns_def_hashref->{$key} = $columns_def_hashref->{$initkey}; |
286 |
} |
287 |
|
288 |
my @translated_keys; |
289 |
for my $key (qw / biblioitems.title biblio.author |
290 |
items.barcode items.itemnumber |
291 |
items.homebranch items.location |
292 |
items.itemcallnumber items.notforloan |
293 |
items.itemlost items.damaged |
294 |
items.stocknumber |
295 |
/ ) { |
296 |
push @translated_keys, $columns_def_hashref->{$key}; |
297 |
} |
298 |
|
299 |
$csv->combine(@translated_keys); |
300 |
print $csv->string, "\n"; |
301 |
|
302 |
my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /; |
303 |
for my $re (@$res) { |
226 |
my @line; |
304 |
my @line; |
227 |
for my $key (keys %$re) { |
305 |
for my $key (@keys) { |
228 |
push @line, $re->{$key}; |
306 |
push @line, $re->{$key}; |
229 |
} |
307 |
} |
|
|
308 |
push @line, "wrong place" if $re->{wrongplace}; |
309 |
push @line, "missing item" if $re->{missingitem}; |
310 |
push @line, "change item status" if $re->{changestatus}; |
230 |
$csv->combine(@line); |
311 |
$csv->combine(@line); |
231 |
print $csv->string, "\n"; |
312 |
print $csv->string, "\n"; |
232 |
} |
313 |
} |
|
|
314 |
# Adding not found barcodes |
315 |
foreach my $error (@errorloop) { |
316 |
my @line; |
317 |
if ($error->{'ERR_BARCODE'}) { |
318 |
push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys; |
319 |
push @line, "barcode not found"; |
320 |
$csv->combine(@line); |
321 |
print $csv->string, "\n"; |
322 |
} |
323 |
} |
233 |
exit; |
324 |
exit; |
234 |
} |
325 |
} |
235 |
|
326 |
|
236 |
- |
|
|