more direct methods for counting stuff
authorpines <pines@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 14 Sep 2006 15:42:53 +0000 (15:42 +0000)
committerpines <pines@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 14 Sep 2006 15:42:53 +0000 (15:42 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6096 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm

index 77d8122..6c4f24a 100644 (file)
@@ -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;