[open-ils-commits] r16163 - in trunk/Open-ILS: src/perlmods/OpenILS/Application/Acq web/js/ui/default/acq/search web/templates/default/acq/search (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Apr 7 17:24:31 EDT 2010


Author: senator
Date: 2010-04-07 17:24:25 -0400 (Wed, 07 Apr 2010)
New Revision: 16163

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
   trunk/Open-ILS/web/js/ui/default/acq/search/unified.js
   trunk/Open-ILS/web/templates/default/acq/search/unified.tt2
Log:
Acq: make invoices searchable with unified search interface


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm	2010-04-07 21:07:02 UTC (rev 16162)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm	2010-04-07 21:24:25 UTC (rev 16163)
@@ -70,7 +70,7 @@
         }
     }
 
-    $invoice = fetch_invice_impl($e, $invoice->id);
+    $invoice = fetch_invoice_impl($e, $invoice->id);
     $e->commit;
 
     return $invoice;
@@ -90,34 +90,37 @@
 );
 
 
-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);
 }
 
 

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm	2010-04-07 21:07:02 UTC (rev 16162)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm	2010-04-07 21:24:25 UTC (rev 16163)
@@ -10,6 +10,7 @@
 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 @@
         \&{"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 @@
     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 @@
     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(
+    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 @@
                     "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 @@
         };
     };
 
-    # 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));
 

Modified: trunk/Open-ILS/web/js/ui/default/acq/search/unified.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/search/unified.js	2010-04-07 21:07:02 UTC (rev 16162)
+++ trunk/Open-ILS/web/js/ui/default/acq/search/unified.js	2010-04-07 21:24:25 UTC (rev 16163)
@@ -150,7 +150,7 @@
     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 @@
  * 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 @@
                 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 @@
         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 @@
         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 @@
         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");
     }

Modified: trunk/Open-ILS/web/templates/default/acq/search/unified.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/search/unified.tt2	2010-04-07 21:07:02 UTC (rev 16162)
+++ trunk/Open-ILS/web/templates/default/acq/search/unified.tt2	2010-04-07 21:24:25 UTC (rev 16163)
@@ -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 + "</a>";
         }
     }
+
+    function formatInvIdent(inv) {
+        if (inv) {
+            return "<a href='" + oilsBasePath + "/acq/invoice/view/" +
+                inv.id + "'>" + inv.inv_ident + "</a>";
+        }
+    }
 </script>
 <!-- later: "[% ctx.page_args.0 %]" -->
 <div id="acq-unified-body" class="hidden">
@@ -64,6 +81,7 @@
                 </option>
                 <option value="picklist">pick lists</option>
                 <option value="purchase_order">purchase orders</option>
+                <option value="invoice">invoices</option>
             </select>
             <label for="acq-unified-conjunction">matching</label>
             <select id="acq-unified-conjunction">
@@ -156,6 +174,24 @@
             </thead>
         </table>
     </div>
+    <div id="acq-unified-results-invoice" class="hidden">
+        <table
+            id="acq-unified-inv-grid"
+            autoHeight="true"
+            dojoType="openils.widget.AutoGrid"
+            query="{id: '*'}"
+            fieldOrder="['inv_ident', 'receiver', 'provider', 'shipper']"
+            defaultCellWidth="'auto'"
+            showPaginator="true"
+            fmClass="acqinv">
+            <thead>
+                <tr>
+                    <th field="inv_ident" get="getInvIdent"
+                        formatter="formatInvIdent">Vendor Invoice ID</th>
+                </tr>
+            </thead>
+        </table>
+    </div>
     <div id="acq-unified-results-no_results" class="hidden">
         There are no results from your search.
     </div>



More information about the open-ils-commits mailing list