Search in sources :

Example 11 with MProduct

use of org.compiere.model.MProduct in project adempiere by adempiere.

the class CalculateReplenishPlan method runProcessCalculatePlannedQty.

private void runProcessCalculatePlannedQty(Map<Integer, MiniMRPProduct> miniMrpProducts) {
    for (Date date : mapDemand.keySet()) {
        Map<Integer, BigDecimal> mapOrderQty = mapDemand.get(date);
        for (Integer productID : mapOrderQty.keySet()) {
            MProduct product = new MProduct(getCtx(), productID, get_TrxName());
            if (!product.isStocked())
                return;
            BigDecimal demandQty = mapOrderQty.get(productID);
            if (demandQty.compareTo(Env.ZERO) != 0) {
                MiniMRPProduct mrp = miniMrpProducts.get(productID);
                if (mrp == null) {
                    MProduct p = MProduct.get(ctx, productID);
                    String error = "Please check Product=" + p.getValue() + " replenishment parameters may not be setup properly.";
                    log.severe(error);
                    throw new AdempiereException(error);
                }
                Integer nonPhantomProduct = (mrp.isPhantom() && mrp.isBOM() ? 0 : productID);
                // (MRP,DateOfDemand,PID,DQty,Level,NonPhontomPID)
                createPlannedQtyMap(miniMrpProducts, date, productID, demandQty, 0, nonPhantomProduct);
            }
        }
    }
}
Also used : MProduct(org.compiere.model.MProduct) AdempiereException(org.adempiere.exceptions.AdempiereException) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 12 with MProduct

use of org.compiere.model.MProduct 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;
    }
}
Also used : MProduct(org.compiere.model.MProduct) AdempiereException(org.adempiere.exceptions.AdempiereException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ProcessInfoLog(org.compiere.process.ProcessInfoLog) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 13 with MProduct

use of org.compiere.model.MProduct in project adempiere by adempiere.

the class VMRPDetailed method selectAttributeSetInstance.

// prepareTable
/**
	 * filter by Attribute Set Instance
	 */
private void selectAttributeSetInstance() {
    int m_warehouse_id = getM_Warehouse_ID();
    int m_product_id = getM_Product_ID();
    if (m_product_id <= 0)
        return;
    MProduct product = MProduct.get(getCtx(), m_product_id);
    MWarehouse wh = MWarehouse.get(getCtx(), m_warehouse_id);
    String title = product.get_Translation(MProduct.COLUMNNAME_Name) + " - " + wh.get_Translation(MWarehouse.COLUMNNAME_Name);
    //	Yamel Senih FR [ 114 ] 2015-11-23
    PAttributeInstance pai = new PAttributeInstance(m_frame.getCFrame(), title, m_warehouse_id, 0, m_product_id, 0);
    if (pai.getM_AttributeSetInstance_ID() != -1) {
        fAttrSetInstance_ID.setText(pai.getM_AttributeSetInstanceName());
        fAttrSetInstance_ID.setValue(new Integer(pai.getM_AttributeSetInstance_ID()));
    } else {
        fAttrSetInstance_ID.setValue(Integer.valueOf(0));
    }
}
Also used : MProduct(org.compiere.model.MProduct) PAttributeInstance(org.compiere.apps.search.PAttributeInstance) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) MWarehouse(org.compiere.model.MWarehouse)

Example 14 with MProduct

use of org.compiere.model.MProduct in project adempiere by adempiere.

the class CAbstractBOMTree method handleTreeEvent.

private void handleTreeEvent(MouseEvent e) {
    String text = model.getBOMMessenger().getToolTipText(e);
    if (text != null) {
        nodeDescription.setText(text);
    }
    if (e.getButton() == MouseEvent.BUTTON3) {
        model.getTree().setSelectionPath(model.getTree().getPathForLocation(e.getX(), e.getY()));
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) model.getTree().getSelectionPath().getLastPathComponent();
        if (node.getUserObject() instanceof BOMLineWrapper) {
            popupBOMLine.show(e.getComponent(), e.getX(), e.getY());
        } else if (node.getUserObject() instanceof BOMWrapper) {
            popupBOM.show(e.getComponent(), e.getX(), e.getY());
        } else if (node.getUserObject() instanceof MProduct) {
            popupRoot.show(e.getComponent(), e.getX(), e.getY());
        } else if (node.getUserObject() instanceof MPPOrder) {
            popupRoot.show(e.getComponent(), e.getX(), e.getY());
        }
    }
    SwingTool.setCursorsFromChild(e.getComponent(), false);
}
Also used : MProduct(org.compiere.model.MProduct) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) BOMWrapper(org.eevolution.model.wrapper.BOMWrapper) MPPOrder(org.eevolution.model.MPPOrder) BOMLineWrapper(org.eevolution.model.wrapper.BOMLineWrapper)

Example 15 with MProduct

use of org.compiere.model.MProduct in project adempiere by adempiere.

the class ProductNotOnPriceListException method buildMessage.

private static final String buildMessage(MProductPricing pp, int documentLineNo) {
    StringBuffer sb = new StringBuffer();
    if (documentLineNo > 0) {
        if (sb.length() > 0)
            sb.append(", ");
        sb.append("@Line@:").append(documentLineNo);
    }
    if (pp.getM_Product_ID() > 0) {
        MProduct p = MProduct.get(Env.getCtx(), pp.getM_Product_ID());
        if (sb.length() > 0)
            sb.append(", ");
        sb.append("@M_Product_ID@:").append(p == null ? "?" : p.get_Translation(MProduct.COLUMNNAME_Name));
    }
    if (pp.getM_PriceList_ID() > 0) {
        MPriceList pl = MPriceList.get(Env.getCtx(), pp.getM_PriceList_ID(), null);
        if (sb.length() > 0)
            sb.append(", ");
        sb.append("@M_PriceList_ID@:").append(pl == null ? "?" : pl.get_Translation(MPriceList.COLUMNNAME_Name));
    }
    if (pp.getPriceDate() != null) {
        DateFormat df = DisplayType.getDateFormat(DisplayType.Date);
        if (sb.length() > 0)
            sb.append(", ");
        sb.append("@Date@:").append(df.format(pp.getPriceDate()));
    }
    //
    sb.insert(0, "@" + AD_Message + "@ - ");
    return sb.toString();
}
Also used : MProduct(org.compiere.model.MProduct) DateFormat(java.text.DateFormat) MPriceList(org.compiere.model.MPriceList)

Aggregations

MProduct (org.compiere.model.MProduct)180 BigDecimal (java.math.BigDecimal)70 AdempiereException (org.adempiere.exceptions.AdempiereException)30 ArrayList (java.util.ArrayList)29 Query (org.compiere.model.Query)29 ResultSet (java.sql.ResultSet)19 MLocator (org.compiere.model.MLocator)18 PreparedStatement (java.sql.PreparedStatement)17 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)17 KeyNamePair (org.compiere.util.KeyNamePair)17 MCostElement (org.compiere.model.MCostElement)16 MStorage (org.compiere.model.MStorage)16 MAcctSchema (org.compiere.model.MAcctSchema)14 MCost (org.compiere.model.MCost)14 MPPProductBOM (org.eevolution.model.MPPProductBOM)14 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)14 SQLException (java.sql.SQLException)13 Timestamp (java.sql.Timestamp)13 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)13 Vector (java.util.Vector)12