diff --git a/index.js b/index.js index dc2de2f..b8e775b 100644 --- a/index.js +++ b/index.js @@ -256,8 +256,8 @@ server.post('/cust_swap', bodyParser.json(), function(req, res) { sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body)); //execute the sql and send the result console.log(sql); - res.json(null); - //Postgres.FirstRow(sql, [], res) + //res.json(null); + Postgres.FirstRow(sql, [], res) }; }) diff --git a/route_sql/swap_cust.sql b/route_sql/swap_cust.sql index 69b6c16..863c37e 100644 --- a/route_sql/swap_cust.sql +++ b/route_sql/swap_cust.sql @@ -24,9 +24,9 @@ target AS (SELECT $$swap_doc$$::jsonb swap) --other stuff doesn't matter becuase it's getting overridden anyways FROM swap - LEFT out JOIN lgdat.cust bc ON + LEFT OUTER JOIN lgdat.cust bc ON bc.bvcust = swap.bill_r - LEFT out JOIN lgdat.cust sc ON + LEFT OUTER JOIN lgdat.cust sc ON sc.bvcust = swap.ship_r ) --put bill to and ship to back together and join in channel, terms, descriptions, etc @@ -121,42 +121,42 @@ target AS (SELECT $$swap_doc$$::jsonb swap) ) ,repl AS ( SELECT - o.fspr - ,o.dplt plnt ---master data + o.fspr + ,o.plnt ---master data ,o.promo --history date mix - ,terms - ,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 - ,COALESCE(c.bill_dba,billto_group) billto_group - ,COALESCE(c.ship_dba,shipto_group) shipto_group - ,chan --master data - ,chansub - ,chan_retail + ,o.terms + ,COALESCE(c.bill_r||' - '||c.bill_dba,o.bill_cust_descr) bill_cust_descr + ,COALESCE(c.ship_r||' - '||c.ship_dba,o.ship_cust_descr) ship_cust_descr + ,o.dsm + ,o.quota_rep_descr --master data + ,o.director + ,COALESCE(c.bill_dba,o.billto_group) billto_group + ,COALESCE(c.ship_dba,o.shipto_group) shipto_group + ,o.chan --master data + ,o.chansub + ,o.chan_retail ,o.part - ,o.partd + ,o.part_descr ,o.part_group ,o.branding ,o.majg_descr ,o.ming_descr ,o.majs_descr ,o.mins_descr - ,seg.segm + ,o.segm ,o.substance - ,o.fs_line --master data + ,o.fs_line --master data ,o.r_currency --history cust mix - ,o.r_rate --master data - ,o.r.curr c_currency --master data - ,o.x.rate c_rate --master data + ,o.r_rate --master data + ,o.c_currency --master data + ,o.c_rate --master data ,-o.units units ,-o.value_loc value_loc ,-o.value_usd value_usd - ,-o.units * c.std cost_loc - ,-o.units * c.std * x.rate cost_usd - ,o.calc_status --0 - ,o.flag --0 + ,-o.cost_loc cost_loc + ,-o.cost_usd cost_usd + ,o.calc_status --0 + ,o.flag --0 ,o.order_date --history date mix ,o.order_month ,o.order_season