From d67e4f591025359aaa7bcda92b059da606d3f3cc Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 30 Jun 2006 17:59:49 +0000 Subject: [PATCH] updated, refactored some, added grocery retrievals git-svn-id: svn://svn.open-ils.org/ILS/trunk@4867 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Collections.pm | 116 ++++++++++++++------- 1 file changed, 77 insertions(+), 39 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Collections.pm b/Open-ILS/src/perlmods/OpenILS/Application/Collections.pm index 96bf5a537b..87272f0abb 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Collections.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Collections.pm @@ -244,8 +244,8 @@ sub transaction_details { # -------------------------------------------------------------- # Collect all open circs for the user -# For each circ, see if any billing were created or payments -# were made during the given time period +# For each circ, see if any billings or payments were created +# during the given time period. # -------------------------------------------------------------- sub fetch_circ_xacts { my $e = shift; @@ -254,8 +254,6 @@ sub fetch_circ_xacts { my $start_date = shift; my $end_date = shift; - my @data; - # first get all open circs for this user my $circs = $e->search_action_circulation( { @@ -266,12 +264,82 @@ sub fetch_circ_xacts { {idlist => 1} ); - for my $cid (@$circs) { + my @data; + my $active_ids = fetch_active($e, $circs, $start_date, $end_date); + + for my $cid (@$active_ids) { + push( @data, + $e->retrieve_action_circulation( + [ + $cid, + { + flesh => 1, + flesh_fields => { + circ => [ "billings", "payments" ] + } + } + ] + ) + ); + } + + return \@data; +} + + +sub fetch_grocery_xacts { + my $e = shift; + my $uid = shift; + my $orgid = shift; + my $start_date = shift; + my $end_date = shift; + + my $xacts = $e->search_money_grocery( + { + usr => $uid, + circ_lib => $orgid, + xact_finish => undef, + }, + {idlist => 1} + ); + + my @data; + my $active_ids = fetch_active($e, $xacts, $start_date, $end_date); + + for my $id (@$active_ids) { + push( @data, + $e->retrieve_money_grocery( + [ + $id, + { + flesh => 1, + flesh_fields => { + mg => [ "billings", "payments" ] } + } + ] + ) + ); + } + + return \@data; +} + + + +# -------------------------------------------------------------- +# Given a list of xact id's, this returns a list of id's that +# had any activity within the given time span +# -------------------------------------------------------------- +sub fetch_active { + my( $e, $ids, $start_date, $end_date ) = @_; + + my @active; + for my $id (@$ids) { # see if any billings were created in the given time range my $bills = $e->search_money_billing ( { - xact => $cid, + xact => $id, billing_ts => { ">=" => $start_date }, billing_ts => { "<=" => $end_date }, }, @@ -285,7 +353,7 @@ sub fetch_circ_xacts { # see if any payments were created in the given range $payments = $e->search_money_payment ( { - xact => $cid, + xact => $id, payment_ts => { ">=" => $start_date }, payment_ts => { "<=" => $end_date }, }, @@ -294,40 +362,10 @@ sub fetch_circ_xacts { } - if( @$bills or @$payments ) { - - # if any payments or bills were created in the given range, - # flesh the circ and add it to the set - push( @data, - $e->retrieve_action_circulation( - [ - $cid, - { - flesh => 1, - flesh_fields => { - circ => [ "billings", "payments", "circ_lib" ] - } - } - ] - ) - ); - } + push( @active, $id ) if @$bills or @$payments; } - return \@data; + return \@active; } - -sub fetch_grocery_xacts { - my $e = shift; - my $uid = shift; - my $orgid = shift; - my $start_date = shift; - my $end_date = shift; - - return []; -} - - - 1; -- 2.11.0