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
import org.compiere.util.Env
if (A_Value != null )
{
int id = ((Integer) A_Value).intValue();
// String sql ="SELECT \"狀態\" FROM \"確認\" WHERE \"確認_id\"=? ";
// PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, id);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
// if (rs.getString("狀態") != null) A_Tab.setValue("狀態",rs. getString ("狀態"));
if (id==1000000 )
{// 拉到 [確認] 才做
int id1 =Env.getContextAsInt(A_Ctx, "#AD_User_ID");
A_Tab.setValue("確認者_ID", new Integer(id1) );
int ordid=((Integer)A_Tab.getValue("銷貨單_ID")).intValue();
String sql1 ="SELECT a.\"出貨通知明細_id\", a.\"訂單明細_id\", a.\"數量\", a.\"贈品量\" FROM \"銷貨單明細\" a WHERE a.\"銷貨單_id\"=? ";
PreparedStatement pstmt1 = DB.prepareStatement(sql1, null);
pstmt1.setInt(1, ordid);
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next())
{
int lineid = rs1. getInt ("出貨通知明細_id");
int pdid = rs1. getInt ("訂單明細_id");
BigDecimal qty1 = rs1. getBigDecimal ("數量");
BigDecimal qty2 = rs1. getBigDecimal ("贈品量");
BigDecimal qty3 = qty2.add(qty1);
sqlx = "UPDATE \"出貨通知明細\" SET \"實際出貨數量\"='"+ qty1 +"',\"實際贈備品數量\"='"+qty2 +"' WHERE \"出貨通知明細_id\"="+lineid +" ";
DB.executeUpdate (sqlx );
sqly = "UPDATE \"訂單明細\" SET \"已銷貨數量\"='"+ qty3 +"' WHERE \"訂單明細_id\"="+pdid +" ";
DB.executeUpdate (sqly );
}
rs1.close();
pstmt1.close();
}
}
rs.close();
pstmt.close();
}
result=""
沒有留言:
張貼留言