add scenario totals_route

This commit is contained in:
Paul Trowbridge 2019-02-28 01:48:42 -05:00
parent d1630811bb
commit a42aefc653
2 changed files with 70 additions and 0 deletions

View File

@ -85,6 +85,59 @@ server.get('/monthly_orders', bodyParser.json(), function (req,res) {
//res.json("hi")
})
server.get('/scenario_totals', bodyParser.json(), function (req,res) {
var w = "";
var c = 1;
var args = [];
for (var i in req.body) {
//console.log(i);
///console.log(req.body[i]);
if (c > 1) {
w = w +
`
AND `
}
w = w + i + " = '" + req.body[i] + "'";
args.push(req.body[i]);
c = c + 1;
};
if (c == 1) {
res.send("no body was sent");
return;
}
//console.log(w);
//console.log(args);
w =
`
WITH
ini AS (
SELECT
order_season
,version
,iter
,SUM(units) units
,SUM(value_usd) value_usd
FROM
rlarp.osm_fcpool
WHERE
` + w +
`
GROUP BY
order_season
,version
,iter
)
SELECT
jsonb_agg(row_to_json(ini)::jsonb) x
FROM
ini`
console.log(w);
Postgres.FirstRow(w,[],res)
//res.json("hi")
})
server.get('/get_pool', bodyParser.json(), function (req,res) {
var args = [req.body.quota_rep];

View File

@ -0,0 +1,17 @@
SELECT
order_season
,version
,iter
,SUM(units) units
,SUM(value_usd) value_usd
FROM
rlarp.osm_fcpool
WHERE
quota_rep_descr = '90005 - MARK WILKINSON'
AND segm = 'Retail'
AND mod_chan = 'MASS'
AND order_month = 'May'
GROUP BY
order_season
,version
,iter