Actually order of operation might be really simple.
I assume internally that you use a sequence id for the custom fields. If the calcuator is limited to only two fields then you need to define the field first before you can use it elsewhere, so if you calculate based on the sequence id then problem solved.
Then for UI, you have"Create Calculated Field" in your menu. That gives a pop up where you:
Define:
- Field Name
- Type (I would limit it to just time and number for simplicity for now)
- Display positioning (similar to custom fields)
- Field 1
- use a drop down selector from current system and custom fields
- filtered on the defined type above
- Operation
- drop down of add/subtract/multiply/divide
- Field 2
- use a drop down selector from current system and custom fields
- if the type is number then you can return any number field.
- if the type is time, then if the operator is add or subtract, then return time and numer fields. If the operator is multiple/divide then only return numer fields as I don't think you should be multiplying or dividing times.
Unlike the custom fields where you can add a bunch at the same time, the calculated fields should be saved one at a time. This enforces the order of operations.
The only other thing might be having an additional entry box beside the field 2 selection should you not want to use a field but instead perform arithmatic using a constant. But I can't think of an obvious use case for that now, so not really a priority.