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,123 +120,66 @@ 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 ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
,b.shipgrp --master data ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric value_usd
,b.geo --master data ,0::numeric cost_loc
,b.chan --master data ,0::numeric cost_usd
,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 ,'replace_source'||' price' iter
,b.glec --master data ,log.id
,b.harm --master data ,log.doc->>'comment' "comment"
,b.clss --master data ,log.doc->>'type' module
,b.brand --master data FROM
,b.assc --master data volume b
,b.fs_line --master data CROSS JOIN pscale s
,b.r_currency --history cust mix CROSS JOIN log
,b.r_rate --master data WHERE
,b.c_currency --master data s.factor <> 0 or s.mod_price <> 0
,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_pl*s.factor END)::numeric value_loc_pl
--,b.value_loc_pl*s.factor value_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'||' price' iter --calculated
-----------------------ui columns--------------------------------
,'replace_iterdet' iterdet
,$$replace_iterdef$$::jsonb iterdef
,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
,(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
) )
--select sum(value_usd), count(*) from final --select sum(value_usd), count(*) from final
, ins AS ( , ins AS (