commit: 2025-03-19 15:31:38

This commit is contained in:
Paul Trowbridge 2025-03-19 15:31:38 -04:00
parent 2a6419b386
commit 2941e0f3a4
3 changed files with 65 additions and 61 deletions

View File

@ -1,13 +1,13 @@
BEGIN;
--\timing
--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;
CREATE TEMP TABLE tdr AS (
SELECT
DATERANGE('2022-06-01','2023-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','2024-06-01','[)') drange
,DATERANGE(('2024-06-01'::date + '1 year'::interval)::date,('2024-06-01'::date + '1 year'::interval)::date,'[)') repl
,'1 year'::interval AS incr
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter
);
@ -148,7 +148,7 @@ gld AS (
,'actuals' "version"
,'actuals' iter
FROM
rlarp.osm_dev o
rlarp.osm o
--snap the ship dates of the historic fiscal period
LEFT OUTER JOIN gld ON
gld.fspr = o.fspr
@ -295,7 +295,7 @@ SELECT
,o.rseas + 1 rseas --incremented
,(o.sdate + interval '1 year')::date sdate --incremented
,o.sseas + 1 sseas --incremented
,'b22' "version"
,'b26' "version"
,'copy' iter
FROM
baseline o
@ -419,7 +419,7 @@ SELECT * FROM baseline
,o.version
,o.iter
FROM
rlarp.osmfs_dev o
rlarp.osmf o
CROSS JOIN tdr
WHERE
--collect all the rows in the base period and

View File

@ -102,15 +102,15 @@ baseline AS (
,o.r_rate
,o.c_currency
,o.c_rate
,sum(o.fb_qty) fb_qty
,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_dis) fb_val_loc_dis
,sum(o.fb_val_loc_qt) fb_val_loc_qt
,sum(o.fb_val_loc_pl) fb_val_loc_pl
,sum(o.fb_val_loc_tar) fb_val_loc_tar
,sum(o.fb_cst_loc) fb_cst_loc
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
,ROUND(sum(o.fb_qty) ,5) fb_qty
,ROUND(sum(o.fb_val_loc) ,2) fb_val_loc
,ROUND(sum(o.fb_val_loc_dis),2) fb_val_loc_dis
,ROUND(sum(o.fb_val_loc_qt) ,2) fb_val_loc_qt
,ROUND(sum(o.fb_val_loc_pl) ,2) fb_val_loc_pl
,ROUND(sum(o.fb_val_loc_tar),2) fb_val_loc_tar
,ROUND(sum(o.fb_cst_loc) ,2) fb_cst_loc
,ROUND(sum(o.fb_cst_loc_cur),2) fb_cst_loc_cur
,ROUND(sum(o.fb_cst_loc_fut),2) fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate
@ -122,7 +122,7 @@ baseline AS (
-----when null, greatest/least is just going to act like coalesce
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
,ss.ssyr sseas
,'b24' "version"
,'b26' "version"
,'actuals' iter
FROM
rlarp.osm o
@ -135,12 +135,12 @@ baseline AS (
WHERE
(
--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 (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01')
--...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 BETWEEN '2501' AND '2510')
)
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
@ -261,27 +261,27 @@ baseline AS (
,o.r_rate
,o.c_currency
,o.c_rate
,sum(o.fb_qty) fb_qty
,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_dis) fb_val_loc_dis
,sum(o.fb_val_loc_qt) fb_val_loc_qt
,sum(o.fb_val_loc_pl) fb_val_loc_pl
,sum(o.fb_val_loc_tar) fb_val_loc_tar
,sum(o.fb_cst_loc) fb_cst_loc
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
,ROUND(sum(o.fb_qty) ,5) fb_qty
,ROUND(sum(o.fb_val_loc) ,2) fb_val_loc
,ROUND(sum(o.fb_val_loc_dis),2) fb_val_loc_dis
,ROUND(sum(o.fb_val_loc_qt) ,2) fb_val_loc_qt
,ROUND(sum(o.fb_val_loc_pl) ,2) fb_val_loc_pl
,ROUND(sum(o.fb_val_loc_tar),2) fb_val_loc_tar
,ROUND(sum(o.fb_cst_loc) ,2) fb_cst_loc
,ROUND(sum(o.fb_cst_loc_cur),2) fb_cst_loc_cur
,ROUND(sum(o.fb_cst_loc_fut),2) fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate + interval '1 year' odate
,o.oseas + 5 rseas
,o.oseas + 1 rseas
,o.rdate + interval '1 year' rdate
,o.rseas + 5 rseas
,o.rseas + 1 rseas
,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
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
,ss.ssyr sseas
,'b24' "version"
,'b26' "version"
,'actuals_plug' iter
FROM
rlarp.osm o
@ -290,16 +290,16 @@ baseline AS (
LEFT OUTER JOIN rlarp.gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
WHERE
false
--o.odate BETWEEN '2022-03-01' AND '2022-05-31'
--AND fs_line = '41010'
--AND calc_status <> 'CANCELED'
true
AND o.odate BETWEEN '2024-03-15' AND '2024-05-31'
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
--AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
----OR (
---- (o.fspr BETWEEN '2209' AND '2212' OR o.fspr = '0000')
---- AND o.sdate BETWEEN '2022-03-01' AND '2022-05-31'
----)
--AND version = 'ACTUALS'
AND version = 'ACTUALS'
GROUP BY
o.fspr
,plnt
@ -414,15 +414,15 @@ baseline AS (
,null::numeric r_rate
,o.c_currency
,null::numeric c_rate
,sum(o.fb_qty) fb_qty
,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_dis) fb_val_loc_dis
,sum(o.fb_val_loc_qt) fb_val_loc_qt
,sum(o.fb_val_loc_pl) fb_val_loc_pl
,sum(o.fb_val_loc_tar) fb_val_loc_tar
,sum(o.fb_cst_loc) fb_cst_loc
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
,ROUND(sum(o.fb_qty) ,5) fb_qty
,ROUND(sum(o.fb_val_loc) ,2) fb_val_loc
,ROUND(sum(o.fb_val_loc_dis),2) fb_val_loc_dis
,ROUND(sum(o.fb_val_loc_qt) ,2) fb_val_loc_qt
,ROUND(sum(o.fb_val_loc_pl) ,2) fb_val_loc_pl
,ROUND(sum(o.fb_val_loc_tar),2) fb_val_loc_tar
,ROUND(sum(o.fb_cst_loc) ,2) fb_cst_loc
,ROUND(sum(o.fb_cst_loc_cur),2) fb_cst_loc_cur
,ROUND(sum(o.fb_cst_loc_fut),2) fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate odate
@ -481,11 +481,11 @@ SELECT
,o."dilin#"
,o.quoten
,o.quotel
,o.dcodat + interval '5 years' --incremented
,o.ddqdat + interval '5 years' --incremented
,o.dcodat + interval '1 years' --incremented
,o.ddqdat + interval '1 years' --incremented
,o.dcmdat
,o.fesdat
,o.dhidat + interval '5 years' --incremented
,o.dhidat + interval '1 years' --incremented
,o.fesind
,o.dhpost
,gld.fspr --incremented
@ -569,20 +569,20 @@ SELECT
,o.fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate + interval '5 years' --incremented
,o.oseas + 5 --incremented
,o.rdate + interval '5 years' --incremented
,o.rseas + 5 --incremented
,o.pdate + interval '5 years' --incremented
,o.pseas + 5 --incremented
,o.sdate + interval '5 years' --incremented
,o.sseas + 5 --incremented
,'b24' "version"
,o.odate + interval '1 years' --incremented
,o.oseas + 1 --incremented
,o.rdate + interval '1 years' --incremented
,o.rseas + 1 --incremented
,o.pdate + interval '1 years' --incremented
,o.pseas + 1 --incremented
,o.sdate + interval '1 years' --incremented
,o.sseas + 1 --incremented
,'b26' "version"
,'copy' iter
FROM
baseline o
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
true
--o.odate + interval '5 years' >= '2023-06-01'
@ -712,7 +712,7 @@ FROM
) x;
---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-------------------
--UPDATE rlarp.osmfs SET iter = 'bad date' WHERE adj_shipdate < adj_orderdate;
UPDATE rlarp.osmf SET iter = 'bad date' WHERE sdate < odate;

View File

@ -1,17 +1,21 @@
SELECT
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,
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,
iter,
sum(fb_val_loc * r_rate) value_loc
FROM
rlarp.osmf_dev o
rlarp.osmf o
WHERE
fs_line = '41010'
and calc_status <> 'CANCELED'
GROUP BY
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'),
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,
iter
ORDER BY