Search in sources :

Example 6 with MProduction

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) X_M_ReplenishPlanLine(org.compiere.model.X_M_ReplenishPlanLine) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) MOrder(org.compiere.model.MOrder) AdempiereException(org.adempiere.exceptions.AdempiereException) ResultSet(java.sql.ResultSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) MProduction(org.compiere.model.MProduction)

Example 7 with MProduction

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;
            }
        }
    }
}
Also used : X_M_ReplenishPlanLine(org.compiere.model.X_M_ReplenishPlanLine) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) BigDecimal(java.math.BigDecimal) MProduction(org.compiere.model.MProduction)

Aggregations

MProduction (org.compiere.model.MProduction)7 BigDecimal (java.math.BigDecimal)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 MMatchInv (org.compiere.model.MMatchInv)2 MMatchPO (org.compiere.model.MMatchPO)2 MProductionLine (org.compiere.model.MProductionLine)2 X_M_ReplenishPlanLine (org.compiere.model.X_M_ReplenishPlanLine)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 MCost (org.compiere.model.MCost)1 MDocType (org.compiere.model.MDocType)1 MInOutLine (org.compiere.model.MInOutLine)1 MInventoryLine (org.compiere.model.MInventoryLine)1 MMovementLine (org.compiere.model.MMovementLine)1 MOrder (org.compiere.model.MOrder)1