Model Validator Table Event
====================
import groovy.sql.Sql
import java.sql.Timestamp
import java.sql.PreparedStatement
import java.sql.ResultSet
import org.compiere.util.Env
import org.compiere.util.DB
// A_Ctx A_PO A_Type A_Event
int client=Env.getContextAsInt(A_Ctx, "AD_Client_ID");
int org=Env.getContextAsInt(A_Ctx, "AD_Org_ID");
int uid=Env.getContextAsInt(A_Ctx, "#AD_User_ID");
// int parent_id=Env.getContextAsInt(A_Ctx, "銷貨單_ID");
int parent_id=((Integer)A_PO.get_Value("銷貨單_ID")).intValue();
String sql = "SELECT SUM(原幣銷貨金額),SUM(本幣銷貨金額) FROM 銷貨單明細 WHERE 銷貨單_id =? ";
PreparedStatement pstmt = DB.prepareStatement(sql, A_PO.get_TrxName());
pstmt.setInt(1, parent_id);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
BigDecimal price = rs.getBigDecimal (1);
BigDecimal tprice = rs.getBigDecimal (2);
if (price ==null) price = new BigDecimal(0);
if (tprice ==null) tprice = new BigDecimal(0);
DB.executeUpdateEx("UPDATE 銷貨單 SET 原幣銷貨金額="+price+" , 本幣銷貨金額="+tprice+", 原幣銷貨稅額="+price+" *營業稅率/100, 本幣銷貨稅額="+tprice+" *營業稅率/100, 本幣合計="+tprice+"*(1+營業稅率/100), 原幣合計="+price+"*(1+營業稅率/100) WHERE 銷貨單_id ="+parent_id, A_PO.get_TrxName());
}
rs.close();
pstmt.close();
沒有留言:
張貼留言