Make real_void_bills accept an editor argument instead of authtoken.
authorJason Stephenson <jason@sigio.com>
Wed, 15 Jan 2014 19:43:38 +0000 (14:43 -0500)
committerKathy Lussier <klussier@masslnc.org>
Thu, 13 Feb 2014 05:43:18 +0000 (00:43 -0500)
This makes its caller responsible for handling a database transaction
and prevents no transaction errors in cases where we have already started
a database transaction.

This commit also eliminates the unvoid_bills function that is no longer
used anywhere in the code.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm

index 77a4748..8acaf36 100644 (file)
@@ -62,7 +62,7 @@ sub void_overdues {
 
     my $billids = $e->search_money_billing([$bill_search, {idlist=>1}]);
     if ($billids && @$billids) {
-        my $result = $class->real_void_bills($e->authtoken, $billids, $note);
+        my $result = $class->real_void_bills($e, $billids, $note);
         if (ref($result)) {
             return $result;
         }
@@ -93,7 +93,7 @@ sub void_bills_of_type {
     );
 
     if ($bills && @$bills) {
-        my $result = $class->real_void_bills($e->authtoken, $bills, $note);
+        my $result = $class->real_void_bills($e, $bills, $note);
         if (ref($result)) {
             return $result;
         }
@@ -102,44 +102,6 @@ sub void_bills_of_type {
     return undef;
 }
 
-# ------------------------------------------------------------------
-# "Unvoids" a given bill.  Basically, we create a new bill equal to
-# the amount voided on the original bill.
-#
-# Takes an authtoken, the bill object whose voids you want to undo, and
-# an optional note.
-#
-# Returns undef on success or an event on failure.
-# ------------------------------------------------------------------
-sub unvoid_bill {
-    my ($class, $authtoken, $bill, $note) = @_;
-
-    # Get and editor, check for a session, and check that we can void
-    # bills.  (If we can void bills, we can unvoid them, too.)
-    my $e = new_editor (authtoken => $authtoken, xact => 1);
-    return $e->die_event unless $e->checkauth;
-    return $e->die_event unless $e->allowed('VOID_BILLING');
-
-    my $voids = $e->search_money_void_payment(
-        {
-            billing => $bill->id()
-        }
-    );
-
-    if ($voids && @$voids) {
-        my $void_total = 0;
-        map {$void_total += $_->amount()} @$voids;
-        my $result = $class->create_bill($e, $void_total, $bill->btype(), $bill->billing_type(), $bill->xact(), $note);
-        if ($result) {
-            $e->rollback();
-            return $result;
-        }
-        $e->commit;
-    }
-
-    return undef;
-}
-
 sub reopen_xact {
     my($class, $e, $xactid) = @_;
 
@@ -504,13 +466,12 @@ sub bill_payment_map_for_xact {
 }
 
 
-# This subroutine actually handles voiding of bills.  It takes an
-# authtoken, an arrayref of bill ids or bills, and an optional note.
+# This subroutine actually handles voiding of bills.  It takes a
+# CStoreEditor, an arrayref of bill ids or bills, and an optional note.
 sub real_void_bills {
-    my ($class, $authtoken, $billids, $note) = @_;
+    my ($class, $e, $billids, $note) = @_;
 
-    # Get an editor and see if we have permission to void bills.
-    my $e = new_editor( authtoken => $authtoken, xact => 1 );
+    # Get with the editor to see if we have permission to void bills.
     return $e->die_event unless $e->checkauth;
     return $e->die_event unless $e->allowed('VOID_BILLING');
 
@@ -618,7 +579,6 @@ sub real_void_bills {
             # made it impossible to void an already voided bill, so
             # we're doing the same.
             if ($amount_to_void <= 0) {
-                $e->rollback;
                 return OpenILS::Event->new('BILL_ALREADY_VOIDED', payload => $bill);
             }
 
@@ -683,7 +643,7 @@ sub real_void_bills {
             OpenILS::Utils::Penalty->calculate_penalties($e, $user_id, $org_id);
         }
     }
-    $e->commit;
+
     return 1;
 }
 
index 31f21bb..a7db19a 100644 (file)
@@ -754,7 +754,16 @@ __PACKAGE__->register_method(
 );
 sub void_bill {
     my( $s, $c, $authtoken, @billids ) = @_;
-    return $CC->real_void_bills($authtoken, \@billids);
+    my $editor = new_editor(auth=>$authtoken, xact=>1);
+    my $rv = $CC->real_void_bills($editor, \@billids);
+    if (ref($rv) eq 'HASH') {
+        # We got an event.
+        $editor->rollback();
+    } else {
+        # We should have gotten 1.
+        $editor->commit();
+    }
+    return $rv;
 }