align rate column

This commit is contained in:
Paul Trowbridge 2021-06-09 16:53:43 -04:00
parent f548780d9f
commit b32d897b1d

View File

@ -10,42 +10,42 @@ incr AS (
('110','PP','M',0.45), ('110','PP','M',0.45),
('110','PP','P',0.45), ('110','PP','P',0.45),
('110','PP','C',0.45), ('110','PP','C',0.45),
('210','PE','B',0.4), ('210','PE','B',0.40),
('210','PE','T',0.4), ('210','PE','T',0.40),
('210','PE','L',0.4), ('210','PE','L',0.40),
('210','PE','M',0.4), ('210','PE','M',0.40),
('210','PE','P',0.4), ('210','PE','P',0.40),
('210','PE','C',0.4), ('210','PE','C',0.40),
('310','PE','B',0.3), ('310','PE','B',0.30),
('310','PE','T',0.35), ('310','PE','T',0.35),
('310','PE','L',0.35), ('310','PE','L',0.35),
('310','PE','M',0.35), ('310','PE','M',0.35),
('310','PE','P',0.35), ('310','PE','P',0.35),
('310','PE','C',0.35), ('310','PE','C',0.35),
('310','PP','B',0.3), ('310','PP','B',0.30),
('310','PP','T',0.3), ('310','PP','T',0.30),
('310','PP','L',0.3), ('310','PP','L',0.30),
('310','PP','M',0.3), ('310','PP','M',0.30),
('310','PP','P',0.3), ('310','PP','P',0.30),
('310','PP','C',0.3), ('310','PP','C',0.30),
('310','PS','B',0.3), ('310','PS','B',0.30),
('310','PS','T',0.3), ('310','PS','T',0.30),
('310','PS','L',0.3), ('310','PS','L',0.30),
('310','PS','M',0.3), ('310','PS','M',0.30),
('310','PS','P',0.3), ('310','PS','P',0.30),
('310','PS','C',0.3), ('310','PS','C',0.30),
('320','PE','B',0.3), ('320','PE','B',0.30),
('320','PE','T',0.3), ('320','PE','T',0.30),
('320','PE','L',0.3), ('320','PE','L',0.30),
('320','PE','M',0.3), ('320','PE','M',0.30),
('320','PE','P',0.3), ('320','PE','P',0.30),
('320','PE','C',0.3), ('320','PE','C',0.30),
('320','PP','B',0.3), ('320','PP','B',0.30),
('320','PP','T',0.3), ('320','PP','T',0.30),
('320','PP','L',0.3), ('320','PP','L',0.30),
('320','PP','M',0.3), ('320','PP','M',0.30),
('320','PP','P',0.3), ('320','PP','P',0.30),
('320','PP','C',0.3), ('320','PP','C',0.30),
('910','PE','B',0.25), ('910','PE','B',0.25),
('910','PE','D',0.25), ('910','PE','D',0.25),
('910','PE','F',0.25), ('910','PE','F',0.25),
@ -350,17 +350,17 @@ GROUP BY
--) --)
--SELECT * FROM test_unique where cnt > 1 --SELECT * FROM test_unique where cnt > 1
----------------create a log entry-------------------- ----------------create a log entry--------------------
,log AS ( --,log AS (
INSERT INTO -- INSERT INTO
rlarp.osm_log(doc) -- rlarp.osm_log(doc)
SELECT -- SELECT
$${ -- $${
"message":"application of last price and target increases to all forecast orders", -- "message":"application of last price and target increases to all forecast orders",
"tag":"last price r1", -- "tag":"last price r1",
"type":"build" -- "type":"build"
}$$::jsonb doc -- }$$::jsonb doc
RETURNING * -- RETURNING *
) --)
---------collapse iterations----------------------- ---------collapse iterations-----------------------
,collapse AS ( ,collapse AS (
SELECT SELECT
@ -518,23 +518,23 @@ SELECT
)*o.units - o.value_loc) * r_rate,2) )*o.units - o.value_loc) * r_rate,2)
,0) AS value_usd ,0) AS value_usd
----debug--- ----debug---
--,least( ,a.py_asp
-- least( ,a.py_gasp
-- COALESCE(a.py_asp,o.price_loc), ,a.last_price
-- COALESCE(a.py_gasp,a.target) ,o.price_loc
-- ) * (1 + a.rate), ,a.target
-- (a.jcprice->>0)::numeric ,a.jcprice
--) AS rev_price ,a.rate
--,o.units ,least(
--,o.value_loc least(
--,o.value_usd COALESCE(a.py_asp,o.price_loc),
--,o.price_loc COALESCE(a.py_gasp,a.target)
--,a.last_price ) * (1 + a.rate),
--,a.target (a.jcprice->>0)::numeric
--,a.jcprice ) AS rev_price
--,a.rate ,o.units qorig
--,a.py_asp ,o.value_loc vl_orig
--,a.py_gasp ,o.value_usd vu_orig
----------- -----------
,0::numeric cost_loc ,0::numeric cost_loc
,0::numeric cost_usd ,0::numeric cost_usd
@ -553,16 +553,16 @@ SELECT
---this iteration has to be listed in the master template file in order to be effectively included--- ---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version ,'b22' AS version
,'upload price' iter ,'upload price' iter
,log.id --,log.id
,COALESCE(log.doc->>'tag','') "tag" --,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment" --,log.doc->>'message' "comment"
,log.doc->>'type' module --,log.doc->>'type' module
FROM FROM
collapse o collapse o
--need to join to itemm to get the product from osm_pool --need to join to itemm to get the product from osm_pool
--,fcp a --,fcp a
,pivot a ,pivot a
,log --,log
WHERE WHERE
-- a.productt = o.productt -- a.productt = o.productt
--AND a.quota_rep_descr = o.quota_rep_descr --AND a.quota_rep_descr = o.quota_rep_descr
@ -579,10 +579,11 @@ WHERE
AND a.shipgrp = o.shipto_group AND a.shipgrp = o.shipto_group
AND o.order_date >= '2021-06-01' AND o.order_date >= '2021-06-01'
AND o.segm <> 'Retail' AND o.segm <> 'Retail'
AND o.dsm = 'PW'
) )
--SELECT order_season, order_month, sum(value_usd) from ins group by order_season, order_month; --SELECT order_season, order_month, sum(value_usd) from ins group by order_season, order_month;
INSERT INTO rlarp.osm_pool SELECT * FROM ins; --INSERT INTO rlarp.osm_pool SELECT * FROM ins;
--SELECT * FROM ins WHERE shipto_group = 'A&W ANNUALS' and part = 'TWA10200G18B027'; SELECT * FROM ins WHERE shipto_group = 'BATTLEFIELD FARMS' and part = 'XNT0TQT3X56B220PYDKP';
-----------aggregate the impact------------ -----------aggregate the impact------------
--COMMIT; --COMMIT;