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
,null::text "version"
,null::text iter
,null::text iterdet
,null::jsonb iterdef
---------------ui columns-------------------------
,od.ssyr order_season
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom),'Mon') order_month
@ -432,26 +434,26 @@ SELECT
,b.dcmdat
,b.dhidat
,b.fspr
,b.remit_to --master data
,b.bill_class --master data
,bc.bvcomp remit_to --master data
,bc.bvclas bill_class --master data
,b.bill_cust --history cust mix
,b.bill_rep --master data
,b.bill_terr --master data
,b.ship_class --master data
,bc.bvsalm bill_rep --master data
,bc.bvterr bill_terr --master data
,sc.bvclas ship_class --master data
,b.ship_cust --history cust mix
,b.ship_rep --master data
,b.ship_terr --master data
,sc.bvsalm ship_rep --master data
,sc.bvterr ship_terr --master data
,b.quota_rep --master data
,b.account --master data
,b.shipgrp --master data
,b.geo --master data
,b.chan --master data
,b.orig_ctry --master data
,b.orig_prov --master data
,b.orig_post --master data
,b.dest_ctry --master data
,b.dest_prov --master data
,b.dest_post --master data
,ad.qzcryc orig_ctry
,ad.qzprov orig_prov
,ad.qzpost orig_post
,sc.bvctry dest_ctry
,sc.bvprcd dest_prov
,sc.bvpost dest_post
,(SELECT (regexp_match(def->>'newpart','(.*) - '::text))[1] FROM target) part --history part mix
,COALESCE(m.avglcd, p.awgldc) ord_gldc --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
,b.fb_qty units
FROM
applyx b
basemix b
LEFT OUTER JOIN LGDAT.STKMM M ON
M.AVPART = b.PART
LEFT OUTER JOIN LGDAT.STKMP P ON
@ -583,76 +585,7 @@ FROM
AND cx.rtyp = 'MA'
AND cx.fcur = copr.curr
AND cx.tcur = 'US'
LEFT OUTER JOIN LGDAT.ADRS AD ON
AD.QZADR = plnt."yaadr#"
)
,ins AS (
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
select * from final