Search in sources :

Example 26 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.

the class WTreeBOM method action_loadBOM.

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);
    DefaultTreeNode parent = new DefaultTreeNode(productSummary(product, false), new ArrayList());
    dataBOM.clear();
    if (isImplosion()) {
        try {
            m_tree.setModel(null);
        } catch (Exception e) {
        }
        if (m_tree.getTreecols() != null)
            m_tree.getTreecols().detach();
        if (m_tree.getTreefoot() != null)
            m_tree.getTreefoot().detach();
        if (m_tree.getTreechildren() != null)
            m_tree.getTreechildren().detach();
        for (MPPProductBOMLine bomline : MPPProductBOMLine.getByProduct(product)) {
            parent.getChildren().add(parent(bomline));
        }
        Treecols treeCols = new Treecols();
        m_tree.appendChild(treeCols);
        Treecol treeCol = new Treecol();
        treeCols.appendChild(treeCol);
        SimpleTreeModel model = new SimpleTreeModel(parent);
        m_tree.setPageSize(-1);
        m_tree.setTreeitemRenderer(model);
        m_tree.setModel(model);
    } else {
        try {
            m_tree.setModel(null);
        } catch (Exception e) {
        }
        if (m_tree.getTreecols() != null)
            m_tree.getTreecols().detach();
        if (m_tree.getTreefoot() != null)
            m_tree.getTreefoot().detach();
        if (m_tree.getTreechildren() != null)
            m_tree.getTreechildren().detach();
        for (MPPProductBOM bom : MPPProductBOM.getProductBOMs(product)) {
            parent.getChildren().add(parent(bom));
        }
        Treecols treeCols = new Treecols();
        m_tree.appendChild(treeCols);
        Treecol treeCol = new Treecol();
        treeCols.appendChild(treeCol);
        SimpleTreeModel model = new SimpleTreeModel(parent);
        m_tree.setPageSize(-1);
        m_tree.setTreeitemRenderer(model);
        m_tree.setModel(model);
    }
    m_tree.addEventListener(Events.ON_SELECTION, this);
    loadTableBOM();
}
Also used : Treecol(org.zkoss.zul.Treecol) Treecols(org.zkoss.zul.Treecols) MProduct(org.compiere.model.MProduct) SimpleTreeModel(org.adempiere.webui.component.SimpleTreeModel) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ArrayList(java.util.ArrayList) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) MPPProductBOM(org.eevolution.model.MPPProductBOM)

Example 27 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.

the class WTreeBOM method parent.

public DefaultTreeNode parent(MPPProductBOMLine bomline) {
    MProduct M_Product = MProduct.get(getCtx(), bomline.getM_Product_ID());
    MPPProductBOM bomproduct = new MPPProductBOM(getCtx(), bomline.getPP_Product_BOM_ID(), null);
    DefaultTreeNode parent = new DefaultTreeNode(productSummary(M_Product, false), new ArrayList());
    Vector<Object> line = new Vector<Object>(17);
    //  0 Select
    line.add(new Boolean(false));
    //  1 IsActive
    line.add(new Boolean(true));
    // 2 Line                
    line.add(new Integer(bomline.getLine()));
    //  3 ValidDrom
    line.add((Timestamp) bomline.getValidFrom());
    //  4 ValidTo
    line.add((Timestamp) bomline.getValidTo());
    KeyNamePair pp = new KeyNamePair(M_Product.getM_Product_ID(), M_Product.getName());
    //  5 M_Product_ID
    line.add(pp);
    KeyNamePair uom = new KeyNamePair(bomline.getC_UOM_ID(), bomline.getC_UOM().getUOMSymbol());
    //  6 C_UOM_ID
    line.add(uom);
    //  7 IsQtyPorcentage
    line.add(new Boolean(bomline.isQtyPercentage()));
    //  8 BatchPercent
    line.add((BigDecimal) bomline.getQtyBatch());
    //  9 QtyBOM
    line.add((BigDecimal) ((bomline.getQtyBOM() != null) ? bomline.getQtyBOM() : new BigDecimal(0)));
    //  10 IsCritical                  
    line.add(new Boolean(bomline.isCritical()));
    // 11 LTOffSet
    line.add((Integer) bomline.getLeadTimeOffset());
    // 12 Assay
    line.add((BigDecimal) bomline.getAssay());
    // 13 Scrap
    line.add((BigDecimal) (bomline.getScrap()));
    // 14 IssueMethod
    line.add((String) bomline.getIssueMethod());
    // 15 BackflushGroup
    line.add((String) bomline.getBackflushGroup());
    // 16 Forecast
    line.add((BigDecimal) bomline.getForecast());
    dataBOM.add(line);
    for (MPPProductBOM bom : MPPProductBOM.getProductBOMs((MProduct) bomproduct.getM_Product())) {
        MProduct component = MProduct.get(getCtx(), bom.getM_Product_ID());
        return component(component);
    }
    return parent;
}
Also used : MProduct(org.compiere.model.MProduct) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ArrayList(java.util.ArrayList) KeyNamePair(org.compiere.util.KeyNamePair) MPPProductBOM(org.eevolution.model.MPPProductBOM) Vector(java.util.Vector) BigDecimal(java.math.BigDecimal)

