diff --git a/route_sql/scale_pd.sql b/route_sql/scale_pd.sql index 2b16515..2f744d3 100644 --- a/route_sql/scale_pd.sql +++ b/route_sql/scale_pd.sql @@ -1,157 +1,88 @@ WITH target AS (select target_increment incr) ,basemix AS ( -SELECT - plnt ---master data - ,0::numeric(11,0) "ddord#" --0 - ,0::numeric(11,0) "dditm#" --0 - ,0::numeric(11,0) "fgbol#" --0 - ,0::numeric(11,0) "fgent#" --0 - ,0::numeric(9,0) "diinv#" --0 - ,0::numeric(3,0) "dilin#" --0 + SELECT + fspr + ,plnt ---master data ,promo --history date mix - ,null::text return_reas --0 ,terms - ,''::text custpo --0 - ,'I' dhincr --0 - ,null::numeric diext - ,null::numeric ditdis - ,null::date dcodat --calculated date mix - ,null::date ddqdat --calculated date mix - ,null::date dcmdat --calculated date mix - ,null::date dhidat --calculated date mix - ,null::text fspr --calculated date mix - ,remit_to --master data - ,bill_class --master data - ,bill_cust --history cust mix - ,bill_rep --master data - ,bill_terr --master data - ,ship_class --master data - ,ship_cust --history cust mix - ,ship_rep --master data - ,ship_terr --master data - ,quota_rep --master data - ,account --master data - ,shipgrp --master data - ,geo --master data + ,bill_cust_descr --history cust mix + ,ship_cust_descr --history cust mix + ,dsm + ,quota_rep_descr --master data + ,director + ,billto_group --master data + ,shipto_group ,chan --master data - ,orig_ctry --master data - ,orig_prov --master data - ,orig_post --master data - ,dest_ctry --master data - ,dest_prov --master data - ,dest_post --master data - ,part --history part mix - ,ord_gldc --master data - ,majg --master data - ,ming --master data - ,majs --master data - ,mins --master data - ,gldc --master data - ,glec --master data - ,harm --master data - ,clss --master data - ,brand --master data - ,assc --master data + ,chansub + ,chan_retail + ,part + ,part_descr + ,part_group + ,branding + ,majg_descr + ,ming_descr + ,majs_descr + ,mins_descr + ,segm ,fs_line --master data ,r_currency --history cust mix ,r_rate --master data ,c_currency --master data ,c_rate --master data - ,0::numeric(15,5) ddqtoi --0 - ,0::numeric(15,5) ddqtsi --0 - ,0::numeric(15,5) fgqshp --0 - ,0::numeric(15,5) diqtsh --0 - ,sum(coalesce(fb_qty,0)) fb_qty --history value - ,sum(coalesce(fb_cst_loc,0)) fb_cst_loc --history part mix - ,sum(coalesce(fb_cst_loc_cur,0)) fb_cst_loc_cur --master data - ,sum(coalesce(fb_cst_loc_fut,0)) fb_cst_loc_fut --master data - ,sum(coalesce(fb_val_loc,0)) fb_val_loc --history value - ,sum(coalesce(fb_val_loc_pl,0)) fb_val_loc_pl --0 + ,sum(coalesce(units,0)) units --history value + ,sum(coalesce(value_loc,0)) value_loc --history value + ,sum(coalesce(value_usd,0)) value_usd --0 + ,sum(coalesce(cost_loc,0)) cost_loc --history part mix + ,sum(coalesce(cost_usd,0)) cost_usd ,calc_status --0 ,flag --0 - ,orderdate --history date mix - ,requestdate --history date mix - ,shipdate --history date mix - ,adj_orderdate --history - ,adj_requestdate --history - ,adj_shipdate --history - ,'b20' "version" --calculated - ,'adjustment' iter --calculated - ---------------ui columns------------------------- - ,order_season + ,order_date --history date mix ,order_month - ,ship_season - ,ship_month - ,request_season + ,order_season + ,request_date --history date mix ,request_month - ,part_descr - ,part_family - ,part_group - ,branding - ,color - ,segm - ,bill_cust_descr - ,billto_group - ,ship_cust_descr - ,shipto_group - ,majg_descr - ,ming_descr - ,majs_descr - ,mins_descr - ,mod_chan - ,mod_chansub - ,quota_rep_descr - ,director_descr - ,null value_loc - ,null value_usd - ,null cost_loc - ,null cost_usd - ,null units + ,request_season + ,ship_date --history date mix + ,ship_month + ,ship_season FROM - rlarp.osm_fcpool + rlarp.osm_pool WHERE -----------------scenario---------------------------- where_clause -----------------additional params------------------- + AND CASE (SELECT flag FROM flagv) + WHEN 'scale all' THEN true + WHEN 'scale copy' THEN iter = 'copy' + WHEN 'scale new part' THEN module = 'new basket' + END AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments - AND adj_orderdate <= adj_shipdate + AND order_date <= ship_date GROUP BY - plnt ---master data - ,promo + fspr + ,plnt ---master data + ,promo --history date mix ,terms - ,remit_to --master data - ,bill_class --master data - ,bill_cust --history cust mix - ,bill_rep --master data - ,bill_terr --master data - ,ship_class --master data - ,ship_cust --history cust mix - ,ship_rep --master data - ,ship_terr --master data - ,quota_rep --master data - ,account --master data - ,shipgrp --master data - ,geo --master data + ,bill_cust_descr --history cust mix + ,ship_cust_descr --history cust mix + ,dsm + ,quota_rep_descr --master data + ,director + ,billto_group --master data + ,shipto_group ,chan --master data - ,orig_ctry --master data - ,orig_prov --master data - ,orig_post --master data - ,dest_ctry --master data - ,dest_prov --master data - ,dest_post --master data - ,part --history part mix - ,ord_gldc --master data - ,majg --master data - ,ming --master data - ,majs --master data - ,mins --master data - ,gldc --master data - ,glec --master data - ,harm --master data - ,clss --master data - ,brand --master data - ,assc --master data + ,chansub + ,chan_retail + ,part + ,part_descr + ,part_group + ,branding + ,majg_descr + ,ming_descr + ,majs_descr + ,mins_descr + ,segm ,fs_line --master data ,r_currency --history cust mix ,r_rate --master data @@ -159,37 +90,15 @@ SELECT ,c_rate --master data ,calc_status --0 ,flag --0 - ,orderdate --history date mix - ,requestdate --history date mix - ,shipdate --history date mix - ,adj_orderdate --history - ,adj_requestdate --history - ,adj_shipdate --history - ---------------ui columns------------------------- - ,order_season + ,order_date --history date mix ,order_month - ,ship_season - ,ship_month - ,request_season + ,order_season + ,request_date --history date mix ,request_month - ,part_descr - ,part_family - ,part_group - ,branding - ,color - ,segm - ,bill_cust_descr - ,billto_group - ,ship_cust_descr - ,shipto_group - ,majg_descr - ,ming_descr - ,majs_descr - ,mins_descr - ,mod_chan - ,mod_chansub - ,quota_rep_descr - ,director_descr + ,request_season + ,ship_date --history date mix + ,ship_month + ,ship_season ) ,scale AS ( SELECT