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 altHist = doc.hist?.cust?.ds;
const iidx = doc.pricing?.iidx;
const list = doc.pricing?.list;
const curr = doc.customer?.curr;
const fxrate = doc.customer?.fxrate;
const fxrate = doc.customer?.fxrate ?? 1.0;
let anchorPrice = null;
let anchorSource = null;
let custPrice = null;
let custSource = null;
let guidance = {};
let calcCeiling = null;
let finalReasonUSD = "";
let finalPriceUSD = null;
let finalReason = "";
let finalPrice = null;
const inflation = Math.max(...Object.keys(iidx).map(Number));
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 (!targetPrice) {
anchorSource = "No target pricing setup";
@ -47,15 +49,26 @@ export function apply_guidance(doc: any) {
anchorSource = `Target Price ${targetPrice}`;
}
//------get the most relevant inflation factor number---------------------------------
//------extract the inflation factor using the relevance key--------------------------
let calcPrice = parseFloat((anchorPrice * inflationFactor).toFixed(5));
//------anchor x inflation / fxrate---------------------------------------------------
let calcPriceUSD = parseFloat((anchorPrice * inflationFactor).toFixed(5));
let calcPrice = parseFloat((calcPriceUSD / fxrate).toFixed(5));
if (calcPrice >= list && list) {
calcCeiling = "Cap At List";
finalPrice = doc.list;
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice} but cap at list ${list}`;
//multiply list by FX to get to USD if in CAD
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 {
finalPrice = calcPrice;
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice}`;
finalPriceUSD = calcPriceUSD;
if (curr === "CA") {
finalReason = `${anchorSource} x ${inflationFactor} / ${fxrate} FX = ${calcPrice} CAD`;
} else {
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice}`;
}
}
}
guidance.AnchorPrice = anchorPrice;
@ -64,6 +77,8 @@ export function apply_guidance(doc: any) {
guidance.CustAnchorSource = custSource;
guidance.InflationFactor = inflationFactor;
guidance.Ceiling = calcCeiling;
guidance.FinalPriceUSD = finalPriceUSD;
guidance.FinalReasonUSD = finalReasonUSD;
guidance.FinalPrice = finalPrice;
guidance.FinalReason = finalReason;
guidance.BridgePremium = bridgePremium;

View File

@ -99,7 +99,7 @@ BEGIN
jsonb_build_object(
'mold',_mold
,'item',_item
,'item rel',_itemr
,'itemrel',_itemr
,'iidx',_iidx
)
);