use of org.compiere.model.MProduction in project adempiere by adempiere.
the class CalculateReplenishPlan method insertOrderDemands.
public Map<Integer, BigDecimal> insertOrderDemands(MiniMRPProduct miniMrpProduct) {
Map<Integer, Map<Integer, BigDecimal>> orderDemands = miniMrpProduct.getDemand();
Map<Integer, BigDecimal> totalDemandLine = new HashMap<Integer, BigDecimal>();
// From MRP Demand MAP
if (!orderDemands.isEmpty()) {
for (Integer orderId : orderDemands.keySet()) {
Map<Integer, BigDecimal> weeklyDemand = orderDemands.get(orderId);
if (weeklyDemand.size() > 0) {
X_M_ReplenishPlanLine miniMRP = getX_M_ReplenishPlanLine(miniMrpProduct, lineNo, TYPE_PRODUCT_ORDER_DEMAND);
miniMRP.setC_Order_ID(orderId);
MOrder order = new MOrder(ctx, orderId, trx);
String datePromised = requiredFormat.format(order.getDatePromised());
miniMRP.setOrderInfo(order.getDocumentNo() + " - " + datePromised);
for (Integer week : weeklyDemand.keySet()) {
BigDecimal qty = weeklyDemand.get(week);
setWeeklyData(miniMRP, week, qty);
if (totalDemandLine.containsKey(week)) {
qty = qty.add(totalDemandLine.get(week));
}
totalDemandLine.put(week, qty);
}
miniMRP.saveEx();
}
lineNo += 10;
}
}
// Get Planned Production Demand as per product wise.
PreparedStatement pstmt = null;
ResultSet rs = null;
int paramCount = 1;
try {
pstmt = DB.prepareStatement(SQL_PRODUCTWISE_INFO_FROM_PRODUCTION, trx);
pstmt.setInt(paramCount++, miniMrpProduct.getM_Product_ID());
pstmt.setInt(paramCount++, docType_PlannedOrder);
pstmt.setTimestamp(paramCount++, dateFrom);
pstmt.setTimestamp(paramCount++, dateTo);
rs = pstmt.executeQuery();
while (rs.next()) {
insertProductionDemand(miniMrpProduct, totalDemandLine, rs.getInt("M_Production_ID"), rs.getString("DocumentNo"), rs.getTimestamp("DatePromised"), rs.getBigDecimal("QtyUsed"), "Planned");
}
} catch (Exception e) {
log.log(Level.SEVERE, SQL_PRODUCTWISE_INFO_FROM_PRODUCTION, e);
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Add demand for SubLevel Product which is Confirmed production.
int[] productionID = DB.getIDsEx(trx, SQL_GET_PRODUCTION_SUBPRODUCTWISE, miniMrpProduct.getM_Product_ID(), dateFrom, dateTo, docType_PlannedOrder);
for (int mProdID : productionID) {
MProduction production = new MProduction(ctx, mProdID, trx);
BigDecimal qty = DB.getSQLValueBD(trx, "SELECT SUM(QtyUsed) FROM M_ProductionLine WHERE M_Production_ID = ? AND M_Product_ID = ? AND AD_Client_ID=?", mProdID, miniMrpProduct.getM_Product_ID(), AD_Client_ID);
if (qty == null) {
qty = Env.ZERO;
}
insertProductionDemand(miniMrpProduct, totalDemandLine, production.getM_Production_ID(), production.getDocumentNo(), production.getDatePromised(), qty, "Confirm");
}
if (totalDemandLine != null && !totalDemandLine.isEmpty())
insertTotalLine(miniMrpProduct, totalDemandLine, TYPE_TOTAL_DEMAND_LINE);
return totalDemandLine;
}
use of org.compiere.model.MProduction in project adempiere by adempiere.
the class CalculateReplenishPlan method insertSupplyLineMO.
/**
* Insert Production for Non Planned Orders (Confirmed) and Planned Orders
*
* @author Sachin Bhimani
* @param miniMrpProduct
* @param totalSupplyLine
* @param subTotalSupplyLine
* @param isPlannedOrder
*/
public void insertSupplyLineMO(MiniMRPProduct miniMrpProduct, Map<Integer, BigDecimal> totalSupplyLine, Map<Integer, BigDecimal> subTotalSupplyLine, boolean isPlannedOrder) {
Map<Integer, Map<Integer, BigDecimal>> supplyLineMO = new TreeMap<Integer, Map<Integer, BigDecimal>>(miniMrpProduct.getSupplyLineMO());
if (!supplyLineMO.isEmpty()) {
for (Integer M_Production_ID : supplyLineMO.keySet()) {
Map<Integer, BigDecimal> weeklyDemand = supplyLineMO.get(M_Production_ID);
MProduction production = new MProduction(ctx, M_Production_ID, trx);
if ((isPlannedOrder == false && production.getC_DocType_ID() != docType_PlannedOrder) || (isPlannedOrder && production.getC_DocType_ID() == docType_PlannedOrder)) {
if (weeklyDemand.size() > 0) {
X_M_ReplenishPlanLine miniMRP = getX_M_ReplenishPlanLine(miniMrpProduct, lineNo, isPlannedOrder ? TYPE_SUPPLY_LINE_MO_PLANNED : TYPE_SUPPLY_LINE_MO_NONPLANNED);
miniMRP.setM_Production_ID(M_Production_ID);
String datePromished = requiredFormat.format(production.getDatePromised());
miniMRP.setProductionInfo(production.getDocumentNo() + " - " + datePromished);
for (Integer week : weeklyDemand.keySet()) {
BigDecimal qty = weeklyDemand.get(week);
setWeeklyData(miniMRP, week, qty);
if (totalSupplyLine.containsKey(week)) {
qty = qty.add(totalSupplyLine.get(week));
}
totalSupplyLine.put(week, qty);
BigDecimal qtyProd = weeklyDemand.get(week);
if (subTotalSupplyLine.containsKey(week)) {
qtyProd = qtyProd.add(subTotalSupplyLine.get(week));
}
subTotalSupplyLine.put(week, qtyProd);
}
miniMRP.saveEx();
}
lineNo += 10;
}
}
}
}
Aggregations