From dde2e8d581170b94bb5b4b2b773ee31bdac18378 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 20 Mar 2025 00:35:32 -0400 Subject: [PATCH] commit: 2025-03-20 00:35:32 --- build/build_forecast.sql | 9 ++- build/rebuild_script.sh | 4 +- offline/new_cust_profile.pg.sql | 59 ++++++++++++++++++ offline/scale_cust.pg.sql | 45 ++++++++++++++ offline/snap_last_price.pg.sql | 106 ++++++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 offline/new_cust_profile.pg.sql create mode 100644 offline/scale_cust.pg.sql diff --git a/build/build_forecast.sql b/build/build_forecast.sql index aeaa43c..753a74b 100644 --- a/build/build_forecast.sql +++ b/build/build_forecast.sql @@ -33,7 +33,7 @@ baseline AS ( ,null::text dhpost ,o.fspr -----------measures-------------------- - ,null::numeric ddqtoi + ,o.ddqtoi ,null::numeric ddqtsi ,null::numeric fgqshp ,null::numeric diqtsh @@ -149,6 +149,7 @@ baseline AS ( AND version = 'ACTUALS' GROUP BY o.fspr + ,o.ddqtoi ,o.plnt ,COALESCE(o.promo,'') ,o.terms @@ -192,7 +193,7 @@ baseline AS ( ,null::text dhpost ,o.fspr -----------measures-------------------- - ,null::numeric ddqtoi + ,o.ddqtoi ,null::numeric ddqtsi ,null::numeric fgqshp ,null::numeric diqtsh @@ -302,6 +303,7 @@ baseline AS ( AND version = 'ACTUALS' GROUP BY o.fspr + ,o.ddqtoi ,plnt ,COALESCE(o.promo,'') ,o.terms @@ -345,7 +347,7 @@ baseline AS ( ,null::text dhpost ,o.fspr -----------measures-------------------- - ,null::numeric ddqtoi + ,o.ddqtoi ,null::numeric ddqtsi ,null::numeric fgqshp ,null::numeric diqtsh @@ -450,6 +452,7 @@ baseline AS ( ------dont pull forecast for a baseline this time around-- GROUP BY o.fspr + ,o.ddqtoi ,plnt ,COALESCE(o.promo,'') ,o.terms diff --git a/build/rebuild_script.sh b/build/rebuild_script.sh index f007c75..8e62aaf 100755 --- a/build/rebuild_script.sh +++ b/build/rebuild_script.sh @@ -5,5 +5,5 @@ $PG -f ./build/build_forecast.sql $PG -f ./build/snap_itemm.sql; $PG -f ./build/snap_cost_current.sql; $PG -f ./build/snap_customer.sql; -$PG -f ./build/build_pool.sql; -$PG -c "CALL rlarp.convert_pool_all();" +#$PG -f ./build/build_pool.sql; +#$PG -c "CALL rlarp.convert_pool_all();" diff --git a/offline/new_cust_profile.pg.sql b/offline/new_cust_profile.pg.sql new file mode 100644 index 0000000..78e618f --- /dev/null +++ b/offline/new_cust_profile.pg.sql @@ -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 diff --git a/offline/scale_cust.pg.sql b/offline/scale_cust.pg.sql new file mode 100644 index 0000000..be5b95b --- /dev/null +++ b/offline/scale_cust.pg.sql @@ -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 diff --git a/offline/snap_last_price.pg.sql b/offline/snap_last_price.pg.sql index e69de29..d13c669 100644 --- a/offline/snap_last_price.pg.sql +++ b/offline/snap_last_price.pg.sql @@ -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