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