fix add month route for volume only with base = 0
This commit is contained in:
parent
833ec511c1
commit
723e2a250c
2
index.js
2
index.js
@ -193,7 +193,7 @@ server.post('/addmonth_v', bodyParser.json(), function (req, res) {
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("scenario = target_scenario",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_increment",'g'),req.body.amount);
|
||||
sql = sql.replace(new RegExp("target_increment",'g'),req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_month",'g'),req.body.month);
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
|
@ -7,6 +7,42 @@ target_month
|
||||
|
||||
WITH
|
||||
target AS (select target_increment incr)
|
||||
,testv AS (
|
||||
SELECT
|
||||
sum(fb_qty) tot
|
||||
,sum(fb_qty) FILTER (WHERE iter = 'copy') base
|
||||
,sum(fb_qty) FILTER (WHERE iterdef->>'type' = 'new basket') newpart
|
||||
FROM
|
||||
rlarp.osm_fcpool
|
||||
WHERE
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
-----------------additional params-------------------
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
|
||||
)
|
||||
,flagv AS (
|
||||
SELECT
|
||||
tot
|
||||
,base
|
||||
,newpart
|
||||
,CASE WHEN tot = 0 THEN
|
||||
CASE WHEN base = 0 THEN
|
||||
CASE WHEN newpart = 0 THEN
|
||||
'unclean data. tested -> does not exist'
|
||||
ELSE
|
||||
'scale new part'
|
||||
END
|
||||
ELSE
|
||||
'scale copy'
|
||||
END
|
||||
ELSE
|
||||
'scale all'
|
||||
END flag
|
||||
FROM
|
||||
testv
|
||||
)
|
||||
,GLD AS (
|
||||
SELECT
|
||||
N1COMP COMP
|
||||
@ -66,7 +102,11 @@ target AS (select target_increment incr)
|
||||
scenario = target_scenario
|
||||
-----------------additional params-------------------
|
||||
AND version = 'b20'
|
||||
AND iter = 'copy'
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
GROUP BY
|
||||
@ -249,6 +289,11 @@ SELECT
|
||||
-----------------scenario----------------------------
|
||||
scenario = target_scenario
|
||||
-----------------additional params-------------------
|
||||
AND CASE (SELECT flag FROM flagv)
|
||||
WHEN 'scale all' THEN true
|
||||
WHEN 'scale copy' THEN iter = 'copy'
|
||||
WHEN 'scale new part' THEN iterdef->>'type' = 'new basket'
|
||||
END
|
||||
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
|
||||
AND adj_orderdate <= adj_shipdate
|
||||
GROUP BY
|
||||
@ -315,8 +360,8 @@ SELECT
|
||||
,scale AS (
|
||||
SELECT
|
||||
(SELECT incr::numeric FROM target) incr
|
||||
,(SELECT sum(fb_val_loc *r_rate) FROM basemix) base
|
||||
,(SELECT incr::numeric FROM target)/(SELECT sum(fb_val_loc *r_rate) 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
|
||||
|
Loading…
Reference in New Issue
Block a user