LP#1453974 copy details reports aged circ user/berick/lp1453974-item-status-aged-circs
authorBill Erickson <berickxx@gmail.com>
Thu, 21 May 2015 21:57:28 +0000 (17:57 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 May 2015 21:57:30 +0000 (17:57 -0400)
If an aged circulation is linked to a copy which is newer than the most
recent standard circulation on the copy, return the aged circ as
additional data ('aged_circ') in the copy details API call.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm

index adf6af2..3879cd5 100644 (file)
@@ -1094,12 +1094,50 @@ sub copy_details {
         ]
     )->[0];
 
+    # The most recent circulation could be an aged circ.
+    # If so, pass it back to the caller to handle as desired.
+   
+    my $aged_circ;
+
+    if ($circ and !$circ->checkin_time and !$circ->xact_finish and (
+            !$circ->stop_fines or 
+            $circ->stop_fines eq OILS_STOP_FINES_MAX_FINES or
+            $circ->stop_fines eq OILS_STOP_FINES_LONGOVERDUE
+        )) {
+   
+        # Skip the aged circ check if the copy is actively circulating.
+        # Saves one cstore call.
+
+    } else {
+
+        my %date_filter = $circ ? 
+            (xact_start => {'>' => $circ->xact_start}) : ();
+
+        $aged_circ = $e->search_action_aged_circulation([
+            {target_copy => $copy_id, %date_filter},
+            { 
+                flesh => 1,
+                flesh_fields => {
+                    acirc => [
+                        'workstation',
+                        'checkin_workstation', 
+                        'duration_rule', 
+                        'max_fine_rule', 
+                        'recurring_fine_rule'
+                    ]
+                },
+                order_by => {circ => 'xact_start desc'}, 
+                limit => 1 
+            }
+        ])->[0];
+    }
 
     return {
-        copy        => $copy,
-        hold        => $hold,
+        copy    => $copy,
+        hold    => $hold,
         transit => $transit,
-        circ        => $circ,
+        circ    => $circ, # most recent non-aged circulation
+        aged_circ => $aged_circ, # most recent aged circ if newer than circ
         volume  => $vol,
         mvr     => $mvr,
     };