Kyle M Hall
b280b4890c
The hbyymmincr autoBarcode builder looks up all barcodes that begin with any number of letters ( the branchcode ) and a two-digit year directly afterward ( e.g. MPL15 ), then grabs the last four digits as the increment counter. The problem is, this does not take months into account, so unlike the description that says the system is limited to 10,000 items a month, it is limited to 10,000 items per *year*. This situation can easily be corrected my adding the month into the lookup ( e.g. MPL1501 ). Test Plan: 1) Enable autoBarcode, set to hbyymmincr 2) Catalog an item, let the barcode.pl plugin generate the next barcode. 3) Catalog an item with the barcode MPL15009999 4) Catalog another item, use the barcode.pl plugin to generate the next barcode. 5) Note the barcode is generated ends with '0001' instead of the correct increment 6) Apply this patch 7) Repeat step 4 8) Note the barcode now ends with the correct increment Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Jeanne Heicher <nppublib@pa.net> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Problem confirmed - the continuing number bit was not reset to start counting from 1 again on the beginning of a new month. Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
110 lines
3.5 KiB
Perl
110 lines
3.5 KiB
Perl
#!/usr/bin/perl
|
|
#
|
|
# Copyright 2008-2010 Foundations Bible College
|
|
# Parts copyright 2012 C & P Bibliography Services
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it under the
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
# Foundation; either version 2 of the License, or (at your option) any later
|
|
# version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with Koha; if not, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
package C4::Barcodes::ValueBuilder::incremental;
|
|
use C4::Context;
|
|
my $DEBUG = 0;
|
|
|
|
sub get_barcode {
|
|
my ($args) = @_;
|
|
my $nextnum;
|
|
# not the best, two catalogers could add the same barcode easily this way :/
|
|
my $query = "select max(abs(barcode)) from items";
|
|
my $sth = C4::Context->dbh->prepare($query);
|
|
$sth->execute();
|
|
while (my ($count)= $sth->fetchrow_array) {
|
|
$nextnum = $count;
|
|
}
|
|
$nextnum++;
|
|
return $nextnum;
|
|
}
|
|
|
|
1;
|
|
|
|
package C4::Barcodes::ValueBuilder::hbyymmincr;
|
|
use C4::Context;
|
|
my $DEBUG = 0;
|
|
|
|
sub get_barcode {
|
|
my ($args) = @_;
|
|
my $nextnum = 0;
|
|
my $year = substr($args->{year}, -2);
|
|
my $month = $args->{mon};
|
|
my $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
|
|
my $sth = C4::Context->dbh->prepare($query);
|
|
$sth->execute("^[-a-zA-Z]{1,}$year$month");
|
|
while (my ($count)= $sth->fetchrow_array) {
|
|
$nextnum = $count if $count;
|
|
$nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 9999 items per month
|
|
warn "Existing incremental number = $nextnum" if $DEBUG;
|
|
}
|
|
$nextnum++;
|
|
$nextnum = sprintf("%0*d", "4",$nextnum);
|
|
$nextnum = $year . $month . $nextnum;
|
|
warn "New hbyymmincr Barcode = $nextnum" if $DEBUG;
|
|
my $scr = "
|
|
for (i=0 ; i<document.f.field_value.length ; i++) {
|
|
if (document.f.tag[i].value == '$args->{loctag}' && document.f.subfield[i].value == '$args->{locsubfield}') {
|
|
fnum = i;
|
|
}
|
|
}
|
|
if (\$('#' + id).val() == '') {
|
|
\$('#' + id).val(document.f.field_value[fnum].value + '$nextnum');
|
|
}
|
|
";
|
|
return $nextnum, $scr;
|
|
}
|
|
|
|
|
|
package C4::Barcodes::ValueBuilder::annual;
|
|
use C4::Context;
|
|
my $DEBUG = 0;
|
|
|
|
sub get_barcode {
|
|
my ($args) = @_;
|
|
my $nextnum;
|
|
my $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
|
|
my $sth=C4::Context->dbh->prepare($query);
|
|
$sth->execute("$args->{year}%");
|
|
while (my ($count)= $sth->fetchrow_array) {
|
|
warn "Examining Record: $count" if $DEBUG;
|
|
$nextnum = $count if $count;
|
|
}
|
|
$nextnum++;
|
|
$nextnum = sprintf("%0*d", "4",$nextnum);
|
|
$nextnum = "$args->{year}-$nextnum";
|
|
return $nextnum;
|
|
}
|
|
|
|
1;
|
|
|
|
|
|
=head1 Barcodes::ValueBuilder
|
|
|
|
This module is intended as a shim to ease the eventual transition from
|
|
having all barcode-related code in the value builder plugin .pl file
|
|
to using C4::Barcodes. Since the shift will require a rather significant
|
|
amount of refactoring, this module will return value builder-formatted
|
|
results, at first by merely running the code that was formerly in the
|
|
barcodes.pl value builder, but later by using C4::Barcodes.
|
|
|
|
=cut
|
|
|
|
1;
|