Lines 31-43
use C4::Context;
Link Here
|
31 |
use C4::Output; |
31 |
use C4::Output; |
32 |
use C4::Biblio; |
32 |
use C4::Biblio; |
33 |
use C4::Items; |
33 |
use C4::Items; |
34 |
use C4::Dates qw/format_date format_date_in_iso/; |
|
|
35 |
use C4::Koha; |
34 |
use C4::Koha; |
36 |
use C4::Branch; # GetBranches |
35 |
use C4::Branch; # GetBranches |
37 |
use C4::Circulation; |
36 |
use C4::Circulation; |
38 |
use C4::Reports::Guided; #_get_column_defs |
37 |
use C4::Reports::Guided; #_get_column_defs |
39 |
use C4::Charset; |
38 |
use C4::Charset; |
40 |
use List::MoreUtils qw/none/; |
39 |
use Koha::DateUtils; |
|
|
40 |
use List::MoreUtils qw( none ); |
41 |
|
41 |
|
42 |
|
42 |
|
43 |
my $minlocation=$input->param('minlocation') || ''; |
43 |
my $minlocation=$input->param('minlocation') || ''; |
Lines 47-65
my $location=$input->param('location') || '';
Link Here
|
47 |
my $itemtype=$input->param('itemtype'); # FIXME note, template does not currently supply this |
47 |
my $itemtype=$input->param('itemtype'); # FIXME note, template does not currently supply this |
48 |
my $ignoreissued=$input->param('ignoreissued'); |
48 |
my $ignoreissued=$input->param('ignoreissued'); |
49 |
my $datelastseen = $input->param('datelastseen'); |
49 |
my $datelastseen = $input->param('datelastseen'); |
50 |
my $offset = $input->param('offset'); |
|
|
51 |
my $markseen = $input->param('markseen'); |
50 |
my $markseen = $input->param('markseen'); |
52 |
$offset=0 unless $offset; |
|
|
53 |
my $pagesize = $input->param('pagesize'); |
54 |
$pagesize=50 unless $pagesize; |
55 |
my $branchcode = $input->param('branchcode') || ''; |
51 |
my $branchcode = $input->param('branchcode') || ''; |
56 |
my $branch = $input->param('branch'); |
52 |
my $branch = $input->param('branch'); |
57 |
my $op = $input->param('op'); |
53 |
my $op = $input->param('op'); |
58 |
my $compareinv2barcd = $input->param('compareinv2barcd'); |
54 |
my $compareinv2barcd = $input->param('compareinv2barcd'); |
59 |
my $res; #contains the results loop |
|
|
60 |
|
55 |
|
61 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
56 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
62 |
{ template_name => "tools/inventory.tmpl", |
57 |
{ template_name => "tools/inventory.tt", |
63 |
query => $input, |
58 |
query => $input, |
64 |
type => "intranet", |
59 |
type => "intranet", |
65 |
authnotrequired => 0, |
60 |
authnotrequired => 0, |
Lines 134-148
$statussth =~ s, and $,,g;
Link Here
|
134 |
$template->param( |
129 |
$template->param( |
135 |
branchloop => \@branch_loop, |
130 |
branchloop => \@branch_loop, |
136 |
authorised_values => \@authorised_value_list, |
131 |
authorised_values => \@authorised_value_list, |
137 |
today => C4::Dates->today(), |
132 |
today => dt_from_string, |
138 |
minlocation => $minlocation, |
133 |
minlocation => $minlocation, |
139 |
maxlocation => $maxlocation, |
134 |
maxlocation => $maxlocation, |
140 |
location => $location, |
135 |
location => $location, |
141 |
ignoreissued => $ignoreissued, |
136 |
ignoreissued => $ignoreissued, |
142 |
branchcode => $branchcode, |
137 |
branchcode => $branchcode, |
143 |
branch => $branch, |
138 |
branch => $branch, |
144 |
offset => $offset, |
|
|
145 |
pagesize => $pagesize, |
146 |
datelastseen => $datelastseen, |
139 |
datelastseen => $datelastseen, |
147 |
compareinv2barcd => $compareinv2barcd, |
140 |
compareinv2barcd => $compareinv2barcd, |
148 |
notforloanlist => $notforloanlist |
141 |
notforloanlist => $notforloanlist |
Lines 153-166
if (defined $notforloanlist) {
Link Here
|
153 |
@notforloans = split(/,/, $notforloanlist); |
146 |
@notforloans = split(/,/, $notforloanlist); |
154 |
} |
147 |
} |
155 |
|
148 |
|
156 |
|
149 |
my @scanned_items; |
157 |
|
|
|
158 |
my @brcditems; |
159 |
my $barcodelist; |
160 |
my @errorloop; |
150 |
my @errorloop; |
161 |
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { |
151 |
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { |
162 |
my $dbh = C4::Context->dbh; |
152 |
my $dbh = C4::Context->dbh; |
163 |
my $date = format_date_in_iso( $input->param('setdate') ) || C4::Dates->today('iso'); |
153 |
my $date = dt_from_string( $input->param('setdate') ); |
|
|
154 |
$date = output_pref( $date, 'iso' ); |
164 |
|
155 |
|
165 |
my $strsth = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; |
156 |
my $strsth = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; |
166 |
my $qonloan = $dbh->prepare($strsth); |
157 |
my $qonloan = $dbh->prepare($strsth); |
Lines 174-187
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
Link Here
|
174 |
|
165 |
|
175 |
for my $barcode ( @barcodes ){ |
166 |
for my $barcode ( @barcodes ){ |
176 |
$barcode =~ s/\r?\n$//; |
167 |
$barcode =~ s/\r?\n$//; |
177 |
$barcodelist .= ($barcodelist) ? '|' . $barcode : $barcode; |
168 |
next unless $barcode; |
178 |
if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) { |
169 |
if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) { |
179 |
push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; |
170 |
push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; |
180 |
} else { |
171 |
} else { |
181 |
my $item = GetItem( '', $barcode ); |
172 |
my $item = GetItem( '', $barcode ); |
182 |
if ( defined $item && $item->{'itemnumber'} ) { |
173 |
if ( defined $item && $item->{'itemnumber'} ) { |
183 |
ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} ); |
174 |
ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} ); |
184 |
push @brcditems, $item; |
175 |
push @scanned_items, $item; |
185 |
$count++; |
176 |
$count++; |
186 |
$qonloan->execute($barcode); |
177 |
$qonloan->execute($barcode); |
187 |
if ($qonloan->rows){ |
178 |
if ($qonloan->rows){ |
Lines 199-294
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
Link Here
|
199 |
} |
190 |
} |
200 |
|
191 |
|
201 |
} |
192 |
} |
202 |
$qonloan->finish; |
|
|
203 |
$qwithdrawn->finish; |
204 |
$template->param( date => format_date($date), Number => $count ); |
205 |
$template->param( errorloop => \@errorloop ) if (@errorloop); |
206 |
|
193 |
|
|
|
194 |
$template->param( date => $date, Number => $count ); |
195 |
$template->param( errorloop => \@errorloop ) if (@errorloop); |
207 |
} |
196 |
} |
208 |
$template->param(barcodelist => $barcodelist); |
|
|
209 |
|
197 |
|
210 |
# now build the result list: inventoried items if requested, and mis-placed items -always- |
198 |
# now build the result list: inventoried items if requested, and mis-placed items -always- |
211 |
my $inventorylist; |
199 |
my $inventorylist; |
|
|
200 |
my @items_with_problems; |
212 |
if ( $markseen or $op ) { |
201 |
if ( $markseen or $op ) { |
213 |
# retrieve all items in this range. |
202 |
# retrieve all items in this range. |
214 |
my $totalrecords; |
203 |
my $totalrecords; |
215 |
($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton); |
204 |
($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton); |
|
|
205 |
} |
216 |
|
206 |
|
217 |
# Real copy |
207 |
# If "compare barcodes list to results" has been checked, we want to alert for missing items |
218 |
my @res_copy; |
208 |
if ( $compareinv2barcd ) { |
219 |
foreach (@$inventorylist) { |
209 |
# set "missing" flags for all items with a datelastseen (dls) before the choosen datelastseen (cdls) |
220 |
push @res_copy, $_; |
210 |
my $dls = output_pref( dt_from_string( $datelastseen ), 'iso' ); |
|
|
211 |
foreach my $item ( @$inventorylist ) { |
212 |
my $cdls = output_pref( dt_from_string( $_->{datelastseen} ), 'iso' ); |
213 |
if ( $cdls lt $dls ) { |
214 |
$item->{problem} = 'missingitem'; |
215 |
# We have to push a copy of the item, not the reference |
216 |
push @items_with_problems, { %$item }; |
217 |
} |
221 |
} |
218 |
} |
222 |
$res = \@res_copy; |
|
|
223 |
} |
219 |
} |
224 |
|
220 |
|
225 |
# set "missing" flags for all items with a datelastseen before the choosen datelastseen |
|
|
226 |
foreach (@$res) { $_->{missingitem}=1 if C4::Dates->new($_->{datelastseen})->output('iso') lt C4::Dates->new($datelastseen)->output('iso'); } |
227 |
|
221 |
|
228 |
# removing missing items from loop if "Compare barcodes list to results" has not been checked |
|
|
229 |
@$res = grep {!$_->{missingitem} == 1 } @$res if (!$input->param('compareinv2barcd')); |
230 |
|
222 |
|
231 |
# insert "wrongplace" to all scanned items that are not supposed to be in this range |
223 |
# insert "wrongplace" to all scanned items that are not supposed to be in this range |
232 |
# note this list is always displayed, whatever the librarian has choosen for comparison |
224 |
# note this list is always displayed, whatever the librarian has choosen for comparison |
233 |
foreach my $temp (@brcditems) { |
225 |
my $moddatecount = 0; |
|
|
226 |
foreach my $item ( @scanned_items ) { |
234 |
|
227 |
|
235 |
# Saving notforloan code before it's replaced by it's authorised value for later comparison |
228 |
# Saving notforloan code before it's replaced by it's authorised value for later comparison |
236 |
$temp->{'notforloancode'} = $temp->{'notforloan'}; |
229 |
$item->{notforloancode} = $item->{notforloan}; |
237 |
|
230 |
|
238 |
# Populating with authorised values |
231 |
# Populating with authorised values |
239 |
foreach (keys %$temp) { |
232 |
foreach my $field ( keys %$item ) { |
240 |
# If the koha field is mapped to a marc field |
233 |
# If the koha field is mapped to a marc field |
241 |
my $fc = $temp->{'frameworkcode'} || ''; |
234 |
my $fc = $item->{'frameworkcode'} || ''; |
242 |
my ($f, $sf) = GetMarcFromKohaField("items.$_", $fc); |
235 |
my ($f, $sf) = GetMarcFromKohaField("items.$field", $fc); |
243 |
if ($f and $sf) { |
236 |
if ($f and $sf) { |
244 |
# We replace the code with it's description |
237 |
# We replace the code with it's description |
245 |
my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $fc); |
238 |
my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $fc); |
246 |
if ($authvals and defined $temp->{$_} and defined $authvals->{$temp->{$_}}) { |
239 |
if ($authvals and defined $item->{$field} and defined $authvals->{$item->{$field}}) { |
247 |
$temp->{$_} = $authvals->{$temp->{$_}}; |
240 |
$item->{$field} = $authvals->{$item->{$field}}; |
248 |
} |
241 |
} |
249 |
} |
242 |
} |
250 |
} |
243 |
} |
251 |
|
244 |
|
252 |
next if $temp->{onloan}; # skip checked out items |
245 |
next if $item->{onloan}; # skip checked out items |
253 |
|
246 |
|
254 |
# If we have scanned items with a non-matching notforloan value |
247 |
# If we have scanned items with a non-matching notforloan value |
255 |
if (none { $temp->{'notforloancode'} eq $_ } @notforloans) { |
248 |
if (none { $item->{'notforloancode'} eq $_ } @notforloans) { |
256 |
$temp->{'changestatus'} = 1; |
249 |
$item->{problem} = 'changestatus'; |
257 |
my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); |
250 |
push @items_with_problems, { %$item }; |
258 |
$temp->{title} = $biblio->{title}; |
|
|
259 |
$temp->{author} = $biblio->{author}; |
260 |
$temp->{datelastseen} = format_date($temp->{datelastseen}); |
261 |
push @$res, $temp; |
262 |
|
263 |
} |
251 |
} |
264 |
if (none { $temp->{barcode} eq $_->{barcode} && !$_->{'onloan'} } @$inventorylist) { |
252 |
if (none { $item->{barcode} eq $_->{barcode} && !$_->{'onloan'} } @$inventorylist) { |
265 |
my $temp2 = { %$temp }; |
253 |
$item->{problem} = 'wrongplace'; |
266 |
$temp2->{wrongplace}=1; |
254 |
push @items_with_problems, { %$item }; |
267 |
my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); |
|
|
268 |
$temp2->{title} = $biblio->{title}; |
269 |
$temp2->{author} = $biblio->{author}; |
270 |
$temp2->{datelastseen} = format_date($temp->{datelastseen}); |
271 |
push @$res, $temp2; |
272 |
} |
255 |
} |
|
|
256 |
|
257 |
# Modify date last seen for scanned items |
258 |
ModDateLastSeen($_->{'itemnumber'}); |
259 |
$moddatecount++; |
273 |
} |
260 |
} |
274 |
|
261 |
|
275 |
# Finally, modifying datelastseen for remaining items |
262 |
if ( $compareinv2barcd ) { |
276 |
my $moddatecount = 0; |
263 |
my @scanned_barcodes = map {$_->{barcode}} @scanned_items; |
277 |
foreach (@$res) { |
264 |
for my $should_be_scanned ( @$inventorylist ) { |
278 |
unless ($_->{'missingitem'}) { |
265 |
my $barcode = $should_be_scanned->{barcode}; |
279 |
ModDateLastSeen($_->{'itemnumber'}); |
266 |
unless ( grep /^$barcode$/, @scanned_barcodes ) { |
280 |
$moddatecount++; |
267 |
$should_be_scanned->{problem} = 'not_scanned'; |
|
|
268 |
push @items_with_problems, { %$should_be_scanned }; |
269 |
} |
281 |
} |
270 |
} |
282 |
} |
271 |
} |
283 |
|
272 |
|
284 |
# Removing items that don't have any problems from loop |
273 |
for my $item ( @items_with_problems ) { |
285 |
@$res = grep { $_->{missingitem} || $_->{wrongplace} || $_->{changestatus} } @$res; |
274 |
my $biblio = C4::Biblio::GetBiblioData($item->{biblionumber}); |
|
|
275 |
$item->{title} = $biblio->{title}; |
276 |
$item->{author} = $biblio->{author}; |
277 |
} |
278 |
|
279 |
# If a barcode file is given, we want to show problems, else all items |
280 |
my @results; |
281 |
@results = $uploadbarcodes |
282 |
? @items_with_problems |
283 |
: $op |
284 |
? @$inventorylist |
285 |
: (); |
286 |
|
286 |
|
287 |
$template->param( |
287 |
$template->param( |
288 |
moddatecount => $moddatecount, |
288 |
moddatecount => $moddatecount, |
289 |
loop => $res, |
289 |
loop => \@results, |
290 |
nextoffset => ( $offset + $pagesize ), |
|
|
291 |
prevoffset => ( $offset ? $offset - $pagesize : 0 ), |
292 |
op => $op |
290 |
op => $op |
293 |
); |
291 |
); |
294 |
|
292 |
|
Lines 319-353
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){
Link Here
|
319 |
/ ) { |
317 |
/ ) { |
320 |
push @translated_keys, $columns_def_hashref->{$key}; |
318 |
push @translated_keys, $columns_def_hashref->{$key}; |
321 |
} |
319 |
} |
|
|
320 |
push @translated_keys, 'problem' if $uploadbarcodes; |
322 |
|
321 |
|
323 |
$csv->combine(@translated_keys); |
322 |
$csv->combine(@translated_keys); |
324 |
print $csv->string, "\n"; |
323 |
print $csv->string, "\n"; |
325 |
|
324 |
|
326 |
my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /; |
325 |
my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /; |
327 |
for my $re (@$res) { |
326 |
for my $item ( @results ) { |
328 |
my @line; |
327 |
my @line; |
329 |
for my $key (@keys) { |
328 |
for my $key (@keys) { |
330 |
push @line, $re->{$key}; |
329 |
push @line, $item->{$key}; |
331 |
} |
330 |
} |
332 |
if ($re->{wrongplace}) { |
331 |
if ( defined $item->{problem} ) { |
333 |
push @line, "wrong place"; |
332 |
if ( $item->{problem} eq 'wrongplace' ) { |
334 |
} elsif ($re->{missingitem}) { |
333 |
push @line, "wrong place"; |
335 |
push @line, "missing item"; |
334 |
} elsif ( $item->{problem} eq 'missingitem' ) { |
336 |
} elsif ($re->{changestatus}) { |
335 |
push @line, "missing item"; |
337 |
push @line, "change item status"; |
336 |
} elsif ( $item->{problem} eq 'changestatus' ) { |
|
|
337 |
push @line, "change item status"; |
338 |
} elsif ($item->{problem} eq 'not_scanned' ) { |
339 |
push @line, "item not scanned"; |
340 |
} |
338 |
} |
341 |
} |
339 |
$csv->combine(@line); |
342 |
$csv->combine(@line); |
340 |
print $csv->string, "\n"; |
343 |
print $csv->string, "\n"; |
341 |
} |
344 |
} |
342 |
# Adding not found barcodes |
345 |
# Adding not found barcodes |
343 |
foreach my $error (@errorloop) { |
346 |
foreach my $error (@errorloop) { |
344 |
my @line; |
347 |
my @line; |
345 |
if ($error->{'ERR_BARCODE'}) { |
348 |
if ($error->{'ERR_BARCODE'}) { |
346 |
push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys; |
349 |
push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys; |
347 |
push @line, "barcode not found"; |
350 |
push @line, "barcode not found"; |
348 |
$csv->combine(@line); |
351 |
$csv->combine(@line); |
349 |
print $csv->string, "\n"; |
352 |
print $csv->string, "\n"; |
350 |
} |
353 |
} |
351 |
} |
354 |
} |
352 |
exit; |
355 |
exit; |
353 |
} |
356 |
} |
354 |
- |
|
|