Auto re-bill forgiven overdues on lost checkin
authorJeff Godin <jgodin@tadl.org>
Wed, 1 May 2013 16:32:06 +0000 (12:32 -0400)
committerJeff Godin <jgodin@tadl.org>
Tue, 7 Apr 2015 16:32:41 +0000 (12:32 -0400)
Auto re-bill forgiven overdues on checkin of a lost item.

This is done by looking for a Forgive payment with a special note,
then creating a new billing of type Overdue materials. Nothing is
done to the previous daily billings on the transaction.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

index f37c0fb..27803fc 100644 (file)
@@ -4023,6 +4023,33 @@ sub checkin_handle_lost_or_lo_now_found_restore_od {
     # restore those overdue charges voided when item was set to lost
     # ------------------------------------------------------------------
 
+    # first, look for a forgive payment with a special note
+    my $forgives = $self->editor->search_money_forgive_payment(
+        {
+            xact => $self->circ->id,
+            note => 'System: OVERDUES FORGIVEN ON LOST'
+        }
+    );
+
+    if ($forgives) {
+        $logger->info("Found forgive payment(s) on circ ", $self->circ->id);
+        # re-bill the forgiven overdue(s)
+        for my $payment (@$forgives) {
+            my $bill = Fieldmapper::money::billing->new;
+            my $amount = $payment->amount;
+            my $billing_type = OILS_BILLING_TYPE_OVERDUE_MATERIALS;
+            my $btype = 1;
+            $bill->xact($self->circ->id);
+            $bill->amount($amount);
+            $bill->note('System: re-billed previously forgiven overdues on lost checkin');
+            $bill->billing_type($billing_type);
+            $bill->btype($btype);
+            $self->editor->create_money_billing($bill) or $self->bail_on_events($self->editor->event);
+            $logger->info("Re-billed previously forgiven overdues of $amount on circ ", $self->circ->id);
+        }
+        return;
+    }
+
     my $ods = $self->editor->search_money_billing(
         {
             xact => $self->circ->id,