LP#1350371 display existing copies
authorBill Erickson <berick@esilibrary.com>
Wed, 30 Jul 2014 21:34:07 +0000 (17:34 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 19 Feb 2015 13:38:17 +0000 (08:38 -0500)
In the picklist / PO lineitem list view, display the number of existing
catalog copies owned at or below the PO ordering agency or Picklist org
unit whose status is not in some form of lost or missing.

Value is displayed beside the lineitem ID and is styled bold/red if the
count is greater than zero.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm
Open-ILS/src/templates/acq/common/li_table.tt2
Open-ILS/web/css/skin/default/acq.css
Open-ILS/web/js/dojo/openils/acq/nls/acq.js
Open-ILS/web/js/ui/default/acq/common/li_table.js

index 12b8def..69ecdf6 100644 (file)
@@ -3958,6 +3958,73 @@ sub apply_new_li_ident_attr {
     return ($source_attr);
 }
 
+__PACKAGE__->register_method(
+    method => 'li_existing_copies',
+    api_name => 'open-ils.acq.lineitem.existing_copies.count',
+    authoritative => 1, 
+    signature => {
+        desc => q/
+            Returns the number of catalog copies (acp) which are children of
+            the same bib record linked to by the given lineitem and which 
+            are owned at or below the lineitem context org unit.
+            Copies with the following statuses are not counted:
+            Lost, Missing, Discard Weed, and Lost and Paid.
+        /,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'Lineitem ID', type => 'number'}
+        ],
+        return => {desc => q/Count or event on error/}
+    }
+);
+
+sub li_existing_copies {
+    my ($self, $client, $auth, $li_id) = @_;
+    my $e = new_editor("authtoken" => $auth);
+    return $e->die_event unless $e->checkauth;
+
+    my ($li, $evt, $org) = fetch_and_check_li($e, $li_id);
+    return 0 if $evt;
+
+    # No fuzzy matching here (e.g. on ISBN).  Only exact matches are supported.
+    return 0 unless $li->eg_bib_id;
+
+    my $counts = $e->json_query({
+        select => {acp => [{
+            column => 'id', 
+            transform => 'count', 
+            aggregate => 1
+        }]},
+        from => {
+            acp => {
+                acqlid => {
+                    fkey => 'id',
+                    field => 'eg_copy_id',
+                    type => 'left'
+                },
+                acn => {join => {bre => {}}}
+            }
+        },
+        where => {
+            '+bre' => {id => $li->eg_bib_id},
+            # don't count copies linked to the lineitem in question
+            '+acqlid' => {
+                '-or' => [
+                    {lineitem => undef},
+                    {lineitem => {'<>' => $li_id}}
+                ]
+            },
+            '+acn' => {
+                owning_lib => $U->get_org_descendants($org)
+            },
+            # NOTE: should the excluded copy statuses be an AOUS?
+            '+acp' => {status => {'not in' => [3, 4, 13, 17]}}
+        }
+    });
+
+    return $counts->[0]->{id};
+}
+
 
 1;
 
index 2239689..9ebc8ad 100644 (file)
                                 </tr>
                                 <tr>
                                     <td colspan='0'>
-                                        <span name="liid"># </span> 
+                                        <span name="liid"># </span> | 
+                                        <span name="li_existing_count">0</span> 
                                         <span name="catalog" class='hidden'> | <a title='[% l('Show In Catalog') %]' name="catalog_link" href="javascript:void(0);">[% l('&#x279F; catalog') %]</a></span> 
                                         <span name="link_to_catalog" class='hidden'> | <a title='[% l('Link To Catalog Record') %]' name="link_to_catalog_link" href="javascript:void(0);">[% l('&#x27BE; link to catalog') %]</a></span> 
                                         <span name="worksheet"> | <a title='[% l('Generate Worksheet') %]' name="worksheet_link" href="javascript:void(0);">[% l('&#x270D; worksheet') %]</a></span>
index 1beff27..1887983 100644 (file)
@@ -279,3 +279,8 @@ span[name="bib_origin"] img { vertical-align: middle; }
 }
 
 span[name="cancel_reason"] { text-decoration: underline; font-weight: bold; }
+
+.acq-existing-count-warn {
+    font-weight: bold;
+    color: red;
+}
index 990260a..53793ce 100644 (file)
     "NO_LI_GENERAL" : "You have not selected any (suitable) line items.",
     "DUPE_PO_NAME_MSG" : "This name is already in use by another PO",
     "DUPE_PO_NAME_LINK" : "View PO",
-    "PO_NAME_OPTIONAL" : "${0} (optional)"
+    "PO_NAME_OPTIONAL" : "${0} (optional)",
+    "LI_EXISTING_COPIES" : "There are ${0} existing copies for this bibliographic record at this location"
 }
index 2a2a2ff..a94d403 100644 (file)
@@ -713,6 +713,27 @@ function AcqLiTable() {
 
         nodeByName("liid", row).innerHTML += li.id();
 
+        var exist = nodeByName('li_existing_count', row);
+        fieldmapper.standardRequest(
+            ['open-ils.acq', 'open-ils.acq.lineitem.existing_copies.count'],
+            {
+                params: [this.authtoken, li.id()],
+                oncomplete : function(r) {
+                    var count = openils.Util.readResponse(r);
+                    exist.innerHTML = count;
+                    if (Number(count) > 0) {
+                        openils.Util.addCSSClass(
+                            exist, 'acq-existing-count-warn');
+                    }
+                    new dijit.Tooltip({
+                        connectId : [exist],
+                        label : dojo.string.substitute(
+                            localeStrings.LI_EXISTING_COPIES, [count])
+                    });
+                }
+            }
+        );
+
         if(li.eg_bib_id()) {
             openils.Util.show(nodeByName('catalog', row), 'inline');
             nodeByName("catalog_link", row).onclick = this.generateMakeRecTab(li.eg_bib_id());