convert to USD
This commit is contained in:
parent
b81261af3f
commit
15c60c629d
@ -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,15 +49,26 @@ 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;
|
||||||
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;
|
guidance.AnchorPrice = anchorPrice;
|
||||||
@ -64,6 +77,8 @@ export function apply_guidance(doc: any) {
|
|||||||
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;
|
||||||
|
@ -99,7 +99,7 @@ BEGIN
|
|||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'mold',_mold
|
'mold',_mold
|
||||||
,'item',_item
|
,'item',_item
|
||||||
,'item rel',_itemr
|
,'itemrel',_itemr
|
||||||
,'iidx',_iidx
|
,'iidx',_iidx
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user