From cc30dab77117b009069807935df75f1580bde2b0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 8 Nov 2013 11:43:38 -0500 Subject: [PATCH] LP#1249398 clear negative balance (p1) Signed-off-by: Bill Erickson --- .../perlmods/lib/OpenILS/Application/Circ/Money.pm | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm index 99a714dc33..91aec13519 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm @@ -951,5 +951,56 @@ sub retrieve_credit_payable_balance { return $sum; } +__PACKAGE__->register_method( + method => 'zeroize_transaction', + api_name => 'open-ils.circ.money.zeroize_transaction', + stream => 1, + authoritative => 1, + signature => { + desc => q/ + Given a negative-balance transaction, juggles the void + payment(s) to produce a zero-balance transaction, without + affecting any of the billings or real patron payments. + /, + params => [ + {desc => 'Authtoken', type => 'string'}, + {desc => 'Array of transaction IDs', type => 'array'} + ], + return { + desc => q/A stream of transaction summaries, one for + each transaction updated. On error, the final item + in the stream will be an Event./ + } + } +); + +sub zeroize_transaction { + my ($self, $client, $auth, $xact_ids) = @_; + my $e = new_editor(xact => 1, authtoken => $auth); + return $e->event unless $e->checkauth; + + # in case a bare ID is passed + $xact_ids = [$xact_ids] unless ref $xact_ids; + + for my $xact_id (@$xact_ids) { + my $xact = + $e->retrieve_money_billable_transaction_summary([ + $xact_id, + {flesh => 1, flesh_fields => {mbts => ['usr']}} + ]) or return $e->die_event; + + # we are only concerned with negative-balance transactions + next if $xact->balance_owed >= 0; + + return $e->die_event unless + $e->allowed('CREATE_PAYMENT', $xact->usr->home_ou); + + # TODO: do the void payment juggling + #my $new_amount = $U->fpdiff($bill->amount(),$void->amount()); + } + + return; +} + 1; -- 2.11.0