calculate current pricing by excluding forecast-to-date pricing

This commit is contained in:
Paul Trowbridge 2021-05-24 17:53:41 -04:00
parent c1b8062d67
commit 8bdcd5cc3e

View File

@ -397,7 +397,8 @@ GROUP BY
,SUM(o.units) units ,SUM(o.units) units
,SUM(o.value_loc) value_loc ,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd ,SUM(o.value_usd) value_usd
,SUM(o.value_loc)/SUM(o.units) price_loc -----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_loc) cost_loc
,SUM(o.cost_usd) cost_usd ,SUM(o.cost_usd) cost_usd
,o.calc_status --0 ,o.calc_status --0
@ -498,6 +499,7 @@ SELECT
,0::numeric units ,0::numeric units
,greatest( ,greatest(
round(least( round(least(
----cap pricing at global ASP or target---
least( least(
COALESCE(a.py_asp,o.price_loc), COALESCE(a.py_asp,o.price_loc),
COALESCE(a.py_gasp,a.target) COALESCE(a.py_gasp,a.target)
@ -508,6 +510,7 @@ SELECT
,greatest( ,greatest(
round((least( round((least(
least( least(
-----price loc needs to be prior to any other pricing adjustments-----
COALESCE(a.py_asp,o.price_loc), COALESCE(a.py_asp,o.price_loc),
COALESCE(a.py_gasp,a.target) COALESCE(a.py_gasp,a.target)
) * (1 + a.rate), ) * (1 + a.rate),
@ -554,12 +557,6 @@ SELECT
,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
-----------debug columns---------
--,value_usd/units price
--,a.py_gasp
--,a.rate
--,a.last_price
--,a.price_increment
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
@ -585,6 +582,7 @@ WHERE
) )
--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';
-----------aggregate the impact------------ -----------aggregate the impact------------
COMMIT; --COMMIT;