LP#1380803 Update PO summary amounts
authorBill Erickson <berickxx@gmail.com>
Mon, 6 Apr 2015 21:33:26 +0000 (17:33 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 13 Apr 2015 14:25:44 +0000 (10:25 -0400)
Refresh the PO summary amounts (spent, encumbered, estimated) each time
an amount-changing event occurs.  These include changing the lineitem
price, adding/removing a direct charge, and adding/removing copies via
the copy grid.

Note that adding/removing copies via the batch-updater alread causes a
page refresh, which updates the summary amounts.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm
Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/js/ui/default/acq/po/item_table.js
Open-ILS/web/js/ui/default/acq/po/view_po.js

index 92dca62..5d74b11 100644 (file)
@@ -821,6 +821,7 @@ __PACKAGE__->register_method(
         method    => 'retrieve_purchase_order',
         api_name  => 'open-ils.acq.purchase_order.retrieve',
         stream    => 1,
+        authoritative => 1,
         signature => {
                       desc      => 'Retrieves a purchase order',
                       params    => [
index a94d403..bf4e4e3 100644 (file)
@@ -1489,6 +1489,7 @@ function AcqLiTable() {
                         var allSet = true;
                         dojo.forEach(priceNodes, function(node) { if (node.value == '') allSet = false});
                         if (allSet) checkCouldActivatePo();
+                        refreshPOSummaryAmounts();
                     }
                 }
             }
@@ -2737,6 +2738,7 @@ function AcqLiTable() {
                     oncomplete: function() {
                         self.drawCopies(liId, true /* force_fetch */);
                         openils.Util.hide("acq-lit-update-copies-progress");
+                        refreshPOSummaryAmounts();
                     }
                 }
             );
index 8752e34..909f7ce 100644 (file)
@@ -93,6 +93,7 @@ function PoItemTable() {
 
                     virtIds.forEach(function(k) { self.deleteRow(k); });
                     objs.forEach(function(o) { self.addItem(o); });
+                    refreshPOSummaryAmounts();
                 }
             }
         );
@@ -118,6 +119,7 @@ function PoItemTable() {
                         progressDialog.hide();
                         r = openils.Util.readResponse(r); /* may not use */
                         if (r == '1') {
+                            refreshPOSummaryAmounts();
                             self._deleteRow(id);
                         } 
                     }
index 9d463aa..dbe7705 100644 (file)
@@ -300,6 +300,33 @@ function prepareInvoiceFeatures() {
     openils.Util.show("acq-po-invoice-stuff", "table-cell");
 }
 
+function setSummaryAmounts() {
+    dojo.byId("acq-po-view-total-enc").innerHTML = PO.amount_encumbered().toFixed(2);
+    dojo.byId("acq-po-view-total-spent").innerHTML = PO.amount_spent().toFixed(2);
+    dojo.byId("acq-po-view-total-estimated").innerHTML = PO.amount_estimated().toFixed(2);
+}
+
+function refreshPOSummaryAmounts() {
+    fieldmapper.standardRequest(
+        ['open-ils.acq', 
+            'open-ils.acq.purchase_order.retrieve.authoritative'],
+        {   async: true,
+            params: [openils.User.authtoken, poId, {
+                "flesh_price_summary": true
+            }],
+            oncomplete: function(r) {
+                // update the global PO instead of replacing it, since other 
+                // code outside our control may be referencing it.
+                var po = openils.Util.readResponse(r);
+                PO.amount_encumbered(po.amount_encumbered());
+                PO.amount_spent(po.amount_spent());
+                PO.amount_estimated(po.amount_estimated());
+                setSummaryAmounts();
+            }
+        }
+    );
+}
+
 /* renderPo() is the best place to add tests that depend on PO-state
  * (or simple ordered-or-not? checks) to enable/disable UI elements
  * across the whole interface. */
@@ -311,10 +338,9 @@ function renderPo() {
         dojo.byId("acq-po-view-provider"),
         PO.provider()
     );
+
+    setSummaryAmounts();
     dojo.byId("acq-po-view-total-li").innerHTML = PO.lineitem_count();
-    dojo.byId("acq-po-view-total-enc").innerHTML = PO.amount_encumbered().toFixed(2);
-    dojo.byId("acq-po-view-total-spent").innerHTML = PO.amount_spent().toFixed(2);
-    dojo.byId("acq-po-view-total-estimated").innerHTML = PO.amount_estimated().toFixed(2);
     dojo.byId("acq-po-view-state").innerHTML = po_state; // TODO i18n
 
     if(PO.order_date()) {