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. */
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()) {
} 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;
}
function init2() {
- var totalEstimated = 0;
var zeroLi = true;
fieldmapper.standardRequest(
['open-ils.acq', 'open-ils.acq.lineitem.search'],
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');
}
);
}
+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 */
);
}
+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);