Compare commits

..

No commits in common. "73f7667ef7f1e432582a7535aad818ac59d6987a" and "15b515a5e173f01950e9500e96da174b22fd087d" have entirely different histories.

View File

@ -2,7 +2,6 @@ DO
$func$ $func$
DECLARE DECLARE
_clist text; _clist text;
_clist_inc text;
_ytdbody text; _ytdbody text;
_order_date text; _order_date text;
_ship_date text; _ship_date text;
@ -24,26 +23,12 @@ FROM
WHERE WHERE
func NOT IN ('version'); func NOT IN ('version');
---------------------------build column to increment dates--------------------------------
SELECT
string_agg(
format('%I',cname) || CASE WHEN func IN ('odate','sdate') AND dtype = 'date' THEN ' + interval ''1 year''' ELSE '' END,E'\n ,' ORDER BY opos ASC)
INTO
_clist_inc
FROM
fc.target_meta
WHERE
func NOT IN ('version');
--RAISE NOTICE 'build list: %',clist; --RAISE NOTICE 'build list: %',clist;
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'order_date') INTO _order_date; SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'order_date') INTO _order_date;
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'ship_date') INTO _ship_date; SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'ship_date') INTO _ship_date;
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'order_status') INTO _order_status; SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'order_status') INTO _order_status;
--------------------------------------clone the actual baseline-----------------------------------------------
SELECT SELECT
$a$SELECT $a$SELECT
$a$::text|| $a$::text||
@ -68,30 +53,26 @@ INTO
_ytdbody; _ytdbody;
--RAISE NOTICE '%', _ytdbody; --RAISE NOTICE '%', _ytdbody;
------------------------------------pull a plug from actuals to create a full year baseline------------------
SELECT SELECT
$$SELECT
$$||_clist_inc||
$$ $$
,'baseline' "version" ,'baseline' "version"
,'plug' iter ,'plug' iter
FROM FROM
rlarp.osm_dev o rlarp.osm_dev o
LEFT OUTER JOIN gld ON
gld.fspr = o.fspr
LEFT OUTER JOIN gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
WHERE WHERE
$$||_order_date||$$ BETWEEN [app_plug_fromdate] AND [app_plug_todate] [target_odate] BETWEEN [target_odate_plug_from] AND [target_odate_plug_to]
--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
_actpy; _actpy;
------------------------------stack the sql into the final format------------------------------------------------
SELECT SELECT
_ytdbody|| _ytdbody
$$UNION ALL ||$$UNION ALL
$$||_actpy $$||_actpy
INTO INTO
_sql; _sql;