Is it possible to avoid using Views PHP? I have a number of values that I need to run a bit of logic on to get a value for a views math expression further down the chain. Im going to provide a much simpler example of what I am actually doing...

Variables set on custom module admin page...


twoyr_a = 5.4
twoyr_b = 12.4
threeyr_a = 5.6
threeyr_b = 12.7
fouryr_a = 5.8
fouryr_b = 13.3


Contract term (Factor A) - Overidden with views-views-field--factor--a.tpl.php

if ($output == '24') {
    print variable_get('twoyr_a');
} elseif ($output == '36') {
    print variable_get('threeyr_a');
} elseif ($output == '48') {
    print variable_get('fouryr_a');
} else {
    print '0';
}


Contract term (Factor B) - Overidden with views-views-field--factor--b.tpl.php

if ($output == '24') {
    print variable_get('twoyr_b');
} elseif ($output == '36') {
    print variable_get('threeyr_b');
} elseif ($output == '48') {
    print variable_get('fouryr_b');
} else {
    print '0';
}


Views Global:Math Expression

[factor_a] + [factor_b] = result

However, the result is always wrong. Instead of using the result from the PHP template, it is adding the Contract terms (24 + 24 = 48).

Im guessing this is because the math expression runs before the template files do.

So my question is, is there anyway to avoid using Views PHP for this? Or is there a fix for my current solution?

Note: $output is already defined in the database as 24, 36, or 48 in a "Contract Term" column. It relates to just a normal field in an ECK entity type called "Deal". It's an integer value to define the length of a contract for that deal. Each contract term has its own A and B factors to calculate my clients profit percentage when borrowing from a loan company.
A possible solution that might help to simplify the challenge in your question, is to use the fairly new Math Field module (for D7). Some more details about this module (from its project page):


  The Math Field module defines a new field type to dynamically calculate values on entity forms. This is an alternative to Computed Field
  that does not require the use of PHP Filter.
  
  Math expression fields are dynamically updated via ajax on the entity form as soon as all necessary fields are populated. If JavaScript is disabled, the field will be evaluated when the form is submitted. The result is stored in the database when the form is submitted.


By creating some auxiliary field(s) (calculated via the Math field), you may be able to complete your puzzle. Possibly via some additional logic implemented via the Rules module, to implement logic that is similar to what I described in my answer to "How to set the values of some fields depending on the value of a list box?".

For more details (step-by-step instructions) about Math Field, refer to either of these links:


the (amazing!) Community documentation about the Math Field module.
the interesting article about Introducing the Math Field module, which also includes some screenprints to see it at work (such as the the add/edit form example).