Skip to content

Commit

Permalink
MT6223: multiple fixes for inventory
Browse files Browse the repository at this point in the history
* 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
(cherry picked from commit b575155)
  • Loading branch information
PaulPoulain authored and clrh committed Jun 22, 2011
1 parent c2ff692 commit bd0bf4f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 42 deletions.
2 changes: 1 addition & 1 deletion C4/Items.pm
Expand Up @@ -1036,7 +1036,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
Expand Down
28 changes: 21 additions & 7 deletions koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tmpl
Expand Up @@ -196,7 +196,11 @@ $(document).ready(function(){
<tr>
<th>Seen</th>
<th>Barcode</th>
<th>Location</th>
<th>Title</th>
<th>Status</th>
<th>Lost</th>
<th>Damaged</th>
<th>Unseen since</th>
<th>Problems</th>
</tr>
Expand All @@ -209,19 +213,29 @@ $(document).ready(function(){
<!-- TMPL_VAR NAME="barcode" -->
</td>
<td>
<p><b><!-- TMPL_VAR NAME="itemcallnumber" --></b> - <a href="#" onclick="window.open('/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!--TMPL_VAR Name="biblionumber"-->','marcview','width=800,height=600,toolbar=0,scrollbars=1');"><!-- TMPL_VAR NAME="title" escape="html" --></a></p>
<!-- TMPL_VAR name="homebranch" --> <!-- TMPL_VAR name="location" --> [<!-- TMPL_VAR NAME="itemcallnumber" -->]
</td>
<td>
<p><a href="#" onclick="window.open('/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!--TMPL_VAR Name="biblionumber"-->','marcview','width=800,height=600,toolbar=0,scrollbars=1');"><!-- TMPL_VAR NAME="title" escape="html" --></a></p>
<p><!-- TMPL_VAR NAME="author" --></p>
</td>
<td>
<!-- TMPL_VAR name="notforloan" -->
</td>
<td>
<!-- TMPL_VAR name="itemlost" -->
</td>
<td>
<!-- TMPL_VAR name="damaged" -->
</td>
<td>
<p><!-- TMPL_VAR name="datelastseen" --></p>
</td>
<td>
<!-- TMPL_IF name="notfoundbarcode" -->
<p style="background: red;">Not found among barcodes in barcodes file.</p>
<!-- TMPL_ELSIF name="notfoundkoha" -->
<p style="background: red;">Not found in koha.</p>
<!-- TMPL_ELSE -->
<p style="background: green;">None</p>
<!-- TMPL_IF name="wrongplace" -->
<p>Item should not have been scanned</p>
<!-- TMPL_ELSIF name="missingitem" -->
<p>Item missing</p>
<!-- /TMPL_IF -->
</td>
</tr>
Expand Down
71 changes: 37 additions & 34 deletions tools/inventory.pl
Expand Up @@ -26,6 +26,7 @@
my $input = CGI->new;
my $uploadbarcodes = $input->param('uploadbarcodes');

use List::MoreUtils qw /none/;
use C4::Auth;
use C4::Context;
use C4::Output;
Expand Down Expand Up @@ -110,7 +111,7 @@
for my $authvfield (@$statuses) {
$staton->{ $authvfield->{fieldname} } = [];
for my $authval ( @{ $authvfield->{values} } ) {
if ( $input->param( 'status-' . $authvfield->{fieldname} . '-' . $authval->{id} ) eq 'on' ) {
if ( $input->param( 'status-' . $authvfield->{fieldname} . '-' . $authval->{id} ) && $input->param( 'status-' . $authvfield->{fieldname} . '-' . $authval->{id} ) eq 'on' ) {
push @{ $staton->{ $authvfield->{fieldname} } }, $authval->{id};
}
}
Expand Down Expand Up @@ -185,41 +186,39 @@
$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 ( ( ( $input->param('compareinv2barcd') eq 'on' ) && ( scalar @brcditems != scalar @$res ) ) && length($uploadbarcodes) > 0 ) {
if ( scalar @brcditems > scalar @$res ) {
for my $brcditem (@brcditems) {
if ( !grep( /$brcditem->{barcode}/, @$res ) ) {
$brcditem->{notfoundkoha} = 1;
push @$res, $brcditem;
}
}
} else {
my @notfound;
for my $item (@$res) {
if ( !grep( /$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 { $temp->{barcode} eq $_->{barcode} && !$_->{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 ( $input->param('CSVexport') eq 'on' ) {
eval { use Text::CSV };
Expand All @@ -229,11 +228,15 @@
-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 ) {
for my $key ( qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged / ) {
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";
}
Expand Down

0 comments on commit bd0bf4f

Please sign in to comment.