Update some 2022 references to 2024, and fix round() function calls.
This commit is contained in:
parent
bbac2ec390
commit
480adef789
@ -1,4 +1,4 @@
|
|||||||
WITH
|
WITH
|
||||||
/*
|
/*
|
||||||
the volume must be expressed in terms of units, since that is what it will be scaling
|
the volume must be expressed in terms of units, since that is what it will be scaling
|
||||||
*/
|
*/
|
||||||
@ -55,7 +55,7 @@ target AS (select target_volume vincr, target_price pincr)
|
|||||||
testv
|
testv
|
||||||
)
|
)
|
||||||
,GLD AS MATERIALIZED (
|
,GLD AS MATERIALIZED (
|
||||||
SELECT
|
SELECT
|
||||||
N1COMP COMP
|
N1COMP COMP
|
||||||
,N1CCYY FSYR
|
,N1CCYY FSYR
|
||||||
,KPMAXP PERDS
|
,KPMAXP PERDS
|
||||||
@ -65,19 +65,19 @@ target AS (select target_volume vincr, target_price pincr)
|
|||||||
,N1ED01 EDAT
|
,N1ED01 EDAT
|
||||||
,daterange(n1sd01, n1ed01,'[]') drange
|
,daterange(n1sd01, n1ed01,'[]') drange
|
||||||
,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,'FM00') SSPR
|
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'FM00') 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
|
||||||
)
|
)
|
||||||
,mseq AS (
|
,mseq AS (
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
(
|
(
|
||||||
VALUES
|
VALUES
|
||||||
('01 - Jun',1,6,-1)
|
('01 - Jun',1,6,-1)
|
||||||
@ -95,7 +95,7 @@ target AS (select target_volume vincr, target_price pincr)
|
|||||||
) x(m,s,cal,yr)
|
) x(m,s,cal,yr)
|
||||||
)
|
)
|
||||||
,alldates AS MATERIALIZED(
|
,alldates AS MATERIALIZED(
|
||||||
SELECT
|
SELECT
|
||||||
promo
|
promo
|
||||||
,terms
|
,terms
|
||||||
,order_month
|
,order_month
|
||||||
@ -112,7 +112,7 @@ target AS (select target_volume vincr, target_price pincr)
|
|||||||
-----------------scenario----------------------------
|
-----------------scenario----------------------------
|
||||||
where_clause
|
where_clause
|
||||||
-----------------additional params-------------------
|
-----------------additional params-------------------
|
||||||
AND CASE (SELECT flag FROM flagv)
|
AND CASE (SELECT flag FROM flagv)
|
||||||
WHEN 'scale all' THEN true
|
WHEN 'scale all' THEN true
|
||||||
WHEN 'scale copy' THEN iter IN ('plan','diff','copy')
|
WHEN 'scale copy' THEN iter IN ('plan','diff','copy')
|
||||||
WHEN 'scale new part' THEN module = 'new basket'
|
WHEN 'scale new part' THEN module = 'new basket'
|
||||||
@ -177,13 +177,13 @@ target AS (select target_volume vincr, target_price pincr)
|
|||||||
mmix
|
mmix
|
||||||
)
|
)
|
||||||
,closest AS (
|
,closest AS (
|
||||||
SELECT
|
SELECT
|
||||||
_month, targm.s, m
|
_month, targm.s, m
|
||||||
FROM
|
FROM
|
||||||
mmixp
|
mmixp
|
||||||
CROSS JOIN targm
|
CROSS JOIN targm
|
||||||
ORDER BY
|
ORDER BY
|
||||||
abs(seq - targm.s) ASC
|
abs(seq - targm.s) ASC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
)
|
)
|
||||||
---------------------the role of basemix here is to get non-dated info which is then dated in the next step---------------------
|
---------------------the role of basemix here is to get non-dated info which is then dated in the next step---------------------
|
||||||
@ -234,7 +234,7 @@ SELECT
|
|||||||
-----------------scenario----------------------------
|
-----------------scenario----------------------------
|
||||||
where_clause
|
where_clause
|
||||||
-----------------additional params-------------------
|
-----------------additional params-------------------
|
||||||
AND CASE (SELECT flag FROM flagv)
|
AND CASE (SELECT flag FROM flagv)
|
||||||
WHEN 'scale all' THEN true
|
WHEN 'scale all' THEN true
|
||||||
WHEN 'scale copy' THEN iter IN ('plan','diff','copy')
|
WHEN 'scale copy' THEN iter IN ('plan','diff','copy')
|
||||||
WHEN 'scale new part' THEN module = 'new basket'
|
WHEN 'scale new part' THEN module = 'new basket'
|
||||||
@ -323,15 +323,15 @@ SELECT
|
|||||||
,round(b.cost_usd*s.factor*m.momix ,2) cost_usd
|
,round(b.cost_usd*s.factor*m.momix ,2) cost_usd
|
||||||
,b.calc_status
|
,b.calc_status
|
||||||
,b.flag
|
,b.flag
|
||||||
,make_date(mseq.yr + 2022,mseq.cal,m.odom) order_date
|
,make_date(mseq.yr + 2024,mseq.cal,m.odom) order_date
|
||||||
,od.sspr || ' - ' || to_char(make_date(mseq.yr + 2022,mseq.cal,m.odom),'Mon') order_month
|
,od.sspr || ' - ' || to_char(make_date(mseq.yr + 2024,mseq.cal,m.odom),'Mon') order_month
|
||||||
,od.ssyr order_season
|
,od.ssyr order_season
|
||||||
,make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag request_date
|
,make_date(mseq.yr + 2024,mseq.cal,m.odom) + rlag request_date
|
||||||
,rd.sspr || ' - ' ||to_char(make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag,'Mon') request_month
|
,rd.sspr || ' - ' ||to_char(make_date(mseq.yr + 2024,mseq.cal,m.odom) + rlag,'Mon') request_month
|
||||||
,rd.ssyr request_season
|
,rd.ssyr request_season
|
||||||
,make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag + slag ship_date
|
,make_date(mseq.yr + 2024,mseq.cal,m.odom) + rlag + slag ship_date
|
||||||
,sd.sspr || ' - ' || to_char(make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
|
,sd.sspr || ' - ' || to_char(make_date(mseq.yr + 2024,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
|
||||||
,sd.ssyr ship_season
|
,sd.ssyr ship_season
|
||||||
,'replace_version' "version"
|
,'replace_version' "version"
|
||||||
,'replace_source'||' volume' iter
|
,'replace_source'||' volume' iter
|
||||||
,log.id
|
,log.id
|
||||||
@ -347,11 +347,11 @@ FROM
|
|||||||
LEFT OUTER JOIN mseq ON
|
LEFT OUTER JOIN mseq ON
|
||||||
mseq.m = closest.m
|
mseq.m = closest.m
|
||||||
LEFT OUTER JOIN gld od ON
|
LEFT OUTER JOIN gld od ON
|
||||||
make_date(mseq.yr + 2022,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
|
make_date(mseq.yr + 2024,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
|
||||||
LEFT OUTER JOIN gld rd ON
|
LEFT OUTER JOIN gld rd ON
|
||||||
make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
make_date(mseq.yr + 2024,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
||||||
LEFT OUTER JOIN gld sd ON
|
LEFT OUTER JOIN gld sd ON
|
||||||
make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
make_date(mseq.yr + 2024,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
||||||
WHERE
|
WHERE
|
||||||
m._month = (SELECT _month FROM closest)
|
m._month = (SELECT _month FROM closest)
|
||||||
)
|
)
|
||||||
@ -362,7 +362,7 @@ WHERE
|
|||||||
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
|
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
|
||||||
0
|
0
|
||||||
ELSE
|
ELSE
|
||||||
((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(value_loc * r_rate) FROM volume)
|
((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(value_loc * r_rate) FROM volume)
|
||||||
END factor
|
END factor
|
||||||
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
|
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
|
||||||
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume)) <> 0 THEN
|
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume)) <> 0 THEN
|
||||||
@ -421,7 +421,7 @@ SELECT
|
|||||||
,b.request_season
|
,b.request_season
|
||||||
,b.ship_date
|
,b.ship_date
|
||||||
,b.ship_month
|
,b.ship_month
|
||||||
,b.ship_season
|
,b.ship_season
|
||||||
,'replace_version' "version"
|
,'replace_version' "version"
|
||||||
,'replace_source'||' price' iter
|
,'replace_source'||' price' iter
|
||||||
,log.id
|
,log.id
|
||||||
|
@ -19,13 +19,13 @@ FROM
|
|||||||
LEFT OUTER JOIN rlarp.osm_log ON
|
LEFT OUTER JOIN rlarp.osm_log ON
|
||||||
id = logid
|
id = logid
|
||||||
WHERE
|
WHERE
|
||||||
order_season = 2022
|
order_season = 2024
|
||||||
GROUP BY
|
GROUP BY
|
||||||
director
|
director
|
||||||
,quota_rep_descr
|
,quota_rep_descr
|
||||||
,part
|
,part
|
||||||
,bill_cust_descr
|
,bill_cust_descr
|
||||||
,ship_cust_descr
|
,ship_cust_descr
|
||||||
,order_month
|
,order_month
|
||||||
,doc->>'stamp'
|
,doc->>'stamp'
|
||||||
,logid
|
,logid
|
||||||
@ -43,7 +43,7 @@ SELECT
|
|||||||
,(max(stamp) FILTER (WHERE tag <> 'Initial Build'))::timestamptz "last edit"
|
,(max(stamp) FILTER (WHERE tag <> 'Initial Build'))::timestamptz "last edit"
|
||||||
FROM
|
FROM
|
||||||
preagg
|
preagg
|
||||||
GROUP BY
|
GROUP BY
|
||||||
GROUPING SETS (
|
GROUPING SETS (
|
||||||
(director,quota_rep_descr),
|
(director,quota_rep_descr),
|
||||||
(director),
|
(director),
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
-- Connection: usmidsap01.ubm
|
||||||
WITH
|
WITH
|
||||||
/*
|
/*
|
||||||
the volume must be expressed in terms of units, since that is what it will be scaling
|
the volume must be expressed in terms of units, since that is what it will be scaling
|
||||||
@ -251,13 +252,13 @@ SELECT
|
|||||||
,substring(jr.part_descr,1,8) part_group
|
,substring(jr.part_descr,1,8) part_group
|
||||||
,mxm.qty*mxm.momix*jr.mix units
|
,mxm.qty*mxm.momix*jr.mix units
|
||||||
,mxm.amount*mxm.momix*jr.mix value_usd --assume that target dollars are USD
|
,mxm.amount*mxm.momix*jr.mix value_usd --assume that target dollars are USD
|
||||||
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) order_date
|
,make_date(mxm.yr + 2024,mxm.cal,mxm.odom) order_date
|
||||||
,od.sortmo order_month
|
,od.sortmo order_month
|
||||||
,od.ssyr order_season
|
,od.ssyr order_season
|
||||||
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag request_date
|
,make_date(mxm.yr + 2024,mxm.cal,mxm.odom) + rlag request_date
|
||||||
,rd.sortmo request_month
|
,rd.sortmo request_month
|
||||||
,rd.ssyr request_season
|
,rd.ssyr request_season
|
||||||
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag + slag ship_date
|
,make_date(mxm.yr + 2024,mxm.cal,mxm.odom) + rlag + slag ship_date
|
||||||
,sd.sortmo ship_month
|
,sd.sortmo ship_month
|
||||||
,sd.ssyr ship_season
|
,sd.ssyr ship_season
|
||||||
,jr.mix
|
,jr.mix
|
||||||
@ -267,11 +268,11 @@ SELECT
|
|||||||
JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true
|
JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true
|
||||||
CROSS JOIN mxm
|
CROSS JOIN mxm
|
||||||
LEFT OUTER JOIN gld od ON
|
LEFT OUTER JOIN gld od ON
|
||||||
od.drange @> make_date(mxm.yr + 2022,mxm.cal,mxm.odom)
|
od.drange @> make_date(mxm.yr + 2024,mxm.cal,mxm.odom)
|
||||||
LEFT OUTER JOIN gld rd ON
|
LEFT OUTER JOIN gld rd ON
|
||||||
rd.drange @> (make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag)
|
rd.drange @> (make_date(mxm.yr + 2024,mxm.cal,mxm.odom) + rlag)
|
||||||
LEFT OUTER JOIN gld sd ON
|
LEFT OUTER JOIN gld sd ON
|
||||||
sd.drange @> (make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag + slag)
|
sd.drange @> (make_date(mxm.yr + 2024,mxm.cal,mxm.odom) + rlag + slag)
|
||||||
)
|
)
|
||||||
--SELECT * FROM basemix
|
--SELECT * FROM basemix
|
||||||
,log AS (
|
,log AS (
|
||||||
@ -329,11 +330,11 @@ 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))::numeric ,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)::numeric ,2) cost_loc
|
||||||
,round(COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate,2) cost_usd
|
,round((COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate)::numeric,2) cost_usd
|
||||||
,'CLOSED' calc_status
|
,'CLOSED' calc_status
|
||||||
,'SHIPMENT' flag
|
,'SHIPMENT' flag
|
||||||
,b.order_date
|
,b.order_date
|
||||||
@ -423,13 +424,13 @@ FROM
|
|||||||
LEFT OUTER JOIN copr ON
|
LEFT OUTER JOIN copr ON
|
||||||
copr.comp = yacomp::text
|
copr.comp = yacomp::text
|
||||||
LEFT OUTER JOIN rlarp.ffcret cx ON
|
LEFT OUTER JOIN rlarp.ffcret cx ON
|
||||||
cx.perd = '2101'
|
cx.perd = '2310'
|
||||||
AND cx.rtyp = 'BG'
|
AND cx.rtyp = 'MA'
|
||||||
AND cx.fcur = copr.curr
|
AND cx.fcur = copr.curr
|
||||||
AND cx.tcur = 'US'
|
AND cx.tcur = 'US'
|
||||||
LEFT OUTER JOIN rlarp.ffcret rx ON
|
LEFT OUTER JOIN rlarp.ffcret rx ON
|
||||||
rx.perd = '2101'
|
rx.perd = '2310'
|
||||||
AND rx.rtyp = 'BG'
|
AND rx.rtyp = 'MA'
|
||||||
AND rx.fcur = COALESCE(bc.bvcurr,b.r_currency)
|
AND rx.fcur = COALESCE(bc.bvcurr,b.r_currency)
|
||||||
AND rx.tcur = 'US'
|
AND rx.tcur = 'US'
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
WITH
|
WITH
|
||||||
target AS (select target_vol vincr, target_prc pincr)
|
target AS (select target_vol vincr, target_prc pincr)
|
||||||
,testv AS (
|
,testv AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -39,17 +39,17 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,basemix AS (
|
,basemix 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
|
||||||
@ -62,18 +62,18 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,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
|
||||||
,sum(coalesce(units,0)) units --history value
|
,sum(coalesce(units,0)) units --history value
|
||||||
,sum(coalesce(value_loc,0)) value_loc --history value
|
,sum(coalesce(value_loc,0)) value_loc --history value
|
||||||
,sum(coalesce(value_usd,0)) value_usd --0
|
,sum(coalesce(value_usd,0)) value_usd --0
|
||||||
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
|
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
|
||||||
,sum(coalesce(cost_usd,0)) cost_usd
|
,sum(coalesce(cost_usd,0)) 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
|
||||||
@ -88,9 +88,9 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
WHERE
|
WHERE
|
||||||
-----------------scenario----------------------------
|
-----------------scenario----------------------------
|
||||||
where_clause
|
where_clause
|
||||||
AND ship_season = 2022
|
AND ship_season = 2024
|
||||||
-----------------additional params-------------------
|
-----------------additional params-------------------
|
||||||
AND CASE (SELECT flag FROM flagv)
|
AND CASE (SELECT flag FROM flagv)
|
||||||
WHEN 'scale all' THEN true
|
WHEN 'scale all' THEN true
|
||||||
WHEN 'scale copy' THEN iter IN ('plan','diff','copy')
|
WHEN 'scale copy' THEN iter IN ('plan','diff','copy')
|
||||||
WHEN 'scale new part' THEN module = 'new basket'
|
WHEN 'scale new part' THEN module = 'new basket'
|
||||||
@ -99,17 +99,17 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
AND order_date <= ship_date
|
AND order_date <= ship_date
|
||||||
GROUP BY
|
GROUP BY
|
||||||
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
|
||||||
@ -122,13 +122,13 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,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
|
||||||
,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
|
||||||
@ -152,17 +152,17 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,volume AS (
|
,volume 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
|
||||||
@ -175,18 +175,18 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,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
|
||||||
,round(units*s.factor ,2) units
|
,round(units*s.factor ,2) units
|
||||||
,round(value_loc*s.factor,2) value_loc
|
,round(value_loc*s.factor,2) value_loc
|
||||||
,round(value_usd*s.factor,2) value_usd
|
,round(value_usd*s.factor,2) value_usd
|
||||||
,round(cost_loc*s.factor ,2) cost_loc
|
,round(cost_loc*s.factor ,2) cost_loc
|
||||||
,round(cost_usd*s.factor ,2) cost_usd
|
,round(cost_usd*s.factor ,2) 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
|
||||||
@ -233,17 +233,17 @@ FROM
|
|||||||
,pricing AS (
|
,pricing 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
|
||||||
@ -256,18 +256,18 @@ FROM
|
|||||||
,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
|
||||||
,0::numeric units
|
,0::numeric units
|
||||||
,round((CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric,2) value_loc
|
,round((CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric,2) value_loc
|
||||||
,round((CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric ,2) value_usd
|
,round((CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric ,2) value_usd
|
||||||
,0::numeric cost_loc
|
,0::numeric cost_loc
|
||||||
,0::numeric cost_usd
|
,0::numeric 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
|
||||||
|
@ -37,7 +37,7 @@ FROM
|
|||||||
WHERE
|
WHERE
|
||||||
where_clause
|
where_clause
|
||||||
--quota_rep_descr = 'MATTHEW STAAL'
|
--quota_rep_descr = 'MATTHEW STAAL'
|
||||||
AND order_season IN (2019,2024)
|
AND order_season IN (2023,2024)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
order_season
|
order_season
|
||||||
,order_month
|
,order_month
|
||||||
@ -95,11 +95,11 @@ GROUP BY
|
|||||||
SELECT
|
SELECT
|
||||||
order_month
|
order_month
|
||||||
,seq
|
,seq
|
||||||
,SUM(units) FILTER (WHERE order_season = 2019) "2023 qty"
|
,SUM(units) FILTER (WHERE order_season = 2023) "2023 qty"
|
||||||
,SUM(units) FILTER (WHERE order_season = 2024 AND iter IN ('copy','short ship','bad_ship','plan')) "2024 base qty"
|
,SUM(units) FILTER (WHERE order_season = 2024 AND iter IN ('copy','short ship','bad_ship','plan')) "2024 base qty"
|
||||||
,SUM(units) FILTER (WHERE order_season = 2024 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2024 adj qty"
|
,SUM(units) FILTER (WHERE order_season = 2024 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2024 adj qty"
|
||||||
,SUM(units) FILTER (WHERE order_season = 2024) "2024 tot qty"
|
,SUM(units) FILTER (WHERE order_season = 2024) "2024 tot qty"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2019) "2023 value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2023) "2023 value_usd"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2024 AND iter IN ('copy','short ship','bad_ship','plan')) "2024 base value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2024 AND iter IN ('copy','short ship','bad_ship','plan')) "2024 base value_usd"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2024 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2024 adj value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2024 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2024 adj value_usd"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2024) "2024 tot value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2024) "2024 tot value_usd"
|
||||||
|
Loading…
Reference in New Issue
Block a user