Example 28 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.

the class RollupBillOfMaterial method getFutureCostPriceLowLevel.

/**
	 * Get the sum Current Cost Price Level Low for this Cost Element
	 * @param acctSchema
	 * @param bom MPPProductBOM
	 * @param costElement MCostElement
	 * @param trxName
	 * @return Cost Price Lower Level
	 */
private BigDecimal getFutureCostPriceLowLevel(MAcctSchema acctSchema, MPPProductBOM bom, MCostElement costElement, String trxName) {
    log.info("Element: " + costElement);
    AtomicReference<BigDecimal> costPriceLowLevel = new AtomicReference<>(Env.ZERO);
    if (bom == null)
        return costPriceLowLevel.get();
    //Iterate bom lines
    Arrays.stream(bom.getLines()).filter(bomLine -> bomLine != null && !bomLine.isCoProduct()).forEach(bomLine -> {
        MProduct component = MProduct.get(getCtx(), bomLine.getM_Product_ID());
        MCost cost = MCost.getOrCreate(component, 0, acctSchema, getOrganizationId(), getWarehouseId(), getCostTypeId(), costElement.getM_CostElement_ID());
        Boolean includingScrapQty = true;
        BigDecimal qty = bomLine.getQty(includingScrapQty);
        if (bomLine.isByProduct())
            cost.setFutureCostPriceLL(Env.ZERO);
        BigDecimal costPrice = cost.getFutureCostPrice().add(cost.getFutureCostPriceLL());
        if (costPrice.equals(BigDecimal.ZERO))
            costPrice = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL());
        if (bomLine.getM_Product().getC_UOM_ID() != bomLine.getC_UOM_ID()) {
            BigDecimal rate = MUOMConversion.getProductRateFrom(getCtx(), component.getM_Product_ID(), bomLine.getC_UOM_ID());
            if (rate == null)
                costPrice = costPrice.multiply(BigDecimal.ONE);
            else
                costPrice = costPrice.multiply(rate);
        }
        if (bomLine.isPacking()) {
            int workflowId = 0;
            MProduct product = MProduct.get(getCtx(), bom.getM_Product_ID());
            MPPProductPlanning productPlanning = null;
            if (workflowId <= 0)
                workflowId = MWorkflow.getWorkflowSearchKey(product);
            if (workflowId <= 0) {
                productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), product.get_ID(), get_TrxName());
                if (productPlanning != null)
                    workflowId = productPlanning.getAD_Workflow_ID();
                else
                    createNotice(product, "@NotFound@ @PP_Product_Planning_ID@");
            }
            if (workflowId <= 0)
                createNotice(product, "@NotFound@ @AD_Workflow_ID@");
            BigDecimal qtyBatchSize = DB.getSQLValueBD(trxName, "SELECT QtyBatchSize FROM AD_Workflow WHERE AD_Workflow_ID=?", workflowId);
            if (qtyBatchSize != null && qtyBatchSize.signum() != 0)
                qty = qty.divide(qtyBatchSize, acctSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
        }
        BigDecimal componentCost = costPrice.multiply(qty);
        costPriceLowLevel.updateAndGet(costAmt -> costAmt.add(componentCost));
        log.info("CostElement: " + costElement.getName() + ", Component: " + component.getValue() + ", CostPrice: " + costPrice + ", Qty: " + qty + ", Cost: " + componentCost + " => Total Cost Element: " + costPriceLowLevel.get());
    });
    // BOM line
    return costPriceLowLevel.get();
}
Also used : MUOMConversion(org.compiere.model.MUOMConversion) MPPProductPlanning(org.eevolution.model.MPPProductPlanning) Arrays(java.util.Arrays) I_PP_Product_Planning(org.eevolution.model.I_PP_Product_Planning) MWorkflow(org.compiere.wf.MWorkflow) Env(org.compiere.util.Env) MCostType(org.compiere.model.MCostType) AtomicReference(java.util.concurrent.atomic.AtomicReference) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) MPPProductBOM(org.eevolution.model.MPPProductBOM) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal) List(java.util.List) Query(org.compiere.model.Query) DB(org.compiere.util.DB) Msg(org.compiere.util.Msg) MCostElement(org.compiere.model.MCostElement) TrxRunnable(org.compiere.util.TrxRunnable) MPPMRP(org.eevolution.model.MPPMRP) Trx(org.compiere.util.Trx) MProduct(org.compiere.model.MProduct) MProduct(org.compiere.model.MProduct) MPPProductPlanning(org.eevolution.model.MPPProductPlanning) MCost(org.compiere.model.MCost) AtomicReference(java.util.concurrent.atomic.AtomicReference) BigDecimal(java.math.BigDecimal)

