update price adjust to same logic as volume

This commit is contained in:
Paul Trowbridge 2019-03-05 23:45:55 -05:00
parent a1ed1a2732
commit 960c02054d

View File

@ -1,5 +1,27 @@
WITH WITH
target AS (select 50000 incr) target AS (select 50000 incr)
,GLD AS (
SELECT
N1COMP COMP
,N1CCYY FSYR
,KPMAXP PERDS
,N1FSPP PERD
,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT
,N1ED01 EDAT
,to_char(N1ED01,'yymm') CAPR
,N1ED01 - N1SD01 +1 NDAYS
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
FROM
LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON
KPCOMP = N1COMP AND
KPCCYY = N1CCYY
WHERE
N1COMP = 93
--AND DIGITS(N1FSYP) = '1901'
)
,mseq AS ( ,mseq AS (
SELECT * FROM SELECT * FROM
( (
@ -179,12 +201,12 @@ SELECT
,'b20' "version" --calculated ,'b20' "version" --calculated
,'adjustment' iter --calculated ,'adjustment' iter --calculated
---------------ui columns------------------------- ---------------ui columns-------------------------
,null order_season ,null::numeric order_season
,null order_month ,null::text order_month
,null ship_season ,null::numeric ship_season
,null ship_month ,null::text ship_month
,null request_season ,null::numeric request_season
,null request_month ,null::text request_month
,part_descr ,part_descr
,part_family ,part_family
,part_group ,part_group
@ -367,12 +389,14 @@ SELECT
,b.version --calculated ,b.version --calculated
,b.iter --calculated ,b.iter --calculated
-----------------------ui columns-------------------------------- -----------------------ui columns--------------------------------
,b.order_season ,'adjust price' iterdet
,b.order_month ,null::jsonb iterdef
,b.ship_season ,od.ssyr order_season
,b.ship_month ,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
,b.request_season ,sd.ssyr ship_season
,b.request_month ,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,rd.ssyr request_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month
,b.part_descr ,b.part_descr
,b.part_family ,b.part_family
,b.part_group ,b.part_group
@ -402,7 +426,13 @@ FROM
CROSS JOIN mmixp m CROSS JOIN mmixp m
LEFT OUTER JOIN mseq ON LEFT OUTER JOIN mseq ON
mseq.m = m._month mseq.m = m._month
LEFT OUTER JOIN gld od ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
WHERE WHERE
m._month = 'Jul' m._month = 'Jul'
) )
select sum(value_usd) from final INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING *