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;
}
//let custPrice null;
//let custReason null;
//let cvolPrice null;
//let cvolReason null;
//let markPrice null;
//let markReason null;
//let targPrice null;
//let targReason null;
function minExcludingNull(...values) {
return values.reduce((min, val) => (val !== null && (min === null || val < min) ? val : min), null);
}
const targetPrice = doc.pricing?.v1tp ?? doc.pricing?.v0tp;
const priceBand = doc.pricing?.v1stdv ?? doc.pricing?.v0stdv;
const earlyPrice = doc.hist?.cust?.early_price;
const earlySeason = doc.hist?.cust?.early_season;
const bridgePremium = doc.pricing?.bridgePremium ?? 1.00000;
const altHist = doc.hist?.cust?.ds;
const iidx = doc.pricing?.iidx;
const curr = doc.customer?.curr;
const fxrate = doc.customer?.fxrate ?? 1.0;
const qty = doc.inputs?.qty;
const pltq = doc.product?.pltq;
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;
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;
// --------------------extract incoming data------------------------------------------------------
const targetPrice = doc.pricing?.v1tp ?? doc.pricing?.v0tp;
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 bridgePremium = doc.pricing?.bridgePremium;
const bridgedPrice = Number((earlyCustPrice * (bridgePremium ?? 1.00)).toFixed(5));
const altHist = doc.hist?.cust?.ds;
const iidx = doc.pricing?.iidx;
const curr = doc.customer?.curr;
const fxrate = doc.customer?.fxrate ?? 1.0;
const qty = doc.inputs?.qty;
const pltq = doc.product?.pltq;
const inflation = Math.max(...Object.keys(iidx).map(Number));
const inflationFactor = iidx[inflation];
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
const listUSD = list ? list / fxrate :null;
//-------set basic customer pricing--------------
custPrice = Number((earlyPrice * bridgePremium).toFixed(5));
anchorPrice = custPrice;
let anchor_sd = priceBand ? ((anchorPrice - targetPrice) / priceBand).toFixed(2) : 0
let optimization = getAdjValue(anchor_sd);
// ------------------calculate price adders------------------------------------------------------
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 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 (!targetPrice) {
@ -63,7 +69,7 @@ export function apply_guidance(doc: any) {
guidance.FinalReason = "No target pricing setup";
} else {
// if there is no customer anchor price use target
if (earlyPrice) {
if (earlyCustPrice) {
// translate alternate product history to current product quoted
// --------if the price needs bridged, add the details to the description--------
if (bridgePremium === 1) {

View File

@ -110,7 +110,7 @@ FROM
,('customer v0ds other',7)
,('customer v0ds vol' ,3)
,('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 v0ds other' ,9)
,('market v0ds vol' ,5)

View File

@ -104,7 +104,7 @@ FROM
,('customer v0ds other',7)
,('customer v0ds vol' ,3)
,('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 v0ds other' ,9)
,('market v0ds vol' ,5)