convert to USD

This commit is contained in:
Paul Trowbridge 2023-11-13 12:25:41 -05:00
parent b81261af3f
commit 15c60c629d
2 changed files with 23 additions and 8 deletions

View File

@ -6,19 +6,21 @@ export function apply_guidance(doc: any) {
const bridgePremium = doc.pricing?.bridgePremium ?? 1.00000; const bridgePremium = doc.pricing?.bridgePremium ?? 1.00000;
const altHist = doc.hist?.cust?.ds; const altHist = doc.hist?.cust?.ds;
const iidx = doc.pricing?.iidx; const iidx = doc.pricing?.iidx;
const list = doc.pricing?.list;
const curr = doc.customer?.curr; const curr = doc.customer?.curr;
const fxrate = doc.customer?.fxrate; const fxrate = doc.customer?.fxrate ?? 1.0;
let anchorPrice = null; let anchorPrice = null;
let anchorSource = null; let anchorSource = null;
let custPrice = null; let custPrice = null;
let custSource = null; let custSource = null;
let guidance = {}; let guidance = {};
let calcCeiling = null; let calcCeiling = null;
let finalReasonUSD = "";
let finalPriceUSD = null;
let finalReason = ""; let finalReason = "";
let finalPrice = null; let finalPrice = null;
const inflation = Math.max(...Object.keys(iidx).map(Number)); const inflation = Math.max(...Object.keys(iidx).map(Number));
const inflationFactor = iidx[inflation] + 1; const inflationFactor = iidx[inflation] + 1;
const list = doc.pricing?.list && doc.product?.itemrel === 1 ? doc.pricing?.list : null;
// ------if there is not target price just exit--------------- // ------if there is not target price just exit---------------
if (!targetPrice) { if (!targetPrice) {
anchorSource = "No target pricing setup"; anchorSource = "No target pricing setup";
@ -47,23 +49,36 @@ export function apply_guidance(doc: any) {
anchorSource = `Target Price ${targetPrice}`; anchorSource = `Target Price ${targetPrice}`;
} }
//------get the most relevant inflation factor number--------------------------------- //------get the most relevant inflation factor number---------------------------------
//------extract the inflation factor using the relevance key-------------------------- //------anchor x inflation / fxrate---------------------------------------------------
let calcPrice = parseFloat((anchorPrice * inflationFactor).toFixed(5)); let calcPriceUSD = parseFloat((anchorPrice * inflationFactor).toFixed(5));
let calcPrice = parseFloat((calcPriceUSD / fxrate).toFixed(5));
if (calcPrice >= list && list) { if (calcPrice >= list && list) {
calcCeiling = "Cap At List"; calcCeiling = "Cap At List";
finalPrice = doc.list; //multiply list by FX to get to USD if in CAD
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice} but cap at list ${list}`; finalPrice = list;
if (curr === "CA") {
finalReason = `${anchorSource} x ${inflationFactor} / ${fxrate} FX = ${calcPrice} CAD, cap at list ${list} CAD`;
} else {
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice}, cap at list ${list}`;
}
} else { } else {
finalPrice = calcPrice; finalPrice = calcPrice;
finalPriceUSD = calcPriceUSD;
if (curr === "CA") {
finalReason = `${anchorSource} x ${inflationFactor} / ${fxrate} FX = ${calcPrice} CAD`;
} else {
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice}`; finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice}`;
} }
} }
}
guidance.AnchorPrice = anchorPrice; guidance.AnchorPrice = anchorPrice;
guidance.AnchorSource = anchorSource; guidance.AnchorSource = anchorSource;
guidance.CustAnchorPrice = custPrice; guidance.CustAnchorPrice = custPrice;
guidance.CustAnchorSource = custSource; guidance.CustAnchorSource = custSource;
guidance.InflationFactor = inflationFactor; guidance.InflationFactor = inflationFactor;
guidance.Ceiling = calcCeiling; guidance.Ceiling = calcCeiling;
guidance.FinalPriceUSD = finalPriceUSD;
guidance.FinalReasonUSD = finalReasonUSD;
guidance.FinalPrice = finalPrice; guidance.FinalPrice = finalPrice;
guidance.FinalReason = finalReason; guidance.FinalReason = finalReason;
guidance.BridgePremium = bridgePremium; guidance.BridgePremium = bridgePremium;