Merge branch 'dev'
This commit is contained in:
commit
745f83e502
14
change_log.sql
Normal file
14
change_log.sql
Normal file
@ -0,0 +1,14 @@
|
||||
WITH l AS (
|
||||
SELECT DISTINCT logid FROM rlarp.osm_pool
|
||||
)
|
||||
SELECT
|
||||
doc->>'user' as user,
|
||||
(doc->>'stamp')::timestamptz stamp,
|
||||
doc->>'type' as type,
|
||||
CASE WHEN logid IS NULL THEN 'undone' ELSE '' END flag,
|
||||
doc->>'tag', doc->>'message',
|
||||
doc->'scenario'->>'quota_rep_descr' dsm
|
||||
FROM
|
||||
rlarp.osm_log
|
||||
LEFT OUTER JOIN l ON logid = id
|
||||
LIMIT 1000;
|
@ -1,4 +1,4 @@
|
||||
BEGIN;
|
||||
--BEGIN;
|
||||
|
||||
WITH
|
||||
------------------goal price increases---------------------
|
||||
@ -257,96 +257,150 @@ FROM
|
||||
}$$::jsonb doc
|
||||
RETURNING *
|
||||
)
|
||||
-------------build the iteration rows----------------
|
||||
,ins AS (
|
||||
,poolprice AS (
|
||||
SELECT
|
||||
o.fspr
|
||||
,o.plnt ---master data
|
||||
,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
|
||||
i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) product
|
||||
,o.quota_rep_descr
|
||||
,o.billto_group
|
||||
,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
|
||||
,order_season
|
||||
,sum(units) units
|
||||
,sum(value_loc) valloc
|
||||
,sum(value_usd) valusd
|
||||
,sum(o.value_loc)/sum(o.units) price
|
||||
,jsonb_agg(DISTINCT iter) iters
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
,rlarp.itemmv i
|
||||
,adj a
|
||||
,log
|
||||
WHERE
|
||||
i.item = o.part
|
||||
AND a.product = i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
||||
AND a.account = o.billto_group
|
||||
AND a.shipgrp = o.shipto_group
|
||||
AND a.price_increment <> 0
|
||||
AND o.units <> 0
|
||||
--AND o.units <> 0
|
||||
---only apply to 2022 orders----
|
||||
AND o.order_date >= '2021-06-01'
|
||||
--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------------
|
||||
--SELECT * FROM ins limit 10000
|
||||
, pooladj AS (
|
||||
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
|
||||
-- order_season
|
||||
-- ,sum(value_loc) val_loc
|
||||
-- ,sum(value_usd) val_usd
|
||||
-- o.fspr
|
||||
-- ,o.plnt ---master data
|
||||
-- ,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
|
||||
-- ins
|
||||
--GROUP BY
|
||||
-- order_season;
|
||||
INSERT INTO
|
||||
rlarp.osm_pool
|
||||
SELECT * FROM ins;
|
||||
|
||||
COMMIT;
|
||||
-- rlarp.osm_pool o
|
||||
-- ,rlarp.itemmv i
|
||||
-- ,adj a
|
||||
-- ,log
|
||||
--WHERE
|
||||
-- i.item = o.part
|
||||
-- AND a.product = i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
||||
-- 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;
|
||||
|
@ -1,15 +1,25 @@
|
||||
SELECT
|
||||
calc_status,
|
||||
flag,
|
||||
sum(fb_val_loc * r_rate) filter (where fb_qty < 0) overship,
|
||||
sum(fb_val_loc * r_rate) filter (where fb_qty > 0) undership
|
||||
calc_status
|
||||
,flag
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty < 0) overship
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty > 0) undership
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND fb_qty = 0) no_units
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND dhincr = 'C') credits
|
||||
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND "ddord#" = 0 ) no_units
|
||||
FROM
|
||||
rlarp.osm_dev
|
||||
rlarp.osmf_dev
|
||||
WHERE
|
||||
oseas = 2021
|
||||
AND version = 'ACTUALS'
|
||||
AND calc_status = 'CLOSED'
|
||||
AND flag = 'REMAINDER'
|
||||
(
|
||||
(
|
||||
oseas = 2021
|
||||
AND odate <@ daterange('2020-06-01','2021-04-11')
|
||||
)
|
||||
OR sseas = 2021
|
||||
)
|
||||
AND fs_line = '41010'
|
||||
--AND version = 'ACTUALS'
|
||||
--AND calc_status = 'CLOSED'
|
||||
--AND flag = 'REMAINDER'
|
||||
GROUP BY
|
||||
calc_status,
|
||||
flag;
|
||||
|
@ -246,7 +246,7 @@ SELECT
|
||||
,mxm.r_currency
|
||||
,jr.bill_cust_descr
|
||||
,jr.ship_cust_descr
|
||||
,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part
|
||||
,rtrim((regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1]) part
|
||||
,jr.part_descr
|
||||
,substring(jr.part_descr,1,8) part_group
|
||||
,mxm.qty*mxm.momix*jr.mix units
|
||||
|
Loading…
Reference in New Issue
Block a user