JBAS-231 blanket PO local template cross-ports
authorBill Erickson <berickxx@gmail.com>
Mon, 20 Apr 2015 21:21:43 +0000 (17:21 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Port blanket PO changes to local templates and scripts.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/openils/var/templates_kcls/acq/po/view.tt2
Open-ILS/web/js/ui/kcls/acq/common/li_table.js
Open-ILS/web/js/ui/kcls/acq/po/view_po.js

index 9e15172..ce58e62 100644 (file)
                                 [% l('Activate Without Loading Items') %]
                             </span>
                         </span>
+                        <span class="hidden" id="acq-po-finalize-links" style='padding: 5px'>
+                            <span dojoType="dijit.form.Button" onClick="finalizePo()" jsId="finalizePoButton">
+                                [% l('Finalize Blanket Order') %]
+                            </span>
+                        </span>
                     </td>
                 </tr>
                 <tr>
index a983a37..187cd2d 100644 (file)
@@ -1409,6 +1409,7 @@ function AcqLiTable() {
                         var allSet = true;
                         dojo.forEach(priceNodes, function(node) { if (node.value == '') allSet = false});
                         if (allSet) checkCouldActivatePo();
+                        refreshPOSummaryAmounts();
                     }
                 }
             }
@@ -2648,6 +2649,7 @@ function AcqLiTable() {
                     oncomplete: function() {
                         self.drawCopies(liId, true /* force_fetch */);
                         openils.Util.hide("acq-lit-update-copies-progress");
+                        refreshPOSummaryAmounts();
                     }
                 }
             );
index e8ea814..5a67e8f 100644 (file)
@@ -299,6 +299,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. */
@@ -310,9 +337,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-state").innerHTML = po_state; // TODO i18n
 
     if(PO.order_date()) {
@@ -368,6 +395,7 @@ function renderPo() {
     } else {
         if (PO.order_date()) {
             dojo.byId("acq-po-activate-checking").innerHTML = localeStrings.PO_ALREADY_ACTIVATED;
+            checkCouldBlanketFinalize();
         } else {
             dojo.byId("acq-po-activate-checking").innerHTML = localeStrings.NO;
         }
@@ -448,7 +476,6 @@ function init() {
 
 function init2() {
 
-    var totalEstimated = 0;
     var zeroLi = true;
     fieldmapper.standardRequest(
         ['open-ils.acq', 'open-ils.acq.lineitem.search'],
@@ -462,13 +489,10 @@ function init2() {
                 zeroLi = false;
                 liTable.show('list');
                 var li = openils.Util.readResponse(r);
-                // TODO: Add po_item's to total estimated amount
-                totalEstimated += (Number(li.item_count() || 0) * Number(li.estimated_unit_price() || 0));
                 liTable.addLineitem(li);
             },
 
             oncomplete : function() {
-                dojo.byId("acq-po-view-total-estimated").innerHTML = totalEstimated.toFixed(2);
                 if (liFocus) liTable.drawCopies(liFocus);
                 if(zeroLi) openils.Util.show('acq-po-no-lineitems');
             }
@@ -495,6 +519,30 @@ function init2() {
     );
 }
 
+function checkCouldBlanketFinalize() {
+
+    if (PO.state() == 'received') return;
+
+    var inv_types = [];
+
+    // get the unique set of invoice item type IDs
+    PO.po_items().forEach(function(item) { 
+        if (inv_types.indexOf(item.inv_item_type()) == -1)
+            inv_types.push(item.inv_item_type());
+    });
+
+    if (inv_types.length == 0) return;
+
+    pcrud.search('aiit', 
+        {code : inv_types, blanket : 't'}, {
+        oncomplete : function(r) {
+            r = openils.Util.readResponse(r);
+            if (r.length == 0) return;
+            openils.Util.show(dojo.byId('acq-po-finalize-links'), 'inline');
+        }
+    });
+}
+
 function checkCouldActivatePo() {
     var d = dojo.byId("acq-po-activate-checking");
     var a = dojo.byId("acq-po-activate-links");  /* <span> not <a> now, but no diff */
@@ -583,6 +631,24 @@ function checkCouldActivatePo() {
     );
 }
 
+function finalizePo() {
+
+    if (!confirm(localeStrings.FINALIZE_PO)) return;
+
+    finalizePoButton.attr('disabled', true);
+
+    fieldmapper.standardRequest(
+        ['open-ils.acq', 'open-ils.acq.purchase_order.blanket.finalize'],
+        {   async : true,
+            params : [openils.User.authtoken, PO.id()],
+            oncomplete : function(r) {
+                if (openils.Util.readResponse(r) == 1) 
+                    location.href = location.href;
+            }
+        }
+    );
+}
+
 function activatePo(argument) {
     activatePoButton.attr("disabled", true);
     activatePoNoAssetsButton.attr("disabled", true);