use of org.compiere.process.ProcessInfoLog in project adempiere by adempiere.
the class CalculateReplenishPlan method doRunProductsSO.
/**
* @param miniMrpProducts
* @param productIds
* @param productSO
*/
@SuppressWarnings("resource")
private void doRunProductsSO(Map<Integer, MiniMRPProduct> miniMrpProducts, Set<Integer> productIds) {
String sql = getQueryForProductSO();
PreparedStatement pstmt = null;
ResultSet rs = null;
int paramCount = 1;
try {
pstmt = DB.prepareStatement(sql, trx);
pstmt.setTimestamp(paramCount++, dateFrom);
pstmt.setTimestamp(paramCount++, dateFrom);
pstmt.setTimestamp(paramCount++, dateTo);
pstmt.setInt(paramCount++, AD_Client_ID);
// Productids
pstmt.setArray(paramCount++, getSqlArray(productIds.toArray(), "numeric", DB.getConnectionRW(false)));
rs = pstmt.executeQuery();
while (rs.next()) {
int mProductID = rs.getInt("m_product_id");
int mOrderID = rs.getInt("c_order_id");
BigDecimal orderQty = rs.getBigDecimal("orderedqty");
int weekPromised = rs.getInt("weekordered");
BigDecimal qty = rs.getBigDecimal("orderedqty");
Date date = rs.getDate("datepromised");
if (miniMrpProducts.containsKey(mProductID)) {
MiniMRPProduct mrpProduct = miniMrpProducts.get(mProductID);
if (mrpProduct.isPhantom())
continue;
if (!mrpProduct.isPhantom)
setQtyAsDemand(mProductID, qty, date);
mrpProduct.explodeDemand(mOrderID, orderQty, weekPromised, miniMrpProducts);
} else {
log.log(Level.SEVERE, "Error in miniMrpProducts setup.");
getProcessInfo().setError(true);
getProcessInfo().addLog(new ProcessInfoLog(getProcessInfo().getAD_Process_ID(), new Timestamp(System.currentTimeMillis()), null, "Error in miniMrpProducts setup.>> "));
throw new AdempiereException("Error in miniMrpProducts setup.");
}
}
} catch (Exception e) {
log.log(Level.SEVERE, sql.toString(), e);
getProcessInfo().setError(true);
getProcessInfo().addLog(new ProcessInfoLog(getProcessInfo().getAD_Process_ID(), new Timestamp(System.currentTimeMillis()), null, "Failed to fetch products for mini MRP >> " + e.getMessage()));
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
use of org.compiere.process.ProcessInfoLog in project adempiere by adempiere.
the class CalculateReplenishPlan method processBOMLines.
/**
* Process of BOM Product lines
*
* @author Sachin Bhimani
* @param miniMrpProducts
* @param productIds
* @param M_Product_ID
*/
public void processBOMLines(Map<Integer, MiniMRPProduct> miniMrpProducts, Set<Integer> productIds, int M_Product_ID) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
if (M_Product_ID > 0) {
MProduct product = new MProduct(getCtx(), M_Product_ID, get_TrxName());
if (!product.isStocked())
return;
//MPPProductBOM bom = MPPProductBOM.getDefault(finishedProduct, get_TrxName());
pstmt = DB.prepareStatement(SQL_GET_BOMLINE_FOR_PROCESS, trx);
pstmt.setInt(1, M_Product_ID);
pstmt.setInt(2, AD_Client_ID);
pstmt.setInt(3, M_WarehouseID);
rs = pstmt.executeQuery();
while (rs.next()) {
int mProductID = rs.getInt(1);
BigDecimal qtyBom = rs.getBigDecimal(2);
MiniMRPProduct parentProduct = miniMrpProducts.get(M_Product_ID);
parentProduct.addMatireals(mProductID, qtyBom);
MiniMRPProduct miniMrpProduct = null;
// If material is already exploded.
if (miniMrpProducts.containsKey(mProductID)) {
miniMrpProduct = miniMrpProducts.get(mProductID);
explodeRequiredMaterials(miniMrpProduct, parentProduct, qtyBom);
} else {
miniMrpProduct = addProductToProcess(mProductID, rs, miniMrpProducts, productIds);
if (miniMrpProduct.isBOM() && miniMrpProduct.isVerified()) {
processBOMLines(miniMrpProducts, productIds, mProductID);
explodeRequiredMaterials(miniMrpProduct, parentProduct, qtyBom);
}
}
}
}
} catch (Exception e) {
log.log(Level.SEVERE, SQL_GET_BOMLINE_FOR_PROCESS, e);
getProcessInfo().setError(true);
getProcessInfo().addLog(new ProcessInfoLog(getProcessInfo().getAD_Process_ID(), new Timestamp(System.currentTimeMillis()), null, "Failed to process BOMLine : >> " + e.getMessage()));
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
use of org.compiere.process.ProcessInfoLog in project adempiere by adempiere.
the class CalculateReplenishPlan method generateProductInfo.
/**
* This method will fetch all the products based on selected category or the
* product. This will process BOMLine if product is finished good. It will
* fill the miniMRPProducts list & id of each product(including BOMlines) in
* productIds
*
* @param miniMrpProducts
* @param productIds
*/
private void generateProductInfo(Map<Integer, MiniMRPProduct> miniMrpProducts, Set<Integer> productIds) {
String sql = getQueryForProductDetails();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, trx);
pstmt.setInt(1, M_WarehouseID);
pstmt.setInt(2, AD_Client_ID);
if (p_M_Product_ID != 0)
pstmt.setInt(3, p_M_Product_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
int mProductID = rs.getInt("m_product_id");
if (!miniMrpProducts.containsKey(mProductID)) {
MiniMRPProduct miniMrpProduct = addProductToProcess(mProductID, rs, miniMrpProducts, productIds);
/* If Product is FG(Finished Goods) calculate it's BOMlines */
if (miniMrpProduct.isBOM() && miniMrpProduct.isVerified()) {
processBOMLines(miniMrpProducts, productIds, miniMrpProduct.getM_Product_ID());
}
}
}
} catch (Exception e) {
log.log(Level.SEVERE, sql.toString(), e);
getProcessInfo().setError(true);
getProcessInfo().addLog(new ProcessInfoLog(getProcessInfo().getAD_Process_ID(), new Timestamp(System.currentTimeMillis()), null, "Failed to fetch products for mini MRP >> " + e.getMessage()));
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
use of org.compiere.process.ProcessInfoLog in project adempiere by adempiere.
the class CalculateReplenishPlan method doRunOpenOrders.
/**
* @author Sachin Bhimani
* @param miniMrpProducts
* @param productIds
* @param type
*/
private void doRunOpenOrders(Map<Integer, MiniMRPProduct> miniMrpProducts, Set<Integer> productIds, String type) {
String sql = null;
if (type.equals(TYPE_MO))
sql = getQueryForOpenMO();
else if (type.equals(TYPE_PO))
sql = getQueryForOpenPO();
else if (type.equals(TYPE_RQ))
sql = getQueryForOpenRequisition();
PreparedStatement pstmt = null;
ResultSet rs = null;
int paramCount = 1;
try {
pstmt = DB.prepareStatement(sql, trx);
pstmt.setTimestamp(paramCount++, dateFrom);
pstmt.setTimestamp(paramCount++, dateFrom);
pstmt.setTimestamp(paramCount++, dateTo);
pstmt.setInt(paramCount++, AD_Client_ID);
// Productids
pstmt.setArray(paramCount++, getSqlArray(productIds.toArray(), "numeric", DB.getConnectionRW(false)));
if (type.equals(TYPE_RQ))
pstmt.setInt(paramCount++, docType_MRPRequisition);
rs = pstmt.executeQuery();
while (rs.next()) {
int M_Product_ID = rs.getInt("m_product_id");
BigDecimal orderQty = rs.getBigDecimal("orderedqty");
int weekPromised = rs.getInt("weekordered");
MiniMRPProduct product = miniMrpProducts.get(M_Product_ID);
if (type.equals(TYPE_PO)) {
int c_order_id = rs.getInt("c_order_id");
product.setSupplyLinePO(c_order_id, weekPromised, orderQty);
} else if (type.equals(TYPE_MO)) {
int m_production_id = rs.getInt("m_production_id");
product.setSupplyLineMO(m_production_id, weekPromised, orderQty);
} else if (type.equals(TYPE_RQ)) {
int M_Requisition_ID = rs.getInt("M_Requisition_ID");
product.setSupplyLineRQ(M_Requisition_ID, weekPromised, orderQty);
}
}
} catch (Exception e) {
log.log(Level.SEVERE, sql.toString(), e);
getProcessInfo().setError(true);
getProcessInfo().addLog(new ProcessInfoLog(getProcessInfo().getAD_Process_ID(), new Timestamp(System.currentTimeMillis()), null, "Failed to fetch products for mini MRP >> " + e.getMessage()));
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
Aggregations