From 3f7bdbfa6ab6958374e465e3f51e5fb4ca261f0c Mon Sep 17 00:00:00 2001 From: phasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4> Date: Tue, 9 Mar 2010 17:05:16 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@15765 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Cat.pm | 52 ++++++++++++++++++++++ Open-ILS/web/opac/locale/en-US/lang.dtd | 2 + .../staff_client/chrome/content/main/constants.js | 1 + .../staff_client/server/cat/volume_copy_creator.js | 25 +++++++++++ .../server/cat/volume_copy_creator.xul | 1 + 5 files changed, 81 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm index f05c7abb97..7aa2d54d1b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm @@ -337,6 +337,58 @@ sub biblio_record_marc_cn { 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", diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index d8b13bc918..25312867a5 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -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"> diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index 33f4a81411..6ccd32c267 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -45,6 +45,7 @@ const api = { '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 }, diff --git a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js index f831bf6194..cefba17004 100644 --- a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js +++ b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js @@ -378,6 +378,31 @@ g.render_barcode_entry = function(node,callnumber,count,ou_id) { } } +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) { diff --git a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul index d6a6e29efd..697055e6bf 100644 --- a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul +++ b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul @@ -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');"/> -- 2.11.0