Create a user_payment_detail method in OpenILS::Application::Actor user/mrpeters-isl/actor_user_payment_details
authorMichael Peters <mrpeters@library.in.gov>
Tue, 18 Oct 2011 19:44:19 +0000 (15:44 -0400)
committerMichael Peters <mrpeters@library.in.gov>
Tue, 18 Oct 2011 19:53:17 +0000 (15:53 -0400)
In relation to LP#812382, I've created a new API, open-ils.actor.user.payments.detailed, which allows you to pull in information
regarding the location (workstation name) and accepting user (username) for a particular user's payment history.
This is the beginnings of a customization which allows for additional detail when attempting to audit payment histories via the staff client.

Additional work is still needed to "link up" this API in the staff client, however, this takes care of the backend Perl.

Signed-off-by: Michael Peters <mrpeters@library.in.gov>
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/xul/staff_client/chrome/content/main/constants.js

index ad6fabc..d2adc42 100644 (file)
@@ -3620,6 +3620,74 @@ sub user_payments {
 }
 
 
+__PACKAGE__->register_method (
+       method          => 'user_payment_detail',
+       api_name    => 'open-ils.actor.user.payments.detailed',
+    stream => 1,
+    signature   => q/
+        Returns all payments for a given user.  Default order is newest payments first.
+        @param auth Authentication token
+        @param user_id The user ID
+        @param filters An optional hash of filters, including limit, offset, and order_by definitions
+    /
+);
+
+sub user_payment_detail {
+    my($self, $conn, $auth, $user_id, $filters) = @_;
+    $filters ||= {};
+
+    my $e = new_editor(authtoken => $auth);
+    return $e->die_event unless $e->checkauth;
+
+    my $user = $e->retrieve_actor_user($user_id) or return $e->event;
+    return $e->event unless 
+        $e->requestor->id == $user_id or
+        $e->allowed('VIEW_USER_TRANSACTIONS', $user->home_ou);
+
+    # Find detailed information about all payments for user $user_id
+    my $query = {
+        select => {mdp => ['id']}, 
+        from => 'mdp', 
+        where => {
+            xact => {
+                in => {
+                    select => {mbt => ['id']}, 
+                    from => 'mbt', 
+                    where => {usr => $user_id}
+                }   
+            }
+        },
+        order_by => [{ # by default, order newest payments first
+            class => 'mp', 
+            field => 'payment_ts',
+            direction => 'desc'
+        }]
+    };
+
+       my $payment_ids = $e->json_query($query);
+        for my $pid (@$payment_ids) {
+        my $pay = $e->retrieve_money_desk_payment([
+            $pid->{id},
+            {   flesh => 6,
+                flesh_fields => {
+                   mdp => ['xact'],
+                   mdp => ['accepting_usr']
+                }
+            }
+        ]);
+       
+        my $resp = {
+            mdp => $pay,
+        };
+
+        $pay->accepting_usr($pay->accepting_usr->id); # de-flesh accepting_usr to usrname
+        $conn->respond($resp);
+       }
+
+
+    return undef;
+}
+
 
 __PACKAGE__->register_method (
        method          => 'negative_balance_users',
index 31142e7..a33b3d4 100644 (file)
@@ -278,6 +278,7 @@ var api = {
     'FM_MP_RETRIEVE_VIA_MBTS_ID' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.payment.retrieve.all' },
     'FM_MP_RETRIEVE_VIA_MBTS_ID.authoritative' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.payment.retrieve.all.authoritative' },
     'FM_MP_RETRIEVE_VIA_USER' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.payments.retrieve' },
+    'FM_MDP_RETRIEVE_VIA_USER' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.payments.detailed' },
     'FM_MP_NOTE_EDIT' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.payment.note.edit' },
     'FM_MG_CREATE' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.grocery.create' },
     'FM_MG_RETRIEVE' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.grocery.retrieve' },