commit: 2025-03-19 15:31:38
This commit is contained in:
parent
2a6419b386
commit
2941e0f3a4
@ -1,13 +1,13 @@
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
--\timing
|
--\timing
|
||||||
--CREATE TABLE IF NOT EXISTS rlarp.osmf_stage AS (SELECT * FROM rlarp.osmf_dev) WITH no data;
|
--CREATE TABLE IF NOT EXISTS rlarp.osmf_stage AS (SELECT * FROM rlarp.osmf_dev) WITH no data;
|
||||||
TRUNCATE TABLE rlarp.osmf_dev;
|
TRUNCATE TABLE rlarp.osmf;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS tdr;
|
DROP TABLE IF EXISTS tdr;
|
||||||
CREATE TEMP TABLE tdr AS (
|
CREATE TEMP TABLE tdr AS (
|
||||||
SELECT
|
SELECT
|
||||||
DATERANGE('2022-06-01','2023-06-01','[)') drange
|
DATERANGE('2024-06-01','2024-06-01','[)') drange
|
||||||
,DATERANGE(('2022-06-01'::date + '1 year'::interval)::date,('2023-06-01'::date + '1 year'::interval)::date,'[)') repl
|
,DATERANGE(('2024-06-01'::date + '1 year'::interval)::date,('2024-06-01'::date + '1 year'::interval)::date,'[)') repl
|
||||||
,'1 year'::interval AS incr
|
,'1 year'::interval AS incr
|
||||||
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter
|
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter
|
||||||
);
|
);
|
||||||
@ -148,7 +148,7 @@ gld AS (
|
|||||||
,'actuals' "version"
|
,'actuals' "version"
|
||||||
,'actuals' iter
|
,'actuals' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_dev o
|
rlarp.osm o
|
||||||
--snap the ship dates of the historic fiscal period
|
--snap the ship dates of the historic fiscal period
|
||||||
LEFT OUTER JOIN gld ON
|
LEFT OUTER JOIN gld ON
|
||||||
gld.fspr = o.fspr
|
gld.fspr = o.fspr
|
||||||
@ -295,7 +295,7 @@ SELECT
|
|||||||
,o.rseas + 1 rseas --incremented
|
,o.rseas + 1 rseas --incremented
|
||||||
,(o.sdate + interval '1 year')::date sdate --incremented
|
,(o.sdate + interval '1 year')::date sdate --incremented
|
||||||
,o.sseas + 1 sseas --incremented
|
,o.sseas + 1 sseas --incremented
|
||||||
,'b22' "version"
|
,'b26' "version"
|
||||||
,'copy' iter
|
,'copy' iter
|
||||||
FROM
|
FROM
|
||||||
baseline o
|
baseline o
|
||||||
@ -419,7 +419,7 @@ SELECT * FROM baseline
|
|||||||
,o.version
|
,o.version
|
||||||
,o.iter
|
,o.iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osmfs_dev o
|
rlarp.osmf o
|
||||||
CROSS JOIN tdr
|
CROSS JOIN tdr
|
||||||
WHERE
|
WHERE
|
||||||
--collect all the rows in the base period and
|
--collect all the rows in the base period and
|
||||||
|
|||||||
@ -102,15 +102,15 @@ baseline AS (
|
|||||||
,o.r_rate
|
,o.r_rate
|
||||||
,o.c_currency
|
,o.c_currency
|
||||||
,o.c_rate
|
,o.c_rate
|
||||||
,sum(o.fb_qty) fb_qty
|
,ROUND(sum(o.fb_qty) ,5) fb_qty
|
||||||
,sum(o.fb_val_loc) fb_val_loc
|
,ROUND(sum(o.fb_val_loc) ,2) fb_val_loc
|
||||||
,sum(o.fb_val_loc_dis) fb_val_loc_dis
|
,ROUND(sum(o.fb_val_loc_dis),2) fb_val_loc_dis
|
||||||
,sum(o.fb_val_loc_qt) fb_val_loc_qt
|
,ROUND(sum(o.fb_val_loc_qt) ,2) fb_val_loc_qt
|
||||||
,sum(o.fb_val_loc_pl) fb_val_loc_pl
|
,ROUND(sum(o.fb_val_loc_pl) ,2) fb_val_loc_pl
|
||||||
,sum(o.fb_val_loc_tar) fb_val_loc_tar
|
,ROUND(sum(o.fb_val_loc_tar),2) fb_val_loc_tar
|
||||||
,sum(o.fb_cst_loc) fb_cst_loc
|
,ROUND(sum(o.fb_cst_loc) ,2) fb_cst_loc
|
||||||
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
|
,ROUND(sum(o.fb_cst_loc_cur),2) fb_cst_loc_cur
|
||||||
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
|
,ROUND(sum(o.fb_cst_loc_fut),2) fb_cst_loc_fut
|
||||||
,o.calc_status
|
,o.calc_status
|
||||||
,o.flag
|
,o.flag
|
||||||
,o.odate
|
,o.odate
|
||||||
@ -122,7 +122,7 @@ baseline AS (
|
|||||||
-----when null, greatest/least is just going to act like coalesce
|
-----when null, greatest/least is just going to act like coalesce
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||||
,ss.ssyr sseas
|
,ss.ssyr sseas
|
||||||
,'b24' "version"
|
,'b26' "version"
|
||||||
,'actuals' iter
|
,'actuals' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm o
|
rlarp.osm o
|
||||||
@ -135,12 +135,12 @@ baseline AS (
|
|||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
--base period orders booked....
|
--base period orders booked....
|
||||||
o.odate BETWEEN '2018-06-01' AND '2019-05-31'
|
o.odate BETWEEN '2024-06-01' AND '2025-03-15'
|
||||||
--...or any open orders currently booked before cutoff....
|
--...or any open orders currently booked before cutoff....
|
||||||
--OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01')
|
--OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01')
|
||||||
--...or anything that shipped in that period
|
--...or anything that shipped in that period
|
||||||
--OR ((o.fspr BETWEEN '1901' AND '1912' OR o.fspr = '0000') AND o.sdate < '2023-03-01')
|
--OR ((o.fspr BETWEEN '1901' AND '1912' OR o.fspr = '0000') AND o.sdate < '2023-03-01')
|
||||||
OR (o.fspr BETWEEN '1901' AND '1912')
|
OR (o.fspr BETWEEN '2501' AND '2510')
|
||||||
)
|
)
|
||||||
AND fs_line = '41010'
|
AND fs_line = '41010'
|
||||||
AND calc_status <> 'CANCELED'
|
AND calc_status <> 'CANCELED'
|
||||||
@ -261,27 +261,27 @@ baseline AS (
|
|||||||
,o.r_rate
|
,o.r_rate
|
||||||
,o.c_currency
|
,o.c_currency
|
||||||
,o.c_rate
|
,o.c_rate
|
||||||
,sum(o.fb_qty) fb_qty
|
,ROUND(sum(o.fb_qty) ,5) fb_qty
|
||||||
,sum(o.fb_val_loc) fb_val_loc
|
,ROUND(sum(o.fb_val_loc) ,2) fb_val_loc
|
||||||
,sum(o.fb_val_loc_dis) fb_val_loc_dis
|
,ROUND(sum(o.fb_val_loc_dis),2) fb_val_loc_dis
|
||||||
,sum(o.fb_val_loc_qt) fb_val_loc_qt
|
,ROUND(sum(o.fb_val_loc_qt) ,2) fb_val_loc_qt
|
||||||
,sum(o.fb_val_loc_pl) fb_val_loc_pl
|
,ROUND(sum(o.fb_val_loc_pl) ,2) fb_val_loc_pl
|
||||||
,sum(o.fb_val_loc_tar) fb_val_loc_tar
|
,ROUND(sum(o.fb_val_loc_tar),2) fb_val_loc_tar
|
||||||
,sum(o.fb_cst_loc) fb_cst_loc
|
,ROUND(sum(o.fb_cst_loc) ,2) fb_cst_loc
|
||||||
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
|
,ROUND(sum(o.fb_cst_loc_cur),2) fb_cst_loc_cur
|
||||||
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
|
,ROUND(sum(o.fb_cst_loc_fut),2) fb_cst_loc_fut
|
||||||
,o.calc_status
|
,o.calc_status
|
||||||
,o.flag
|
,o.flag
|
||||||
,o.odate + interval '1 year' odate
|
,o.odate + interval '1 year' odate
|
||||||
,o.oseas + 5 rseas
|
,o.oseas + 1 rseas
|
||||||
,o.rdate + interval '1 year' rdate
|
,o.rdate + interval '1 year' rdate
|
||||||
,o.rseas + 5 rseas
|
,o.rseas + 1 rseas
|
||||||
,o.pdate + interval '1 year' pdate
|
,o.pdate + interval '1 year' pdate
|
||||||
,o.pseas + 5 pseas
|
,o.pseas + 1 pseas
|
||||||
-----when null, greatest/least is just going to act like coalesce
|
-----when null, greatest/least is just going to act like coalesce
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
||||||
,ss.ssyr sseas
|
,ss.ssyr sseas
|
||||||
,'b24' "version"
|
,'b26' "version"
|
||||||
,'actuals_plug' iter
|
,'actuals_plug' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm o
|
rlarp.osm o
|
||||||
@ -290,16 +290,16 @@ baseline AS (
|
|||||||
LEFT OUTER JOIN rlarp.gld ss ON
|
LEFT OUTER JOIN rlarp.gld ss ON
|
||||||
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
|
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
|
||||||
WHERE
|
WHERE
|
||||||
false
|
true
|
||||||
--o.odate BETWEEN '2022-03-01' AND '2022-05-31'
|
AND o.odate BETWEEN '2024-03-15' AND '2024-05-31'
|
||||||
--AND fs_line = '41010'
|
AND fs_line = '41010'
|
||||||
--AND calc_status <> 'CANCELED'
|
AND calc_status <> 'CANCELED'
|
||||||
--AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
--AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
||||||
----OR (
|
----OR (
|
||||||
---- (o.fspr BETWEEN '2209' AND '2212' OR o.fspr = '0000')
|
---- (o.fspr BETWEEN '2209' AND '2212' OR o.fspr = '0000')
|
||||||
---- AND o.sdate BETWEEN '2022-03-01' AND '2022-05-31'
|
---- AND o.sdate BETWEEN '2022-03-01' AND '2022-05-31'
|
||||||
----)
|
----)
|
||||||
--AND version = 'ACTUALS'
|
AND version = 'ACTUALS'
|
||||||
GROUP BY
|
GROUP BY
|
||||||
o.fspr
|
o.fspr
|
||||||
,plnt
|
,plnt
|
||||||
@ -414,15 +414,15 @@ baseline AS (
|
|||||||
,null::numeric r_rate
|
,null::numeric r_rate
|
||||||
,o.c_currency
|
,o.c_currency
|
||||||
,null::numeric c_rate
|
,null::numeric c_rate
|
||||||
,sum(o.fb_qty) fb_qty
|
,ROUND(sum(o.fb_qty) ,5) fb_qty
|
||||||
,sum(o.fb_val_loc) fb_val_loc
|
,ROUND(sum(o.fb_val_loc) ,2) fb_val_loc
|
||||||
,sum(o.fb_val_loc_dis) fb_val_loc_dis
|
,ROUND(sum(o.fb_val_loc_dis),2) fb_val_loc_dis
|
||||||
,sum(o.fb_val_loc_qt) fb_val_loc_qt
|
,ROUND(sum(o.fb_val_loc_qt) ,2) fb_val_loc_qt
|
||||||
,sum(o.fb_val_loc_pl) fb_val_loc_pl
|
,ROUND(sum(o.fb_val_loc_pl) ,2) fb_val_loc_pl
|
||||||
,sum(o.fb_val_loc_tar) fb_val_loc_tar
|
,ROUND(sum(o.fb_val_loc_tar),2) fb_val_loc_tar
|
||||||
,sum(o.fb_cst_loc) fb_cst_loc
|
,ROUND(sum(o.fb_cst_loc) ,2) fb_cst_loc
|
||||||
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
|
,ROUND(sum(o.fb_cst_loc_cur),2) fb_cst_loc_cur
|
||||||
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
|
,ROUND(sum(o.fb_cst_loc_fut),2) fb_cst_loc_fut
|
||||||
,o.calc_status
|
,o.calc_status
|
||||||
,o.flag
|
,o.flag
|
||||||
,o.odate odate
|
,o.odate odate
|
||||||
@ -481,11 +481,11 @@ SELECT
|
|||||||
,o."dilin#"
|
,o."dilin#"
|
||||||
,o.quoten
|
,o.quoten
|
||||||
,o.quotel
|
,o.quotel
|
||||||
,o.dcodat + interval '5 years' --incremented
|
,o.dcodat + interval '1 years' --incremented
|
||||||
,o.ddqdat + interval '5 years' --incremented
|
,o.ddqdat + interval '1 years' --incremented
|
||||||
,o.dcmdat
|
,o.dcmdat
|
||||||
,o.fesdat
|
,o.fesdat
|
||||||
,o.dhidat + interval '5 years' --incremented
|
,o.dhidat + interval '1 years' --incremented
|
||||||
,o.fesind
|
,o.fesind
|
||||||
,o.dhpost
|
,o.dhpost
|
||||||
,gld.fspr --incremented
|
,gld.fspr --incremented
|
||||||
@ -569,20 +569,20 @@ SELECT
|
|||||||
,o.fb_cst_loc_fut
|
,o.fb_cst_loc_fut
|
||||||
,o.calc_status
|
,o.calc_status
|
||||||
,o.flag
|
,o.flag
|
||||||
,o.odate + interval '5 years' --incremented
|
,o.odate + interval '1 years' --incremented
|
||||||
,o.oseas + 5 --incremented
|
,o.oseas + 1 --incremented
|
||||||
,o.rdate + interval '5 years' --incremented
|
,o.rdate + interval '1 years' --incremented
|
||||||
,o.rseas + 5 --incremented
|
,o.rseas + 1 --incremented
|
||||||
,o.pdate + interval '5 years' --incremented
|
,o.pdate + interval '1 years' --incremented
|
||||||
,o.pseas + 5 --incremented
|
,o.pseas + 1 --incremented
|
||||||
,o.sdate + interval '5 years' --incremented
|
,o.sdate + interval '1 years' --incremented
|
||||||
,o.sseas + 5 --incremented
|
,o.sseas + 1 --incremented
|
||||||
,'b24' "version"
|
,'b26' "version"
|
||||||
,'copy' iter
|
,'copy' iter
|
||||||
FROM
|
FROM
|
||||||
baseline o
|
baseline o
|
||||||
LEFT OUTER JOIN rlarp.gld ON
|
LEFT OUTER JOIN rlarp.gld ON
|
||||||
(o.sdate + interval '5 years') BETWEEN gld.sdat and gld.edat
|
(o.sdate + interval '1 years') BETWEEN gld.sdat and gld.edat
|
||||||
WHERE
|
WHERE
|
||||||
true
|
true
|
||||||
--o.odate + interval '5 years' >= '2023-06-01'
|
--o.odate + interval '5 years' >= '2023-06-01'
|
||||||
@ -712,7 +712,7 @@ FROM
|
|||||||
) x;
|
) x;
|
||||||
|
|
||||||
---identify short ships: causes disconnect with actual sales-------------------------------------------------------------------
|
---identify short ships: causes disconnect with actual sales-------------------------------------------------------------------
|
||||||
--UPDATE rlarp.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER';
|
UPDATE rlarp.osmf SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER';
|
||||||
|
|
||||||
---identify goofy ship dates: causes disconnect with sales when splicing in a forecast that has this problem-------------------
|
---identify goofy ship dates: causes disconnect with sales when splicing in a forecast that has this problem-------------------
|
||||||
--UPDATE rlarp.osmfs SET iter = 'bad date' WHERE adj_shipdate < adj_orderdate;
|
UPDATE rlarp.osmf SET iter = 'bad date' WHERE sdate < odate;
|
||||||
|
|||||||
@ -1,17 +1,21 @@
|
|||||||
SELECT
|
SELECT
|
||||||
oseas,
|
oseas,
|
||||||
to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month,
|
to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month,
|
||||||
|
sseas,
|
||||||
|
to_char(CASE WHEN extract(month FROM o.sdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.sdate),'FM00')||' - '||to_char(o.sdate,'TMMon') ship_month,
|
||||||
version,
|
version,
|
||||||
iter,
|
iter,
|
||||||
sum(fb_val_loc * r_rate) value_loc
|
sum(fb_val_loc * r_rate) value_loc
|
||||||
FROM
|
FROM
|
||||||
rlarp.osmf_dev o
|
rlarp.osmf o
|
||||||
WHERE
|
WHERE
|
||||||
fs_line = '41010'
|
fs_line = '41010'
|
||||||
and calc_status <> 'CANCELED'
|
and calc_status <> 'CANCELED'
|
||||||
GROUP BY
|
GROUP BY
|
||||||
oseas,
|
oseas,
|
||||||
to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon'),
|
to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon'),
|
||||||
|
sseas,
|
||||||
|
to_char(CASE WHEN extract(month FROM o.sdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.sdate),'FM00')||' - '||to_char(o.sdate,'TMMon'),
|
||||||
version,
|
version,
|
||||||
iter
|
iter
|
||||||
ORDER BY
|
ORDER BY
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user