updates
This commit is contained in:
parent
d7d2447be2
commit
68aa1c219a
@ -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,7 @@
|
||||
--\timing
|
||||
truncate table rlarp.osmf_dev;
|
||||
TRUNCATE TABLE rlarp.osmf;
|
||||
|
||||
INSERT INTO rlarp.osmf
|
||||
WITH
|
||||
gld AS (
|
||||
SELECT
|
||||
@ -90,8 +91,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 +131,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 +149,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-02-15'
|
||||
--...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-02-15')
|
||||
--...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-02-15')
|
||||
)
|
||||
AND fs_line = '41010'
|
||||
AND calc_status <> 'CANCELED'
|
||||
@ -176,6 +180,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 +249,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 +289,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-02-15' 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 +328,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 +397,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 +437,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 +473,8 @@ gld AS (
|
||||
,o.oseas
|
||||
,o.rdate
|
||||
,o.rseas
|
||||
,o.pdate
|
||||
,o.pseas
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||
,ss.ssyr
|
||||
)
|
||||
@ -524,9 +540,10 @@ SELECT
|
||||
,o.coltier
|
||||
,o.colstat
|
||||
,o.sizc
|
||||
,o.pckg
|
||||
,o.kit
|
||||
,o.brnd
|
||||
,o.uomp
|
||||
,o.suffix
|
||||
,o.accs_ps
|
||||
,o.brnd
|
||||
,o.majg
|
||||
,o.ming
|
||||
,o.majs
|
||||
@ -563,6 +580,8 @@ 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"
|
||||
@ -574,10 +593,129 @@ FROM
|
||||
WHERE
|
||||
o.odate + interval '1 year' >= '2021-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';
|
||||
|
@ -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/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user