From d01c5105de059b3b9b96db67840bc99436f6eec2 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Tue, 5 Apr 2011 14:10:19 +0200 Subject: [PATCH] Bug #6057 - Improve finding next stock number Signed-off-by: Paul Poulain Signed-off-by: Chris Cormack (cherry picked from commit 00354d93bbfc78a6dcc0bab17ab8ace368e25be4) Signed-off-by: Chris Nighswonger --- cataloguing/value_builder/stocknumber.pl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cataloguing/value_builder/stocknumber.pl b/cataloguing/value_builder/stocknumber.pl index 005f01168f..4c9b2671c1 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 = <