include avg cost for inactive items

This commit is contained in:
Paul Trowbridge 2023-11-29 08:16:26 -05:00
parent eca0da084e
commit a2322876e1
2 changed files with 6 additions and 1 deletions

View File

@ -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);

View File

@ -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