groovy:計算金額
Callout
=============
import java.sql.Timestamp
import java.math.BigDecimal
import java.sql.PreparedStatement
import java.sql.ResultSet
import org.compiere.util.DB
import org.compiere.model.MUser
//@script:groovy:getQuotationForOrder
BigDecimal qty = null;
BigDecimal price = null;
BigDecimal disrate = null;
BigDecimal taxrate = null;
if (A_Value != null && A_Field.getColumnName().equals("數量") )
{
qty = (BigDecimal) A_Value;
price = A_Tab.getValue("單價");
disrate = A_Tab.getValue("折扣率");
taxrate = A_Tab.getValue("營業稅率");
}
if (A_Value != null && A_Field.getColumnName().equals("單價") )
{
price = (BigDecimal) A_Value;
qty = A_Tab.getValue("數量");
disrate = A_Tab.getValue("折扣率");
taxrate = A_Tab.getValue("營業稅率");
}
if (A_Value != null && A_Field.getColumnName().equals("折扣率") )
{
disrate = (BigDecimal) A_Value;
qty = A_Tab.getValue("數量");
price = A_Tab.getValue("單價");
taxrate = A_Tab.getValue("營業稅率");
}
if (A_Value != null && A_Field.getColumnName().equals("營業稅率") )
{
taxrate = (BigDecimal) A_Value;
qty = A_Tab.getValue("數量");
price = A_Tab.getValue("單價");
disrate = A_Tab.getValue("折扣率");
}
if (price != null && qty != null)
{
if (disrate==null) disrate = new BigDecimal(0);
if (taxrate==null) taxrate = new BigDecimal(0);
disrate = (new BigDecimal(1)).subtract(disrate.divide(new BigDecimal(100)));
taxrate = (new BigDecimal(1)).add(taxrate.divide(new BigDecimal(100)));
BigDecimal amt = price.multiply(qty).multiply(disrate).multiply(taxrate);
A_Tab.setValue("金額", amt);
}else{
A_Tab.setValue("金額", null);
}
result=""
沒有留言:
張貼留言