work on simplifying and condensing logic

This commit is contained in:
Paul Trowbridge 2023-11-15 16:57:21 -05:00
parent 32217d52c4
commit dc1f493700
3 changed files with 48 additions and 42 deletions

View File

@ -14,48 +14,54 @@ export function apply_guidance(doc: any) {
return match ? match.adj : null; return match ? match.adj : null;
} }
//let custPrice null; function minExcludingNull(...values) {
//let custReason null; return values.reduce((min, val) => (val !== null && (min === null || val < min) ? val : min), null);
//let cvolPrice null; }
//let cvolReason null;
//let markPrice null;
//let markReason null;
//let targPrice null;
//let targReason null;
const targetPrice = doc.pricing?.v1tp ?? doc.pricing?.v0tp; // --------------------extract incoming data------------------------------------------------------
const priceBand = doc.pricing?.v1stdv ?? doc.pricing?.v0stdv; const targetPrice = doc.pricing?.v1tp ?? doc.pricing?.v0tp;
const earlyPrice = doc.hist?.cust?.early_price; const priceBand = doc.pricing?.v1stdv ?? doc.pricing?.v0stdv;
const earlySeason = doc.hist?.cust?.early_season; const earlyCustPrice = doc.hist?.cust?.early_price;
const bridgePremium = doc.pricing?.bridgePremium ?? 1.00000; const earlyCustSeason = doc.hist?.cust?.early_season;
const altHist = doc.hist?.cust?.ds; const earlyMarkPrice = doc.hist?.mark?.early_price;
const iidx = doc.pricing?.iidx; const earlyMarkSeason = doc.hist?.mark?.early_season;
const curr = doc.customer?.curr; const bridgePremium = doc.pricing?.bridgePremium;
const fxrate = doc.customer?.fxrate ?? 1.0; const bridgedPrice = Number((earlyCustPrice * (bridgePremium ?? 1.00)).toFixed(5));
const qty = doc.inputs?.qty; const altHist = doc.hist?.cust?.ds;
const pltq = doc.product?.pltq; const iidx = doc.pricing?.iidx;
let anchorPrice = null; const curr = doc.customer?.curr;
let anchorSource = null; const fxrate = doc.customer?.fxrate ?? 1.0;
let custPrice = null; const qty = doc.inputs?.qty;
let custSource = null; const pltq = doc.product?.pltq;
let guidance = {}; const inflation = Math.max(...Object.keys(iidx).map(Number));
let calcCeiling = null; const inflationFactor = iidx[inflation];
let finalReasonUSD = ""; const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
let finalPriceUSD = null; const listUSD = list ? list / fxrate :null;
let finalReason = "";
let finalPrice = null;
let ltp = qty < pltq ? 1.15 : null;
let increase = null;
const inflation = Math.max(...Object.keys(iidx).map(Number));
const inflationFactor = iidx[inflation] + 1;
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
//-------set basic customer pricing-------------- // ------------------calculate price adders------------------------------------------------------
custPrice = Number((earlyPrice * bridgePremium).toFixed(5)); let ltp = qty < pltq ? 0.15 : null;
anchorPrice = custPrice; let anchor_sd = priceBand ? ((bridgedPrice - targetPrice) / priceBand).toFixed(2) : 0
let anchor_sd = priceBand ? ((anchorPrice - targetPrice) / priceBand).toFixed(2) : 0 let optimization = getAdjValue(anchor_sd);
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 custAddReason = `${inflReason}${ltpReason}${optReason}`;
let markAddReason = `${inflReason}${ltpReason}`;
// ------------------start building price options------------------------------------------------
let custPrice = bridgedPrice * (1 + custAdder);
let custSeason = earlySeason;
let custReason = bridgePremium
? `${custSeason} (similar + ${altHist} price ${earlyPrice} x ${bridgePremium} = ${custPrice}) + ${custAddReason}`
: `${custSeason} + price ${custPrice} + ${custAddReason}`;
let markReason = `${markSeason} ASP + ${markPrice} + ${markAddReason}`;
let targPrice = targetPrice * (1 + markAdder);
let targReason = `Target price ${targetPrice} + ${markAddReason}`;
let finalPrice = minExcludingNull(listUSD,custPrice,targPrice);
// ------if there is not target price just exit--------------- // ------if there is not target price just exit---------------
if (!targetPrice) { if (!targetPrice) {
@ -63,7 +69,7 @@ export function apply_guidance(doc: any) {
guidance.FinalReason = "No target pricing setup"; guidance.FinalReason = "No target pricing setup";
} else { } else {
// if there is no customer anchor price use target // if there is no customer anchor price use target
if (earlyPrice) { if (earlyCustPrice) {
// translate alternate product history to current product quoted // translate alternate product history to current product quoted
// --------if the price needs bridged, add the details to the description-------- // --------if the price needs bridged, add the details to the description--------
if (bridgePremium === 1) { if (bridgePremium === 1) {

View File

@ -110,7 +110,7 @@ FROM
,('customer v0ds other',7) ,('customer v0ds other',7)
,('customer v0ds vol' ,3) ,('customer v0ds vol' ,3)
,('customer v1ds other',6) ,('customer v1ds other',6)
,('customer v1ds vol' ,2) ,('customer v1ds vol' ,2) --this will always sort to the top, v0ds will never sort to the top. you will always be getting the highest volume base price
,('market exact' ,4) ,('market exact' ,4)
,('market v0ds other' ,9) ,('market v0ds other' ,9)
,('market v0ds vol' ,5) ,('market v0ds vol' ,5)

View File

@ -104,7 +104,7 @@ FROM
,('customer v0ds other',7) ,('customer v0ds other',7)
,('customer v0ds vol' ,3) ,('customer v0ds vol' ,3)
,('customer v1ds other',6) ,('customer v1ds other',6)
,('customer v1ds vol' ,2) ,('customer v1ds vol' ,2) --this will always sort to the top, v0ds will never sort to the top. you will always be getting the highest volume base price
,('market exact' ,4) ,('market exact' ,4)
,('market v0ds other' ,9) ,('market v0ds other' ,9)
,('market v0ds vol' ,5) ,('market v0ds vol' ,5)