From: Mike Rylander <mrylander@gmail.com>
Date: Tue, 28 Aug 2018 15:45:11 +0000 (-0400)
Subject: LP#1712854: Provide a "only last captured copy" option to filter holds shelf
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3af031b4a1449d5e28bbaa15e5bdcf7a451c2c5f;p=evergreen%2Fequinox.git

LP#1712854: Provide a "only last captured copy" option to filter holds shelf

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
---

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
index e0e96f98a5..46a9ed023c 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
@@ -2131,7 +2131,23 @@ sub wide_hold_data {
     # force this to either 'true' or 'false'
     my $is_staff_request = delete($$restrictions{is_staff_request}) || 'false';
     $is_staff_request = 'false' if (!grep {$is_staff_request eq $_} qw/true false/);
-    $log->info('is_staff_request: '. $is_staff_request);
+
+    # option to filter for the latest captured hold for a given copy
+    my $last_captured_hold = delete($$restrictions{last_captured_hold}) || 'false';
+    $last_captured_hold = $last_captured_hold eq 'true' ? 1 : 0;
+
+    my $initial_condition = 'TRUE';
+    if ($last_captured_hold) {
+        $initial_condition = <<"        SQL";
+            (h.capture_time IS NULL OR (h.id = (
+                SELECT  id
+                  FROM  action.hold_request recheck
+                  WHERE recheck.current_copy = cp.id
+                  ORDER BY capture_time DESC
+                  LIMIT 1
+            )))
+        SQL
+    }
 
     my $select = <<"    SQL";
 WITH
@@ -2353,7 +2369,7 @@ SELECT  h.id, h.request_time, h.capture_time, h.fulfillment_time, h.checkin_time
                     LEFT JOIN config.circ_modifier cm ON (cp.circ_modifier = cm.code)
               WHERE m.hold = h.id
         ) AS hold_wait
-  WHERE TRUE
+  WHERE $initial_condition
     SQL
 
     my %field_map = (
diff --git a/Open-ILS/web/js/ui/default/staff/circ/holds/app.js b/Open-ILS/web/js/ui/default/staff/circ/holds/app.js
index 6456aad800..d41e963aa7 100644
--- a/Open-ILS/web/js/ui/default/staff/circ/holds/app.js
+++ b/Open-ILS/web/js/ui/default/staff/circ/holds/app.js
@@ -75,6 +75,7 @@ function($scope , $q , $routeParams , $window , $location , egCore , egHolds , e
         holds = [];
         var restrictions = {
                 is_staff_request  : 'true',
+                last_captured_hold: 'true',
                 capture_time      : { not : null },
                 cs_id             : 8, // on holds shelf
                 fulfillment_time  : null,