28e5427c60
Implement auto-incrementing EAN-13 barcodes To make this work, C4::Barcodes::next was modified to call process_tail with new incremented value so that process_tail can generate correct checksum. Since process_tail is currenlty not used by any barcodes, this change is safe. C4::Barcodes is used by addbiblio.pl when adding multiple records, while value_builder is used in all other cases. Test scenario: 1. prove t/Barcodes_EAN13.t 2. KOHA_CONF=/etc/koha/sites/fer/koha-conf.xml prove t/db_dependent/Barcodes.t this will check C4::Barcode implementataion 3. in systempreference change autoBarcode to incremental EAN-13 barcode 4. edit two items of any biblio assigning barcodes and verify that numbers are increasing. Have in mind that last digit is check digit, and it doesn't increment, but is calculated from barcode itself. Example with checksum in brackets: 000000086275[2], 000000086276[9], 000000086277[6] 5. Add Item and verify that it gets assigned next barcode 6. Add & Duplicate item and verify barcode increase 7. Add Multiple Copies and verify that barcode increase for each copy Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz> Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
57 lines
1.6 KiB
Perl
57 lines
1.6 KiB
Perl
package C4::Barcodes::EAN13;
|
|
|
|
# Copyright 2012 Koha Development team
|
|
#
|
|
# 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.
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use C4::Context;
|
|
use C4::Debug;
|
|
|
|
use Algorithm::CheckDigits;
|
|
|
|
use vars qw($VERSION @ISA);
|
|
use vars qw($debug $cgi_debug); # from C4::Debug, of course
|
|
|
|
BEGIN {
|
|
$VERSION = 0.01;
|
|
@ISA = qw(C4::Barcodes);
|
|
}
|
|
|
|
sub parse {
|
|
my $self = shift;
|
|
my $barcode = (@_) ? shift : $self->value;
|
|
my $ean = CheckDigits('ean');
|
|
if ( $ean->is_valid($barcode) ) {
|
|
return ( '', $ean->basenumber($barcode), $ean->checkdigit($barcode) );
|
|
} else {
|
|
die "$barcode not valid EAN-13 barcode";
|
|
}
|
|
}
|
|
|
|
sub process_tail {
|
|
my ( $self,$tail,$whole,$specific ) = @_;
|
|
my $ean = CheckDigits('ean');
|
|
my $full = $ean->complete($whole);
|
|
my $chk = $ean->checkdigit($full);
|
|
$debug && warn "# process_tail $tail -> $chk [$whole -> $full] $specific";
|
|
return $chk;
|
|
}
|
|
|
|
1;
|
|
__END__
|