The general solution to this problem is to use a runtime expression evaluator in the form of scripts. Similar problems appear in handling complex and varying calculations like costing, quoting and payroll.
To take a simple example, the script code might read:
$total = $overtime-given * 1.5 - $overtime-paid
The questions are:
- What language to use for the expressions.
- How to give the language access to the variables it needs (and nothing else)
The main choices are:
- Write your expression evaluator/language. Hard! (but my favorite)
- Use the hosting language, if suitable. I believe PHP can be used in this role, but I defer to others as to how well that would work.
- Embed a dynamically compiled/interpreted language designed for the purpose. I would suggest Lua, but it depends on whether it can be embedded on your platform.
This is not a complete answer, but rather a direction to pursue. I have done this in Ruby (embedded my own expression evaluator), but hesitate to suggest it unless you really like compiler technology.