vupd was scaling from scratch instead of just cleaning up the volume increase to match the dollar target

This commit is contained in:
Paul Trowbridge 2019-04-04 12:19:40 -05:00
parent 22841d3671
commit bf03eff862

View File

@ -358,9 +358,11 @@ target AS (select target_vol vincr, target_prc pincr)
(SELECT pincr::numeric FROM target) incr
,(SELECT sum(fb_val_loc * r_rate) FROM volume) base
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN
--if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
0
ELSE
(SELECT pincr::numeric FROM target)/(SELECT sum(fb_val_loc * r_rate) FROM volume)
--if the target $amount is not achieved, adjust further
((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(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