From: Jeff Godin Date: Tue, 12 Jun 2012 15:56:26 +0000 (-0400) Subject: Support forgive of Lost bills on checkin X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e61f595c887fca06277b5743599e95aab4607340;p=evergreen%2Ftadl.git Support forgive of Lost bills on checkin Add support for making a Forgive payment on outstanding Lost and Lost Processing Fee bills on checkin of a lost item. Signed-off-by: Jeff Godin --- 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 3bd0638be6..5e5ab8d1dd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -3079,7 +3079,7 @@ sub checkin_handle_circ { # ------------------------------------------------------------------ -# See if we need to void billings for lost checkin +# See if we need to void or forgive billings for lost checkin # ------------------------------------------------------------------ sub checkin_handle_lost { my $self = shift; @@ -3104,6 +3104,10 @@ sub checkin_handle_lost { if (!$max_return){ # there's either no max time to accept returns defined or we're within that time + my $forgive_lost = $U->ou_ancestor_setting_value( + $circ_lib, OILS_SETTING_FORGIVE_LOST_ON_CHECKIN, $self->editor) || 0; + my $forgive_lost_fee = $U->ou_ancestor_setting_value( + $circ_lib, OILS_SETTING_FORGIVE_LOST_PROCESS_FEE_ON_CHECKIN, $self->editor) || 0; my $void_lost = $U->ou_ancestor_setting_value( $circ_lib, OILS_SETTING_VOID_LOST_ON_CHECKIN, $self->editor) || 0; my $void_lost_fee = $U->ou_ancestor_setting_value( @@ -3111,8 +3115,8 @@ sub checkin_handle_lost { my $restore_od = $U->ou_ancestor_setting_value( $circ_lib, OILS_SETTING_RESTORE_OVERDUE_ON_LOST_RETURN, $self->editor) || 0; - $self->checkin_handle_lost_now_found(3) if $void_lost; - $self->checkin_handle_lost_now_found(4) if $void_lost_fee; + $self->checkin_handle_lost_now_found(3, $forgive_lost) if $forgive_lost || $void_lost; + $self->checkin_handle_lost_now_found(4, $forgive_lost_fee) if $forgive_lost_fee || $void_lost_fee; $self->checkin_handle_lost_now_found_restore_od() if $restore_od && ! $self->void_overdues; } @@ -3445,31 +3449,63 @@ sub make_trigger_events { sub checkin_handle_lost_now_found { - my ($self, $bill_type) = @_; + my ($self, $bill_type, $forgive) = @_; # ------------------------------------------------------------------ # remove charge from patron's account if lost item is returned # ------------------------------------------------------------------ - my $bills = $self->editor->search_money_billing( - { - xact => $self->circ->id, - btype => $bill_type + if ($forgive) { + my $bills = $U->outstanding_bills_for_circ($self->editor, $self->circ); + + $logger->debug("forgiving lost item charge of ".scalar(@$bills)); + my $total_to_forgive = 0; + for my $bill (@$bills) { + if ($bill->btype == $bill_type) { + $logger->info("lost item returned - will make payment to forgive bill ".$bill->id); + # add this bill's amount to the total to forgive + $total_to_forgive = (($total_to_forgive*100) + ($bill->amount*100)) / 100; + } else { + last; + } } - ); + if ($total_to_forgive >= 0.01) { + # pay with forgive payment + my $payobj = Fieldmapper::money::forgive_payment->new; + $payobj->amount($total_to_forgive); + $payobj->amount_collected($total_to_forgive); + $payobj->xact($self->circ->id); + $payobj->note("System: FORGIVEN FOR LOST ITEM RETURNED"); + $payobj->accepting_usr($self->editor->requestor->id); + + $logger->info("checkin_handle_lost_now_found about to create forgive payment... "); + $self->bail_on_events($self->editor->event) + unless $self->editor->create_money_forgive_payment($payobj); + } else { + $logger->info("checkin_handle_lost_now_found found no billings of type $bill_type to forgive."); + } + + } else { + my $bills = $self->editor->search_money_billing( + { + xact => $self->circ->id, + btype => $bill_type + } + ); - $logger->debug("voiding lost item charge of ".scalar(@$bills)); - for my $bill (@$bills) { - if( !$U->is_true($bill->voided) ) { - $logger->info("lost item returned - voiding bill ".$bill->id); - $bill->voided('t'); - $bill->void_time('now'); - $bill->voider($self->editor->requestor->id); - my $note = ($bill->note) ? $bill->note . "\n" : ''; - $bill->note("${note}System: VOIDED FOR LOST ITEM RETURNED"); + $logger->debug("voiding lost item charge of ".scalar(@$bills)); + for my $bill (@$bills) { + if( !$U->is_true($bill->voided) ) { + $logger->info("lost item returned - voiding bill ".$bill->id); + $bill->voided('t'); + $bill->void_time('now'); + $bill->voider($self->editor->requestor->id); + my $note = ($bill->note) ? $bill->note . "\n" : ''; + $bill->note("${note}System: VOIDED FOR LOST ITEM RETURNED"); - $self->bail_on_events($self->editor->event) - unless $self->editor->update_money_billing($bill); + $self->bail_on_events($self->editor->event) + unless $self->editor->update_money_billing($bill); + } } } }