swap out columns on price adjust

This commit is contained in:
Trowbridge 2020-02-13 12:47:25 -05:00
parent 5e4690a1f4
commit fb7fdc7959

View File

@ -199,7 +199,7 @@ target AS (select target_vol vincr, target_prc pincr)
,log.doc->>'type' module ,log.doc->>'type' module
FROM FROM
basemix b basemix b
CROSS JOIN scale s CROSS JOIN vscale s
CROSS JOIN log CROSS JOIN log
) )
,pscale AS ( ,pscale AS (
@ -225,121 +225,63 @@ FROM
END mod_price END mod_price
) )
--select * from pscale --select * from pscale
,pricing AS (
SELECT
b.plnt --master data
,b."ddord#" --0
,b."dditm#" --0
,b."fgbol#" --0
,b."fgent#" --0
,b."diinv#" --0
,b."dilin#" --0
,b.promo --history date mix
,b.return_reas --0
,b.terms --history cust mix
,b.custpo --0
,b.dhincr --0
,b.diext --0
,b.ditdis --0
,b.dcodat --calculated date mix
,b.ddqdat --calculated date mix
,b.dcmdat --calculated date mix
,b.dhidat --calculated date mix
,b.fspr --calculated date mix
,b.remit_to --master data
,b.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
,b.ship_cust --history cust mix
,b.ship_rep --master data
,b.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
,b.part --history part mix
,b.ord_gldc --master data
,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.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
,0 units
,0 fb_cst_loc
,0 fb_cst_loc_cur
,0 fb_cst_loc_fut
--,b.value_loc*s.factor value_loc
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc_pl*s.factor END)::numeric value_loc_pl ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc_pl*s.factor END)::numeric value_loc_pl
--,b.value_loc_pl*s.factor value_loc_pl ,pricing AS (
,b.calc_status --0 SELECT
,b.flag --0 fspr
,b.orderdate ,plnt ---master data
,b.requestdate ,promo --history date mix
,b.shipdate ,terms
,b.adj_orderdate ,bill_cust_descr --history cust mix
,b.adj_requestdate ,ship_cust_descr --history cust mix
,b.adj_shipdate ,dsm
,'replace_version' "version" --calculated ,quota_rep_descr --master data
,'replace_source'||' price' iter ,director
-----------------------ui columns-------------------------------- ,billto_group --master data
,'replace_iterdet' iterdet ,shipto_group
,$$replace_iterdef$$::jsonb iterdef ,chan --master data
,b.order_season ,chansub
,b.order_month ,chan_retail
,b.ship_season ,part
,b.ship_month ,part_descr
,b.request_season ,part_group
,b.request_month ,branding
,b.part_descr ,majg_descr
,b.part_family ,ming_descr
,b.part_group ,majs_descr
,b.branding ,mins_descr
,b.color ,segm
,b.segm ,fs_line --master data
,b.bill_cust_descr ,r_currency --history cust mix
,b.billto_group ,r_rate --master data
,b.ship_cust_descr ,c_currency --master data
,b.shipto_group ,c_rate --master data
,b.majg_descr ,0::numeric units
,b.ming_descr
,b.majs_descr
,b.mins_descr
,b.mod_chan
,b.mod_chansub
,b.quota_rep_descr
,b.director_descr
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_loc*s.factor*b.r_rate END)::numeric value_usd ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric value_usd
,0 cost_loc ,0::numeric cost_loc
,0 cost_usd ,0::numeric cost_usd
,0 units ,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
,request_date --history date mix
,request_month
,request_season
,ship_date --history date mix
,ship_month
,ship_season
,'replace_version' "version"
,'replace_source'||' price' iter
,log.id
,log.doc->>'comment' "comment"
,log.doc->>'type' module
FROM FROM
volume b volume b
CROSS JOIN pscale s CROSS JOIN pscale s
CROSS JOIN log
WHERE WHERE
s.factor <> 0 or s.mod_price <> 0 s.factor <> 0 or s.mod_price <> 0
) )