W dniu 2010-07-29 15:14, chris snow pisze:
Hi BJ, I was responding to your comment:

"I like the design of Drool but think we need to go one step higher
and see this as how to run a business."

Guvnor has an abstraction on top of drools that is aimed at the
business user.  I don't know enough about drools to comment on how it
would be integrated with the business model.  I still have a lot more
learning to do around the subject...


I made some attempts with Drools as engine for future (probably open source) ERP. But it not like excel. You can write calculation rules but Drools would not order them automatically based on dependencies. (e.g. calc line total before sum of order). But in many ways it is very powerful tool.


There are example rules for simple Order (I could send whole project):

package com.sample

import com.sample.Order;
import com.sample.OrderItem
import com.sample.OrderTaxLine;
import com.sample.OrderTaxSummary;
import com.sample.OrderDiscount;
import com.sample.Product;
import com.sample.Tax;
import com.sample.TaxCalculator;
import com.sample.Discount;
import com.sample.DiscountCalculator;

dialect "java"

function Tax calcTax(int customerId,int productId) {
    return TaxCalculator.calculateTax(customerId,productId);
}

rule "order item price"
    dialect "mvel"
    agenda-group "Items"
    lock-on-active true
    salience  9
    when
        $item : OrderItem();
    then
    modify($item){
            setPrice($item.product.price);
    }
end

rule "order item amountNetto"
    dialect "mvel"
    lock-on-active true
    agenda-group "Items"
    salience 8
    when
        $item : OrderItem();
    then
    modify($item){
        setAmountNetto($item.price * $item.quantity);
    }
end

rule "order item tax"
    dialect "mvel"
    lock-on-active true
    agenda-group "Items"
    salience  7
    when
        $item : OrderItem();
    then
    modify($item){
setTaxes(calcTax($item.order.partyDelivery.partyId.intValue(),$item.product.productId.intValue()));
    }
end

rule "order item amountTax"
    dialect "mvel"
    lock-on-active true
    agenda-group "Items"
    salience 6
    when
        $item : OrderItem();
    then
    modify($item){
        setAmountTax($item.tax.rateTax * $item.amountNetto);
    }
end

rule "order item amountBrutto"
    dialect "mvel"
    lock-on-active true
    agenda-group "Items"
    salience 5
    when
        $item : OrderItem();
    then
    modify($item){
        setAmountBrutto($item.amountNetto + $item.amountTax);
    }
end

rule "Switch to Order"
    dialect "mvel"
    lock-on-active true
    agenda-group "Items"
    salience -100000
    when
        $item : OrderItem();
    then
        drools.setFocus("Order");
end

rule "order calucations"
    dialect "mvel"
    lock-on-active true
    agenda-group "Order"
    salience 4
    when
        $order : Order();
$amountTax : Number() from accumulate (OrderItem( order==$order, amountTax!=null,$amount:amountTax), sum($amount));
    then
        $order.amountTax = $amountTax;
end

rule "order calucations 2"
    dialect "mvel"
    lock-on-active true
    agenda-group "Order"
    salience 3
    when
        $order : Order();
$amountNetto : Number() from accumulate (OrderItem( order==$order, amountNetto!=null, $amount:amountNetto), sum($amount));
    then
        $order.amountNetto = $amountNetto;
end


rule "order calucations 3"
    dialect "mvel"
    lock-on-active true
    agenda-group "Order"
    salience 2
    when
        $order : Order(amountTax !=null,amountNetto!=null);
    then
        $order.amountBrutto = ($order.amountTax + $order.amountNetto);
end



Maybe facts assertions should not be like above "OrderLine exists" but e.g. "quantity of order line changed"



Reply via email to