# --------------------------------------------------------------
# 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;
my $start_date = shift;
my $end_date = shift;
- my @data;
-
# first get all open circs for this user
my $circs = $e->search_action_circulation(
{
{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 },
},
# 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 },
},
}
- 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;