[open-ils-commits] r15232 - trunk/Open-ILS/src/perlmods/OpenILS/Application (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Dec 23 13:26:27 EST 2009


Author: erickson
Date: 2009-12-23 13:26:24 -0500 (Wed, 23 Dec 2009)
New Revision: 15232

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
added api call that returns the set of users with an overall negative balance, including balance owed and last billing activity time, optionally sorted by home org

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2009-12-23 17:04:57 UTC (rev 15231)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2009-12-23 18:26:24 UTC (rev 15232)
@@ -34,6 +34,7 @@
 
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Utils::Penalty;
+use List::Util qw/max/;
 
 sub initialize {
 	OpenILS::Application::Actor::Container->initialize();
@@ -3676,6 +3677,66 @@
 
 
 
+__PACKAGE__->register_method (
+	method		=> 'negative_balance_users',
+	api_name    => 'open-ils.actor.users.negative_balance',
+    stream => 1,
+    signature   => q/
+        Returns all users that have an overall negative balance
+        @param auth Authentication token
+        @param org_id The context org unit as an ID or list of IDs.  This will be the home 
+        library of the user.  If no org_unit is specified, no org unit filter is applied
+    /
+);
 
+sub negative_balance_users {
+    my($self, $conn, $auth, $org_id) = @_;
+
+    my $e = new_editor(authtoken => $auth);
+    return $e->die_event unless $e->checkauth;
+    return $e->die_event unless $e->allowed('VIEW_USER', $org_id);
+
+    my $query = {
+        select => { 
+            mous => ['usr', 'balance_owed'], 
+            au => ['home_ou'], 
+            mbts => [
+                {column => 'last_billing_ts', transform => 'max', aggregate => 1},
+                {column => 'last_payment_ts', transform => 'max', aggregate => 1},
+            ]
+        }, 
+        from => { 
+            mous => { 
+                au => { 
+                    fkey => 'usr', 
+                    field => 'id', 
+                    join => { 
+                        mbts => { 
+                            key => 'id', 
+                            field => 'usr' 
+                        } 
+                    } 
+                } 
+            } 
+        }, 
+        where => {'+mous' => {balance_owed => {'<' => 0}}} 
+    };
+
+    $query->{from}->{mous}->{au}->{filter}->{home_ou} = $org_id if $org_id;
+
+    my $list = $e->json_query($query, {timeout => 600});
+
+    for my $data (@$list) {
+        $conn->respond({
+            usr => $e->retrieve_actor_user([$data->{usr}, {flesh => 1, flesh_fields => {au => ['card']}}]),
+            balance_owed => $data->{balance_owed},
+            last_billing_activity => max($data->{last_billing_ts}, $data->{last_payment_ts})
+        });
+    }
+
+    return undef;
+}
+
+
 1;
 



More information about the open-ils-commits mailing list