LP#1249398 clear negative balance (p1)
authorBill Erickson <berick@esilibrary.com>
Fri, 8 Nov 2013 16:43:38 +0000 (11:43 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 8 Nov 2013 16:43:38 +0000 (11:43 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm

index 99a714d..91aec13 100644 (file)
@@ -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;