[Koha-patches] [PATCH] Bug #6057 - Improve finding next stock number

Alex Arnaud alex.arnaud at biblibre.com
Tue Apr 5 14:11:59 CEST 2011


---
 cataloguing/value_builder/stocknumber.pl |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/cataloguing/value_builder/stocknumber.pl b/cataloguing/value_builder/stocknumber.pl
index 005f011..4c9b267 100755
--- a/cataloguing/value_builder/stocknumber.pl
+++ b/cataloguing/value_builder/stocknumber.pl
@@ -53,14 +53,11 @@ sub plugin_javascript {
 
 	my $branchcode = C4::Context->userenv->{'branch'};
 
-	$query = "SELECT MAX(CAST(SUBSTRING_INDEX(stocknumber,'_',-1) AS SIGNED)) FROM items WHERE homebranch = ?";
+	$query = "SELECT MAX(CAST(SUBSTRING_INDEX(stocknumber,'_',-1) AS SIGNED))+1 FROM items WHERE homebranch = ? AND stocknumber LIKE ?";
 	my $sth=$dbh->prepare($query);
-	$sth->execute($branchcode);
-	while (my ($count)= $sth->fetchrow_array) {
-		$nextnum = $count;
-	}
-	$nextnum++;
 
+	$sth->execute($branchcode,$branchcode."_%");
+	my ($nextnum) = $sth->fetchrow;
 	my $nextnum = $branchcode.'_'.$nextnum;
 
     my $scr = <<END_OF_JS;
-- 
1.6.3.3



More information about the Koha-patches mailing list