use strict; use warnings;
use base qw/OpenSRF::Application/;
use OpenSRF::Utils::Cache;
-use OpenSRF::EX qw(:try);
-use OpenILS::Perm;
-use OpenSRF::Utils::Logger;
+use OpenSRF::Utils::Logger qw/$logger/;
use OpenILS::Utils::ModsParser;
+use OpenSRF::EX qw(:try);
use OpenILS::Event;
use Data::Dumper;
-my $logger = "OpenSRF::Utils::Logger";
+use OpenILS::Utils::CStoreEditor;
my $cache_client = "OpenSRF::Utils::Cache";
}
# checks the list of user perms. The first one that fails returns a new
-# OpenILS::Perm object of that type. Returns undef if all perms are allowed
sub check_perms {
my( $self, $user_id, $org_id, @perm_types ) = @_;
my $t = $self->check_user_perms( $user_id, $org_id, @perm_types );
+my $ORG_TREE;
+sub fetch_org_tree {
+ my $self = shift;
+ return $ORG_TREE if $ORG_TREE;
+ return $ORG_TREE = OpenILS::Utils::CStoreEditor->new->search_actor_org_unit(
+ [
+ {"parent_ou" => undef },
+ {
+ flesh => 2,
+ flesh_fields => { aou => ['children'] },
+ order_by => { aou => 'name'}
+ }
+ ]
+ )->[0];
+}
+
+sub walk_org_tree {
+ my( $self, $node, $callback ) = @_;
+ return unless $node;
+ $callback->($node);
+ if( $node->children ) {
+ $self->walk_org_tree($_, $callback) for @{$node->children};
+ }
+}
+
+
+
1;
use OpenSRF::Utils::Logger qw(:logger);
use OpenSRF::Application;
use base 'OpenSRF::Application';
-my $U = "OpenILS::Application::AppUtils";
use OpenILS::Utils::CStoreEditor qw/:funcs/;
use OpenILS::Utils::Fieldmapper;
use OpenILS::Event;
+my $U = "OpenILS::Application::AppUtils";
# --------------------------------------------------------------
sub initialize { return 1; }
+
__PACKAGE__->register_method(
method => 'users_of_interest',
api_name => 'open-ils.collections.users_of_interest.retrieve',
my $org = $e->search_actor_org_unit({shortname => $location})
or return $e->event; $org = $org->[0];
+ # get a reference to the org inside of the tree
+ $org = $U->find_org($U->fetch_org_tree(), $org->id);
+
my @data;
for my $uid (@$user_list) {
my $blob = {};
$blob->{transactions} = {
circulations =>
- fetch_circ_xacts($e, $uid, $org->id, $start_date, $end_date),
+ fetch_circ_xacts($e, $uid, $org, $start_date, $end_date),
grocery =>
- fetch_grocery_xacts($e, $uid, $org->id, $start_date, $end_date)
+ fetch_grocery_xacts($e, $uid, $org, $start_date, $end_date)
};
push( @data, $blob );
sub fetch_circ_xacts {
my $e = shift;
my $uid = shift;
- my $orgid = shift;
+ my $org = shift;
my $start_date = shift;
my $end_date = shift;
- # first get all open circs for this user
- my $circs = $e->search_action_circulation(
- {
- usr => $uid,
- circ_lib => $orgid,
- xact_finish => undef,
- },
- {idlist => 1}
+ my @circs;
+
+ # at the specified org and each descendent org,
+ # fetch the open circs for this user
+ $U->walk_org_tree( $org,
+ sub {
+ my $n = shift;
+ $logger->debug("collect: searching for open circs at " . $n->shortname);
+ push( @circs,
+ @{
+ $e->search_action_circulation(
+ {
+ usr => $uid,
+ circ_lib => $n->id,
+ xact_finish => undef,
+ },
+ {idlist => 1}
+ )
+ }
+ );
+ }
);
+
my @data;
- my $active_ids = fetch_active($e, $circs, $start_date, $end_date);
+ my $active_ids = fetch_active($e, \@circs, $start_date, $end_date);
for my $cid (@$active_ids) {
push( @data,
sub fetch_grocery_xacts {
my $e = shift;
my $uid = shift;
- my $orgid = shift;
+ my $org = 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 @xacts;
+ $U->walk_org_tree( $org,
+ sub {
+ my $n = shift;
+ $logger->debug("collect: searching for open grocery xacts at " . $n->shortname);
+ push( @xacts,
+ @{
+ $e->search_money_grocery(
+ {
+ usr => $uid,
+ billing_location => $n->id,
+ xact_finish => undef,
+ },
+ {idlist => 1}
+ )
+ }
+ );
+ }
);
my @data;
- my $active_ids = fetch_active($e, $xacts, $start_date, $end_date);
+ my $active_ids = fetch_active($e, \@xacts, $start_date, $end_date);
for my $id (@$active_ids) {
push( @data,
sub fetch_active {
my( $e, $ids, $start_date, $end_date ) = @_;
+ # use this..
+ # { payment_ts => { between => [ $start, $end ] } } ' ;)
+
my @active;
for my $id (@$ids) {
my $bills = $e->search_money_billing (
{
xact => $id,
- billing_ts => { ">=" => $start_date },
- billing_ts => { "<=" => $end_date },
+ billing_ts => { between => [ $start_date, $end_date ] },
},
{idlist =>1}
);
$payments = $e->search_money_payment (
{
xact => $id,
- payment_ts => { ">=" => $start_date },
- payment_ts => { "<=" => $end_date },
+ payment_ts => { between => [ $start_date, $end_date ] },
},
{idlist =>1}
);