Acq: Make manual lineitem claiming work better. When a claiming policy has not
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 4 Jan 2011 14:40:23 +0000 (14:40 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 4 Jan 2011 14:40:23 +0000 (14:40 +0000)
been applied, users can now choose claim actions manually (this is what a
claiming policy would have specified).

git-svn-id: svn://svn.open-ils.org/ILS/trunk@19094 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Acq/Claims.pm
Open-ILS/web/js/dojo/openils/acq/nls/acq.js
Open-ILS/web/js/ui/default/acq/common/claim_dialog.js
Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/templates/default/acq/common/claim_dialog.tt2

index 5f4c2a9..dba843c 100644 (file)
@@ -123,6 +123,13 @@ __PACKAGE__->register_method(
                 /, 
                 type => 'array'
             },
+            {   desc => q/
+                    Optional: Claim Event Types.  If present, we bypass any policy configuration
+                    and use the specified event types.  This is useful for manual claiming against
+                    items that have no claim policy.
+                /,
+                type => 'array'
+            }
         ],
         return => {
             desc => "The claim voucher events on success, Event on error",
@@ -140,7 +147,9 @@ sub claim_item {
     my $claim_type_id = shift;
     my $note = shift;
     my $policy_actions = shift;
-#   my $only_eligible = shift; # so far unused
+
+    # if this claim occurs outside of a policy, allow the caller to specificy the event type
+    my $claim_event_types = shift; 
 
     my $e = new_editor(xact => 1, authtoken=>$auth);
     return $e->die_event unless $e->checkauth;
@@ -169,32 +178,28 @@ sub claim_item {
         return OpenILS::Event->new('BAD_PARAMS');
     }
 
+
+    my $lids;
     if($self->api_name =~ /claim.lineitem_detail/) {
-        my $lids = $e->search_acq_lineitem_detail([
+
+        $lids = $e->search_acq_lineitem_detail([
             {"id" => $object_id, "cancel_reason" => undef},
             $lid_flesh
         ]) or return $e->die_event;
-        foreach my $lid (@$lids) {
-            return $evt if
-                $evt = claim_lineitem_detail(
-                    $e, $lid, $claim, $claim_type, $policy_actions,
-                    $note, $claim_events
-                );
-        }
 
     } elsif($self->api_name =~ /claim.lineitem/) {
-        my $lids = $e->search_acq_lineitem_detail([
+        $lids = $e->search_acq_lineitem_detail([
             {"lineitem" => $object_id, "cancel_reason" => undef},
             $lid_flesh
         ]) or return $e->die_event;
+    }
 
-        foreach my $lid (@$lids) {
-            return $evt if
-                $evt = claim_lineitem_detail(
-                    $e, $lid, $claim, $claim_type, $policy_actions,
-                    $note, $claim_events
-                );
-        }
+    foreach my $lid (@$lids) {
+        return $evt if
+            $evt = claim_lineitem_detail(
+                $e, $lid, $claim, $claim_type, $policy_actions,
+                $note, $claim_events, $claim_event_types
+            );
     }
 
     $e->commit;
@@ -210,7 +215,7 @@ sub claim_item {
 }
 
 sub claim_lineitem_detail {
-    my($e, $lid, $claim, $claim_type, $policy_actions, $note, $claim_events) = @_;
+    my($e, $lid, $claim, $claim_type, $policy_actions, $note, $claim_events, $claim_event_types) = @_;
 
     # Create the claim object
     unless($claim) {
@@ -220,23 +225,35 @@ sub claim_lineitem_detail {
         $e->create_acq_claim($claim) or return $e->die_event;
     }
 
-    # find all eligible policy actions if none are provided
-    unless($policy_actions) {
-        my $list = $e->json_query({
-            select => {acrlid => ['claim_policy_action']},
-            from => 'acrlid',
-            where => {lineitem_detail => $lid->id}
-        });
+    unless($claim_event_types) {
+        # user did not specify explicit event types
+
+        unless($policy_actions) {
+            # user did not specifcy policy actions.  find all eligible.
 
-        $policy_actions = [map { $_->{claim_policy_action} } @$list];
+            my $list = $e->json_query({
+                select => {acrlid => ['claim_policy_action']},
+                from => 'acrlid',
+                where => {lineitem_detail => $lid->id}
+            });
+    
+            $policy_actions = [map { $_->{claim_policy_action} } @$list];
+        }
+
+        # from the set of policy_action's, locate the related event types
+        # IOW, the policy action's action
+        $claim_event_types = [];
+        for my $act_id (@$policy_actions) {
+            my $action = $e->retrieve_acq_claim_policy_action($act_id) or return $e->die_event;
+            push(@$claim_event_types, $action->action);
+        }
     }
 
     # for each eligible (or chosen) policy actions, create a claim_event
-    for my $act_id (@$policy_actions) {
-        my $action = $e->retrieve_acq_claim_policy_action($act_id) or return $e->die_event;
+    for my $event_type (@$claim_event_types) {
         my $event = Fieldmapper::acq::claim_event->new;
         $event->claim($claim->id);
-        $event->type($action->action);
+        $event->type($event_type);
         $event->creator($e->requestor->id);
         $event->note($note);
         $e->create_acq_claim_event($event) or return $e->die_event;
index 3b8f8b5..040bec3 100644 (file)
@@ -76,5 +76,6 @@
     "INVOICES" : "Invoices",
     "NUM_CLAIMS_EXISTING" : "Claims (${0} existing)",
     "LOAD_TERMS_FIRST" : "You can't retrieve records until you've loaded a CSV file\nwith bibliographic IDs in the first column.",
-    "SELECT_SEARCH_FIELD": "Select Search Field"
+    "SELECT_SEARCH_FIELD": "Select Search Field",
+    "LIBRARY_INITIATED": "Library Initiated"
 }
index 28042b2..0c0c98f 100644 (file)
@@ -26,6 +26,11 @@ function ClaimDialogManager(
         nodeByName("lid_to_claim", this.eligibleList)
     );
 
+    var acqclet_template_parent = dojo.byId("acqclet-tbody");
+    this.eventTypeTemplate = acqclet_template_parent.removeChild(
+        nodeByName("acqclet-template", acqclet_template_parent)
+    );
+
     dojo.byId("acq-lit-li-claim-dia-claim").onclick = function() {
         var lid_ids = self.getSelectedEligible();
         if (lid_ids.length) {
@@ -55,7 +60,9 @@ function ClaimDialogManager(
 
         openils.Util.hide("acq-lit-li-claim-dia-initiate");
         openils.Util.hide("acq-lit-li-claim-dia-show");
+        openils.Util.hide("acqclet-display");
 
+        dojo.empty("acqclet-tbody");
         dojo.empty(this.showingList);
         dojo.empty(this.eligibleList);
     };
@@ -87,6 +94,62 @@ function ClaimDialogManager(
                 }
             }
         );
+
+        if (!li.claim_policy())
+            this.showClaimEventTypes();
+    };
+
+    this.showClaimEventTypes = function() {
+        if (!this._cached_event_types) {
+            this._cached_event_types = new openils.PermaCrud({
+                "authtoken": openils.User.authtoken
+            }).retrieveAll(
+                "acqclet", {"order_by": {"acqclet": "code"}}
+            );
+        }
+
+        if (this._cached_event_types && this._cached_event_types.length) {
+            openils.Util.show("acqclet-display");
+            dojo.empty("acqclet-tbody");
+            this._cached_event_types.forEach(
+                function(clet) { self._render_event_type_row(clet); }
+            );
+        }
+    };
+
+    this.selectedEventTypes = function() {
+        var selected = dojo.query("[id^='acqclet-checkbox-']").filter(
+            function(node) {
+                return dojo.attr(node, "checked");
+            }
+        ).map(
+            function(node) {
+                return dojo.attr(node, "id").match(/-(\d+)$/)[1];
+            }
+        );
+
+        return selected.length ? selected : null;
+    };
+
+    this._render_event_type_row = function(clet) {
+        var row = dojo.clone(this.eventTypeTemplate);
+
+        var checkbox = nodeByName("acqclet-checkbox", row);
+        var label = nodeByName("acqclet-label", row);
+
+        var checkbox_id = "acqclet-checkbox-" + clet.id();
+        dojo.attr(checkbox, "id", checkbox_id);
+        dojo.attr(label, "for", checkbox_id);
+
+        label.innerHTML = dojo.string.substitute(label.innerHTML, {
+            "description": clet.description(),
+            "code": clet.code(),
+            "library_initiated": clet.library_initiated() ?
+                localeStrings.LIBRARY_INITIATED : "",
+            "ou": aou.findOrgUnit(clet.org_unit()).shortname()
+        });
+
+        dojo.place(row, "acqclet-tbody");
     };
 
     this._reprReceived = function(lid) {
@@ -178,7 +241,9 @@ function ClaimDialogManager(
                 "params": [
                     openils.User.authtoken, lid_ids, null,
                     this.claimType.attr("value"),
-                    dijit.byId("acq-eligible-claim-note").attr("value")
+                    dijit.byId("acq-eligible-claim-note").attr("value"),
+                    null,
+                    this.selectedEventTypes()
                 ],
                 "async": true,
                 "onresponse": function(r) {
index 3088b68..cb0e20f 100644 (file)
@@ -228,6 +228,7 @@ function AcqLiTable() {
                         [li], self.claimPolicyPicker.attr("value"),
                         function() {
                             self.setClaimPolicyControl(li, row);
+                            self.reconsiderClaimControl(li, row);
                             liClaimPolicyDialog.hide();
                         }
                     );
@@ -291,12 +292,15 @@ function AcqLiTable() {
         dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
 
         if (!this.skipInitialEligibilityCheck)
-            this.fetchClaimInfo(li.id(), false, null, row);
+            this.fetchClaimInfo(
+                li.id(),
+                false,
+                function(full) { self.setClaimPolicyControl(full, row) },
+                row
+            );
 
         this.updateLiNotesCount(li, row);
 
-        this.setClaimPolicyControl(li, row);
-
         // show which PO this lineitem is a member of
         if(li.purchase_order() && !this.isPO) {
             var po = 
@@ -420,7 +424,7 @@ function AcqLiTable() {
             function(lid) { self.claimEligibleLid[lid.id()] = true; }
         );
         this.reconsiderClaimControl(li, row);
-        if (callback) callback();
+        if (callback) callback(li);
         /*
         this.clearEligibility(li);
         fieldmapper.standardRequest(
@@ -1926,7 +1930,10 @@ function AcqLiTable() {
                         self.claimPolicyPicker.attr("value"),
                         function() {
                             li_list.forEach(
-                                function(li) { self.setClaimPolicyControl(li); }
+                                function(li) {
+                                    self.setClaimPolicyControl(li);
+                                    self.reconsiderClaimControl(li);
+                                }
                             );
                             liClaimPolicyDialog.hide();
                         }
index edc9aa1..741a8a6 100644 (file)
@@ -21,9 +21,9 @@
                 </ul>
             </li>
         </ul>
+        <hr />
     </div>
     <div id="acq-lit-li-claim-dia-initiate" class="hidden">
-        <hr />
         <div><big>Initiate New Claims</big></div>
         <div id="acq-lit-li-claim-dia-lid-list-init">
             <div name="lid_to_claim">
                 </label>
             </div>
         </div>
+        <hr />
+        <div id="acqclet-display" class="hidden">
+            <div><big>Select Claim Action</big></div>
+            <table>
+                <tbody id="acqclet-tbody">
+                    <tr name="acqclet-template">
+                        <td>
+                            <input type="checkbox" name="acqclet-checkbox" />
+                        </td>
+                        <td style="padding-left: 1em;">
+                            <label name="acqclet-label">
+                                (${ou}) ${code} <em>${description}</em>
+                                <span style="color: #069;">
+                                    ${library_initiated}</span>
+                            </label>
+                        </td>
+                    </tr>
+                </tbody>
+            </table>
+            <hr />
+        </div>
         <button id="acq-lit-li-claim-dia-claim">Claim selected</button>
     </div>
 </div>