From 7d901e7f42c1f4aa6b106008d462e5da9993f7ab Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 1 Mar 2023 16:01:32 -0500 Subject: [PATCH 1/4] new forecast baseline dates --- build/build_forecast.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build/build_forecast.sql b/build/build_forecast.sql index e592eef..49ae916 100644 --- a/build/build_forecast.sql +++ b/build/build_forecast.sql @@ -149,11 +149,11 @@ gld AS ( WHERE ( --base period orders booked.... - o.odate BETWEEN '2022-06-01' AND '2023-02-15' + o.odate BETWEEN '2022-06-01' AND '2023-03-01' --...or any open orders currently booked before cutoff.... - OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-02-15') + OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01') --...or anything that shipped in that period - OR ((o.fspr BETWEEN '2301' AND '2309' OR o.fspr = '0000') AND o.sdate < '2023-02-15') + OR ((o.fspr BETWEEN '2301' AND '2309' OR o.fspr = '0000') AND o.sdate < '2023-03-01') ) AND fs_line = '41010' AND calc_status <> 'CANCELED' @@ -303,7 +303,7 @@ gld AS ( LEFT OUTER JOIN gld ss ON greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat WHERE - o.odate BETWEEN '2022-02-15' AND '2022-05-31' + o.odate BETWEEN '2022-03-01' AND '2022-05-31' AND fs_line = '41010' AND calc_status <> 'CANCELED' ------exclude actuals for now and use forecast to get the plug for the rest of the year @@ -584,14 +584,14 @@ SELECT ,o.pseas + 1 --incremented ,o.sdate + interval '1 year' --incremented ,o.sseas + 1 --incremented - ,'b22' "version" + ,'b23' "version" ,'copy' iter FROM baseline o LEFT OUTER JOIN gld ON o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat WHERE - o.odate + interval '1 year' >= '2021-06-01' + o.odate + interval '1 year' >= '2023-06-01' ) --INSERT INTO rlarp.osmf SELECT @@ -715,7 +715,7 @@ FROM SELECT * FROM baseline UNION ALL SELECT * FROM incr - ) x + ) x; ---identify short ships: causes disconnect with actual sales------------------------------------------------------------------- --UPDATE rlarp.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER'; From e5db7372a11efda6f2207d28e05b2627389aeb3f Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 1 Mar 2023 16:07:36 -0500 Subject: [PATCH 2/4] repoint snaps --- build/rebuild_script.sh | 2 +- build/snap_cost_current.sql | 6 +- build/snap_customer.sql | 108 ++++++++++++++++++------------------ build/snap_itemm.sql | 49 ++++++++-------- 4 files changed, 83 insertions(+), 82 deletions(-) mode change 100644 => 100755 build/rebuild_script.sh diff --git a/build/rebuild_script.sh b/build/rebuild_script.sh old mode 100644 new mode 100755 index 7b85682..d5bec49 --- a/build/rebuild_script.sh +++ b/build/rebuild_script.sh @@ -1,6 +1,6 @@ #!/bin/bash #$PG -f ./build_stage.sql; -$PG -f ./build_rolling.sql; +#$PG -f ./build_rolling.sql; $PG -f ./snap_itemm.sql; $PG -f ./snap_cost_current.sql; $PG -f ./snap_customer.sql; diff --git a/build/snap_cost_current.sql b/build/snap_cost_current.sql index de94437..0f052ba 100644 --- a/build/snap_cost_current.sql +++ b/build/snap_cost_current.sql @@ -6,7 +6,7 @@ plist AS ( part ,plnt FROM - rlarp.osmf_dev + rlarp.osmf -----prevent a list of fake parts INNER JOIN lgdat.stka ON v6part = part @@ -30,7 +30,7 @@ plist AS ( AND ir.y0plnt = p.plnt ) UPDATE - rlarp.osmf_dev o + rlarp.osmf o SET fb_cst_loc_cur = c.stdcost * o.fb_qty FROM @@ -40,4 +40,4 @@ WHERE AND c.plnt = o.plnt; --AND version = 'b21'; -commit; \ No newline at end of file +commit; diff --git a/build/snap_customer.sql b/build/snap_customer.sql index 55c1eaf..4c24786 100644 --- a/build/snap_customer.sql +++ b/build/snap_customer.sql @@ -1,64 +1,64 @@ ----------------------------SET BILL-TO REP------------------------------------ UPDATE - RLARP.OSMF_DEV S + rlarp.osmf s SET - BILL_REP = C.BVSALM - ,BILL_CLASS = C.BVCLAS - ,BILL_TERR = C.BVTERR - ,BILL_CTRY = C.bvctry - ,bill_prov = C.bvprcd - ,bill_post = C.bvpost + bill_rep = c.bvsalm + ,bill_class = c.bvclas + ,bill_terr = c.bvterr + ,bill_ctry = c.bvctry + ,bill_prov = c.bvprcd + ,bill_post = c.bvpost ,remit_to = c.bvcomp - ,ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END + ,account = CASE bvadr6 WHEN '' THEN bvname ELSE bvadr6 END FROM - LGDAT.CUST C + lgdat.cust c WHERE - C.BVCUST = S.BILL_CUST + c.bvcust = s.bill_cust AND ( - COALESCE(S.BILL_REP,'') <> C.BVSALM - OR COALESCE(S.BILL_CLASS,'') <> C.BVCLAS - OR COALESCE(S.BILL_TERR,'') <> C.BVTERR - OR COALESCE(BILL_CTRY,'') <> C.bvctry - OR COALESCE(bill_prov,'') <> C.bvprcd - OR COALESCE(bill_post,'') <> C.bvpost + COALESCE(s.bill_rep,'') <> c.bvsalm + OR COALESCE(s.bill_class,'') <> c.bvclas + OR COALESCE(s.bill_terr,'') <> c.bvterr + OR COALESCE(bill_ctry,'') <> c.bvctry + OR COALESCE(bill_prov,'') <> c.bvprcd + OR COALESCE(bill_post,'') <> c.bvpost OR COALESCE(remit_to,'') <> c.bvcomp::text ); ----------------------------SET SHIP-TO REP------------------------------------ UPDATE - RLARP.OSMF_DEV S + rlarp.osmf s SET - SHIP_REP = C.BVSALM - ,SHIP_CLASS = C.BVCLAS - ,SHIP_TERR = C.BVTERR - ,dest_CTRY = C.bvctry - ,dest_prov = C.bvprcd - ,dest_post = C.bvpost + ship_rep = c.bvsalm + ,ship_class = c.bvclas + ,ship_terr = c.bvterr + ,dest_ctry = c.bvctry + ,dest_prov = c.bvprcd + ,dest_post = c.bvpost FROM - LGDAT.CUST C + lgdat.cust c WHERE - C.BVCUST = S.SHIP_CUST + c.bvcust = s.ship_cust AND ( - COALESCE(S.SHIP_REP,'') <> C.BVSALM - OR COALESCE(S.SHIP_CLASS,'') <> C.BVCLAS - OR COALESCE(S.SHIP_TERR,'') <> C.BVTERR - OR COALESCE(dest_CTRY,'') <> C.bvctry - OR COALESCE(dest_prov,'') <> C.bvprcd - OR COALESCE(dest_post,'') <> C.bvpost + COALESCE(s.ship_rep,'') <> c.bvsalm + OR COALESCE(s.ship_class,'') <> c.bvclas + OR COALESCE(s.ship_terr,'') <> c.bvterr + OR COALESCE(dest_ctry,'') <> c.bvctry + OR COALESCE(dest_prov,'') <> c.bvprcd + OR COALESCE(dest_post,'') <> c.bvpost ); ----------------------------SET BILLTO GROUP------------------------------------ UPDATE - RLARP.OSMF_DEV O + rlarp.osmf o SET ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END FROM - LGDAT.CUST C + lgdat.cust c WHERE - C.BVCUST = O.BILL_CUST + c.bvcust = o.bill_cust AND coalesce(account,'') <> CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END; @@ -66,13 +66,13 @@ WHERE ----------------------------SET SHIPTO GROUP------------------------------------ UPDATE - RLARP.OSMF_DEV O + rlarp.osmf o SET SHIPGRP = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END FROM - LGDAT.CUST C + lgdat.cust c WHERE - C.BVCUST = O.SHIP_CUST + c.bvcust = o.ship_cust AND CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END <> COALESCE(O.SHIPGRP,''); @@ -80,7 +80,7 @@ WHERE UPDATE - rlarp.osmF_dev + rlarp.osmf SET CHAN = CASE SUBSTRING(BILL_CLASS,2,3) --if the bill to class is ditsributor, then it's either warehouse or drop @@ -136,17 +136,17 @@ WHERE UPDATE - RLARP.OSMF_DEV S + rlarp.osmf s SET - DSM = CR.QUOTA_REP + dsm = cr.quota_rep FROM ( SELECT DISTINCT - VERSION, - COALESCE(GLEC,'') GLEC, - MING, - BILL_CUST, - SHIP_CUST, + version, + COALESCE(glec,'') glec, + ming, + bill_cust, + ship_cust, ------------quota rep column-------------- CASE WHEN COALESCE(ming,'') = 'B52' THEN 'PW' ELSE --if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available @@ -163,18 +163,18 @@ FROM END END QUOTA_REP FROM - RLARP.OSMF_DEV S - LEFT OUTER JOIN LGDAT.CUST ON - BVCUST = BILL_CUST + rlarp.osmf s + LEFT OUTER JOIN lgdat.cust ON + bvcust = bill_cust LEFT OUTER JOIN lgpgm.usrcust cu ON cu.cucust = s.bill_cust WHERE version = 'ACTUALS' ) CR WHERE - CR.VERSION = S.VERSION - AND CR.GLEC = COALESCE(S.GLEC,'') - AND CR.MING = S.MING - AND CR.BILL_CUST = S.BILL_CUST - AND CR.SHIP_CUST = S.SHIP_CUST - AND COALESCE(S.DSM,'') <> CR.QUOTA_REP; + cr.version = s.version + AND cr.glec = COALESCE(s.glec,'') + AND cr.ming = s.ming + AND cr.bill_cust = s.bill_cust + AND cr.ship_cust = s.ship_cust + AND COALESCE(s.dsm,'') <> cr.quota_rep; diff --git a/build/snap_itemm.sql b/build/snap_itemm.sql index 4a18be1..43bca4d 100644 --- a/build/snap_itemm.sql +++ b/build/snap_itemm.sql @@ -1,28 +1,29 @@ UPDATE - RLARP.OSMF_DEV O + rlarp.osmf o SET - STYC = M.STLC - ,COLC = M.COLC - ,COLGRP = M.COLGRP - ,COLTIER = M.COLTIER - ,COLSTAT = M.COLSTAT - ,SIZC = M.SIZC - ,PCKG = M.PACKAGE - ,KIT = M.KIT - ,BRND = M.BRANDING - ,MAJG = M.MAJG - ,MING = M.MING - ,MAJS = M.MAJS - ,MINS = M.MINS - ,GLDC = M.GLCD - ,GLEC = M.GLEC - ,HARM = M.HARM - ,CLSS = M.CLSS - ,BRAND = M.BRAND - ,ASSC = M.ASSC - ,LBS = CASE M.NWUN WHEN 'KG' THEN 2.2046 ELSE 1 END*M.NWHT - ,UNTI = M.UNTI + stlc = m.stlc + ,colc = m.colc + ,colgrp = m.colgrp + ,coltier = m.coltier + ,colstat = m.colstat + ,sizc = m.sizc + ,uomp = m.uomp + ,suffix = m.suffix + ,accs_ps = m.accs_ps + ,brnd = m.branding + ,majg = m.majg + ,ming = m.ming + ,majs = m.majs + ,mins = m.mins + ,gldc = m.glcd + ,glec = m.glec + ,harm = m.harm + ,clss = m.clss + ,brand = m.brand + ,assc = m.assc + ,lbs = CASE m.nwun WHEN 'KG' THEN 2.2046 ELSE 1 END*m.nwht + ,unti = m.unti FROM - RLARP.ITEMM M + "CMS.CUSLG".itemm m WHERE - M.ITEM = O.PART + m.item = o.part From fd4079cb177561318270fd9461b87c4ec49989c3 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 1 Mar 2023 16:32:52 -0500 Subject: [PATCH 3/4] clean up --- build/build_pool.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/build_pool.sql b/build/build_pool.sql index 8214724..c1ffc0c 100644 --- a/build/build_pool.sql +++ b/build/build_pool.sql @@ -59,7 +59,7 @@ repc AS ( ) --select * from si ,logload AS ( - INSERT INTO rlarp.osm_log (doc) SELECT jsonb_build_object('user',current_user,'tag','1+11','type','build_pool','stamp',current_timestamp,'source','top level','message','don''t undo') RETURNING * + INSERT INTO rlarp.osm_log (doc) SELECT jsonb_build_object('user',current_user,'tag','baseline','type','build_pool','stamp',current_timestamp,'source','top level','message','don''t undo') RETURNING * ) --select * from logload ,loadset AS ( @@ -156,7 +156,7 @@ SELECT ,logload.doc->>'message' "comment" ,logload.doc->>'type' module FROM - rlarp.osmf_dev o + rlarp.osmf o CROSS JOIN logload LEFT OUTER JOIN lgdat.cust bc ON bc.bvcust = o.bill_cust @@ -178,7 +178,7 @@ FROM */ LEFT OUTER JOIN seg ON seg.glec = o.glec - LEFT OUTER JOIN rlarp.itemm i ON + LEFT OUTER JOIN "CMS.CUSLG".itemm i ON i.item = o.part ) SELECT * FROM loadset From 5dc5a114890792d1ce526d310bbf7aa27589be4f Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 1 Mar 2023 17:07:44 -0500 Subject: [PATCH 4/4] increment year --- route_sql/scenario_package.sql | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/route_sql/scenario_package.sql b/route_sql/scenario_package.sql index b05aad4..3a04bbf 100644 --- a/route_sql/scenario_package.sql +++ b/route_sql/scenario_package.sql @@ -36,7 +36,7 @@ FROM rlarp.osm_pool WHERE where_clause - AND order_season IN (2021,2022) + AND order_season IN (2023,2024) GROUP BY order_season ,order_month @@ -94,14 +94,14 @@ GROUP BY SELECT order_month ,seq - ,SUM(units) FILTER (WHERE order_season = 2021) "2021 qty" - ,SUM(units) FILTER (WHERE order_season = 2022 AND iter IN ('copy','short ship','bad_ship','plan')) "2022 base qty" - ,SUM(units) FILTER (WHERE order_season = 2022 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2022 adj qty" - ,SUM(units) FILTER (WHERE order_season = 2022) "2022 tot qty" - ,SUM(value_usd) FILTER (WHERE order_season = 2021) "2021 value_usd" - ,SUM(value_usd) FILTER (WHERE order_season = 2022 AND iter IN ('copy','short ship','bad_ship','plan')) "2022 base value_usd" - ,SUM(value_usd) FILTER (WHERE order_season = 2022 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2022 adj value_usd" - ,SUM(value_usd) FILTER (WHERE order_season = 2022) "2022 tot value_usd" + ,SUM(units) FILTER (WHERE order_season = 2023) "2023 qty" + ,SUM(units) FILTER (WHERE order_season = 2024 AND iter IN ('copy','short ship','bad_ship','plan')) "2024 base qty" + ,SUM(units) FILTER (WHERE order_season = 2024 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2024 adj qty" + ,SUM(units) FILTER (WHERE order_season = 2024) "2024 tot qty" + ,SUM(value_usd) FILTER (WHERE order_season = 2023) "2023 value_usd" + ,SUM(value_usd) FILTER (WHERE order_season = 2024 AND iter IN ('copy','short ship','bad_ship','plan')) "2024 base value_usd" + ,SUM(value_usd) FILTER (WHERE order_season = 2024 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2024 adj value_usd" + ,SUM(value_usd) FILTER (WHERE order_season = 2024) "2024 tot value_usd" FROM months GROUP BY @@ -113,14 +113,14 @@ GROUP BY ,mlist AS ( SELECT mseq.m order_month - ,"2021 qty" - ,"2022 base qty" - ,"2022 adj qty" - ,"2022 tot qty" - ,"2021 value_usd" - ,"2022 base value_usd" - ,"2022 adj value_usd" - ,"2022 tot value_usd" + ,"2023 qty" + ,"2024 base qty" + ,"2024 adj qty" + ,"2024 tot qty" + ,"2023 value_usd" + ,"2024 base value_usd" + ,"2024 adj value_usd" + ,"2024 tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON