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