1 package OpenILS::Application::Storage::Publisher::money;
2 use base qw/OpenILS::Application::Storage/;
3 use OpenSRF::Utils::Logger qw/:level/;
5 my $log = 'OpenSRF::Utils::Logger';
14 my $mct = money::collections_tracker->table;
15 my $mb = money::billing->table;
16 my $circ = action::circulation->table;
17 my $mg = money::grocery->table;
18 my $descendants = "actor.org_unit_descendants((select id from actor.org_unit where shortname = ?))";
22 MAX(bl.billing_ts) AS last_pertinent_billing,
23 SUM(bl.amount) - COALESCE(SUM((SELECT SUM(amount) FROM money.payment WHERE xact = lt.id)),0) AS threshold_amount
24 FROM ( SELECT id,usr,billing_location AS location FROM money.grocery
26 SELECT id,usr,circ_lib AS location FROM action.circulation ) AS lt
27 JOIN $descendants d ON (lt.location = d.id)
28 JOIN money.billing bl ON (lt.id = bl.xact AND bl.voided IS FALSE)
29 WHERE AGE(bl.billing_ts) > ?
33 FROM money.collections_tracker
40 AND (SUM(bl.amount) - COALESCE(SUM((SELECT SUM(amount) FROM money.payment WHERE xact = lt.id)),0)) > ?
45 my $sth = money::collections_tracker->db_Main->prepare($SQL);
46 $sth->execute(uc($l), $age, uc($l), $amount );
47 while (my $row = $sth->fetchrow_hashref) {
48 #$row->{usr} = actor::user->retrieve($row->{usr})->to_fieldmapper;
49 $client->respond( $row );
54 __PACKAGE__->register_method(
55 method => 'new_collections',
56 api_name => 'open-ils.storage.money.collections.users_of_interest',
61 sub active_in_collections {
64 my $startdate = shift;
68 my $mct = money::collections_tracker->table;
69 my $mb = money::billing->table;
70 my $circ = action::circulation->table;
71 my $mg = money::grocery->table;
72 my $descendants = "actor.org_unit_descendants((select id from actor.org_unit where shortname = ?))";
76 MAX(bl.billing_ts) AS last_pertinent_billing,
77 MAX(pm.payment_ts) AS last_pertinent_payment
78 FROM ( SELECT id,usr,billing_location AS location FROM money.grocery
80 SELECT id,usr,circ_lib AS location FROM action.circulation ) AS lt
81 JOIN $descendants d ON (lt.location = d.id)
82 JOIN money.collections_tracker cl ON (lt.usr = cl.usr)
83 LEFT JOIN money.billing bl ON (lt.id = bl.xact)
84 LEFT JOIN money.payment pm ON (lt.id = pm.xact)
85 WHERE cl.location IN ((SELECT id FROM $descendants))
86 AND ( bl.billing_ts between ? and ?
87 OR pm.payment_ts between ? and ? )
93 my $sth = money::collections_tracker->db_Main->prepare($SQL);
94 $sth->execute(uc($l), uc($l), $startdate, $enddate, $startdate, $enddate );
95 while (my $row = $sth->fetchrow_hashref) {
96 $row->{usr} = actor::user->retrieve($row->{usr})->to_fieldmapper;
97 $client->respond( $row );
102 __PACKAGE__->register_method(
103 method => 'active_in_collections',
104 api_name => 'open-ils.storage.money.collections.users_with_activity',