From 97cf13a14d971b671eae5a49f630850d07b6eaea Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 30 Jul 2014 17:34:07 -0400 Subject: [PATCH] LP#1350371 display existing copies 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 --- .../perlmods/lib/OpenILS/Application/Acq/Order.pm | 67 ++++++++++++++++++++++ Open-ILS/src/templates/acq/common/li_table.tt2 | 3 +- Open-ILS/web/css/skin/default/acq.css | 5 ++ Open-ILS/web/js/dojo/openils/acq/nls/acq.js | 3 +- Open-ILS/web/js/ui/default/acq/common/li_table.js | 21 +++++++ 5 files changed, 97 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm index 61dab6c395..6d4cf0fd6f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -3949,6 +3949,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; diff --git a/Open-ILS/src/templates/acq/common/li_table.tt2 b/Open-ILS/src/templates/acq/common/li_table.tt2 index d2259767f1..30b5daabeb 100644 --- a/Open-ILS/src/templates/acq/common/li_table.tt2 +++ b/Open-ILS/src/templates/acq/common/li_table.tt2 @@ -175,7 +175,8 @@ - # + # | + 0 | [% l('✍ worksheet') %] diff --git a/Open-ILS/web/css/skin/default/acq.css b/Open-ILS/web/css/skin/default/acq.css index 1beff279df..1887983f5b 100644 --- a/Open-ILS/web/css/skin/default/acq.css +++ b/Open-ILS/web/css/skin/default/acq.css @@ -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; +} diff --git a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js index dfd3c56246..caa2f7cc87 100644 --- a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js +++ b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js @@ -102,5 +102,6 @@ "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" } diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index eecb232651..cd1b124b61 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -709,6 +709,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()); -- 2.11.0