From 8ca5d5ff85c429ee972b3f80f91f5b27a58cf5d5 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Tue, 5 Apr 2011 11:50:48 +0200 Subject: [PATCH] Bug 5213 - Suffix number sequence not resetting properly in hmyymmincr barcode autogen pattern MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Two things are happening. First, the SELECT does not account for a branchcode greater than 2 chars. This is fixed by just selecting the final four digits representing the incremental suffix from the barcode field. Second, the incremental suffix (4 digits) is not rolling back over to zero when reaching 9999. This pattern probably needs help. It should allow for cataloging of 10000 items per month as is. I would not recommend doing barcode numbering this way, but need to support it since it is in use in at least one library. This patch also impliments strict and warnings per Bug 2505 Signed-off-by: Stéphane Delaune Signed-off-by: Chris Cormack --- cataloguing/value_builder/barcode.pl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cataloguing/value_builder/barcode.pl b/cataloguing/value_builder/barcode.pl index 3c6ef740b1..c05ec48b26 100755 --- a/cataloguing/value_builder/barcode.pl +++ b/cataloguing/value_builder/barcode.pl @@ -1,8 +1,6 @@ #!/usr/bin/perl - -# $Id: barcode.pl,v 1.1.2.2 2006/09/20 02:24:42 kados Exp $ - # Copyright 2000-2002 Katipo Communications +# Parts copyright 2008-2010 Foundations Bible College # # This file is part of Koha. # @@ -19,10 +17,13 @@ # 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; FIXME - Bug 2505 +use strict; +use warnings; +no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings + use C4::Context; require C4::Dates; + my $DEBUG = 0; =head1 @@ -99,11 +100,12 @@ sub plugin_javascript { } elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit $year = substr($year, -2); - $query = "SELECT MAX(CAST(SUBSTRING(barcode,7,4) AS signed)) FROM items WHERE barcode REGEXP ?"; + $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; my $sth = $dbh->prepare($query); $sth->execute("^[a-zA-Z]{1,}$year"); while (my ($count)= $sth->fetchrow_array) { $nextnum = $count if $count; + $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 10000 books per month warn "Existing incremental number = $nextnum" if $DEBUG; } $nextnum++; -- 2.39.2