Compare commits
No commits in common. "f924da0e4d7e0a39a88c7fea9416feaf19e5c505" and "b881fae5b45d8a4c6fc94a975236b129644e783b" have entirely different histories.
f924da0e4d
...
b881fae5b4
17
README.md
17
README.md
@ -8,20 +8,3 @@ Slowness Options
|
||||
* move json to a separate table and the change can be marked with a sequence
|
||||
* have the data actually be a query from the database
|
||||
* reduce number of columns in fc_pool
|
||||
|
||||
Discussion
|
||||
* special look at Mar-Apr sales since it is being copied from plan or older data
|
||||
- [ ] at the end of March, we will swap out the budget from March with actuals and re-forecast
|
||||
- [ ] need to think through how to overlay actuals into the budget
|
||||
* last price paid snap - preload
|
||||
- [ ] dont do this
|
||||
* FX - currently nothing loaded
|
||||
- [ ] we'll pick one (see Bruno)
|
||||
* cost - snap to current cost
|
||||
- [ ] snap to current
|
||||
* need to be able to reload the forecast as we lock in new months of sales data - replay changes over top?
|
||||
* item 1
|
||||
* refresh new part list
|
||||
* add comments on monthly
|
||||
* add a tag that is separate from the comment?
|
||||
* need to test extrapolating osm_pool into osmp_dev
|
37
index.js
37
index.js
@ -80,7 +80,6 @@ server.get('/get_pool', bodyParser.json(), function(req, res) {
|
||||
console.log(new Date().toISOString() + "-------------------------get pool:----------------------------");
|
||||
console.log(req.body.quota_rep);
|
||||
sql = sql.replace("rep_replace", req.body.quota_rep);
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
|
||||
@ -129,7 +128,7 @@ server.get('/scenario_package', bodyParser.json(), function(req, res) {
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w)
|
||||
//execute the sql and send the result
|
||||
console.log(sql);
|
||||
//console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
})
|
||||
@ -165,39 +164,6 @@ server.get('/list_changes', bodyParser.json(), function(req, res) {
|
||||
};
|
||||
})
|
||||
|
||||
server.get('/undo_change', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
var w = "";
|
||||
var c = 1;
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/undo.sql';
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("fatal error pulling sql file")
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
console.log(new Date().toISOString() + "-------------------------undo change:------------------------------")
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("replace_id", 'g'), JSON.stringify(req.body.logid))
|
||||
//execute the sql and send the result
|
||||
console.log(sql);
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
};
|
||||
})
|
||||
|
||||
//deprecating this route, just use _vp for volume and prive
|
||||
/*
|
||||
server.post('/addmonth_v', bodyParser.json(), function(req, res) {
|
||||
|
||||
var sql = "";
|
||||
@ -239,7 +205,6 @@ server.post('/addmonth_v', bodyParser.json(), function(req, res) {
|
||||
Postgres.FirstRow(sql, [], res)
|
||||
}
|
||||
})
|
||||
*/
|
||||
|
||||
server.post('/addmonth_vp', bodyParser.json(), function(req, res) {
|
||||
|
||||
|
20
route_meta/adjust.json
Normal file
20
route_meta/adjust.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"scenario": {
|
||||
"ship_season": 2019,
|
||||
"ship_month": "Mar",
|
||||
"order_season": 2019,
|
||||
"order_month": "Mar",
|
||||
"version": "9p3",
|
||||
"iter": [
|
||||
"forecast"
|
||||
]
|
||||
},
|
||||
"adj_amount": -1248994,
|
||||
"adj_qty": -2828623,
|
||||
"tar_amount": 5335749,
|
||||
"tar_qty": 18623740,
|
||||
"stamp": "2019-03-01 10:00:00",
|
||||
"user": "Trowbridge, Paul",
|
||||
"source": "forecast ui",
|
||||
"type":"scale_v"
|
||||
}
|
@ -9,20 +9,21 @@ WITH
|
||||
target AS (select target_increment incr)
|
||||
,testv AS (
|
||||
SELECT
|
||||
sum(units) tot
|
||||
,sum(units) FILTER (WHERE iter = 'copy') base
|
||||
,COALESCE(sum(units) FILTER (WHERE module = 'new basket'),0) newpart
|
||||
,sum(value_loc *r_rate) totsales
|
||||
,sum(value_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
|
||||
,COALESCE(sum(value_loc *r_rate) FILTER (WHERE module = 'new basket'),0) newpartsales
|
||||
sum(fb_qty) tot
|
||||
,sum(fb_qty) FILTER (WHERE iter = 'copy') base
|
||||
,COALESCE(sum(fb_qty) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpart
|
||||
,sum(fb_val_loc *r_rate) totsales
|
||||
,sum(fb_val_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
|
||||
,COALESCE(sum(fb_val_loc *r_rate) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpartsales
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
rlarp.osm_fcpool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
|
||||
)
|
||||
,flagv AS (
|
||||
SELECT
|
||||
@ -67,7 +68,6 @@ target AS (select target_increment incr)
|
||||
,to_char(N1FSYP,'FM0000') FSPR
|
||||
,N1SD01 SDAT
|
||||
,N1ED01 EDAT
|
||||
,daterange(n1sd01, n1ed01) drange
|
||||
,to_char(N1ED01,'yymm') CAPR
|
||||
,N1ED01 - N1SD01 +1 NDAYS
|
||||
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
|
||||
@ -85,18 +85,18 @@ target AS (select target_increment incr)
|
||||
SELECT * FROM
|
||||
(
|
||||
VALUES
|
||||
('01 - Jun',1,6,-1)
|
||||
,('02 - Jul',2,7,-1)
|
||||
,('03 - Aug',3,8,-1)
|
||||
,('04 - Sep',4,9,-1)
|
||||
,('05 - Oct',5,10,-1)
|
||||
,('06 - Nov',6,11,-1)
|
||||
,('07 - Dec',7,12,-1)
|
||||
,('08 - Jan',8,1,0)
|
||||
,('09 - Feb',9,2,0)
|
||||
,('10 - Mar',10,3,0)
|
||||
,('11 - Apr',11,4,0)
|
||||
,('12 - May',12,5,0)
|
||||
('Jun',1,6,-1)
|
||||
,('Jul',2,7,-1)
|
||||
,('Aug',3,8,-1)
|
||||
,('Sep',4,9,-1)
|
||||
,('Oct',5,10,-1)
|
||||
,('Nov',6,11,-1)
|
||||
,('Dec',7,12,-1)
|
||||
,('Jan',8,1,0)
|
||||
,('Feb',9,2,0)
|
||||
,('Mar',10,3,0)
|
||||
,('Apr',11,4,0)
|
||||
,('May',12,5,0)
|
||||
) x(m,s,cal,yr)
|
||||
)
|
||||
,alldates AS (
|
||||
@ -105,68 +105,68 @@ target AS (select target_increment incr)
|
||||
,terms
|
||||
,order_month
|
||||
,mseq.s seq
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
,sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) value_usd
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
rlarp.osm_fcpool
|
||||
LEFT OUTER JOIN mseq ON
|
||||
mseq.m = order_month
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
-----------------additional params-------------------
|
||||
AND version = 'b21'
|
||||
AND version = 'b20'
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
GROUP BY
|
||||
promo
|
||||
,terms
|
||||
,order_month
|
||||
,mseq.s
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
HAVING
|
||||
sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) <> 0
|
||||
)
|
||||
--select * from alldates
|
||||
,dom AS (
|
||||
SELECT
|
||||
extract(day FROM order_date) dom
|
||||
extract(day FROM orderdate) dom
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
GROUP BY
|
||||
extract(day FROM order_date)
|
||||
extract(day FROM orderdate)
|
||||
)
|
||||
---------------------may want ot look at a top-5 mix solution in the future facilitated by sum() over (order by sales desc)---------------
|
||||
,mmix AS (
|
||||
SELECT
|
||||
to_char(order_date,'Mon') _month
|
||||
to_char(orderdate,'Mon') _month
|
||||
,seq
|
||||
,promo
|
||||
,sum(extract(day from order_date)*value_usd) dom_wa
|
||||
--,request_date-order_date rlag
|
||||
,sum((request_date-order_date)*(value_usd)) rlag_wa
|
||||
--,ship_date - request_date slag
|
||||
,sum((ship_date - request_date)*(value_usd)) slag_wa
|
||||
,sum(extract(day from orderdate)*value_usd) dom_wa
|
||||
--,requestdate-orderdate rlag
|
||||
,sum((requestdate-orderdate)*(value_usd)) rlag_wa
|
||||
--,shipdate - requestdate slag
|
||||
,sum((shipdate - requestdate)*(value_usd)) slag_wa
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
GROUP BY
|
||||
to_char(order_date,'Mon')
|
||||
to_char(orderdate,'Mon')
|
||||
,seq
|
||||
,promo
|
||||
--,extract(day from order_date)
|
||||
--,request_date-order_date
|
||||
--,ship_date - request_date
|
||||
--,extract(day from orderdate)
|
||||
--,requestdate-orderdate
|
||||
--,shipdate - requestdate
|
||||
)
|
||||
,targm AS (select s, m from mseq where m = 'target_month' )
|
||||
,mmixp AS (
|
||||
@ -255,20 +255,20 @@ SELECT
|
||||
,0::numeric(15,5) ddqtsi --0
|
||||
,0::numeric(15,5) fgqshp --0
|
||||
,0::numeric(15,5) diqtsh --0
|
||||
,sum(coalesce(units,0)) units --history value
|
||||
,sum(coalesce(fb_qty,0)) fb_qty --history value
|
||||
,sum(coalesce(fb_cst_loc,0)) fb_cst_loc --history part mix
|
||||
,sum(coalesce(fb_cst_loc_cur,0)) fb_cst_loc_cur --master data
|
||||
,sum(coalesce(fb_cst_loc_fut,0)) fb_cst_loc_fut --master data
|
||||
,sum(coalesce(value_loc,0)) value_loc --history value
|
||||
,sum(coalesce(value_loc_pl,0)) value_loc_pl --0
|
||||
,sum(coalesce(fb_val_loc,0)) fb_val_loc --history value
|
||||
,sum(coalesce(fb_val_loc_pl,0)) fb_val_loc_pl --0
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,null::date order_date --history date mix
|
||||
,null::date request_date --history date mix
|
||||
,null::date ship_date --history date mix
|
||||
,null::date order_date --history
|
||||
,null::date adj_request_date --history
|
||||
,null::date ship_date --history
|
||||
,null::date orderdate --history date mix
|
||||
,null::date requestdate --history date mix
|
||||
,null::date shipdate --history date mix
|
||||
,null::date adj_orderdate --history
|
||||
,null::date adj_requestdate --history
|
||||
,null::date adj_shipdate --history
|
||||
---------------ui columns-------------------------
|
||||
,null::numeric order_season
|
||||
,null::text order_month
|
||||
@ -300,7 +300,7 @@ SELECT
|
||||
,null cost_usd
|
||||
,null units
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
rlarp.osm_fcpool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
@ -308,10 +308,10 @@ SELECT
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
GROUP BY
|
||||
plnt ---master data
|
||||
,terms
|
||||
@ -376,8 +376,8 @@ SELECT
|
||||
,scale AS (
|
||||
SELECT
|
||||
(SELECT incr::numeric FROM target) incr
|
||||
,(SELECT sum(units) FROM basemix) base
|
||||
,(SELECT incr::numeric FROM target)/(SELECT sum(units) FROM basemix) factor
|
||||
,(SELECT sum(fb_qty) FROM basemix) base
|
||||
,(SELECT incr::numeric FROM target)/(SELECT sum(fb_qty) FROM basemix) factor
|
||||
)
|
||||
,final AS (
|
||||
SELECT
|
||||
@ -441,20 +441,20 @@ SELECT
|
||||
,b.ddqtsi --0
|
||||
,b.fgqshp --0
|
||||
,b.diqtsh --0
|
||||
,b.units*s.factor*m.momix units
|
||||
,b.fb_qty*s.factor*m.momix fb_qty
|
||||
,b.fb_cst_loc*s.factor*m.momix fb_cst_loc
|
||||
,b.fb_cst_loc_cur*s.factor*m.momix fb_cst_loc_cur
|
||||
,b.fb_cst_loc_fut*s.factor*m.momix fb_cst_loc_fut
|
||||
,b.value_loc*s.factor*m.momix value_loc
|
||||
,b.value_loc_pl*s.factor*m.momix value_loc_pl
|
||||
,b.fb_val_loc*s.factor*m.momix fb_val_loc
|
||||
,b.fb_val_loc_pl*s.factor*m.momix fb_val_loc_pl
|
||||
,b.calc_status --0
|
||||
,b.flag --0
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) order_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag request_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag ship_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) order_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_request_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag ship_date
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
|
||||
,'replace_version' "version" --calculated
|
||||
,'replace_source'||' volume' iter --calculated
|
||||
-----------------------ui columns--------------------------------
|
||||
@ -484,11 +484,11 @@ SELECT
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,(b.value_loc*s.factor*m.momix)::numeric value_loc
|
||||
,(b.value_loc*s.factor*m.momix*r_rate)::numeric value_usd
|
||||
,(b.fb_val_loc*s.factor*m.momix)::numeric value_loc
|
||||
,(b.fb_val_loc*s.factor*m.momix*r_rate)::numeric value_usd
|
||||
,(b.fb_cst_loc*s.factor*m.momix)::numeric cost_loc
|
||||
,(b.fb_cst_loc*s.factor*m.momix*c_rate)::numeric cost_usd
|
||||
,(b.units*s.factor*m.momix)::numeric units
|
||||
,(b.fb_qty*s.factor*m.momix)::numeric units
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN scale s
|
||||
@ -506,7 +506,7 @@ WHERE
|
||||
m._month = (SELECT _month FROM closest)
|
||||
)
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_pool SELECT * FROM final RETURNING *
|
||||
INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
@ -5,20 +5,21 @@ the volume must be expressed in terms of units, since that is what it will be sc
|
||||
target AS (select target_volume vincr, target_price pincr)
|
||||
,testv AS (
|
||||
SELECT
|
||||
sum(units) tot
|
||||
,sum(units) FILTER (WHERE iter = 'copy') base
|
||||
,COALESCE(sum(units) FILTER (WHERE module = 'new basket'),0) newpart
|
||||
,sum(value_loc *r_rate) totsales
|
||||
,sum(value_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
|
||||
,COALESCE(sum(value_loc *r_rate) FILTER (WHERE module = 'new basket'),0) newpartsales
|
||||
sum(fb_qty) tot
|
||||
,sum(fb_qty) FILTER (WHERE iter = 'copy') base
|
||||
,COALESCE(sum(fb_qty) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpart
|
||||
,sum(fb_val_loc *r_rate) totsales
|
||||
,sum(fb_val_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
|
||||
,COALESCE(sum(fb_val_loc *r_rate) FILTER (WHERE iterdef->>'type' = 'new basket'),0) newpartsales
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
rlarp.osm_fcpool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
|
||||
)
|
||||
,flagv AS (
|
||||
SELECT
|
||||
@ -54,7 +55,7 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
FROM
|
||||
testv
|
||||
)
|
||||
,GLD AS MATERIALIZED (
|
||||
,GLD AS (
|
||||
SELECT
|
||||
N1COMP COMP
|
||||
,N1CCYY FSYR
|
||||
@ -63,11 +64,10 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
,to_char(N1FSYP,'FM0000') FSPR
|
||||
,N1SD01 SDAT
|
||||
,N1ED01 EDAT
|
||||
,daterange(n1sd01, n1ed01) drange
|
||||
,to_char(N1ED01,'yymm') CAPR
|
||||
,N1ED01 - N1SD01 +1 NDAYS
|
||||
,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,'00') SSPR
|
||||
FROM
|
||||
LGDAT.GLDATREF
|
||||
INNER JOIN LGDAT.GLDATE ON
|
||||
@ -75,37 +75,38 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
KPCCYY = N1CCYY
|
||||
WHERE
|
||||
N1COMP = 93
|
||||
--AND DIGITS(N1FSYP) = '1901'
|
||||
)
|
||||
,mseq AS (
|
||||
SELECT * FROM
|
||||
(
|
||||
VALUES
|
||||
('01 - Jun',1,6,-1)
|
||||
,('02 - Jul',2,7,-1)
|
||||
,('03 - Aug',3,8,-1)
|
||||
,('04 - Sep',4,9,-1)
|
||||
,('05 - Oct',5,10,-1)
|
||||
,('06 - Nov',6,11,-1)
|
||||
,('07 - Dec',7,12,-1)
|
||||
,('08 - Jan',8,1,0)
|
||||
,('09 - Feb',9,2,0)
|
||||
,('10 - Mar',10,3,0)
|
||||
,('11 - Apr',11,4,0)
|
||||
,('12 - May',12,5,0)
|
||||
('Jun',1,6,-1)
|
||||
,('Jul',2,7,-1)
|
||||
,('Aug',3,8,-1)
|
||||
,('Sep',4,9,-1)
|
||||
,('Oct',5,10,-1)
|
||||
,('Nov',6,11,-1)
|
||||
,('Dec',7,12,-1)
|
||||
,('Jan',8,1,0)
|
||||
,('Feb',9,2,0)
|
||||
,('Mar',10,3,0)
|
||||
,('Apr',11,4,0)
|
||||
,('May',12,5,0)
|
||||
) x(m,s,cal,yr)
|
||||
)
|
||||
,alldates AS MATERIALIZED(
|
||||
,alldates AS (
|
||||
SELECT
|
||||
promo
|
||||
,terms
|
||||
,order_month
|
||||
,mseq.s seq
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
,sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) value_usd
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
rlarp.osm_fcpool
|
||||
LEFT OUTER JOIN mseq ON
|
||||
mseq.m = order_month
|
||||
WHERE
|
||||
@ -115,52 +116,52 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
GROUP BY
|
||||
promo
|
||||
,terms
|
||||
,order_month
|
||||
,mseq.s
|
||||
,order_date
|
||||
,request_date
|
||||
,ship_date
|
||||
,orderdate
|
||||
,requestdate
|
||||
,shipdate
|
||||
HAVING
|
||||
sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) <> 0
|
||||
)
|
||||
--select * from alldates
|
||||
,dom AS (
|
||||
SELECT
|
||||
extract(day FROM order_date) DOM
|
||||
extract(day FROM orderdate) DOM
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
GROUP BY
|
||||
extract(day FROM order_date)
|
||||
extract(day FROM orderdate)
|
||||
)
|
||||
---------------------may want ot look at a top-5 mix solution in the future facilitated by sum() over (order by sales desc)---------------
|
||||
,mmix AS (
|
||||
SELECT
|
||||
to_char(order_date,'Mon') _month
|
||||
to_char(orderdate,'Mon') _month
|
||||
,seq
|
||||
,promo
|
||||
,sum(extract(day from order_date)*value_usd) dom_wa
|
||||
--,request_date-order_date rlag
|
||||
,sum((request_date-order_date)*(value_usd)) rlag_wa
|
||||
--,ship_date - request_date slag
|
||||
,sum((ship_date - request_date)*(value_usd)) slag_wa
|
||||
,sum(extract(day from orderdate)*value_usd) dom_wa
|
||||
--,requestdate-orderdate rlag
|
||||
,sum((requestdate-orderdate)*(value_usd)) rlag_wa
|
||||
--,shipdate - requestdate slag
|
||||
,sum((shipdate - requestdate)*(value_usd)) slag_wa
|
||||
,sum(value_usd) value_usd
|
||||
FROM
|
||||
alldates
|
||||
GROUP BY
|
||||
to_char(order_date,'Mon')
|
||||
to_char(orderdate,'Mon')
|
||||
,seq
|
||||
,promo
|
||||
--,extract(day from order_date)
|
||||
--,request_date-order_date
|
||||
--,ship_date - request_date
|
||||
--,extract(day from orderdate)
|
||||
--,requestdate-orderdate
|
||||
--,shipdate - requestdate
|
||||
)
|
||||
,targm AS (select s, m from mseq where m = 'target_month' )
|
||||
,mmixp AS (
|
||||
@ -186,50 +187,117 @@ target AS (select target_volume vincr, target_price pincr)
|
||||
abs(seq - targm.s) ASC
|
||||
LIMIT 1
|
||||
)
|
||||
---------------------the role of basemix here is to get non-dated info which is then dated in the next step---------------------
|
||||
--SELECT * FROM mmixp order by seq asc, vperc desc
|
||||
,basemix AS (
|
||||
SELECT
|
||||
--fspr in next step
|
||||
o.plnt
|
||||
--promo in next step
|
||||
--terms in next step
|
||||
,c.bvterm terms
|
||||
,o.bill_cust_descr
|
||||
,o.ship_cust_descr
|
||||
,o.dsm
|
||||
,o.quota_rep_descr
|
||||
,o.director
|
||||
,o.billto_group
|
||||
,o.shipto_group
|
||||
,o.chan
|
||||
,o.chansub
|
||||
,o.chan_retail
|
||||
,o.part
|
||||
,o.part_descr
|
||||
,o.part_group
|
||||
,o.branding
|
||||
,o.majg_descr
|
||||
,o.ming_descr
|
||||
,o.majs_descr
|
||||
,o.mins_descr
|
||||
,o.segm
|
||||
,o.substance
|
||||
,o.fs_line
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,sum(coalesce(o.units,0)) units
|
||||
,sum(coalesce(o.value_loc,0)) value_loc
|
||||
,sum(coalesce(o.value_usd,0)) value_usd
|
||||
,sum(coalesce(o.cost_loc,0)) cost_loc
|
||||
,sum(coalesce(o.cost_usd,0)) cost_usd
|
||||
,o.calc_status
|
||||
,o.flag
|
||||
plnt ---master data
|
||||
,0::numeric(11,0) "ddord#" --0
|
||||
,0::numeric(11,0) "dditm#" --0
|
||||
,0::numeric(11,0) "fgbol#" --0
|
||||
,0::numeric(11,0) "fgent#" --0
|
||||
,0::numeric(9,0) "diinv#" --0
|
||||
,0::numeric(3,0) "dilin#" --0
|
||||
,null::text promo --history date mix
|
||||
,null::text return_reas --0
|
||||
,terms
|
||||
,''::text custpo --0
|
||||
,'I' dhincr --0
|
||||
,null::numeric diext
|
||||
,null::numeric ditdis
|
||||
,null::date dcodat --calculated date mix
|
||||
,null::date ddqdat --calculated date mix
|
||||
,null::date dcmdat --calculated date mix
|
||||
,null::date dhidat --calculated date mix
|
||||
,null::text fspr --calculated date mix
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,dest_prov --master data
|
||||
,dest_post --master data
|
||||
,part --history part mix
|
||||
,ord_gldc --master data
|
||||
,majg --master data
|
||||
,ming --master data
|
||||
,majs --master data
|
||||
,mins --master data
|
||||
,gldc --master data
|
||||
,glec --master data
|
||||
,harm --master data
|
||||
,clss --master data
|
||||
,brand --master data
|
||||
,assc --master data
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,0::numeric(15,5) ddqtoi --0
|
||||
,0::numeric(15,5) ddqtsi --0
|
||||
,0::numeric(15,5) fgqshp --0
|
||||
,0::numeric(15,5) diqtsh --0
|
||||
,sum(coalesce(fb_qty,0)) fb_qty --history value
|
||||
,sum(coalesce(fb_cst_loc,0)) fb_cst_loc --history part mix
|
||||
,sum(coalesce(fb_cst_loc_cur,0)) fb_cst_loc_cur --master data
|
||||
,sum(coalesce(fb_cst_loc_fut,0)) fb_cst_loc_fut --master data
|
||||
,sum(coalesce(fb_val_loc,0)) fb_val_loc --history value
|
||||
,sum(coalesce(fb_val_loc_pl,0)) fb_val_loc_pl --0
|
||||
,calc_status --0
|
||||
,flag --0
|
||||
,null::date orderdate --history date mix
|
||||
,null::date requestdate --history date mix
|
||||
,null::date shipdate --history date mix
|
||||
,null::date adj_orderdate --history
|
||||
,null::date adj_requestdate --history
|
||||
,null::date adj_shipdate --history
|
||||
,'b20' "version" --calculated
|
||||
,'adjustment' iter --calculated
|
||||
---------------ui columns-------------------------
|
||||
,null::numeric order_season
|
||||
,null::text order_month
|
||||
,null::numeric ship_season
|
||||
,null::text ship_month
|
||||
,null::numeric request_season
|
||||
,null::text request_month
|
||||
,part_descr
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,segm
|
||||
,bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
,null value_loc
|
||||
,null value_usd
|
||||
,null cost_loc
|
||||
,null cost_usd
|
||||
,null units
|
||||
FROM
|
||||
rlarp.osm_pool o
|
||||
LEFT OUTER JOIN lgdat.cust c ON
|
||||
c.bvcust = rtrim(substr(o.bill_cust_descr,1,8))
|
||||
rlarp.osm_fcpool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
@ -237,137 +305,217 @@ SELECT
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN module = 'new basket'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND order_date <= ship_date
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
GROUP BY
|
||||
--fspr in next step
|
||||
o.plnt
|
||||
,c.bvterm
|
||||
--promo in next step
|
||||
--terms in next step
|
||||
,o.bill_cust_descr
|
||||
,o.ship_cust_descr
|
||||
,o.dsm
|
||||
,o.quota_rep_descr
|
||||
,o.director
|
||||
,o.billto_group
|
||||
,o.shipto_group
|
||||
,o.chan
|
||||
,o.chansub
|
||||
,o.chan_retail
|
||||
,o.part
|
||||
,o.part_descr
|
||||
,o.part_group
|
||||
,o.branding
|
||||
,o.majg_descr
|
||||
,o.ming_descr
|
||||
,o.majs_descr
|
||||
,o.mins_descr
|
||||
,o.segm
|
||||
,o.substance
|
||||
,o.fs_line
|
||||
,o.r_currency
|
||||
,o.r_rate
|
||||
,o.c_currency
|
||||
,o.c_rate
|
||||
,o.calc_status
|
||||
,o.flag
|
||||
plnt ---master data
|
||||
,terms
|
||||
,remit_to --master data
|
||||
,bill_class --master data
|
||||
,bill_cust --history cust mix
|
||||
,bill_rep --master data
|
||||
,bill_terr --master data
|
||||
,ship_class --master data
|
||||
,ship_cust --history cust mix
|
||||
,ship_rep --master data
|
||||
,ship_terr --master data
|
||||
,quota_rep --master data
|
||||
,account --master data
|
||||
,shipgrp --master data
|
||||
,geo --master data
|
||||
,chan --master data
|
||||
,orig_ctry --master data
|
||||
,orig_prov --master data
|
||||
,orig_post --master data
|
||||
,dest_ctry --master data
|
||||
,dest_prov --master data
|
||||
,dest_post --master data
|
||||
,part --history part mix
|
||||
,ord_gldc --master data
|
||||
,majg --master data
|
||||
,ming --master data
|
||||
,majs --master data
|
||||
,mins --master data
|
||||
,gldc --master data
|
||||
,glec --master data
|
||||
,harm --master data
|
||||
,clss --master data
|
||||
,brand --master data
|
||||
,assc --master data
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
,c_currency --master data
|
||||
,c_rate --master data
|
||||
,calc_status
|
||||
,flag
|
||||
,part_descr
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
,color
|
||||
,segm
|
||||
,bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
)
|
||||
,vscale AS (
|
||||
SELECT
|
||||
(SELECT vincr::numeric FROM target) incr
|
||||
,(SELECT sum(units) FROM basemix) base
|
||||
,(SELECT vincr::numeric FROM target)/(SELECT sum(units) FROM basemix) factor
|
||||
,(SELECT sum(fb_qty) FROM basemix) base
|
||||
,(SELECT vincr::numeric FROM target)/(SELECT sum(fb_qty) FROM basemix) factor
|
||||
)
|
||||
--select * from SCALE
|
||||
,log AS (
|
||||
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
|
||||
)
|
||||
,volume AS (
|
||||
SELECT
|
||||
sd.fspr
|
||||
,b.plnt
|
||||
,m.promo
|
||||
,b.terms
|
||||
,b.bill_cust_descr
|
||||
,b.ship_cust_descr
|
||||
,b.dsm
|
||||
,b.quota_rep_descr
|
||||
,b.director
|
||||
,b.billto_group
|
||||
,b.shipto_group
|
||||
,b.chan
|
||||
,b.chansub
|
||||
,b.chan_retail
|
||||
,b.part
|
||||
b.plnt --master data
|
||||
,b."ddord#" --0
|
||||
,b."dditm#" --0
|
||||
,b."fgbol#" --0
|
||||
,b."fgent#" --0
|
||||
,b."diinv#" --0
|
||||
,b."dilin#" --0
|
||||
,m.promo --history date mix
|
||||
,b.return_reas --0
|
||||
,b.terms --history cust mix
|
||||
,b.custpo --0
|
||||
,b.dhincr --0
|
||||
,b.diext --0
|
||||
,b.ditdis --0
|
||||
,b.dcodat --calculated date mix
|
||||
,b.ddqdat --calculated date mix
|
||||
,b.dcmdat --calculated date mix
|
||||
,b.dhidat --calculated date mix
|
||||
,b.fspr --calculated date mix
|
||||
,b.remit_to --master data
|
||||
,b.bill_class --master data
|
||||
,b.bill_cust --history cust mix
|
||||
,b.bill_rep --master data
|
||||
,b.bill_terr --master data
|
||||
,b.ship_class --master data
|
||||
,b.ship_cust --history cust mix
|
||||
,b.ship_rep --master data
|
||||
,b.ship_terr --master data
|
||||
,b.quota_rep --master data
|
||||
,b.account --master data
|
||||
,b.shipgrp --master data
|
||||
,b.geo --master data
|
||||
,b.chan --master data
|
||||
,b.orig_ctry --master data
|
||||
,b.orig_prov --master data
|
||||
,b.orig_post --master data
|
||||
,b.dest_ctry --master data
|
||||
,b.dest_prov --master data
|
||||
,b.dest_post --master data
|
||||
,b.part --history part mix
|
||||
,b.ord_gldc --master data
|
||||
,b.majg --master data
|
||||
,b.ming --master data
|
||||
,b.majs --master data
|
||||
,b.mins --master data
|
||||
,b.gldc --master data
|
||||
,b.glec --master data
|
||||
,b.harm --master data
|
||||
,b.clss --master data
|
||||
,b.brand --master data
|
||||
,b.assc --master data
|
||||
,b.fs_line --master data
|
||||
,b.r_currency --history cust mix
|
||||
,b.r_rate --master data
|
||||
,b.c_currency --master data
|
||||
,b.c_rate --master data
|
||||
,b.ddqtoi --0
|
||||
,b.ddqtsi --0
|
||||
,b.fgqshp --0
|
||||
,b.diqtsh --0
|
||||
,b.fb_qty*s.factor*m.momix fb_qty
|
||||
,b.fb_cst_loc*s.factor*m.momix fb_cst_loc
|
||||
,b.fb_cst_loc_cur*s.factor*m.momix fb_cst_loc_cur
|
||||
,b.fb_cst_loc_fut*s.factor*m.momix fb_cst_loc_fut
|
||||
,b.fb_val_loc*s.factor*m.momix fb_val_loc
|
||||
,b.fb_val_loc_pl*s.factor*m.momix fb_val_loc_pl
|
||||
,b.calc_status --0
|
||||
,b.flag --0
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
|
||||
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
|
||||
,'replace_version' "version" --calculated
|
||||
,'replace_source'||' volume' iter
|
||||
-----------------------ui columns--------------------------------
|
||||
,'replace_iterdet' iterdet
|
||||
,$$replace_iterdef$$::jsonb iterdef
|
||||
,od.ssyr order_season
|
||||
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
|
||||
,sd.ssyr ship_season
|
||||
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
|
||||
,rd.ssyr request_season
|
||||
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month
|
||||
,b.part_descr
|
||||
,b.part_family
|
||||
,b.part_group
|
||||
,b.branding
|
||||
,b.color
|
||||
,b.segm
|
||||
,b.bill_cust_descr
|
||||
,b.billto_group
|
||||
,b.ship_cust_descr
|
||||
,b.shipto_group
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.segm
|
||||
,b.substance
|
||||
,b.fs_line
|
||||
,b.r_currency
|
||||
,b.r_rate
|
||||
,b.c_currency
|
||||
,b.c_rate
|
||||
,b.units*s.factor*m.momix units
|
||||
,b.value_loc*s.factor*m.momix value_loc
|
||||
,b.value_usd*s.factor*m.momix value_usd
|
||||
,b.cost_loc*s.factor*m.momix cost_loc
|
||||
,b.cost_usd*s.factor*m.momix cost_usd
|
||||
,b.calc_status
|
||||
,b.flag
|
||||
,make_date(mseq.yr + 2021,mseq.cal,m.odom) order_date
|
||||
,od.sspr || ' - ' || to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom),'Mon') order_month
|
||||
,od.ssyr order_season
|
||||
,make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag request_date
|
||||
,rd.sspr || ' - ' ||to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag,'Mon') request_month
|
||||
,rd.ssyr request_season
|
||||
,make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag ship_date
|
||||
,sd.sspr || ' - ' || to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
|
||||
,sd.ssyr ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'module' module
|
||||
,b.mod_chan
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,b.fb_val_loc*s.factor*m.momix value_loc
|
||||
,b.fb_val_loc*s.factor*m.momix*r_rate value_usd
|
||||
,b.fb_cst_loc*s.factor*m.momix cost_loc
|
||||
,b.fb_cst_loc*s.factor*m.momix*c_rate cost_usd
|
||||
,(b.fb_qty*s.factor*m.momix) units
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN vscale s
|
||||
CROSS JOIN mmixp m
|
||||
CROSS JOIN closest
|
||||
CROSS JOIN log
|
||||
LEFT OUTER JOIN mseq ON
|
||||
mseq.m = closest.m
|
||||
LEFT OUTER JOIN gld od ON
|
||||
make_date(mseq.yr + 2021,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
|
||||
make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
|
||||
LEFT OUTER JOIN gld rd ON
|
||||
make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
||||
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
||||
LEFT OUTER JOIN gld sd ON
|
||||
make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
||||
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
||||
WHERE
|
||||
m._month = (SELECT _month FROM closest)
|
||||
)
|
||||
,pscale AS (
|
||||
SELECT
|
||||
(SELECT pincr::numeric FROM target) incr
|
||||
,(SELECT sum(value_loc * r_rate) FROM volume) base
|
||||
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
|
||||
,(SELECT sum(fb_val_loc * r_rate) FROM volume) base
|
||||
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN
|
||||
0
|
||||
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(fb_val_loc * r_rate) FROM volume))/(SELECT sum(fb_val_loc * r_rate) FROM volume)
|
||||
END factor
|
||||
,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 sum(fb_val_loc * r_rate) FROM volume) = 0 THEN
|
||||
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume)) <> 0 THEN
|
||||
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply
|
||||
((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume)
|
||||
((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume))/(SELECT sum(fb_qty) FROM volume)
|
||||
ELSE
|
||||
0
|
||||
END
|
||||
@ -377,92 +525,143 @@ WHERE
|
||||
)
|
||||
,price AS (
|
||||
SELECT
|
||||
b.fspr
|
||||
,b.plnt
|
||||
,b.promo
|
||||
,b.terms
|
||||
,b.bill_cust_descr
|
||||
,b.ship_cust_descr
|
||||
,b.dsm
|
||||
,b.quota_rep_descr
|
||||
,b.director
|
||||
,b.billto_group
|
||||
,b.shipto_group
|
||||
,b.chan
|
||||
,b.chansub
|
||||
,b.chan_retail
|
||||
,b.part
|
||||
b.plnt --master data
|
||||
,b."ddord#" --0
|
||||
,b."dditm#" --0
|
||||
,b."fgbol#" --0
|
||||
,b."fgent#" --0
|
||||
,b."diinv#" --0
|
||||
,b."dilin#" --0
|
||||
,b.promo --history date mix
|
||||
,b.return_reas --0
|
||||
,b.terms --history cust mix
|
||||
,b.custpo --0
|
||||
,b.dhincr --0
|
||||
,b.diext --0
|
||||
,b.ditdis --0
|
||||
,b.dcodat --calculated date mix
|
||||
,b.ddqdat --calculated date mix
|
||||
,b.dcmdat --calculated date mix
|
||||
,b.dhidat --calculated date mix
|
||||
,b.fspr --calculated date mix
|
||||
,b.remit_to --master data
|
||||
,b.bill_class --master data
|
||||
,b.bill_cust --history cust mix
|
||||
,b.bill_rep --master data
|
||||
,b.bill_terr --master data
|
||||
,b.ship_class --master data
|
||||
,b.ship_cust --history cust mix
|
||||
,b.ship_rep --master data
|
||||
,b.ship_terr --master data
|
||||
,b.quota_rep --master data
|
||||
,b.account --master data
|
||||
,b.shipgrp --master data
|
||||
,b.geo --master data
|
||||
,b.chan --master data
|
||||
,b.orig_ctry --master data
|
||||
,b.orig_prov --master data
|
||||
,b.orig_post --master data
|
||||
,b.dest_ctry --master data
|
||||
,b.dest_prov --master data
|
||||
,b.dest_post --master data
|
||||
,b.part --history part mix
|
||||
,b.ord_gldc --master data
|
||||
,b.majg --master data
|
||||
,b.ming --master data
|
||||
,b.majs --master data
|
||||
,b.mins --master data
|
||||
,b.gldc --master data
|
||||
,b.glec --master data
|
||||
,b.harm --master data
|
||||
,b.clss --master data
|
||||
,b.brand --master data
|
||||
,b.assc --master data
|
||||
,b.fs_line --master data
|
||||
,b.r_currency --history cust mix
|
||||
,b.r_rate --master data
|
||||
,b.c_currency --master data
|
||||
,b.c_rate --master data
|
||||
,b.ddqtoi --0
|
||||
,b.ddqtsi --0
|
||||
,b.fgqshp --0
|
||||
,b.diqtsh --0
|
||||
,0 fb_qty
|
||||
,0 fb_cst_loc
|
||||
,0 fb_cst_loc_cur
|
||||
,0 fb_cst_loc_fut
|
||||
,b.fb_val_loc*p.factor fb_val_loc
|
||||
,b.fb_val_loc_pl*p.factor fb_val_loc_pl
|
||||
,b.calc_status --0
|
||||
,b.flag --0
|
||||
,b.orderdate
|
||||
,b.requestdate
|
||||
,b.shipdate
|
||||
,b.adj_orderdate
|
||||
,b.adj_requestdate
|
||||
,b.adj_shipdate
|
||||
,'replace_version' "version" --calculated
|
||||
,'replace_source'||' price' iter --calculateds
|
||||
,'replace_iterdet' iterdet
|
||||
,$$replace_iterdef$$::jsonb iterdef
|
||||
,b.order_season
|
||||
,b.order_month
|
||||
,b.ship_season
|
||||
,b.ship_month
|
||||
,b.request_season
|
||||
,b.request_month
|
||||
,b.part_descr
|
||||
,b.part_family
|
||||
,b.part_group
|
||||
,b.branding
|
||||
,b.color
|
||||
,b.segm
|
||||
,b.bill_cust_descr
|
||||
,b.billto_group
|
||||
,b.ship_cust_descr
|
||||
,b.shipto_group
|
||||
,b.majg_descr
|
||||
,b.ming_descr
|
||||
,b.majs_descr
|
||||
,b.mins_descr
|
||||
,b.segm
|
||||
,b.substance
|
||||
,b.fs_line
|
||||
,b.r_currency
|
||||
,b.r_rate
|
||||
,b.c_currency
|
||||
,b.c_rate
|
||||
,0::numeric units
|
||||
,(CASE WHEN p.factor = 0 THEN b.units * p.mod_price/b.r_rate ELSE b.value_loc*p.factor END)::numeric value_loc
|
||||
,(CASE WHEN p.factor = 0 THEN b.units * p.mod_price ELSE b.value_usd*p.factor END)::numeric value_usd
|
||||
,0::numeric cost_loc
|
||||
,0::numeric cost_usd
|
||||
,b.calc_status
|
||||
,b.flag
|
||||
,b.order_date
|
||||
,b.order_month
|
||||
,b.order_season
|
||||
,b.request_date
|
||||
,b.request_month
|
||||
,b.request_season
|
||||
,b.ship_date
|
||||
,b.ship_month
|
||||
,b.ship_season
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' price' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'module' module
|
||||
,b.mod_chan
|
||||
,b.mod_chansub
|
||||
,b.quota_rep_descr
|
||||
,b.director_descr
|
||||
,(CASE WHEN p.factor = 0 THEN b.fb_qty * p.mod_price/b.r_rate ELSE b.fb_val_loc*p.factor END)::numeric value_loc
|
||||
,(CASE WHEN p.factor = 0 THEN b.fb_qty * p.mod_price ELSE b.fb_val_loc*p.factor END)::numeric value_usd
|
||||
,0 cost_loc
|
||||
,0 cost_usd
|
||||
,0 units
|
||||
FROM
|
||||
volume b
|
||||
CROSS JOIN pscale p
|
||||
CROSS JOIN log
|
||||
WHERE
|
||||
p.factor <> 0 or p.mod_price <> 0
|
||||
)
|
||||
, ins AS (
|
||||
INSERT INTO rlarp.osm_pool (SELECT * FROM price UNION ALL SELECT * FROM volume) RETURNING *
|
||||
INSERT INTO rlarp.osm_fcpool (SELECT * FROM price UNION ALL SELECT * FROM volume) RETURNING *
|
||||
)
|
||||
,insagg AS (
|
||||
SELECT
|
||||
---------customer info-----------------
|
||||
SELECT
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,director_descr
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
@ -472,41 +671,33 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
FROM
|
||||
FROM
|
||||
ins
|
||||
GROUP BY
|
||||
---------customer info-----------------
|
||||
GROUP BY
|
||||
bill_cust_descr
|
||||
,billto_group
|
||||
,ship_cust_descr
|
||||
,shipto_group
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,director_descr
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
,mod_chan
|
||||
,mod_chansub
|
||||
,majg_descr
|
||||
,ming_descr
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
--,brand
|
||||
--,part_family
|
||||
,brand
|
||||
,part_family
|
||||
,part_group
|
||||
,branding
|
||||
--,color
|
||||
,color
|
||||
,part_descr
|
||||
---------dates-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
,ship_season
|
||||
@ -516,8 +707,6 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
--SELECT * FROM insagg
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
@ -1,9 +1,4 @@
|
||||
BEGIN;
|
||||
|
||||
DROP TABLE IF EXISTS rlarp.osm_pool;
|
||||
DROP TABLE IF EXISTS rlarp.osm_log;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS rlarp.osm_log(id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, doc jsonb);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS rlarp.osm_pool AS (
|
||||
WITH
|
||||
@ -82,7 +77,6 @@ SELECT
|
||||
,o.majs||' - '||i.majsd majs_descr
|
||||
,o.mins||' - '||i.minsd mins_descr
|
||||
,seg.segm
|
||||
,CASE WHEN o.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
|
||||
,fs_line
|
||||
,r_currency
|
||||
,r_rate
|
||||
@ -96,20 +90,19 @@ SELECT
|
||||
,calc_status
|
||||
,flag
|
||||
,o.odate order_date
|
||||
,to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month
|
||||
,to_char(CASE WHEN extract(month FROM o.odate) > 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month
|
||||
,oseas order_season
|
||||
,rdate request_date
|
||||
,to_char(CASE WHEN extract(month FROM o.rdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.rdate),'FM00')||' - '||to_char(o.rdate,'TMMon') request_month
|
||||
,to_char(CASE WHEN extract(month FROM o.rdate) > 6 THEN -5 ELSE 7 END + extract(month FROM o.rdate),'FM00')||' - '||to_char(o.rdate,'TMMon') request_month
|
||||
,rseas request_season
|
||||
,sdate ship_date
|
||||
,to_char(CASE WHEN extract(month FROM o.sdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.sdate),'FM00')||' - '||to_char(o.sdate,'TMMon') ship_month
|
||||
,to_char(CASE WHEN extract(month FROM o.sdate) > 6 THEN -5 ELSE 7 END + extract(month FROM o.sdate),'FM00')||' - '||to_char(o.sdate,'TMMon') ship_month
|
||||
,sseas ship_season
|
||||
,version
|
||||
,iter
|
||||
,null::int logid
|
||||
,''::text tag
|
||||
,''::text "comment"
|
||||
,''::text module
|
||||
,null::text "comment"
|
||||
,null::text module
|
||||
FROM
|
||||
rlarp.osmf_dev o
|
||||
LEFT OUTER JOIN lgdat.cust bc ON
|
||||
@ -137,10 +130,12 @@ FROM
|
||||
--LIMIT 100
|
||||
) WITH DATA;
|
||||
|
||||
CREATE INDEX osm_qr ON rlarp.osm_pool(quota_rep_descr, bill_cust_descr, ship_cust_descr);
|
||||
ALTER TABLE rlarp.osm_pool ADD CONSTRAINT logfk FOREIGN KEY (logid) REFERENCES rlarp.osm_log(id);
|
||||
CREATE INDEX osm_pool_logid ON rlarp.osm_pool(logid);
|
||||
CREATE INDEX osm_qr ON rlarp.osm_pool(quota_rep_descr);
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS rlarp.osm_log;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS rlarp.osm_log(id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, doc jsonb);
|
||||
|
||||
GRANT ALL ON TABLE rlarp.osm_log TO api;
|
||||
GRANT ALL ON TABLE rlarp.osm_pool TO api;
|
||||
|
||||
COMMIT;
|
@ -8,7 +8,6 @@ SELECT
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -30,17 +29,14 @@ SELECT
|
||||
,request_season
|
||||
,request_month
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
,sum(cost_loc) cost_loc
|
||||
,sum(cost_usd) cost_usd
|
||||
,sum(units) units
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
@ -54,7 +50,6 @@ GROUP BY
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -78,10 +73,6 @@ GROUP BY
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
,substance
|
||||
)
|
||||
SELECT
|
||||
json_agg(row_to_json(rows)) x
|
||||
|
@ -4,7 +4,6 @@ SELECT
|
||||
l.doc->>'user' "user",
|
||||
jsonb_path_query_first(l.doc,'$.scenario.quota_rep_descr')->>0 quota_rep_descr,
|
||||
to_char((l.doc->>'stamp')::timestamptz,'YYYY-MM-DD HH:MI:SS') "stamp",
|
||||
l.doc->>'tag' "tag",
|
||||
l.doc->>'message' "comment",
|
||||
jsonb_pretty(l.doc) def,
|
||||
l.id
|
||||
@ -18,7 +17,6 @@ SELECT
|
||||
list.user
|
||||
,list.quota_rep_descr
|
||||
,list.stamp
|
||||
,list.tag
|
||||
,list.comment
|
||||
,list.def
|
||||
,list.id
|
||||
@ -31,7 +29,6 @@ group BY
|
||||
list.user
|
||||
,list.quota_rep_descr
|
||||
,list.stamp
|
||||
,list.tag
|
||||
,list.comment
|
||||
,list.def
|
||||
,list.id
|
||||
|
@ -308,7 +308,6 @@ SELECT
|
||||
,i.majs||' - '||i.majsd majs_descr
|
||||
,i.mins||' - '||i.minsd mins_descr
|
||||
,seg.segm
|
||||
,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
|
||||
,'41010' fs_line --master data
|
||||
,bc.bvcurr r_currency --history cust mix
|
||||
,rx.rate r_rate --master data
|
||||
@ -333,9 +332,8 @@ SELECT
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'module' module
|
||||
,log.doc->>'comment' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN log
|
||||
@ -431,7 +429,6 @@ FROM
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -455,9 +452,6 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
@ -475,7 +469,6 @@ FROM
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -499,8 +492,5 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
@ -25,7 +25,6 @@ target AS (select target_increment incr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -79,7 +78,6 @@ target AS (select target_increment incr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -145,7 +143,6 @@ target AS (select target_increment incr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -170,9 +167,8 @@ target AS (select target_increment incr)
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' price' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'module' module
|
||||
,log.doc->>'comment' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN scale s
|
||||
@ -194,7 +190,6 @@ target AS (select target_increment incr)
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -218,9 +213,6 @@ target AS (select target_increment incr)
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
@ -238,7 +230,6 @@ target AS (select target_increment incr)
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -262,8 +253,5 @@ target AS (select target_increment incr)
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
@ -61,7 +61,6 @@ target AS (select incr_qty qincr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -120,7 +119,6 @@ target AS (select incr_qty qincr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -174,7 +172,6 @@ target AS (select incr_qty qincr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -199,9 +196,8 @@ target AS (select incr_qty qincr)
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'module' module
|
||||
,log.doc->>'comment' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN scale s
|
||||
@ -221,7 +217,6 @@ FROM
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -245,9 +240,6 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
@ -265,7 +257,6 @@ FROM
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -289,8 +280,5 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
@ -61,7 +61,6 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -120,7 +119,6 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -173,7 +171,6 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -198,9 +195,8 @@ target AS (select target_vol vincr, target_prc pincr)
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' volume' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'module' module
|
||||
,log.doc->>'comment' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
basemix b
|
||||
CROSS JOIN vscale s
|
||||
@ -254,7 +250,6 @@ FROM
|
||||
,majs_descr
|
||||
,mins_descr
|
||||
,segm
|
||||
,substance
|
||||
,fs_line --master data
|
||||
,r_currency --history cust mix
|
||||
,r_rate --master data
|
||||
@ -279,9 +274,8 @@ FROM
|
||||
,'replace_version' "version"
|
||||
,'replace_source'||' price' iter
|
||||
,log.id
|
||||
,COALESCE(log.doc->>'tag','') "tag"
|
||||
,log.doc->>'message' "comment"
|
||||
,log.doc->>'module' module
|
||||
,log.doc->>'comment' "comment"
|
||||
,log.doc->>'type' module
|
||||
FROM
|
||||
volume b
|
||||
CROSS JOIN pscale s
|
||||
@ -303,7 +297,6 @@ FROM
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -327,9 +320,6 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
--------values-------------------------
|
||||
,sum(value_loc) value_loc
|
||||
,sum(value_usd) value_usd
|
||||
@ -347,7 +337,6 @@ FROM
|
||||
,quota_rep_descr
|
||||
,director
|
||||
,segm
|
||||
,substance
|
||||
,chan
|
||||
,chansub
|
||||
---------product info------------------
|
||||
@ -371,8 +360,5 @@ FROM
|
||||
,promo
|
||||
,version
|
||||
,iter
|
||||
,logid
|
||||
,tag
|
||||
,comment
|
||||
)
|
||||
SELECT json_agg(row_to_json(insagg)) x from insagg
|
||||
|
@ -142,19 +142,6 @@ GROUP BY
|
||||
,version
|
||||
,iter
|
||||
)
|
||||
,tags AS (
|
||||
SELECT DISTINCT
|
||||
doc->>'tag' tag
|
||||
FROM
|
||||
rlarp.osm_log
|
||||
WHERE doc ? 'tag'
|
||||
UNION
|
||||
SELECT * FROM
|
||||
(VALUES
|
||||
('price'),
|
||||
('volume')
|
||||
) x(tag)
|
||||
)
|
||||
SELECT
|
||||
jsonb_build_object(
|
||||
'months'
|
||||
@ -165,6 +152,4 @@ SELECT
|
||||
,(SELECT jsonb_agg(row_to_json(basket)::jsonb) FROM basket)
|
||||
,'totals'
|
||||
,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals)
|
||||
,'tags'
|
||||
,(SELECT jsonb_agg(tag) FROM tags)
|
||||
) package
|
@ -1,8 +0,0 @@
|
||||
WITH
|
||||
d AS (
|
||||
DELETE FROM rlarp.osm_log WHERE id = replace_id RETURNING id
|
||||
)
|
||||
,d_osm AS (
|
||||
DELETE FROM rlarp.osm_pool WHERE logid IN (select id from d)
|
||||
)
|
||||
SELECT json_agg(row_to_json(d)) x from d
|
@ -1,28 +0,0 @@
|
||||
{
|
||||
"scenario": {
|
||||
"quota_rep_descr": "TINA PETTIGREW",
|
||||
"substance": "Plastic",
|
||||
"chan": "DIR",
|
||||
"billto_group": "H&A MASTRONARDI",
|
||||
"shipto_group": "H&A MASTRONARDI",
|
||||
"majg_descr": "110 - INJECTION",
|
||||
"part_descr": "HWA13000E21B025LZBLD - 13.00 WRAPT HP CHOCOLATE",
|
||||
"version": "b21",
|
||||
"iter": [
|
||||
"copy",
|
||||
"adj volume",
|
||||
"adj price",
|
||||
"upload volume",
|
||||
"upload price"
|
||||
]
|
||||
},
|
||||
"stamp": "2020-02-19 17:03:38",
|
||||
"user": "Trowbridge, Paul",
|
||||
"source": "adj",
|
||||
"message": "2% on volume and price",
|
||||
"tag": "standard price",
|
||||
"version": "b21",
|
||||
"type": "scale_vp",
|
||||
"qty": 453.60,
|
||||
"amount": 728.43624
|
||||
}
|
Loading…
Reference in New Issue
Block a user