adding mbts builder to storage
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 11 Sep 2006 23:44:15 +0000 (23:44 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 11 Sep 2006 23:44:15 +0000 (23:44 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6067 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 2dbcef8..97c6686 100644 (file)
@@ -572,8 +572,8 @@ sub modify_from_fieldmapper {
        actor::org_unit->has_many( checkins => 'action::circulation' => 'checkin_lib' );
 
        money::billable_transaction->has_a( usr => 'actor::user' );
-       #money::billable_transaction->might_have( circulation => 'action::circulation' );
-       #money::billable_transaction->might_have( grocery => 'money::grocery' );
+       money::billable_transaction->might_have( circulation => 'action::circulation' );
+       money::billable_transaction->might_have( grocery => 'money::grocery' );
        actor::user->has_many( billable_transactions => 'action::circulation' => 'usr' );
        
        
index d85d735..c2818b4 100644 (file)
@@ -4,6 +4,77 @@ use OpenSRF::Utils::Logger qw/:level/;
 
 my $log = 'OpenSRF::Utils::Logger';
 
+sub _make_mbts {
+        my @xacts = @_;
+
+        my @mbts;
+        for my $x (@xacts) {
+                my $s = new Fieldmapper::money::billable_transaction_summary;
+                $s->id( $x->id );
+                $s->usr( $x->usr );
+                $s->xact_start( $x->xact_start );
+                $s->xact_finish( $x->xact_finish );
+
+                my $to = 0;
+                my $lb = undef;
+                for my $b ($x->billings) {
+                        next if ($U->is_true($b->voided));
+                        $to += int($b->amount * 100);
+                        $lb ||= $b->billing_ts;
+                        if ($b->billing_ts ge $lb) {
+                                $lb = $b->billing_ts;
+                                $s->last_billing_note($b->note);
+                                $s->last_billing_ts($b->billing_ts);
+                                $s->last_billing_type($b->billing_type);
+                        }
+                }
+
+                $s->total_owed( sprintf('%0.2f', $to / 100 ) );
+
+                my $tp = 0;
+                my $lp = undef;
+                for my $p ($x->payments) {
+                        next if ($U->is_true($p->voided));
+                        $tp += int($p->amount * 100);
+                        $lp ||= $p->payment_ts;
+                        if ($p->payment_ts ge $lp) {
+                                $lp = $p->payment_ts;
+                                $s->last_payment_note($p->note);
+                                $s->last_payment_ts($p->payment_ts);
+                                $s->last_payment_type($p->payment_type);
+                        }
+                }
+                $s->total_paid( sprintf('%0.2f', $tp / 100 ) );
+
+                $s->balance_owed( sprintf('%0.2f', int($to - $tp) / 100) );
+
+                $s->xact_type( 'grocery' ) if ($x->grocery);
+                $s->xact_type( 'circulation' ) if ($x->circulation);
+
+                push @mbts, $s;
+        }
+
+        return @mbts;
+}
+
+sub search_mbts {
+       my $self = shift;
+       my $client = shift;
+       my $search = shift;
+
+       my @xacts = money::billable_xact->search_where( $search );
+       $client->respond( $_ ) for (_make_mbts(@xacts));
+
+       return undef;
+}
+__PACKAGE__->register_method(
+       method          => 'search_mbts',
+       api_name        => 'open-ils.storage.money.billable_transaction.summary.search',
+       stream          => 1,
+       argc            => 1,
+);
+
+
 sub new_collections {
        my $self = shift;
        my $client = shift;