back to original stage file
This commit is contained in:
parent
7f8ed574c5
commit
b9c6c64764
@ -1,27 +1,17 @@
|
|||||||
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;
|
||||||
--will not match actuals exactly due to short-ships
|
|
||||||
TRUNCATE TABLE rlarp.osmf_dev;
|
TRUNCATE TABLE rlarp.osmf_dev;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS tdr;
|
DROP TABLE IF EXISTS tdr;
|
||||||
|
|
||||||
CREATE TEMP TABLE tdr AS (
|
CREATE TEMP TABLE tdr AS (
|
||||||
SELECT
|
SELECT
|
||||||
-----------actuals---------------------------------------------------
|
DATERANGE('2020-06-01','2021-06-01','[)') drange
|
||||||
DATERANGE('2020-06-01','2021-07-07','[]') adrange
|
,DATERANGE(('2020-06-01'::date + '1 year'::interval)::date,('2021-06-01'::date + '1 year'::interval)::date,'[)') repl
|
||||||
-----------actuals to target for incremnt----------------------------
|
,'1 year'::interval AS incr
|
||||||
,DATERANGE('2022-06-01','2022-06-01','[)') arepl
|
|
||||||
,'0 year'::interval AS aincr
|
|
||||||
-----------budget to target for increment----------------------------
|
|
||||||
,DATERANGE('2021-07-08','2022-06-01','[)') prepl
|
|
||||||
,'0 year'::interval AS pincr
|
|
||||||
-----------iterations to merge with----------------------------------
|
|
||||||
,(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
|
||||||
);
|
);
|
||||||
|
|
||||||
--select * from tdr
|
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
gld AS (
|
gld AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -168,17 +158,14 @@ gld AS (
|
|||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
--base period orders booked....
|
--base period orders booked....
|
||||||
o.odate <@ (SELECT adrange FROM tdr)
|
o.odate <@ (SELECT drange FROM tdr)
|
||||||
--...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 <= (SELECT UPPER(adrange) FROM tdr))
|
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < (SELECT UPPER(drange) FROM tdr))
|
||||||
--...or anything that shipped in that period
|
--...or anything that shipped in that period
|
||||||
OR (o.sdate <@ (SELECT adrange FROM tdr) AND sseas IS NOT NULL)
|
OR (o.sdate <@ (SELECT drange FROM tdr) AND sseas IS NOT NULL)
|
||||||
)
|
)
|
||||||
---exclude R&A's
|
|
||||||
AND fs_line = '41010'
|
AND fs_line = '41010'
|
||||||
---exclude canceled orders
|
|
||||||
AND calc_status <> 'CANCELED'
|
AND calc_status <> 'CANCELED'
|
||||||
---exclude short ships
|
|
||||||
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
||||||
---exclude integrated quotes----
|
---exclude integrated quotes----
|
||||||
AND version = 'ACTUALS'
|
AND version = 'ACTUALS'
|
||||||
@ -205,7 +192,6 @@ gld AS (
|
|||||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||||
,ss.ssyr
|
,ss.ssyr
|
||||||
)
|
)
|
||||||
--SELECT * FROM baseline
|
|
||||||
,incr AS (
|
,incr AS (
|
||||||
SELECT
|
SELECT
|
||||||
o."ddord#"
|
o."ddord#"
|
||||||
@ -216,14 +202,14 @@ SELECT
|
|||||||
,o."dilin#"
|
,o."dilin#"
|
||||||
,o.quoten
|
,o.quoten
|
||||||
,o.quotel
|
,o.quotel
|
||||||
,o.dcodat + (SELECT aincr FROM tdr) dcodat --incremented
|
,o.dcodat + interval '1 year' dcodat --incremented
|
||||||
,o.ddqdat + (SELECT aincr FROM tdr) ddqdat --incremented
|
,o.ddqdat + interval '1 year' ddqdat --incremented
|
||||||
,o.dcmdat
|
,o.dcmdat
|
||||||
,o.fesdat
|
,o.fesdat
|
||||||
,o.dhidat + (SELECT aincr FROM tdr) dhidat --incremented
|
,o.dhidat + interval '1 year' dhidat --incremented
|
||||||
,o.fesind
|
,o.fesind
|
||||||
,o.dhpost
|
,o.dhpost
|
||||||
,sg.fspr --incremented
|
,gld.fspr --incremented
|
||||||
,o.ddqtoi
|
,o.ddqtoi
|
||||||
,o.ddqtsi
|
,o.ddqtsi
|
||||||
,o.fgqshp
|
,o.fgqshp
|
||||||
@ -303,28 +289,21 @@ SELECT
|
|||||||
,o.fb_cst_loc_fut
|
,o.fb_cst_loc_fut
|
||||||
,o.calc_status
|
,o.calc_status
|
||||||
,o.flag
|
,o.flag
|
||||||
,(o.odate + (SELECT aincr FROM tdr))::date odate --incremented
|
,(o.odate + interval '1 year')::date odate --incremented
|
||||||
,og.ssyr oseas --incremented
|
,o.oseas + 1 oseas --incremented
|
||||||
,(o.rdate + (SELECT aincr FROM tdr))::date rdate --incremented
|
,(o.rdate + interval '1 year')::date rdate --incremented
|
||||||
,rg.ssyr rseas --incremented
|
,o.rseas + 1 rseas --incremented
|
||||||
,(o.sdate + (SELECT aincr FROM tdr))::date sdate --incremented
|
,(o.sdate + interval '1 year')::date sdate --incremented
|
||||||
,sg.ssyr sseas --incremented
|
,o.sseas + 1 sseas --incremented
|
||||||
,'b22' "version"
|
,'b22' "version"
|
||||||
,'copy' iter
|
,'copy' iter
|
||||||
FROM
|
FROM
|
||||||
baseline o
|
baseline o
|
||||||
-----join to date tables based on revised dating--------------
|
LEFT OUTER JOIN gld ON
|
||||||
LEFT OUTER JOIN rlarp.gld sg ON
|
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
|
||||||
sg.drange @> (o.sdate + (SELECT aincr FROM tdr))::date
|
|
||||||
LEFT OUTER JOIN rlarp.gld og ON
|
|
||||||
og.drange @> (o.odate + (SELECT aincr FROM tdr))::date
|
|
||||||
LEFT OUTER JOIN rlarp.gld rg ON
|
|
||||||
rg.drange @> (o.odate + (SELECT aincr FROM tdr))::date
|
|
||||||
WHERE
|
WHERE
|
||||||
-------only return orders where the forecast orderdate is in the target forecast range-----------
|
o.odate + interval '1 year' >= (SELECT LOWER(drange) + INTERVAL '1 year' FROM tdr)
|
||||||
(o.odate + (SELECT aincr FROM tdr)) >= (SELECT LOWER(arepl) + aincr FROM tdr)
|
|
||||||
)
|
)
|
||||||
--SELECT count(*) FROM incr
|
|
||||||
,stage AS (
|
,stage AS (
|
||||||
SELECT * FROM incr
|
SELECT * FROM incr
|
||||||
UNION ALL
|
UNION ALL
|
||||||
@ -440,14 +419,14 @@ SELECT * FROM baseline
|
|||||||
,o.version
|
,o.version
|
||||||
,o.iter
|
,o.iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osmf_dev o
|
rlarp.osmfs_dev 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
|
||||||
--the destination slot for the new rows
|
--the destination slot for the new rows
|
||||||
(
|
(
|
||||||
o.odate <@ tdr.adrange
|
o.odate <@ tdr.drange
|
||||||
OR o.odate <@ tdr.arepl
|
OR o.odate <@ tdr.repl
|
||||||
)
|
)
|
||||||
---only merge with targeted iterations
|
---only merge with targeted iterations
|
||||||
AND tdr.iter ? o.iter
|
AND tdr.iter ? o.iter
|
||||||
@ -600,10 +579,8 @@ SELECT * FROM baseline
|
|||||||
WHERE
|
WHERE
|
||||||
--collect all the rows in the base period and
|
--collect all the rows in the base period and
|
||||||
--the destination slot for the new rows
|
--the destination slot for the new rows
|
||||||
o.odate <@ (SELECT tdr.adrange FROM tdr)
|
o.odate <@ (SELECT tdr.drange FROM tdr)
|
||||||
OR o.sdate <@ (SELECT tdr.adrange FROM tdr)
|
OR o.odate <@ (SELECT tdr.repl FROM tdr)
|
||||||
OR o.odate <@ (SELECT tdr.arepl FROM tdr)
|
|
||||||
OR o.sdate <@ (SELECT tdr.arepl FROM tdr)
|
|
||||||
GROUP BY
|
GROUP BY
|
||||||
o.dhidat
|
o.dhidat
|
||||||
,o.fspr
|
,o.fspr
|
||||||
@ -630,9 +607,9 @@ SELECT * FROM baseline
|
|||||||
,o.sseas
|
,o.sseas
|
||||||
--,o.version
|
--,o.version
|
||||||
--,o.iter
|
--,o.iter
|
||||||
--HAVING
|
HAVING
|
||||||
-- round(sum(o.fb_qty),2) <> 0
|
round(sum(o.fb_qty),2) <> 0
|
||||||
-- OR round(sum(o.fb_val_loc),2) <> 0
|
OR round(sum(o.fb_val_loc),2) <> 0
|
||||||
--OR round(sum(o.fb_cst_loc),2) <> 0
|
--OR round(sum(o.fb_cst_loc),2) <> 0
|
||||||
)
|
)
|
||||||
INSERT INTO rlarp.osmf_dev SELECT * FROM merge_diff;
|
INSERT INTO rlarp.osmf_dev SELECT * FROM merge_diff;
|
||||||
@ -671,6 +648,8 @@ WHERE
|
|||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
|
END
|
||||||
|
|
||||||
---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.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user