Compare commits
No commits in common. "8809cb9ad4a76b1aabe24551b7248f4319dcecb7" and "e73d69ad65d702e2af868d2d166b03554604329f" have entirely different histories.
8809cb9ad4
...
e73d69ad65
BIN
Master Template 1.6.xlsm
Normal file
BIN
Master Template 1.6.xlsm
Normal file
Binary file not shown.
Binary file not shown.
@ -6,8 +6,8 @@ TRUNCATE TABLE rlarp.osmf_dev;
|
|||||||
DROP TABLE IF EXISTS tdr;
|
DROP TABLE IF EXISTS tdr;
|
||||||
CREATE TEMP TABLE tdr AS (
|
CREATE TEMP TABLE tdr AS (
|
||||||
SELECT
|
SELECT
|
||||||
DATERANGE('2022-06-01','2023-06-01','[)') drange
|
DATERANGE('2020-06-01','2021-06-01','[)') drange
|
||||||
,DATERANGE(('2022-06-01'::date + '1 year'::interval)::date,('2023-06-01'::date + '1 year'::interval)::date,'[)') repl
|
,DATERANGE(('2020-06-01'::date + '1 year'::interval)::date,('2021-06-01'::date + '1 year'::interval)::date,'[)') repl
|
||||||
,'1 year'::interval AS incr
|
,'1 year'::interval AS incr
|
||||||
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter
|
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter
|
||||||
);
|
);
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
-- Connection: usmidsap01.ubm
|
|
||||||
--\timing
|
--\timing
|
||||||
TRUNCATE TABLE rlarp.osmf;
|
truncate table rlarp.osmf_dev;
|
||||||
|
|
||||||
INSERT INTO rlarp.osmf
|
|
||||||
WITH
|
WITH
|
||||||
gld AS (
|
gld AS (
|
||||||
SELECT
|
SELECT
|
||||||
N1COMP COMP
|
N1COMP COMP
|
||||||
,N1CCYY FSYR
|
,N1CCYY FSYR
|
||||||
,KPMAXP PERDS
|
,KPMAXP PERDS
|
||||||
@ -14,13 +12,13 @@ gld AS (
|
|||||||
,N1SD01 SDAT
|
,N1SD01 SDAT
|
||||||
,N1ED01 EDAT
|
,N1ED01 EDAT
|
||||||
,to_char(N1ED01,'yymm') CAPR
|
,to_char(N1ED01,'yymm') CAPR
|
||||||
,N1ED01 - N1SD01 +1 NDAYS
|
,N1ED01 - N1SD01 +1 NDAYS
|
||||||
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
|
,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
|
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
|
||||||
FROM
|
FROM
|
||||||
LGDAT.GLDATREF
|
LGDAT.GLDATREF
|
||||||
INNER JOIN LGDAT.GLDATE ON
|
INNER JOIN LGDAT.GLDATE ON
|
||||||
KPCOMP = N1COMP AND
|
KPCOMP = N1COMP AND
|
||||||
KPCCYY = N1CCYY
|
KPCCYY = N1CCYY
|
||||||
WHERE
|
WHERE
|
||||||
N1COMP = 93
|
N1COMP = 93
|
||||||
@ -92,9 +90,8 @@ gld AS (
|
|||||||
,null::text coltier
|
,null::text coltier
|
||||||
,null::text colstat
|
,null::text colstat
|
||||||
,null::text sizc
|
,null::text sizc
|
||||||
,null::text uomp
|
,null::text pckg
|
||||||
,null::text suffix
|
,null::text kit
|
||||||
,null::text accs_ps
|
|
||||||
,null::text brnd
|
,null::text brnd
|
||||||
,null::text majg
|
,null::text majg
|
||||||
,null::text ming
|
,null::text ming
|
||||||
@ -132,15 +129,13 @@ gld AS (
|
|||||||
,o.oseas
|
,o.oseas
|
||||||
,o.rdate
|
,o.rdate
|
||||||
,o.rseas
|
,o.rseas
|
||||||
,o.pdate
|
|
||||||
,o.pseas
|
|
||||||
-----when null, greatest/least is just going to act like coalesce
|
-----when null, greatest/least is just going to act like coalesce
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||||
,ss.ssyr sseas
|
,ss.ssyr sseas
|
||||||
,'15mo' "version"
|
,'15mo' "version"
|
||||||
,'actuals' iter
|
,'actuals' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm o
|
rlarp.osm_dev o
|
||||||
--snap the ship dates of the historic fiscal period
|
--snap the ship dates of the historic fiscal period
|
||||||
LEFT OUTER JOIN gld ON
|
LEFT OUTER JOIN gld ON
|
||||||
gld.fspr = o.fspr
|
gld.fspr = o.fspr
|
||||||
@ -150,11 +145,11 @@ gld AS (
|
|||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
--base period orders booked....
|
--base period orders booked....
|
||||||
o.odate BETWEEN '2022-06-01' AND '2023-03-01'
|
o.odate BETWEEN '2020-06-01' AND '2021-04-11'
|
||||||
--...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-03-01')
|
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2021-04-11')
|
||||||
--...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-03-01')
|
OR o.fspr BETWEEN '2101' AND '2110'
|
||||||
)
|
)
|
||||||
AND fs_line = '41010'
|
AND fs_line = '41010'
|
||||||
AND calc_status <> 'CANCELED'
|
AND calc_status <> 'CANCELED'
|
||||||
@ -181,8 +176,6 @@ gld AS (
|
|||||||
,o.oseas
|
,o.oseas
|
||||||
,o.rdate
|
,o.rdate
|
||||||
,o.rseas
|
,o.rseas
|
||||||
,o.pdate
|
|
||||||
,o.pseas
|
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||||
,ss.ssyr
|
,ss.ssyr
|
||||||
UNION ALL
|
UNION ALL
|
||||||
@ -250,9 +243,8 @@ gld AS (
|
|||||||
,null::text coltier
|
,null::text coltier
|
||||||
,null::text colstat
|
,null::text colstat
|
||||||
,null::text sizc
|
,null::text sizc
|
||||||
,null::text uomp
|
,null::text pckg
|
||||||
,null::text suffix
|
,null::text kit
|
||||||
,null::text accs_ps
|
|
||||||
,null::text brnd
|
,null::text brnd
|
||||||
,null::text majg
|
,null::text majg
|
||||||
,null::text ming
|
,null::text ming
|
||||||
@ -287,24 +279,22 @@ gld AS (
|
|||||||
,o.calc_status
|
,o.calc_status
|
||||||
,o.flag
|
,o.flag
|
||||||
,o.odate + interval '1 year' odate
|
,o.odate + interval '1 year' odate
|
||||||
,o.oseas + 1 rseas
|
,o.oseas + 1 rseas
|
||||||
,o.rdate + interval '1 year' rdate
|
,o.rdate + interval '1 year' rdate
|
||||||
,o.rseas + 1 rseas
|
,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
|
-----when null, greatest/least is just going to act like coalesce
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
||||||
,ss.ssyr sseas
|
,ss.ssyr sseas
|
||||||
,'actuals' "version"
|
,'actuals' "version"
|
||||||
,'actuals_plug' iter
|
,'actuals_plug' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm o
|
rlarp.osm_dev o
|
||||||
LEFT OUTER JOIN gld ON
|
LEFT OUTER JOIN gld ON
|
||||||
gld.fspr = o.fspr
|
gld.fspr = o.fspr
|
||||||
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-03-01' AND '2022-05-31'
|
o.odate BETWEEN '2020-04-12' AND '2020-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
|
||||||
@ -329,8 +319,6 @@ gld AS (
|
|||||||
,o.oseas
|
,o.oseas
|
||||||
,o.rdate
|
,o.rdate
|
||||||
,o.rseas
|
,o.rseas
|
||||||
,o.pdate
|
|
||||||
,o.pseas
|
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||||
,ss.ssyr
|
,ss.ssyr
|
||||||
UNION ALL
|
UNION ALL
|
||||||
@ -398,9 +386,8 @@ gld AS (
|
|||||||
,null::text coltier
|
,null::text coltier
|
||||||
,null::text colstat
|
,null::text colstat
|
||||||
,null::text sizc
|
,null::text sizc
|
||||||
,null::text uomp
|
,null::text pckg
|
||||||
,null::text suffix
|
,null::text kit
|
||||||
,null::text accs_ps
|
|
||||||
,null::text brnd
|
,null::text brnd
|
||||||
,null::text majg
|
,null::text majg
|
||||||
,null::text ming
|
,null::text ming
|
||||||
@ -435,18 +422,16 @@ gld AS (
|
|||||||
,o.calc_status
|
,o.calc_status
|
||||||
,o.flag
|
,o.flag
|
||||||
,o.odate odate
|
,o.odate odate
|
||||||
,o.oseas rseas
|
,o.oseas rseas
|
||||||
,o.rdate rdate
|
,o.rdate rdate
|
||||||
,o.rseas rseas
|
,o.rseas rseas
|
||||||
,o.pdate pdate
|
|
||||||
,o.pseas pseas
|
|
||||||
-----when null, greatest/least is just going to act like coalesce
|
-----when null, greatest/least is just going to act like coalesce
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||||
,ss.ssyr sseas
|
,ss.ssyr sseas
|
||||||
,'actuals' "version"
|
,'actuals' "version"
|
||||||
,'forecast_plug' iter
|
,'forecast_plug' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osmp o
|
rlarp.osmp_dev o
|
||||||
LEFT OUTER JOIN gld ON
|
LEFT OUTER JOIN gld ON
|
||||||
gld.fspr = o.fspr
|
gld.fspr = o.fspr
|
||||||
LEFT OUTER JOIN gld ss ON
|
LEFT OUTER JOIN gld ss ON
|
||||||
@ -474,13 +459,11 @@ gld AS (
|
|||||||
,o.oseas
|
,o.oseas
|
||||||
,o.rdate
|
,o.rdate
|
||||||
,o.rseas
|
,o.rseas
|
||||||
,o.pdate
|
|
||||||
,o.pseas
|
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||||
,ss.ssyr
|
,ss.ssyr
|
||||||
)
|
)
|
||||||
,incr AS (
|
,incr AS (
|
||||||
SELECT
|
SELECT
|
||||||
o."ddord#"
|
o."ddord#"
|
||||||
,o."dditm#"
|
,o."dditm#"
|
||||||
,o."fgbol#"
|
,o."fgbol#"
|
||||||
@ -541,9 +524,8 @@ SELECT
|
|||||||
,o.coltier
|
,o.coltier
|
||||||
,o.colstat
|
,o.colstat
|
||||||
,o.sizc
|
,o.sizc
|
||||||
,o.uomp
|
,o.pckg
|
||||||
,o.suffix
|
,o.kit
|
||||||
,o.accs_ps
|
|
||||||
,o.brnd
|
,o.brnd
|
||||||
,o.majg
|
,o.majg
|
||||||
,o.ming
|
,o.ming
|
||||||
@ -581,142 +563,21 @@ SELECT
|
|||||||
,o.oseas + 1 --incremented
|
,o.oseas + 1 --incremented
|
||||||
,o.rdate + interval '1 year' --incremented
|
,o.rdate + interval '1 year' --incremented
|
||||||
,o.rseas + 1 --incremented
|
,o.rseas + 1 --incremented
|
||||||
,o.pdate + interval '1 year' --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
|
||||||
,'b23' "version"
|
,'b22' "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' >= '2023-06-01'
|
o.odate + interval '1 year' >= '2021-06-01'
|
||||||
)
|
)
|
||||||
--INSERT INTO rlarp.osmf
|
INSERT INTO rlarp.osmf_dev
|
||||||
SELECT
|
SELECT * FROM incr
|
||||||
-----------documents-------------
|
UNION ALL
|
||||||
"ddord#"
|
SELECT * FROM baseline;
|
||||||
,"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-------------------------------------------------------------------
|
---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';
|
||||||
|
@ -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','baseline','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','1+11','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 o
|
rlarp.osmf_dev 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 "CMS.CUSLG".itemm i ON
|
LEFT OUTER JOIN rlarp.itemm i ON
|
||||||
i.item = o.part
|
i.item = o.part
|
||||||
)
|
)
|
||||||
SELECT * FROM loadset
|
SELECT * FROM loadset
|
||||||
|
2
build/rebuild_script.sh
Executable file → Normal file
2
build/rebuild_script.sh
Executable file → Normal 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;
|
||||||
|
@ -6,7 +6,7 @@ plist AS (
|
|||||||
part
|
part
|
||||||
,plnt
|
,plnt
|
||||||
FROM
|
FROM
|
||||||
rlarp.osmf
|
rlarp.osmf_dev
|
||||||
-----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 o
|
rlarp.osmf_dev 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;
|
@ -1,64 +1,64 @@
|
|||||||
----------------------------SET BILL-TO REP------------------------------------
|
----------------------------SET BILL-TO REP------------------------------------
|
||||||
|
|
||||||
UPDATE
|
UPDATE
|
||||||
rlarp.osmf s
|
RLARP.OSMF_DEV 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 s
|
RLARP.OSMF_DEV 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 o
|
RLARP.OSMF_DEV 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 o
|
RLARP.OSMF_DEV 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
|
rlarp.osmF_dev
|
||||||
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 s
|
RLARP.OSMF_DEV 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 s
|
RLARP.OSMF_DEV 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;
|
||||||
|
@ -1,29 +1,28 @@
|
|||||||
UPDATE
|
UPDATE
|
||||||
rlarp.osmf o
|
RLARP.OSMF_DEV O
|
||||||
SET
|
SET
|
||||||
stlc = m.stlc
|
STYC = 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
|
||||||
,uomp = m.uomp
|
,PCKG = M.PACKAGE
|
||||||
,suffix = m.suffix
|
,KIT = M.KIT
|
||||||
,accs_ps = m.accs_ps
|
,BRND = M.BRANDING
|
||||||
,brnd = m.branding
|
,MAJG = M.MAJG
|
||||||
,majg = m.majg
|
,MING = M.MING
|
||||||
,ming = m.ming
|
,MAJS = M.MAJS
|
||||||
,majs = m.majs
|
,MINS = M.MINS
|
||||||
,mins = m.mins
|
,GLDC = M.GLCD
|
||||||
,gldc = m.glcd
|
,GLEC = M.GLEC
|
||||||
,glec = m.glec
|
,HARM = M.HARM
|
||||||
,harm = m.harm
|
,CLSS = M.CLSS
|
||||||
,clss = m.clss
|
,BRAND = M.BRAND
|
||||||
,brand = m.brand
|
,ASSC = M.ASSC
|
||||||
,assc = m.assc
|
,LBS = CASE M.NWUN WHEN 'KG' THEN 2.2046 ELSE 1 END*M.NWHT
|
||||||
,lbs = CASE m.nwun WHEN 'KG' THEN 2.2046 ELSE 1 END*m.nwht
|
,UNTI = M.UNTI
|
||||||
,unti = m.unti
|
|
||||||
FROM
|
FROM
|
||||||
"CMS.CUSLG".itemm m
|
RLARP.ITEMM M
|
||||||
WHERE
|
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
|
,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_pool o
|
rlarp.osm_pool o
|
||||||
LEFT OUTER JOIN "CMS.CUSLG".itemmv i ON
|
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||||
i.item = o.part
|
i.item = o.part
|
||||||
LEFT OUTER JOIN seg ON
|
LEFT OUTER JOIN seg ON
|
||||||
seg.glec = i.glec
|
seg.glec = i.glec
|
||||||
|
@ -3,9 +3,9 @@ Description=forecast_api
|
|||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/home/fc/.nvm/versions/node/v18.14.2/bin/node //opt/forecast_api/index.js
|
ExecStart=/usr/bin/node //opt/forecast_api/index.js
|
||||||
Restart=always
|
Restart=always
|
||||||
User=fc
|
User=fc_api
|
||||||
Environemnt=NODE_ENV=production
|
Environemnt=NODE_ENV=production
|
||||||
WorkingDirectory=//opt/forecast_api/
|
WorkingDirectory=//opt/forecast_api/
|
||||||
|
|
||||||
|
10
index.js
10
index.js
@ -203,7 +203,7 @@ server.post('/swap', bodyParser.json(), function(req, res) {
|
|||||||
res.send("no body was sent");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() + "-------------------------post swap:------------------------------")
|
console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------")
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//parse the where clause into the main sql statement
|
//parse the where clause into the main sql statement
|
||||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
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");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() + "-------------------------cust swap:------------------------------")
|
console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------")
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//parse the where clause into the main sql statement
|
//parse the where clause into the main sql statement
|
||||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
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");
|
res.send("no body was sent");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(new Date().toISOString() + "--------------------scale volume & price sales:-------------------");
|
console.log(new Date().toISOString() + "--------------------scale volume & price:-------------------");
|
||||||
req.body.stamp = new Date().toISOString()
|
req.body.stamp = new Date().toISOString()
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
//console.log(args);
|
//console.log(args);
|
||||||
@ -696,7 +696,7 @@ function build_where(req, c, w, d, args) {
|
|||||||
if (req.body.stamp) {
|
if (req.body.stamp) {
|
||||||
w = w +
|
w = w +
|
||||||
`
|
`
|
||||||
AND order_date >= least('` + req.body.stamp + "'::date,'2021-06-01')";
|
AND order_date >= '` + req.body.stamp + "'::date";
|
||||||
}
|
}
|
||||||
return { c, w, d };
|
return { c, w, d };
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
--BEGIN;
|
--BEGIN;
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
------------------goal price increases---------------------
|
------------------goal price increases---------------------
|
||||||
incr AS (
|
incr AS (
|
||||||
SELECT * FROM (VALUES
|
SELECT * FROM (VALUES
|
||||||
@ -99,7 +99,7 @@ incr AS (
|
|||||||
WHERE
|
WHERE
|
||||||
pricing <> ''
|
pricing <> ''
|
||||||
AND dba <> ''
|
AND dba <> ''
|
||||||
GROUP BY
|
GROUP BY
|
||||||
dba
|
dba
|
||||||
)
|
)
|
||||||
----customer dba price list pricing------
|
----customer dba price list pricing------
|
||||||
@ -154,11 +154,11 @@ 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
|
,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
|
FROM
|
||||||
rlarp.osm_dev o
|
rlarp.osm_dev o
|
||||||
INNER JOIN "CMS.CUSLG".itemm i ON
|
INNER JOIN rlarp.itemmv i ON
|
||||||
i.item = o.part
|
i.item = o.part
|
||||||
WHERE
|
WHERE
|
||||||
---exclude R&A's
|
---exclude R&A's
|
||||||
o.fs_line = '41010'
|
o.fs_line = '41010'
|
||||||
---exclude canceled orders
|
---exclude canceled orders
|
||||||
AND o.calc_status <> 'CANCELED'
|
AND o.calc_status <> 'CANCELED'
|
||||||
---exclude quotes
|
---exclude quotes
|
||||||
@ -207,7 +207,7 @@ incr AS (
|
|||||||
,assc
|
,assc
|
||||||
,chgrp
|
,chgrp
|
||||||
)
|
)
|
||||||
--SELECT * FROM baseline WHERE product = 'AMK06000.CBXX'
|
--SELECT * FROM baseline WHERE product = 'AMK06000.CBXX'
|
||||||
----------calculate pricing as it sits in the forecast--------------
|
----------calculate pricing as it sits in the forecast--------------
|
||||||
,poolprice AS (
|
,poolprice AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -226,7 +226,7 @@ SELECT
|
|||||||
,jsonb_agg(DISTINCT iter) iters
|
,jsonb_agg(DISTINCT iter) iters
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_pool o
|
rlarp.osm_pool o
|
||||||
,"CMS.CUSLG".itemm i
|
,rlarp.itemmv i
|
||||||
WHERE
|
WHERE
|
||||||
i.item = o.part
|
i.item = o.part
|
||||||
--AND o.units <> 0
|
--AND o.units <> 0
|
||||||
@ -249,7 +249,7 @@ HAVING
|
|||||||
)
|
)
|
||||||
----------pivot the pricing out into columns per customer/product--------
|
----------pivot the pricing out into columns per customer/product--------
|
||||||
,pivot AS (
|
,pivot AS (
|
||||||
SELECT
|
SELECT
|
||||||
p.productt
|
p.productt
|
||||||
,p.product
|
,p.product
|
||||||
--,p.styc
|
--,p.styc
|
||||||
@ -275,7 +275,7 @@ SELECT
|
|||||||
WHEN 'D' THEN i.rate
|
WHEN 'D' THEN i.rate
|
||||||
ELSE CASE p.majg
|
ELSE CASE p.majg
|
||||||
WHEN '610' THEN .02
|
WHEN '610' THEN .02
|
||||||
ElSE CASE p.colgrp
|
ElSE CASE p.colgrp
|
||||||
WHEN 'B' THEN .20
|
WHEN 'B' THEN .20
|
||||||
WHEN 'C' THEN .25
|
WHEN 'C' THEN .25
|
||||||
ELSE 1
|
ELSE 1
|
||||||
@ -285,7 +285,7 @@ SELECT
|
|||||||
,ms.avg_price target
|
,ms.avg_price target
|
||||||
----------------potential price list increase of 5% across board-----
|
----------------potential price list increase of 5% across board-----
|
||||||
,JSONB_AGG(DISTINCT (plist.jcpric*1.05)/1000) jcprice
|
,JSONB_AGG(DISTINCT (plist.jcpric*1.05)/1000) jcprice
|
||||||
--,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL
|
--,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL
|
||||||
-- THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
|
-- THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
|
||||||
-- THEN 'unknown'
|
-- THEN 'unknown'
|
||||||
-- ELSE 'new'
|
-- ELSE 'new'
|
||||||
@ -295,7 +295,7 @@ SELECT
|
|||||||
-- ELSE 'repeat'
|
-- ELSE 'repeat'
|
||||||
-- END
|
-- END
|
||||||
--END flag
|
--END flag
|
||||||
FROM
|
FROM
|
||||||
p
|
p
|
||||||
LEFT OUTER JOIN baseline bl ON
|
LEFT OUTER JOIN baseline bl ON
|
||||||
bl.product = p.product
|
bl.product = p.product
|
||||||
@ -353,29 +353,29 @@ GROUP BY
|
|||||||
--,log AS (
|
--,log AS (
|
||||||
-- INSERT INTO
|
-- INSERT INTO
|
||||||
-- rlarp.osm_log(doc)
|
-- rlarp.osm_log(doc)
|
||||||
-- SELECT
|
-- SELECT
|
||||||
-- $${
|
-- $${
|
||||||
-- "message":"application of last price and target increases to all forecast orders",
|
-- "message":"application of last price and target increases to all forecast orders",
|
||||||
-- "tag":"last price r1",
|
-- "tag":"last price r1",
|
||||||
-- "type":"build"
|
-- "type":"build"
|
||||||
-- }$$::jsonb doc
|
-- }$$::jsonb doc
|
||||||
-- RETURNING *
|
-- RETURNING *
|
||||||
--)
|
--)
|
||||||
---------collapse iterations-----------------------
|
---------collapse iterations-----------------------
|
||||||
,collapse AS (
|
,collapse AS (
|
||||||
SELECT
|
SELECT
|
||||||
o.fspr
|
o.fspr
|
||||||
,o.plnt ---master data
|
,o.plnt ---master data
|
||||||
,o.promo --history date mix
|
,o.promo --history date mix
|
||||||
,o.terms
|
,o.terms
|
||||||
,o.bill_cust_descr --history cust mix
|
,o.bill_cust_descr --history cust mix
|
||||||
,o.ship_cust_descr --history cust mix
|
,o.ship_cust_descr --history cust mix
|
||||||
,o.dsm
|
,o.dsm
|
||||||
,o.quota_rep_descr --master data
|
,o.quota_rep_descr --master data
|
||||||
,o.director
|
,o.director
|
||||||
,o.billto_group --master data
|
,o.billto_group --master data
|
||||||
,o.shipto_group
|
,o.shipto_group
|
||||||
,o.chan --master data
|
,o.chan --master data
|
||||||
,o.chansub
|
,o.chansub
|
||||||
,o.chan_retail
|
,o.chan_retail
|
||||||
,o.part
|
,o.part
|
||||||
@ -389,11 +389,11 @@ GROUP BY
|
|||||||
,o.mins_descr
|
,o.mins_descr
|
||||||
,o.segm
|
,o.segm
|
||||||
,o.substance
|
,o.substance
|
||||||
,o.fs_line
|
,o.fs_line
|
||||||
,o.r_currency
|
,o.r_currency
|
||||||
,o.r_rate
|
,o.r_rate
|
||||||
,o.c_currency
|
,o.c_currency
|
||||||
,o.c_rate
|
,o.c_rate
|
||||||
,SUM(o.units) units
|
,SUM(o.units) units
|
||||||
,SUM(o.value_loc) value_loc
|
,SUM(o.value_loc) value_loc
|
||||||
,SUM(o.value_usd) value_usd
|
,SUM(o.value_usd) value_usd
|
||||||
@ -401,8 +401,8 @@ GROUP BY
|
|||||||
,SUM(o.value_loc) FILTER (WHERE iter <> 'upload price')/SUM(o.units) FILTER (WHERE iter <> 'upload price') price_loc
|
,SUM(o.value_loc) FILTER (WHERE iter <> 'upload price')/SUM(o.units) FILTER (WHERE iter <> 'upload price') price_loc
|
||||||
,SUM(o.cost_loc) cost_loc
|
,SUM(o.cost_loc) cost_loc
|
||||||
,SUM(o.cost_usd) cost_usd
|
,SUM(o.cost_usd) cost_usd
|
||||||
,o.calc_status --0
|
,o.calc_status --0
|
||||||
,o.flag --0
|
,o.flag --0
|
||||||
,o.order_date --history date mix
|
,o.order_date --history date mix
|
||||||
,o.order_month
|
,o.order_month
|
||||||
,o.order_season
|
,o.order_season
|
||||||
@ -415,22 +415,22 @@ GROUP BY
|
|||||||
FROM
|
FROM
|
||||||
rlarp.osm_pool o
|
rlarp.osm_pool o
|
||||||
--need to join to itemm to get the product from osm_pool
|
--need to join to itemm to get the product from osm_pool
|
||||||
,"CMS.CUSLG".itemm i
|
,rlarp.itemmv i
|
||||||
WHERE
|
WHERE
|
||||||
i.item = o.part
|
i.item = o.part
|
||||||
GROUP BY
|
GROUP BY
|
||||||
o.fspr
|
o.fspr
|
||||||
,o.plnt ---master data
|
,o.plnt ---master data
|
||||||
,o.promo --history date mix
|
,o.promo --history date mix
|
||||||
,o.terms
|
,o.terms
|
||||||
,o.bill_cust_descr --history cust mix
|
,o.bill_cust_descr --history cust mix
|
||||||
,o.ship_cust_descr --history cust mix
|
,o.ship_cust_descr --history cust mix
|
||||||
,o.dsm
|
,o.dsm
|
||||||
,o.quota_rep_descr --master data
|
,o.quota_rep_descr --master data
|
||||||
,o.director
|
,o.director
|
||||||
,o.billto_group --master data
|
,o.billto_group --master data
|
||||||
,o.shipto_group
|
,o.shipto_group
|
||||||
,o.chan --master data
|
,o.chan --master data
|
||||||
,o.chansub
|
,o.chansub
|
||||||
,o.chan_retail
|
,o.chan_retail
|
||||||
,o.part
|
,o.part
|
||||||
@ -444,13 +444,13 @@ GROUP BY
|
|||||||
,o.mins_descr
|
,o.mins_descr
|
||||||
,o.segm
|
,o.segm
|
||||||
,o.substance
|
,o.substance
|
||||||
,o.fs_line
|
,o.fs_line
|
||||||
,o.r_currency
|
,o.r_currency
|
||||||
,o.r_rate
|
,o.r_rate
|
||||||
,o.c_currency
|
,o.c_currency
|
||||||
,o.c_rate
|
,o.c_rate
|
||||||
,o.calc_status --0
|
,o.calc_status --0
|
||||||
,o.flag --0
|
,o.flag --0
|
||||||
,o.order_date --history date mix
|
,o.order_date --history date mix
|
||||||
,o.order_month
|
,o.order_month
|
||||||
,o.order_season
|
,o.order_season
|
||||||
@ -467,17 +467,17 @@ GROUP BY
|
|||||||
,ins AS (
|
,ins AS (
|
||||||
SELECT
|
SELECT
|
||||||
o.fspr
|
o.fspr
|
||||||
,o.plnt ---master data
|
,o.plnt ---master data
|
||||||
,o.promo --history date mix
|
,o.promo --history date mix
|
||||||
,o.terms
|
,o.terms
|
||||||
,o.bill_cust_descr --history cust mix
|
,o.bill_cust_descr --history cust mix
|
||||||
,o.ship_cust_descr --history cust mix
|
,o.ship_cust_descr --history cust mix
|
||||||
,o.dsm
|
,o.dsm
|
||||||
,o.quota_rep_descr --master data
|
,o.quota_rep_descr --master data
|
||||||
,o.director
|
,o.director
|
||||||
,o.billto_group --master data
|
,o.billto_group --master data
|
||||||
,o.shipto_group
|
,o.shipto_group
|
||||||
,o.chan --master data
|
,o.chan --master data
|
||||||
,o.chansub
|
,o.chansub
|
||||||
,o.chan_retail
|
,o.chan_retail
|
||||||
,o.part
|
,o.part
|
||||||
@ -490,11 +490,11 @@ SELECT
|
|||||||
,o.mins_descr
|
,o.mins_descr
|
||||||
,o.segm
|
,o.segm
|
||||||
,o.substance
|
,o.substance
|
||||||
,o.fs_line --master data
|
,o.fs_line --master data
|
||||||
,o.r_currency --history cust mix
|
,o.r_currency --history cust mix
|
||||||
,o.r_rate --master data
|
,o.r_rate --master data
|
||||||
,o.c_currency --master data
|
,o.c_currency --master data
|
||||||
,o.c_rate --master data
|
,o.c_rate --master data
|
||||||
--,o.units
|
--,o.units
|
||||||
,0::numeric units
|
,0::numeric units
|
||||||
,greatest(
|
,greatest(
|
||||||
@ -538,8 +538,8 @@ SELECT
|
|||||||
-----------
|
-----------
|
||||||
,0::numeric cost_loc
|
,0::numeric cost_loc
|
||||||
,0::numeric cost_usd
|
,0::numeric cost_usd
|
||||||
,o.calc_status --0
|
,o.calc_status --0
|
||||||
,o.flag --0
|
,o.flag --0
|
||||||
,o.order_date --history date mix
|
,o.order_date --history date mix
|
||||||
,o.order_month
|
,o.order_month
|
||||||
,o.order_season
|
,o.order_season
|
||||||
@ -560,7 +560,7 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
collapse o
|
collapse o
|
||||||
--need to join to itemm to get the product from osm_pool
|
--need to join to itemm to get the product from osm_pool
|
||||||
--,fcp a
|
--,fcp a
|
||||||
,pivot a
|
,pivot a
|
||||||
--,log
|
--,log
|
||||||
WHERE
|
WHERE
|
||||||
|
824
package-lock.json
generated
824
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -9,8 +9,8 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^6.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"pg": "^8.9.0"
|
"pg": "^7.18.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ target AS (select $$replace_request$$::json def)
|
|||||||
SELECT
|
SELECT
|
||||||
LTRIM(RTRIM(A9)) AS COMP,
|
LTRIM(RTRIM(A9)) AS COMP,
|
||||||
A30 AS DESCR,
|
A30 AS DESCR,
|
||||||
SUBSTR(C.A249,242,2) CURR,
|
SUBSTR(C.A249,242,2) CURR,
|
||||||
SUBSTR(C.A249,32,4) AS GL,
|
SUBSTR(C.A249,32,4) AS GL,
|
||||||
SUBSTR(C.A249,190,4) AS AR,
|
SUBSTR(C.A249,190,4) AS AR,
|
||||||
SUBSTR(C.A249,182,4) AS AP,
|
SUBSTR(C.A249,182,4) AS AP,
|
||||||
@ -206,7 +206,7 @@ target AS (select $$replace_request$$::json def)
|
|||||||
FROM
|
FROM
|
||||||
mmix
|
mmix
|
||||||
)
|
)
|
||||||
--select * from mmixp
|
--select * from mmixp
|
||||||
--month cross join mix
|
--month cross join mix
|
||||||
,mxm AS (
|
,mxm AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -232,7 +232,7 @@ FROM
|
|||||||
FROM
|
FROM
|
||||||
mmixp
|
mmixp
|
||||||
ORDER BY
|
ORDER BY
|
||||||
abs(seq - t.s) ASC
|
abs(seq - t.s) ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -290,7 +290,7 @@ SELECT
|
|||||||
,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director
|
,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director
|
||||||
,COALESCE(CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END,b.bill_cust_descr) billto_group
|
,COALESCE(CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END,b.bill_cust_descr) billto_group
|
||||||
,COALESCE(CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE sc.BVADR6 END,b.ship_cust_descr) shipto_group
|
,COALESCE(CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE sc.BVADR6 END,b.ship_cust_descr) shipto_group
|
||||||
,CASE SUBSTRING(bc.bvclas,2,3)
|
,CASE SUBSTRING(bc.bvclas,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
|
||||||
WHEN 'DIS' THEN
|
WHEN 'DIS' THEN
|
||||||
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
||||||
@ -302,7 +302,7 @@ SELECT
|
|||||||
--everything else does not involve a distributor and is considered direct
|
--everything else does not involve a distributor and is considered direct
|
||||||
ELSE 'DIR'
|
ELSE 'DIR'
|
||||||
END chan
|
END chan
|
||||||
,CASE SUBSTRING(bc.bvclas,2,3)
|
,CASE SUBSTRING(bc.bvclas,2,3)
|
||||||
WHEN 'DIS' THEN
|
WHEN 'DIS' THEN
|
||||||
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
||||||
CASE SUBSTRING(sc.bvclas,2,3)
|
CASE SUBSTRING(sc.bvclas,2,3)
|
||||||
@ -329,7 +329,7 @@ SELECT
|
|||||||
,rx.rate r_rate --master data
|
,rx.rate r_rate --master data
|
||||||
,copr.curr c_currency --master data
|
,copr.curr c_currency --master data
|
||||||
,cx.rate c_rate --master data
|
,cx.rate c_rate --master data
|
||||||
,round(b.units ,2) units
|
,round(b.units ,2) units
|
||||||
,round(b.value_usd / COALESCE(rx.rate,1) ,2) value_loc --b.value is denominated in USD, need to apply currency to get to local, assume 1 if using a fake customer
|
,round(b.value_usd / COALESCE(rx.rate,1) ,2) value_loc --b.value is denominated in USD, need to apply currency to get to local, assume 1 if using a fake customer
|
||||||
,round(b.value_usd ,2) value_usd --b.value is already denominated in usd
|
,round(b.value_usd ,2) value_usd --b.value is already denominated in usd
|
||||||
,round(COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units ,2) cost_loc
|
,round(COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units ,2) cost_loc
|
||||||
@ -354,7 +354,7 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
basemix b
|
basemix b
|
||||||
CROSS JOIN log
|
CROSS JOIN log
|
||||||
LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
|
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||||
i.item = b.part
|
i.item = b.part
|
||||||
LEFT OUTER JOIN SEG ON
|
LEFT OUTER JOIN SEG ON
|
||||||
SEG.GLEC = i.glec
|
SEG.GLEC = i.glec
|
||||||
@ -364,7 +364,7 @@ FROM
|
|||||||
LEFT OUTER JOIN LGDAT.CUST SC ON
|
LEFT OUTER JOIN LGDAT.CUST SC ON
|
||||||
SC.BVCUST = rtrim(substring(b.ship_cust_descr,1,8))
|
SC.BVCUST = rtrim(substring(b.ship_cust_descr,1,8))
|
||||||
LEFT OUTER JOIN REPC ON
|
LEFT OUTER JOIN REPC ON
|
||||||
REPC.RCODE = RTRIM(
|
REPC.RCODE = RTRIM(
|
||||||
--retail items go to currep, or if null go to 90005
|
--retail items go to currep, or if null go to 90005
|
||||||
CASE WHEN i.glec IN ('1RE','1CU') THEN
|
CASE WHEN i.glec IN ('1RE','1CU') THEN
|
||||||
CASE WHEN bc.bvctry = 'CAN' THEN
|
CASE WHEN bc.bvctry = 'CAN' THEN
|
||||||
@ -397,11 +397,11 @@ FROM
|
|||||||
END
|
END
|
||||||
--minor group b52 goes to dedicated rep
|
--minor group b52 goes to dedicated rep
|
||||||
ELSE
|
ELSE
|
||||||
CASE WHEN i.MING = 'B52' THEN
|
CASE WHEN i.MING = 'B52' THEN
|
||||||
'PW'
|
'PW'
|
||||||
--gdir, ndir go to bill-to rep
|
--gdir, ndir go to bill-to rep
|
||||||
ELSE
|
ELSE
|
||||||
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
|
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
|
||||||
bc.bvsalm
|
bc.bvsalm
|
||||||
ELSE
|
ELSE
|
||||||
sc.bvsalm
|
sc.bvsalm
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
--\timing
|
--\timing
|
||||||
--explain (analyze, buffers)
|
--explain (analyze, buffers)
|
||||||
WITH
|
WITH
|
||||||
mseq AS (
|
mseq AS (
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
(
|
(
|
||||||
VALUES
|
VALUES
|
||||||
('01 - Jun',1)
|
('01 - Jun',1)
|
||||||
@ -36,7 +36,7 @@ FROM
|
|||||||
rlarp.osm_pool
|
rlarp.osm_pool
|
||||||
WHERE
|
WHERE
|
||||||
where_clause
|
where_clause
|
||||||
AND order_season IN (2023,2024)
|
AND order_season IN (2021,2022)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
order_season
|
order_season
|
||||||
,order_month
|
,order_month
|
||||||
@ -67,7 +67,7 @@ GROUP BY
|
|||||||
,CASE WHEN sum(value_usd) over () = 0 THEN 0 ELSE value_usd/sum(value_usd) over () END mix
|
,CASE WHEN sum(value_usd) over () = 0 THEN 0 ELSE value_usd/sum(value_usd) over () END mix
|
||||||
FROM
|
FROM
|
||||||
basket1
|
basket1
|
||||||
ORDER BY
|
ORDER BY
|
||||||
mix DESC
|
mix DESC
|
||||||
)
|
)
|
||||||
,months AS (
|
,months AS (
|
||||||
@ -94,14 +94,14 @@ GROUP BY
|
|||||||
SELECT
|
SELECT
|
||||||
order_month
|
order_month
|
||||||
,seq
|
,seq
|
||||||
,SUM(units) FILTER (WHERE order_season = 2023) "2023 qty"
|
,SUM(units) FILTER (WHERE order_season = 2021) "2021 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 = 2022 AND iter IN ('copy','short ship','bad_ship','plan')) "2022 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 = 2022 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2022 adj qty"
|
||||||
,SUM(units) FILTER (WHERE order_season = 2024) "2024 tot qty"
|
,SUM(units) FILTER (WHERE order_season = 2022) "2022 tot qty"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2023) "2023 value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2021) "2021 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 = 2022 AND iter IN ('copy','short ship','bad_ship','plan')) "2022 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 = 2022 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2022 adj value_usd"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2024) "2024 tot value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2022) "2022 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
|
||||||
,"2023 qty"
|
,"2021 qty"
|
||||||
,"2024 base qty"
|
,"2022 base qty"
|
||||||
,"2024 adj qty"
|
,"2022 adj qty"
|
||||||
,"2024 tot qty"
|
,"2022 tot qty"
|
||||||
,"2023 value_usd"
|
,"2021 value_usd"
|
||||||
,"2024 base value_usd"
|
,"2022 base value_usd"
|
||||||
,"2024 adj value_usd"
|
,"2022 adj value_usd"
|
||||||
,"2024 tot value_usd"
|
,"2022 tot value_usd"
|
||||||
FROM
|
FROM
|
||||||
mseq
|
mseq
|
||||||
LEFT OUTER JOIN mpvt ON
|
LEFT OUTER JOIN mpvt ON
|
||||||
@ -147,12 +147,12 @@ GROUP BY
|
|||||||
doc->>'tag' tag
|
doc->>'tag' tag
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_log
|
rlarp.osm_log
|
||||||
WHERE
|
WHERE
|
||||||
doc ? 'tag'
|
doc ? 'tag'
|
||||||
AND id <> 1
|
AND id <> 1
|
||||||
UNION
|
UNION
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
(VALUES
|
(VALUES
|
||||||
('price'),
|
('price'),
|
||||||
('volume')
|
('volume')
|
||||||
) x(tag)
|
) x(tag)
|
||||||
@ -168,7 +168,7 @@ GROUP BY
|
|||||||
bill_cust_descr
|
bill_cust_descr
|
||||||
,ship_cust_descr
|
,ship_cust_descr
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'months'
|
'months'
|
||||||
,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months)
|
,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months)
|
||||||
|
@ -11,7 +11,7 @@ target AS (select 'replace_new_mold' new_mold)
|
|||||||
SUM(value_usd) value_usd
|
SUM(value_usd) value_usd
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_pool o
|
rlarp.osm_pool o
|
||||||
LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
|
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||||
i.item = o.part
|
i.item = o.part
|
||||||
WHERE
|
WHERE
|
||||||
-----------------scenario----------------------------
|
-----------------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
|
CASE WHEN substring(b.part,9,12) = substring(i.item,9,12) THEN '1' ELSE 0 END fit
|
||||||
FROM
|
FROM
|
||||||
basemix b
|
basemix b
|
||||||
LEFT OUTER JOIN "CMS.CUSLG".itemm i ON
|
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||||
i.stlc = (SELECT new_mold FROM target WHERE new_mold <> '')
|
i.stlc = (SELECT new_mold FROM target WHERE new_mold <> '')
|
||||||
AND CASE WHEN b.sizc = i.sizc THEN '1' ELSE '0' END||
|
AND CASE WHEN b.sizc = i.sizc THEN '1' ELSE '0' END||
|
||||||
CASE WHEN i.aplnt = 'I' THEN '0' ELSE '1' END||
|
CASE WHEN i.aplnt = 'I' THEN '0' ELSE '1' END||
|
||||||
@ -55,7 +55,7 @@ target AS (select 'replace_new_mold' new_mold)
|
|||||||
CASE WHEN b.colc = i.colc THEN '1' ELSE '0' END||
|
CASE WHEN b.colc = i.colc THEN '1' ELSE '0' END||
|
||||||
CASE WHEN substring(b.part,9,12) = substring(i.item,9,12) THEN '1' ELSE 0 END >= '111110'
|
CASE WHEN substring(b.part,9,12) = substring(i.item,9,12) THEN '1' ELSE 0 END >= '111110'
|
||||||
)
|
)
|
||||||
--SELECT * FROM tag
|
--SELECT * FROM tag
|
||||||
,rsort AS (
|
,rsort AS (
|
||||||
SELECT
|
SELECT
|
||||||
part,
|
part,
|
||||||
@ -63,9 +63,9 @@ SELECT
|
|||||||
item swap,
|
item swap,
|
||||||
fit,
|
fit,
|
||||||
ROW_NUMBER() OVER (PARTITION BY tag.part ORDER BY fit DESC) ranked
|
ROW_NUMBER() OVER (PARTITION BY tag.part ORDER BY fit DESC) ranked
|
||||||
FROM
|
FROM
|
||||||
tag
|
tag
|
||||||
ORDER BY
|
ORDER BY
|
||||||
part
|
part
|
||||||
,fit desc
|
,fit desc
|
||||||
)
|
)
|
||||||
@ -74,4 +74,4 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
rsort
|
rsort
|
||||||
WHERE
|
WHERE
|
||||||
ranked = 1
|
ranked = 1
|
@ -44,17 +44,17 @@ target AS (SELECT $$swap_doc$$::jsonb swap)
|
|||||||
,remove AS (
|
,remove AS (
|
||||||
SELECT
|
SELECT
|
||||||
fspr
|
fspr
|
||||||
,plnt ---master data
|
,plnt ---master data
|
||||||
,promo --history date mix
|
,promo --history date mix
|
||||||
,terms
|
,terms
|
||||||
,bill_cust_descr --history cust mix
|
,bill_cust_descr --history cust mix
|
||||||
,ship_cust_descr --history cust mix
|
,ship_cust_descr --history cust mix
|
||||||
,dsm
|
,dsm
|
||||||
,quota_rep_descr --master data
|
,quota_rep_descr --master data
|
||||||
,director
|
,director
|
||||||
,billto_group --master data
|
,billto_group --master data
|
||||||
,shipto_group
|
,shipto_group
|
||||||
,chan --master data
|
,chan --master data
|
||||||
,chansub
|
,chansub
|
||||||
,chan_retail
|
,chan_retail
|
||||||
,part
|
,part
|
||||||
@ -67,18 +67,18 @@ target AS (SELECT $$swap_doc$$::jsonb swap)
|
|||||||
,mins_descr
|
,mins_descr
|
||||||
,segm
|
,segm
|
||||||
,substance
|
,substance
|
||||||
,fs_line --master data
|
,fs_line --master data
|
||||||
,r_currency --history cust mix
|
,r_currency --history cust mix
|
||||||
,r_rate --master data
|
,r_rate --master data
|
||||||
,c_currency --master data
|
,c_currency --master data
|
||||||
,c_rate --master data
|
,c_rate --master data
|
||||||
,-units units
|
,-units units
|
||||||
,-value_loc value_loc
|
,-value_loc value_loc
|
||||||
,-value_usd value_usd
|
,-value_usd value_usd
|
||||||
,-cost_loc cost_loc
|
,-cost_loc cost_loc
|
||||||
,-cost_usd cost_usd
|
,-cost_usd cost_usd
|
||||||
,calc_status --0
|
,calc_status --0
|
||||||
,flag --0
|
,flag --0
|
||||||
,order_date --history date mix
|
,order_date --history date mix
|
||||||
,order_month
|
,order_month
|
||||||
,order_season
|
,order_season
|
||||||
@ -160,13 +160,13 @@ target AS (SELECT $$swap_doc$$::jsonb swap)
|
|||||||
remove o
|
remove o
|
||||||
INNER JOIN pl ON
|
INNER JOIN pl ON
|
||||||
pl.original = o.part
|
pl.original = o.part
|
||||||
INNER JOIN "CMS.CUSLG".itemm m ON
|
INNER JOIN rlarp.itemmv m ON
|
||||||
m.item = pl.replace
|
m.item = pl.replace
|
||||||
LEFT OUTER JOIN rlarp.icstx c ON
|
LEFT OUTER JOIN rlarp.icstx c ON
|
||||||
c.part = pl.replace
|
c.part = pl.replace
|
||||||
AND c.plnt = m.dplt
|
AND c.plnt = m.dplt
|
||||||
LEFT OUTER JOIN rlarp.plpr r ON
|
LEFT OUTER JOIN rlarp.plpr r ON
|
||||||
r.plnt = m.dplt
|
yaplnt = m.dplt
|
||||||
LEFT OUTER JOIN rlarp.ffcret x ON
|
LEFT OUTER JOIN rlarp.ffcret x ON
|
||||||
x.fcur = r.curr
|
x.fcur = r.curr
|
||||||
AND x.tcur = 'US'
|
AND x.tcur = 'US'
|
||||||
|
Loading…
Reference in New Issue
Block a user