Compare commits

..

No commits in common. "e3c1367e518e44b55eed7d5dc59b1702a235b6e7" and "1250c671e77ab1ac2c820c7457330013409d5ac6" have entirely different histories.

3 changed files with 22 additions and 24 deletions

View File

@ -118,40 +118,43 @@ export function apply_guidance(doc: any) {
//} //}
const targetPrice = doc.v1tp ?? doc.v0tp; doc.targetPrice = doc.v1tp ?? doc.v0tp;
const earlyPrice = doc.hist.cust.early_price;
let anchorPrice = null;
let anchorSource = null;
let bridgePremium = doc.bridgePremium ?? 1.00000;
// Determine the anchor price and source // Determine the anchor price and source
if (earlyPrice) { if (doc.hist.cust?.early_price !== undefined ) {
// translate alternate product history to current product quoted if (doc.hist.cust.relevance !== 'customer exact') {
anchorPrice = Number((earlyPrice * bridgePremium).toFixed(5)); doc.anchorPrice = Number((doc.hist.cust.early_price * doc.bridgePremium).toFixed(5));
if (targetPrice < anchorPrice) { if (doc.targetPrice < doc.anchorPrice) {
anchorSource = 'Target Price'; doc.anchorPrice = doc.targetPrice;
anchorPrice = 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 { } else {
anchorSource = doc.hist.cust.early_season + ' Similar (' + doc.hist.cust.ds + ') Customer Price ' + earlyPrice + ' x ' + doc.bridgePremium + ' = ' + anchorPrice; doc.anchorPrice = doc.hist.cust.early_price;
doc.anchorSource = doc.hist.cust.early_season + ' Customer Price ' + doc.hist.cust.early_price;
} }
} else { } else {
anchorPrice = doc.targetPrice; doc.anchorPrice = doc.targetPrice;
anchorSource = 'Target Price'; doc.anchorSource = 'Target Price';
} }
doc.anchorSource = anchorSource;
const inflation = Math.max(...Object.keys(doc.iidx).map(Number)); const inflation = Math.max(...Object.keys(doc.iidx).map(Number));
const inflationFactor = doc.iidx[inflation] + 1; const inflationFactor = doc.iidx[inflation] + 1;
doc.inflationFactor = inflationFactor; doc.inflationFactor = inflationFactor;
var calcPrice = anchorPrice * doc.inflationFactor; var calcPrice = doc.anchorPrice * doc.inflationFactor;
calcPrice = parseFloat(calcPrice.toFixed(5)); calcPrice = parseFloat(calcPrice.toFixed(5));
let finalReason = ""; let finalReason = "";
if (calcPrice >= doc.list) { if (calcPrice >= doc.list) {
doc.calcCeiling = "Cap At List"; doc.calcCeiling = "Cap At List";
doc.finalPrice = doc.list; doc.finalPrice = doc.list;
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice} but cap at list ${doc.list}`; finalReason = `${doc.anchorSource} x ${inflationFactor} = ${calcPrice} but cap at list ${doc.list}`;
} else { } else {
doc.finalPrice = calcPrice; doc.finalPrice = calcPrice;
finalReason = `${anchorSource} x ${inflationFactor} = ${calcPrice}`; finalReason = `${doc.anchorSource} x ${inflationFactor} = ${calcPrice}`;
} }
doc.finalReason = finalReason; doc.finalReason = finalReason;

View File

@ -1,5 +0,0 @@
SELECT
rlarp.get_guidance(lq.billto, lq.shipto, lq.part, lq.units_each, 2024)
FROM
pricequote.live_quotes lq
LIMIT 100

View File

@ -133,7 +133,7 @@ BEGIN
--RAISE NOTICE 'list: %', jsonb_pretty(_list); --RAISE NOTICE 'list: %', jsonb_pretty(_list);
----------------get premium for quote hist gap-------------- ----------------get premium for quote hist gap--------------
SELECT coalesce(rlarp.get_premium(_stlc, _seas, (SELECT xchan FROM _chx WHERE chan = _chan),_rslt->'hist'->'cust'->>'ds', _v1ds),'{}'::jsonb) INTO _prem; SELECT coalesce(rlarp.get_premium(_stlc, _seas, (SELECT xchan FROM _chx WHERE chan = _chan),_v1ds, ((_rslt->'mostRelevantCustomerPriceInfo')->'source')->>'v1ds'),'{}'::jsonb) INTO _prem;
_rslt := _rslt||_prem; _rslt := _rslt||_prem;
--RAISE NOTICE 'list: %', jsonb_pretty(_list); --RAISE NOTICE 'list: %', jsonb_pretty(_list);