zero-pad barcodes to 13 digits
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 3 Jun 2011 22:01:46 +0000 (00:01 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 23 Jun 2011 17:57:27 +0000 (19:57 +0200)
C4/Circulation.pm
cataloguing/value_builder/barcode.pl

index dd21c8e..f2addd8 100644 (file)
@@ -158,14 +158,11 @@ sub barcodedecode {
         # Why drop the nonzero digit after the T?
         # Why pass non-digits (or empty string) to "T%07d"?
        } elsif ($filter eq 'EAN13') {
+               $barcode = sprintf('%013d',$barcode);
                my $ean = CheckDigits('ean');
-               if ( $ean->is_valid($barcode) ) {
-                       if ( length($barcode) == 12 ) {
-                               # upgrade UPC-A to EAN-13
-                               $barcode = '0' . $barcode;
-                       }
+               if ( ! $ean->is_valid($barcode) ) {
+                       warn "[$barcode] not valid EAN-13/UPC-A";
                }
-               return "$barcode - not valid EAN-13/UPC-A"; # XXX comment-out to disable
        }
     return $barcode;    # return barcode, modified or not
 }
index 0b3a342..9b25bc5 100755 (executable)
@@ -136,7 +136,7 @@ sub plugin_javascript {
                my $ean = CheckDigits('ean');
                if ( $ean->is_valid($nextnum) ) {
                        my $next = $ean->basenumber( $nextnum ) + 1;
-                       $nextnum = $ean->complete( $next );
+                       $nextnum = sprintf('%013d',$ean->complete( $next ));
                } else {
                        warn "ERROR: invalid EAN-13 $nextnum, using increment";
                        $nextnum++;