Merge branch 'dev'

This commit is contained in:
Paul Trowbridge 2021-06-02 09:03:34 -04:00
commit 3fe5126861
3 changed files with 66 additions and 58 deletions

View File

@ -6,8 +6,8 @@ TRUNCATE TABLE rlarp.osmf_dev;
DROP TABLE IF EXISTS tdr; DROP TABLE IF EXISTS tdr;
CREATE TEMP TABLE tdr AS ( CREATE TEMP TABLE tdr AS (
SELECT SELECT
DATERANGE('2020-05-01','2021-05-01','[)') drange DATERANGE('2020-06-01','2021-06-01','[)') drange
,DATERANGE(('2020-05-01'::date + '1 year'::interval)::date,('2021-05-01'::date + '1 year'::interval)::date,'[)') repl ,DATERANGE(('2020-06-01'::date + '1 year'::interval)::date,('2021-06-01'::date + '1 year'::interval)::date,'[)') repl
,'1 year'::interval AS incr ,'1 year'::interval AS incr
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter ,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter
); );

View File

@ -110,7 +110,8 @@ SELECT
ship_date, ship_date,
ship_season, ship_season,
version, version,
iter iter,
tag
FROM FROM
rlarp.osm_pool; rlarp.osm_pool;

View File

@ -1,51 +1,51 @@
BEGIN; --BEGIN;
WITH WITH
------------------goal price increases--------------------- ------------------goal price increases---------------------
incr AS ( incr AS (
SELECT * FROM (VALUES SELECT * FROM (VALUES
('110','PP','B',0.3), ('110','PP','B',0.35),
('110','PP','T',0.3), ('110','PP','T',0.35),
('110','PP','L',0.4), ('110','PP','L',0.45),
('110','PP','M',0.4), ('110','PP','M',0.45),
('110','PP','P',0.4), ('110','PP','P',0.45),
('110','PP','C',0.4), ('110','PP','C',0.45),
('210','PE','B',0.3), ('210','PE','B',0.4),
('210','PE','T',0.3), ('210','PE','T',0.4),
('210','PE','L',0.3), ('210','PE','L',0.4),
('210','PE','M',0.3), ('210','PE','M',0.4),
('210','PE','P',0.3), ('210','PE','P',0.4),
('210','PE','C',0.3), ('210','PE','C',0.4),
('310','PE','B',0.25), ('310','PE','B',0.3),
('310','PE','T',0.3), ('310','PE','T',0.35),
('310','PE','L',0.3), ('310','PE','L',0.35),
('310','PE','M',0.3), ('310','PE','M',0.35),
('310','PE','P',0.3), ('310','PE','P',0.35),
('310','PE','C',0.3), ('310','PE','C',0.35),
('310','PP','B',0.25), ('310','PP','B',0.3),
('310','PP','T',0.25), ('310','PP','T',0.3),
('310','PP','L',0.25), ('310','PP','L',0.3),
('310','PP','M',0.25), ('310','PP','M',0.3),
('310','PP','P',0.25), ('310','PP','P',0.3),
('310','PP','C',0.25), ('310','PP','C',0.3),
('310','PS','B',0.25), ('310','PS','B',0.3),
('310','PS','T',0.25), ('310','PS','T',0.3),
('310','PS','L',0.25), ('310','PS','L',0.3),
('310','PS','M',0.25), ('310','PS','M',0.3),
('310','PS','P',0.25), ('310','PS','P',0.3),
('310','PS','C',0.25), ('310','PS','C',0.3),
('320','PE','B',0.25), ('320','PE','B',0.3),
('320','PE','T',0.25), ('320','PE','T',0.3),
('320','PE','L',0.25), ('320','PE','L',0.3),
('320','PE','M',0.25), ('320','PE','M',0.3),
('320','PE','P',0.25), ('320','PE','P',0.3),
('320','PE','C',0.25), ('320','PE','C',0.3),
('320','PP','B',0.25), ('320','PP','B',0.3),
('320','PP','T',0.25), ('320','PP','T',0.3),
('320','PP','L',0.25), ('320','PP','L',0.3),
('320','PP','M',0.25), ('320','PP','M',0.3),
('320','PP','P',0.25), ('320','PP','P',0.3),
('320','PP','C',0.25), ('320','PP','C',0.3),
('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),
@ -55,6 +55,14 @@ incr AS (
('910','PS','B',0.25), ('910','PS','B',0.25),
('910','PS','D',0.25), ('910','PS','D',0.25),
('910','PS','F',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','','B',0.02),
('610','','S',0.02), ('610','','S',0.02),
('610','','W',0.02) ('610','','W',0.02)
@ -268,14 +276,15 @@ SELECT
ELSE CASE p.majg ELSE CASE p.majg
WHEN '610' THEN .02 WHEN '610' THEN .02
ElSE CASE p.colgrp ElSE CASE p.colgrp
WHEN 'B' THEN .15 WHEN 'B' THEN .20
WHEN 'C' THEN .20 WHEN 'C' THEN .25
ELSE 1 ELSE 1
END END
END END
END rate END rate
,ms.avg_price target ,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 --,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL
-- THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL -- THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
-- THEN 'unknown' -- THEN 'unknown'
@ -347,7 +356,7 @@ GROUP BY
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", "tag":"last price r1",
"type":"build" "type":"build"
}$$::jsonb doc }$$::jsonb doc
RETURNING * RETURNING *
@ -388,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
@ -489,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)
@ -499,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),
@ -545,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
@ -576,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;