2023-03-01 17:55:30 -05:00
|
|
|
-- Connection: usmidsap01.ubm
|
2020-02-19 17:05:27 -05:00
|
|
|
--\timing
|
2023-02-24 19:28:14 -05:00
|
|
|
TRUNCATE TABLE rlarp.osmf;
|
2020-02-19 17:05:27 -05:00
|
|
|
|
2023-02-24 19:28:14 -05:00
|
|
|
INSERT INTO rlarp.osmf
|
2020-02-19 17:05:27 -05:00
|
|
|
WITH
|
|
|
|
gld AS (
|
2023-03-01 17:55:30 -05:00
|
|
|
SELECT
|
2020-02-19 17:05:27 -05:00
|
|
|
N1COMP COMP
|
|
|
|
,N1CCYY FSYR
|
|
|
|
,KPMAXP PERDS
|
|
|
|
,N1FSPP PERD
|
|
|
|
,to_char(N1FSYP,'FM0000') FSPR
|
|
|
|
,N1SD01 SDAT
|
|
|
|
,N1ED01 EDAT
|
|
|
|
,to_char(N1ED01,'yymm') CAPR
|
2023-03-01 17:55:30 -05:00
|
|
|
,N1ED01 - N1SD01 +1 NDAYS
|
2020-02-19 17:05:27 -05:00
|
|
|
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
|
|
|
|
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
|
2023-03-01 17:55:30 -05:00
|
|
|
FROM
|
|
|
|
LGDAT.GLDATREF
|
|
|
|
INNER JOIN LGDAT.GLDATE ON
|
|
|
|
KPCOMP = N1COMP AND
|
2020-02-19 17:05:27 -05:00
|
|
|
KPCCYY = N1CCYY
|
|
|
|
WHERE
|
|
|
|
N1COMP = 93
|
|
|
|
--AND DIGITS(N1FSYP) = '1901'
|
|
|
|
)
|
|
|
|
--SELECT * FROM gld
|
|
|
|
,baseline AS (
|
|
|
|
SELECT
|
|
|
|
-----------documents-------------
|
|
|
|
null::int "ddord#"
|
|
|
|
,null::int "dditm#"
|
|
|
|
,null::int "fgbol#"
|
|
|
|
,null::int "fgent#"
|
|
|
|
,null::int "diinv#"
|
|
|
|
,null::int "dilin#"
|
|
|
|
,null::int quoten
|
|
|
|
,null::int quotel
|
|
|
|
----------dates/status------------------
|
|
|
|
,o.odate dcodat
|
|
|
|
,o.rdate ddqdat
|
|
|
|
,null::date dcmdat
|
|
|
|
,null::date fesdat
|
|
|
|
,greatest(least(o.sdate,gld.edat),gld.sdat) dhidat
|
|
|
|
,null::text fesind
|
|
|
|
,null::text dhpost
|
|
|
|
,o.fspr
|
|
|
|
-----------measures--------------------
|
|
|
|
,null::numeric ddqtoi
|
|
|
|
,null::numeric ddqtsi
|
|
|
|
,null::numeric fgqshp
|
|
|
|
,null::numeric diqtsh
|
|
|
|
,null::numeric diext
|
|
|
|
,null::numeric ditdis
|
|
|
|
,null::jsonb discj
|
|
|
|
,null::text dhincr
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.plnt
|
2020-02-21 11:30:03 -05:00
|
|
|
,COALESCE(o.promo,'') promo
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text return_reas
|
|
|
|
,o.terms
|
|
|
|
,null::text custpo
|
|
|
|
,null::text remit_to
|
|
|
|
,null::text bill_class
|
|
|
|
,o.bill_cust
|
|
|
|
,null::text bill_rep
|
|
|
|
,null::text bill_terr
|
|
|
|
,null::text ship_class
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.ship_cust
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text ship_rep
|
|
|
|
,null::text ship_terr
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.dsm
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text account
|
|
|
|
,null::text shipgrp
|
|
|
|
,null::text geo
|
|
|
|
,null::text chan
|
|
|
|
,null::text chansub
|
|
|
|
,null::text orig_ctry
|
|
|
|
,null::text orig_prov
|
|
|
|
,null::text orig_post
|
|
|
|
,null::text bill_ctry
|
|
|
|
,null::text bill_prov
|
|
|
|
,null::text bill_post
|
|
|
|
,null::text dest_ctry
|
|
|
|
,null::text dest_prov
|
|
|
|
,null::text dest_post
|
|
|
|
,o.part
|
|
|
|
,null::text styc
|
|
|
|
,null::text colc
|
|
|
|
,null::text colgrp
|
|
|
|
,null::text coltier
|
|
|
|
,null::text colstat
|
|
|
|
,null::text sizc
|
2023-02-24 19:28:14 -05:00
|
|
|
,null::text uomp
|
|
|
|
,null::text suffix
|
|
|
|
,null::text accs_ps
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text brnd
|
|
|
|
,null::text majg
|
|
|
|
,null::text ming
|
|
|
|
,null::text majs
|
|
|
|
,null::text mins
|
|
|
|
,null::text gldco
|
|
|
|
,null::text gldc
|
|
|
|
,null::text glec
|
|
|
|
,null::text harm
|
|
|
|
,null::text clss
|
|
|
|
,null::text brand
|
|
|
|
,null::text assc
|
|
|
|
,null::text ddunit
|
|
|
|
,null::text unti
|
|
|
|
,null::numeric lbs
|
|
|
|
,null::numeric plt
|
|
|
|
,null::text plcd
|
|
|
|
,o.fs_line
|
|
|
|
,o.r_currency
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.r_rate
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.c_currency
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.c_rate
|
2020-02-19 17:05:27 -05:00
|
|
|
,sum(o.fb_qty) fb_qty
|
|
|
|
,sum(o.fb_val_loc) fb_val_loc
|
|
|
|
,sum(o.fb_val_loc_dis) fb_val_loc_dis
|
|
|
|
,sum(o.fb_val_loc_qt) fb_val_loc_qt
|
|
|
|
,sum(o.fb_val_loc_pl) fb_val_loc_pl
|
|
|
|
,sum(o.fb_val_loc_tar) fb_val_loc_tar
|
|
|
|
,sum(o.fb_cst_loc) fb_cst_loc
|
|
|
|
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
|
|
|
|
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
|
|
|
|
,o.calc_status
|
|
|
|
,o.flag
|
|
|
|
,o.odate
|
|
|
|
,o.oseas
|
|
|
|
,o.rdate
|
|
|
|
,o.rseas
|
2023-02-24 19:28:14 -05:00
|
|
|
,o.pdate
|
|
|
|
,o.pseas
|
2020-02-19 17:05:27 -05:00
|
|
|
-----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
|
2023-02-24 19:28:14 -05:00
|
|
|
rlarp.osm o
|
2020-02-19 17:05:27 -05:00
|
|
|
--snap the ship dates of the historic fiscal period
|
|
|
|
LEFT OUTER JOIN gld ON
|
|
|
|
gld.fspr = o.fspr
|
|
|
|
--get the shipping season for open orders based on the snapped date
|
|
|
|
LEFT OUTER JOIN gld ss ON
|
|
|
|
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
|
|
|
WHERE
|
|
|
|
(
|
2020-02-20 14:26:39 -05:00
|
|
|
--base period orders booked....
|
2023-03-01 16:01:32 -05:00
|
|
|
o.odate BETWEEN '2022-06-01' AND '2023-03-01'
|
2020-02-20 14:26:39 -05:00
|
|
|
--...or any open orders currently booked before cutoff....
|
2023-03-01 16:01:32 -05:00
|
|
|
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01')
|
2020-02-20 14:26:39 -05:00
|
|
|
--...or anything that shipped in that period
|
2023-03-01 16:01:32 -05:00
|
|
|
OR ((o.fspr BETWEEN '2301' AND '2309' OR o.fspr = '0000') AND o.sdate < '2023-03-01')
|
2020-02-19 17:05:27 -05:00
|
|
|
)
|
|
|
|
AND fs_line = '41010'
|
|
|
|
AND calc_status <> 'CANCELED'
|
2020-02-24 22:51:17 -05:00
|
|
|
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
2021-04-05 12:06:49 -04:00
|
|
|
---exclude integrated quotes----
|
|
|
|
AND version = 'ACTUALS'
|
2020-02-19 17:05:27 -05:00
|
|
|
GROUP BY
|
|
|
|
o.fspr
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.plnt
|
2020-02-21 11:30:03 -05:00
|
|
|
,COALESCE(o.promo,'')
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.terms
|
|
|
|
,o.bill_cust
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.ship_cust
|
|
|
|
,o.dsm
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.part
|
|
|
|
,o.fs_line
|
|
|
|
,o.r_currency
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.r_rate
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.c_currency
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.c_rate
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.calc_status
|
|
|
|
,o.flag
|
|
|
|
,o.odate
|
|
|
|
,o.oseas
|
|
|
|
,o.rdate
|
|
|
|
,o.rseas
|
2023-02-24 19:28:14 -05:00
|
|
|
,o.pdate
|
|
|
|
,o.pseas
|
2020-02-19 17:05:27 -05:00
|
|
|
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
|
|
|
,ss.ssyr
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
|
|
-----------documents-------------
|
|
|
|
null::int "ddord#"
|
|
|
|
,null::int "dditm#"
|
|
|
|
,null::int "fgbol#"
|
|
|
|
,null::int "fgent#"
|
|
|
|
,null::int "diinv#"
|
|
|
|
,null::int "dilin#"
|
|
|
|
,null::int quoten
|
|
|
|
,null::int quotel
|
|
|
|
----------dates/status------------------
|
|
|
|
,o.odate + interval '1 year' dcodat
|
|
|
|
,o.rdate + interval '1 year' ddqdat
|
|
|
|
,null::date dcmdat
|
|
|
|
,null::date fesdat
|
|
|
|
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' dhidat
|
|
|
|
,null::text fesind
|
|
|
|
,null::text dhpost
|
|
|
|
,o.fspr
|
|
|
|
-----------measures--------------------
|
|
|
|
,null::numeric ddqtoi
|
|
|
|
,null::numeric ddqtsi
|
|
|
|
,null::numeric fgqshp
|
|
|
|
,null::numeric diqtsh
|
|
|
|
,null::numeric diext
|
|
|
|
,null::numeric ditdis
|
|
|
|
,null::jsonb discj
|
|
|
|
,null::text dhincr
|
|
|
|
,plnt
|
2020-02-21 11:30:03 -05:00
|
|
|
,COALESCE(o.promo,'') promo
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text return_reas
|
|
|
|
,o.terms
|
|
|
|
,null::text custpo
|
|
|
|
,null::text remit_to
|
|
|
|
,null::text bill_class
|
|
|
|
,o.bill_cust
|
|
|
|
,null::text bill_rep
|
|
|
|
,null::text bill_terr
|
|
|
|
,null::text ship_class
|
|
|
|
,ship_cust
|
|
|
|
,null::text ship_rep
|
|
|
|
,null::text ship_terr
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.dsm
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text account
|
|
|
|
,null::text shipgrp
|
|
|
|
,null::text geo
|
|
|
|
,null::text chan
|
|
|
|
,null::text chansub
|
|
|
|
,null::text orig_ctry
|
|
|
|
,null::text orig_prov
|
|
|
|
,null::text orig_post
|
|
|
|
,null::text bill_ctry
|
|
|
|
,null::text bill_prov
|
|
|
|
,null::text bill_post
|
|
|
|
,null::text dest_ctry
|
|
|
|
,null::text dest_prov
|
|
|
|
,null::text dest_post
|
|
|
|
,o.part
|
|
|
|
,null::text styc
|
|
|
|
,null::text colc
|
|
|
|
,null::text colgrp
|
|
|
|
,null::text coltier
|
|
|
|
,null::text colstat
|
|
|
|
,null::text sizc
|
2023-02-24 19:28:14 -05:00
|
|
|
,null::text uomp
|
|
|
|
,null::text suffix
|
|
|
|
,null::text accs_ps
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text brnd
|
|
|
|
,null::text majg
|
|
|
|
,null::text ming
|
|
|
|
,null::text majs
|
|
|
|
,null::text mins
|
|
|
|
,null::text gldco
|
|
|
|
,null::text gldc
|
|
|
|
,null::text glec
|
|
|
|
,null::text harm
|
|
|
|
,null::text clss
|
|
|
|
,null::text brand
|
|
|
|
,null::text assc
|
|
|
|
,null::text ddunit
|
|
|
|
,null::text unti
|
|
|
|
,null::numeric lbs
|
|
|
|
,null::numeric plt
|
|
|
|
,null::text plcd
|
|
|
|
,o.fs_line
|
|
|
|
,o.r_currency
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.r_rate
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.c_currency
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.c_rate
|
2020-02-19 17:05:27 -05:00
|
|
|
,sum(o.fb_qty) fb_qty
|
|
|
|
,sum(o.fb_val_loc) fb_val_loc
|
|
|
|
,sum(o.fb_val_loc_dis) fb_val_loc_dis
|
|
|
|
,sum(o.fb_val_loc_qt) fb_val_loc_qt
|
|
|
|
,sum(o.fb_val_loc_pl) fb_val_loc_pl
|
|
|
|
,sum(o.fb_val_loc_tar) fb_val_loc_tar
|
|
|
|
,sum(o.fb_cst_loc) fb_cst_loc
|
|
|
|
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
|
|
|
|
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
|
|
|
|
,o.calc_status
|
|
|
|
,o.flag
|
|
|
|
,o.odate + interval '1 year' odate
|
2023-03-01 17:55:30 -05:00
|
|
|
,o.oseas + 1 rseas
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.rdate + interval '1 year' rdate
|
|
|
|
,o.rseas + 1 rseas
|
2023-02-24 19:28:14 -05:00
|
|
|
,o.pdate + interval '1 year' pdate
|
|
|
|
,o.pseas + 1 pseas
|
2020-02-19 17:05:27 -05:00
|
|
|
-----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
|
2023-02-24 19:28:14 -05:00
|
|
|
rlarp.osm o
|
2020-02-19 17:05:27 -05:00
|
|
|
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
|
2023-03-01 16:01:32 -05:00
|
|
|
o.odate BETWEEN '2022-03-01' AND '2022-05-31'
|
2020-02-19 17:05:27 -05:00
|
|
|
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
|
2021-04-05 12:06:49 -04:00
|
|
|
AND version = 'ACTUALS'
|
2020-02-19 17:05:27 -05:00
|
|
|
GROUP BY
|
|
|
|
o.fspr
|
|
|
|
,plnt
|
2020-02-21 11:30:03 -05:00
|
|
|
,COALESCE(o.promo,'')
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.terms
|
|
|
|
,o.bill_cust
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.ship_cust
|
|
|
|
,o.dsm
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.part
|
|
|
|
,o.fs_line
|
|
|
|
,o.r_currency
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.r_rate
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.c_currency
|
2021-04-05 12:06:49 -04:00
|
|
|
,o.c_rate
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.calc_status
|
|
|
|
,o.flag
|
|
|
|
,o.odate
|
|
|
|
,o.oseas
|
|
|
|
,o.rdate
|
|
|
|
,o.rseas
|
2023-02-24 19:28:14 -05:00
|
|
|
,o.pdate
|
|
|
|
,o.pseas
|
2020-02-19 17:05:27 -05:00
|
|
|
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
|
|
|
,ss.ssyr
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
|
|
-----------documents-------------
|
|
|
|
null::int "ddord#"
|
|
|
|
,null::int "dditm#"
|
|
|
|
,null::int "fgbol#"
|
|
|
|
,null::int "fgent#"
|
|
|
|
,null::int "diinv#"
|
|
|
|
,null::int "dilin#"
|
|
|
|
,null::int quoten
|
|
|
|
,null::int quotel
|
|
|
|
----------dates/status------------------
|
|
|
|
,o.odate + interval '1 year' dcodat
|
|
|
|
,o.rdate + interval '1 year' ddqdat
|
|
|
|
,null::date dcmdat
|
|
|
|
,null::date fesdat
|
|
|
|
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' dhidat
|
|
|
|
,null::text fesind
|
|
|
|
,null::text dhpost
|
|
|
|
,o.fspr
|
|
|
|
-----------measures--------------------
|
|
|
|
,null::numeric ddqtoi
|
|
|
|
,null::numeric ddqtsi
|
|
|
|
,null::numeric fgqshp
|
|
|
|
,null::numeric diqtsh
|
|
|
|
,null::numeric diext
|
|
|
|
,null::numeric ditdis
|
|
|
|
,null::jsonb discj
|
|
|
|
,null::text dhincr
|
|
|
|
,plnt
|
2020-02-21 11:30:03 -05:00
|
|
|
,COALESCE(o.promo,'') promo
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text return_reas
|
|
|
|
,o.terms
|
|
|
|
,null::text custpo
|
|
|
|
,null::text remit_to
|
|
|
|
,null::text bill_class
|
|
|
|
,o.bill_cust
|
|
|
|
,null::text bill_rep
|
|
|
|
,null::text bill_terr
|
|
|
|
,null::text ship_class
|
|
|
|
,ship_cust
|
|
|
|
,null::text ship_rep
|
|
|
|
,null::text ship_terr
|
|
|
|
,null::text dsm
|
|
|
|
,null::text account
|
|
|
|
,null::text shipgrp
|
|
|
|
,null::text geo
|
|
|
|
,null::text chan
|
|
|
|
,null::text chansub
|
|
|
|
,null::text orig_ctry
|
|
|
|
,null::text orig_prov
|
|
|
|
,null::text orig_post
|
|
|
|
,null::text bill_ctry
|
|
|
|
,null::text bill_prov
|
|
|
|
,null::text bill_post
|
|
|
|
,null::text dest_ctry
|
|
|
|
,null::text dest_prov
|
|
|
|
,null::text dest_post
|
|
|
|
,o.part
|
|
|
|
,null::text styc
|
|
|
|
,null::text colc
|
|
|
|
,null::text colgrp
|
|
|
|
,null::text coltier
|
|
|
|
,null::text colstat
|
|
|
|
,null::text sizc
|
2023-02-24 19:28:14 -05:00
|
|
|
,null::text uomp
|
|
|
|
,null::text suffix
|
|
|
|
,null::text accs_ps
|
2020-02-19 17:05:27 -05:00
|
|
|
,null::text brnd
|
|
|
|
,null::text majg
|
|
|
|
,null::text ming
|
|
|
|
,null::text majs
|
|
|
|
,null::text mins
|
|
|
|
,null::text gldco
|
|
|
|
,null::text gldc
|
|
|
|
,null::text glec
|
|
|
|
,null::text harm
|
|
|
|
,null::text clss
|
|
|
|
,null::text brand
|
|
|
|
,null::text assc
|
|
|
|
,null::text ddunit
|
|
|
|
,null::text unti
|
|
|
|
,null::numeric lbs
|
|
|
|
,null::numeric plt
|
|
|
|
,null::text plcd
|
|
|
|
,o.fs_line
|
|
|
|
,o.r_currency
|
|
|
|
,null::numeric r_rate
|
|
|
|
,o.c_currency
|
|
|
|
,null::numeric c_rate
|
|
|
|
,sum(o.fb_qty) fb_qty
|
|
|
|
,sum(o.fb_val_loc) fb_val_loc
|
|
|
|
,sum(o.fb_val_loc_dis) fb_val_loc_dis
|
|
|
|
,sum(o.fb_val_loc_qt) fb_val_loc_qt
|
|
|
|
,sum(o.fb_val_loc_pl) fb_val_loc_pl
|
|
|
|
,sum(o.fb_val_loc_tar) fb_val_loc_tar
|
|
|
|
,sum(o.fb_cst_loc) fb_cst_loc
|
|
|
|
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
|
|
|
|
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
|
|
|
|
,o.calc_status
|
|
|
|
,o.flag
|
|
|
|
,o.odate odate
|
2023-03-01 17:55:30 -05:00
|
|
|
,o.oseas rseas
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.rdate rdate
|
|
|
|
,o.rseas rseas
|
2023-02-24 19:28:14 -05:00
|
|
|
,o.pdate pdate
|
|
|
|
,o.pseas pseas
|
2020-02-19 17:05:27 -05:00
|
|
|
-----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
|
2023-02-24 19:28:14 -05:00
|
|
|
rlarp.osmp o
|
2020-02-19 17:05:27 -05:00
|
|
|
LEFT OUTER JOIN gld ON
|
|
|
|
gld.fspr = o.fspr
|
|
|
|
LEFT OUTER JOIN gld ss ON
|
|
|
|
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
|
|
|
WHERE
|
2021-04-05 12:06:49 -04:00
|
|
|
false
|
|
|
|
--o.odate BETWEEN '2020-03-01' AND '2020-05-31'
|
|
|
|
--AND fs_line = '41010'
|
|
|
|
--AND calc_status <> 'CANCELED'
|
2021-04-04 23:18:18 -04:00
|
|
|
------dont pull forecast for a baseline this time around--
|
2020-02-19 17:05:27 -05:00
|
|
|
GROUP BY
|
|
|
|
o.fspr
|
|
|
|
,plnt
|
2020-02-21 11:30:03 -05:00
|
|
|
,COALESCE(o.promo,'')
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.terms
|
|
|
|
,o.bill_cust
|
|
|
|
,ship_cust
|
|
|
|
,o.part
|
|
|
|
,o.fs_line
|
|
|
|
,o.r_currency
|
|
|
|
,o.c_currency
|
|
|
|
,o.calc_status
|
|
|
|
,o.flag
|
|
|
|
,o.odate
|
|
|
|
,o.oseas
|
|
|
|
,o.rdate
|
|
|
|
,o.rseas
|
2023-02-24 19:28:14 -05:00
|
|
|
,o.pdate
|
|
|
|
,o.pseas
|
2020-02-19 17:05:27 -05:00
|
|
|
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
|
|
|
,ss.ssyr
|
|
|
|
)
|
|
|
|
,incr AS (
|
2023-03-01 17:55:30 -05:00
|
|
|
SELECT
|
2020-02-19 17:05:27 -05:00
|
|
|
o."ddord#"
|
|
|
|
,o."dditm#"
|
|
|
|
,o."fgbol#"
|
|
|
|
,o."fgent#"
|
|
|
|
,o."diinv#"
|
|
|
|
,o."dilin#"
|
|
|
|
,o.quoten
|
|
|
|
,o.quotel
|
|
|
|
,o.dcodat + interval '1 year' --incremented
|
|
|
|
,o.ddqdat + interval '1 year' --incremented
|
|
|
|
,o.dcmdat
|
|
|
|
,o.fesdat
|
|
|
|
,o.dhidat + interval '1 year' --incremented
|
|
|
|
,o.fesind
|
|
|
|
,o.dhpost
|
|
|
|
,gld.fspr --incremented
|
|
|
|
,o.ddqtoi
|
|
|
|
,o.ddqtsi
|
|
|
|
,o.fgqshp
|
|
|
|
,o.diqtsh
|
|
|
|
,o.diext
|
|
|
|
,o.ditdis
|
|
|
|
,o.discj
|
|
|
|
,o.dhincr
|
|
|
|
,o.plnt
|
|
|
|
,o.promo
|
|
|
|
,o.return_reas
|
|
|
|
,o.terms
|
|
|
|
,o.custpo
|
|
|
|
,o.remit_to
|
|
|
|
,o.bill_class
|
|
|
|
,o.bill_cust
|
|
|
|
,o.bill_rep
|
|
|
|
,o.bill_terr
|
|
|
|
,o.ship_class
|
|
|
|
,o.ship_cust
|
|
|
|
,o.ship_rep
|
|
|
|
,o.ship_terr
|
|
|
|
,o.dsm
|
|
|
|
,o.account
|
|
|
|
,o.shipgrp
|
|
|
|
,o.geo
|
|
|
|
,o.chan
|
|
|
|
,o.chansub
|
|
|
|
,o.orig_ctry
|
|
|
|
,o.orig_prov
|
|
|
|
,o.orig_post
|
|
|
|
,o.bill_ctry
|
|
|
|
,o.bill_prov
|
|
|
|
,o.bill_post
|
|
|
|
,o.dest_ctry
|
|
|
|
,o.dest_prov
|
|
|
|
,o.dest_post
|
|
|
|
,o.part
|
|
|
|
,o.styc
|
|
|
|
,o.colc
|
|
|
|
,o.colgrp
|
|
|
|
,o.coltier
|
|
|
|
,o.colstat
|
|
|
|
,o.sizc
|
2023-03-01 17:55:30 -05:00
|
|
|
,o.uomp
|
|
|
|
,o.suffix
|
2023-02-24 19:28:14 -05:00
|
|
|
,o.accs_ps
|
2023-03-01 17:55:30 -05:00
|
|
|
,o.brnd
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.majg
|
|
|
|
,o.ming
|
|
|
|
,o.majs
|
|
|
|
,o.mins
|
|
|
|
,o.gldco
|
|
|
|
,o.gldc
|
|
|
|
,o.glec
|
|
|
|
,o.harm
|
|
|
|
,o.clss
|
|
|
|
,o.brand
|
|
|
|
,o.assc
|
|
|
|
,o.ddunit
|
|
|
|
,o.unti
|
|
|
|
,o.lbs
|
|
|
|
,o.plt
|
|
|
|
,o.plcd
|
|
|
|
,o.fs_line
|
|
|
|
,o.r_currency
|
|
|
|
,o.r_rate
|
|
|
|
,o.c_currency
|
|
|
|
,o.c_rate
|
|
|
|
,o.fb_qty
|
|
|
|
,o.fb_val_loc
|
|
|
|
,o.fb_val_loc_dis
|
|
|
|
,o.fb_val_loc_qt
|
|
|
|
,o.fb_val_loc_pl
|
|
|
|
,o.fb_val_loc_tar
|
|
|
|
,o.fb_cst_loc
|
|
|
|
,o.fb_cst_loc_cur
|
|
|
|
,o.fb_cst_loc_fut
|
|
|
|
,o.calc_status
|
|
|
|
,o.flag
|
|
|
|
,o.odate + interval '1 year' --incremented
|
|
|
|
,o.oseas + 1 --incremented
|
|
|
|
,o.rdate + interval '1 year' --incremented
|
|
|
|
,o.rseas + 1 --incremented
|
2023-02-24 19:28:14 -05:00
|
|
|
,o.pdate + interval '1 year' --incremented
|
|
|
|
,o.pseas + 1 --incremented
|
2020-02-19 17:05:27 -05:00
|
|
|
,o.sdate + interval '1 year' --incremented
|
|
|
|
,o.sseas + 1 --incremented
|
2023-03-01 16:01:32 -05:00
|
|
|
,'b23' "version"
|
2020-02-19 17:05:27 -05:00
|
|
|
,'copy' iter
|
2023-03-01 17:55:30 -05:00
|
|
|
FROM
|
2020-02-19 17:05:27 -05:00
|
|
|
baseline o
|
|
|
|
LEFT OUTER JOIN gld ON
|
|
|
|
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
|
|
|
|
WHERE
|
2023-03-01 16:01:32 -05:00
|
|
|
o.odate + interval '1 year' >= '2023-06-01'
|
2020-02-19 17:05:27 -05:00
|
|
|
)
|
2023-02-24 19:28:14 -05:00
|
|
|
--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
|
2023-03-01 17:55:30 -05:00
|
|
|
,sizc
|
|
|
|
,uomp
|
|
|
|
,suffix
|
|
|
|
,accs_ps
|
|
|
|
,brnd
|
2023-02-24 19:28:14 -05:00
|
|
|
,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
|
2023-03-01 17:55:30 -05:00
|
|
|
,pdate
|
|
|
|
,pseas
|
2023-02-24 19:28:14 -05:00
|
|
|
,sdate
|
|
|
|
,sseas
|
|
|
|
,"version"
|
|
|
|
,iter
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT * FROM baseline
|
|
|
|
UNION ALL
|
|
|
|
SELECT * FROM incr
|
2023-03-01 16:01:32 -05:00
|
|
|
) x;
|
2020-02-19 17:05:27 -05:00
|
|
|
|
|
|
|
---identify short ships: causes disconnect with actual sales-------------------------------------------------------------------
|
|
|
|
--UPDATE rlarp.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER';
|
|
|
|
|
|
|
|
---identify goofy ship dates: causes disconnect with sales when splicing in a forecast that has this problem-------------------
|
2021-04-04 23:18:18 -04:00
|
|
|
--UPDATE rlarp.osmfs SET iter = 'bad date' WHERE adj_shipdate < adj_orderdate;
|