recast scale_v to be based on qty and handle -0- qty
This commit is contained in:
parent
731c811fc3
commit
8cb6b843ba
2
index.js
2
index.js
@ -269,7 +269,7 @@ server.post('/scale_v', bodyParser.json(), function (req, res) {
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause",'g'),w);
|
||||
sql = sql.replace(new RegExp("target_increment",'g'),req.body.amount);
|
||||
sql = sql.replace(new RegExp("incr_qty",'g'),req.body.qty);
|
||||
sql = sql.replace(new RegExp("replace_version",'g'),req.body.scenario.version);
|
||||
sql = sql.replace(new RegExp("replace_source",'g'),req.body.source);
|
||||
sql = sql.replace(new RegExp("replace_iterdef",'g'),JSON.stringify(req.body));
|
||||
|
@ -1,5 +1,42 @@
|
||||
WITH
|
||||
target AS (select target_increment incr)
|
||||
target AS (select incr_qty qincr)
|
||||
,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----------------------------
|
||||
where_clause
|
||||
-----------------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
|
||||
)
|
||||
--ever need receive a target of -0- qty but value <> 0?
|
||||
,basemix AS (
|
||||
SELECT
|
||||
plnt ---master data
|
||||
@ -76,8 +113,8 @@ SELECT
|
||||
,adj_orderdate --history
|
||||
,adj_requestdate --history
|
||||
,adj_shipdate --history
|
||||
,'b20' "version" --calculated
|
||||
,'adjustment' iter --calculated
|
||||
,null::text "version" --calculated
|
||||
,null::text iter --calculated
|
||||
---------------ui columns-------------------------
|
||||
,order_season
|
||||
,order_month
|
||||
@ -114,6 +151,11 @@ SELECT
|
||||
-----------------scenario----------------------------
|
||||
where_clause
|
||||
-----------------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
|
||||
@ -190,12 +232,14 @@ SELECT
|
||||
,quota_rep_descr
|
||||
,director_descr
|
||||
)
|
||||
--SELECT * FROM basemix
|
||||
,scale AS (
|
||||
SELECT
|
||||
(SELECT incr::numeric FROM target) incr
|
||||
(SELECT qincr::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 qincr FROM target)/(SELECT SUM(fb_qty) FROM basemix) factor
|
||||
)
|
||||
--select * from scale
|
||||
,final AS (
|
||||
SELECT
|
||||
b.plnt --master data
|
||||
|
Loading…
Reference in New Issue
Block a user