added UPC-A to EAN13 itemBarcodeInputFilter
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 14 Jun 2011 07:54:52 +0000 (09:54 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 23 Jun 2011 17:57:27 +0000 (19:57 +0200)
This tries to expand UPC-A barcodes to EAN13 adding leading zero to support
older RFID readers with just UPC-A decoding when barcodes are zero-padded

It also checks validity of EAN-13 barcodes and returns error.

Conflicts:

C4/Circulation.pm
installer/data/mysql/en/mandatory/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
kohaversion.pl
t/Circulation_barcodedecode.t

C4/Circulation.pm
installer/data/mysql/en/mandatory/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
kohaversion.pl
t/Circulation_barcodedecode.t

index 2869fc6..dd21c8e 100644 (file)
@@ -46,6 +46,7 @@ use Date::Calc qw(
 use POSIX qw(strftime);
 use C4::Branch; # GetBranches
 use C4::Log; # logaction
+use Algorithm::CheckDigits;
 
 use Data::Dumper;
 
@@ -156,6 +157,15 @@ sub barcodedecode {
         # FIXME: $barcode could be "T1", causing warning: substr outside of string
         # Why drop the nonzero digit after the T?
         # Why pass non-digits (or empty string) to "T%07d"?
+       } elsif ($filter eq 'EAN13') {
+               my $ean = CheckDigits('ean');
+               if ( $ean->is_valid($barcode) ) {
+                       if ( length($barcode) == 12 ) {
+                               # upgrade UPC-A to EAN-13
+                               $barcode = '0' . $barcode;
+                       }
+               }
+               return "$barcode - not valid EAN-13/UPC-A"; # XXX comment-out to disable
        }
     return $barcode;    # return barcode, modified or not
 }
index 0aebcb5..a0111a1 100644 (file)
@@ -146,7 +146,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
 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('globalDueDate','','If set, allows a global static due date for all checkouts','10','free');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ceilingDueDate','','If set, date due will not be past this date.  Enter date according to the dateformat System Preference',NULL,'free');
-INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','whitespace|T-prefix|cuecat','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|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');
index 7ade75a..c80b59a 100755 (executable)
@@ -4102,6 +4102,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.02.10.001"; # FIXME
+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";
+    setversion($dbversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 DropAllForeignKeys($table)
index b948495..4daa2ef 100644 (file)
@@ -14,6 +14,7 @@ Circulation:
                   whitespace: Remove spaces from
                   cuecat: Convert from CueCat form
                   T-prefix: Remove the first number from T-prefix style
+                  EAN13: upgrade 12-digit UPC-A to EAN13 and check validity
             - scanned patron barcodes.
         -
             - Sort previous checkouts on the circulation page from
index 93fa419..526e43a 100644 (file)
@@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts :
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.02.10.000';
+    our $VERSION = '3.02.10.001';
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install
index 5f2edc2..df007a2 100644 (file)
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16;
+use Test::More tests => 18;
 
 BEGIN {
     use_ok('C4::Circulation');
@@ -15,12 +15,14 @@ our %inputs = (
                     'q.C3nZC3nZC3nWDNzYDxf2CNnY.fHmc.C3DWC3nZCNjXD3nW.', '.C3nZC3nZC3nWCxjWE3D1C3nX.cGf2.ENr7C3v7D3T3ENj3C3zYDNnZ.' ],
     whitespace => [" 26002315", "26002315 ", "\n\t26002315\n"],
     'T-prefix' => [qw(T0031472 T32)],
+    EAN13      => [qw(892685001928 000000695152)],
     other      => [qw(26002315 T0031472 T32 Alphanum123), "Alpha Num 345"],
 );
 our %outputs = (
     cuecat     => ["26002315", "046675000808", "046675000808", "043000112403", "978068484914051500"],
     whitespace => [qw(26002315 26002315 26002315)],
     'T-prefix' => [qw(T0031472 T0000002         )],
+    EAN13      => [qw(0892685001928 0000000695152)],
     other      => [qw(26002315 T0031472 T32 Alphanum123), "Alpha Num 345"],
 );