From a2322876e1863d8a3c335b36f2404ed224ad88d1 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 29 Nov 2023 08:16:26 -0500 Subject: [PATCH] include avg cost for inactive items --- sql/get_guidance_dseg.pg.sql | 5 +++++ sql/livequotes.pg.sql | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/get_guidance_dseg.pg.sql b/sql/get_guidance_dseg.pg.sql index 9084c7d..572b7c3 100644 --- a/sql/get_guidance_dseg.pg.sql +++ b/sql/get_guidance_dseg.pg.sql @@ -16,6 +16,7 @@ DECLARE _unti text; _pltq numeric; _fstd numeric; + _fstdina numeric; _cust text; _curr text; _rate numeric; @@ -67,6 +68,7 @@ BEGIN ,prefer ,pltq ,fstd_usd + ,fstd_usd_ina INTO _mold ,_item @@ -74,6 +76,7 @@ BEGIN ,_itemr ,_pltq ,_fstd + ,_fstdina FROM ( SELECT @@ -84,6 +87,7 @@ BEGIN ,i.v0ds ,i.pltq ,avg(i.fstd_usd) FILTER (WHERE aplnt <> 'I') fstd_usd + ,avg(i.fstd_usd) fstd_usd_ina ,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 @@ -114,6 +118,7 @@ BEGIN ,'iidx',_iidx ,'pltq',_pltq ,'fstd_usd',_fstd + ,'fstd_usd_ina',_fstdina ) ); --RAISE NOTICE 'item data %', jsonb_pretty(_product||_input); diff --git a/sql/livequotes.pg.sql b/sql/livequotes.pg.sql index 06b06eb..ba12ed8 100644 --- a/sql/livequotes.pg.sql +++ b/sql/livequotes.pg.sql @@ -18,7 +18,7 @@ lq AS MATERIALIZED ( ,(pricing->'product'->>'pltq')::numeric pltq ,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance ,pricing->'guidance'->'finalPrice'->>'Reason' reason - ,(pricing->'product'->>'fstd_usd')::numeric fstd_usd + ,(pricing->'product'->>'fstd_usd_ina')::numeric fstd_usd ,(pricing->'guidance'->>'ltp')::numeric ltp ,(pricing->'guidance'->>'optimization')::numeric optimization ,(pricing->'guidance'->>'inflationFactor')::numeric inflation