Example 29 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.

the class PP_Product_BOM_Check method doIt.

// prepare
/**
	 * Process
	 * 
	 * @return message
	 * @throws Exception
	 */
protected String doIt() throws Exception {
    log.info("Check BOM Structure");
    // Record ID is M_Product_ID of product to be tested
    MProduct xp = new MProduct(Env.getCtx(), p_Record_ID, get_TrxName());
    if (!xp.isBOM()) {
        log.info("Product is not a BOM");
        // No BOM - should not happen, but no problem
        return "OK";
    }
    // Check Parent Level
    int lowlevel = MPPProductBOMLine.getLowLevel(getCtx(), p_Record_ID, get_TrxName());
    xp.setLowLevel(lowlevel);
    xp.setIsVerified(true);
    xp.saveEx();
    // Get Default BOM from this product
    MPPProductBOM tbom = MPPProductBOM.getDefault(xp, get_TrxName());
    if (tbom == null) {
        raiseError("No Default BOM found: ", "Check BOM Parent search key");
    }
    // Check All BOM Lines
    if (tbom.getM_Product_ID() != 0) {
        MPPProductBOMLine[] tbomlines = tbom.getLines();
        for (MPPProductBOMLine tbomline : tbomlines) {
            lowlevel = tbomline.getLowLevel();
            MProduct p = new MProduct(getCtx(), tbomline.getM_Product_ID(), get_TrxName());
            p.setLowLevel(lowlevel);
            p.setIsVerified(true);
            p.saveEx();
        }
    }
    return "OK";
}
Also used : MProduct(org.compiere.model.MProduct) MPPProductBOM(org.eevolution.model.MPPProductBOM) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine)

Example 30 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.

the class RadioButtonTreeCellRenderer method component.

public DefaultMutableTreeNode component(MProduct M_Product, MPPProductBOM bomPassed, MPPProductBOMLine bomlinePassed) {
    MUOM UOM = new MUOM(Env.getCtx(), M_Product.getC_UOM_ID(), null);
    String whereClause = "Value=?";
    List<MPPProductBOM> boms = new Query(Env.getCtx(), MPPProductBOM.Table_Name, whereClause, null).setParameters(new Object[] { M_Product.getValue() }).setOnlyActiveRecords(true).list();
    for (MPPProductBOM bom : boms) {
        return parent(bom);
    }
    return new DefaultMutableTreeNode(new nodeUserObject(Msg.translate(Env.getCtx(), "Value") + ": " + M_Product.getValue() + " " + Msg.translate(Env.getCtx(), "Name") + ": " + M_Product.getName() + " " + Msg.translate(Env.getCtx(), "C_UOM_ID") + ": " + UOM.getName(), M_Product, bomPassed, bomlinePassed));
}
Also used : MUOM(org.compiere.model.MUOM) Query(org.compiere.model.Query) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MPPProductBOM(org.eevolution.model.MPPProductBOM)

Aggregations

MPPProductBOM (org.eevolution.model.MPPProductBOM)31 BigDecimal (java.math.BigDecimal)14 MProduct (org.compiere.model.MProduct)14 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)14 Query (org.compiere.model.Query)11 ArrayList (java.util.ArrayList)8 AdempiereException (org.adempiere.exceptions.AdempiereException)6 MWorkflow (org.compiere.wf.MWorkflow)6 Arrays (java.util.Arrays)5 List (java.util.List)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 MAcctSchema (org.compiere.model.MAcctSchema)5 MCost (org.compiere.model.MCost)5 MCostElement (org.compiere.model.MCostElement)5 Env (org.compiere.util.Env)5 MPPOrder (org.eevolution.model.MPPOrder)5 MBPartner (org.compiere.model.MBPartner)4 I_PP_Order (org.eevolution.model.I_PP_Order)4 MPPProductPlanning (org.eevolution.model.MPPProductPlanning)4 Vector (java.util.Vector)3