[open-ils-commits] r15765 - in trunk/Open-ILS: src/perlmods/OpenILS/Application web/opac/locale/en-US xul/staff_client/chrome/content/main xul/staff_client/server/cat (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Mar 9 12:05:20 EST 2010


Author: phasefx
Date: 2010-03-09 12:05:16 -0500 (Tue, 09 Mar 2010)
New Revision: 15765

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
   trunk/Open-ILS/web/opac/locale/en-US/lang.dtd
   trunk/Open-ILS/xul/staff_client/chrome/content/main/constants.js
   trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
   trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul
Log:
Ability to auto-generate barcodes in the Volume/Copy dialog.  Takes the first barcode entered and generates subsequent barcodes using the typical library/codabar checkdigit algorithm if the barcodes are 13-14 digits, otherwise, just incrementing them without checkdigits.

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm	2010-03-09 16:33:30 UTC (rev 15764)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm	2010-03-09 17:05:16 UTC (rev 15765)
@@ -337,7 +337,59 @@
 	return \@res
 }
 
+__PACKAGE__->register_method(
+    method => 'autogen_barcodes',
+    api_name	=> "open-ils.cat.item.barcode.autogen",
+    signature => {
+        desc => 'Returns N generated barcodes following a specified barcode.',
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'Barcode which the sequence should follow from', type => 'string'},
+            {desc => 'Number of barcodes to generate', type => 'number'},
+            {desc => 'Options hash.  Currently you can pass in checkdigit : false to disable the use of checkdigits.'}
+        ],
+        return => {desc => 'Array of generated barcodes'}
+    }
+);
 
+sub autogen_barcodes {
+    my( $self, $client, $auth, $barcode, $num_of_barcodes, $options ) = @_;
+    my $e = new_editor(authtoken => $auth);
+    return $e->event unless $e->checkauth;
+    return $e->event unless $e->allowed('UPDATE_COPY', $e->requestor->ws_ou);
+    $options ||= {};
+
+    my @res;
+    for (my $i = 1; $i <= $num_of_barcodes; $i++) {
+        # default is to use checkdigits, so looking for an explicit false here
+        if (defined $$options{'checkdigit'} && ! $$options{'checkdigit'}) { 
+            push @res, $barcode + $i;
+        } else {
+            if ($barcode !~ /^\d{13,14}$/) {
+                push @res, $barcode + $i;
+            } else {
+                push @res, add_codabar_checkdigit($barcode + $i*10);
+            }
+        }
+    }
+    return \@res
+}
+
+# Codabar doesn't define a checkdigit algorithm, but this one is typically used by libraries.  gmcharlt++
+sub add_codabar_checkdigit {
+    my $barcode = shift;
+
+    return $barcode if $barcode !~ /^\d{13,14}$/;
+    $barcode = substr($barcode, 0, 13); # ignore 14th digit
+    my @digits = split //, $barcode;
+    my $total = 0;
+    $total += $digits[$_] foreach (1, 3, 5, 7, 9, 11);
+    $total += (2 * $digits[$_] >= 10) ? (2 * $digits[$_] - 9) : (2 * $digits[$_]) foreach (0, 2, 4, 6, 8, 10, 12);
+    my $remainder = $total % 10;
+    my $checkdigit = ($remainder == 0) ? $remainder : 10 - $remainder;
+    return $barcode . $checkdigit;
+}
+
 __PACKAGE__->register_method(
 	method	=> "orgs_for_title",
     authoritative => 1,

Modified: trunk/Open-ILS/web/opac/locale/en-US/lang.dtd
===================================================================
--- trunk/Open-ILS/web/opac/locale/en-US/lang.dtd	2010-03-09 16:33:30 UTC (rev 15764)
+++ trunk/Open-ILS/web/opac/locale/en-US/lang.dtd	2010-03-09 17:05:16 UTC (rev 15765)
@@ -2507,6 +2507,8 @@
 <!ENTITY staff.cat.volume_copy_creator.label "Volume and Copy Creator">
 <!ENTITY staff.cat.volume_copy_creator.check_barcodes.label "Check Barcodes?">
 <!ENTITY staff.cat.volume_copy_creator.check_barcodes.accesskey "B">
+<!ENTITY staff.cat.volume_copy_creator.generate_barcodes.label "Auto-Generate Barcodes?">
+<!ENTITY staff.cat.volume_copy_creator.generate_barcodes.accesskey "G">
 <!ENTITY staff.cat.volume_copy_creator.print_labels.label "Print Labels?">
 <!ENTITY staff.cat.volume_copy_creator.print_labels.accesskey "P">
 <!ENTITY staff.cat.volume_copy_creator.library_label.value "Library">

Modified: trunk/Open-ILS/xul/staff_client/chrome/content/main/constants.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/main/constants.js	2010-03-09 16:33:30 UTC (rev 15764)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/main/constants.js	2010-03-09 17:05:16 UTC (rev 15765)
@@ -45,6 +45,7 @@
     'AUTH_DELETE' : { 'app' : 'open-ils.auth', 'method' : 'open-ils.auth.session.delete' },
     'AUTH_WORKSTATION' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.workstation.register' },
     'AUTH_VERIFY_CREDENTIALS' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.verify_user_password' },
+    'AUTOGENERATE_BARCODES' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.item.barcode.autogen' },
     'BILL_PAY' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.payment' },
     'BLOB_AU_PARTS_RETRIEVE' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.retrieve.parts', 'cacheable' : true, 'ttl' : 120000 },
     'BLOB_MARC_CALLNUMBERS_RETRIEVE' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.biblio.record.marc_cn.retrieve', 'secure' : false },

Modified: trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js	2010-03-09 16:33:30 UTC (rev 15764)
+++ trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js	2010-03-09 17:05:16 UTC (rev 15765)
@@ -378,6 +378,31 @@
     }
 }
 
