build dates

This commit is contained in:
Trowbridge 2019-03-21 12:11:20 -04:00
parent 24188768f1
commit 2fc146ae5d

View File

@ -176,18 +176,18 @@ SELECT
,0::numeric(11,0) "fgent#"
,0::numeric(9,0) "diinv#"
,0::numeric(3,0) "dilin#"
,null::text promo --history date mix
,null::text promo --history
,null::text return_reas
,null::tex terms
,null::text terms
,''::text custpo
,'I' dhincr
,null::numeric diext
,null::numeric ditdis
,null::date dcodatdate mix
,null::date ddqdatdate mix
,null::date dcmdatdate mix
,null::date dhidatdate mix
,null::text fsprdate mix
,null::date dcodat
,null::date ddqdat
,null::date dcmdat
,null::date dhidat
,null::text fspr
,remit_to
,bill_class
,bill_cust
@ -237,9 +237,9 @@ SELECT
,0::numeric fb_val_loc_pl
,calc_status
,flag
,null::date orderdate --history date mix
,null::date requestdate --history date mix
,null::date shipdate --history date mix
,null::date orderdate --history
,null::date requestdate --history
,null::date shipdate --history
,null::date adj_orderdate --history
,null::date adj_requestdate --history
,null::date adj_shipdate --history
@ -323,69 +323,6 @@ SELECT
,quota_rep_descr
,director_descr
)
,custmix AS (
SELECT
remit_to
,bill_class
,bill_cust
,bill_rep
,bill_terr
,ship_class
,ship_cust
,ship_rep
,ship_terr
,quota_rep
,account
,shipgrp
,geo
,chan
,orig_ctry
,orig_prov
,orig_post
,dest_ctry
,dest_prov
,dest_post
,r_currency
,r_rate
--fcpool columns
,bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,(SELECT (regexp_match(def->>'newpart','(.*) - '::text))[1] FROM target) part_descr
,sum(coalesce(fb_val_loc * r_rate,0))/(SELECT sum(fb_val_loc * r_rate) FROM basemix) mix
FROM
basemix
GROUP BY
remit_to
,bill_class
,bill_cust
,bill_rep
,bill_terr
,ship_class
,ship_cust
,ship_rep
,ship_terr
,quota_rep
,account
,shipgrp
,geo
,chan
,orig_ctry
,orig_prov
,orig_post
,dest_ctry
,dest_prov
,dest_post
,r_currency
,r_rate
--fcpool columns
,bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,(SELECT (regexp_match(def->>'newpart','(.*) - '::text))[1] FROM target)
)
SELECT
b.plnt --master data
,b."ddord#"
@ -394,18 +331,18 @@ SELECT
,b."fgent#"
,b."diinv#"
,b."dilin#"
,b.promo --history date mix
,b.promo --history
,b.return_reas
,b.terms --history cust mix
,b.custpo
,b.dhincr
,b.diext
,b.ditdis
,b.dcodatdate mix
,b.ddqdatdate mix
,b.dcmdatdate mix
,b.dhidatdate mix
,b.fsprdate mix
,b.dcodat
,b.ddqdat
,b.dcmdat
,b.dhidat
,b.fspr
,b.remit_to --master data
,b.bill_class --master data
,b.bill_cust --history cust mix
@ -455,23 +392,23 @@ SELECT
,b.fb_val_loc_pl
,b.calc_status
,b.flag
,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) orderdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag requestdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag shipdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) adj_orderdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag adj_requestdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag adj_shipdate
,'replace_version' "version"
,'replace_source'||' volume' iter
-----------------------ui columns--------------------------------
,'replace_iterdet' iterdet
,$$replace_iterdef$$::jsonb iterdef
,$${"replace_iterdef":""}$$::json iterdef
,od.ssyr order_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom),'Mon') order_month
,sd.ssyr ship_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.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
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag,'Mon') request_month
,b.part_descr
,b.part_family
,b.part_group