insert new columns and log

This commit is contained in:
Trowbridge 2020-02-13 13:20:33 -05:00
parent 9793596d27
commit a4cf5b7607

View File

@ -120,122 +120,65 @@ target AS (select target_increment incr)
0 0
END mod_price END mod_price
) )
,log AS (
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
)
,final AS ( ,final 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 ,0::numeric units
,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 ELSE b.value_usd*s.factor END)::numeric value_usd
--,b.value_loc_pl*s.factor value_loc_pl ,0::numeric cost_loc
,b.calc_status --0 ,0::numeric cost_usd
,b.flag --0 ,calc_status --0
,b.orderdate ,flag --0
,b.requestdate ,order_date --history date mix
,b.shipdate ,order_month
,b.adj_orderdate ,order_season
,b.adj_requestdate ,request_date --history date mix
,b.adj_shipdate ,request_month
,'replace_version' "version" --calculated ,request_season
,'replace_source'||' price' iter --calculated ,ship_date --history date mix
-----------------------ui columns-------------------------------- ,ship_month
,'replace_iterdet' iterdet ,ship_season
,$$replace_iterdef$$::jsonb iterdef ,'replace_version' "version"
,b.order_season ,'replace_source'||' price' iter
,b.order_month ,log.id
,b.ship_season ,log.doc->>'comment' "comment"
,b.ship_month ,log.doc->>'type' module
,b.request_season FROM
,b.request_month volume b
,b.part_descr CROSS JOIN pscale s
,b.part_family CROSS JOIN log
,b.part_group WHERE
,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
,(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*r_rate END)::numeric value_usd
,0 cost_loc
,0 cost_usd
,0 units
FROM
basemix b
CROSS JOIN scale s
WHERE
s.factor <> 0 or s.mod_price <> 0 s.factor <> 0 or s.mod_price <> 0
) )
--select sum(value_usd), count(*) from final --select sum(value_usd), count(*) from final