Why not simply use something like this:-
 
rule "TaxCalc"
    when
         $i : Invoice($st : salesTax, $gst : gstRate, $sa : salesAmount,
$id : importDuty, $gr : govtRebate)
    then
         $i.setTotalTax(round($st + ($gst * $sa / 100) + $id - $gr, 2));
         update($i);
end

What do you gain by checking whether the Total Tax is different from the
value of the calculation? I must be missing something from your
simplified example?!?
 
(I think, big disclaimer!!) you could achieve your requirement using
eval and a tax value function that uses a cache under the hood, much
like the following:-
 
rule "TaxCalc"
    when
         $i : Invoice($tt : totalTax, $st : salesTax, $gst : gstRate,
$sa : salesAmount, $id : importDuty, $gr : govtRebate)
         eval(Invoice($tt != taxFunction($st, $gst, $sa, Sid, $gr))
    then
         $i.setTotalTax(taxFunction($st, $gst, $sa, Sid, $gr);
         update($i);
end

Evals cannot be indexed so you take a performance hit.
 
With kind regards,
 
Mike



________________________________

        From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Shabbir Dhari
        Sent: 03 July 2009 01:24
        To: rules-users@lists.jboss.org
        Subject: [rules-users] Formula value assginment in LHS
        
        
        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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to