insert to log and swap out columns on volume scale

This commit is contained in:
Paul Trowbridge 2020-02-13 12:26:13 -05:00
parent 994b076321
commit ef914f3d5e

View File

@ -143,119 +143,64 @@ target AS (select target_vol vincr, target_prc pincr)
,(SELECT vincr::numeric FROM target)/(SELECT sum(units)::numeric FROM basemix) factor ,(SELECT vincr::numeric FROM target)/(SELECT sum(units)::numeric FROM basemix) factor
) )
--select * from vscale --select * from vscale
,log AS (
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
)
,volume AS ( ,volume AS (
SELECT SELECT
b.plnt --master data fspr
,b."ddord#" --0 ,plnt ---master data
,b."dditm#" --0 ,promo --history date mix
,b."fgbol#" --0 ,terms
,b."fgent#" --0 ,bill_cust_descr --history cust mix
,b."diinv#" --0 ,ship_cust_descr --history cust mix
,b."dilin#" --0 ,dsm
,b.promo --history date mix ,quota_rep_descr --master data
,b.return_reas --0 ,director
,b.terms --history cust mix ,billto_group --master data
,b.custpo --0 ,shipto_group
,b.dhincr --0 ,chan --master data
,b.diext --0 ,chansub
,b.ditdis --0 ,chan_retail
,b.dcodat --calculated date mix ,part
,b.ddqdat --calculated date mix ,part_descr
,b.dcmdat --calculated date mix ,part_group
,b.dhidat --calculated date mix ,branding
,b.fspr --calculated date mix ,majg_descr
,b.remit_to --master data ,ming_descr
,b.bill_class --master data ,majs_descr
,b.bill_cust --history cust mix ,mins_descr
,b.bill_rep --master data ,segm
,b.bill_terr --master data ,fs_line --master data
,b.ship_class --master data ,r_currency --history cust mix
,b.ship_cust --history cust mix ,r_rate --master data
,b.ship_rep --master data ,c_currency --master data
,b.ship_terr --master data ,c_rate --master data
,b.quota_rep --master data ,units*s.factor
,b.account --master data ,value_loc*s.factor
,b.shipgrp --master data ,value_usd*s.factor
,b.geo --master data ,cost_loc*s.factor
,b.chan --master data ,cost_usd*s.factor
,b.orig_ctry --master data ,calc_status --0
,b.orig_prov --master data ,flag --0
,b.orig_post --master data ,order_date --history date mix
,b.dest_ctry --master data ,order_month
,b.dest_prov --master data ,order_season
,b.dest_post --master data ,request_date --history date mix
,b.part --history part mix ,request_month
,b.ord_gldc --master data ,request_season
,b.majg --master data ,ship_date --history date mix
,b.ming --master data ,ship_month
,b.majs --master data ,ship_season
,b.mins --master data ,'replace_version' "version"
,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.fs_line --master data
,b.r_currency --history cust mix
,b.r_rate --master data
,b.c_currency --master data
,b.c_rate --master data
,b.ddqtoi --0
,b.ddqtsi --0
,b.fgqshp --0
,b.diqtsh --0
,b.units*s.factor units
,b.fb_cst_loc*s.factor fb_cst_loc
,b.fb_cst_loc_cur*s.factor fb_cst_loc_cur
,b.fb_cst_loc_fut*s.factor fb_cst_loc_fut
,b.fb_val_loc*s.factor fb_val_loc
,b.fb_val_loc_pl*s.factor fb_val_loc_pl
,b.calc_status --0
,b.flag --0
,b.orderdate
,b.requestdate
,b.shipdate
,b.adj_orderdate
,b.adj_requestdate
,b.adj_shipdate
,'replace_version' "version" --calculated
,'replace_source'||' volume' iter ,'replace_source'||' volume' iter
-----------------------ui columns-------------------------------- ,log.id
,'replace_iterdet' iterdet ,log.doc->>'comment' "comment"
,$$replace_iterdef$$::jsonb iterdef ,log.doc->>'type' module
,b.order_season
,b.order_month
,b.ship_season
,b.ship_month
,b.request_season
,b.request_month
,b.part_descr
,b.part_family
,b.part_group
,b.branding
,b.color
,b.segm
,b.bill_cust_descr
,b.billto_group
,b.ship_cust_descr
,b.shipto_group
,b.majg_descr
,b.ming_descr
,b.majs_descr
,b.mins_descr
,b.mod_chan
,b.mod_chansub
,b.quota_rep_descr
,b.director_descr
,(b.fb_val_loc*s.factor)::numeric value_loc
,(b.fb_val_loc*s.factor*r_rate)::numeric value_usd
,(b.fb_cst_loc*s.factor)::numeric cost_loc
,(b.fb_cst_loc*s.factor*c_rate)::numeric cost_usd
,(b.units*s.factor)::numeric units
FROM FROM
basemix b basemix b
CROSS JOIN vscale s CROSS JOIN scale s
CROSS JOIN log
) )
,pscale AS ( ,pscale AS (
SELECT SELECT