From: Jason Stephenson Date: Sun, 6 Oct 2013 21:13:01 +0000 (-0400) Subject: Add CircCommon->unvoid_bill and use it in Circulate.pm. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a28a8f6d9c70a5c831030cf45dfe248ac1cf46ca;p=evergreen%2Fequinox.git Add CircCommon->unvoid_bill and use it in Circulate.pm. Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm index a00a4a3316..0ba84c96ee 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm @@ -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) = @_; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm index 8511ab6eb4..3cc56677a6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -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); } }