Merge branch 'dev'

This commit is contained in:
Paul Trowbridge 2021-04-14 11:55:49 -04:00
commit 745f83e502
4 changed files with 169 additions and 91 deletions

14
change_log.sql Normal file
View 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;

View File

@ -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;

View File

@ -1,15 +1,25 @@
SELECT SELECT
calc_status, calc_status
flag, ,flag
sum(fb_val_loc * r_rate) filter (where 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) overship
sum(fb_val_loc * r_rate) filter (where fb_qty > 0) undership ,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 FROM
rlarp.osm_dev rlarp.osmf_dev
WHERE WHERE
oseas = 2021 (
AND version = 'ACTUALS' (
AND calc_status = 'CLOSED' oseas = 2021
AND flag = 'REMAINDER' 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 GROUP BY
calc_status, calc_status,
flag; flag;

View File

@ -246,7 +246,7 @@ SELECT
,mxm.r_currency ,mxm.r_currency
,jr.bill_cust_descr ,jr.bill_cust_descr
,jr.ship_cust_descr ,jr.ship_cust_descr
,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part ,rtrim((regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1]) part
,jr.part_descr ,jr.part_descr
,substring(jr.part_descr,1,8) part_group ,substring(jr.part_descr,1,8) part_group
,mxm.qty*mxm.momix*jr.mix units ,mxm.qty*mxm.momix*jr.mix units