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;
</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('➟ 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('➾ link to catalog') %]</a></span>
<span name="worksheet"> | <a title='[% l('Generate Worksheet') %]' name="worksheet_link" href="javascript:void(0);">[% l('✍ worksheet') %]</a></span>
"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"
}
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());