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) = @_;
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);
}
$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);
}
}