temp price factor
This commit is contained in:
parent
959d858b10
commit
0e904c1631
@ -1,36 +1,34 @@
|
|||||||
DO
|
DO
|
||||||
$func$
|
$func$
|
||||||
DECLARE
|
DECLARE
|
||||||
_clist text;
|
_clist_all text; --all columns
|
||||||
_clist_vol text;
|
_clist_sum text; --group away forecast iteration rows
|
||||||
_clist_prc text;
|
_clist_group text; --group away forecast iteration rows
|
||||||
_clist_inc text;
|
_clist_vol text; --volume columns scaled
|
||||||
_ytdbody text;
|
_clist_prc text; --price columns scaled
|
||||||
|
_target_table text;
|
||||||
_order_date text;
|
_order_date text;
|
||||||
_ship_date text;
|
_ship_date text;
|
||||||
_order_status text;
|
_order_status text;
|
||||||
_actpy text;
|
|
||||||
_sql text;
|
|
||||||
_target_table text;
|
|
||||||
_version_col text;
|
_version_col text;
|
||||||
_baseline text;
|
_iter_col text;
|
||||||
_date_funcs jsonb;
|
_logid_col text;
|
||||||
_perd_joins text;
|
|
||||||
_interval interval;
|
|
||||||
_units_col text;
|
_units_col text;
|
||||||
_value_col text;
|
_value_col text;
|
||||||
|
_sql text;
|
||||||
|
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
-----------------populate application variables--------------------------------------------
|
-----------------populate application variables--------------------------------------------
|
||||||
--need a handler if any of these are not specified--
|
SELECT cname INTO _order_date FROM fc.target_meta WHERE appcol = 'order_date' ;
|
||||||
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'order_date') INTO _order_date;
|
SELECT cname INTO _ship_date FROM fc.target_meta WHERE appcol = 'ship_date' ;
|
||||||
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'ship_date') INTO _ship_date;
|
SELECT cname INTO _order_status FROM fc.target_meta WHERE appcol = 'order_status' ;
|
||||||
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'order_status') INTO _order_status;
|
SELECT cname INTO _units_col FROM fc.target_meta WHERE appcol = 'units' ;
|
||||||
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'units') INTO _units_col;
|
SELECT cname INTO _value_col FROM fc.target_meta WHERE appcol = 'value' ;
|
||||||
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'value') INTO _value_col;
|
SELECT cname INTO _version_col FROM fc.target_meta WHERE appcol = 'version' ;
|
||||||
|
SELECT cname INTO _iter_col FROM fc.target_meta WHERE appcol = 'iter' ;
|
||||||
|
SELECT cname INTO _logid_col FROM fc.target_meta WHERE appcol = 'logid' ;
|
||||||
SELECT format('%I',max(schema))||'.'||format('%I',max(tname)) INTO _target_table FROM fc.target_meta;
|
SELECT format('%I',max(schema))||'.'||format('%I',max(tname)) INTO _target_table FROM fc.target_meta;
|
||||||
SELECT cname INTO _version_col FROM fc.target_meta WHERE appcol = 'version';
|
|
||||||
|
|
||||||
RAISE NOTICE '_order_date; %', _order_date;
|
RAISE NOTICE '_order_date; %', _order_date;
|
||||||
RAISE NOTICE '_ship_date; %', _ship_date;
|
RAISE NOTICE '_ship_date; %', _ship_date;
|
||||||
@ -39,59 +37,110 @@ RAISE NOTICE '_units_col; %', _units_col;
|
|||||||
RAISE NOTICE '_value_col; %', _value_col;
|
RAISE NOTICE '_value_col; %', _value_col;
|
||||||
RAISE NOTICE '_target_table;%', _target_table;
|
RAISE NOTICE '_target_table;%', _target_table;
|
||||||
RAISE NOTICE '_version_col; %', _version_col;
|
RAISE NOTICE '_version_col; %', _version_col;
|
||||||
|
RAISE NOTICE '_iter_col; %', _iter_col;
|
||||||
|
RAISE NOTICE '_logid_col; %', _logid_col;
|
||||||
-------------------------all columns ------------------------------------------------------
|
-------------------------all columns ------------------------------------------------------
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
string_agg('o.'||format('%I',cname),E'\n ,' ORDER BY opos ASC)
|
string_agg('o.'||format('%I',cname),E'\n ,' ORDER BY opos ASC)
|
||||||
INTO
|
INTO
|
||||||
_clist
|
_clist_all
|
||||||
FROM
|
FROM
|
||||||
fc.target_meta
|
fc.target_meta;
|
||||||
WHERE
|
|
||||||
COALESCE(appcol,'') NOT IN ('version','iter','logid');
|
|
||||||
|
|
||||||
RAISE NOTICE 'all columns %', _clist;
|
-------------------------basemix sum columns-----------------------------------------------
|
||||||
|
|
||||||
-------------------------all columns except volume scale-----------------------------------
|
|
||||||
SELECT
|
SELECT
|
||||||
string_agg(
|
string_agg(
|
||||||
--create the column reference
|
--create the column reference
|
||||||
'o.'||format('%I',cname)||
|
CASE appcol
|
||||||
CASE WHEN appcol IN ('units', 'value', 'cost') THEN ' * vscale.factor AS '||format('%I',cname) ELSE '' END,
|
WHEN 'units' THEN 'sum(o.'||format('%I',cname)||') AS '||format('%I',cname)
|
||||||
|
WHEN 'value' THEN 'sum(o.'||format('%I',cname)||') AS '||format('%I',cname)
|
||||||
|
WHEN 'cost' THEN 'sum(o.'||format('%I',cname)||') AS '||format('%I',cname)
|
||||||
|
---if basemix is used in price or volume, these columns are overridden anyways---
|
||||||
|
WHEN 'version' THEN '''app_forecast_name'' AS '||format('%I',_version_col)
|
||||||
|
WHEN 'iter' THEN '''scale'' AS '||format('%I',_iter_col)
|
||||||
|
WHEN 'logid' THEN '0::bigint AS '||format('%I',_logid_col)
|
||||||
|
ELSE 'o.'||format('%I',cname)
|
||||||
|
END
|
||||||
--delimiter
|
--delimiter
|
||||||
E'\n ,'
|
,E'\n ,'
|
||||||
|
--sort column ordinal
|
||||||
|
ORDER BY opos ASC
|
||||||
|
)
|
||||||
|
INTO
|
||||||
|
_clist_sum
|
||||||
|
FROM
|
||||||
|
fc.target_meta;
|
||||||
|
|
||||||
|
RAISE NOTICE 'sumation columns %', _clist_sum;
|
||||||
|
|
||||||
|
-------------------------basemix group by columns------------------------------------------
|
||||||
|
SELECT
|
||||||
|
string_agg(
|
||||||
|
--create the column reference
|
||||||
|
'o.'||format('%I',cname)
|
||||||
|
--delimiter
|
||||||
|
,E'\n ,'
|
||||||
|
--sort column ordinal
|
||||||
|
ORDER BY opos ASC
|
||||||
|
)
|
||||||
|
INTO
|
||||||
|
_clist_group
|
||||||
|
FROM
|
||||||
|
fc.target_meta
|
||||||
|
WHERE
|
||||||
|
COALESCe(appcol,'') NOT IN ('version','iter','logid','value','cost','units');
|
||||||
|
|
||||||
|
RAISE NOTICE 'sumation columns %', _clist_group;
|
||||||
|
|
||||||
|
-------------------------all columns as-is except volume types which need scaled-----------------------------------
|
||||||
|
SELECT
|
||||||
|
string_agg(
|
||||||
|
--create the column reference
|
||||||
|
CASE appcol
|
||||||
|
----calculation should yield the value necessary to get to the target increment value------------
|
||||||
|
WHEN 'units' THEN 'o.'||format('%I',cname)||' * vscale.factor AS '||format('%I',cname)
|
||||||
|
WHEN 'value' THEN 'o.'||format('%I',cname)||' * vscale.factor AS '||format('%I',cname)
|
||||||
|
WHEN 'cost' THEN 'o.'||format('%I',cname)||' * vscale.factor AS '||format('%I',cname)
|
||||||
|
WHEN 'version' THEN '''app_forecast_name'' AS '||format('%I',_version_col)
|
||||||
|
WHEN 'iter' THEN '''scale volume'' AS '||format('%I',_iter_col)
|
||||||
|
WHEN 'logid' THEN '(SELECT id FROM ilog) AS '||format('%I',_logid_col)
|
||||||
|
ELSE 'o.'||format('%I',cname)
|
||||||
|
END
|
||||||
|
--delimiter
|
||||||
|
,E'\n ,'
|
||||||
--sort column ordinal
|
--sort column ordinal
|
||||||
ORDER BY opos ASC
|
ORDER BY opos ASC
|
||||||
)
|
)
|
||||||
INTO
|
INTO
|
||||||
_clist_vol
|
_clist_vol
|
||||||
FROM
|
FROM
|
||||||
fc.target_meta
|
fc.target_meta;
|
||||||
WHERE
|
|
||||||
COALESCE(appcol,'') NOT IN ('version','iter','logid');
|
|
||||||
|
|
||||||
RAISE NOTICE ' all columns plus scale volume columns %', _clist_vol;
|
RAISE NOTICE ' all columns plus scale volume columns %', _clist_vol;
|
||||||
|
|
||||||
-------------------------all columns except volume scale-----------------------------------
|
-------------------------all columns with price types getting scaled-----------------------------------
|
||||||
SELECT
|
SELECT
|
||||||
string_agg(
|
string_agg(
|
||||||
--create the column reference
|
--create the column reference
|
||||||
CASE
|
CASE appcol
|
||||||
WHEN appcol IN ('units', 'cost') THEN '0::numeric'
|
WHEN 'units' THEN '0::numeric AS '||format('%I',cname)
|
||||||
WHEN appcol IN ('value') THEN $$(CASE WHEN pscale.factor = 0 THEN o.$$||_units_col||$$ * pscale.mod_price ELSE o.$$||format('%I',cname)||' * pscale.factor END)::numeric AS '||_value_col
|
WHEN 'cost' THEN '0::numeric AS '||format('%I',cname)
|
||||||
|
WHEN 'value' THEN $$(CASE WHEN pscale.factor = 0 THEN o.$$||_units_col||$$ * pscale.mod_price ELSE o.$$||format('%I',cname)||' * pscale.factor END)::numeric AS '||format('%I',cname)
|
||||||
|
WHEN 'version' THEN '''app_forecast_name'' AS '||format('%I',_version_col)
|
||||||
|
WHEN 'iter' THEN '''scale volume'' AS '||format('%I',_iter_col)
|
||||||
|
WHEN 'logid' THEN '(SELECT id FROM ilog) AS '||format('%I',_logid_col)
|
||||||
ELSE 'o.'||format('%I',cname)
|
ELSE 'o.'||format('%I',cname)
|
||||||
END,
|
END
|
||||||
--delimiter
|
--delimiter
|
||||||
E'\n ,'
|
,E'\n ,'
|
||||||
--sort column ordinal
|
--sort column ordinal
|
||||||
ORDER BY opos ASC
|
ORDER BY opos ASC
|
||||||
)
|
)
|
||||||
INTO
|
INTO
|
||||||
_clist_prc
|
_clist_prc
|
||||||
FROM
|
FROM
|
||||||
fc.target_meta
|
fc.target_meta;
|
||||||
WHERE
|
|
||||||
COALESCE(appcol,'') NOT IN ('version','iter','logid');
|
|
||||||
|
|
||||||
RAISE NOTICE 'all columns plus scale price %', _clist_prc;
|
RAISE NOTICE 'all columns plus scale price %', _clist_prc;
|
||||||
|
|
||||||
@ -109,20 +158,32 @@ req AS (SELECT $$||'$$app_req$$::jsonb j)'||$$
|
|||||||
-----this block is supposed to test for new products that might not be in baseline etc-------
|
-----this block is supposed to test for new products that might not be in baseline etc-------
|
||||||
,test AS (
|
,test AS (
|
||||||
SELECT
|
SELECT
|
||||||
sum($$||_units_col||$$) FILTER (WHERE version <> 'ACTUALS') total
|
sum($$||_units_col||$$) FILTER (WHERE $$||format('%I',_iter_col)||$$ <> 'ACTUALS') total
|
||||||
,sum($$||_units_col||$$) FILTER (WHERE iter = 'baseline') base
|
,sum($$||_units_col||$$) FILTER (WHERE $$||format('%I',_iter_col)||$$ = 'baseline') base
|
||||||
FROM
|
FROM
|
||||||
$$||_target_table||$$ o
|
$$||_target_table||$$ o
|
||||||
WHERE
|
WHERE
|
||||||
app_where
|
app_where
|
||||||
)
|
)
|
||||||
|
,ilog AS (
|
||||||
|
INSERT INTO
|
||||||
|
fc.log (doc)
|
||||||
|
SELECT
|
||||||
|
req.j
|
||||||
|
FROM
|
||||||
|
req
|
||||||
|
RETURNING *
|
||||||
|
)
|
||||||
|
------need to group basemix and forego any detail iterations
|
||||||
,basemix AS (
|
,basemix AS (
|
||||||
SELECT
|
SELECT
|
||||||
$$||_clist||$$
|
$$||_clist_sum||$$
|
||||||
FROM
|
FROM
|
||||||
$$||_target_table||$$ o
|
$$||_target_table||$$ o
|
||||||
WHERE
|
WHERE
|
||||||
app_where
|
app_where
|
||||||
|
GROUP BY
|
||||||
|
$$||_clist_group||$$
|
||||||
),
|
),
|
||||||
vscale AS (
|
vscale AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -132,52 +193,34 @@ vscale AS (
|
|||||||
FROM
|
FROM
|
||||||
basemix
|
basemix
|
||||||
)
|
)
|
||||||
,ilog AS (
|
,volume_only AS (
|
||||||
INSERT INTO
|
|
||||||
fc.log (doc)
|
|
||||||
SELECT
|
|
||||||
req.j
|
|
||||||
FROM
|
|
||||||
req
|
|
||||||
)
|
|
||||||
,volume AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
$$||_clist_vol||$$
|
$$||_clist_vol||$$
|
||||||
,'app_forecast_name' AS version
|
|
||||||
,'scale vol' AS iter
|
|
||||||
FROM
|
FROM
|
||||||
basemix o
|
basemix o
|
||||||
CROSS JOIN vscale
|
CROSS JOIN vscale
|
||||||
|
WHERE
|
||||||
|
vscale.factor <> 0
|
||||||
|
)
|
||||||
|
,volume AS (
|
||||||
|
SELECT * FROM volume_only
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM baseline WHERE (SELECT COUNT(*) FROM volume_only) = 0
|
||||||
)
|
)
|
||||||
,pscale AS (
|
,pscale AS (
|
||||||
SELECT
|
----what if the selection has several value columns, which one to use?-----
|
||||||
|
SELECT
|
||||||
(SELECT pincr FROM target) AS target_increment
|
(SELECT pincr FROM target) AS target_increment
|
||||||
,sum($$||format('%I',_value_col)||') AS value'||$$
|
,sum("Amount") AS value
|
||||||
,CASE WHEN (SELECT sum($$||format('%I',_value_col)||$$) FROM volume) = 0 THEN
|
,CASE WHEN (SELECT vscale.
|
||||||
--if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
|
((SELECT pincr FROM target)-(SELECT sum("Amount") FROM volume))/(SELECT sum("Amount") FROM volume)
|
||||||
0
|
,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN 0 ELSE (SELECT pincr FROM target)/sum("Amount") FROM volume END factor
|
||||||
ELSE
|
FROM
|
||||||
--if the target dollar value still does not match the target increment, make this adjustment
|
|
||||||
((SELECT pincr FROM target)-(SELECT sum($$||format('%I',_value_col)||$$) FROM volume))/(SELECT sum($$||format('%I',_value_col)||$$) FROM volume)
|
|
||||||
END factor
|
|
||||||
,CASE WHEN (SELECT sum($$||format('%I',_value_col)||$$) FROM volume) = 0 THEN
|
|
||||||
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum($$||format('%I',_value_col)||$$) FROM volume)) <> 0 THEN
|
|
||||||
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply
|
|
||||||
((SELECT pincr::numeric FROM target) - (SELECT sum($$||format('%I',_value_col)||$$) FROM volume))/(SELECT sum($$||format('%I',_units_col)||$$) FROM volume)
|
|
||||||
ELSE
|
|
||||||
0
|
|
||||||
END
|
|
||||||
ELSE
|
|
||||||
0
|
|
||||||
END mod_price
|
|
||||||
FROM
|
|
||||||
volume
|
volume
|
||||||
)
|
)
|
||||||
,pricing AS (
|
,pricing AS (
|
||||||
SELECT
|
SELECT
|
||||||
$$||_clist_prc||$$
|
$$||_clist_prc||$$
|
||||||
,'app_forecast_name' AS version
|
|
||||||
,'scale price' AS iter
|
|
||||||
FROM
|
FROM
|
||||||
volume o
|
volume o
|
||||||
CROSS JOIN pscale
|
CROSS JOIN pscale
|
||||||
@ -185,7 +228,7 @@ WHERE
|
|||||||
pscale.factor <> 0 or pscale.mod_price <> 0
|
pscale.factor <> 0 or pscale.mod_price <> 0
|
||||||
)
|
)
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
$$||_target_table||$$ o
|
$$||_target_table||$$
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM
|
FROM
|
||||||
|
@ -10,13 +10,23 @@ req AS (SELECT $$app_req$$::jsonb j)
|
|||||||
-----this block is supposed to test for new products that might not be in baseline etc-------
|
-----this block is supposed to test for new products that might not be in baseline etc-------
|
||||||
,test AS (
|
,test AS (
|
||||||
SELECT
|
SELECT
|
||||||
sum(app_units) FILTER (WHERE version <> 'ACTUALS') total
|
sum(app_units) FILTER (WHERE app_iter <> 'ACTUALS') total
|
||||||
,sum(app_units) FILTER (WHERE iter = 'baseline') base
|
,sum(app_units) FILTER (WHERE app_iter = 'baseline') base
|
||||||
FROM
|
FROM
|
||||||
tpsv.dcard o
|
tpsv.dcard o
|
||||||
WHERE
|
WHERE
|
||||||
app_where
|
app_where
|
||||||
)
|
)
|
||||||
|
,ilog AS (
|
||||||
|
INSERT INTO
|
||||||
|
fc.log (doc)
|
||||||
|
SELECT
|
||||||
|
req.j
|
||||||
|
FROM
|
||||||
|
req
|
||||||
|
RETURNING *
|
||||||
|
)
|
||||||
|
------need to group basemix and forego any detail iterations
|
||||||
,basemix AS (
|
,basemix AS (
|
||||||
SELECT
|
SELECT
|
||||||
o.id
|
o.id
|
||||||
@ -24,15 +34,27 @@ SELECT
|
|||||||
,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
|
,'app_forecast_name' AS app_version
|
||||||
|
,'scale' AS app_iter
|
||||||
|
,0::bigint AS app_logid
|
||||||
|
,sum(o.app_units) AS app_units
|
||||||
FROM
|
FROM
|
||||||
tpsv.dcard o
|
tpsv.dcard o
|
||||||
WHERE
|
WHERE
|
||||||
app_where
|
app_where
|
||||||
|
GROUP BY
|
||||||
|
o.id
|
||||||
|
,o.logid
|
||||||
|
,o."Trans. Date"
|
||||||
|
,o."Post Date"
|
||||||
|
,o."Description"
|
||||||
|
,o."Category"
|
||||||
|
,o."Party"
|
||||||
|
,o."Reason"
|
||||||
),
|
),
|
||||||
vscale AS (
|
vscale AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -42,15 +64,7 @@ vscale AS (
|
|||||||
FROM
|
FROM
|
||||||
basemix
|
basemix
|
||||||
)
|
)
|
||||||
,ilog AS (
|
,volume_only AS (
|
||||||
INSERT INTO
|
|
||||||
fc.log (doc)
|
|
||||||
SELECT
|
|
||||||
req.j
|
|
||||||
FROM
|
|
||||||
req
|
|
||||||
)
|
|
||||||
,volume AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
o.id
|
o.id
|
||||||
,o.logid
|
,o.logid
|
||||||
@ -61,35 +75,28 @@ SELECT
|
|||||||
,o."Category"
|
,o."Category"
|
||||||
,o."Party"
|
,o."Party"
|
||||||
,o."Reason"
|
,o."Reason"
|
||||||
|
,'app_forecast_name' AS app_version
|
||||||
|
,'scale volume' AS app_iter
|
||||||
|
,(SELECT id FROM ilog) AS app_logid
|
||||||
,o.app_units * vscale.factor AS app_units
|
,o.app_units * vscale.factor AS app_units
|
||||||
,'app_forecast_name' AS version
|
|
||||||
,'scale vol' AS iter
|
|
||||||
FROM
|
FROM
|
||||||
basemix o
|
basemix o
|
||||||
CROSS JOIN vscale
|
CROSS JOIN vscale
|
||||||
|
WHERE
|
||||||
|
vscale.factor <> 0
|
||||||
|
)
|
||||||
|
,volume AS (
|
||||||
|
SELECT * FROM volume_only
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM baseline WHERE (SELECT COUNT(*) FROM volume_only) = 0
|
||||||
)
|
)
|
||||||
,pscale AS (
|
,pscale AS (
|
||||||
SELECT
|
----what if the selection has several value columns, which one to use?-----
|
||||||
|
SELECT
|
||||||
(SELECT pincr FROM target) AS target_increment
|
(SELECT pincr FROM target) AS target_increment
|
||||||
,sum("Amount") AS value
|
,sum("Amount") AS value
|
||||||
,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN
|
,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN 0 ELSE (SELECT pincr FROM target)/sum("Amount") FROM volume END factor
|
||||||
--if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
|
FROM
|
||||||
0
|
|
||||||
ELSE
|
|
||||||
--if the target dollar value still does not match the target increment, make this adjustment
|
|
||||||
((SELECT pincr FROM target)-(SELECT sum("Amount") FROM volume))/(SELECT sum("Amount") FROM volume)
|
|
||||||
END factor
|
|
||||||
,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN
|
|
||||||
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum("Amount") FROM volume)) <> 0 THEN
|
|
||||||
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply
|
|
||||||
((SELECT pincr::numeric FROM target) - (SELECT sum("Amount") FROM volume))/(SELECT sum(app_units) FROM volume)
|
|
||||||
ELSE
|
|
||||||
0
|
|
||||||
END
|
|
||||||
ELSE
|
|
||||||
0
|
|
||||||
END mod_price
|
|
||||||
FROM
|
|
||||||
volume
|
volume
|
||||||
)
|
)
|
||||||
,pricing AS (
|
,pricing AS (
|
||||||
@ -99,13 +106,14 @@ SELECT
|
|||||||
,o."Trans. Date"
|
,o."Trans. Date"
|
||||||
,o."Post Date"
|
,o."Post Date"
|
||||||
,o."Description"
|
,o."Description"
|
||||||
,(CASE WHEN pscale.factor = 0 THEN o.app_units * pscale.mod_price ELSE o."Amount" * pscale.factor END)::numeric AS Amount
|
,(CASE WHEN pscale.factor = 0 THEN o.app_units * pscale.mod_price ELSE o."Amount" * pscale.factor END)::numeric AS "Amount"
|
||||||
,o."Category"
|
,o."Category"
|
||||||
,o."Party"
|
,o."Party"
|
||||||
,o."Reason"
|
,o."Reason"
|
||||||
,0::numeric
|
,'app_forecast_name' AS app_version
|
||||||
,'app_forecast_name' AS version
|
,'scale volume' AS app_iter
|
||||||
,'scale price' AS iter
|
,(SELECT id FROM ilog) AS app_logid
|
||||||
|
,0::numeric AS app_units
|
||||||
FROM
|
FROM
|
||||||
volume o
|
volume o
|
||||||
CROSS JOIN pscale
|
CROSS JOIN pscale
|
||||||
@ -113,7 +121,7 @@ WHERE
|
|||||||
pscale.factor <> 0 or pscale.mod_price <> 0
|
pscale.factor <> 0 or pscale.mod_price <> 0
|
||||||
)
|
)
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
tpsv.dcard o
|
tpsv.dcard
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM
|
FROM
|
||||||
|
Loading…
Reference in New Issue
Block a user