From a91a15dd524ecee20e967120cd9c7393a455888a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 6 Apr 2015 17:33:26 -0400 Subject: [PATCH] LP#1380803 Update PO summary amounts 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 Signed-off-by: Kathy Lussier --- .../lib/OpenILS/Application/Acq/Financials.pm | 1 + .../web/js/ui/default/acq/common/li_table.js | 2 ++ .../web/js/ui/default/acq/po/item_table.js | 2 ++ Open-ILS/web/js/ui/default/acq/po/view_po.js | 32 +++++++++++++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm index 92dca62920..5d74b11ce3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm @@ -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 => [ 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 a94d403ef8..bf4e4e3eee 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 @@ -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(); } } ); diff --git a/Open-ILS/web/js/ui/default/acq/po/item_table.js b/Open-ILS/web/js/ui/default/acq/po/item_table.js index 8752e34999..909f7ced3e 100644 --- a/Open-ILS/web/js/ui/default/acq/po/item_table.js +++ b/Open-ILS/web/js/ui/default/acq/po/item_table.js @@ -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); } } diff --git a/Open-ILS/web/js/ui/default/acq/po/view_po.js b/Open-ILS/web/js/ui/default/acq/po/view_po.js index 9d463aa982..dbe7705f7a 100644 --- a/Open-ILS/web/js/ui/default/acq/po/view_po.js +++ b/Open-ILS/web/js/ui/default/acq/po/view_po.js @@ -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()) { -- 2.43.2