use C4::Barcodes::hbyymmincr;
use C4::Barcodes::annual;
use C4::Barcodes::incremental;
+use C4::Barcodes::EAN13;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
use vars qw($debug $cgi_debug); # from C4::Debug, of course
$incr++;
$debug and warn "$incr";
- $head = $self->process_head($head,$max,$specific);
- $tail = $self->process_tail($tail,$max,$specific);
+ $head = $self->process_head($head,$incr,$specific);
+ $tail = $self->process_tail($tail,$incr,$specific); # XXX use $incr and not $max!
my $next_value = $head . $incr . $tail;
$debug and print STDERR "( next ) max barcode found: $next_value\n";
return $next_value;
incremental => sub {C4::Barcodes::incremental->new_object(@_);},
hbyymmincr => sub {C4::Barcodes::hbyymmincr->new_object(@_); },
OFF => sub {C4::Barcodes::OFF->new_object(@_); },
+ EAN13 => sub {C4::Barcodes::EAN13->new_object(@_); },
};
sub new {
--- /dev/null
+package C4::Barcodes::EAN13;
+
+# 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 Carp;
+
+use C4::Context;
+use C4::Debug;
+use C4::Dates;
+
+use Algorithm::CheckDigits;
+
+use vars qw($VERSION @ISA);
+use vars qw($debug $cgi_debug); # from C4::Debug, of course
+use vars qw($width);
+
+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 {
+ carp "$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__
use C4::Context;
require C4::Dates;
+use Algorithm::CheckDigits;
+
my $DEBUG = 0;
=head1
}
";
}
+ elsif ($autoBarcodeType eq 'EAN13') {
+ # not the best, two catalogers could add the same barcode easily this way :/
+ $query = "select max(abs(barcode)) from items";
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ while (my ($count)= $sth->fetchrow_array) {
+ $nextnum = $count;
+ }
+ my $ean = CheckDigits('ean');
+ if ( $ean->is_valid($nextnum) ) {
+ my $next = $ean->basenumber( $nextnum ) + 1;
+ $nextnum = $ean->complete( $next );
+ } else {
+ warn "ERROR: invalid EAN-13 $nextnum, using increment";
+ $nextnum++;
+ }
+ }
+ else {
+ warn "ERROR: unknown autoBarcode: $autoBarcodeType";
+ }
# default js body (if not filled by hbyymmincr)
$scr or $scr = <<END_OF_JS;
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
$dbh->do("UPDATE `systempreferences` SET options='whitespace|t-prefix|cuecat|libsuite8|ean13' WHERE variable='itembarcodeinputfilter'");
print "Upgrade to $dbversion done (Add itemBarcodeInputFilter choice EAN13)\n";
+
+ $dbh->do("UPDATE systempreferences SET options = concat(options,'|EAN13'), explanation = concat(explanation,'; EAN13 - incremental') WHERE variable = 'autoBarcode';");
+ print "Upgrade to $DBversion done ( Added EAN13 barcode autogeneration sequence )\n";
setversion($dbversion);
}
incremental: generated in the form 1, 2, 3.
annual: generated in the form <year>-0001, <year>-0002.
hbyymmincr: generated in the form <branchcode>yymm0001.
+ EAN13: incremental EAN-13 barcodes
"OFF": not generated automatically.
Display:
-
--- /dev/null
+#!/usr/bin/perl
+#
+# This Koha test module is a stub!
+# Add more tests here!!!
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+BEGIN {
+ use_ok('C4::Barcodes::EAN13');
+}
+
use strict;
use warnings;
-use Test::More tests => 49;
+use Test::More tests => 66;
BEGIN {
use FindBin;
use lib $FindBin::Bin;
incremental => [],
annual => [],
hbyymmincr => ['MAIN'],
+ EAN13 => ['0000000695152','892685001928'],
);
print "\n";