Merge branch 'dev' of github.com:The-HC-Companies/forecast_api into dev
This commit is contained in:
commit
bd8aa18208
@ -150,11 +150,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'
|
||||
@ -304,7 +304,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
|
||||
@ -585,14 +585,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
|
||||
@ -716,7 +716,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';
|
||||
|
@ -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
|
||||
|
2
build/rebuild_script.sh
Normal file → Executable file
2
build/rebuild_script.sh
Normal file → Executable file
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -36,7 +36,7 @@ FROM
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
where_clause
|
||||
AND order_season IN (2022,2023)
|
||||
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 = 2022) "2022 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 = 2023 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2023 adj qty"
|
||||
,SUM(units) FILTER (WHERE order_season = 2023) "2023 tot qty"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2022) "2022 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 = 2023 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2023 adj value_usd"
|
||||
,SUM(value_usd) FILTER (WHERE order_season = 2023) "2023 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
|
||||
,"2022 qty"
|
||||
,"2023 base qty"
|
||||
,"2023 adj qty"
|
||||
,"2023 tot qty"
|
||||
,"2022 value_usd"
|
||||
,"2023 base value_usd"
|
||||
,"2023 adj value_usd"
|
||||
,"2023 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
|
||||
|
Loading…
Reference in New Issue
Block a user