From b81261af3f0a7b5acb27c45c44ee52753904f047 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 13 Nov 2023 11:45:47 -0500 Subject: [PATCH] fix bridge pricing --- apply_guidance.ts | 9 ++++++++- sql/get_guidance_dseg.pg.sql | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apply_guidance.ts b/apply_guidance.ts index ed8e24d..72bd348 100644 --- a/apply_guidance.ts +++ b/apply_guidance.ts @@ -11,6 +11,8 @@ export function apply_guidance(doc: any) { const fxrate = doc.customer?.fxrate; let anchorPrice = null; let anchorSource = null; + let custPrice = null; + let custSource = null; let guidance = {}; let calcCeiling = null; let finalReason = ""; @@ -25,12 +27,15 @@ export function apply_guidance(doc: any) { // if there is no customer anchor price use target if (earlyPrice) { // translate alternate product history to current product quoted - anchorPrice = Number((earlyPrice * bridgePremium).toFixed(5)); + custPrice = Number((earlyPrice * bridgePremium).toFixed(5)); + anchorPrice = custPrice; // --------if the price needs bridged, add the details to the description-------- if (bridgePremium === 1) { anchorSource = earlySeason + ' Customer Price ' + earlyPrice; + custSource = anchorSource; } else { anchorSource = earlySeason + ' Similar (' + altHist + ') Customer Price ' + earlyPrice + ' x ' + bridgePremium + ' = ' + anchorPrice; + custSource = anchorSource; } // --------after the early price is translated see if target is still less------- if (targetPrice < anchorPrice) { @@ -55,6 +60,8 @@ export function apply_guidance(doc: any) { } guidance.AnchorPrice = anchorPrice; guidance.AnchorSource = anchorSource; + guidance.CustAnchorPrice = custPrice; + guidance.CustAnchorSource = custSource; guidance.InflationFactor = inflationFactor; guidance.Ceiling = calcCeiling; guidance.FinalPrice = finalPrice; diff --git a/sql/get_guidance_dseg.pg.sql b/sql/get_guidance_dseg.pg.sql index 390a896..53d1445 100644 --- a/sql/get_guidance_dseg.pg.sql +++ b/sql/get_guidance_dseg.pg.sql @@ -144,7 +144,7 @@ BEGIN ----------------price history------------------------------- SELECT jsonb_build_object('hist',rlarp.get_hist(_mold, _v1ds, _cust, substring(_chan,1,1))) INTO _hist; - --RAISE NOTICE 'history %', _hist; + --RAISE NOTICE 'history %', jsonb_pretty(_hist); ----------------target pricing------------------------------ SELECT @@ -213,7 +213,7 @@ BEGIN --RAISE NOTICE 'add list: %', jsonb_pretty(_pricing); ----------------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),_hist->'hist'->'cust'->>'ds', _v1ds),'{}'::jsonb) INTO _prem; _pricing := jsonb_build_object('pricing',_pricing||_prem); --RAISE NOTICE 'add bridge: %', jsonb_pretty(_pricing);