update addmonth_v to manifest iteration changes
This commit is contained in:
parent
45fc2255eb
commit
2352a898be
23
index.js
23
index.js
@ -104,6 +104,7 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) {
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w)
|
||||
//execute the sql and send the result
|
||||
//console.log(sql);
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
};
|
||||
|
||||
@ -122,7 +123,8 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
var c = 1;
|
||||
var c = 1; //counts iterations through each scaenario key
|
||||
var d = 1; //counts cycles in scenario key values which are arrays
|
||||
var args = [];
|
||||
var path = './route_sql/addmonth_vd.sql';
|
||||
|
||||
@ -137,7 +139,21 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
||||
`
|
||||
AND `
|
||||
}
|
||||
if (Array.isArray(req.body.scenario[i])){
|
||||
//if the scenario key has a value that is an array of items, push it into an `IN` statement
|
||||
//iter = [stage1, stage2] --> SQL --> iter IN ('stag1', stage2')
|
||||
w = w + i + " IN (";
|
||||
for (var j in req.body.scenario[i]){
|
||||
if (d>1){
|
||||
w = w + ",";
|
||||
}
|
||||
w = w + "'" + req.body.scenario[i][j] + "'";
|
||||
d = d + 1;
|
||||
}
|
||||
w = w + ")"
|
||||
} else {
|
||||
w = w + i + " = '" + req.body.scenario[i] + "'";
|
||||
}
|
||||
args.push(req.body.scenario[i]);
|
||||
c = c + 1;
|
||||
};
|
||||
@ -151,7 +167,12 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
||||
sql = sql.replace(new RegExp("scenario = target_scenario",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_increment",'g'),req.body.amount);
|
||||
sql = sql.replace(new RegExp("target_month",'g'),req.body.month);
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_iteration",'g'),"tool volume");
|
||||
sql = sql.replace(new RegExp("replace_iterdet",'g'),"addmonth_vd");
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
//console.log(sql);
|
||||
console.log(sql)
|
||||
Postgres.FirstRow(sql,[],res)
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,11 @@
|
||||
"ship_month": "Mar",
|
||||
"order_season": 2019,
|
||||
"order_month": "Mar",
|
||||
"version": "9p3"
|
||||
},
|
||||
"version": "9p3",
|
||||
"iter": [
|
||||
"forecast"
|
||||
],
|
||||
]
|
||||
},
|
||||
"adj_amount": -1248994,
|
||||
"adj_qty": -2828623,
|
||||
"tar_amount": 5335749,
|
||||
|
@ -213,8 +213,6 @@ SELECT
|
||||
,null::date adj_orderdate --history
|
||||
,null::date adj_requestdate --history
|
||||
,null::date adj_shipdate --history
|
||||
,'b20' "version" --calculated
|
||||
,'adjustment' iter --calculated
|
||||
---------------ui columns-------------------------
|
||||
,null::numeric order_season
|
||||
,null::text order_month
|
||||
@ -251,8 +249,6 @@ SELECT
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
-----------------additional params-------------------
|
||||
AND version = 'b20'
|
||||
AND iter = 'copy'
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
GROUP BY
|
||||
@ -398,11 +394,11 @@ SELECT
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
|
||||
,b.version --calculated
|
||||
,b.iter --calculated
|
||||
,'replace_version' "version" --calculated
|
||||
,'replace_iteration' iter --calculated
|
||||
-----------------------ui columns--------------------------------
|
||||
,'adjust volume' iterdet
|
||||
,null::jsonb iterdef
|
||||
,'replace_iterdet' iterdet
|
||||
,$$replace_iterdef$$::jsonb iterdef
|
||||
,od.ssyr order_season
|
||||
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
|
||||
,sd.ssyr ship_season
|
||||
|
@ -71,12 +71,12 @@ GROUP BY
|
||||
,seq
|
||||
,SUM(units) FILTER (WHERE order_season = 2019) "2019 qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2020 AND iter = 'copy') "2020 base qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2020 AND iter = 'adjustment') "2020 adj qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2020 AND iter IN ('copy','adjustment')) "2020 tot qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2020 AND iter <> 'copy') "2020 adj qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2020) "2020 tot qty"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2019) "2019 value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2020 AND iter = 'copy') "2020 base value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2020 AND iter = 'adjustment') "2020 adj value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2020 AND iter IN ('copy','adjustment')) "2020 tot value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2020 AND iter <> 'copy') "2020 adj value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2020) "2020 tot value_usd"
|
||||
FROM
|
||||
months
|
||||
GROUP BY
|
||||
|
Loading…
Reference in New Issue
Block a user