From 0eccfae941b78a1c6a6616296d98f3333e318648 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 4 May 2012 12:14:43 +0200 Subject: [PATCH 1/1] Bug 7684: multiple fixes for inventory * when a file was uploaded and the comparison with catalogue range requested, the comparison was wrong: the logic was wrong * items that were not supposed to be scanned (ie: supposed to be on another shelf) didn't had the author and title, it was hard to retrieve them on the shelved * some useful fields were missing, like homebranch, location, status * the CSV export contained all the item information. It should contain the same informations as the screen Behaviour now: * scan a list of barcode & select a range of location * if a barcode has been scanned and should not be (mis placed item), the information is displayed * if you choose "compare barcodes list to result option", the resulting list contains all items that have been scanned and those that were supposed to be. Any item not in both list appears with a specific message on the last column --- C4/Items.pm | 2 +- .../prog/en/modules/tools/inventory.tt | 28 +++++-- tools/inventory.pl | 94 ++++++++++++-------- 3 files changed, 79 insertions(+), 45 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 52423a2..b128110 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -963,7 +963,7 @@ sub GetItemsForInventory { my ( @bind_params, @where_strings ); my $query = <<'END_SQL'; -SELECT items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, datelastseen +SELECT items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, datelastseen, homebranch, location FROM items LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt index d8eb82f..e3fdae6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt @@ -127,7 +127,7 @@ $(document).ready(function(){ - + [% END %] [% END %] @@ -196,7 +196,11 @@ $(document).ready(function(){ Seen Barcode + Location Title + Status + Lost + Damaged Unseen since Problems @@ -209,17 +213,29 @@ $(document).ready(function(){ [% loo.barcode %] -

[% loo.itemcallnumber %] - [% loo.title |html %]

+ [% loo.homebranch %] [% loo.location %] [[% loo.itemcallnumber %]] + + +

[% loo.title |html %]

[% loo.author %]

+ [% loo.notforloan %] + + + [% loo.itemlost %] + + + [% loo.damaged %] + +

[% loo.datelastseen %]

- [% IF ( loo.notfoundbarcode ) %] -

Not found among barcodes in barcodes file.

- [% ELSIF ( loo.notfoundkoha ) %] -

Not found in Koha.

+ [% IF ( loo.wrongplace ) %] +

Item should not have been scanned.

+ [% ELSIF ( loo.missingitem ) %] +

Item missing.

[% ELSE %]

None

