@@ -, +, @@ this checks expansion of 12 digit UPC-A to 13 digit EAN-13 and zero padding --- C4/Circulation.pm | 10 ++++++++++ installer/data/mysql/sysprefs.sql | 2 +- installer/data/mysql/updatedatabase.pl | 7 +++++++ .../en/modules/admin/preferences/circulation.pref | 1 + t/Circulation_barcodedecode.t | 4 +++- 5 files changed, 22 insertions(+), 2 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -38,6 +38,8 @@ use C4::Branch; # GetBranches use C4::Log; # logaction use C4::Koha qw(GetAuthorisedValueByCode); use C4::Overdues qw(CalcFine UpdateFine); +use Algorithm::CheckDigits; + use Data::Dumper; use Koha::DateUtils; use Koha::Calendar; @@ -169,6 +171,14 @@ sub barcodedecode { $barcode =~ s/^(\D+)[0]*(\d+)$/$branch-$1-$2/i; } } + } elsif ($filter eq 'EAN13') { + my $ean = CheckDigits('ean'); + if ( $ean->is_valid($barcode) ) { + #$barcode = sprintf('%013d',$barcode); # this doesn't work on 32-bit systems + $barcode = '0' x ( 13 - length($barcode) ) . $barcode; + } else { + warn "# [$barcode] not valid EAN-13/UPC-A\n"; + } } return $barcode; # return barcode, modified or not } --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -166,7 +166,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('emailLibrarianWhenHoldIsPlaced',0,'If ON, emails the librarian whenever a hold is placed',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('numReturnedItemsToShow','20','Number of returned items to show on the check-in page',NULL,'Integer'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesMode','test','Choose the fines mode, \'off\', \'test\' (emails admin report) or \'production\' (accrue overdue fines). Requires accruefines cronjob.','off|test|production','Choice'); -INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','whitespace|T-prefix|cuecat|libsuite8','Choice'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','whitespace|T-prefix|cuecat|libsuite8|EAN13','Choice'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('singleBranchMode',0,'Operate in Single-branch mode, hide branch selection in the OPAC',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('URLLinkText','','Text to display as the link anchor in the OPAC',NULL,'free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACViewOthersSuggestions',0,'If ON, allows all suggestions to be displayed in the OPAC',NULL,'YesNo'); --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -5536,6 +5536,13 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.09.00.XXX"; # FIXME +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("UPDATE systempreferences SET options=concat(options,'|EAN13') WHERE variable='itemBarcodeInputFilter' AND options NOT LIKE '%EAN13%'"); + print "Upgrade to $DBversion done (Add itemBarcodeInputFilter choice EAN13)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -16,6 +16,7 @@ Circulation: cuecat: Convert from CueCat form T-prefix: Remove the first number from T-prefix style libsuite8: Convert from Libsuite8 form + EAN13: EAN-13 or zero-padded UPC-A from - scanned item barcodes. - - Sort previous checkouts on the circulation page from --- a/t/Circulation_barcodedecode.t +++ a/t/Circulation_barcodedecode.t @@ -4,7 +4,7 @@ use strict; use warnings; -use Test::More tests => 24; +use Test::More tests => 26; C4::Context->_new_userenv(123456); C4::Context->set_userenv(1,'kmkale' , 1, 'kk1' , 'IMS', 0, 'kmkale@anantcorp.com'); @@ -18,6 +18,7 @@ our %inputs = ( whitespace => [" 26002315", "26002315 ", "\n\t26002315\n"], 'T-prefix' => [qw(T0031472 T32)], 'libsuite8' => ['b000126', 'b12', 'B0126', 'IMS-B-126', 'ims-b-126','CD0000024','00123','11998'], + EAN13 => [qw(892685001928 695152)], other => [qw(26002315 T0031472 T32 Alphanum123), "Alpha Num 345"], ); our %outputs = ( @@ -25,6 +26,7 @@ our %outputs = ( whitespace => [qw(26002315 26002315 26002315)], 'T-prefix' => [qw(T0031472 T0000002 )], 'libsuite8' => ['IMS-b-126', 'IMS-b-12', 'IMS-B-126', 'IMS-B-126', 'ims-b-126','IMS-CD-24','IMS-b-123','IMS-b-11998'], + EAN13 => [qw(0892685001928 0000000695152)], other => [qw(26002315 T0031472 T32 Alphanum123), "Alpha Num 345"], ); --