From 18ffeacfe2b6fe0283e100a9218faadeb8b5ccea Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 6 Sep 2006 06:21:25 +0000 Subject: [PATCH 1/1] more billing git-svn-id: svn://svn.open-ils.org/ILS/trunk@5982 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Actor.pm | 40 ++++++------ .../OpenILS/Application/Circ/Money.pm | 62 ++++++++++++++++++- 2 files changed, 82 insertions(+), 20 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 7a002ed8ef..4bb03cc2ac 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -1805,24 +1805,8 @@ sub _user_transaction_history { } =cut - -sub user_transaction_history { - my( $self, $conn, $auth, $userid, $type ) = @_; - my $e = new_editor(authtoken=>$auth); - return $e->event unless $e->checkauth; - return $e->event unless $e->allowed('VIEW_USER_TRANSACTIONS'); - - my $api = $self->api_name; - my @xact_finish = (xact_finish => undef ) if $api =~ /still_open/; - - 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' }, - } - ] - ) }; +sub _make_mbts { + my @xacts = shift; my @mbts; for my $x (@xacts) { @@ -1870,8 +1854,28 @@ sub user_transaction_history { push @mbts, $s; } + return @mbts; +} + +sub user_transaction_history { + my( $self, $conn, $auth, $userid, $type ) = @_; + my $e = new_editor(authtoken=>$auth); + return $e->event unless $e->checkauth; + return $e->event unless $e->allowed('VIEW_USER_TRANSACTIONS'); + + my $api = $self->api_name; + my @xact_finish = (xact_finish => undef ) if $api =~ /still_open/; + 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 = _make_mbts( @xacts ); if(defined($type)) { @mbts = grep { $_->xact_type eq $type } @mbts; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm index f8cc997dac..62f250b403 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm @@ -488,6 +488,58 @@ sub _check_open_xact { } +sub _make_mbts { + my @xacts = shift; + + my @mbts; + for my $x (@xacts) { + my $s = new Fieldmapper::money::billable_transaction_summary; + $s->id( $x->id ); + $s->usr( $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 ); + + $s->xact_type( 'grocery' ) if ($x->grocery); + $s->xact_type( 'circulation' ) if ($x->circulation); + + push @mbts, $s; + } + + return @mbts; +} + __PACKAGE__->register_method ( method => 'fetch_mbts', @@ -496,8 +548,14 @@ __PACKAGE__->register_method ( sub fetch_mbts { my($s, $c, $authtoken, $id) = @_; - my $sum = $U->cstorereq( - 'open-ils.cstore.direct.money.billable_transaction_summary.retrieve', $id ); + my @xacts = @{ $e->search_money_billable_transaction( + [ { id => $id }, + { flesh => 1, flesh_fields => { mbt => [ qw/billings payments grocery circulation/ ] } } + ] + ) }; + + my ($sum) = _make_mbts(@xacts); + return OpenILS::Event->new('MONEY_BILLABLE_TRANSACTION_SUMMARY_NOT_FOUND', id => $id) unless $sum; my ($reqr, $evt) = $U->checkses($authtoken); -- 2.43.2