finish work on customer swap, start testing this

This commit is contained in:
Paul Trowbridge 2021-04-07 20:23:12 +00:00
parent b487430057
commit f7f26b2804

View File

@ -112,9 +112,9 @@ target AS (SELECT $$swap_doc$$::jsonb swap)
FROM
rlarp.osm_pool o
CROSS JOIN log
INNER JOIN swap ON
swap.bill_to = SUBSTRING(o.bill_cust_descr,1,8)
swap.bill_to = SUBSTRING(o.ship_cust_descr,1,8)
INNER JOIN cust c ON
c.billto = SUBSTRING(o.bill_cust_descr,1,8)
AND c.shipto = SUBSTRING(o.ship_cust_descr,1,8)
WHERE
-----------------scenario----------------------------
where_clause
@ -125,13 +125,13 @@ target AS (SELECT $$swap_doc$$::jsonb swap)
,o.dplt plnt ---master data
,o.promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,COALESCE(c.bill_r||' - '||c.bill_dba,bill_cust_descr) bill_cust_descr
,COALESCE(c.ship_r||' - '||c.ship_dba,ship_cust_descr) ship_cust_descr
,dsm
,quota_rep_descr --master data
,director
,billto_group --master data
,shipto_group
,COALESCE(c.bill_dba,billto_group) billto_group
,COALESCE(c.ship_dba,shipto_group) shipto_group
,chan --master data
,chansub
,chan_retail
@ -174,12 +174,11 @@ target AS (SELECT $$swap_doc$$::jsonb swap)
,o.module
FROM
remove o
LEFT OUTER JOIN bill ON
bill.billto = rtrim(substring(o.bill_cust_desrc,1,8))
LEFT OUTER JOIN ship ON
ship.shipto = rtrim(substring(o.ship_cust_desrc,1,8))
INNER JOIN cust c ON
c.billto = SUBSTRING(o.bill_cust_descr,1,8)
AND c.shipto = SUBSTRING(o.ship_cust_descr,1,8)
)
--select bill_cust_descr, ship_cust_descr, sum(value_usd) from (SELECT * FROM remove UNION ALL SELECT * FROM repl) x group by bill_cust_descr, ship_cust_descr
,ins AS (
INSERT INTO rlarp.osm_pool SELECT * FROM remove UNION ALL SELECT * FROM repl RETURNING *
)