[Koha-patches] [PATCH] tweak Inventory tool and sub in C4/Items so call number min and max are not required
Michael Hafen
mdhafen at tech.washk12.org
Wed Feb 4 00:46:25 CET 2009
This changes the setting if default values in the inventory tool where
the min and max call number are concerned. Also changes how the query
is formed in C4/Items so that these two are not required.
---
C4/Items.pm | 26 +++++++++++++++++++-------
tools/inventory.pl | 4 ++--
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/C4/Items.pm b/C4/Items.pm
index fba4a21..457c91f 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -978,38 +978,50 @@ offset & size can be used to retrieve only a part of the whole listing (defaut b
sub GetItemsForInventory {
my ( $minlocation, $maxlocation,$location, $itemtype, $datelastseen, $branch, $offset, $size ) = @_;
my $dbh = C4::Context->dbh;
+ my ( @bind_params, @where_strings );
my $query = <<'END_SQL';
SELECT itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, datelastseen
FROM items
LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
-WHERE itemcallnumber >= ?
- AND itemcallnumber <= ?
END_SQL
- my @bind_params = ( $minlocation, $maxlocation );
+
+ if ($minlocation) {
+ push @where_strings, 'itemcallnumber >= ?';
+ push @bind_params, $minlocation;
+ }
+
+ if ($maxlocation) {
+ push @where_strings, 'itemcallnumber <= ?';
+ push @bind_params, $maxlocation;
+ }
if ($datelastseen) {
$datelastseen = format_date_in_iso($datelastseen);
- $query .= ' AND (datelastseen < ? OR datelastseen IS NULL) ';
+ push @where_strings, '(datelastseen < ? OR datelastseen IS NULL)';
push @bind_params, $datelastseen;
}
if ( $location ) {
- $query.= ' AND items.location = ? ';
+ push @where_strings, 'items.location = ?';
push @bind_params, $location;
}
if ( $branch ) {
- $query.= ' AND items.homebranch = ? ';
+ push @where_strings, 'items.homebranch = ?';
push @bind_params, $branch;
}
if ( $itemtype ) {
- $query.= ' AND biblioitems.itemtype = ? ';
+ push @where_strings, 'biblioitems.itemtype = ?';
push @bind_params, $itemtype;
}
+ if ( @where_strings ) {
+ $query .= 'WHERE ';
+ $query .= join ' AND ', @where_strings;
+ }
$query .= ' ORDER BY itemcallnumber, title';
my $sth = $dbh->prepare($query);
$sth->execute( @bind_params );
diff --git a/tools/inventory.pl b/tools/inventory.pl
index a144b17..16aa6b0 100755
--- a/tools/inventory.pl
+++ b/tools/inventory.pl
@@ -29,9 +29,9 @@ use C4::Koha;
use C4::Branch; # GetBranches
my $input = new CGI;
-my $minlocation=$input->param('minlocation') || 'A';
+my $minlocation=$input->param('minlocation') || '';
my $maxlocation=$input->param('maxlocation');
-$maxlocation=$minlocation.'Z' unless $maxlocation;
+$maxlocation=$minlocation.'Z' unless ( $maxlocation || ! $minlocation );
my $location=$input->param('location');
my $itemtype=$input->param('itemtype');
my $datelastseen = $input->param('datelastseen');
--
1.5.6.3
More information about the Koha-patches
mailing list