Compare commits
5 Commits
994a1027df
...
e54e2eb05c
Author | SHA1 | Date | |
---|---|---|---|
e54e2eb05c | |||
078d8294c4 | |||
39a8454b0e | |||
4ed3f11bd8 | |||
624ffca813 |
2
curl
2
curl
@ -1 +1 @@
|
|||||||
curl -H Content-Type: application/json -X GET -d@./sample_request.json https://192.168.1.110:8082/baseline --insecure
|
curl -H "Content-Type: application/json" -X GET -d@./sample_request.json https://localhost:8082/baseline --insecure > baseline.sql
|
||||||
|
@ -77,7 +77,7 @@ SELECT
|
|||||||
ELSE
|
ELSE
|
||||||
--use the date key but increment by the target interval
|
--use the date key but increment by the target interval
|
||||||
--this assumes that the primary key for the func is a date, but it has to be or it wont join anyways
|
--this assumes that the primary key for the func is a date, but it has to be or it wont join anyways
|
||||||
'o.'||fkey||' + interval '||format('%L',_interval)
|
'o.'||fkey||' + interval '||format('%L',_interval) ||' AS '||fkey
|
||||||
END
|
END
|
||||||
ELSE
|
ELSE
|
||||||
'o.'||format('%I',cname)
|
'o.'||format('%I',cname)
|
||||||
@ -107,11 +107,11 @@ FROM
|
|||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
--base period orders booked....
|
--base period orders booked....
|
||||||
$$||_order_date||$$ BETWEEN [app_baseline_from_date] AND [app_baseline_to_date]
|
$$||_order_date||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date
|
||||||
--...or any open orders currently booked before cutoff....
|
--...or any open orders currently booked before cutoff....
|
||||||
OR ($$||_order_status||$$ IN ([app_openstatus_code]) and $$||_order_date||$$ <= [app_openorder_cutoff])
|
OR ($$||_order_status||$$ IN (app_openstatus_code) and $$||_order_date||$$ <= 'app_openorder_cutoff'::date)
|
||||||
--...or anything that shipped in that period
|
--...or anything that shipped in that period
|
||||||
OR ($$||_ship_date||$$ BETWEEN [app_baseline_from_date] AND [app_baseline_to_date])
|
OR ($$||_ship_date||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date)
|
||||||
)
|
)
|
||||||
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
||||||
$$::text
|
$$::text
|
||||||
@ -132,7 +132,7 @@ $$
|
|||||||
FROM
|
FROM
|
||||||
fc.live o$$||E'\n'||_perd_joins||$$
|
fc.live o$$||E'\n'||_perd_joins||$$
|
||||||
WHERE
|
WHERE
|
||||||
$$||_order_date||$$ BETWEEN [app_plug_fromdate] AND [app_plug_todate]
|
$$||_order_date||$$ BETWEEN 'app_plug_fromdate'::date AND 'app_plug_todate'::date
|
||||||
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
||||||
$$
|
$$
|
||||||
INTO
|
INTO
|
||||||
@ -141,8 +141,9 @@ INTO
|
|||||||
------------------------------copy a full year and increment by 1 year for the baseline-------------------------
|
------------------------------copy a full year and increment by 1 year for the baseline-------------------------
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
$$INSERT INTO
|
--$$INSERT INTO
|
||||||
fc.live
|
-- fc.live
|
||||||
|
$$,incr AS (
|
||||||
SELECT
|
SELECT
|
||||||
$$||_clist_inc||
|
$$||_clist_inc||
|
||||||
$$
|
$$
|
||||||
@ -150,9 +151,16 @@ SELECT
|
|||||||
,'baseline' iter
|
,'baseline' iter
|
||||||
FROM
|
FROM
|
||||||
baseline o$$||E'\n'||_perd_joins||$$
|
baseline o$$||E'\n'||_perd_joins||$$
|
||||||
|
)
|
||||||
|
INSERT INTO
|
||||||
|
fc.live
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
incr i
|
||||||
WHERE
|
WHERE
|
||||||
$$||_order_date||' >= [app_first_forecast_date]'||$$
|
i.$$||_order_date||$$ >= 'app_first_forecast_date'::date$$||$$
|
||||||
OR $$||_ship_date||' >= [app_first_forecast_date]'
|
OR i.$$||_ship_date||$$ >= 'app_first_forecast_date'::date$$
|
||||||
--any orders in the forecast period, or any sales in the forecast period (from open orders)
|
--any orders in the forecast period, or any sales in the forecast period (from open orders)
|
||||||
INTO
|
INTO
|
||||||
_baseline;
|
_baseline;
|
||||||
|
37
index.js
37
index.js
@ -62,22 +62,13 @@ server.get('/baseline', bodyParser.json(), function(req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//list of parameters that will need to be supplied from the app
|
var app_baseline_from_date = req.body.app_baseline_from_date;
|
||||||
//app_baseline_from_date
|
var app_baseline_to_date = req.body.app_baseline_to_date;
|
||||||
//app_baseline_to_date
|
var app_first_forecast_date = req.body.app_first_forecast_date;
|
||||||
//app_first_forecast_date
|
var app_openorder_cutoff = req.body.app_openorder_cutoff;
|
||||||
//app_openorder_cutoff
|
var app_plug_fromdate = req.body.app_plug_fromdate;
|
||||||
//app_openstatus_code
|
var app_plug_todate = req.body.app_plug_todate;
|
||||||
//app_plug_fromdate
|
var app_openstatus_code = req.body.app_openstatus_code;
|
||||||
//app_plug_todate
|
|
||||||
|
|
||||||
var app_baseline_from_date = '2020-06-01';
|
|
||||||
var app_baseline_to_date = '2020-09-30';
|
|
||||||
var app_first_forecast_date = '2021-06-01';
|
|
||||||
var app_openorder_cutoff = '2020-09-30';
|
|
||||||
var app_openstatus_code = "'OPEN','BACKORDER'";
|
|
||||||
var app_plug_fromdate = '2020-10-01';
|
|
||||||
var app_plug_todate = '2020-05-30';
|
|
||||||
|
|
||||||
var callback = function(arg) {
|
var callback = function(arg) {
|
||||||
sql = arg;
|
sql = arg;
|
||||||
@ -86,13 +77,13 @@ server.get('/baseline', bodyParser.json(), function(req, res) {
|
|||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//parse the where clause into the main sql statement
|
//parse the where clause into the main sql statement
|
||||||
//sql = sql.replace(new RegExp("where_clause", 'g'), w)
|
//sql = sql.replace(new RegExp("where_clause", 'g'), w)
|
||||||
sql = sql.replace(new RegExp("app_baseline_from_date"), app_baseline_from_date);
|
sql = sql.replace(new RegExp("app_baseline_from_date", 'g'), app_baseline_from_date);
|
||||||
sql = sql.replace(new RegExp("app_baseline_to_date"), app_baseline_from_date);
|
sql = sql.replace(new RegExp("app_baseline_to_date", 'g'), app_baseline_to_date);
|
||||||
sql = sql.replace(new RegExp("app_first_forecast_date"), app_first_forecast_date);
|
sql = sql.replace(new RegExp("app_first_forecast_date", 'g'), app_first_forecast_date);
|
||||||
sql = sql.replace(new RegExp("app_openorder_cutoff"), app_baseline_from_date);
|
sql = sql.replace(new RegExp("app_openorder_cutoff", 'g'), app_openorder_cutoff);
|
||||||
sql = sql.replace(new RegExp("app_openstatus_code"), app_baseline_from_date);
|
sql = sql.replace(new RegExp("app_openstatus_code", 'g'), app_openstatus_code);
|
||||||
sql = sql.replace(new RegExp("app_plug_fromdate"), app_plug_fromdate);
|
sql = sql.replace(new RegExp("app_plug_fromdate", 'g'), app_plug_fromdate);
|
||||||
sql = sql.replace(new RegExp("app_plug_todate"), app_plug_todate);
|
sql = sql.replace(new RegExp("app_plug_todate", 'g'), app_plug_todate);
|
||||||
//execute the sql and send the result
|
//execute the sql and send the result
|
||||||
args.push(req.body.app_baseline_from_date);
|
args.push(req.body.app_baseline_from_date);
|
||||||
console.log(sql);
|
console.log(sql);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"app_baseline_from_date":"2020-06-01",
|
"app_baseline_from_date":"2020-06-01",
|
||||||
"app_baseline_to_date":"2020-10-31",
|
"app_baseline_to_date":"2020-09-30",
|
||||||
"app_first_forecast_date":"2021-06-01",
|
"app_first_forecast_date":"2021-06-01",
|
||||||
"app_openorder_cutoff":"2020-10-31",
|
"app_openorder_cutoff":"2020-09-30",
|
||||||
"app_openstatus_code":["OPEN","BACKORDERD"],
|
"app_openstatus_code":"'OPEN','BACKORDERD'",
|
||||||
"app_plug_fromdate":"2020-11-01",
|
"app_plug_fromdate":"2019-10-01",
|
||||||
"app_plug_todate":"2020-05-31"
|
"app_plug_todate":"2020-05-31"
|
||||||
}
|
}
|
||||||
|
21
setup_sql/mapping.md
Normal file
21
setup_sql/mapping.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
| tname | cname | opos | func | fkey | pretty | dtype | mastcol | appcol | dateref |
|
||||||
|
| ------- | -------------- | ---- | ------------ | ------------ | ------ | ------- | -------------- | ------------ | ------- |
|
||||||
|
| fc.live | fb_cst_loc | 91 | cost | | | numeric | fb_cst_loc | | |
|
||||||
|
| fc.live | ship_cust | 36 | scust | scust | | text | ship_cust | | |
|
||||||
|
| fc.live | rdate | 98 | rdate | rdate | | date | drange | | |
|
||||||
|
| fc.live | geo | 42 | scust | | | text | geo | customer | |
|
||||||
|
| fc.live | part | 54 | item | item | | text | part | item | |
|
||||||
|
| fc.live | odate | 96 | odate | odate | | date | drange | order_date | |
|
||||||
|
| fc.live | sdate | 100 | sdate | sdate | | date | sdate | ship_date | |
|
||||||
|
| fc.live | oseas | 97 | odate | | | integer | ssyr | | ssyr |
|
||||||
|
| fc.live | calc_status | 94 | order_status | order_status | | text | calc_status | order_status | |
|
||||||
|
| fc.live | rseas | 99 | rdate | | | integer | ssyr | | ssyr |
|
||||||
|
| fc.live | sseas | 101 | sdate | | | integer | ssyr | | ssyr |
|
||||||
|
|
||||||
|
|
||||||
|
* func: table name of associated data
|
||||||
|
* fkey: primary key of assoicated dat
|
||||||
|
* pretty: display column name
|
||||||
|
* mastcol: associated table column reference (whats the point of this?)
|
||||||
|
* appcol: parameters that will have to be supplied but the application
|
||||||
|
* dateref:
|
Loading…
Reference in New Issue
Block a user