Add an API for generating barcodes
authorDan Scott <dan@coffeecode.net>
Thu, 8 Sep 2011 21:26:58 +0000 (17:26 -0400)
committerDan Scott <dscott@laurentian.ca>
Thu, 9 Aug 2012 12:31:08 +0000 (08:31 -0400)
Add a custom API to open-ils.actor for generating barcodes; accepts one
argument, user ID, which gets the barcode set to their new value. If no
arg is passed, just generates a new barcode and returns it (should be
useful on the patron editor screen).

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm

index d6de3db..170b129 100644 (file)
@@ -4610,7 +4610,6 @@ sub mark_users_contact_invalid {
     # phone number (or staff manually delete the penalty).
 
     my $contact_type = ($self->api_name =~ /invalidate.(\w+)(\.|$)/)[0];
-
     my $e = new_editor(authtoken => $auth, xact => 1);
     return $e->die_event unless $e->checkauth;
 
@@ -4620,6 +4619,47 @@ sub mark_users_contact_invalid {
     );
 }
 
+__PACKAGE__->register_method(
+    method   => "generate_patron_barcode",
+    api_name => "open-ils.actor.generate_patron_barcode",
+    signature => {
+        desc => "Generates a new patron barcode. If a user ID is supplied," .
+                "that user's card will be updated to point at the new barcode." ,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'User ID', type => 'number'},
+        ],
+        return => {desc => 'Generated barcode on success'}
+    }
+);
+
+# evergreen.lu_update_barcode(user-id) generates a barcode, creates an actor.card
+# object, and points actor.usr.card to the new actor.card.id
+#
+# evergreen.lu_generate_barcode() just generates a barcode
+sub generate_patron_barcode {
+
+    my( $self, $client, $auth, $user_id ) = @_;
+
+    my $e = new_editor( authtoken=>$auth );
+    return $e->die_event unless $e->checkauth;
+
+    my $barcode;
+    if ($user_id) {
+        return $e->die_event unless $e->allowed('UPDATE_USER');
+        $barcode = $e->json_query(
+            {from => ['evergreen.lu_update_barcode', $user_id]})->[0] 
+            or return $e->die_event;
+    } else {
+        $barcode = $e->json_query(
+            {from => ['evergreen.lu_generate_barcode']})->[0] 
+            or return $e->die_event;
+    }
+
+    return $barcode;
+}
+
+
 # Putting the following method in open-ils.actor is a bad fit, except in that
 # it serves an interface that lives under 'actor' in the templates directory,
 # and in that there's nowhere else obvious to put it (open-ils.trigger is