vault backup: 2023-11-16 10:25:41
This commit is contained in:
parent
52e802b389
commit
56d139c22d
@ -14,8 +14,34 @@ export function apply_guidance(doc: any) {
|
||||
return match ? match.adj : null;
|
||||
}
|
||||
|
||||
function minExcludingNull(...values) {
|
||||
return values.reduce((min, val) => (val !== null && (min === null || val < min) ? val : min), null);
|
||||
function lowestPrice(priceObject) {
|
||||
let Price = Infinity;
|
||||
let Reason = '';
|
||||
let Source = '';
|
||||
let Snapped = Infinity;
|
||||
|
||||
// Iterate over each property in the object
|
||||
for (let key in priceObject) {
|
||||
if (priceObject.hasOwnProperty(key) && key !== "mark") {
|
||||
let [cprice, creason, csource, csnap] = priceObject[key];
|
||||
// Check if the current price is lower than the found so far
|
||||
if (cprice && cprice < Price) {
|
||||
Price = cprice;
|
||||
Reason = creason;
|
||||
Source = csource;
|
||||
Snapped = csnap;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {Reason, Price, Source, Snapped};
|
||||
}
|
||||
|
||||
function ceiling(value, significance) {
|
||||
return Math.ceil(value / significance) * significance;
|
||||
}
|
||||
|
||||
function pp(value) {
|
||||
return (value * 1000).toFixed(2);
|
||||
}
|
||||
|
||||
// --------------------extract incoming data------------------------------------------------------
|
||||
@ -23,8 +49,8 @@ export function apply_guidance(doc: any) {
|
||||
const priceBand = doc.pricing?.v1stdv ?? doc.pricing?.v0stdv;
|
||||
const earlyCustPrice = doc.hist?.cust?.early_price;
|
||||
const earlyCustSeason = doc.hist?.cust?.early_season;
|
||||
const earlyMarkPrice = doc.hist?.mark?.early_price;
|
||||
const earlyMarkSeason = doc.hist?.mark?.early_season;
|
||||
const earlyMarkPrice = doc.hist?.market?.early_price;
|
||||
const earlyMarkSeason = doc.hist?.market?.early_season;
|
||||
const bridgePremium = doc.pricing?.bridgePremium;
|
||||
const bridgedPrice = Number((earlyCustPrice * (bridgePremium ?? 1.00)).toFixed(5));
|
||||
const altHist = doc.hist?.cust?.ds;
|
||||
@ -42,94 +68,42 @@ export function apply_guidance(doc: any) {
|
||||
let ltp = qty < pltq ? 0.15 : null;
|
||||
let anchor_sd = priceBand ? ((bridgedPrice - targetPrice) / priceBand).toFixed(2) : 0
|
||||
let optimization = getAdjValue(anchor_sd);
|
||||
let inflReason = inflationFactor !== 0 ? ` +${(inflationFactor *100).toFixed(1)}%`: "";
|
||||
let ltpReason = ltp ? ` +${(ltp * 100).toFixed(1))}%` : "";
|
||||
let optReason = optimization !== 0 ? ` +${(inflationFactor *100).toFixed(1)}%`: "";
|
||||
let custAdder = (ltp ?? 0) + optimization + inflationFactor;
|
||||
let markAdder = (ltp ?? 0) + inflationFactor;
|
||||
let inflReason = (inflationFactor ?? 0) !== 0 ? ` + ${(inflationFactor * 100).toFixed(1)}% infl`: "";
|
||||
let ltpReason = ltp ? ` + ${(ltp * 100).toFixed(1)}% ltp` : "";
|
||||
let optReason = (optimization ?? 0) !== 0 ? ` + ${(optimization * 100).toFixed(1)}% opt`: "";
|
||||
let custAddReason = `${inflReason}${ltpReason}${optReason}`;
|
||||
let markAddReason = `${inflReason}${ltpReason}`;
|
||||
|
||||
// ------------------start building price options------------------------------------------------
|
||||
|
||||
let custPrice = bridgedPrice * (1 + custAdder);
|
||||
let custSeason = earlySeason;
|
||||
let snap = .0005;
|
||||
|
||||
let custPrice = Number((bridgedPrice * (1 + custAdder)).toFixed(5));
|
||||
let custSeason = earlyCustSeason;
|
||||
let custReason = bridgePremium
|
||||
? `${custSeason} (similar + ${altHist} price ${earlyPrice} x ${bridgePremium} = ${custPrice}) + ${custAddReason}`
|
||||
: `${custSeason} + price ${custPrice} + ${custAddReason}`;
|
||||
let markReason = `${markSeason} ASP + ${markPrice} + ${markAddReason}`;
|
||||
? `${custSeason} (similar ${altHist} price ${pp(earlyCustPrice)} x ${bridgePremium} = ${pp(bridgedPrice)})${custAddReason}`
|
||||
: `${custSeason} + price ${pp(custPrice)}${custAddReason}`;
|
||||
let markPrice = earlyMarkPrice * (1 + markAdder);
|
||||
let markReason = `${earlyMarkSeason} ASP + ${pp(earlyMarkPrice)}${markAddReason}`;
|
||||
let targPrice = targetPrice * (1 + markAdder);
|
||||
let targReason = `Target price ${targetPrice} + ${markAddReason}`;
|
||||
let targReason = `Target price ${pp(targetPrice)}${markAddReason}`;
|
||||
let listPrice = listUSD;
|
||||
let listReason = "";
|
||||
|
||||
let price = {
|
||||
cust: [custPrice, custReason],
|
||||
mark: [markPrice, markReason],
|
||||
targ: [targPrice, targReason]
|
||||
let prices = {
|
||||
cust: [custPrice, custReason, "cust", ceiling(custPrice,snap)],
|
||||
mark: [markPrice, markReason, "mark", ceiling(markPrice,snap)],
|
||||
targ: [targPrice, targReason, "targ", ceiling(targPrice,snap)],
|
||||
list: [listPrice, listReason, "list", ceiling(listPrice,snap)]
|
||||
}
|
||||
|
||||
let finalPrice = minExcludingNull(listUSD,custPrice,targPrice);
|
||||
|
||||
// ------if there is not target price just exit---------------
|
||||
if (!targetPrice) {
|
||||
anchorSource = "No target pricing setup";
|
||||
guidance.FinalReason = "No target pricing setup";
|
||||
} else {
|
||||
// if there is no customer anchor price use target
|
||||
if (earlyCustPrice) {
|
||||
// translate alternate product history to current product quoted
|
||||
// --------if the price needs bridged, add the details to the description--------
|
||||
if (bridgePremium === 1) {
|
||||
anchorSource = earlySeason + ' Price ' + earlyPrice;
|
||||
custSource = anchorSource;
|
||||
} else {
|
||||
anchorSource = earlySeason + ' Similar (' + altHist + ') Price ' + earlyPrice + ' x ' + bridgePremium + ' = ' + anchorPrice;
|
||||
custSource = anchorSource;
|
||||
}
|
||||
// --------after the early price is translated see if target is still less-------
|
||||
if (targetPrice < anchorPrice) {
|
||||
anchorSource = `Target Price ${targetPrice}`;
|
||||
anchorPrice = targetPrice;
|
||||
}
|
||||
} else {
|
||||
anchorPrice = targetPrice;
|
||||
anchorSource = `Target Price ${targetPrice}`;
|
||||
}
|
||||
//------get the most relevant inflation factor number---------------------------------
|
||||
//------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";
|
||||
//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;
|
||||
finalPriceUSD = calcPriceUSD;
|
||||
if (curr === "CA") {
|
||||
finalReason = `${anchorSource} x ${inflationFactor} / ${fxrate} FX = ${calcPrice} CAD`;
|
||||
} else {
|
||||
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice}`;
|
||||
}
|
||||
}
|
||||
let finalPrice = lowestPrice(prices);
|
||||
let guidance = {
|
||||
prices
|
||||
,finalPrice
|
||||
}
|
||||
guidance.AnchorPrice = anchorPrice;
|
||||
guidance.AnchorSource = anchorSource;
|
||||
guidance.CustAnchorPrice = custPrice;
|
||||
guidance.CustAnchorSource = custSource;
|
||||
guidance.InflationFactor = inflationFactor;
|
||||
guidance.Ceiling = calcCeiling;
|
||||
guidance.FinalPriceUSD = finalPriceUSD;
|
||||
guidance.FinalReasonUSD = finalReasonUSD;
|
||||
guidance.FinalPrice = finalPrice;
|
||||
guidance.FinalReason = finalReason;
|
||||
guidance.BridgePremium = bridgePremium;
|
||||
guidance.TargetPrice = targetPrice;
|
||||
guidance.ListPrice = list;
|
||||
doc.guidance = guidance;
|
||||
return doc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user