+g.generate_barcodes = function() {
+    try {
+        var nodes = document.getElementsByAttribute('rel_vert_pos','4');
+        if (nodes.length < 1) { return; }
+        var first_barcode = nodes[0].value;
+
+        var barcodes = g.network.simple_request(
+            'AUTOGENERATE_BARCODES',
+            [ ses(), first_barcode, nodes.length - 1 ]
+        );
+
+        if (typeof barcodes.ilsevent != 'undefined') {
+            throw(barcodes);
+        }
+
+        for (var i = 0; i < barcodes.length; i++) {
+            nodes[i+1].value = barcodes[i];
+            nodes[i+1].select();
+        }
+
+    } catch(E) {
+        g.error.sdump('D_ERROR','g.generate_barcodes: ' + E);
+    }
+}
+
 g.new_node_id = -1;
 
 g.stash_and_close = function(param) {

Modified: trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul	2010-03-09 16:33:30 UTC (rev 15764)
+++ trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul	2010-03-09 17:05:16 UTC (rev 15765)
@@ -42,6 +42,7 @@
         <hbox style="border-bottom: solid black thin">
             <hbox id="marc_cn"/>
             <spacer flex="1" />
+            <button id="generate_barcodes" label="&staff.cat.volume_copy_creator.generate_barcodes.label;" oncommand="g.generate_barcodes();" accesskey="&staff.cat.volume_copy_creator.generate_barcodes.accesskey;"/>
             <checkbox id="check_barcodes" label="&staff.cat.volume_copy_creator.check_barcodes.label;" oncommand="g.save_prefs();" accesskey="&staff.cat.volume_copy_creator.check_barcodes.accesskey;"/>
             <checkbox id="print_labels" label="&staff.cat.volume_copy_creator.print_labels.label;"  oncommand="g.save_prefs();" accesskey="&staff.cat.volume_copy_creator.print_labels.accesskey;"/>
             <button id="CreateWithDefaults" disabled="true" oncommand="g.stash_and_close('noedit');"/>



More information about the open-ils-commits mailing list