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

svn at svn.open-ils.org svn at svn.open-ils.org
Mon May 3 10:39:30 EDT 2010


Author: phasefx
Date: 2010-05-03 10:39:28 -0400 (Mon, 03 May 2010)
New Revision: 16375

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
Paging options for user_transactions and user_transactions_history, plus refactored post-query grep filters into the query itself

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2010-05-03 14:02:50 UTC (rev 16374)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2010-05-03 14:39:28 UTC (rev 16375)
@@ -1525,6 +1525,7 @@
     { desc => 'Authentication token', type => 'string' },
     { desc => 'User ID',              type => 'string' },
     { desc => 'Transactions type (optional, defaults to all)', type => 'string' },
+    { desc => 'Options hash.  May contain limit and offset for paged results.', type => 'object' },
 ];
 my %methods = (
     'open-ils.actor.user.transactions'                      => '',
@@ -1592,7 +1593,8 @@
 
 
 sub user_transactions {
-	my( $self, $client, $login_session, $user_id, $type ) = @_;
+	my( $self, $client, $login_session, $user_id, $type, $options ) = @_;
+    $options ||= {};
 
 	my( $user_obj, $target, $evt ) = $apputils->checkses_requestor(
 		$login_session, $user_id, 'VIEW_USER_TRANSACTIONS' );
@@ -1600,14 +1602,14 @@
 
     my $api = $self->api_name();
 
+    my $filter = ($api =~ /have_balance/o) ?
+        { 'balance_owed' => { '<>' => 0 } }:
+        { 'total_owed' => { '>' => 0 } };
+
     my ($trans) = $self->method_lookup(
         'open-ils.actor.user.transactions.history.still_open')
-      ->run( $login_session, $user_id, $type );
+      ->run( $login_session, $user_id, $type, $filter, $options );
 
-    $trans = ($api =~ /have_balance/o) ?
-            [ grep { int($_->balance_owed * 100) != 0 } @$trans ] : 
-            [ grep { int($_->total_owed   * 100)  > 0 } @$trans ] ;
-
 	if($api =~ /total/o) { 
 		my $total = 0.0;
 		for my $t (@$trans) {
@@ -2104,8 +2106,9 @@
 
 
 sub user_transaction_history {
-	my( $self, $conn, $auth, $userid, $type, $filter ) = @_;
+	my( $self, $conn, $auth, $userid, $type, $filter, $options ) = @_;
     $filter ||= {};
+    $options ||= {};
 
 	# run inside of a transaction to prevent replication delays
 	my $e = new_editor(authtoken=>$auth);
@@ -2119,41 +2122,46 @@
 	my $api = $self->api_name;
 	my @xact_finish  = (xact_finish => undef ) if ($api =~ /history.still_open$/);
 
-    my $mbts = $e->search_money_billable_transaction_summary(
-        [ 
-            { usr => $userid, @xact_finish, %$filter },
-            { order_by => { mbt => 'xact_start DESC' } }
-        ]
-    );
-
 	if(defined($type)) {
-		@$mbts = grep { $_->xact_type eq $type } @$mbts;
+		$filter->{'xact_type'} = $type;
 	}
 
 	if($api =~ /have_bill_or_payment/o) {
 
         # transactions that have a non-zero sum across all billings or at least 1 payment
-		@$mbts = grep { 
-            int($_->balance_owed * 100) != 0 ||
-            defined($_->last_payment_ts) } @$mbts;
+        $filter->{'-or'} = {
+            'balance_owed' => { '<>' => 0 },
+            'last_payment_ts' => { '<>' => undef }
+        };
 
     } elsif( $api =~ /have_balance/o) {
 
         # transactions that have a non-zero overall balance
-		@$mbts = grep { int($_->balance_owed * 100) != 0 } @$mbts;
+        $filter->{'balance_owed'} = { '<>' => 0 };
 
 	} elsif( $api =~ /have_charge/o) {
 
         # transactions that have at least 1 billing, regardless of whether it was voided
-		@$mbts = grep { defined($_->last_billing_ts) } @$mbts;
+        $filter->{'last_billing_ts'} = { '<>' => undef };
 
 	} elsif( $api =~ /have_bill/o) {
 
         # transactions that have non-zero sum across all billings.  This will exclude
         # xacts where all billings have been voided
-		@$mbts = grep { int($_->total_owed * 100) != 0 } @$mbts;
+        $filter->{'total_owed'} = { '<>' => 0 };
 	}
 
+    my $options_clause = { order_by => { mbt => 'xact_start DESC' } };
+    $options_clause->{'limit'} = $options->{'limit'} if $options->{'limit'}; 
+    $options_clause->{'offset'} = $options->{'offset'} if $options->{'offset'}; 
+
+    my $mbts = $e->search_money_billable_transaction_summary(
+        [ 
+            { usr => $userid, @xact_finish, %$filter },
+            $options_clause
+        ]
+    );
+
     if ($api =~ /\.ids/) {
     	return [map {$_->id} @$mbts];
     } else {



More information about the open-ils-commits mailing list