Switch source table from rlarp.itemmv to "CMS.CUSLG".itemm
This commit is contained in:
parent
59cb926d9c
commit
ed5975daf7
@ -1,10 +1,11 @@
|
|||||||
|
-- Connection: usmidsap01.ubm
|
||||||
--\timing
|
--\timing
|
||||||
TRUNCATE TABLE rlarp.osmf;
|
TRUNCATE TABLE rlarp.osmf;
|
||||||
|
|
||||||
INSERT INTO rlarp.osmf
|
INSERT INTO rlarp.osmf
|
||||||
WITH
|
WITH
|
||||||
gld AS (
|
gld AS (
|
||||||
SELECT
|
SELECT
|
||||||
N1COMP COMP
|
N1COMP COMP
|
||||||
,N1CCYY FSYR
|
,N1CCYY FSYR
|
||||||
,KPMAXP PERDS
|
,KPMAXP PERDS
|
||||||
@ -13,13 +14,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
|
||||||
@ -286,7 +287,7 @@ 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.pdate + interval '1 year' pdate
|
||||||
@ -434,7 +435,7 @@ 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.pdate pdate
|
||||||
@ -479,7 +480,7 @@ gld AS (
|
|||||||
,ss.ssyr
|
,ss.ssyr
|
||||||
)
|
)
|
||||||
,incr AS (
|
,incr AS (
|
||||||
SELECT
|
SELECT
|
||||||
o."ddord#"
|
o."ddord#"
|
||||||
,o."dditm#"
|
,o."dditm#"
|
||||||
,o."fgbol#"
|
,o."fgbol#"
|
||||||
@ -540,10 +541,10 @@ SELECT
|
|||||||
,o.coltier
|
,o.coltier
|
||||||
,o.colstat
|
,o.colstat
|
||||||
,o.sizc
|
,o.sizc
|
||||||
,o.uomp
|
,o.uomp
|
||||||
,o.suffix
|
,o.suffix
|
||||||
,o.accs_ps
|
,o.accs_ps
|
||||||
,o.brnd
|
,o.brnd
|
||||||
,o.majg
|
,o.majg
|
||||||
,o.ming
|
,o.ming
|
||||||
,o.majs
|
,o.majs
|
||||||
@ -586,7 +587,7 @@ SELECT
|
|||||||
,o.sseas + 1 --incremented
|
,o.sseas + 1 --incremented
|
||||||
,'b22' "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
|
||||||
@ -661,11 +662,11 @@ SELECT
|
|||||||
,colgrp
|
,colgrp
|
||||||
,coltier
|
,coltier
|
||||||
,colstat
|
,colstat
|
||||||
,sizc
|
,sizc
|
||||||
,uomp
|
,uomp
|
||||||
,suffix
|
,suffix
|
||||||
,accs_ps
|
,accs_ps
|
||||||
,brnd
|
,brnd
|
||||||
,majg
|
,majg
|
||||||
,ming
|
,ming
|
||||||
,majs
|
,majs
|
||||||
@ -704,8 +705,8 @@ SELECT
|
|||||||
,oseas
|
,oseas
|
||||||
,rdate
|
,rdate
|
||||||
,rseas
|
,rseas
|
||||||
,pdate
|
,pdate
|
||||||
,pseas
|
,pseas
|
||||||
,sdate
|
,sdate
|
||||||
,sseas
|
,sseas
|
||||||
,"version"
|
,"version"
|
||||||
|
@ -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 rlarp.itemmv i ON
|
LEFT OUTER JOIN "CMS.CUSLG".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
|
||||||
|
@ -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 rlarp.itemmv i ON
|
INNER JOIN "CMS.CUSLG".itemm 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
|
||||||
,rlarp.itemmv i
|
,"CMS.CUSLG".itemm 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
|
||||||
,rlarp.itemmv i
|
,"CMS.CUSLG".itemm 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
|
||||||
|
@ -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 rlarp.itemmv i ON
|
LEFT OUTER JOIN "CMS.CUSLG".itemm 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
|
||||||
|
@ -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 rlarp.itemmv i ON
|
LEFT OUTER JOIN "CMS.CUSLG".itemm 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 rlarp.itemmv i ON
|
LEFT OUTER JOIN "CMS.CUSLG".itemm 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 rlarp.itemmv m ON
|
INNER JOIN "CMS.CUSLG".itemm 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
|
||||||
yaplnt = m.dplt
|
r.plnt = 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