Search in sources :

Example 56 with MProduct

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

the class VTreeBOM method action_loadBOM.

//	actionPerformed
/**
	 * 	Action: Fill Tree with all nodes
	 */
private void action_loadBOM() {
    int M_Product_ID = getM_Product_ID();
    if (M_Product_ID == 0)
        return;
    MProduct product = MProduct.get(getCtx(), M_Product_ID);
    DefaultMutableTreeNode parent = new DefaultMutableTreeNode(productSummary(product, false));
    dataBOM.clear();
    m_level = 0;
    if (isImplosion()) {
        for (MPPProductBOMLine bomline : MPPProductBOMLine.getByProduct(product)) {
            parent.add(parent(bomline));
        }
        m_tree = new JTree(parent);
    } else {
        for (MPPProductBOM bom : MPPProductBOM.getProductBOMs(product)) {
            parent.add(parent(bom));
        }
        m_tree = new JTree(parent);
    }
    m_tree.addTreeSelectionListener(this);
    treePane.getViewport().add(m_tree, null);
    loadTableBOM();
    dataPane.getViewport().add(tableBOM, null);
    // 4Layers - Set divider location
    splitPane.setDividerLocation(DIVIDER_LOCATION);
// 4Layers - end
}
Also used : MProduct(org.compiere.model.MProduct) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) MPPProductBOM(org.eevolution.model.MPPProductBOM)

Example 57 with MProduct

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

the class VProductConfigurationBOM method getProductFromMPPProductBOM.

//	createMainPanel
/**
	 * 	Get last product of a BOM
	 *	@return MProduct
	 */
private MProduct getProductFromMPPProductBOM(int PP_Product_BOM_ID) {
    MProduct m_product = null;
    try {
        StringBuffer sql1 = new StringBuffer("select m_product_id from pp_product_bom where pp_product_bom_id = ?");
        PreparedStatement pstmt = DB.prepareStatement(sql1.toString(), null);
        pstmt.setInt(1, PP_Product_BOM_ID);
        ResultSet rs = pstmt.executeQuery();
        //
        if (rs.next()) {
            int m_product_id = rs.getInt(1);
            m_product = new MProduct(Env.getCtx(), m_product_id, null);
        }
        rs.close();
        pstmt.close();
    } catch (SQLException s) {
        log.log(Level.SEVERE, "ERROR:", s);
    }
    return m_product;
}
Also used : MProduct(org.compiere.model.MProduct) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 58 with MProduct

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

the class VProductConfigurationBOM method addBOMLine.

//	addBOMLines
/**
	 * 	Add BOM Line to this.
	 * 	Calls addBOMLines if added product is a BOM
	 * 	@param line BOM Line
	 * 	@param qty quantity
	 */
private void addBOMLine(MPPProductBOMLine line, BigDecimal qty) {
    log.fine("In addBOMLine");
    log.fine(line.toString());
    //FIXME:  add a bomtype accessor here
    String bomType = line.getComponentType();
    if (bomType == null)
        bomType = MProductBOM.BOMTYPE_StandardPart;
    BigDecimal lineQty = new BigDecimal(0);
    MProduct product = getProductFromMPPProductBOMLine(line);
    if (product == null)
        return;
    addDisplay(line.getM_Product_ID(), product.getM_Product_ID(), bomType, product.getName(), lineQty, line.getPP_Product_BOM_ID(), line.getFeature(), line.get_ID());
}
Also used : MProduct(org.compiere.model.MProduct) BigDecimal(java.math.BigDecimal)

Example 59 with MProduct

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

the class PosKeyGenerate method doIt.

/**
	 * Generate keys for each product
	 */
@Override
protected String doIt() throws Exception {
    if (posKeyLayoutId == 0)
        throw new FillMandatoryException("C_POSKeyLayout_ID");
    int count = 0;
    String where = "";
    Object[] params = new Object[] {};
    if (productCategoryId > 0) {
        where = "M_Product_Category_ID = ? ";
        params = new Object[] { productCategoryId };
    }
    Query query = new Query(getCtx(), MProduct.Table_Name, where, get_TrxName()).setParameters(params).setOnlyActiveRecords(true).setOrderBy("Value");
    List<MProduct> products = query.list();
    for (MProduct product : products) {
        MPOSKey key = new MPOSKey(getCtx(), 0, get_TrxName());
        key.setName(product.getName());
        key.setM_Product_ID(product.getM_Product_ID());
        key.setC_POSKeyLayout_ID(posKeyLayoutId);
        key.setSeqNo(count * 10);
        key.setQty(Env.ONE);
        key.saveEx();
        count++;
    }
    return "@Created@ " + count;
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MPOSKey(org.compiere.model.MPOSKey) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 60 with MProduct

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

the class ProductUOMConvert method doIt.

//	prepare
/**
	 * 	Process
	 *	@return message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    if (p_M_Product_ID == 0 || p_M_Product_To_ID == 0 || p_M_Locator_ID == 0 || p_Qty == null || Env.ZERO.compareTo(p_Qty) == 0)
        throw new AdempiereUserError("Invalid Parameter");
    //
    MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
    MProduct productTo = MProduct.get(getCtx(), p_M_Product_To_ID);
    log.info("Product=" + product + ", ProductTo=" + productTo + ", M_Locator_ID=" + p_M_Locator_ID + ", Qty=" + p_Qty);
    MUOMConversion[] conversions = MUOMConversion.getProductConversions(getCtx(), product.getM_Product_ID());
    MUOMConversion conversion = null;
    for (int i = 0; i < conversions.length; i++) {
        if (conversions[i].getC_UOM_To_ID() == productTo.getC_UOM_ID())
            conversion = conversions[i];
    }
    if (conversion == null)
        throw new AdempiereUserError("@NotFound@: @C_UOM_Conversion_ID@");
    MUOM uomTo = MUOM.get(getCtx(), productTo.getC_UOM_ID());
    BigDecimal qtyTo = p_Qty.divide(conversion.getDivideRate(), uomTo.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
    BigDecimal qtyTo6 = p_Qty.divide(conversion.getDivideRate(), 6, BigDecimal.ROUND_HALF_UP);
    if (qtyTo.compareTo(qtyTo6) != 0)
        throw new AdempiereUserError("@StdPrecision@: " + qtyTo + " <> " + qtyTo6 + " (" + p_Qty + "/" + conversion.getDivideRate() + ")");
    log.info(conversion + " -> " + qtyTo);
    //	Set to Beta
    return "Not completed yet";
}
Also used : MUOMConversion(org.compiere.model.MUOMConversion) MProduct(org.compiere.model.MProduct) MUOM(org.compiere.model.MUOM) AdempiereUserError(org.compiere.util.AdempiereUserError) BigDecimal(java.math.BigDecimal)

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