From 735a8dcde16a417c215f5c78bda0c57920bf2df0 Mon Sep 17 00:00:00 2001 From: senator Date: Wed, 7 Apr 2010 21:24:25 +0000 Subject: [PATCH] Acq: make invoices searchable with unified search interface git-svn-id: svn://svn.open-ils.org/ILS/trunk@16163 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Invoice.pm | 33 +++++++++-------- .../src/perlmods/OpenILS/Application/Acq/Search.pm | 43 +++++++++++++++++++--- Open-ILS/web/js/ui/default/acq/search/unified.js | 27 ++++++++++++-- .../web/templates/default/acq/search/unified.tt2 | 36 ++++++++++++++++++ 4 files changed, 115 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm index a1060d32d4..da7d7ab9b2 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm @@ -70,7 +70,7 @@ sub build_invoice_api { } } - $invoice = fetch_invice_impl($e, $invoice->id); + $invoice = fetch_invoice_impl($e, $invoice->id); $e->commit; return $invoice; @@ -90,34 +90,37 @@ __PACKAGE__->register_method( ); -sub fetch_invice_api { - my($self, $conn, $auth, $invoice_id) = @_; +sub fetch_invoice_api { + my($self, $conn, $auth, $invoice_id, $options) = @_; my $e = new_editor(authtoken=>$auth); return $e->event unless $e->checkauth; - my $invoice = fetch_invoice_impl($e, $invoice_id) or return $e->event; + my $invoice = fetch_invoice_impl($e, $invoice_id, $options) or + return $e->event; return $e->event unless $e->allowed(['VIEW_INVOICE', 'CREATE_INVOICE'], $invoice->receiver); return $invoice; } -sub fetch_invice_impl { - my $e = shift; - my $invoice_id = shift; +sub fetch_invoice_impl { + my ($e, $invoice_id, $options) = @_; - return $e->retrieve_acq_invoice([ + $options ||= {}; + + my $args = $options->{"no_flesh_misc"} ? $invoice_id : [ $invoice_id, { - flesh => 4, - flesh_fields => { - acqinv => ['entries', 'items'], - acqie => ['lineitem', 'purchase_order'], - acqii => ['fund_debit'], - jub => ['attributes'] + "flesh" => 4, + "flesh_fields" => { + "acqinv" => ["entries", "items"], + "acqie" => ["lineitem", "purchase_order"], + "acqii" => ["fund_debit"], + "jub" => ["attributes"] } } - ]); + ]; + return $e->retrieve_acq_invoice($args); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm index fb74708531..fe2badb4bd 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm @@ -10,6 +10,7 @@ use OpenILS::Utils::Fieldmapper; use OpenILS::Application::Acq::Lineitem; use OpenILS::Application::Acq::Financials; use OpenILS::Application::Acq::Picklist; +use OpenILS::Application::Acq::Invoice; my %RETRIEVERS = ( "lineitem" => @@ -18,7 +19,10 @@ my %RETRIEVERS = ( \&{"OpenILS::Application::Acq::Picklist::retrieve_picklist_impl"}, "purchase_order" => \&{ "OpenILS::Application::Acq::Financials::retrieve_purchase_order_impl" - } + }, + "invoice" => \&{ + "OpenILS::Application::Acq::Invoice::fetch_invoice_impl" + }, ); sub F { $Fieldmapper::fieldmap->{"Fieldmapper::" . $_[0]}; } @@ -208,7 +212,7 @@ sub prepare_terms { my $conj = $is_and ? "-and" : "-or"; my $outer_clause = {}; - foreach my $class (qw/acqpo acqpl jub/) { + foreach my $class (qw/acqpo acqpl acqinv jub/) { next if not exists $terms->{$class}; $outer_clause->{$conj} = [] unless $outer_clause->{$conj}; @@ -250,7 +254,14 @@ sub add_au_joins { my $n = 0; foreach my $join (@_) { my ($hint, $attr, $num) = @$join; - my $start = $hint eq "jub" ? $from->{$hint} : $from->{"jub"}->{$hint}; + my $start; + if ($hint eq "jub") { + $start = $from->{$hint}; + } elsif ($hint eq "acqinv") { + $start = $from->{"jub"}->{"acqie"}->{"join"}->{$hint}; + } else { + $start = $from->{"jub"}->{$hint}; + } my $clause = { "class" => "au", "type" => "left", @@ -318,6 +329,17 @@ __PACKAGE__->register_method( } ); +__PACKAGE__->register_method( + method => "unified_search", + api_name => "open-ils.acq.invoice.unified_search", + stream => 1, + signature => { + desc => q/Returns invoices lists based on flexible search terms. + See open-ils.acq.lineitem.unified_search/, + return => {desc => "A stream of invoices on success, Event on failure"} + } +); + sub unified_search { my ($self, $conn, $auth, $and_terms, $or_terms, $conj, $options) = @_; $options ||= {}; @@ -347,6 +369,18 @@ sub unified_search { "type" => "full", "field" => "id", "fkey" => "picklist" + }, + "acqie" => { + "type" => "full", + "field" => "lineitem", + "fkey" => "id", + "join" => { + "acqinv" => { + "type" => "full", + "fkey" => "invoice", + "field" => "id" + } + } } } }, @@ -363,9 +397,6 @@ sub unified_search { }; }; - # TODO find instances of fields of type "timestamp" and massage the - # comparison to match search input (which is only at date precision, - # not timestamp). my $offset = add_au_joins($query->{"from"}, prepare_au_terms($and_terms)); add_au_joins($query->{"from"}, prepare_au_terms($or_terms, $offset)); diff --git a/Open-ILS/web/js/ui/default/acq/search/unified.js b/Open-ILS/web/js/ui/default/acq/search/unified.js index 0686e82435..73d26cb6b4 100644 --- a/Open-ILS/web/js/ui/default/acq/search/unified.js +++ b/Open-ILS/web/js/ui/default/acq/search/unified.js @@ -150,7 +150,7 @@ function TermManager() { var self = this; this.terms = {}; - ["jub", "acqpl", "acqpo"].forEach( + ["jub", "acqpl", "acqpo", "acqinv"].forEach( function(hint) { var o = {}; o.__label = fieldmapper.IDL.fmclasses[hint].label; @@ -309,14 +309,16 @@ function TermManager() { * layer, and it chooses which ML method to call as well as what widgets to use * to display the results. */ -function ResultManager(liTable, poGrid, plGrid) { +function ResultManager(liTable, poGrid, plGrid, invGrid) { var self = this; this.liTable = liTable; this.poGrid = poGrid; this.plGrid = plGrid; + this.invGrid = invGrid; this.poCache = {}; this.plCache = {}; + this.invCache = {}; this.result_types = { "lineitem": { @@ -349,6 +351,15 @@ function ResultManager(liTable, poGrid, plGrid) { self.plCache = {}; } }, + "invoice": { + "search_options": { + "no_flesh_misc": true + }, + "revealer": function() { + self.invGrid.resetStore(); + self.invCache = {}; + } + }, "no_results": { "revealer": function() { alert(localeStrings.NO_RESULTS); } } @@ -368,6 +379,11 @@ function ResultManager(liTable, poGrid, plGrid) { this.plGrid.store.newItem(acqpl.toStoreItem(pl)); }; + this._add_invoice = function(inv) { + this.invCache[inv.id()] = inv; + this.invGrid.store.newItem(acqinv.toStoreItem(inv)); + }; + this._finish_purchase_order = function() { this.poGrid.hideLoadProgressIndicator(); }; @@ -376,6 +392,10 @@ function ResultManager(liTable, poGrid, plGrid) { this.plGrid.hideLoadProgressIndicator(); }; + this._finish_invoice = function() { + this.invGrid.hideLoadProgressIndicator(); + }; + this.add = function(which, what) { var name = "_add_" + which; if (this[name]) this[name](what); @@ -448,7 +468,8 @@ openils.Util.addOnLoad( resultManager = new ResultManager( new AcqLiTable(), dijit.byId("acq-unified-po-grid"), - dijit.byId("acq-unified-pl-grid") + dijit.byId("acq-unified-pl-grid"), + dijit.byId("acq-unified-inv-grid") ); openils.Util.show("acq-unified-body"); } diff --git a/Open-ILS/web/templates/default/acq/search/unified.tt2 b/Open-ILS/web/templates/default/acq/search/unified.tt2 index b400d4e73e..146c5412a3 100644 --- a/Open-ILS/web/templates/default/acq/search/unified.tt2 +++ b/Open-ILS/web/templates/default/acq/search/unified.tt2 @@ -15,6 +15,16 @@ } } + function getInvIdent(rowIndex, item) { + if (item) { + return { + "inv_ident": this.grid.store.getValue(item, "inv_ident") || + this.grid.store.getValue(item, "id"), + "id": this.grid.store.getValue(item, "id") + }; + } + } + function getPlOwnerName(rowIndex, item) { try { return resultManager.plCache[this.grid.store.getValue(item, "id")]. @@ -37,6 +47,13 @@ pl.id + "'>" + pl.name + ""; } } + + function formatInvIdent(inv) { + if (inv) { + return "" + inv.inv_ident + ""; + } + }