Compare commits
No commits in common. "f8bf1518f9fdd111fcfcdd9e1fdcf6f3eae0d803" and "be9ca7b848d9ad299e2649301c2b9df158d3edda" have entirely different histories.
f8bf1518f9
...
be9ca7b848
@ -17,12 +17,10 @@ WITH
|
|||||||
---these dates will have to be syncronized with the forecast build-----------
|
---these dates will have to be syncronized with the forecast build-----------
|
||||||
tdr AS (
|
tdr AS (
|
||||||
SELECT
|
SELECT
|
||||||
-----------intented forecast range-----------------------------------
|
-----------actuals into baseline-------------------------------------
|
||||||
DATERANGE('2021-06-01','2022-06-01','[)') prange
|
DATERANGE('2020-06-01','2021-07-12','[]') arange
|
||||||
-----------explicitly call out overlap period------------------------
|
-----------plan into baseline----------------------------------------
|
||||||
-----------anythign in this period has to net out to match actuals---
|
,DATERANGE('2021-06-01','2022-06-01','[)') prange
|
||||||
,DATERANGE('2021-06-01','2021-07-12','[]') overlap
|
|
||||||
,jsonb_build_array('plan','diff') iter
|
|
||||||
)
|
)
|
||||||
,booked AS materialized(
|
,booked AS materialized(
|
||||||
SELECT
|
SELECT
|
||||||
@ -34,7 +32,8 @@ tdr AS (
|
|||||||
rlarp.osm_pool
|
rlarp.osm_pool
|
||||||
WHERE
|
WHERE
|
||||||
--find actual orders in the overlap range (where orders fall in both target ranges)
|
--find actual orders in the overlap range (where orders fall in both target ranges)
|
||||||
order_date <@ (SELECT overlap FROM tdr)
|
order_date <@ (SELECT arange FROM tdr)
|
||||||
|
AND order_date <@ (SELECT prange FROM tdr)
|
||||||
--anything that falls in this range is supposed to already match actuals, so no need to filter for actuals
|
--anything that falls in this range is supposed to already match actuals, so no need to filter for actuals
|
||||||
GROUP BY
|
GROUP BY
|
||||||
billto_group
|
billto_group
|
||||||
@ -62,7 +61,7 @@ tdr AS (
|
|||||||
--budget orders have already been trued up to match actual, so should not be included in the this isolation
|
--budget orders have already been trued up to match actual, so should not be included in the this isolation
|
||||||
--find actual orders in the overlap range (where orders fall in both target ranges)
|
--find actual orders in the overlap range (where orders fall in both target ranges)
|
||||||
p.order_date <@ (SELECT prange FROM tdr)
|
p.order_date <@ (SELECT prange FROM tdr)
|
||||||
AND (SELECT iter FROM tdr) ? p.iter
|
AND p.iter IN ('plan','diff')
|
||||||
GROUP BY
|
GROUP BY
|
||||||
p.billto_group
|
p.billto_group
|
||||||
,p.shipto_group
|
,p.shipto_group
|
||||||
@ -79,7 +78,7 @@ tdr AS (
|
|||||||
,p.order_date
|
,p.order_date
|
||||||
,p.ship_date
|
,p.ship_date
|
||||||
,round(p.plan_units,2) plan_units
|
,round(p.plan_units,2) plan_units
|
||||||
,round(SUM(p.plan_units) FILTER (WHERE order_date >= (SELECT upper(overlap) FROM tdr)) OVER (PARTITION BY p.billto_group, p.shipto_group, p.part_group ORDER BY p.order_date, p.ship_date),2) plan_rolling
|
,round(SUM(p.plan_units) FILTER (WHERE order_date >= (SELECT upper(arange) FROM tdr)) OVER (PARTITION BY p.billto_group, p.shipto_group, p.part_group ORDER BY p.order_date, p.ship_date),2) plan_rolling
|
||||||
,round(SUM(p.plan_units) OVER (PARTITION BY p.billto_group, p.shipto_group, p.part_group ),2) plan_units_tot
|
,round(SUM(p.plan_units) OVER (PARTITION BY p.billto_group, p.shipto_group, p.part_group ),2) plan_units_tot
|
||||||
--,round(SUM(COALESCE(p.plan_units,0) + COALESCE(p.diff_units,0)) OVER (PARTITION BY p.billto_group, p.shipto_group, p.part_group ORDER BY p.order_date, p.ship_date),2) net_units_agg
|
--,round(SUM(COALESCE(p.plan_units,0) + COALESCE(p.diff_units,0)) OVER (PARTITION BY p.billto_group, p.shipto_group, p.part_group ORDER BY p.order_date, p.ship_date),2) net_units_agg
|
||||||
,round(COALESCE(p.diff_units,0) + coalesce(p.plan_units,0),2) net_units
|
,round(COALESCE(p.diff_units,0) + coalesce(p.plan_units,0),2) net_units
|
||||||
@ -115,8 +114,8 @@ tdr AS (
|
|||||||
rlarp.osm_log(doc)
|
rlarp.osm_log(doc)
|
||||||
SELECT
|
SELECT
|
||||||
$${
|
$${
|
||||||
"message":"remove future orders to the extent the new forecast totals more than the original budget",
|
"message":"force accounts to match target total value and margin",
|
||||||
"tag":"1+11",
|
"tag":"retail plug",
|
||||||
"type":"build"
|
"type":"build"
|
||||||
}$$::jsonb doc
|
}$$::jsonb doc
|
||||||
RETURNING *
|
RETURNING *
|
||||||
@ -170,10 +169,10 @@ tdr AS (
|
|||||||
,o.ship_season
|
,o.ship_season
|
||||||
,'1+11' AS version
|
,'1+11' AS version
|
||||||
,'pf' iter
|
,'pf' iter
|
||||||
,log.id
|
--,log.id
|
||||||
,coalescE(log.doc->>'tag','') AS "tag"
|
--,coalescE(log.doc->>'tag','') AS "tag"
|
||||||
,log.doc->>'message' AS "comment"
|
--,log.doc->>'message' AS "comment"
|
||||||
,log.doc->>'type' module
|
--,log.doc->>'type' module
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_pool o
|
rlarp.osm_pool o
|
||||||
INNER JOIN eval e ON
|
INNER JOIN eval e ON
|
||||||
@ -182,7 +181,7 @@ tdr AS (
|
|||||||
e.part_group = o.part_group AND
|
e.part_group = o.part_group AND
|
||||||
e.order_date = o.order_date AND
|
e.order_date = o.order_date AND
|
||||||
e.ship_date = o.ship_date
|
e.ship_date = o.ship_date
|
||||||
CROSS JOIN log
|
--CROSS JOIN log
|
||||||
WHERE
|
WHERE
|
||||||
e.flag
|
e.flag
|
||||||
GROUP BY
|
GROUP BY
|
||||||
@ -226,10 +225,10 @@ tdr AS (
|
|||||||
,o.ship_date
|
,o.ship_date
|
||||||
,o.ship_month
|
,o.ship_month
|
||||||
,o.ship_season
|
,o.ship_season
|
||||||
,log.id
|
--,log.id
|
||||||
,coalescE(log.doc->>'tag','')
|
--,coalescE(log.doc->>'tag','') AS "tag"
|
||||||
,log.doc->>'message'
|
--,log.doc->>'message' AS "comment"
|
||||||
,log.doc->>'type'
|
--,log.doc->>'type' module
|
||||||
-----some bad forecast swings, if one is removed it's wacky
|
-----some bad forecast swings, if one is removed it's wacky
|
||||||
-----cap at -1,000,000
|
-----cap at -1,000,000
|
||||||
HAVING
|
HAVING
|
||||||
|
@ -16,13 +16,13 @@ DROP TABLE IF EXISTS tdr;
|
|||||||
CREATE TEMP TABLE tdr AS (
|
CREATE TEMP TABLE tdr AS (
|
||||||
SELECT
|
SELECT
|
||||||
-----------actuals into baseline-------------------------------------
|
-----------actuals into baseline-------------------------------------
|
||||||
DATERANGE('2020-06-01','2021-07-15','[]') arange
|
DATERANGE('2020-06-01','2021-07-12','[]') arange
|
||||||
-----------plan into baseline----------------------------------------
|
-----------plan into baseline----------------------------------------
|
||||||
,DATERANGE('2020-06-01','2022-06-01','[)') prange
|
,DATERANGE('2021-06-01','2022-06-01','[)') prange
|
||||||
-----------forecast into baseline------------------------------------
|
-----------forecast into baseline------------------------------------
|
||||||
,DATERANGE('2022-06-01','2022-06-01','[)') frange -- this range effectively excludes
|
,DATERANGE('2022-06-01','2022-06-01','[)') frange -- this range effectively excludes
|
||||||
-----------baseline selection for increment--------------------------
|
-----------baseline selection for increment--------------------------
|
||||||
,DATERANGE('2021-07-15','2021-07-15','[)') selection
|
,DATERANGE('2021-07-08','2021-07-08','[)') selection
|
||||||
-----------selection increment size----------------------------------
|
-----------selection increment size----------------------------------
|
||||||
,'0 year'::interval AS incr
|
,'0 year'::interval AS incr
|
||||||
-----------iterations to merge with----------------------------------
|
-----------iterations to merge with----------------------------------
|
||||||
|
@ -113,9 +113,7 @@ SELECT
|
|||||||
iter,
|
iter,
|
||||||
tag
|
tag
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_pool
|
rlarp.osm_pool;
|
||||||
WHERE
|
|
||||||
version <> 'actuals'
|
|
||||||
|
|
||||||
-------need to set item master values before other things-----------
|
-------need to set item master values before other things-----------
|
||||||
UPDATE
|
UPDATE
|
||||||
|
Loading…
Reference in New Issue
Block a user