baseline functional, but json doesn't look correct in fc.log or the sql
This commit is contained in:
		
							parent
							
								
									a0fb500f29
								
							
						
					
					
						commit
						9c6ed6b304
					
				
							
								
								
									
										3
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								index.js
									
									
									
									
									
								
							@ -55,7 +55,7 @@ server.get('/baseline', bodyParser.json(), function(req, res) {
 | 
				
			|||||||
    var path = './routes/baseline/baseline.sql';
 | 
					    var path = './routes/baseline/baseline.sql';
 | 
				
			||||||
    var args = [];
 | 
					    var args = [];
 | 
				
			||||||
   
 | 
					   
 | 
				
			||||||
 | 
					    var app_req                      =  JSON.stringify(req.body);
 | 
				
			||||||
    var app_baseline_from_date =        req.body.app_baseline_from_date;
 | 
					    var app_baseline_from_date =        req.body.app_baseline_from_date;
 | 
				
			||||||
    var app_baseline_to_date =          req.body.app_baseline_to_date;
 | 
					    var app_baseline_to_date =          req.body.app_baseline_to_date;
 | 
				
			||||||
    var app_first_forecast_date =       req.body.app_first_forecast_date;
 | 
					    var app_first_forecast_date =       req.body.app_first_forecast_date;
 | 
				
			||||||
@ -71,6 +71,7 @@ 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_req", 'g'),                   app_req);
 | 
				
			||||||
        sql = sql.replace(new RegExp("app_baseline_from_date", 'g'),    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", 'g'),      app_baseline_to_date);
 | 
					        sql = sql.replace(new RegExp("app_baseline_to_date", 'g'),      app_baseline_to_date);
 | 
				
			||||||
        sql = sql.replace(new RegExp("app_first_forecast_date", 'g'),   app_first_forecast_date);
 | 
					        sql = sql.replace(new RegExp("app_first_forecast_date", 'g'),   app_first_forecast_date);
 | 
				
			||||||
 | 
				
			|||||||
@ -48,6 +48,7 @@ setup
 | 
				
			|||||||
    * logid   (added if missing)
 | 
					    * logid   (added if missing)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
issues
 | 
					issues
 | 
				
			||||||
 | 
					 - [ ] baseline request json is not depostiing correctly into the sql
 | 
				
			||||||
 - [ ] what if you create a func table but some of the values are null? (orders without quotes)
 | 
					 - [ ] what if you create a func table but some of the values are null? (orders without quotes)
 | 
				
			||||||
 - [x] what if you want certain things like invoice numbers included in the baseline, is a func table necesary? no, just leave fkey null and no table will be setup
 | 
					 - [x] what if you want certain things like invoice numbers included in the baseline, is a func table necesary? no, just leave fkey null and no table will be setup
 | 
				
			||||||
 - [ ] baseline needs to populate all columns in sequential order like the scale route
 | 
					 - [ ] baseline needs to populate all columns in sequential order like the scale route
 | 
				
			||||||
 | 
				
			|||||||
@ -1,20 +1,30 @@
 | 
				
			|||||||
DELETE FROM tpsv.dcard WHERE app_version = 'app_forecast_name';
 | 
					DELETE FROM tpsv.dcard WHERE app_version = 'app_forecast_name';
 | 
				
			||||||
WITH
 | 
					WITH
 | 
				
			||||||
baseline AS (
 | 
					req AS  (SELECT $$app_req$$::jsonb j)
 | 
				
			||||||
 | 
					,ilog AS (
 | 
				
			||||||
 | 
					    INSERT INTO
 | 
				
			||||||
 | 
					        fc.log (doc)
 | 
				
			||||||
 | 
					    SELECT
 | 
				
			||||||
 | 
					        req.j 
 | 
				
			||||||
 | 
					    FROM
 | 
				
			||||||
 | 
					        req
 | 
				
			||||||
 | 
					    RETURNING *
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					,baseline AS (
 | 
				
			||||||
SELECT
 | 
					SELECT
 | 
				
			||||||
    o.id
 | 
					    null::integer AS id
 | 
				
			||||||
    ,o.logid
 | 
					    ,null::integer AS logid
 | 
				
			||||||
    ,o."Trans. Date"
 | 
					    ,o."Trans. Date"
 | 
				
			||||||
    ,o."Post Date"
 | 
					    ,o."Post Date"
 | 
				
			||||||
    ,o."Description"
 | 
					    ,o."Description"
 | 
				
			||||||
    ,o."Amount"
 | 
					    ,sum(o."Amount") AS "Amount"
 | 
				
			||||||
    ,o."Category"
 | 
					    ,o."Category"
 | 
				
			||||||
    ,o."Party"
 | 
					    ,o."Party"
 | 
				
			||||||
    ,o."Reason"
 | 
					    ,o."Reason"
 | 
				
			||||||
    ,o.app_units
 | 
					    ,sum(o.app_units) AS app_units
 | 
				
			||||||
    ,'app_forecast_name' "version"
 | 
					    ,'app_forecast_name' AS app_version
 | 
				
			||||||
    ,'actuals' iter
 | 
					    ,'baseline' AS app_iter
 | 
				
			||||||
    ,null::bigint app_logid
 | 
					    ,(SELECT id FROM ilog) AS app_logid
 | 
				
			||||||
FROM
 | 
					FROM
 | 
				
			||||||
    tpsv.dcard o
 | 
					    tpsv.dcard o
 | 
				
			||||||
WHERE
 | 
					WHERE
 | 
				
			||||||
@ -27,52 +37,72 @@ WHERE
 | 
				
			|||||||
        OR ("Post Date" BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date)
 | 
					        OR ("Post 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
 | 
				
			||||||
UNION ALL
 | 
					GROUP BY
 | 
				
			||||||
SELECT
 | 
					    o."Trans. Date"
 | 
				
			||||||
    o.id
 | 
					    ,o."Post Date"
 | 
				
			||||||
    ,o.logid
 | 
					 | 
				
			||||||
    ,o."Trans. Date" + interval '1 year' AS "Trans. Date"
 | 
					 | 
				
			||||||
    ,o."Post Date" + interval '1 year' AS "Post Date"
 | 
					 | 
				
			||||||
    ,o."Description"
 | 
					    ,o."Description"
 | 
				
			||||||
    ,o."Amount"
 | 
					 | 
				
			||||||
    ,o."Category"
 | 
					    ,o."Category"
 | 
				
			||||||
    ,o."Party"
 | 
					    ,o."Party"
 | 
				
			||||||
    ,o."Reason"
 | 
					    ,o."Reason"
 | 
				
			||||||
    ,o.app_units
 | 
					UNION ALL
 | 
				
			||||||
    ,'app_forecast_name' "version"
 | 
					SELECT
 | 
				
			||||||
    ,'plug' iter
 | 
					    null::integer AS id
 | 
				
			||||||
    ,null::bigint app_logid
 | 
					    ,null::integer AS logid
 | 
				
			||||||
 | 
					    ,o."Trans. Date" + interval '1 year' AS "Trans. Date"
 | 
				
			||||||
 | 
					    ,o."Post Date" + interval '1 year' AS "Post Date"
 | 
				
			||||||
 | 
					    ,o."Description"
 | 
				
			||||||
 | 
					    ,sum(o."Amount") AS "Amount"
 | 
				
			||||||
 | 
					    ,o."Category"
 | 
				
			||||||
 | 
					    ,o."Party"
 | 
				
			||||||
 | 
					    ,o."Reason"
 | 
				
			||||||
 | 
					    ,sum(o.app_units) AS app_units
 | 
				
			||||||
 | 
					    ,'app_forecast_name' AS app_version
 | 
				
			||||||
 | 
					    ,'baseline' AS app_iter
 | 
				
			||||||
 | 
					    ,(SELECT id FROM ilog) AS app_logid
 | 
				
			||||||
FROM
 | 
					FROM
 | 
				
			||||||
    tpsv.dcard o
 | 
					    tpsv.dcard o
 | 
				
			||||||
LEFT OUTER JOIN fc.perd pdate ON
 | 
					    LEFT OUTER JOIN fc.perd tdate ON
 | 
				
			||||||
        (o."Post Date" + interval '1 year' )::date <@ pdate.drange
 | 
					 | 
				
			||||||
LEFT OUTER JOIN fc.perd tdate ON
 | 
					 | 
				
			||||||
        (o."Trans. Date" + interval '1 year' )::date <@ tdate.drange
 | 
					        (o."Trans. Date" + interval '1 year' )::date <@ tdate.drange
 | 
				
			||||||
 | 
					    LEFT OUTER JOIN fc.perd pdate ON
 | 
				
			||||||
 | 
					        (o."Post Date" + interval '1 year' )::date <@ pdate.drange
 | 
				
			||||||
WHERE
 | 
					WHERE
 | 
				
			||||||
    "Trans. Date" BETWEEN 'app_plug_fromdate'::date AND 'app_plug_todate'::date
 | 
					    "Trans. 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
 | 
				
			||||||
)
 | 
					GROUP BY
 | 
				
			||||||
 | 
					    o."Trans. Date"
 | 
				
			||||||
 | 
					    ,o."Post Date"
 | 
				
			||||||
 | 
					    ,o."Description"
 | 
				
			||||||
 | 
					    ,o."Category"
 | 
				
			||||||
 | 
					    ,o."Party"
 | 
				
			||||||
 | 
					    ,o."Reason")
 | 
				
			||||||
,incr AS (
 | 
					,incr AS (
 | 
				
			||||||
SELECT
 | 
					SELECT
 | 
				
			||||||
    o.id
 | 
					    null::integer AS id
 | 
				
			||||||
    ,o.logid
 | 
					    ,null::integer AS logid
 | 
				
			||||||
    ,o."Trans. Date" + interval '1 year' AS "Trans. Date"
 | 
					    ,o."Trans. Date" + interval '1 year' AS "Trans. Date"
 | 
				
			||||||
    ,o."Post Date" + interval '1 year' AS "Post Date"
 | 
					    ,o."Post Date" + interval '1 year' AS "Post Date"
 | 
				
			||||||
    ,o."Description"
 | 
					    ,o."Description"
 | 
				
			||||||
    ,o."Amount"
 | 
					    ,sum(o."Amount") AS "Amount"
 | 
				
			||||||
    ,o."Category"
 | 
					    ,o."Category"
 | 
				
			||||||
    ,o."Party"
 | 
					    ,o."Party"
 | 
				
			||||||
    ,o."Reason"
 | 
					    ,o."Reason"
 | 
				
			||||||
    ,o.app_units
 | 
					    ,sum(o.app_units) AS app_units
 | 
				
			||||||
    ,'app_forecast_name' "version"
 | 
					    ,'app_forecast_name' AS app_version
 | 
				
			||||||
    ,'baseline' iter
 | 
					    ,'baseline' AS app_iter
 | 
				
			||||||
    ,null::bigint app_logid
 | 
					    ,(SELECT id FROM ilog) AS app_logid
 | 
				
			||||||
FROM
 | 
					FROM
 | 
				
			||||||
    baseline o
 | 
					    baseline o
 | 
				
			||||||
LEFT OUTER JOIN fc.perd pdate ON
 | 
					 | 
				
			||||||
        (o."Post Date" + interval '1 year' )::date <@ pdate.drange
 | 
					 | 
				
			||||||
LEFT OUTER JOIN fc.perd tdate ON
 | 
					LEFT OUTER JOIN fc.perd tdate ON
 | 
				
			||||||
        (o."Trans. Date" + interval '1 year' )::date <@ tdate.drange
 | 
					        (o."Trans. Date" + interval '1 year' )::date <@ tdate.drange
 | 
				
			||||||
 | 
					    LEFT OUTER JOIN fc.perd pdate ON
 | 
				
			||||||
 | 
					        (o."Post Date" + interval '1 year' )::date <@ pdate.drange
 | 
				
			||||||
 | 
					GROUP BY
 | 
				
			||||||
 | 
					    o."Trans. Date"
 | 
				
			||||||
 | 
					    ,o."Post Date"
 | 
				
			||||||
 | 
					    ,o."Description"
 | 
				
			||||||
 | 
					    ,o."Category"
 | 
				
			||||||
 | 
					    ,o."Party"
 | 
				
			||||||
 | 
					    ,o."Reason"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
,ins AS (
 | 
					,ins AS (
 | 
				
			||||||
INSERT INTO
 | 
					INSERT INTO
 | 
				
			||||||
 | 
				
			|||||||
@ -219,13 +219,11 @@ SELECT
 | 
				
			|||||||
--    fc.live
 | 
					--    fc.live
 | 
				
			||||||
$$,incr AS (
 | 
					$$,incr AS (
 | 
				
			||||||
SELECT
 | 
					SELECT
 | 
				
			||||||
    $$||_clist_inc||
 | 
					    $$||_clist_inc||$$
 | 
				
			||||||
    $$
 | 
					 | 
				
			||||||
    ,'app_forecast_name' "version"
 | 
					 | 
				
			||||||
    ,'baseline' iter
 | 
					 | 
				
			||||||
    ,null::bigint app_logid
 | 
					 | 
				
			||||||
FROM
 | 
					FROM
 | 
				
			||||||
    baseline o$$||E'\n'||_perd_joins||$$
 | 
					    baseline o$$||E'\n'||_perd_joins||$$
 | 
				
			||||||
 | 
					GROUP BY
 | 
				
			||||||
 | 
					    $$||_clist_group||$$
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
,ins AS (
 | 
					,ins AS (
 | 
				
			||||||
INSERT INTO
 | 
					INSERT INTO
 | 
				
			||||||
@ -251,7 +249,8 @@ RAISE NOTICE E'_baseline -------> \n%',_baseline;
 | 
				
			|||||||
SELECT
 | 
					SELECT
 | 
				
			||||||
$$DELETE FROM $$||_target_table||$$ WHERE $$||_version_col||$$ = 'app_forecast_name';
 | 
					$$DELETE FROM $$||_target_table||$$ WHERE $$||_version_col||$$ = 'app_forecast_name';
 | 
				
			||||||
WITH
 | 
					WITH
 | 
				
			||||||
ilog AS (
 | 
					req AS  (SELECT $$||'$$app_req$$::jsonb j)'||$$
 | 
				
			||||||
 | 
					,ilog AS (
 | 
				
			||||||
    INSERT INTO
 | 
					    INSERT INTO
 | 
				
			||||||
        fc.log (doc)
 | 
					        fc.log (doc)
 | 
				
			||||||
    SELECT
 | 
					    SELECT
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user