use of org.compiere.model.X_M_ReplenishPlanLine in project adempiere by adempiere.
the class CalculateReplenishPlan method insertTotalSupplyLine.
/**
* Insert total Supply line, summation of confirmed purchase order and
* Requisition
*
* @author Sachin Bhimani
* @param miniMrpProduct
* @param subTotalSupplyLine
* @param isPO
*/
public void insertTotalSupplyLine(MiniMRPProduct miniMrpProduct, Map<Integer, BigDecimal> subTotalSupplyLine, boolean isPO) {
if (!subTotalSupplyLine.isEmpty()) {
X_M_ReplenishPlanLine miniMRP = getX_M_ReplenishPlanLine(miniMrpProduct, lineNo, isPO ? TYPE_TOTAL_SUPPLY_LINE_PO : TYPE_TOTAL_SUPPLY_LINE_RQ);
// Insert Total Supply line.
for (Integer week : subTotalSupplyLine.keySet()) {
BigDecimal qty = subTotalSupplyLine.get(week);
setWeeklyData(miniMRP, week, qty);
}
miniMRP.saveEx();
}
lineNo += 10;
}
use of org.compiere.model.X_M_ReplenishPlanLine in project adempiere by adempiere.
the class CalculateReplenishPlan method insertClosingBalanceLine.
/**
* Insert closing Balance Line.
*
* @author Sachin Bhimani
* @param miniMrpProduct
* @param closingBalanceLine
*/
public void insertClosingBalanceLine(MiniMRPProduct miniMrpProduct, Map<Integer, BigDecimal> closingBalanceLine) {
if (!closingBalanceLine.isEmpty()) {
X_M_ReplenishPlanLine miniMRP = getX_M_ReplenishPlanLine(miniMrpProduct, lineNo, TYPE_CLOSING_BALANCE_LINE);
for (Integer week : closingBalanceLine.keySet()) {
setWeeklyData(miniMRP, week, closingBalanceLine.get(week));
}
miniMRP.saveEx();
}
}
use of org.compiere.model.X_M_ReplenishPlanLine in project adempiere by adempiere.
the class CalculateReplenishPlan method insertProductionDemand.
/**
* @param miniMrpProduct
* @param totalDemandLine
* @param mProduction_ID
* @param documentNo
* @param promisedDate
* @param qtyUsed
* @param prodType
*/
private void insertProductionDemand(MiniMRPProduct miniMrpProduct, Map<Integer, BigDecimal> totalDemandLine, int mProduction_ID, String documentNo, Timestamp promisedDate, BigDecimal qtyUsed, String prodType) {
X_M_ReplenishPlanLine miniMRP = getX_M_ReplenishPlanLine(miniMrpProduct, lineNo, TYPE_PRODUCT_ORDER_DEMAND);
miniMRP.setM_Production_ID(mProduction_ID);
String datePromised = null;
int week = 0;
datePromised = requiredFormat.format(promisedDate);
week = DB.getSQLValue(trx, SQL_GET_ISO_WEEKNO, dateFrom, promisedDate, promisedDate, promisedDate);
miniMRP.setProductionInfo(documentNo + " - " + datePromised + " - " + prodType);
setWeeklyData(miniMRP, week, qtyUsed);
if (totalDemandLine.containsKey(week)) {
BigDecimal totalDemand = totalDemandLine.get(week);
if (totalDemand == null) {
totalDemand = Env.ZERO;
}
qtyUsed = qtyUsed.add(totalDemand);
}
totalDemandLine.put(week, qtyUsed);
miniMRP.saveEx();
lineNo += 10;
}
use of org.compiere.model.X_M_ReplenishPlanLine 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.X_M_ReplenishPlanLine 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