save work on post-volume price adjustment
This commit is contained in:
parent
fee1b9202f
commit
cf6e3b6695
@ -1,4 +1,4 @@
|
|||||||
BEGIN;
|
--BEGIN;
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
------------------goal price increases---------------------
|
------------------goal price increases---------------------
|
||||||
@ -257,96 +257,150 @@ FROM
|
|||||||
}$$::jsonb doc
|
}$$::jsonb doc
|
||||||
RETURNING *
|
RETURNING *
|
||||||
)
|
)
|
||||||
-------------build the iteration rows----------------
|
,poolprice AS (
|
||||||
,ins AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
o.fspr
|
i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) product
|
||||||
,o.plnt ---master data
|
,o.quota_rep_descr
|
||||||
,o.promo --history date mix
|
,o.billto_group
|
||||||
,o.terms
|
|
||||||
,o.bill_cust_descr --history cust mix
|
|
||||||
,o.ship_cust_descr --history cust mix
|
|
||||||
,o.dsm
|
|
||||||
,o.quota_rep_descr --master data
|
|
||||||
,o.director
|
|
||||||
,o.billto_group --master data
|
|
||||||
,o.shipto_group
|
,o.shipto_group
|
||||||
,o.chan --master data
|
,order_season
|
||||||
,o.chansub
|
,sum(units) units
|
||||||
,o.chan_retail
|
,sum(value_loc) valloc
|
||||||
,o.part
|
,sum(value_usd) valusd
|
||||||
,o.part_descr
|
,sum(o.value_loc)/sum(o.units) price
|
||||||
,o.part_group
|
,jsonb_agg(DISTINCT iter) iters
|
||||||
,o.branding
|
|
||||||
,o.majg_descr
|
|
||||||
,o.ming_descr
|
|
||||||
,o.majs_descr
|
|
||||||
,o.mins_descr
|
|
||||||
,o.segm
|
|
||||||
,o.substance
|
|
||||||
,o.fs_line --master data
|
|
||||||
,o.r_currency --history cust mix
|
|
||||||
,o.r_rate --master data
|
|
||||||
,o.c_currency --master data
|
|
||||||
,o.c_rate --master data
|
|
||||||
,0::numeric units
|
|
||||||
,ROUND(o.units * (a.price_increment/o.r_rate),2) value_loc
|
|
||||||
,ROUND(o.units * a.price_increment,2) value_usd
|
|
||||||
,0::numeric cost_loc
|
|
||||||
,0::numeric cost_usd
|
|
||||||
,o.calc_status --0
|
|
||||||
,o.flag --0
|
|
||||||
,o.order_date --history date mix
|
|
||||||
,o.order_month
|
|
||||||
,o.order_season
|
|
||||||
,o.request_date --history date mix
|
|
||||||
,o.request_month
|
|
||||||
,o.request_season
|
|
||||||
,o.ship_date --history date mix
|
|
||||||
,o.ship_month
|
|
||||||
,o.ship_season
|
|
||||||
,o.version
|
|
||||||
---this iteration has to be listed in the master template file in order to be effectively included---
|
|
||||||
,'upload price' iter
|
|
||||||
,log.id
|
|
||||||
,COALESCE(log.doc->>'tag','') "tag"
|
|
||||||
,log.doc->>'message' "comment"
|
|
||||||
,log.doc->>'type' module
|
|
||||||
-----------debug columns---------
|
|
||||||
--,value_usd/units price
|
|
||||||
--,a.py_gasp
|
|
||||||
--,a.rate
|
|
||||||
--,a.last_price
|
|
||||||
--,a.price_increment
|
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_pool o
|
rlarp.osm_pool o
|
||||||
,rlarp.itemmv i
|
,rlarp.itemmv i
|
||||||
,adj a
|
|
||||||
,log
|
|
||||||
WHERE
|
WHERE
|
||||||
i.item = o.part
|
i.item = o.part
|
||||||
AND a.product = i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
--AND o.units <> 0
|
||||||
AND a.account = o.billto_group
|
|
||||||
AND a.shipgrp = o.shipto_group
|
|
||||||
AND a.price_increment <> 0
|
|
||||||
AND o.units <> 0
|
|
||||||
---only apply to 2022 orders----
|
---only apply to 2022 orders----
|
||||||
AND o.order_date >= '2021-06-01'
|
AND o.order_date >= '2021-06-01'
|
||||||
--only include baseline stuff---
|
--only include baseline stuff---
|
||||||
AND iter IN ('actuals','copy','actuals_plug')
|
AND segm <> 'Retail'
|
||||||
|
GROUP BY
|
||||||
|
i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
||||||
|
,o.quota_rep_descr
|
||||||
|
,o.billto_group
|
||||||
|
,o.shipto_group
|
||||||
|
,order_season
|
||||||
|
--AND iter <> 'upload price'
|
||||||
)
|
)
|
||||||
-----------aggregate the impact------------
|
, pooladj AS (
|
||||||
--SELECT * FROM ins limit 10000
|
SELECT
|
||||||
|
p.product
|
||||||
|
,p.quota_rep_descr
|
||||||
|
,p.billto_group
|
||||||
|
,p.shipto_group
|
||||||
|
,p.price
|
||||||
|
,a.py_gasp
|
||||||
|
,a.rate
|
||||||
|
,a.last_price
|
||||||
|
,a.price_increment
|
||||||
|
FROM
|
||||||
|
poolprice p
|
||||||
|
,adj a
|
||||||
|
WHERE
|
||||||
|
a.product = p.product
|
||||||
|
AND a.account = p.billto_group
|
||||||
|
AND a.shipgrp = p.shipto_group
|
||||||
|
)
|
||||||
|
SELECT * FROM pooladj WHERE product ~ 'STG06000' AND shipto_group = 'BWI' limit 100
|
||||||
|
--SELECT * FROM poolprice WHERE product ~ 'TCA06600' AND shipto_group = 'BWI' AND quota_rep_descr = 'BRYAN HILL' LIMIT 1000
|
||||||
|
-------------build the iteration rows----------------
|
||||||
|
--,ins AS (
|
||||||
--SELECT
|
--SELECT
|
||||||
-- order_season
|
-- o.fspr
|
||||||
-- ,sum(value_loc) val_loc
|
-- ,o.plnt ---master data
|
||||||
-- ,sum(value_usd) val_usd
|
-- ,o.promo --history date mix
|
||||||
|
-- ,o.terms
|
||||||
|
-- ,o.bill_cust_descr --history cust mix
|
||||||
|
-- ,o.ship_cust_descr --history cust mix
|
||||||
|
-- ,o.dsm
|
||||||
|
-- ,o.quota_rep_descr --master data
|
||||||
|
-- ,o.director
|
||||||
|
-- ,o.billto_group --master data
|
||||||
|
-- ,o.shipto_group
|
||||||
|
-- ,o.chan --master data
|
||||||
|
-- ,o.chansub
|
||||||
|
-- ,o.chan_retail
|
||||||
|
-- ,o.part
|
||||||
|
-- ,o.part_descr
|
||||||
|
-- ,o.part_group
|
||||||
|
-- ,o.branding
|
||||||
|
-- ,o.majg_descr
|
||||||
|
-- ,o.ming_descr
|
||||||
|
-- ,o.majs_descr
|
||||||
|
-- ,o.mins_descr
|
||||||
|
-- ,o.segm
|
||||||
|
-- ,o.substance
|
||||||
|
-- ,o.fs_line --master data
|
||||||
|
-- ,o.r_currency --history cust mix
|
||||||
|
-- ,o.r_rate --master data
|
||||||
|
-- ,o.c_currency --master data
|
||||||
|
-- ,o.c_rate --master data
|
||||||
|
-- ,0::numeric units
|
||||||
|
-- ,ROUND(o.units * (a.price_increment/o.r_rate),2) value_loc
|
||||||
|
-- ,ROUND(o.units * a.price_increment,2) value_usd
|
||||||
|
-- ,0::numeric cost_loc
|
||||||
|
-- ,0::numeric cost_usd
|
||||||
|
-- ,o.calc_status --0
|
||||||
|
-- ,o.flag --0
|
||||||
|
-- ,o.order_date --history date mix
|
||||||
|
-- ,o.order_month
|
||||||
|
-- ,o.order_season
|
||||||
|
-- ,o.request_date --history date mix
|
||||||
|
-- ,o.request_month
|
||||||
|
-- ,o.request_season
|
||||||
|
-- ,o.ship_date --history date mix
|
||||||
|
-- ,o.ship_month
|
||||||
|
-- ,o.ship_season
|
||||||
|
-- ,o.version
|
||||||
|
-- ---this iteration has to be listed in the master template file in order to be effectively included---
|
||||||
|
-- ,'upload price' iter
|
||||||
|
-- ,log.id
|
||||||
|
-- ,COALESCE(log.doc->>'tag','') "tag"
|
||||||
|
-- ,log.doc->>'message' "comment"
|
||||||
|
-- ,log.doc->>'type' module
|
||||||
|
-- -----------debug columns---------
|
||||||
|
-- --,value_usd/units price
|
||||||
|
-- --,a.py_gasp
|
||||||
|
-- --,a.rate
|
||||||
|
-- --,a.last_price
|
||||||
|
-- --,a.price_increment
|
||||||
--FROM
|
--FROM
|
||||||
-- ins
|
-- rlarp.osm_pool o
|
||||||
--GROUP BY
|
-- ,rlarp.itemmv i
|
||||||
-- order_season;
|
-- ,adj a
|
||||||
INSERT INTO
|
-- ,log
|
||||||
rlarp.osm_pool
|
--WHERE
|
||||||
SELECT * FROM ins;
|
-- i.item = o.part
|
||||||
|
-- AND a.product = i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
||||||
COMMIT;
|
-- AND a.account = o.billto_group
|
||||||
|
-- AND a.shipgrp = o.shipto_group
|
||||||
|
-- AND a.price_increment <> 0
|
||||||
|
-- AND o.units <> 0
|
||||||
|
-- ---only apply to 2022 orders----
|
||||||
|
-- AND o.order_date >= '2021-06-01'
|
||||||
|
-- --only include baseline stuff---
|
||||||
|
-- AND iter <> 'upload price'
|
||||||
|
--)
|
||||||
|
-------------aggregate the impact------------
|
||||||
|
----SELECT * FROM ins limit 10000
|
||||||
|
----SELECT
|
||||||
|
---- order_season
|
||||||
|
---- ,sum(value_loc) val_loc
|
||||||
|
---- ,sum(value_usd) val_usd
|
||||||
|
----FROM
|
||||||
|
---- ins
|
||||||
|
----GROUP BY
|
||||||
|
---- order_season;
|
||||||
|
--,del AS (
|
||||||
|
-- DELETE FROM rlarp.osm_pool WHERE iter = 'upload price' RETURNING *
|
||||||
|
--)
|
||||||
|
--INSERT INTO
|
||||||
|
-- rlarp.osm_pool
|
||||||
|
--SELECT * FROM ins;
|
||||||
|
--
|
||||||
|
--COMMIT;
|
||||||
|
Loading…
Reference in New Issue
Block a user