From abde0b87073597cb3b7134e8808f09f505a99cd0 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 7 Oct 2013 03:31:02 -0400 Subject: [PATCH] Better logic for checkin_handle_lost_or_lo_now_found_restore_od. Signed-off-by: Jason Stephenson --- .../perlmods/lib/OpenILS/Application/AppUtils.pm | 2 +- .../lib/OpenILS/Application/Circ/Circulate.pm | 27 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index 18d15ea074..ef9bbb53bb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -2206,7 +2206,7 @@ sub fpdiff { while (my $arg = shift(@args)) { $result -= $arg * 100; } - retrun $result / 100; + return $result / 100; } 1; 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 3cc56677a6..c3d2653143 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -3990,7 +3990,6 @@ sub checkin_handle_lost_or_lo_now_found_restore_od { # ------------------------------------------------------------------ # restore those overdue charges voided when item was set to lost # ------------------------------------------------------------------ - my $ods = $self->editor->search_money_billing( { xact => $self->circ->id, @@ -3999,9 +3998,29 @@ sub checkin_handle_lost_or_lo_now_found_restore_od { ); $logger->debug("returning ".scalar(@$ods)." overdue charges pre-$tag"); - for my $bill (@$ods) { - my $result = $CC->unvoid_bill($self->editor->authtoken, $bill, "System: $tag RETURNED - OVERDUES REINSTATED" ); - $self->bail_on_events($result) if ($result); + # Because actual users get up to all kinds of unexpectedness, we + # only recreate up to $circ->max_fine in bills. I know you think + # it wouldn't happen that bills could get created, voided, and + # recreated more than once, but I guaran-damn-tee you that it will + # happen. + if ($ods && @$ods) { + my $void_amount = 0; + my $void_max = $self->circ->max_fine(); + my @billings = map {$_->id()} @$ods; + my $voids = $self->editor->search_money_void_payment( + { + billing => \@billings + } + ); + map {$void_amount += $_->amount()} @$voids; + $CC->create_bill( + $self->editor, + ($void_amount < $void_max ? $void_amount : $void_max), + $ods->[0]->btype(), + $ods->[0]->billing_type(), + $self->circ->id(), + "System: $tag RETURNED - OVERDUES REINSTATED" + ); } } -- 2.11.0