commit: 2025-03-20 00:35:32

This commit is contained in:
Paul Trowbridge 2025-03-20 00:35:32 -04:00
parent f2f4dcedae
commit dde2e8d581
5 changed files with 218 additions and 5 deletions

View File

@ -33,7 +33,7 @@ baseline AS (
,null::text dhpost ,null::text dhpost
,o.fspr ,o.fspr
-----------measures-------------------- -----------measures--------------------
,null::numeric ddqtoi ,o.ddqtoi
,null::numeric ddqtsi ,null::numeric ddqtsi
,null::numeric fgqshp ,null::numeric fgqshp
,null::numeric diqtsh ,null::numeric diqtsh
@ -149,6 +149,7 @@ baseline AS (
AND version = 'ACTUALS' AND version = 'ACTUALS'
GROUP BY GROUP BY
o.fspr o.fspr
,o.ddqtoi
,o.plnt ,o.plnt
,COALESCE(o.promo,'') ,COALESCE(o.promo,'')
,o.terms ,o.terms
@ -192,7 +193,7 @@ baseline AS (
,null::text dhpost ,null::text dhpost
,o.fspr ,o.fspr
-----------measures-------------------- -----------measures--------------------
,null::numeric ddqtoi ,o.ddqtoi
,null::numeric ddqtsi ,null::numeric ddqtsi
,null::numeric fgqshp ,null::numeric fgqshp
,null::numeric diqtsh ,null::numeric diqtsh
@ -302,6 +303,7 @@ baseline AS (
AND version = 'ACTUALS' AND version = 'ACTUALS'
GROUP BY GROUP BY
o.fspr o.fspr
,o.ddqtoi
,plnt ,plnt
,COALESCE(o.promo,'') ,COALESCE(o.promo,'')
,o.terms ,o.terms
@ -345,7 +347,7 @@ baseline AS (
,null::text dhpost ,null::text dhpost
,o.fspr ,o.fspr
-----------measures-------------------- -----------measures--------------------
,null::numeric ddqtoi ,o.ddqtoi
,null::numeric ddqtsi ,null::numeric ddqtsi
,null::numeric fgqshp ,null::numeric fgqshp
,null::numeric diqtsh ,null::numeric diqtsh
@ -450,6 +452,7 @@ baseline AS (
------dont pull forecast for a baseline this time around-- ------dont pull forecast for a baseline this time around--
GROUP BY GROUP BY
o.fspr o.fspr
,o.ddqtoi
,plnt ,plnt
,COALESCE(o.promo,'') ,COALESCE(o.promo,'')
,o.terms ,o.terms

View File

@ -5,5 +5,5 @@ $PG -f ./build/build_forecast.sql
$PG -f ./build/snap_itemm.sql; $PG -f ./build/snap_itemm.sql;
$PG -f ./build/snap_cost_current.sql; $PG -f ./build/snap_cost_current.sql;
$PG -f ./build/snap_customer.sql; $PG -f ./build/snap_customer.sql;
$PG -f ./build/build_pool.sql; #$PG -f ./build/build_pool.sql;
$PG -c "CALL rlarp.convert_pool_all();" #$PG -c "CALL rlarp.convert_pool_all();"

View File

@ -0,0 +1,59 @@
WITH
newc AS (
SELECT
*
FROM
(
VALUES
('JOHNSON FARMS'),
('QUALITREE PROPAGATORS'),
('TY NURSERY INC'),
('CK GREENHOUSES'),
('DESERT HORIZON NURSERY'),
('PHELPS NURSERY'),
('R PLANTS'),
('STOKLEY NURSERY'),
('ONE FLORAL'),
('HUIZENGA BRO GREENHOUSE INC'),
('SUNRISE GREENHOUSES'),
('HORTECH INC'),
('EDGEWOOD GREENHOUSE'),
('DGI'),
('DAYNABROOK GREENHOUSES'),
('A&W ANNUALS'),
('ANDERSEN NURSERY'),
('BUCKHORN NURSERY'),
('RAZBUTONS INC'),
('HSU''S'),
('JANOSKI GREENHOUSE'),
('GROWERS SOLUTION LLC'),
('GREEN BARN INC'),
('HONEYMOON ACRES'),
('WALNUT GROVE NURSERY'),
('PIEPER NURSERY'),
('SUN NURSERIES'),
('D''ADDIO FAMILY NURSERY'),
('BOEKESTYN GREENHOUSES LTD'),
('GORRELL BROTHERS LLC'),
('EXOTIC BOTANICALS'),
('SPRING VALLEY NURSERY'),
('PINE VIEW FARM'),
('BROUWERS FLOWERS'),
('HUNTER ROAD GREENHOUSES'),
('CAPOGNA FLOWERS'),
('J FRANK GAUDET TREE NURSERY'),
('SALMON WHOLESALE NURSERY'),
('ORLANDO NURSERY INC'),
('ARIZONA EAST'),
('ALASKA GDN & PET SUPPLY RET'),
('TONYS GARDEN CENTER'),
('SESTER FARMS INC')
) x(cust)
)
,profile AS (
SELECT * FROM rlarp.osm WHERE shipgrp IN (select cust FROM newc ) AND oseas = 2019
)
,checkc AS (
SELECT distinct shipgrp FROM profile
)
SELECT cust, sum(fb_qty) FROM newc LEFT OUTER JOIN profile ON shipgrp = cust GROUP by cust

45
offline/scale_cust.pg.sql Normal file
View File

@ -0,0 +1,45 @@
WITH
grp AS (
SELECT
o.account
,o.shipgrp
,o.part
,o.oseas
,o.odate
,o.sseas
,o.sdate
-- ,o.calc_status
,ROUND(sum(fb_qty * lbs),5) lbs
,ROUND(sum(fb_qty),2) qty
,ROUND(sum(fb_val_loc * r_rate),2) sales_usd
,ROUND(sum(fb_cst_loc_cur * c_rate),2) cost_curstd_usd
FROM
rlarp.osmf o
WHERE
iter IN ('actuals','actuals_plug','copy')
GROUP BY
o.account
,o.shipgrp
,o.part
,o.oseas
,o.odate
,o.sseas
,o.sdate
-- ,o.calc_status
)
SELECT
account
,shipgrp
,part
,oseas
,odate
,sseas
,sdate
-- ,calc_status
,lbs
,qty
,sales_usd
,cost_curstd_usd
,sum(lbs) OVER (PARTITION BY shipgrp, oseas) shiplbs
FROM
grp

View File

@ -0,0 +1,106 @@
-- WITH
-- grp AS (
-- SELECT
-- o.account
-- ,o.shipgrp
-- ,o.part
-- ,o.odate
-- ,round(o.fb_val_loc/o.fb_qty,5) price
-- ,o.ddqtoi
-- ,i.mpck
-- ,o.lbs
-- FROM
-- rlarp.osmf o
-- LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
-- i.item = o.part
-- WHERE
-- version = 'b26'
-- GROUP BY
-- o.account
-- ,o.shipgrp
-- ,o.part
-- ,o.odate
-- ,round(o.fb_val_loc/o.fb_qty,5)
-- ,o.ddqtoi
-- ,i.mpck
-- ,o.lbs
-- )
-- SELECT
-- account
-- ,shipgrp
-- ,part
-- ,odate
-- ,price
-- ,ddqtoi
-- ,round(avg(price) over (PARTITION BY account, shipgrp, part),5) avgprice
-- ,row_number() OVER (PARTITION BY account, shipgrp, part ORDER BY odate desc) rn
-- ,mpck
-- ,lbs
-- FROM grp
WITH
grp AS (
SELECT
o.bill_dba
,o.ship_dba
,o.part
,o.odate
,o.qtyord
,i.nwht * CASE WHEN i.nwun = 'KG' THEN 2.2 ELSE 1 END lbs
,i.mpck pltq
,ROUND(o.sales_usd / o.qty,5) price
,(o.pricing->>'guidance_price')::NUMERIC guidance
,(o.pricing->>'floor' )::numeric(15,5) floor
,(o.pricing->>'ceiling')::numeric(15,5) ceiling
,(o.pricing->>'uselimits')::boolean uselimits
FROM
rlarp.osm_stack o
LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
i.item = o.part
WHERE
VERSION = 'Actual'
AND oseas >= 2024
AND calc_status <> 'CANCELED'
AND o.fs_line = '41010'
AND o.part <> ''
AND substring(o.glec,1,1) <= '2'
AND o.qty <> 0
GROUP BY
o.bill_dba
,o.ship_dba
,o.part
,o.odate
,o.qtyord
,o.pounds
,o.pallets
,ROUND(o.sales_usd / o.qty,5)
,i.nwht * CASE WHEN i.nwun = 'KG' THEN 2.2 ELSE 1 END
,i.mpck
,(o.pricing->>'guidance_price')::NUMERIC
,(o.pricing->>'floor' )::numeric(15,5)
,(o.pricing->>'ceiling')::numeric(15,5)
,(o.pricing->>'uselimits')::boolean
)
,seq AS (
SELECT
bill_dba
,ship_dba
,part
,odate
,qtyord
,lbs
,pltq
,price
,guidance
,floor
,ceiling
,uselimits
,row_number() OVER (PARTITION BY bill_dba, ship_dba, part ORDER BY odate desc) rn
,round(avg(price) over (PARTITION BY bill_dba, ship_dba, part),5) avgprice
FROM
grp
)
SELECT * FROM seq WHERE rn = 1
SELECT
FROM
rlarp.osm