swap out value fields

This commit is contained in:
Trowbridge 2020-02-13 12:47:01 -05:00
parent ef914f3d5e
commit 5e4690a1f4

View File

@ -205,18 +205,18 @@ FROM
,pscale AS ( ,pscale AS (
SELECT SELECT
(SELECT pincr::numeric FROM target) incr (SELECT pincr::numeric FROM target) incr
,(SELECT sum(fb_val_loc * r_rate) FROM volume) base ,(SELECT sum(value_loc * r_rate) FROM volume) base
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN ,CASE WHEN (SELECT sum(value_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- --if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
0 0
ELSE ELSE
--if the target $amount is not achieved, adjust further --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) ((SELECT pincr::numeric FROM target)-(SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(value_loc * r_rate) FROM volume)
END factor END factor
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN ,CASE WHEN (SELECT sum(value_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 CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume)) <> 0 THEN
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply --if the base value is -0- but the target value hasn't been achieved, derive a price to apply
((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume) ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume)
ELSE ELSE
0 0
END END
@ -291,10 +291,10 @@ FROM
,0 fb_cst_loc ,0 fb_cst_loc
,0 fb_cst_loc_cur ,0 fb_cst_loc_cur
,0 fb_cst_loc_fut ,0 fb_cst_loc_fut
--,b.fb_val_loc*s.factor fb_val_loc --,b.value_loc*s.factor value_loc
,(CASE WHEN s.factor = 0 THEN b.units * 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.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.fb_val_loc_pl*s.factor END)::numeric fb_val_loc_pl ,(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.fb_val_loc_pl*s.factor fb_val_loc_pl --,b.value_loc_pl*s.factor value_loc_pl
,b.calc_status --0 ,b.calc_status --0
,b.flag --0 ,b.flag --0
,b.orderdate ,b.orderdate
@ -332,8 +332,8 @@ FROM
,b.mod_chansub ,b.mod_chansub
,b.quota_rep_descr ,b.quota_rep_descr
,b.director_descr ,b.director_descr
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.fb_val_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*s.factor END)::numeric value_loc
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.fb_val_loc*s.factor*b.r_rate END)::numeric value_usd ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_loc*s.factor*b.r_rate END)::numeric value_usd
,0 cost_loc ,0 cost_loc
,0 cost_usd ,0 cost_usd
,0 units ,0 units