diff --git a/apply_guidance.ts b/apply_guidance.ts index dbd383e..a39ad26 100644 --- a/apply_guidance.ts +++ b/apply_guidance.ts @@ -119,7 +119,7 @@ export function apply_guidance(doc: any) { const targetPrice = doc.v1tp ?? doc.v0tp; - const earlyPrice = doc.hist.cust.early_price; + const earlyPrice = doc.hist?.cust?.early_price; let anchorPrice = null; let anchorSource = null; let bridgePremium = doc.bridgePremium ?? 1.00000; @@ -127,6 +127,7 @@ export function apply_guidance(doc: any) { if (earlyPrice) { // translate alternate product history to current product quoted anchorPrice = Number((earlyPrice * bridgePremium).toFixed(5)); + // after the early price is translated see if target is still less if (targetPrice < anchorPrice) { anchorSource = 'Target Price'; anchorPrice = targetPrice; @@ -137,15 +138,12 @@ export function apply_guidance(doc: any) { anchorPrice = doc.targetPrice; anchorSource = 'Target Price'; } - doc.anchorSource = anchorSource; const inflation = Math.max(...Object.keys(doc.iidx).map(Number)); const inflationFactor = doc.iidx[inflation] + 1; - doc.inflationFactor = inflationFactor; - var calcPrice = anchorPrice * doc.inflationFactor; - calcPrice = parseFloat(calcPrice.toFixed(5)); + var calcPrice = parseFloat((anchorPrice * inflationFactor).toFixed(5)); let finalReason = ""; - if (calcPrice >= doc.list) { + if (calcPrice >= doc.list && doc.list) { doc.calcCeiling = "Cap At List"; doc.finalPrice = doc.list; finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice} but cap at list ${doc.list}`; @@ -153,6 +151,8 @@ export function apply_guidance(doc: any) { doc.finalPrice = calcPrice; finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice}`; } + doc.anchorSource = anchorSource; + doc.inflationFactor = inflationFactor; doc.finalReason = finalReason; return doc;