diff --git a/build/build_stage.sql b/build/build_stage.sql index db18bb6..f14d8c3 100644 --- a/build/build_stage.sql +++ b/build/build_stage.sql @@ -6,8 +6,8 @@ TRUNCATE TABLE rlarp.osmf_dev; DROP TABLE IF EXISTS tdr; CREATE TEMP TABLE tdr AS ( SELECT - DATERANGE('2020-05-01','2021-05-01','[)') drange - ,DATERANGE(('2020-05-01'::date + '1 year'::interval)::date,('2021-05-01'::date + '1 year'::interval)::date,'[)') repl + DATERANGE('2020-06-01','2021-06-01','[)') drange + ,DATERANGE(('2020-06-01'::date + '1 year'::interval)::date,('2021-06-01'::date + '1 year'::interval)::date,'[)') repl ,'1 year'::interval AS incr ,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter ); diff --git a/build/convert_pool_all.sql b/build/convert_pool_all.sql index dc8fa78..67370a8 100644 --- a/build/convert_pool_all.sql +++ b/build/convert_pool_all.sql @@ -110,7 +110,8 @@ SELECT ship_date, ship_season, version, - iter + iter, + tag FROM rlarp.osm_pool; diff --git a/offline/last_price.sql b/offline/last_price.sql index 8379d7a..88582b9 100644 --- a/offline/last_price.sql +++ b/offline/last_price.sql @@ -1,51 +1,51 @@ -BEGIN; +--BEGIN; WITH ------------------goal price increases--------------------- incr AS ( SELECT * FROM (VALUES - ('110','PP','B',0.3), - ('110','PP','T',0.3), - ('110','PP','L',0.4), - ('110','PP','M',0.4), - ('110','PP','P',0.4), - ('110','PP','C',0.4), - ('210','PE','B',0.3), - ('210','PE','T',0.3), - ('210','PE','L',0.3), - ('210','PE','M',0.3), - ('210','PE','P',0.3), - ('210','PE','C',0.3), - ('310','PE','B',0.25), - ('310','PE','T',0.3), - ('310','PE','L',0.3), - ('310','PE','M',0.3), - ('310','PE','P',0.3), - ('310','PE','C',0.3), - ('310','PP','B',0.25), - ('310','PP','T',0.25), - ('310','PP','L',0.25), - ('310','PP','M',0.25), - ('310','PP','P',0.25), - ('310','PP','C',0.25), - ('310','PS','B',0.25), - ('310','PS','T',0.25), - ('310','PS','L',0.25), - ('310','PS','M',0.25), - ('310','PS','P',0.25), - ('310','PS','C',0.25), - ('320','PE','B',0.25), - ('320','PE','T',0.25), - ('320','PE','L',0.25), - ('320','PE','M',0.25), - ('320','PE','P',0.25), - ('320','PE','C',0.25), - ('320','PP','B',0.25), - ('320','PP','T',0.25), - ('320','PP','L',0.25), - ('320','PP','M',0.25), - ('320','PP','P',0.25), - ('320','PP','C',0.25), + ('110','PP','B',0.35), + ('110','PP','T',0.35), + ('110','PP','L',0.45), + ('110','PP','M',0.45), + ('110','PP','P',0.45), + ('110','PP','C',0.45), + ('210','PE','B',0.4), + ('210','PE','T',0.4), + ('210','PE','L',0.4), + ('210','PE','M',0.4), + ('210','PE','P',0.4), + ('210','PE','C',0.4), + ('310','PE','B',0.3), + ('310','PE','T',0.35), + ('310','PE','L',0.35), + ('310','PE','M',0.35), + ('310','PE','P',0.35), + ('310','PE','C',0.35), + ('310','PP','B',0.3), + ('310','PP','T',0.3), + ('310','PP','L',0.3), + ('310','PP','M',0.3), + ('310','PP','P',0.3), + ('310','PP','C',0.3), + ('310','PS','B',0.3), + ('310','PS','T',0.3), + ('310','PS','L',0.3), + ('310','PS','M',0.3), + ('310','PS','P',0.3), + ('310','PS','C',0.3), + ('320','PE','B',0.3), + ('320','PE','T',0.3), + ('320','PE','L',0.3), + ('320','PE','M',0.3), + ('320','PE','P',0.3), + ('320','PE','C',0.3), + ('320','PP','B',0.3), + ('320','PP','T',0.3), + ('320','PP','L',0.3), + ('320','PP','M',0.3), + ('320','PP','P',0.3), + ('320','PP','C',0.3), ('910','PE','B',0.25), ('910','PE','D',0.25), ('910','PE','F',0.25), @@ -55,6 +55,14 @@ incr AS ( ('910','PS','B',0.25), ('910','PS','D',0.25), ('910','PS','F',0.25), + ('910','','B',0.25), + ('910','','T',0.25), + ('910','','L',0.25), + ('910','','M',0.25), + ('910','','P',0.25), + ('910','','D',0.25), + ('910','','F',0.25), + ('910','','C',0.25), ('610','','B',0.02), ('610','','S',0.02), ('610','','W',0.02) @@ -268,14 +276,15 @@ SELECT ELSE CASE p.majg WHEN '610' THEN .02 ElSE CASE p.colgrp - WHEN 'B' THEN .15 - WHEN 'C' THEN .20 + WHEN 'B' THEN .20 + WHEN 'C' THEN .25 ELSE 1 END END END rate ,ms.avg_price target - ,JSONB_AGG(DISTINCT plist.jcpric/1000) jcprice + ----------------potential price list increase of 5% across board----- + ,JSONB_AGG(DISTINCT (plist.jcpric*1.05)/1000) jcprice --,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL -- THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL -- THEN 'unknown' @@ -347,7 +356,7 @@ GROUP BY SELECT $${ "message":"application of last price and target increases to all forecast orders", - "tag":"last price", + "tag":"last price r1", "type":"build" }$$::jsonb doc RETURNING * @@ -388,7 +397,8 @@ GROUP BY ,SUM(o.units) units ,SUM(o.value_loc) value_loc ,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_usd) cost_usd ,o.calc_status --0 @@ -489,6 +499,7 @@ SELECT ,0::numeric units ,greatest( round(least( + ----cap pricing at global ASP or target--- least( COALESCE(a.py_asp,o.price_loc), COALESCE(a.py_gasp,a.target) @@ -499,6 +510,7 @@ SELECT ,greatest( round((least( least( + -----price loc needs to be prior to any other pricing adjustments----- COALESCE(a.py_asp,o.price_loc), COALESCE(a.py_gasp,a.target) ) * (1 + a.rate), @@ -545,12 +557,6 @@ SELECT ,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 collapse o --need to join to itemm to get the product from osm_pool @@ -576,6 +582,7 @@ WHERE ) --SELECT order_season, order_month, sum(value_usd) from ins group by order_season, order_month; INSERT INTO rlarp.osm_pool SELECT * FROM ins; +--SELECT * FROM ins WHERE shipto_group = 'A&W ANNUALS' and part = 'TWA10200G18B027'; -----------aggregate the impact------------ -COMMIT; +--COMMIT;