While thinking this over, several things have come to my mind.
(1) Obviously you are using double for representing monetary values. This is
dangerous, as even simple calculations may result in values that are not
acceptable due to accounting customs or tax laws.
(2) The effort for checking is done for every Invoice anyway. You might
consider not checking at all, but setting the correct value for all Invoice
objects, disregarding the current value. (You'll have to avoid looping by
settingthe rule attribute no-loop to true.)
(3) You could design a (Java) function that caches the calculated value
based on the function arguments, but for simple formulas like the one you
have shown the effort for maintaining the cache is much higher that simply
calculating twice.
(4) According to (3), just don't worry about the duplication of the effort
for calculating twice, especially if you expect that the original value is
correct most of the time.
(5) Worrying about the duplication of the computational effort is fine, but
I'd worry even more about the duplication of the formula, which is a drag
for maintenance. Tax calculations and rebate strategies are subject to
change, and it would be advisable to have these formulas as static methods
in your application, just once.
-W
On 7/3/09, Shabbir Dhari <sdhari(a)hotmail.com> wrote:
Dear all
We are developing a financial business application that contains hundreds
of business rules for validations and calculations. In the calculation rules
we change the value of attribute if values past in the request is incorrect
e.g.
rule "TaxCalc"
when
$i : Invoice()
Invoice (totalTax != (round(salesTax + (gstRate * salesAmount /
100) + importDuty – govtRebate, 2)))
then
i.setTotalTax(round(salesTax + (gstRate * salesAmount / 100) +
importDuty – govtRebate, 2));
end
The above code works perfectly fine. Only problem is the perform
calculation twice. What I was looking if possible I can store calculated tax
in a variable and simply assign variable to attribute if rule condiation
fails. Some thing like:
rule "TaxCalc"
when
$i : Invoice()
Invoice (totalTax != calTax : (round(salesTax + (gstRate *
salesAmount / 100)+ importDuty – govtRebate, 2)))
then
i.setTotalTax(calTax);
end
But this does not work - shows system error at calculated value assignment.
Is there any work around?
------------------------------
Click here to find out more POP access for Hotmail is
here!<http://windowslive.ninemsn.com.au/article.aspx?id=802246>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users