parameterize for route prep

This commit is contained in:
Trowbridge 2019-03-22 04:42:13 -04:00
parent dfcd85f98b
commit a8f8a8cffb

View File

@ -2,7 +2,7 @@ WITH
/*
the volume must be expressed in terms of units, since that is what it will be scaling
*/
target AS (select '{"scenario":{"quota_rep_descr":"30033 - ROBERT NELSON","mod_chan":"DISTRIBUTOR","shipto_group":"KINNEY BONDED","version":"b20","iter":["copy"]},"stamp":"2019-03-22 03:24:28","user":"Trowbridge, Paul","source":"adj","type":"new_part","months":{"Jun":{"amount":"49649.1264","qty":"266248"},"Jul":{"amount":"37780.1","qty":"111786"},"Aug":{"amount":"36449.5","qty":"200396"},"Sep":{"amount":"29804.36","qty":"142327"},"Oct":{"amount":"48592.24","qty":"195356"},"Nov":{"amount":"33608.52","qty":"158100"},"Dec":{"amount":"50410.33","qty":"185462"},"Jan":{"amount":"60578.05","qty":"180712"},"Feb":{"amount":"36233.39","qty":"171236"},"Mar":{"amount":68208.7799685946,"qty":"223464.85292"},"Apr":{"amount":57397.3621278386,"qty":"263108.09419"},"May":{"amount":78626.8773843847,"qty":"324395.89234"}},"newpart":"XNT0TQT2G18B220 - 01.00 Q PER PRP CX BKBK","basket":[{"part_descr":"XNT0TQT2G18B220 - 01.00 Q PER PRP CX BKBK","bill_cust_descr":"KINN0002 - KINNEY BONDED WAREHOUSE INC","ship_cust_descr":"KINN0002 - KINNEY BONDED WAREHOUSE INC","mix":0.61885609384386},{"part_descr":"XNT0TQT2G18B220 - 01.00 Q PER PRP CX BKBK","bill_cust_descr":"KINN0002 - KINNEY BONDED WAREHOUSE INC","ship_cust_descr":"KINN0003 - KINNEY BONDED WAREHOUSE INC","mix":0.381143906156143}]}'::json def)
target AS (select $$replace_request$$::json def)
--select * from newm
,GLD AS (
SELECT
@ -365,11 +365,11 @@ SELECT
,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
,null::text "version"
,null::text iter
,null::text iterdet
,null::jsonb iterdef
---------------ui columns-------------------------
,'replace_version' "version"
,'replace_source'||' new basket' iter
-----------------------ui columns--------------------------------
,'replace_iterdet' iterdet
,$$replace_iterdef$$::json iterdef
,od.ssyr order_season
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom),'Mon') order_month
,sd.ssyr ship_season
@ -536,8 +536,8 @@ SELECT
,b.request_season
,b.request_month
,b.part_descr
,SUBSTR(b.part,1,3)||' - '||F.DESCR part_family
,SUBSTRING(b.part,1,8)||' - '||MD.DESCR part_group
,SUBSTR(b.part,1,3)||coalesce(' - '||F.DESCR,'') part_family
,SUBSTRING(b.part,1,8)||coalesce(' - '||MD.DESCR,'') part_group
,COALESCE(MG.GRP,'Unbranded') branding
,CASE WHEN substring(COALESCE(m.avgled, p.awgled),1,1) <= '2' THEN SUBSTRING(b.part,9,3) ELSE '' END color
,COALESCE(SEG.SEGM,'Other') segm
@ -669,4 +669,129 @@ FROM
LEFT OUTER JOIN LGDAT.ADRS AD ON
AD.QZADR = plnt."yaadr#"
)
select * from final
/*
,clone_part_meta AS (
SELECT
b.majg --master data
,b.ming --master data
,b.majs --master data
,b.mins --master data
,b.gldc --master data
,b.glec --master data
,b.harm --master data
,b.clss --master data
,b.brand --master data
,b.assc --master data
,b.segm
,b.majg_descr
,b.ming_descr
,b.majs_descr
,b.mins_descr
,b.quota_rep
,sum(fb_val_loc * r_rate) agg
FROM
rlarp.osm_fcpool b
WHERE
-----------------scenario----------------------------
--where_clause
quota_rep_descr = '30033 - ROBERT NELSON'
AND mod_chan = 'DISTRIBUTOR'
AND shipto_group = 'KINNEY BONDED'
AND "version" = 'b20'
AND iter = 'copy'
--probably dont want to include adjustments that have blown away volume and good sources of dating info
-----------------additional params-------------------
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate
GROUP BY
b.majg --master data
,b.ming --master data
,b.majs --master data
,b.mins --master data
,b.gldc --master data
,b.glec --master data
,b.harm --master data
,b.clss --master data
,b.brand --master data
,b.assc --master data
,b.segm
,b.majg_descr
,b.ming_descr
,b.majs_descr
,b.mins_descr
,b.quota_rep
ORDER BY
agg desc
)
*/
, ins AS (
INSERT INTO rlarp.osm_fcpool (SELECT * FROM pricing UNION ALL SELECT * FROM volume) 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 json_agg(row_to_json(insagg)) x from insagg