LP1182519 Per-Hold Behind Desk ML
authorBill Erickson <berick@esilibrary.com>
Tue, 21 May 2013 17:00:20 +0000 (13:00 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 31 May 2013 15:12:33 +0000 (11:12 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

index d8f7e8d..229b250 100644 (file)
@@ -274,6 +274,22 @@ sub promote_lineitem_holds {
             $hold->target( $li->eg_bib_id );
         }
 
+        # if behind-the-desk holds are supported at the 
+        # pickup library, apply the patron default
+        my $bdous = $U->ou_ancestor_setting_value(
+            $hold->pickup_lib, 
+            'circ.holds.behind_desk_pickup_supported', 
+            $mgr->editor
+        );
+
+        if ($bdous) {
+            my $set = $mgr->editor->search_actor_user_setting(
+                {usr => $hold->usr, name => 'circ.holds_behind_desk'})->[0];
+    
+            $hold->behind_desk('t') if $set and 
+                OpenSRF::Utils::JSON->JSON2perl($set->value);
+        }
+
         $mgr->editor->create_action_hold_request( $hold ) or return 0;
     }
 
index d818454..797e1bc 100644 (file)
@@ -1917,11 +1917,17 @@ __PACKAGE__->register_method(
     api_name      => "open-ils.actor.user.hold_requests.count",
     authoritative => 1,
     argc          => 1,
-    notes         => 'Returns hold ready/total counts'
+    notes         => q/
+        Returns hold ready vs. total counts.
+        If a context org unit is provided, a third value 
+        is returned with key 'behind_desk', which reports
+        how many holds are ready at the pickup library 
+        with the behind_desk flag set to true.
+    /
 );
        
 sub hold_request_count {
-       my( $self, $client, $authtoken, $user_id ) = @_;
+       my( $self, $client, $authtoken, $user_id, $ctx_org ) = @_;
     my $e = new_editor(authtoken => $authtoken);
     return $e->event unless $e->checkauth;
 
@@ -1933,7 +1939,7 @@ sub hold_request_count {
     }
 
     my $holds = $e->json_query({
-        select => {ahr => ['pickup_lib', 'current_shelf_lib']},
+        select => {ahr => ['pickup_lib', 'current_shelf_lib', 'behind_desk']},
         from => 'ahr',
         where => {
             usr => $user_id,
@@ -1942,15 +1948,27 @@ sub hold_request_count {
         }
     });
 
-       return { 
+    my @ready = grep { 
+        $_->{current_shelf_lib} and # avoid undef warnings
+        $_->{pickup_lib} eq $_->{current_shelf_lib} 
+    } @$holds;
+
+       my $resp = { 
         total => scalar(@$holds), 
-        ready => scalar(
-            grep { 
-                $_->{current_shelf_lib} and # avoid undef warnings
-                $_->{pickup_lib} eq $_->{current_shelf_lib} 
-            } @$holds
-        ) 
+        ready => scalar(@ready)
     };
+
+    if ($ctx_org) {
+        # count of holds ready at pickup lib with behind_desk true.
+        $resp->{behind_desk} = scalar(
+            grep {
+                $_->{pickup_lib} == $ctx_org and
+                $U->is_true($_->{behind_desk})
+            } @ready
+        );
+    }
+
+    return $resp;
 }
 
 __PACKAGE__->register_method(
index cde9619..046dcc9 100644 (file)
@@ -36,6 +36,7 @@ use DateTime::Format::ISO8601;
 use OpenSRF::Utils qw/:datetime/;
 use Digest::MD5 qw(md5_hex);
 use OpenSRF::Utils::Cache;
+use OpenSRF::Utils::JSON;
 my $apputils = "OpenILS::Application::AppUtils";
 my $U = $apputils;
 
@@ -338,6 +339,31 @@ sub create_hold {
         $hold->expire_time(calculate_expire_time($recipient->home_ou));
     }
 
+
+    # if behind-the-desk pickup is supported at the hold pickup lib,
+    # set the value to the patron default, unless a value has already
+    # been applied.  If it's not supported, force the value to false.
+
+    my $bdous = $U->ou_ancestor_setting_value(
+        $hold->pickup_lib, 
+        'circ.holds.behind_desk_pickup_supported', $e);
+
+    if ($bdous) {
+        if (!defined $hold->behind_desk) {
+
+            my $set = $e->search_actor_user_setting({
+                usr => $hold->usr, 
+                name => 'circ.holds_behind_desk'
+            })->[0];
+        
+            $hold->behind_desk('t') if $set and 
+                OpenSRF::Utils::JSON->JSON2perl($set->value);
+        }
+    } else {
+        # behind the desk not supported, force it to false
+        $hold->behind_desk('f');
+    }
+
     $hold->requestor($e->requestor->id);
     $hold->request_lib($e->requestor->ws_ou);
     $hold->selection_ou($hold->pickup_lib) unless $hold->selection_ou;