From 1250c671e77ab1ac2c820c7457330013409d5ac6 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 10 Nov 2023 02:59:19 -0500 Subject: [PATCH] vault backup: 2023-11-10 02:59:19 --- apply_guidance.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/apply_guidance.ts b/apply_guidance.ts index feed6e4..caa3d87 100644 --- a/apply_guidance.ts +++ b/apply_guidance.ts @@ -117,23 +117,29 @@ export function apply_guidance(doc: any) { // }; //} - - doc.targetPrice = doc.v1tp ?? doc.v0tp ?? null; + + doc.targetPrice = doc.v1tp ?? doc.v0tp; // Determine the anchor price and source - if (doc.targetPrice !== undefined && (doc.hist.cust.early_price === undefined || doc.targetPrice < doc.hist.cust.early_price)) { - doc.anchorPrice = doc.targetPrice; - doc.anchorSource = 'Target Price'; - } else if (doc.hist.cust.early_price !== undefined) { + if (doc.hist.cust?.early_price !== undefined ) { if (doc.hist.cust.relevance !== 'customer exact') { - doc.anchorPrice = doc.hist.cust.early_price * doc.bridgePremium; - doc.anchorSource = doc.hist.cust.early_season + ' Similar (' + doc.hist.cust.ds + ') Customer Price ' + doc.hist.cust.early_price + ' x ' + doc.bridgePremium + ' = ' + doc.anchorPrice; + doc.anchorPrice = Number((doc.hist.cust.early_price * doc.bridgePremium).toFixed(5)); + if (doc.targetPrice < doc.anchorPrice) { + doc.anchorPrice = doc.targetPrice; + doc.anchorSource = 'Target Price' + } else { + doc.anchorSource = doc.hist.cust.early_season + ' Similar (' + doc.hist.cust.ds + ') Customer Price ' + doc.hist.cust.early_price + ' x ' + doc.bridgePremium + ' = ' + doc.anchorPrice; + if (doc.targetPrice < doc.anchorPrice) { + doc.anchorSource = 'Target Price'; + doc.anchorPrice = doc.targetPrice; + } + } } else { doc.anchorPrice = doc.hist.cust.early_price; doc.anchorSource = doc.hist.cust.early_season + ' Customer Price ' + doc.hist.cust.early_price; } } else { - doc.anchorPrice = null; - doc.anchorSource = 'none'; // or any other default value you wish to indicate no anchor price was found + doc.anchorPrice = doc.targetPrice; + doc.anchorSource = 'Target Price'; } const inflation = Math.max(...Object.keys(doc.iidx).map(Number)); @@ -145,10 +151,10 @@ export function apply_guidance(doc: any) { if (calcPrice >= doc.list) { doc.calcCeiling = "Cap At List"; doc.finalPrice = doc.list; - finalReason = `${doc.anchorSource} ${doc.anchorPrice} x ${inflationFactor} = ${calcPrice} but cap at list ${doc.list}`; + finalReason = `${doc.anchorSource} x ${inflationFactor} = ${calcPrice} but cap at list ${doc.list}`; } else { doc.finalPrice = calcPrice; - finalReason = `${doc.anchorSource} ${doc.anchorPrice} x ${inflationFactor} = ${calcPrice}`; + finalReason = `${doc.anchorSource} x ${inflationFactor} = ${calcPrice}`; } doc.finalReason = finalReason;