add notes and create an adjustment based on a percentage for lines where not all is pullforward
This commit is contained in:
parent
fc8f9592b8
commit
752aeffa06
@ -42,6 +42,8 @@ tdr AS (
|
|||||||
,shipto_group
|
,shipto_group
|
||||||
,part_group
|
,part_group
|
||||||
)
|
)
|
||||||
|
--SELECT * FROM booked
|
||||||
|
------------plan units according to the 'plan' iteration of the current forecast----------------------------
|
||||||
,planned AS (
|
,planned AS (
|
||||||
SELECT
|
SELECT
|
||||||
p.billto_group
|
p.billto_group
|
||||||
@ -72,6 +74,8 @@ tdr AS (
|
|||||||
,p.ship_date
|
,p.ship_date
|
||||||
,b.units
|
,b.units
|
||||||
)
|
)
|
||||||
|
--SELECT * FROM planned LIMIT 100
|
||||||
|
-------flag rows by preparing a rolling total in this step------------------
|
||||||
,plan_ranked AS (
|
,plan_ranked AS (
|
||||||
SELECT
|
SELECT
|
||||||
p.billto_group
|
p.billto_group
|
||||||
@ -89,7 +93,8 @@ tdr AS (
|
|||||||
FROM
|
FROM
|
||||||
planned p
|
planned p
|
||||||
)
|
)
|
||||||
---flag any rows where
|
--SELECT * FROM plan_ranked
|
||||||
|
---flag future budget where up to the extent that actuals are larger than budget, but not more------
|
||||||
,eval AS (
|
,eval AS (
|
||||||
SELECT
|
SELECT
|
||||||
p.billto_group
|
p.billto_group
|
||||||
@ -104,12 +109,20 @@ tdr AS (
|
|||||||
,p.net_units_tot
|
,p.net_units_tot
|
||||||
,p.net_units
|
,p.net_units
|
||||||
--,p.booked
|
--,p.booked
|
||||||
,plan_rolling <= (p.net_units_tot - p.plan_units_tot + plan_units) flag
|
-----total current units less plan total units is the excess
|
||||||
|
-----if the current row contributes to the excess, flag it
|
||||||
|
-----the last row will likely pull out too much, it will need split probably
|
||||||
|
,(plan_rolling - plan_units) <= (p.net_units_tot - p.plan_units_tot) flag
|
||||||
|
,-(p.net_units_tot - p.plan_units_tot) max_possible_reduction
|
||||||
|
,-CASE
|
||||||
|
WHEN plan_rolling <= (p.net_units_tot - p.plan_units_tot) THEN plan_units
|
||||||
|
WHEN plan_rolling > (p.net_units_tot - p.plan_units_tot) AND (plan_rolling - plan_units) <= (p.net_units_tot - p.plan_units_tot) THEN (p.net_units_tot - p.plan_units_tot) - (plan_rolling - plan_units)
|
||||||
|
END qty
|
||||||
--,CASE WHEN (p.plan_units_agg - p.plan_units) > p.booked AND p.plan_units_agg <= p.booked * 2 THEN true ELSE false END remove
|
--,CASE WHEN (p.plan_units_agg - p.plan_units) > p.booked AND p.plan_units_agg <= p.booked * 2 THEN true ELSE false END remove
|
||||||
FROM
|
FROM
|
||||||
plan_ranked p
|
plan_ranked p
|
||||||
)
|
)
|
||||||
--select * from eval limit 10000
|
--SELECT * FROM eval LIMIT 10000
|
||||||
----------------create a log entry--------------------
|
----------------create a log entry--------------------
|
||||||
,log AS (
|
,log AS (
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
@ -153,11 +166,12 @@ tdr AS (
|
|||||||
,o.r_rate
|
,o.r_rate
|
||||||
,o.c_currency
|
,o.c_currency
|
||||||
,o.c_rate
|
,o.c_rate
|
||||||
,round(-sum(o.units ),2) units
|
-----only keep the percentage of the current row determined by the last step--------
|
||||||
,round(-sum(o.value_loc),2) value_loc
|
,round(-sum(o.units ),2)*(-e.qty/e.plan_units) units
|
||||||
,round(-sum(o.value_usd),2) value_usd
|
,round(-sum(o.value_loc),2)*(-e.qty/e.plan_units) value_loc
|
||||||
,round(-sum(o.cost_loc ),2) cost_loc
|
,round(-sum(o.value_usd),2)*(-e.qty/e.plan_units) value_usd
|
||||||
,round(-sum(o.cost_usd ),2) cost_usd
|
,round(-sum(o.cost_loc ),2)*(-e.qty/e.plan_units) cost_loc
|
||||||
|
,round(-sum(o.cost_usd ),2)*(-e.qty/e.plan_units) cost_usd
|
||||||
,o.calc_status
|
,o.calc_status
|
||||||
,o.flag
|
,o.flag
|
||||||
,o.order_date
|
,o.order_date
|
||||||
|
Loading…
Reference in New Issue
Block a user