diff --git a/route_sql/scale_pd.sql b/route_sql/scale_pd.sql index 2f744d3..bf8a760 100644 --- a/route_sql/scale_pd.sql +++ b/route_sql/scale_pd.sql @@ -103,16 +103,16 @@ target AS (select target_increment incr) ,scale AS ( SELECT (SELECT incr::numeric FROM target) incr - ,(SELECT sum(fb_val_loc * r_rate) FROM basemix) base - ,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM basemix) = 0 THEN + ,(SELECT sum(value_loc * r_rate) FROM basemix) base + ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN 0 ELSE - (SELECT incr::numeric FROM target)/(SELECT sum(fb_val_loc * r_rate) FROM basemix) + (SELECT incr::numeric FROM target)/(SELECT sum(value_loc * r_rate) FROM basemix) END factor - ,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM basemix) = 0 THEN - CASE WHEN ((SELECT incr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM basemix)) <> 0 THEN + ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN + CASE WHEN ((SELECT incr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM basemix)) <> 0 THEN --if the base value is -0- but the target value hasn't been achieved, derive a price to apply - ((SELECT incr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM basemix))/(SELECT sum(fb_qty) FROM basemix) + ((SELECT incr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM basemix))/(SELECT sum(units) FROM basemix) ELSE 0 END @@ -182,14 +182,14 @@ SELECT ,b.ddqtsi --0 ,b.fgqshp --0 ,b.diqtsh --0 - ,0 fb_qty + ,0 units ,0 fb_cst_loc ,0 fb_cst_loc_cur ,0 fb_cst_loc_fut - --,b.fb_val_loc*s.factor fb_val_loc - ,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric fb_val_loc - ,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc_pl*s.factor END)::numeric fb_val_loc_pl - --,b.fb_val_loc_pl*s.factor fb_val_loc_pl + --,b.value_loc*s.factor value_loc + ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc + ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc_pl*s.factor END)::numeric value_loc_pl + --,b.value_loc_pl*s.factor value_loc_pl ,b.calc_status --0 ,b.flag --0 ,b.orderdate @@ -227,8 +227,8 @@ SELECT ,b.mod_chansub ,b.quota_rep_descr ,b.director_descr - ,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric value_loc - ,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price ELSE b.fb_val_loc*s.factor*r_rate END)::numeric value_usd + ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc + ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_loc*s.factor*r_rate END)::numeric value_usd ,0 cost_loc ,0 cost_usd ,0 units