bring in some customer master

This commit is contained in:
Trowbridge 2019-03-22 04:03:42 -04:00
parent 966b072f72
commit 6faa31c46b

View File

@ -367,6 +367,8 @@ SELECT
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag adj_shipdate ,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag adj_shipdate
,null::text "version" ,null::text "version"
,null::text iter ,null::text iter
,null::text iterdet
,null::jsonb iterdef
---------------ui columns------------------------- ---------------ui columns-------------------------
,od.ssyr order_season ,od.ssyr order_season
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom),'Mon') order_month ,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom),'Mon') order_month
@ -432,26 +434,26 @@ SELECT
,b.dcmdat ,b.dcmdat
,b.dhidat ,b.dhidat
,b.fspr ,b.fspr
,b.remit_to --master data ,bc.bvcomp remit_to --master data
,b.bill_class --master data ,bc.bvclas bill_class --master data
,b.bill_cust --history cust mix ,b.bill_cust --history cust mix
,b.bill_rep --master data ,bc.bvsalm bill_rep --master data
,b.bill_terr --master data ,bc.bvterr bill_terr --master data
,b.ship_class --master data ,sc.bvclas ship_class --master data
,b.ship_cust --history cust mix ,b.ship_cust --history cust mix
,b.ship_rep --master data ,sc.bvsalm ship_rep --master data
,b.ship_terr --master data ,sc.bvterr ship_terr --master data
,b.quota_rep --master data ,b.quota_rep --master data
,b.account --master data ,b.account --master data
,b.shipgrp --master data ,b.shipgrp --master data
,b.geo --master data ,b.geo --master data
,b.chan --master data ,b.chan --master data
,b.orig_ctry --master data ,ad.qzcryc orig_ctry
,b.orig_prov --master data ,ad.qzprov orig_prov
,b.orig_post --master data ,ad.qzpost orig_post
,b.dest_ctry --master data ,sc.bvctry dest_ctry
,b.dest_prov --master data ,sc.bvprcd dest_prov
,b.dest_post --master data ,sc.bvpost dest_post
,(SELECT (regexp_match(def->>'newpart','(.*) - '::text))[1] FROM target) part --history part mix ,(SELECT (regexp_match(def->>'newpart','(.*) - '::text))[1] FROM target) part --history part mix
,COALESCE(m.avglcd, p.awgldc) ord_gldc --master data ,COALESCE(m.avglcd, p.awgldc) ord_gldc --master data
,COALESCE(m.avmajg,p.awmajg) majg --master data ,COALESCE(m.avmajg,p.awmajg) majg --master data
@ -528,7 +530,7 @@ SELECT
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty*cx.rate cost_usd ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty*cx.rate cost_usd
,b.fb_qty units ,b.fb_qty units
FROM FROM
applyx b basemix b
LEFT OUTER JOIN LGDAT.STKMM M ON LEFT OUTER JOIN LGDAT.STKMM M ON
M.AVPART = b.PART M.AVPART = b.PART
LEFT OUTER JOIN LGDAT.STKMP P ON LEFT OUTER JOIN LGDAT.STKMP P ON
@ -583,76 +585,7 @@ FROM
AND cx.rtyp = 'MA' AND cx.rtyp = 'MA'
AND cx.fcur = copr.curr AND cx.fcur = copr.curr
AND cx.tcur = 'US' AND cx.tcur = 'US'
LEFT OUTER JOIN LGDAT.ADRS AD ON
AD.QZADR = plnt."yaadr#"
) )
,ins AS ( select * from final
INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING *
)
,insagg AS (
SELECT
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director_descr
,segm
,mod_chan
,mod_chansub
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,brand
,part_family
,part_group
,branding
,color
,part_descr
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
,sum(value_loc) value_loc
,sum(value_usd) value_usd
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
FROM
ins
GROUP BY
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director_descr
,segm
,mod_chan
,mod_chansub
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,brand
,part_family
,part_group
,branding
,color
,part_descr
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
)
--SELECT * FROM insagg
SELECT json_agg(row_to_json(insagg)) x from insagg