From: pines Date: Thu, 14 Sep 2006 15:42:53 +0000 (+0000) Subject: more direct methods for counting stuff X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0697a04810954ba1a1bbf1efa63825024e28a398;p=Evergreen.git more direct methods for counting stuff git-svn-id: svn://svn.open-ils.org/ILS/trunk@6096 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm index 77d8122254..6c4f24a822 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm @@ -22,6 +22,51 @@ __PACKAGE__->register_method( method => 'new_usergroup_id', ); +sub usr_total_owed { + my $self = shift; + my $client = shift; + my $usr = shift; + + my $sql = <<" SQL"; + SELECT x.usr, + SUM(COALESCE((SELECT SUM(b.amount) FROM money.billing b WHERE b.voided IS FALSE AND b.xact = x.id),0.0)) - + SUM(COALESCE((SELECT SUM(p.amount) FROM money.payment p WHERE p.voided IS FALSE AND p.xact = x.id),0.0)) + FROM money.billable_xact x + WHERE x.usr = ? + GROUP BY 1 + SQL + + my (undef,$val) = actor::user->db_Main->selectrow_array($sql, {}, $usr); + + return $val; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.actor.user.total_owed', + api_level => 1, + method => 'usr_total_owed', +); + +sub usr_total_out { + my $self = shift; + my $client = shift; + my $usr = shift; + + my $sql = <<" SQL"; + SELECT count(*) + FROM action.circulation + WHERE usr = ? AND checkin_time IS NULL + SQL + + my ($val) = actor::user->db_Main->selectrow_array($sql, {}, $usr); + + return $val; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.actor.user.total_out', + api_level => 1, + method => 'usr_total_out', +); + sub calc_proximity { my $self = shift; my $client = shift;