add aggregator

This commit is contained in:
Paul Trowbridge 2019-02-27 14:26:28 -05:00
parent 8c8e8b22e4
commit e1c30e24a2

153
index.js
View File

@ -92,82 +92,85 @@ server.get('/get_pool', bodyParser.json(), function (req,res) {
var w = var w =
` `
WITH rows AS ( WITH rows AS (
SELECT SELECT
---------customer info-----------------
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director_descr
,segm
,mod_chan
,mod_chansub
---------product info------------------
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,brand
,part_family
,part_group
,branding
,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
--------values-------------------------
,sum(value_loc) value_loc
,sum(value_usd) value_usd
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
FROM
rlarp.osm_fcpool
WHERE
quota_rep_descr = $1
GROUP BY
---------customer info----------------- ---------customer info-----------------
bill_cust_descr bill_cust_descr
,billto_group ,billto_group
,ship_cust_descr ,ship_cust_descr
,shipto_group ,shipto_group
,quota_rep_descr ,quota_rep_descr
,director_descr ,director_descr
,segm ,segm
,mod_chan ,mod_chan
,mod_chansub ,mod_chansub
---------product info------------------ ---------product info------------------
,majg_descr ,majg_descr
,ming_descr ,ming_descr
,majs_descr ,majs_descr
,mins_descr ,mins_descr
,brand ,brand
,part_family ,part_family
,part_group ,part_group
,branding ,branding
,color ,color
,part_descr ,part_descr
---------dates------------------------- ---------dates-------------------------
,order_season ,order_season
,order_month ,order_month
,ship_season ,ship_season
,ship_month ,ship_month
,request_season ,request_season
,request_month ,request_month
,promo ,promo
,version ,version
,iter ,iter
) --------values-------------------------
SELECT row_to_json(rows) x FROM rows`; ,sum(value_loc) value_loc
,sum(value_usd) value_usd
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
FROM
rlarp.osm_fcpool
WHERE
quota_rep_descr = '13025 - JAMES REGER'
GROUP BY
---------customer info-----------------
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director_descr
,segm
,mod_chan
,mod_chansub
---------product info------------------
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,brand
,part_family
,part_group
,branding
,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
)
SELECT
json_agg(row_to_json(rows)) x
FROM
rows`;
//-----------------replace default quota_rep---------------------------------------------------- //-----------------replace default quota_rep----------------------------------------------------
console.log(w); console.log(w);
Postgres.FirstRow(w,args,res) Postgres.FirstRow(w,args,res)