From 238ee8bd7bb8795d026cded675726c041841355f Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 11 Sep 2006 23:44:15 +0000 Subject: [PATCH] adding mbts builder to storage git-svn-id: svn://svn.open-ils.org/ILS/trunk@6067 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/CDBI.pm | 4 +- .../Application/Storage/Publisher/money.pm | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm index 2dbcef8375..97c66860e8 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm @@ -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' ); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/money.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/money.pm index d85d735982..c2818b4faa 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/money.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/money.pm @@ -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; -- 2.43.2