# ------------------------------------------------------------------
-# 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;
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(
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;
}
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);
+ }
}
}
}