2014年1月27日 星期一

groovy:sum淨重& 毛重-packinglist

groovy:sum淨重& 毛重-packinglist
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, "packinglist_ID");
int parent_id=((Integer)A_PO.get_Value("packinglist_ID")).intValue();

String sql = "SELECT SUM(淨重),SUM(毛重) FROM packinglistline WHERE packinglist_id =? ";
PreparedStatement pstmt = DB.prepareStatement(sql, A_PO.get_TrxName());
pstmt.setInt(1, parent_id);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
BigDecimal nw = rs.getBigDecimal (1);
BigDecimal gw = rs.getBigDecimal (2);
if (nw==null)  nw = new BigDecimal(0);
if (gw==null)  gw = new BigDecimal(0);
DB.executeUpdateEx("UPDATE packinglist SET 總淨重="+nw +" , 總毛重="+gw +" WHERE packinglist_id ="+parent_id,  A_PO.get_TrxName());
}
rs.close();
pstmt.close();

result=""

沒有留言:

張貼留言