|
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 170-183
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
Link Here
|
| 170 |
|
161 |
|
| 171 |
while ( my $barcode = <$uploadbarcodes> ) { |
162 |
while ( my $barcode = <$uploadbarcodes> ) { |
| 172 |
$barcode =~ s/\r?\n$//; |
163 |
$barcode =~ s/\r?\n$//; |
| 173 |
$barcodelist .= ($barcodelist) ? '|' . $barcode : $barcode; |
164 |
next unless $barcode; |
| 174 |
if ( $qwthdrawn->execute($barcode) && $qwthdrawn->rows ) { |
165 |
if ( $qwthdrawn->execute($barcode) && $qwthdrawn->rows ) { |
| 175 |
push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; |
166 |
push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; |
| 176 |
} else { |
167 |
} else { |
| 177 |
my $item = GetItem( '', $barcode ); |
168 |
my $item = GetItem( '', $barcode ); |
| 178 |
if ( defined $item && $item->{'itemnumber'} ) { |
169 |
if ( defined $item && $item->{'itemnumber'} ) { |
| 179 |
ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} ); |
170 |
ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} ); |
| 180 |
push @brcditems, $item; |
171 |
push @scanned_items, $item; |
| 181 |
$count++; |
172 |
$count++; |
| 182 |
$qonloan->execute($barcode); |
173 |
$qonloan->execute($barcode); |
| 183 |
if ($qonloan->rows){ |
174 |
if ($qonloan->rows){ |
|
Lines 195-291
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
Link Here
|
| 195 |
} |
186 |
} |
| 196 |
|
187 |
|
| 197 |
} |
188 |
} |
| 198 |
$qonloan->finish; |
189 |
$template->param( date => $date, Number => $count ); |
| 199 |
$qwthdrawn->finish; |
|
|
| 200 |
$template->param( date => format_date($date), Number => $count ); |
| 201 |
$template->param( errorloop => \@errorloop ) if (@errorloop); |
190 |
$template->param( errorloop => \@errorloop ) if (@errorloop); |
| 202 |
|
|
|
| 203 |
|
| 204 |
} |
191 |
} |
| 205 |
$template->param(barcodelist => $barcodelist); |
|
|
| 206 |
|
192 |
|
| 207 |
# now build the result list: inventoried items if requested, and mis-placed items -always- |
193 |
# now build the result list: inventoried items if requested, and mis-placed items -always- |
| 208 |
my $inventorylist; |
194 |
my $inventorylist; |
|
|
195 |
my @items_with_problems; |
| 209 |
if ( $markseen or $op ) { |
196 |
if ( $markseen or $op ) { |
| 210 |
# retrieve all items in this range. |
197 |
# retrieve all items in this range. |
| 211 |
my $totalrecords; |
198 |
my $totalrecords; |
| 212 |
($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton); |
199 |
($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton); |
|
|
200 |
} |
| 213 |
|
201 |
|
| 214 |
# Real copy |
202 |
# If "compare barcodes list to results" has been checked, we want to alert for missing items |
| 215 |
my @res_copy; |
203 |
if ( $compareinv2barcd ) { |
| 216 |
foreach (@$inventorylist) { |
204 |
# set "missing" flags for all items with a datelastseen (dls) before the choosen datelastseen (cdls) |
| 217 |
push @res_copy, $_; |
205 |
my $dls = output_pref( dt_from_string( $datelastseen ), 'iso' ); |
|
|
206 |
foreach my $item ( @$inventorylist ) { |
| 207 |
my $cdls = output_pref( dt_from_string( $_->{datelastseen} ), 'iso' ); |
| 208 |
if ( $cdls lt $dls ) { |
| 209 |
$item->{problem} = 'missingitem'; |
| 210 |
# We have to push a copy of the item, not the reference |
| 211 |
push @items_with_problems, { %$item }; |
| 212 |
} |
| 218 |
} |
213 |
} |
| 219 |
$res = \@res_copy; |
|
|
| 220 |
} |
214 |
} |
| 221 |
|
215 |
|
| 222 |
# set "missing" flags for all items with a datelastseen before the choosen datelastseen |
|
|
| 223 |
foreach (@$res) { $_->{missingitem}=1 if C4::Dates->new($_->{datelastseen})->output('iso') lt C4::Dates->new($datelastseen)->output('iso'); } |
| 224 |
|
216 |
|
| 225 |
# removing missing items from loop if "Compare barcodes list to results" has not been checked |
|
|
| 226 |
@$res = grep {!$_->{missingitem} == 1 } @$res if (!$input->param('compareinv2barcd')); |
| 227 |
|
217 |
|
| 228 |
# insert "wrongplace" to all scanned items that are not supposed to be in this range |
218 |
# insert "wrongplace" to all scanned items that are not supposed to be in this range |
| 229 |
# note this list is always displayed, whatever the librarian has choosen for comparison |
219 |
# note this list is always displayed, whatever the librarian has choosen for comparison |
| 230 |
foreach my $temp (@brcditems) { |
220 |
my $moddatecount = 0; |
|
|
221 |
foreach my $item ( @scanned_items ) { |
| 231 |
|
222 |
|
| 232 |
# Saving notforloan code before it's replaced by it's authorised value for later comparison |
223 |
# Saving notforloan code before it's replaced by it's authorised value for later comparison |
| 233 |
$temp->{'notforloancode'} = $temp->{'notforloan'}; |
224 |
$item->{notforloancode} = $item->{notforloan}; |
| 234 |
|
225 |
|
| 235 |
# Populating with authorised values |
226 |
# Populating with authorised values |
| 236 |
foreach (keys %$temp) { |
227 |
foreach my $field ( keys %$item ) { |
| 237 |
# If the koha field is mapped to a marc field |
228 |
# If the koha field is mapped to a marc field |
| 238 |
my $fc = $temp->{'frameworkcode'} || ''; |
229 |
my $fc = $item->{'frameworkcode'} || ''; |
| 239 |
my ($f, $sf) = GetMarcFromKohaField("items.$_", $fc); |
230 |
my ($f, $sf) = GetMarcFromKohaField("items.$field", $fc); |
| 240 |
if ($f and $sf) { |
231 |
if ($f and $sf) { |
| 241 |
# We replace the code with it's description |
232 |
# We replace the code with it's description |
| 242 |
my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $fc); |
233 |
my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $fc); |
| 243 |
if ($authvals and defined $temp->{$_} and defined $authvals->{$temp->{$_}}) { |
234 |
if ($authvals and defined $item->{$field} and defined $authvals->{$item->{$field}}) { |
| 244 |
$temp->{$_} = $authvals->{$temp->{$_}}; |
235 |
$item->{$field} = $authvals->{$item->{$field}}; |
| 245 |
} |
236 |
} |
| 246 |
} |
237 |
} |
| 247 |
} |
238 |
} |
| 248 |
|
239 |
|
| 249 |
next if $temp->{onloan}; # skip checked out items |
240 |
next if $item->{onloan}; # skip checked out items |
| 250 |
|
241 |
|
| 251 |
# If we have scanned items with a non-matching notforloan value |
242 |
# If we have scanned items with a non-matching notforloan value |
| 252 |
if (none { $temp->{'notforloancode'} eq $_ } @notforloans) { |
243 |
if (none { $item->{'notforloancode'} eq $_ } @notforloans) { |
| 253 |
$temp->{'changestatus'} = 1; |
244 |
$item->{problem} = 'changestatus'; |
| 254 |
my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); |
245 |
push @items_with_problems, { %$item }; |
| 255 |
$temp->{title} = $biblio->{title}; |
|
|
| 256 |
$temp->{author} = $biblio->{author}; |
| 257 |
$temp->{datelastseen} = format_date($temp->{datelastseen}); |
| 258 |
push @$res, $temp; |
| 259 |
|
| 260 |
} |
246 |
} |
| 261 |
if (none { $temp->{barcode} eq $_->{barcode} && !$_->{'onloan'} } @$inventorylist) { |
247 |
if (none { $item->{barcode} eq $_->{barcode} && !$_->{'onloan'} } @$inventorylist) { |
| 262 |
my $temp2 = { %$temp }; |
248 |
$item->{problem} = 'wrongplace'; |
| 263 |
$temp2->{wrongplace}=1; |
249 |
push @items_with_problems, { %$item }; |
| 264 |
my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); |
|
|
| 265 |
$temp2->{title} = $biblio->{title}; |
| 266 |
$temp2->{author} = $biblio->{author}; |
| 267 |
$temp2->{datelastseen} = format_date($temp->{datelastseen}); |
| 268 |
push @$res, $temp2; |
| 269 |
} |
250 |
} |
|
|
251 |
|
| 252 |
# Modify date last seen for scanned items |
| 253 |
ModDateLastSeen($_->{'itemnumber'}); |
| 254 |
$moddatecount++; |
| 270 |
} |
255 |
} |
| 271 |
|
256 |
|
| 272 |
# Finally, modifying datelastseen for remaining items |
257 |
if ( $compareinv2barcd ) { |
| 273 |
my $moddatecount = 0; |
258 |
my @scanned_barcodes = map {$_->{barcode}} @scanned_items; |
| 274 |
foreach (@$res) { |
259 |
for my $should_be_scanned ( @$inventorylist ) { |
| 275 |
unless ($_->{'missingitem'}) { |
260 |
my $barcode = $should_be_scanned->{barcode}; |
| 276 |
ModDateLastSeen($_->{'itemnumber'}); |
261 |
unless ( grep /^$barcode$/, @scanned_barcodes ) { |
| 277 |
$moddatecount++; |
262 |
$should_be_scanned->{problem} = 'not_scanned'; |
|
|
263 |
push @items_with_problems, { %$should_be_scanned }; |
| 264 |
} |
| 278 |
} |
265 |
} |
| 279 |
} |
266 |
} |
| 280 |
|
267 |
|
| 281 |
# Removing items that don't have any problems from loop |
268 |
for my $item ( @items_with_problems ) { |
| 282 |
@$res = grep { $_->{missingitem} || $_->{wrongplace} || $_->{changestatus} } @$res; |
269 |
my $biblio = C4::Biblio::GetBiblioData($item->{biblionumber}); |
|
|
270 |
$item->{title} = $biblio->{title}; |
| 271 |
$item->{author} = $biblio->{author}; |
| 272 |
} |
| 273 |
|
| 274 |
# If a barcode file is given, we want to show problems, else all items |
| 275 |
my @results; |
| 276 |
@results = $uploadbarcodes |
| 277 |
? @items_with_problems |
| 278 |
: $op |
| 279 |
? @$inventorylist |
| 280 |
: (); |
| 283 |
|
281 |
|
| 284 |
$template->param( |
282 |
$template->param( |
| 285 |
moddatecount => $moddatecount, |
283 |
moddatecount => $moddatecount, |
| 286 |
loop => $res, |
284 |
loop => \@results, |
| 287 |
nextoffset => ( $offset + $pagesize ), |
|
|
| 288 |
prevoffset => ( $offset ? $offset - $pagesize : 0 ), |
| 289 |
op => $op |
285 |
op => $op |
| 290 |
); |
286 |
); |
| 291 |
|
287 |
|
|
Lines 316-350
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){
Link Here
|
| 316 |
/ ) { |
312 |
/ ) { |
| 317 |
push @translated_keys, $columns_def_hashref->{$key}; |
313 |
push @translated_keys, $columns_def_hashref->{$key}; |
| 318 |
} |
314 |
} |
|
|
315 |
push @translated_keys, 'problem' if $uploadbarcodes; |
| 319 |
|
316 |
|
| 320 |
$csv->combine(@translated_keys); |
317 |
$csv->combine(@translated_keys); |
| 321 |
print $csv->string, "\n"; |
318 |
print $csv->string, "\n"; |
| 322 |
|
319 |
|
| 323 |
my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /; |
320 |
my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /; |
| 324 |
for my $re (@$res) { |
321 |
for my $item ( @results ) { |
| 325 |
my @line; |
322 |
my @line; |
| 326 |
for my $key (@keys) { |
323 |
for my $key (@keys) { |
| 327 |
push @line, $re->{$key}; |
324 |
push @line, $item->{$key}; |
| 328 |
} |
325 |
} |
| 329 |
if ($re->{wrongplace}) { |
326 |
if ( defined $item->{problem} ) { |
| 330 |
push @line, "wrong place"; |
327 |
if ( $item->{problem} eq 'wrongplace' ) { |
| 331 |
} elsif ($re->{missingitem}) { |
328 |
push @line, "wrong place"; |
| 332 |
push @line, "missing item"; |
329 |
} elsif ( $item->{problem} eq 'missingitem' ) { |
| 333 |
} elsif ($re->{changestatus}) { |
330 |
push @line, "missing item"; |
| 334 |
push @line, "change item status"; |
331 |
} elsif ( $item->{problem} eq 'changestatus' ) { |
|
|
332 |
push @line, "change item status"; |
| 333 |
} elsif ($item->{problem} eq 'not_scanned' ) { |
| 334 |
push @line, "item not scanned"; |
| 335 |
} |
| 335 |
} |
336 |
} |
| 336 |
$csv->combine(@line); |
337 |
$csv->combine(@line); |
| 337 |
print $csv->string, "\n"; |
338 |
print $csv->string, "\n"; |
| 338 |
} |
339 |
} |
| 339 |
# Adding not found barcodes |
340 |
# Adding not found barcodes |
| 340 |
foreach my $error (@errorloop) { |
341 |
foreach my $error (@errorloop) { |
| 341 |
my @line; |
342 |
my @line; |
| 342 |
if ($error->{'ERR_BARCODE'}) { |
343 |
if ($error->{'ERR_BARCODE'}) { |
| 343 |
push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys; |
344 |
push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys; |
| 344 |
push @line, "barcode not found"; |
345 |
push @line, "barcode not found"; |
| 345 |
$csv->combine(@line); |
346 |
$csv->combine(@line); |
| 346 |
print $csv->string, "\n"; |
347 |
print $csv->string, "\n"; |
| 347 |
} |
348 |
} |
| 348 |
} |
349 |
} |
| 349 |
exit; |
350 |
exit; |
| 350 |
} |
351 |
} |
| 351 |
- |
|
|