From bf03eff862acd10ec7d70e9e67d7680a9a1be7f0 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 4 Apr 2019 12:19:40 -0500 Subject: [PATCH] vupd was scaling from scratch instead of just cleaning up the volume increase to match the dollar target --- route_sql/scale_vupd.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/route_sql/scale_vupd.sql b/route_sql/scale_vupd.sql index 59ade9d..0042a2c 100644 --- a/route_sql/scale_vupd.sql +++ b/route_sql/scale_vupd.sql @@ -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