Add CircCommon->unvoid_bill and use it in Circulate.pm.
authorJason Stephenson <jason@sigio.com>
Sun, 6 Oct 2013 21:13:01 +0000 (17:13 -0400)
committerJason Stephenson <jason@sigio.com>
Thu, 7 Nov 2013 22:01:17 +0000 (17:01 -0500)
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

index a00a4a3..0ba84c9 100644 (file)
@@ -96,6 +96,39 @@ 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) = @_;
+
+    my $ed = new_editor (authtoken => $authtoken, xact => 1);
+    my $voids = $ed->search_money_void_payment(
+        {
+            billing => $bill->id()
+        }
+    );
+
+    if ($voids && @$voids) {
+        my $void_total = 0;
+        map {$void_total += $_->amount()} @$voids;
+        my $result = $class->create_bill($ed, $void_total, $bill->btype(), $bill->billing_type(), $bill->xact(), $note);
+        if ($result) {
+            $ed->rollback();
+            return $result;
+        }
+        $ed->commit;
+    }
+
+    return undef;
+}
+
 sub reopen_xact {
     my($class, $e, $xactid) = @_;
 
index 8511ab6..3cc5667 100644 (file)
@@ -3972,12 +3972,12 @@ sub make_trigger_events {
 
 
 sub checkin_handle_lost_or_lo_now_found {
-    my ($self, $bill_type, $is_longoverdue) = @_;
+    my ($self, $btype, $is_longoverdue) = @_;
 
     my $tag = $is_longoverdue ? "LONGOVERDUE" : "LOST";
 
     $logger->debug("voiding $tag item billings");
-    my $result = $CC->void_bills_of_type($self->editor, $self->circ, $bill_type, "System: VOIDED FOR $tag ITEM RETURNED");
+    my $result = $CC->void_bills_of_type($self->editor, $self->circ, $btype, "System: VOIDED FOR $tag ITEM RETURNED");
     $self->bail_on_events($self->editor->event) if ($result);
 }
 
@@ -4000,17 +4000,8 @@ sub checkin_handle_lost_or_lo_now_found_restore_od {
 
     $logger->debug("returning ".scalar(@$ods)." overdue charges pre-$tag");
     for my $bill (@$ods) {
-        if( $U->is_true($bill->voided) ) {
-                $logger->info("$tag item returned - restoring overdue ".$bill->id);
-                $bill->voided('f');
-                $bill->clear_void_time;
-                $bill->voider($self->editor->requestor->id);
-                my $note = ($bill->note) ? $bill->note . "\n" : '';
-                $bill->note("${note}System: $tag RETURNED - OVERDUES REINSTATED");
-
-                $self->bail_on_events($self->editor->event)
-                        unless $self->editor->update_money_billing($bill);
-        }
+        my $result = $CC->unvoid_bill($self->editor->authtoken, $bill, "System: $tag RETURNED - OVERDUES REINSTATED" );
+        $self->bail_on_events($result) if ($result);
     }
 }