[% END %] diff --git a/tools/inventory.pl b/tools/inventory.pl index 5e7b198..ba484f9 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -18,11 +18,12 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -use strict; -use warnings; +use Modern::Perl; #need to open cgi and get the fh before anything else opens a new cgi context (see C4::Auth) use CGI; +use List::MoreUtils qw /none/; + my $input = CGI->new; my $uploadbarcodes = $input->param('uploadbarcodes'); @@ -104,12 +105,12 @@ for my $statfield (qw/items.notforloan items.itemlost items.wthdrawn items.damag } } $template->param( statuses => $statuses ); -my $staton = {}; #authorized values that are ticked +my $staton = {}; #authorized values that are ticked for my $authvfield (@$statuses) { $staton->{$authvfield->{fieldname}} = []; for my $authval (@{$authvfield->{values}}){ - if ( defined $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{id}) && $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{id}) eq 'on' ){ - push @{$staton->{$authvfield->{fieldname}}}, $authval->{id}; + if ( defined $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{authorised_value}) && $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{authorised_value}) eq 'on' ){ + push @{$staton->{$authvfield->{fieldname}}}, $authval->{authorised_value}; } } } @@ -179,40 +180,40 @@ if ($uploadbarcodes && length($uploadbarcodes)>0){ # $template->param(errorfile=>$errorfile) if ($errorfile); $template->param(errorloop=>\@errorloop) if (@errorloop); } -#if we want to compare the results to a list of barcodes, or we have no barcode file -if ( ! ($uploadbarcodes && length($uploadbarcodes)>0 ) || ( $input->param('compareinv2barcd') eq 'on' && length($uploadbarcodes)>0) ) { - if ($markseen) { - foreach ($input->param) { - /SEEN-(.+)/ and &ModDateLastSeen($1); - } - } - if ($markseen or $op) { - $res = GetItemsForInventory( $minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $branch, $offset, $pagesize, $staton ); - $template->param(loop =>$res, - nextoffset => ($offset+$pagesize), - prevoffset => ($offset?$offset-$pagesize:0), - ); + +# mark seen if applicable (ie: coming form mark seen checkboxes) +if ($markseen) { + foreach ( $input->param ) { + /SEEN-(.+)/ and &ModDateLastSeen($1); } - if ( defined $input->param('compareinv2barcd') && ( ( $input->param('compareinv2barcd') eq 'on' ) && ( scalar @brcditems != scalar @$res ) ) && length($uploadbarcodes) > 0 ){ - if ( scalar @brcditems > scalar @$res ){ - for my $brcditem (@brcditems) { - if (! grep( $_->{barcode} =~ /$brcditem->{barcode}/ , @$res) ){ - $brcditem->{notfoundkoha} = 1; - push @$res, $brcditem; - } - } - } else { - my @notfound; - for my $item (@$res) { - if ( ! grep( $_->{barcode} =~ /$item->{barcode}/ , @brcditems) ){ - $item->{notfoundbarcode} = 1; - push @notfound, $item; - } - } - $res = [@$res, @notfound]; - } +} +# now build the result list: inventoried items if requested, and mis-placed items -always- +my $inventorylist; +if ( $markseen or $op ) { + # retrieve all items in this range. + $inventorylist = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, $offset, $pagesize, $staton); + # if comparison is requested, then display all the result (otherwise, we'll use the inventorylist to find missplaced items, later + $res = $inventorylist if $input->param('compareinv2barcd'); +} +# set "missing" flags for all items with a datelastseen before the choosen datelastseen +foreach (@$res) {$_->{missingitem}=1 if C4::Dates->new($_->{datelastseen})->output('iso') lt C4::Dates->new($datelastseen)->output('iso')} +# insert "wrongplace" to all scanned items that are not supposed to be in this range +# note this list is always displayed, whatever the librarian has choosen for comparison +foreach my $temp (@brcditems) { + next if $temp->{onloan}; # skip checked out items + if (none { defined $_->{barcode} and $temp->{barcode} eq $_->{barcode} and !$_->{onloan} } @$inventorylist) { + $temp->{wrongplace}=1; + my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); + $temp->{title} = $biblio->{title}; + $temp->{author} = $biblio->{author}; + push @$res, $temp; } } +$template->param( + loop => $res, + nextoffset => ( $offset + $pagesize ), + prevoffset => ( $offset ? $offset - $pagesize : 0 ), +); if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ eval {use Text::CSV}; @@ -222,11 +223,28 @@ if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ -type => 'text/csv', -attachment => 'inventory.csv', ); + $csv->combine(qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged /); + print $csv->string, "\n"; for my $re (@$res){ my @line; - for my $key (keys %$re) { - push @line, $re->{$key}; + for my $key ( qw / title author barcode itemnumber homebranch location itemcallnumber notforloan itemlost damaged / ) { + given ( $key ) { + when ( /notforloan/ ) { + push @line, GetAuthorisedValueDesc('', '', $re->{$key}, '', '', 'NOT_LOAN', ''); + } + when ( /itemlost/ ) { + push @line, GetAuthorisedValueDesc('', '', $re->{$key}, '', '', 'LOST', ''); + } + when ( /damaged/ ) { + push @line, GetAuthorisedValueDesc('', '', $re->{$key}, '', '', 'DAMAGED', ''); + } + default { + push @line, $re->{$key}; + } + } } + push @line, "wrong place" if $re->{wrongplace}; + push @line, "missing item" if $re->{missingitem}; $csv->combine(@line); print $csv->string, "\n"; } -- 1.7.7.3