From 9bd2eccbbcf44ec5b3233c7cf374b1626a12cca8 Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 6 Sep 2006 04:12:30 +0000 Subject: [PATCH] billing git-svn-id: svn://svn.open-ils.org/ILS/trunk@5971 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 6 +- .../src/perlmods/OpenILS/Application/Actor.pm | 84 +++++++++++++++++-- 2 files changed, 79 insertions(+), 11 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 46bec88995..22b249095f 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -1501,13 +1501,15 @@ + + - - + + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index d1909b43c8..1127c80e4c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -1812,17 +1812,83 @@ sub user_transaction_history { return $e->event unless $e->allowed('VIEW_USER_TRANSACTIONS'); my $api = $self->api_name; - my @xact = (xact_type => $type) if(defined($type)); - my @balance = (balance_owed => { "!=" => 0}) if($api =~ /have_balance/); - my @charge = (last_billing_ts => { "!=" => undef }) if $api =~ /have_charge/; - my @total_billed = (total_owed => { "!=" => 0}) if $api =~ /have_bill/; my @xact_finish = (xact_finish => undef ) if $api =~ /still_open/; - return $e->search_money_billable_transaction_summary( - [ - { usr => $userid, @xact, @charge, @balance, @xact_finish, @total_billed }, - { order_by => 'xact_start DESC' } - ], {idlist => 1}); + my @xacts = @{ $e->search_money_billable_transaction( + [ { usr => $userid, @xact_finish }, + { flesh => 1, + flesh_fields => { mbt => [ qw/billings payments grocery circulation/ ] } + order_by => { mbt => 'xact_start DESC' }, + } + ] + ) }; + + my @mbts; + for my $x (@xacts) { + my $s = new Fieldmapper::money::billable_transaction_summary; + $s->id( $x->id ); + $s->id( $userid ); + $s->xact_start( $x->xact_start ); + $s->xact_finish( $x->xact_finish ); + + my $to = 0.0; + my $lb = undef; + for my $b (@{ $x->billings }) { + next if ($b->voided eq 'f' or !$b->voided); + $to += $b->amount; + $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( $to ); + + my $tp = 0.0; + my $lp = undef; + for my $p (@{ $x->payments }) { + next if ($p->voided eq 'f' or !$p->voided); + $tp += $p->amount; + $lp ||= $p->payment_ts; + if ($b->payment_ts ge $lp) { + $lp = $b->payment_ts; + $s->last_payment_note($b->note); + $s->last_payment_ts($b->payment_ts); + $s->last_payment_type($b->payment_type); + } + } + $s->total_paid( $tp ); + + $s->balance_owed( $s->total_owed - $s->total_paid ); + + $x->xact_type = 'grocery' if ($x->grocery); + $x->xact_type = 'circulation' if ($x->circulation); + + push @mbts, $x; + } + + + + + if(defined($type)) { + @mbts = grep { $_->xact_type eq $type } @mbts; + } + + if($api =~ /have_balance/o) { + @mbts = grep { int($_->balance_owed * 100) > 0 } @mbts; + } + + if($api =~ /have_charge/o) { + @mbts = grep { defined($_->last_billing_ts) } @mbts; + } + + if($api =~ /total_owed/o) { + @mbts = grep { int($_->total_owed * 100) != 0 } @mbts; + } + + return [@mbts]; } -- 2.43.2