KMAIN154 - KMIG45 - KCLSUPGRAD12 - Backdating Lost Item
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Oct 2014 21:05:46 +0000 (17:05 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
    Cross-port: ec196ab

Conflicts:
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

index 73d69ef..6b7ab50 100644 (file)
@@ -4292,4 +4292,80 @@ sub checkin_handle_lost_or_lo_now_found_restore_od {
     }
 }
 
+# ------------------------------------------------------------------
+# Lost-then-found item checked in.  This sub generates new overdue
+# fines, beyond the point of any existing and possibly voided 
+# overdue fines, up to the point of final checkin time (or max fine
+# amount).  
+# ------------------------------------------------------------------
+sub generate_lost_overdue_fines {
+    my $self = shift;
+    my $circ = $self->circ;
+    my $e = $self->editor;
+    my $isBackDated = 0;
+
+    # Re-open the transaction so the fine generator can see it
+    if ($circ->checkin_time == $circ->checkin_scan_time) {
+        #Check in is not backdated
+        if($circ->xact_finish or $circ->stop_fines) {
+            $e->xact_begin;
+            $circ->clear_xact_finish;
+            $circ->clear_stop_fines;
+            $circ->clear_stop_fines_time;
+            $e->update_action_circulation($circ) or return $e->die_event;
+            $e->xact_commit;
+        }
+    }
+    else {
+        #Check in is backdated
+        $isBackDated = 1;
+        if($circ->xact_finish or $circ->stop_fines) {
+            $e->xact_begin;
+            $circ->clear_xact_finish;
+            $e->update_action_circulation($circ) or return $e->die_event;
+            $e->xact_commit;
+        }
+    }
+
+    $e->xact_begin; # generate_fines expects an in-xact editor
+    $self->generate_fines;
+    $circ = $self->circ; # generate fines re-fetches the circ
+    
+    my $update = 0;
+
+    # Re-close the transaction if no money is owed
+    my ($obt) = $U->fetch_mbts($circ->id, $e);
+    if ($obt and $obt->balance_owed == 0) {
+        $circ->xact_finish('now');
+        $update = 1;
+    }
+
+    if ($isBackDated == 1) {
+        #Check in is backdated
+        if($circ->xact_finish or $circ->stop_fines) {
+            $circ->clear_stop_fines;
+            $circ->clear_stop_fines_time;
+        }
+    }
+
+    # Set stop fines if the fine generator didn't have to
+    unless($circ->stop_fines) {
+        $circ->stop_fines(OILS_STOP_FINES_CHECKIN);
+        $circ->stop_fines_time('now');
+        $update = 1;
+    }
+
+    # update the event data sent to the caller within the transaction
+    $self->checkin_flesh_events;
+
+    if ($update) {
+        $e->update_action_circulation($circ) or return $e->die_event;
+        $e->commit;
+    } else {
+        $e->rollback;
+    }
+
+    return undef;
+}
+
 1;