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; _unti text;
_pltq numeric; _pltq numeric;
_fstd numeric; _fstd numeric;
_fstdina numeric;
_cust text; _cust text;
_curr text; _curr text;
_rate numeric; _rate numeric;
@ -67,6 +68,7 @@ BEGIN
,prefer ,prefer
,pltq ,pltq
,fstd_usd ,fstd_usd
,fstd_usd_ina
INTO INTO
_mold _mold
,_item ,_item
@ -74,6 +76,7 @@ BEGIN
,_itemr ,_itemr
,_pltq ,_pltq
,_fstd ,_fstd
,_fstdina
FROM FROM
( (
SELECT SELECT
@ -84,6 +87,7 @@ BEGIN
,i.v0ds ,i.v0ds
,i.pltq ,i.pltq
,avg(i.fstd_usd) FILTER (WHERE aplnt <> 'I') fstd_usd ,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 ,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 ,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END prefer
FROM FROM
@ -114,6 +118,7 @@ BEGIN
,'iidx',_iidx ,'iidx',_iidx
,'pltq',_pltq ,'pltq',_pltq
,'fstd_usd',_fstd ,'fstd_usd',_fstd
,'fstd_usd_ina',_fstdina
) )
); );
--RAISE NOTICE 'item data %', jsonb_pretty(_product||_input); --RAISE NOTICE 'item data %', jsonb_pretty(_product||_input);

View File

@ -18,7 +18,7 @@ lq AS MATERIALIZED (
,(pricing->'product'->>'pltq')::numeric pltq ,(pricing->'product'->>'pltq')::numeric pltq
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance ,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
,pricing->'guidance'->'finalPrice'->>'Reason' reason ,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'->>'ltp')::numeric ltp
,(pricing->'guidance'->>'optimization')::numeric optimization ,(pricing->'guidance'->>'optimization')::numeric optimization
,(pricing->'guidance'->>'inflationFactor')::numeric inflation ,(pricing->'guidance'->>'inflationFactor')::numeric inflation