increment sql

This commit is contained in:
Paul Trowbridge 2025-04-04 13:43:47 -04:00
parent 77e1fc1f55
commit db3dc8bc73
7 changed files with 84 additions and 28 deletions

View File

@ -135,7 +135,7 @@ baseline AS (
WHERE WHERE
( (
--base period orders booked.... --base period orders booked....
o.odate BETWEEN '2024-06-01' AND '2025-03-26' o.odate BETWEEN '2024-06-01' AND '2025-03-31'
--...or any open orders currently booked before cutoff.... --...or any open orders currently booked before cutoff....
--OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01') --OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01')
--...or anything that shipped in that period --...or anything that shipped in that period
@ -292,7 +292,7 @@ baseline AS (
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
WHERE WHERE
true true
AND o.odate BETWEEN '2024-03-26' AND '2024-05-31' AND o.odate BETWEEN '2024-04-01' AND '2024-05-31'
AND fs_line = '41010' AND fs_line = '41010'
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
--AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') --AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')

View File

@ -155,6 +155,7 @@ SELECT
,logload.doc->>'tag' tag ,logload.doc->>'tag' tag
,logload.doc->>'message' "comment" ,logload.doc->>'message' "comment"
,logload.doc->>'type' module ,logload.doc->>'type' module
,round(o.fb_qty * o.lbs) pounds
FROM FROM
rlarp.osmf o rlarp.osmf o
CROSS JOIN logload CROSS JOIN logload
@ -181,7 +182,7 @@ FROM
LEFT OUTER JOIN "CMS.CUSLG".itemm i ON LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
i.item = o.part i.item = o.part
) )
SELECT * FROM loadset SELECT * FROM loadset WHERE iter NOT IN ('py carryover','short ship','bad date')
) WITH DATA; ) WITH DATA;

View File

@ -379,6 +379,50 @@ WHERE
AND CR.SHIP_CUST = S.SHIP_CUST AND CR.SHIP_CUST = S.SHIP_CUST
AND COALESCE(S.DSM,'') <> CR.QUOTA_REP; AND COALESCE(S.DSM,'') <> CR.QUOTA_REP;
--------------------------------------------------------------------------
---------------------------Add Ownership columns--------------------------
--------------------------------------------------------------------------
UPDATE
rlarp.osmfs s
SET
dsm = cr.default_rep
-- keyaccount_rep = cr.keyaccount_rep,
-- retail_rep = cr.retail_rep,
-- inside_rep = cr.inside_rep
FROM (
SELECT DISTINCT
s.bill_cust,
bc.cclass,
s.ship_cust,
CASE substring(s.ming, 1, 3)
WHEN 'A27' THEN '70100'
ELSE COALESCE(sc.default_rep, bc.default_rep)
END AS default_rep,
CASE
WHEN COALESCE(sc.keyaccount_rep, '') <> '' AND bc.cclass = 'GDIS' THEN sc.keyaccount_rep
ELSE bc.keyaccount_rep
END AS keyaccount_rep,
s.glec,
CASE
WHEN COALESCE(s.glec, '') = '1RE' AND COALESCE(bc.retail_rep, '') <> '' THEN bc.retail_rep
ELSE NULL
END AS retail_rep,
CASE SUBSTRING(bc.cclass, 2, 3)
WHEN 'DIS' THEN sc.inside_rep
ELSE bc.inside_rep
END AS inside_rep
FROM
rlarp.osmfs s
LEFT OUTER JOIN rlarp.cust bc ON bc.code = s.bill_cust
LEFT OUTER JOIN rlarp.cust sc ON sc.code = s.ship_cust
WHERE
glec IS NOT NULL
) cr
WHERE
cr.glec = s.glec
AND cr.bill_cust = s.bill_cust
AND COALESCE(cr.ship_cust, '') = COALESCE(s.ship_cust, '');
-------------------set fiscal period-------------------------------------- -------------------set fiscal period--------------------------------------

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

@ -38,6 +38,17 @@ FROM
WHERE WHERE
c.part = o.part c.part = o.part
AND c.plnt = o.plnt; AND c.plnt = o.plnt;
UPDATE
rlarp.osmf o
SET
fb_cst_loc_fut = c.std * o.fb_qty
FROM
rlarp.arcstx c
WHERE
c.part = o.part
AND c.plnt = o.plnt;
--AND version = 'b21'; --AND version = 'b21';
commit; commit;

View File

