Compare commits
18 Commits
e73d69ad65
...
8809cb9ad4
Author | SHA1 | Date | |
---|---|---|---|
|
8809cb9ad4 | ||
|
bd8aa18208 | ||
|
bfcf8ff4b4 | ||
|
ed5975daf7 | ||
|
59cb926d9c | ||
5dc5a11489 | |||
fd4079cb17 | |||
e5db7372a1 | |||
7d901e7f42 | |||
|
bc9aa4a456 | ||
|
3b72871cc6 | ||
|
8ba18476d8 | ||
|
5b507d3d65 | ||
68aa1c219a | |||
|
21e72a42cc | ||
|
70392a6829 | ||
|
d7d2447be2 | ||
|
e1359714cc |
Binary file not shown.
BIN
Master Template.xlsm
Normal file
BIN
Master Template.xlsm
Normal file
Binary file not shown.
@ -6,8 +6,8 @@ TRUNCATE TABLE rlarp.osmf_dev;
|
||||
DROP TABLE IF EXISTS tdr;
|
||||
CREATE TEMP TABLE tdr AS (
|
||||
SELECT
|
||||
DATERANGE('2020-06-01','2021-06-01','[)') drange
|
||||
,DATERANGE(('2020-06-01'::date + '1 year'::interval)::date,('2021-06-01'::date + '1 year'::interval)::date,'[)') repl
|
||||
DATERANGE('2022-06-01','2023-06-01','[)') drange
|
||||
,DATERANGE(('2022-06-01'::date + '1 year'::interval)::date,('2023-06-01'::date + '1 year'::interval)::date,'[)') repl
|
||||
,'1 year'::interval AS incr
|
||||
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter
|
||||
);
|
||||
|
@ -1,6 +1,8 @@
|
||||
-- Connection: usmidsap01.ubm
|
||||
--\timing
|
||||
truncate table rlarp.osmf_dev;
|
||||
TRUNCATE TABLE rlarp.osmf;
|
||||
|
||||
INSERT INTO rlarp.osmf
|
||||
WITH
|
||||
gld AS (
|
||||
SELECT
|
||||
@ -90,8 +92,9 @@ gld AS (
|
||||
,null::text coltier
|
||||
,null::text colstat
|
||||
,null::text sizc
|
||||
,null::text pckg
|
||||
,null::text kit
|
||||
,null::text uomp
|
||||
,null::text suffix
|
||||
,null::text accs_ps
|
||||
,null::text brnd
|
||||
,null::text majg
|
||||
,null::text ming
|
||||
@ -129,13 +132,15 @@ gld AS (
|
||||
,o.oseas
|
||||
,o.rdate
|
||||
,o.rseas
|
||||
,o.pdate
|
||||
,o.pseas
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||
,ss.ssyr sseas
|
||||
,'15mo' "version"
|
||||
,'actuals' iter
|
||||
FROM
|
||||
rlarp.osm_dev o
|
||||
rlarp.osm o
|
||||
--snap the ship dates of the historic fiscal period
|
||||
LEFT OUTER JOIN gld ON
|
||||
gld.fspr = o.fspr
|
||||
@ -145,11 +150,11 @@ gld AS (
|
||||
WHERE
|
||||
(
|
||||
--base period orders booked....
|
||||
o.odate BETWEEN '2020-06-01' AND '2021-04-11'
|
||||
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 < '2021-04-11')
|
||||
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01')
|
||||
--...or anything that shipped in that period
|
||||
OR o.fspr BETWEEN '2101' AND '2110'
|
||||
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'
|
||||
@ -176,6 +181,8 @@ gld AS (
|
||||
,o.oseas
|
||||
,o.rdate
|
||||
,o.rseas
|
||||
,o.pdate
|
||||
,o.pseas
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||
,ss.ssyr
|
||||
UNION ALL
|
||||
@ -243,8 +250,9 @@ gld AS (
|
||||
,null::text coltier
|
||||
,null::text colstat
|
||||
,null::text sizc
|
||||
,null::text pckg
|
||||
,null::text kit
|
||||
,null::text uomp
|
||||
,null::text suffix
|
||||
,null::text accs_ps
|
||||
,null::text brnd
|
||||
,null::text majg
|
||||
,null::text ming
|
||||
@ -282,19 +290,21 @@ gld AS (
|
||||
,o.oseas + 1 rseas
|
||||
,o.rdate + interval '1 year' rdate
|
||||
,o.rseas + 1 rseas
|
||||
,o.pdate + interval '1 year' pdate
|
||||
,o.pseas + 1 pseas
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
||||
,ss.ssyr sseas
|
||||
,'actuals' "version"
|
||||
,'actuals_plug' iter
|
||||
FROM
|
||||
rlarp.osm_dev o
|
||||
rlarp.osm o
|
||||
LEFT OUTER JOIN gld ON
|
||||
gld.fspr = o.fspr
|
||||
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 '2020-04-12' AND '2020-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
|
||||
@ -319,6 +329,8 @@ gld AS (
|
||||
,o.oseas
|
||||
,o.rdate
|
||||
,o.rseas
|
||||
,o.pdate
|
||||
,o.pseas
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||
,ss.ssyr
|
||||
UNION ALL
|
||||
@ -386,8 +398,9 @@ gld AS (
|
||||
,null::text coltier
|
||||
,null::text colstat
|
||||
,null::text sizc
|
||||
,null::text pckg
|
||||
,null::text kit
|
||||
,null::text uomp
|
||||
,null::text suffix
|
||||
,null::text accs_ps
|
||||
,null::text brnd
|
||||
,null::text majg
|
||||
,null::text ming
|
||||
@ -425,13 +438,15 @@ gld AS (
|
||||
,o.oseas rseas
|
||||
,o.rdate rdate
|
||||
,o.rseas rseas
|
||||
,o.pdate pdate
|
||||
,o.pseas pseas
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||
,ss.ssyr sseas
|
||||
,'actuals' "version"
|
||||
,'forecast_plug' iter
|
||||
FROM
|
||||
rlarp.osmp_dev o
|
||||
rlarp.osmp o
|
||||
LEFT OUTER JOIN gld ON
|
||||
gld.fspr = o.fspr
|
||||
LEFT OUTER JOIN gld ss ON
|
||||
@ -459,6 +474,8 @@ gld AS (
|
||||
,o.oseas
|
||||
,o.rdate
|
||||
,o.rseas
|
||||
,o.pdate
|
||||
,o.pseas
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||
,ss.ssyr
|
||||
)
|
||||
@ -524,8 +541,9 @@ SELECT
|
||||
,o.coltier
|
||||
,o.colstat
|
||||
,o.sizc
|
||||
,o.pckg
|
||||
,o.kit
|
||||
,o.uomp
|
||||
,o.suffix
|
||||
,o.accs_ps
|
||||
,o.brnd
|
||||
,o.majg
|
||||
,o.ming
|
||||
@ -563,21 +581,142 @@ SELECT
|
||||
,o.oseas + 1 --incremented
|
||||
,o.rdate + interval '1 year' --incremented
|
||||
,o.rseas + 1 --incremented
|
||||
,o.pdate + interval '1 year' --incremented
|
||||
,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_dev
|
||||
SELECT * FROM incr
|
||||
UNION ALL
|
||||
SELECT * FROM baseline;
|
||||
--INSERT INTO rlarp.osmf
|
||||
SELECT
|
||||
-----------documents-------------
|
||||
"ddord#"
|
||||
,"dditm#"
|
||||
,"fgbol#"
|
||||
,"fgent#"
|
||||
,"diinv#"
|
||||
,"dilin#"
|
||||
,quoten
|
||||
,quotel
|
||||
----------dates/status------------------
|
||||
,dcodat
|
||||
,ddqdat
|
||||
,dcmdat
|
||||
,fesdat
|
||||
,dhidat
|
||||
------------document flags-------------------
|
||||
,fesind
|
||||
,dhpost
|
||||
,fspr
|
||||
-----------measures--------------------
|
||||
,ddqtoi
|
||||
,ddqtsi
|
||||
,fgqshp
|
||||
,diqtsh
|
||||
,diext
|
||||
,ditdis
|
||||
,discj
|
||||
------------document attributes--------------
|
||||
,dhincr
|
||||
,plnt
|
||||
,promo
|
||||
,return_reas
|
||||
,terms
|
||||
,custpo
|
||||
,remit_to
|
||||
------------customer info---------------------
|
||||
,bill_class
|
||||
,bill_cust
|
||||
,bill_rep
|
||||
,bill_terr
|
||||
,ship_class
|
||||
,ship_cust
|
||||
,ship_rep
|
||||
,ship_terr
|
||||
,dsm
|
||||
,account
|
||||
,shipgrp
|
||||
,geo
|
||||
,chan
|
||||
,chansub
|
||||
,orig_ctry
|
||||
,orig_prov
|
||||
,orig_post
|
||||
,bill_ctry
|
||||
,bill_prov
|
||||
,bill_post
|
||||
,dest_ctry
|
||||
,dest_prov
|
||||
,dest_post
|
||||
------------product info----------------------
|
||||
,part
|
||||
,styc
|
||||
,colc
|
||||
,colgrp
|
||||
,coltier
|
||||
,colstat
|
||||
,sizc
|
||||
,uomp
|
||||
,suffix
|
||||
,accs_ps
|
||||
,brnd
|
||||
,majg
|
||||
,ming
|
||||
,majs
|
||||
,mins
|
||||
,gldco
|
||||
,gldc
|
||||
,glec
|
||||
,harm
|
||||
,clss
|
||||
,brand
|
||||
,assc
|
||||
,ddunit
|
||||
,unti
|
||||
,lbs
|
||||
,plt
|
||||
------------fiscal info-----------------------
|
||||
,plcd
|
||||
,fs_line
|
||||
,r_currency
|
||||
,r_rate
|
||||
,c_currency
|
||||
,c_rate
|
||||
,fb_qty
|
||||
,fb_val_loc
|
||||
,fb_val_loc_dis
|
||||
,fb_val_loc_qt
|
||||
,fb_val_loc_pl
|
||||
,fb_val_loc_tar
|
||||
,fb_cst_loc
|
||||
,fb_cst_loc_cur
|
||||
,fb_cst_loc_fut
|
||||
------------status info-----------------------
|
||||
,calc_status
|
||||
,flag
|
||||
,odate
|
||||
,oseas
|
||||
,rdate
|
||||
,rseas
|
||||
,pdate
|
||||
,pseas
|
||||
,sdate
|
||||
,sseas
|
||||
,"version"
|
||||
,iter
|
||||
FROM
|
||||
(
|
||||
SELECT * FROM baseline
|
||||
UNION ALL
|
||||
SELECT * FROM incr
|
||||
) 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
|
||||
|
@ -39,7 +39,7 @@ SELECT DISTINCT
|
||||
,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||
LEFT OUTER JOIN "CMS.CUSLG".itemmv i ON
|
||||
i.item = o.part
|
||||
LEFT OUTER JOIN seg ON
|
||||
seg.glec = i.glec
|
||||
|
@ -3,9 +3,9 @@ Description=forecast_api
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/node //opt/forecast_api/index.js
|
||||
ExecStart=/home/fc/.nvm/versions/node/v18.14.2/bin/node //opt/forecast_api/index.js
|
||||
Restart=always
|
||||
User=fc_api
|
||||
User=fc
|
||||
Environemnt=NODE_ENV=production
|
||||
WorkingDirectory=//opt/forecast_api/
|
||||
|
||||
|
8
index.js
8
index.js
@ -203,7 +203,7 @@ server.post('/swap', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------")
|
||||
console.log(new Date().toISOString() + "-------------------------post swap:------------------------------")
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
@ -246,7 +246,7 @@ server.post('/cust_swap', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------")
|
||||
console.log(new Date().toISOString() + "-------------------------cust swap:------------------------------")
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
@ -553,7 +553,7 @@ server.post('/scale_vp_sales', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "--------------------scale volume & price:-------------------");
|
||||
console.log(new Date().toISOString() + "--------------------scale volume & price sales:-------------------");
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
@ -696,7 +696,7 @@ function build_where(req, c, w, d, args) {
|
||||
if (req.body.stamp) {
|
||||
w = w +
|
||||
`
|
||||
AND order_date >= '` + req.body.stamp + "'::date";
|
||||
AND order_date >= least('` + req.body.stamp + "'::date,'2021-06-01')";
|
||||
}
|
||||
return { c, w, d };
|
||||
}
|
@ -154,7 +154,7 @@ incr AS (
|
||||
,row_number() OVER (PARTITION BY o.styc||'.'||o.colgrp||substring(o.sizc,1,3),o.account, o.shipgrp ORDER BY o.odate DESC) rn
|
||||
FROM
|
||||
rlarp.osm_dev o
|
||||
INNER JOIN rlarp.itemmv i ON
|
||||
INNER JOIN "CMS.CUSLG".itemm i ON
|
||||
i.item = o.part
|
||||
WHERE
|
||||
---exclude R&A's
|
||||
@ -226,7 +226,7 @@ SELECT
|
||||
,jsonb_agg(DISTINCT iter) iters
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
,rlarp.itemmv i
|
||||
,"CMS.CUSLG".itemm i
|
||||
WHERE
|
||||
i.item = o.part
|
||||
--AND o.units <> 0
|
||||
@ -415,7 +415,7 @@ GROUP BY
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
--need to join to itemm to get the product from osm_pool
|
||||
,rlarp.itemmv i
|
||||
,"CMS.CUSLG".itemm i
|
||||
WHERE
|
||||
i.item = o.part
|
||||
GROUP BY
|
||||
|
846
package-lock.json
generated
846
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -9,8 +9,8 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^6.2.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.17.1",
|
||||
"pg": "^7.18.1"
|
||||
"pg": "^8.9.0"
|
||||
}
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ SELECT
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN log
|
||||
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||
LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
|
||||
i.item = b.part
|
||||
LEFT OUTER JOIN SEG ON
|
||||
SEG.GLEC = i.glec
|
||||
|
@ -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
|
||||
|
@ -11,7 +11,7 @@ target AS (select 'replace_new_mold' new_mold)
|
||||
SUM(value_usd) value_usd
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||
LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
|
||||
i.item = o.part
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
@ -46,7 +46,7 @@ target AS (select 'replace_new_mold' new_mold)
|
||||
CASE WHEN substring(b.part,9,12) = substring(i.item,9,12) THEN '1' ELSE 0 END fit
|
||||
FROM
|
||||
basemix b
|
||||
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||
LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
|
||||
i.stlc = (SELECT new_mold FROM target WHERE new_mold <> '')
|
||||
AND CASE WHEN b.sizc = i.sizc THEN '1' ELSE '0' END||
|
||||
CASE WHEN i.aplnt = 'I' THEN '0' ELSE '1' END||
|
||||
|
@ -160,13 +160,13 @@ target AS (SELECT $$swap_doc$$::jsonb swap)
|
||||
remove o
|
||||
INNER JOIN pl ON
|
||||
pl.original = o.part
|
||||
INNER JOIN rlarp.itemmv m ON
|
||||
INNER JOIN "CMS.CUSLG".itemm m ON
|
||||
m.item = pl.replace
|
||||
LEFT OUTER JOIN rlarp.icstx c ON
|
||||
c.part = pl.replace
|
||||
AND c.plnt = m.dplt
|
||||
LEFT OUTER JOIN rlarp.plpr r ON
|
||||
yaplnt = m.dplt
|
||||
r.plnt = m.dplt
|
||||
LEFT OUTER JOIN rlarp.ffcret x ON
|
||||
x.fcur = r.curr
|
||||
AND x.tcur = 'US'
|
||||
|
Loading…
Reference in New Issue
Block a user