From 14ee797b918d28069f6b60b20a3e93851487c1cf Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 20 Nov 2023 15:46:59 -0500 Subject: [PATCH] vault backup: 2023-11-20 15:46:59 --- sql/apply_guidance.pg.sql | 4 ++++ sql/get_guidance_dseg.pg.sql | 7 ++++++- sql/livequotes.pg.sql | 10 ++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sql/apply_guidance.pg.sql b/sql/apply_guidance.pg.sql index d36d51f..568d3de 100644 --- a/sql/apply_guidance.pg.sql +++ b/sql/apply_guidance.pg.sql @@ -81,6 +81,7 @@ AS $function$ const inflationFactor = iidx ? iidx[inflation] : 0; const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null; const listUSD = list ? list * fxrate :null; + const fstdUSD = doc.product?.std; // ------------------calculate price adders------------------------------------------------------ let ltp = qty < pltq ? 0.15 : null; @@ -121,6 +122,9 @@ AS $function$ let guidance = { prices ,finalPrice + ,targetPrice + ,listUSD + ,fstdUSD } doc.guidance = guidance; return doc; diff --git a/sql/get_guidance_dseg.pg.sql b/sql/get_guidance_dseg.pg.sql index fad11e6..90b1ee0 100644 --- a/sql/get_guidance_dseg.pg.sql +++ b/sql/get_guidance_dseg.pg.sql @@ -1,4 +1,4 @@ -DROP FUNCTION rlarp.get_guidance_dseg; +DROP FUNCTION rlarp.get_guidance_dseg CASCADE; CREATE OR REPLACE FUNCTION rlarp.get_guidance_dseg(_bill text, _ship text, _stlc text, _dseg text, _qty numeric, _seas int) RETURNS jsonb LANGUAGE plpgsql AS @@ -15,6 +15,7 @@ DECLARE _item text; _unti text; _pltq numeric; + _fstd numeric; _cust text; _curr text; _rate numeric; @@ -65,12 +66,14 @@ BEGIN ,idxk ,prefer ,pltq + ,fstd_usd INTO _mold ,_item ,_iidx ,_itemr ,_pltq + ,_fstd FROM ( SELECT @@ -80,6 +83,7 @@ BEGIN ,i.v1ds ,i.v0ds ,i.pltq + ,avg(i.fstd_usd) FILTER (WHERE aplnt <> 'I') fstd_usd ,jsonb_strip_nulls(jsonb_build_object('assc',CASE WHEN i.assc <> '' THEN i.assc ELSE null::text END,'majg',i.majg::int,'coltier',i.coltier)) idxk ,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END prefer FROM @@ -109,6 +113,7 @@ BEGIN ,'itemrel',_itemr ,'iidx',_iidx ,'pltq',_pltq + ,'fstd_usd',_fstd ) ); --RAISE NOTICE 'item data %', jsonb_pretty(_product||_input); diff --git a/sql/livequotes.pg.sql b/sql/livequotes.pg.sql index cb79ea7..d738bfe 100644 --- a/sql/livequotes.pg.sql +++ b/sql/livequotes.pg.sql @@ -11,20 +11,18 @@ lq AS MATERIALIZED ( ,lqg AS ( SELECT lq.* - ,m.part_group - ,i.pltq + ,pricing->'product'->>'mold' part_group + ,pricing->'product'->>'itemrel' item_fit + ,(pricing->'product'->>'pltq')::numeric pltq ,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance ,pricing->'guidance'->'finalPrice'->>'Reason' reason + ,(pricing->'product'->>'fstd_usd')::numeric fstd_usd ,jsonb_pretty(pricing) pricing FROM lq JOIN LATERAL rlarp.guidance_r1( rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2024) ) pricing ON TRUE - LEFT OUTER JOIN rlarp.molds m ON - m.stlc = lq.mold - LEFT OUTER JOIN "CMS.CUSLG".itemmv i ON - i.item = lq.part WHERE lq.qstat ~ 'Submitted' )