@ -250,13 +250,13 @@ SELECT
,substring(jr.part_descr,1,8) part_group ,substring(jr.part_descr,1,8) part_group
,mxm.qty*mxm.momix*jr.mix units ,mxm.qty*mxm.momix*jr.mix units
,mxm.amount*mxm.momix*jr.mix value_usd --assume that target dollars are USD ,mxm.amount*mxm.momix*jr.mix value_usd --assume that target dollars are USD
,make_date(mxm.yr + 2025,mxm.cal,mxm.odom) order_date ,make_date(mxm.yr + 2026,mxm.cal,mxm.odom) order_date
,od.sortmo order_month ,od.sortmo order_month
,od.ssyr order_season ,od.ssyr order_season
,make_date(mxm.yr + 2025,mxm.cal,mxm.odom) + rlag request_date ,make_date(mxm.yr + 2026,mxm.cal,mxm.odom) + rlag request_date
,rd.sortmo request_month ,rd.sortmo request_month
,rd.ssyr request_season ,rd.ssyr request_season
,make_date(mxm.yr + 2025,mxm.cal,mxm.odom) + rlag + slag ship_date ,make_date(mxm.yr + 2026,mxm.cal,mxm.odom) + rlag + slag ship_date
,sd.sortmo ship_month ,sd.sortmo ship_month
,sd.ssyr ship_season ,sd.ssyr ship_season
,jr.mix ,jr.mix
@ -266,11 +266,11 @@ SELECT
JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true
CROSS JOIN mxm CROSS JOIN mxm
LEFT OUTER JOIN gld od ON LEFT OUTER JOIN gld od ON
od.drange @> make_date(mxm.yr + 2025,mxm.cal,mxm.odom) od.drange @> make_date(mxm.yr + 2026,mxm.cal,mxm.odom)
LEFT OUTER JOIN gld rd ON LEFT OUTER JOIN gld rd ON
rd.drange @> (make_date(mxm.yr + 2025,mxm.cal,mxm.odom) + rlag) rd.drange @> (make_date(mxm.yr + 2026,mxm.cal,mxm.odom) + rlag)
LEFT OUTER JOIN gld sd ON LEFT OUTER JOIN gld sd ON
sd.drange @> (make_date(mxm.yr + 2025,mxm.cal,mxm.odom) + rlag + slag) sd.drange @> (make_date(mxm.yr + 2026,mxm.cal,mxm.odom) + rlag + slag)
) )
-- SELECT 'basemix', * FROM basemix -- SELECT 'basemix', * FROM basemix
-- --

View File

@ -36,7 +36,7 @@ FROM
rlarp.osm_pool rlarp.osm_pool
WHERE WHERE
where_clause where_clause
AND order_season IN (2024,2025) AND order_season IN (2025,2026)
GROUP BY GROUP BY
order_season order_season
,order_month ,order_month
@ -102,14 +102,14 @@ GROUP BY
SELECT SELECT
order_month order_month
,seq ,seq
,SUM(units) FILTER (WHERE order_season = 2024) "2024 qty" ,SUM(units) FILTER (WHERE order_season = 2025) "2025 qty"
,SUM(units) FILTER (WHERE order_season = 2025 AND iter IN ('copy','short ship','bad_ship','plan')) "2025 base qty" ,SUM(units) FILTER (WHERE order_season = 2026 AND iter IN ('copy','short ship','bad_ship','plan')) "2026 base qty"
,SUM(units) FILTER (WHERE order_season = 2025 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2025 adj qty" ,SUM(units) FILTER (WHERE order_season = 2026 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2026 adj qty"
,SUM(units) FILTER (WHERE order_season = 2025) "2025 tot qty" ,SUM(units) FILTER (WHERE order_season = 2026) "2026 tot qty"
,SUM(value_usd) FILTER (WHERE order_season = 2024) "2024 value_usd" ,SUM(value_usd) FILTER (WHERE order_season = 2025) "2025 value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2025 AND iter IN ('copy','short ship','bad_ship','plan')) "2025 base value_usd" ,SUM(value_usd) FILTER (WHERE order_season = 2026 AND iter IN ('copy','short ship','bad_ship','plan')) "2026 base value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2025 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2025 adj value_usd" ,SUM(value_usd) FILTER (WHERE order_season = 2026 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2026 adj value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2025) "2025 tot value_usd" ,SUM(value_usd) FILTER (WHERE order_season = 2026) "2026 tot value_usd"
FROM FROM
months months
GROUP BY GROUP BY
@ -123,14 +123,14 @@ GROUP BY
,mlist AS ( ,mlist AS (
SELECT SELECT
mseq.m order_month mseq.m order_month
,"2024 qty" ,"2025 qty"
,"2025 base qty" ,"2026 base qty"
,"2025 adj qty" ,"2026 adj qty"
,"2025 tot qty" ,"2026 tot qty"
,"2024 value_usd" ,"2025 value_usd"
,"2025 base value_usd" ,"2026 base value_usd"
,"2025 adj value_usd" ,"2026 adj value_usd"
,"2025 tot value_usd" ,"2026 tot value_usd"
FROM FROM
mseq mseq
LEFT OUTER JOIN mpvt ON LEFT OUTER JOIN mpvt ON