use of org.compiere.model.I_M_MovementLine in project adempiere by adempiere.
the class InventoryUtil method getLineCosts.
private static BigDecimal getLineCosts(PO line, BigDecimal lineQty, boolean isSOTrx) {
ArrayList<Object> params = new ArrayList<Object>();
String sql = "SELECT" + " SUM(" + MCostDetail.COLUMNNAME_Amt + ")" + ",SUM(" + MCostDetail.COLUMNNAME_Qty + ")" + " FROM " + MCostDetail.Table_Name + " WHERE " + line.get_TableName() + "_ID=?";
params.add(line.get_ID());
if (line instanceof I_M_MovementLine) {
sql += " AND " + MCostDetail.COLUMNNAME_IsSOTrx + "=?";
params.add(isSOTrx);
}
PreparedStatement pstmt = null;
ResultSet rs = null;
BigDecimal costs = null;
BigDecimal qty = null;
try {
pstmt = DB.prepareStatement(sql, line.get_TrxName());
DB.setParameters(pstmt, params);
rs = pstmt.executeQuery();
if (rs.next()) {
costs = rs.getBigDecimal(1);
qty = rs.getBigDecimal(2);
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (costs == null)
costs = Env.ZERO;
if (qty == null)
qty = Env.ZERO;
// Convert Qty sign from Absolute to Relative (for comparation purposes)
if (isSOTrx)
qty = qty.negate();
// Check Line Qty (if specified)
if (lineQty != null && qty.compareTo(lineQty) != 0) {
throw new RuntimeException("CostDetail Qty Not Match - TargetQty=" + lineQty + ", ActualQty=" + qty + ", Costs=" + costs);
}
return costs;
}
Aggregations