Merge branch 'dev' of github.com:The-HC-Companies/forecast_api into dev

This commit is contained in:
PhilRunninger 2023-03-01 18:00:18 -05:00
commit bd8aa18208
7 changed files with 110 additions and 109 deletions

View File

@ -150,11 +150,11 @@ gld AS (
WHERE WHERE
( (
--base period orders booked.... --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 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 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 fs_line = '41010'
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
@ -304,7 +304,7 @@ gld AS (
LEFT OUTER JOIN gld ss ON LEFT OUTER JOIN gld ss ON
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
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 fs_line = '41010'
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
------exclude actuals for now and use forecast to get the plug for the rest of the year ------exclude actuals for now and use forecast to get the plug for the rest of the year
@ -585,14 +585,14 @@ SELECT
,o.pseas + 1 --incremented ,o.pseas + 1 --incremented
,o.sdate + interval '1 year' --incremented ,o.sdate + interval '1 year' --incremented
,o.sseas + 1 --incremented ,o.sseas + 1 --incremented
,'b22' "version" ,'b23' "version"
,'copy' iter ,'copy' iter
FROM FROM
baseline o baseline o
LEFT OUTER JOIN gld ON LEFT OUTER JOIN gld ON
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
WHERE WHERE
o.odate + interval '1 year' >= '2021-06-01' o.odate + interval '1 year' >= '2023-06-01'
) )
--INSERT INTO rlarp.osmf --INSERT INTO rlarp.osmf
SELECT SELECT
@ -716,7 +716,7 @@ FROM
SELECT * FROM baseline SELECT * FROM baseline
UNION ALL UNION ALL
SELECT * FROM incr SELECT * FROM incr
) x ) x;
---identify short ships: causes disconnect with actual sales------------------------------------------------------------------- ---identify short ships: causes disconnect with actual sales-------------------------------------------------------------------
--UPDATE rlarp.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER'; --UPDATE rlarp.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER';

View File

