Compare commits
No commits in common. "f65b0d02f8d22ec4e6433ac555b09b2b11de841e" and "b32d897b1d3af16ad73779be2f41e5a8a5e11c8a" have entirely different histories.
f65b0d02f8
...
b32d897b1d
@ -1 +0,0 @@
|
||||
curl -H "Content-Type: application/json" -X POST -d@retail_volume.json https://usmidlnx01:8080/scale_v --insecure
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"scenario": {
|
||||
"segm": "Retail",
|
||||
"version": "b22",
|
||||
"iter": [
|
||||
"copy",
|
||||
"adj volume",
|
||||
"adj price",
|
||||
"upload volume",
|
||||
"upload price"
|
||||
]
|
||||
},
|
||||
"stamp": "2021-06-10 08:34:07",
|
||||
"user": "Trowbridge, Paul",
|
||||
"source": "adj",
|
||||
"message": "first scale volume to hit target std cost 36.6-13.2",
|
||||
"tag": "retail plug",
|
||||
"type": "scale_v",
|
||||
"amount": 931051.61,
|
||||
"qty": 1013419.06
|
||||
}
|
@ -300,7 +300,7 @@ GROUP BY
|
||||
s.account = o.billto_group
|
||||
CROSS JOIN log
|
||||
WHERE
|
||||
o.ship_season = 2022
|
||||
o.order_season = 2022
|
||||
AND o.segm = s.segment
|
||||
GROUP BY
|
||||
o.fspr
|
||||
|
@ -1,194 +0,0 @@
|
||||
--BEGIN;
|
||||
|
||||
WITH
|
||||
req AS (
|
||||
SELECT
|
||||
23400000 cost_d
|
||||
)
|
||||
---------collapse iterations-----------------------
|
||||
,collapse 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
|
||||
,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
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,SUM(o.units) units
|
||||
,SUM(o.value_loc) value_loc
|
||||
,SUM(o.value_usd) value_usd
|
||||
-----exclude any prior pricing adjustments from the "current" price in the forecast------
|
||||
,SUM(o.cost_loc) cost_loc
|
||||
,SUM(o.cost_usd) 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
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
WHERE
|
||||
o.segm = 'Retail'
|
||||
AND o.ship_season = '2022'
|
||||
GROUP BY
|
||||
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
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,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
|
||||
--HAVING
|
||||
-- sum(o.units) <> 0
|
||||
)
|
||||
,adj AS (
|
||||
SELECT
|
||||
(SELECT cost_d FROM req) - SUM(o.cost_usd) adj_d
|
||||
,((SELECT cost_d FROM req) - SUM(o.cost_usd))/SUM(o.cost_usd) adj_p
|
||||
FROM
|
||||
collapse o
|
||||
)
|
||||
--SELECT * from adj;
|
||||
----------------create a log entry--------------------
|
||||
,log AS (
|
||||
INSERT INTO
|
||||
rlarp.osm_log(doc)
|
||||
SELECT
|
||||
$${
|
||||
"message":"plug retail sales",
|
||||
"tag":"retail plug",
|
||||
"type":"build"
|
||||
}$$::jsonb doc
|
||||
RETURNING *
|
||||
)
|
||||
-------------build the iteration rows----------------
|
||||
,ins 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
|
||||
,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
|
||||
--,o.units
|
||||
,units*adj.adj_p units
|
||||
,0::numeric value_loc
|
||||
,0::numeric value_usd
|
||||
,cost_loc*adj.adj_p cost_loc
|
||||
,cost_usd*adj.adj_p 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
|
||||
---this iteration has to be listed in the master template file in order to be effectively included---
|
||||
,'b22' AS version
|
||||
,'upload volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
collapse o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
,log
|
||||
,adj
|
||||
)
|
||||
--SELECT *, SUM(VALUE_USD) OVER() FROM (SELECT order_season, order_month, sum(value_usd) value_usd from ins group by order_season, order_month) as x;
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM ins;
|
||||
--SELECT * FROM ins WHERE shipto_group = 'BATTLEFIELD FARMS' and part = 'XNT0TQT3X56B220PYDKP';
|
||||
-----------aggregate the impact------------
|
||||
|
||||
--COMMIT;
|
@ -1,194 +0,0 @@
|
||||
--BEGIN;
|
||||
|
||||
WITH
|
||||
req AS (
|
||||
SELECT
|
||||
36600000 value_d
|
||||
)
|
||||
---------collapse iterations-----------------------
|
||||
,collapse 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
|
||||
,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
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,SUM(o.units) units
|
||||
,SUM(o.value_loc) value_loc
|
||||
,SUM(o.value_usd) value_usd
|
||||
-----exclude any prior pricing adjustments from the "current" price in the forecast------
|
||||
,SUM(o.cost_loc) cost_loc
|
||||
,SUM(o.cost_usd) 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
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
WHERE
|
||||
o.segm = 'Retail'
|
||||
AND o.ship_season = '2022'
|
||||
GROUP BY
|
||||
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
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,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
|
||||
--HAVING
|
||||
-- sum(o.units) <> 0
|
||||
)
|
||||
,adj AS (
|
||||
SELECT
|
||||
(SELECT value_d FROM req) - SUM(o.value_usd) adj_d
|
||||
,((SELECT value_d FROM req) - SUM(o.value_usd))/SUM(o.value_usd) adj_p
|
||||
FROM
|
||||
collapse o
|
||||
)
|
||||
--SELECT * from adj;
|
||||
----------------create a log entry--------------------
|
||||
,log AS (
|
||||
INSERT INTO
|
||||
rlarp.osm_log(doc)
|
||||
SELECT
|
||||
$${
|
||||
"message":"plug retail sales",
|
||||
"tag":"retail plug",
|
||||
"type":"build"
|
||||
}$$::jsonb doc
|
||||
RETURNING *
|
||||
)
|
||||
-------------build the iteration rows----------------
|
||||
,ins 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
|
||||
,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
|
||||
--,o.units
|
||||
,0::numeric units
|
||||
,value_loc*adj.adj_p value_loc
|
||||
,value_usd*adj.adj_p 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
|
||||
---this iteration has to be listed in the master template file in order to be effectively included---
|
||||
,'b22' AS version
|
||||
,'upload volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
collapse o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
,log
|
||||
,adj
|
||||
)
|
||||
--SELECT *, SUM(VALUE_USD) OVER() FROM (SELECT order_season, order_month, sum(value_usd) value_usd from ins group by order_season, order_month) as x;
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM ins;
|
||||
--SELECT * FROM ins WHERE shipto_group = 'BATTLEFIELD FARMS' and part = 'XNT0TQT3X56B220PYDKP';
|
||||
-----------aggregate the impact------------
|
||||
|
||||
--COMMIT;
|
@ -1,191 +0,0 @@
|
||||
--BEGIN;
|
||||
|
||||
WITH
|
||||
----------------create a log entry--------------------
|
||||
log AS (
|
||||
INSERT INTO
|
||||
rlarp.osm_log(doc)
|
||||
SELECT
|
||||
$${
|
||||
"message":"application of last price and target increases to all forecast orders",
|
||||
"tag":"last price r1",
|
||||
"type":"build"
|
||||
}$$::jsonb doc
|
||||
RETURNING *
|
||||
)
|
||||
---------collapse iterations-----------------------
|
||||
,collapse 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
|
||||
,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
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,SUM(o.units) units
|
||||
,SUM(o.value_loc) value_loc
|
||||
,SUM(o.value_usd) value_usd
|
||||
-----exclude any prior pricing adjustments from the "current" price in the forecast------
|
||||
,SUM(o.value_loc) FILTER (WHERE iter <> 'upload price')/SUM(o.units) FILTER (WHERE iter <> 'upload price') price_loc
|
||||
,SUM(o.cost_loc) cost_loc
|
||||
,SUM(o.cost_usd) 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
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
GROUP BY
|
||||
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
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,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
|
||||
HAVING
|
||||
sum(o.units) <> 0
|
||||
)
|
||||
-------------build the iteration rows----------------
|
||||
,ins 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
|
||||
,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
|
||||
--,o.units
|
||||
,0::numeric units
|
||||
,value_loc*.45 value_loc
|
||||
,value_usd*.45 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
|
||||
---this iteration has to be listed in the master template file in order to be effectively included---
|
||||
,'b22' AS version
|
||||
,'upload price' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
collapse o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
,log
|
||||
WHERE
|
||||
-- a.productt = o.productt
|
||||
--AND a.quota_rep_descr = o.quota_rep_descr
|
||||
--AND a.majg = SUBSTRING(o.majg_descr,1,3)
|
||||
--AND a.billto_group = o.billto_group
|
||||
--AND a.shipto_group = o.shipto_group
|
||||
--AND a.chgrp = substring(o.chan,1,1)
|
||||
---only apply to 2022 orders----
|
||||
---join p
|
||||
o.order_date >= '2021-06-01'
|
||||
AND o.segm <> 'Retail'
|
||||
AND o.dsm = 'PW'
|
||||
)
|
||||
--SELECT *, SUM(VALUE_USD) OVER() FROM (SELECT order_season, order_month, sum(value_usd) value_usd from ins group by order_season, order_month) as x;
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM ins;
|
||||
--SELECT * FROM ins WHERE shipto_group = 'BATTLEFIELD FARMS' and part = 'XNT0TQT3X56B220PYDKP';
|
||||
-----------aggregate the impact------------
|
||||
|
||||
--COMMIT;
|
@ -1,195 +0,0 @@
|
||||
--BEGIN;
|
||||
|
||||
WITH
|
||||
req AS (
|
||||
SELECT
|
||||
18454134 value_d
|
||||
)
|
||||
---------collapse iterations-----------------------
|
||||
,collapse 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
|
||||
,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
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,SUM(o.units) units
|
||||
,SUM(o.value_loc) value_loc
|
||||
,SUM(o.value_usd) value_usd
|
||||
-----exclude any prior pricing adjustments from the "current" price in the forecast------
|
||||
,SUM(o.cost_loc) cost_loc
|
||||
,SUM(o.cost_usd) 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
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
WHERE
|
||||
o.segm <> 'Retail'
|
||||
AND o.ship_season = '2022'
|
||||
AND o.ship_month = '01 - Jun'
|
||||
GROUP BY
|
||||
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
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,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
|
||||
--HAVING
|
||||
-- sum(o.units) <> 0
|
||||
)
|
||||
,adj AS (
|
||||
SELECT
|
||||
(SELECT value_d FROM req) - SUM(o.value_usd) adj_d
|
||||
,((SELECT value_d FROM req) - SUM(o.value_usd))/SUM(o.value_usd) adj_p
|
||||
FROM
|
||||
collapse o
|
||||
)
|
||||
--SELECT * from adj;
|
||||
----------------create a log entry--------------------
|
||||
,log AS (
|
||||
INSERT INTO
|
||||
rlarp.osm_log(doc)
|
||||
SELECT
|
||||
$${
|
||||
"message":"top level adjust",
|
||||
"tag":"top level adjust",
|
||||
"type":"build"
|
||||
}$$::jsonb doc
|
||||
RETURNING *
|
||||
)
|
||||
-------------build the iteration rows----------------
|
||||
,ins 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
|
||||
,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
|
||||
--,o.units
|
||||
,units*adj.adj_p units
|
||||
,value_loc*adj.adj_p value_loc
|
||||
,value_usd*adj.adj_p value_usd
|
||||
,cost_loc*adj.adj_p cost_loc
|
||||
,cost_usd*adj.adj_p 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
|
||||
---this iteration has to be listed in the master template file in order to be effectively included---
|
||||
,'b22' AS version
|
||||
,'upload volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
collapse o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
,log
|
||||
,adj
|
||||
)
|
||||
--SELECT *, SUM(VALUE_USD) OVER() FROM (SELECT order_season, order_month, sum(value_usd) value_usd from ins group by order_season, order_month) as x;
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM ins;
|
||||
--SELECT * FROM ins WHERE shipto_group = 'BATTLEFIELD FARMS' and part = 'XNT0TQT3X56B220PYDKP';
|
||||
-----------aggregate the impact------------
|
||||
|
||||
--COMMIT;
|
Loading…
Reference in New Issue
Block a user