__PACKAGE__->register_method(
- method => 'users_owing_money',
- api_name => 'open-ils.collections.users_owing_money.retrieve',
- api_level => 1,
- argc => 5,
- stream => 1,
- signature => {
- desc => q/
- Returns an array of users that owe money during
- the given time frame at the location (or child locations)
- provided/,
-
- params => [
- { name => 'auth',
- desc => 'The authentication token',
- type => 'string' },
-
- { name => 'start_date',
- desc => 'The start of the time interval to check',
- type => q/string (ISO 8601 timestamp. E.g. 2006-06-24, 1994-11-05T08:15:30-05:00 /,
- },
-
- { name => 'end_date',
- desc => q/Then end date of the time interval to check/,
- type => q/string (ISO 8601 timestamp. E.g. 2006-06-24, 1994-11-05T08:15:30-05:00 /,
- },
- { name => 'fine_level',
- desc => q/The fine threshold at which users will be included in the search results /,
- type => q/number/,
- },
- { name => 'locations',
- desc => q/ A list of one or more org-unit short names.
- If a selected location has 'child' locations (e.g. a library region), the
- child locations will be included in the search/,
- type => q'string',
- },
- ],
- 'return' => {
- desc => q/An array of user information objects/,
- type => 'array',
- }
- }
-);
-
-
-sub users_owing_money {
- my( $self, $conn, $auth, $start_date, $end_date, $fine_level, @locations ) = @_;
-
- return OpenILS::Event->new('BAD_PARAMS')
- unless ($auth and $start_date and $end_date and @locations);
-
- my $e = new_editor(authtoken => $auth);
- return $e->event unless $e->checkauth;
-
- # they need global perms to view users so no org is provided
- return $e->event unless $e->allowed('VIEW_USER');
-
- my $data = [];
-
- my $ses = OpenSRF::AppSession->create('open-ils.storage');
-
- my $start = time;
- my $req = $ses->request(
- 'open-ils.storage.money.collections.users_owing_money',
- $start_date, $end_date, $fine_level, @locations);
-
- # let the client know we're still here
- $conn->status( new OpenSRF::DomainObject::oilsContinueStatus );
-
- return process_users_of_interest_results(
- $self, $conn, $e, $req, $start, $start_date, $end_date, $fine_level, @locations);
-}
-
-
-
-__PACKAGE__->register_method(
method => 'users_with_activity',
api_name => 'open-ils.collections.users_with_activity.retrieve',
api_level => 1,
my $circ = action::circulation->table;
my $mg = money::grocery->table;
my $res = booking::reservation->table;
- my $descendants = "actor.org_unit_descendants((select id from actor.org_unit where shortname = ?))";
my $SQL = <<" SQL";
argc => 3,
);
-sub users_owing_money {
- my $self = shift;
- my $client = shift;
- my $start = shift;
- my $end = shift;
- my $amount = shift;
- my @loc = @_;
-
- my $mct = money::collections_tracker->table;
- my $mb = money::billing->table;
- my $circ = action::circulation->table;
- my $mg = money::grocery->table;
- my $descendants = "actor.org_unit_descendants((select id from actor.org_unit where shortname = ?))";
-
- my $SQL = <<" SQL";
-
-select
- usr,
- SUM(total_billing) - SUM(COALESCE(p.amount,0)) as threshold_amount
- from (select
- x.id,
- x.usr,
- SUM(b.amount) AS total_billing
- from action.circulation x
- join money.billing b on (b.xact = x.id)
- where x.xact_finish is null
- and x.circ_lib in (XX)
- and b.billing_ts between ? and ?
- and not b.voided
- group by 1,2
-
- union all
-
- select
- x.id,
- x.usr,
- SUM(b.amount) AS total_billing
- from money.grocery x
- join money.billing b on (b.xact = x.id)
- where x.xact_finish is null
- and x.billing_location in (XX)
- and b.billing_ts between ? and ?
- and not b.voided
- group by 1,2
-
- union all
-
- select
- x.id,
- x.usr,
- SUM(b.amount) AS total_billing
- from booking.reservation x
- join money.billing b on (b.xact = x.id)
- where x.xact_finish is null
- and x.pickup_lib in (XX)
- and b.billing_ts between ? and ?
- and not b.voided
- group by 1,2
- ) full_list
- left join money.payment p on (full_list.id = p.xact)
- group by 1
- having SUM(total_billing) - SUM(COALESCE(p.amount,0)) > ?
-;
- SQL
-
- my @l_ids;
- for my $l (@loc) {
- my ($org) = actor::org_unit->search( shortname => uc($l) );
- next unless $org;
-
- my $o_list = actor::org_unit->db_Main->selectcol_arrayref( "SELECT id FROM actor.org_unit_descendants(?);", {}, $org->id );
- next unless (@$o_list);
-
- my $o_txt = join ',' => @$o_list;
-
- (my $real_sql = $SQL) =~ s/XX/$o_txt/gsm;
-
- my $sth = money::collections_tracker->db_Main->prepare($real_sql);
- $sth->execute( $start, $end, $start, $end, $amount );
-
- while (my $row = $sth->fetchrow_hashref) {
- #$row->{usr} = actor::user->retrieve($row->{usr})->to_fieldmapper;
- $client->respond( $row );
- }
- }
- return undef;
-}
-__PACKAGE__->register_method(
- method => 'users_owing_money',
- api_name => 'open-ils.storage.money.collections.users_owing_money',
- stream => 1,
- argc => 4,
-);
-
sub active_in_collections {
my $self = shift;
my $client = shift;