@ -59,7 +59,7 @@ repc AS (
) )
--select * from si --select * from si
,logload AS ( ,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 --select * from logload
,loadset AS ( ,loadset AS (
@ -156,7 +156,7 @@ SELECT
,logload.doc->>'message' "comment" ,logload.doc->>'message' "comment"
,logload.doc->>'type' module ,logload.doc->>'type' module
FROM FROM
rlarp.osmf_dev o rlarp.osmf o
CROSS JOIN logload CROSS JOIN logload
LEFT OUTER JOIN lgdat.cust bc ON LEFT OUTER JOIN lgdat.cust bc ON
bc.bvcust = o.bill_cust bc.bvcust = o.bill_cust
@ -178,7 +178,7 @@ FROM
*/ */
LEFT OUTER JOIN seg ON LEFT OUTER JOIN seg ON
seg.glec = o.glec seg.glec = o.glec
LEFT OUTER JOIN rlarp.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

2
build/rebuild_script.sh Normal file → Executable file
View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
#$PG -f ./build_stage.sql; #$PG -f ./build_stage.sql;
$PG -f ./build_rolling.sql; #$PG -f ./build_rolling.sql;
$PG -f ./snap_itemm.sql; $PG -f ./snap_itemm.sql;
$PG -f ./snap_cost_current.sql; $PG -f ./snap_cost_current.sql;
$PG -f ./snap_customer.sql; $PG -f ./snap_customer.sql;

View File

@ -6,7 +6,7 @@ plist AS (
part part
,plnt ,plnt
FROM FROM
rlarp.osmf_dev rlarp.osmf
-----prevent a list of fake parts -----prevent a list of fake parts
INNER JOIN lgdat.stka ON INNER JOIN lgdat.stka ON
v6part = part v6part = part
@ -30,7 +30,7 @@ plist AS (
AND ir.y0plnt = p.plnt AND ir.y0plnt = p.plnt
) )
UPDATE UPDATE
rlarp.osmf_dev o rlarp.osmf o
SET SET
fb_cst_loc_cur = c.stdcost * o.fb_qty fb_cst_loc_cur = c.stdcost * o.fb_qty
FROM FROM
@ -40,4 +40,4 @@ WHERE
AND c.plnt = o.plnt; AND c.plnt = o.plnt;
--AND version = 'b21'; --AND version = 'b21';
commit; commit;

View File

@ -1,64 +1,64 @@
----------------------------SET BILL-TO REP------------------------------------ ----------------------------SET BILL-TO REP------------------------------------
UPDATE UPDATE
RLARP.OSMF_DEV S rlarp.osmf s
SET SET
BILL_REP = C.BVSALM bill_rep = c.bvsalm
,BILL_CLASS = C.BVCLAS ,bill_class = c.bvclas
,BILL_TERR = C.BVTERR ,bill_terr = c.bvterr
,BILL_CTRY = C.bvctry ,bill_ctry = c.bvctry
,bill_prov = C.bvprcd ,bill_prov = c.bvprcd
,bill_post = C.bvpost ,bill_post = c.bvpost
,remit_to = c.bvcomp ,remit_to = c.bvcomp
,ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END ,account = CASE bvadr6 WHEN '' THEN bvname ELSE bvadr6 END
FROM FROM
LGDAT.CUST C lgdat.cust c
WHERE WHERE
C.BVCUST = S.BILL_CUST c.bvcust = s.bill_cust
AND ( AND (
COALESCE(S.BILL_REP,'') <> C.BVSALM COALESCE(s.bill_rep,'') <> c.bvsalm
OR COALESCE(S.BILL_CLASS,'') <> C.BVCLAS OR COALESCE(s.bill_class,'') <> c.bvclas
OR COALESCE(S.BILL_TERR,'') <> C.BVTERR OR COALESCE(s.bill_terr,'') <> c.bvterr
OR COALESCE(BILL_CTRY,'') <> C.bvctry OR COALESCE(bill_ctry,'') <> c.bvctry
OR COALESCE(bill_prov,'') <> C.bvprcd OR COALESCE(bill_prov,'') <> c.bvprcd
OR COALESCE(bill_post,'') <> C.bvpost OR COALESCE(bill_post,'') <> c.bvpost
OR COALESCE(remit_to,'') <> c.bvcomp::text OR COALESCE(remit_to,'') <> c.bvcomp::text
); );
----------------------------SET SHIP-TO REP------------------------------------ ----------------------------SET SHIP-TO REP------------------------------------
UPDATE UPDATE
RLARP.OSMF_DEV S rlarp.osmf s
SET SET
SHIP_REP = C.BVSALM ship_rep = c.bvsalm
,SHIP_CLASS = C.BVCLAS ,ship_class = c.bvclas
,SHIP_TERR = C.BVTERR ,ship_terr = c.bvterr
,dest_CTRY = C.bvctry ,dest_ctry = c.bvctry
,dest_prov = C.bvprcd ,dest_prov = c.bvprcd
,dest_post = C.bvpost ,dest_post = c.bvpost
FROM FROM
LGDAT.CUST C lgdat.cust c
WHERE WHERE
C.BVCUST = S.SHIP_CUST c.bvcust = s.ship_cust
AND ( AND (
COALESCE(S.SHIP_REP,'') <> C.BVSALM COALESCE(s.ship_rep,'') <> c.bvsalm
OR COALESCE(S.SHIP_CLASS,'') <> C.BVCLAS OR COALESCE(s.ship_class,'') <> c.bvclas
OR COALESCE(S.SHIP_TERR,'') <> C.BVTERR OR COALESCE(s.ship_terr,'') <> c.bvterr
OR COALESCE(dest_CTRY,'') <> C.bvctry OR COALESCE(dest_ctry,'') <> c.bvctry
OR COALESCE(dest_prov,'') <> C.bvprcd OR COALESCE(dest_prov,'') <> c.bvprcd
OR COALESCE(dest_post,'') <> C.bvpost OR COALESCE(dest_post,'') <> c.bvpost
); );
----------------------------SET BILLTO GROUP------------------------------------ ----------------------------SET BILLTO GROUP------------------------------------
UPDATE UPDATE
RLARP.OSMF_DEV O rlarp.osmf o
SET SET
ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM FROM
LGDAT.CUST C lgdat.cust c
WHERE WHERE
C.BVCUST = O.BILL_CUST c.bvcust = o.bill_cust
AND coalesce(account,'') <> CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END; AND coalesce(account,'') <> CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END;
@ -66,13 +66,13 @@ WHERE
----------------------------SET SHIPTO GROUP------------------------------------ ----------------------------SET SHIPTO GROUP------------------------------------
UPDATE UPDATE
RLARP.OSMF_DEV O rlarp.osmf o
SET SET
SHIPGRP = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END SHIPGRP = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM FROM
LGDAT.CUST C lgdat.cust c
WHERE WHERE
C.BVCUST = O.SHIP_CUST c.bvcust = o.ship_cust
AND CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END <> COALESCE(O.SHIPGRP,''); AND CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END <> COALESCE(O.SHIPGRP,'');
@ -80,7 +80,7 @@ WHERE
UPDATE UPDATE
rlarp.osmF_dev rlarp.osmf
SET SET
CHAN = CASE SUBSTRING(BILL_CLASS,2,3) CHAN = CASE SUBSTRING(BILL_CLASS,2,3)
--if the bill to class is ditsributor, then it's either warehouse or drop --if the bill to class is ditsributor, then it's either warehouse or drop
@ -136,17 +136,17 @@ WHERE
UPDATE UPDATE
RLARP.OSMF_DEV S rlarp.osmf s
SET SET
DSM = CR.QUOTA_REP dsm = cr.quota_rep
FROM FROM
( (
SELECT DISTINCT SELECT DISTINCT
VERSION, version,
COALESCE(GLEC,'') GLEC, COALESCE(glec,'') glec,
MING, ming,
BILL_CUST, bill_cust,
SHIP_CUST, ship_cust,
------------quota rep column-------------- ------------quota rep column--------------
CASE WHEN COALESCE(ming,'') = 'B52' THEN 'PW' ELSE 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 --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
END QUOTA_REP END QUOTA_REP
FROM FROM
RLARP.OSMF_DEV S rlarp.osmf s
LEFT OUTER JOIN LGDAT.CUST ON LEFT OUTER JOIN lgdat.cust ON
BVCUST = BILL_CUST bvcust = bill_cust
LEFT OUTER JOIN lgpgm.usrcust cu ON LEFT OUTER JOIN lgpgm.usrcust cu ON
cu.cucust = s.bill_cust cu.cucust = s.bill_cust
WHERE WHERE
version = 'ACTUALS' version = 'ACTUALS'
) CR ) CR
WHERE WHERE
CR.VERSION = S.VERSION cr.version = s.version
AND CR.GLEC = COALESCE(S.GLEC,'') AND cr.glec = COALESCE(s.glec,'')
AND CR.MING = S.MING AND cr.ming = s.ming
AND CR.BILL_CUST = S.BILL_CUST AND cr.bill_cust = s.bill_cust
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;

View File

@ -1,28 +1,29 @@
UPDATE UPDATE
RLARP.OSMF_DEV O rlarp.osmf o
SET SET
STYC = M.STLC stlc = m.stlc
,COLC = M.COLC ,colc = m.colc
,COLGRP = M.COLGRP ,colgrp = m.colgrp
,COLTIER = M.COLTIER ,coltier = m.coltier
,COLSTAT = M.COLSTAT ,colstat = m.colstat
,SIZC = M.SIZC ,sizc = m.sizc
,PCKG = M.PACKAGE ,uomp = m.uomp
,KIT = M.KIT ,suffix = m.suffix
,BRND = M.BRANDING ,accs_ps = m.accs_ps
,MAJG = M.MAJG ,brnd = m.branding
,MING = M.MING ,majg = m.majg
,MAJS = M.MAJS ,ming = m.ming
,MINS = M.MINS ,majs = m.majs
,GLDC = M.GLCD ,mins = m.mins
,GLEC = M.GLEC ,gldc = m.glcd
,HARM = M.HARM ,glec = m.glec
,CLSS = M.CLSS ,harm = m.harm
,BRAND = M.BRAND ,clss = m.clss
,ASSC = M.ASSC ,brand = m.brand
,LBS = CASE M.NWUN WHEN 'KG' THEN 2.2046 ELSE 1 END*M.NWHT ,assc = m.assc
,UNTI = M.UNTI ,lbs = CASE m.nwun WHEN 'KG' THEN 2.2046 ELSE 1 END*m.nwht
,unti = m.unti
FROM FROM
RLARP.ITEMM M "CMS.CUSLG".itemm m
WHERE WHERE
M.ITEM = O.PART m.item = o.part

View File

@ -36,7 +36,7 @@ FROM
rlarp.osm_pool rlarp.osm_pool
WHERE WHERE
where_clause where_clause
AND order_season IN (2022,2023) AND order_season IN (2023,2024)
GROUP BY GROUP BY
order_season order_season
,order_month ,order_month
@ -94,14 +94,14 @@ GROUP BY
SELECT SELECT
order_month order_month
,seq ,seq
,SUM(units) FILTER (WHERE order_season = 2022) "2022 qty" ,SUM(units) FILTER (WHERE order_season = 2023) "2023 qty"
,SUM(units) FILTER (WHERE order_season = 2023 AND iter IN ('copy','short ship','bad_ship','plan')) "2023 base 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 = 2023 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2023 adj 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 = 2023) "2023 tot qty" ,SUM(units) FILTER (WHERE order_season = 2024) "2024 tot qty"
,SUM(value_usd) FILTER (WHERE order_season = 2022) "2022 value_usd" ,SUM(value_usd) FILTER (WHERE order_season = 2023) "2023 value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2023 AND iter IN ('copy','short ship','bad_ship','plan')) "2023 base 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 = 2023 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2023 adj 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 = 2023) "2023 tot value_usd" ,SUM(value_usd) FILTER (WHERE order_season = 2024) "2024 tot value_usd"
FROM FROM
months months
GROUP BY GROUP BY
@ -113,14 +113,14 @@ GROUP BY
,mlist AS ( ,mlist AS (
SELECT SELECT
mseq.m order_month mseq.m order_month
,"2022 qty" ,"2023 qty"
,"2023 base qty" ,"2024 base qty"
,"2023 adj qty" ,"2024 adj qty"
,"2023 tot qty" ,"2024 tot qty"
,"2022 value_usd" ,"2023 value_usd"
,"2023 base value_usd" ,"2024 base value_usd"
,"2023 adj value_usd" ,"2024 adj value_usd"
,"2023 tot value_usd" ,"2024 tot value_usd"
FROM FROM
mseq mseq
LEFT OUTER JOIN mpvt ON LEFT OUTER JOIN mpvt ON