[rules-users] one rule not fired properly.

manyasri.m manyasri.m at gmail.com
Wed Nov 26 13:52:17 EST 2008


Hi,
  
The business requirements are as follows.

We have 3 rules which need to be fired depending upon the criteria which
will be met.  We have an order object which has various orderline items and
the following business rules need to be executed depending upon the inserted
facts.
•	If a particular item is on discount, the discount % is applied to the line
item.
•	If the quantity for a particular item is greater than 10, an added 10%
discount is given for the order.
•	If the total order amount is greater than 1000, then an additional 5%
discount is given on the order.

The above rules need to be executed at the same time.

In This case i tryed all the conditions it's working fine.But,
rule "Apply 5% discount if Total Price greater than 1000"  is not fired.

package com.sample.orderItem

import com.sample.orderItem.DiscountDetails
import com.sample.orderItem.ItemQuantity
import com.sample.orderItem.PriceCal
import com.sample.orderItem.PriceDetails

expander Sample.dsl



rule "Purchase Item"
    salience 10
 when
   > $p:PriceCal(itemName:itemName, quantity:quantity,
discountPer:discountPer, itemprice:itemprice, totalprice:totalprice,
totalPriceAfterDiscount:totalPriceAfterDiscount)
  
 then
   >  System.out.println("Purchased Item     : " +itemName ); 
   >  System.out.println("Itemprice Prise    : " +itemprice);
   >  System.out.println("Itemprice quantity : " +quantity); 
   >  System.out.println("discountPer        : " +discountPer);
end 

rule "Item Discountper equal to null"
    salience 10
 when
   > $p:PriceCal(itemName:itemName, quantity:quantity,
discountPer:discountPer, itemprice:itemprice, totalprice:totalprice,
totalPriceAfterDiscount:totalPriceAfterDiscount)
   > eval($p.getDiscountPer() == null)
 then
 
   >  $p.setTotalprice(totalprice+itemprice*quantity);
   >  System.out.println("totalprice non Disc         : "
+$p.getTotalprice() );
end 

rule "Item Discountper not equal to null"
    salience 10
 when
				
   > $p:PriceCal(itemName:itemName, quantity:quantity,
discountPer:discountPer, itemprice:itemprice, totalprice:totalprice,
totalPriceAfterDiscount:totalPriceAfterDiscount)
   > eval($p.getDiscountPer() != null)
 then
   
   >  $p.setItemprice(itemprice*(100-Integer.parseInt(discountPer))/100);
   >  System.out.println("default discountl: "+$p.getItemprice());
   >  $p.setTotalprice(totalprice+$p.getItemprice()*quantity);
   >  System.out.println("Totalprice         : " +$p.getTotalprice() );
end 

rule "Apply 10% discount if quantity greater than 10"
				
 when
   > $p:PriceCal(itemName:itemName, quantity:quantity,
discountPer:discountPer, itemprice:itemprice, totalprice:totalprice,
totalPriceAfterDiscount:totalPriceAfterDiscount)
   > eval($p.getQuantity() > 10)
   
 then
   >  $p.setTotalprice($p.getTotalprice()*0.90);
   >  System.out.println("Apply 10% discount if quantity greater than 10        
: " +$p.getTotalprice() ); 
   
end 

rule "Apply 5% discount if Total Price greater than 1000"

 when
   > $p:PriceCal(itemName:itemName, quantity:quantity,
discountPer:discountPer, itemprice:itemprice, totalprice:totalprice,
totalPriceAfterDiscount:totalPriceAfterDiscount)
   > eval($p.getTotalprice() > 1000)
  
 then
    
   >  $p.setTotalprice($p.getTotalprice()*0.95);
   >  System.out.println("Apply 5% discount if Total Price greater than 1000       
: " +$p.getTotalprice() ); 
  
end 

Result:
-------
Purchased Item     : abc
Itemprice Prise    : 100.0
Itemprice quantity : 13
discountPer          : 5
default discount   l: 95.0
Totalprice         : 1235.0
Apply 10% discount if quantity greater than 10         : 1111.5


please give me proper suggestion of this.


thanks,
manyasri.
 
-- 
View this message in context: http://www.nabble.com/one-rule-not-fired-properly.-tp20706884p20706884.html
Sent from the drools - user mailing list archive at Nabble.com.





More information about the rules-users mailing list