Search in sources :

Example 1 with X_T_BOMLine

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

the class SimulatedPickList method loadBOM.

/**
	 * Action: Fill Tree with all nodes
	 */
private void loadBOM() throws Exception {
    int count = 0;
    if (p_M_Product_ID == 0)
        raiseError("Error: ", "Product ID not found");
    MProduct product = new MProduct(getCtx(), p_M_Product_ID, get_TrxName());
    X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
    tboml.setAD_Org_ID(product.getAD_Org_ID());
    tboml.setPP_Product_BOM_ID(0);
    tboml.setPP_Product_BOMLine_ID(0);
    tboml.setSel_Product_ID(p_M_Product_ID);
    tboml.setM_Product_ID(p_M_Product_ID);
    tboml.setSel_Product_ID(p_M_Product_ID);
    tboml.setDateTrx(p_DateTrx);
    tboml.setImplosion(false);
    tboml.setLevelNo(0);
    tboml.setLevels("0");
    tboml.setQtyBOM(Env.ONE);
    tboml.setQtyRequired(p_QtyRequiered);
    tboml.setM_Warehouse_ID(p_M_Warehouse_ID);
    tboml.setSeqNo(0);
    tboml.setAD_PInstance_ID(AD_PInstance_ID);
    tboml.saveEx();
    final String whereClause = MPPProductBOM.COLUMNNAME_M_Product_ID + "=?";
    List<MPPProductBOM> boms = new Query(getCtx(), X_PP_Product_BOM.Table_Name, whereClause, get_TrxName()).setClient_ID().setOnlyActiveRecords(true).setParameters(p_M_Product_ID).list();
    for (MPPProductBOM bom : boms) {
        if (bom.isValidFromTo(p_DateTrx)) {
            parentExplotion(bom.get_ID(), p_QtyRequiered);
            ++count;
        }
    }
    if (count == 0)
        raiseError("Error: ", "Product is not a BOM");
}
Also used : MProduct(org.compiere.model.MProduct) MQuery(org.compiere.model.MQuery) Query(org.compiere.model.Query) MPPProductBOM(org.eevolution.model.MPPProductBOM) X_T_BOMLine(org.eevolution.model.X_T_BOMLine)

Example 2 with X_T_BOMLine

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

the class SimulatedPickList method parentExplotion.

/**
	 * Generate an Explosion for this BOM
	 * 
	 * @param PP_Product_BOMLine_ID
	 *            ID BOM Line
	 */
public void parentExplotion(int PP_Product_BOM_ID, BigDecimal qtyRequiered) throws Exception {
    ArrayList<Object> parameters = new ArrayList<Object>();
    parameters.add(PP_Product_BOM_ID);
    final StringBuilder whereClause = new StringBuilder(MPPProductBOMLine.COLUMNNAME_PP_Product_BOM_ID).append("=?");
    if (p_BackflushGroup != null) {
        whereClause.append(" AND ").append(MPPProductBOMLine.COLUMNNAME_BackflushGroup).append("LIKE ?");
        parameters.add(p_BackflushGroup);
    }
    List<MPPProductBOMLine> bomLines = new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause.toString(), get_TrxName()).setClient_ID().setOnlyActiveRecords(true).setParameters(parameters).setOrderBy(MPPProductBOMLine.COLUMNNAME_Line).list();
    for (MPPProductBOMLine line : bomLines) {
        if (line.isValidFromTo(p_DateTrx)) {
            SeqNo += 1;
            MProduct product = new MProduct(getCtx(), line.getM_Product_ID(), get_TrxName());
            X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
            tboml.setAD_Org_ID(product.getAD_Org_ID());
            tboml.setPP_Product_BOM_ID(PP_Product_BOM_ID);
            tboml.setPP_Product_BOMLine_ID(line.get_ID());
            tboml.setM_Product_ID(line.getM_Product_ID());
            tboml.setLevelNo(LevelNo);
            tboml.setDateTrx(p_DateTrx);
            tboml.setLevels(levels.substring(0, LevelNo) + LevelNo);
            tboml.setSeqNo(SeqNo);
            tboml.setAD_PInstance_ID(AD_PInstance_ID);
            tboml.setSel_Product_ID(p_M_Product_ID);
            tboml.setQtyBOM(line.getQty(true));
            tboml.setQtyRequired(qtyRequiered.multiply(line.getQty(true)));
            tboml.setM_Warehouse_ID(p_M_Warehouse_ID);
            tboml.setImplosion(false);
            tboml.saveEx();
            component(line.getM_Product_ID(), tboml.getQtyBOM());
        }
    }
}
Also used : MProduct(org.compiere.model.MProduct) MQuery(org.compiere.model.MQuery) Query(org.compiere.model.Query) ArrayList(java.util.ArrayList) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) X_T_BOMLine(org.eevolution.model.X_T_BOMLine)

Example 3 with X_T_BOMLine

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

the class CostBillOfMaterial method createLines.

/**
     * createLines
     *
     * @param bom
     * @param bomLine
     */
private void createLines(MAcctSchema accountSchema, MPPProductBOM bom, MPPProductBOMLine bomLine) {
    MProduct product;
    BigDecimal qty;
    if (bomLine != null) {
        product = MProduct.get(getCtx(), bomLine.getM_Product_ID());
        qty = bomLine.getQty();
    } else if (bom != null) {
        product = MProduct.get(getCtx(), bom.getM_Product_ID());
        qty = Env.ONE;
    } else {
        throw new AdempiereException("@NotFound@ @PP_Product_BOM_ID@");
    }
    //for (MCostElement costElement : getCostElements())
    getCostElements().stream().filter(costElement -> costElement != null).forEach(costElement -> {
        X_T_BOMLine reportBOMLine = new X_T_BOMLine(getCtx(), 0, get_TrxName());
        reportBOMLine.setAD_Org_ID(getOrganizationId());
        reportBOMLine.setM_Warehouse_ID(getWarehouseId());
        reportBOMLine.setSel_Product_ID(getProductId());
        reportBOMLine.setImplosion(isImplosion);
        reportBOMLine.setC_AcctSchema_ID(getAccountingSchemaId());
        reportBOMLine.setM_CostType_ID(getCostTypeId());
        reportBOMLine.setCostingMethod(getCostingMethod());
        reportBOMLine.setAD_PInstance_ID(getAD_PInstance_ID());
        reportBOMLine.setM_CostElement_ID(costElement.get_ID());
        reportBOMLine.setM_Product_ID(product.get_ID());
        reportBOMLine.setM_Warehouse_ID(getWarehouseId());
        reportBOMLine.setQtyBOM(qty);
        reportBOMLine.setSeqNo(seqNo);
        reportBOMLine.setLevelNo(levelNo);
        reportBOMLine.setLevels(LEVELS.substring(0, levelNo) + levelNo);
        BigDecimal currentCostPrice = Env.ZERO;
        BigDecimal currentCostPriceLL = Env.ZERO;
        BigDecimal futureCostPrice = Env.ZERO;
        BigDecimal futureCostPriceLL = Env.ZERO;
        final CostEngine engine = CostEngineFactory.getCostEngine(getAD_Client_ID());
        List<MCost> costs = MCost.getByElement(product, accountSchema, getCostTypeId(), getOrganizationId(), getWarehouseId(), 0, costElement.getM_CostElement_ID());
        boolean isCostFrozen = false;
        for (MCost cost : costs) {
            currentCostPrice = currentCostPrice.add(cost.getCurrentCostPrice());
            currentCostPriceLL = currentCostPriceLL.add(cost.getCurrentCostPriceLL());
            futureCostPrice = futureCostPrice.add(cost.getFutureCostPrice());
            futureCostPriceLL = futureCostPriceLL.add(cost.getFutureCostPriceLL());
            isCostFrozen = cost.isCostFrozen();
        }
        reportBOMLine.setCurrentCostPrice(currentCostPrice);
        reportBOMLine.setCurrentCostPriceLL(currentCostPriceLL);
        reportBOMLine.setFutureCostPrice(currentCostPrice);
        reportBOMLine.setFutureCostPriceLL(currentCostPriceLL);
        reportBOMLine.setIsCostFrozen(isCostFrozen);
        if (bomLine != null) {
            reportBOMLine.setPP_Product_BOM_ID(bomLine.getPP_Product_BOM_ID());
            reportBOMLine.setPP_Product_BOMLine_ID(bomLine.getPP_Product_BOMLine_ID());
        } else if (bom != null) {
            reportBOMLine.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID());
        }
        reportBOMLine.saveEx();
        seqNo++;
    });
}
Also used : CostEngineFactory(org.adempiere.engine.CostEngineFactory) Arrays(java.util.Arrays) Env(org.compiere.util.Env) X_T_BOMLine(org.eevolution.model.X_T_BOMLine) 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) AdempiereException(org.adempiere.exceptions.AdempiereException) MCostElement(org.compiere.model.MCostElement) MProduct(org.compiere.model.MProduct) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) CostEngine(org.adempiere.engine.CostEngine) MProduct(org.compiere.model.MProduct) CostEngine(org.adempiere.engine.CostEngine) AdempiereException(org.adempiere.exceptions.AdempiereException) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal) X_T_BOMLine(org.eevolution.model.X_T_BOMLine)

Example 4 with X_T_BOMLine

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

the class PrintBOM method parentExplotion.

/**
	 * Generate an Explotion for this BOM
	 * 
	 * @param PP_Product_BOMLine_ID
	 *            ID BOM Line
	 */
public void parentExplotion(int PP_Product_BOM_ID) throws Exception {
    PreparedStatement stmt = null;
    ResultSet rs = null;
    String sql = "SELECT PP_Product_BOMLine_ID, M_Product_ID FROM PP_Product_BOMLine boml " + "WHERE IsActive = 'Y' AND PP_Product_BOM_ID = ? ORDER BY Line ";
    try {
        stmt = DB.prepareStatement(sql, get_TrxName());
        stmt.setInt(1, PP_Product_BOM_ID);
        rs = stmt.executeQuery();
        while (rs.next()) {
            SeqNo += 1;
            X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
            tboml.setPP_Product_BOM_ID(PP_Product_BOM_ID);
            tboml.setPP_Product_BOMLine_ID(rs.getInt(1));
            tboml.setM_Product_ID(rs.getInt(2));
            tboml.setLevelNo(LevelNo);
            tboml.setLevels(levels.substring(0, LevelNo) + LevelNo);
            tboml.setSeqNo(SeqNo);
            tboml.setAD_PInstance_ID(AD_PInstance_ID);
            tboml.setSel_Product_ID(p_M_Product_ID);
            tboml.setImplosion(p_implosion);
            tboml.save();
            component(rs.getInt(2));
        }
    } catch (SQLException e) {
        log.log(Level.SEVERE, e.getLocalizedMessage() + sql, e);
        throw new Exception("SQLException: " + e.getLocalizedMessage());
    } finally {
        DB.close(rs, stmt);
        rs = null;
        stmt = null;
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) X_T_BOMLine(org.eevolution.model.X_T_BOMLine)

Example 5 with X_T_BOMLine

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

the class PrintBOM method parentImplotion.

/**
	 * Generate an Implotion for this BOM Line
	 * 
	 * @param PP_Product_BOMLine_ID
	 *            ID BOM Line
	 */
public void parentImplotion(int PP_Product_BOMLine_ID) throws Exception {
    int PP_Product_BOM_ID = 0;
    int M_Product_ID = 0;
    X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
    PP_Product_BOM_ID = DB.getSQLValue(null, "SELECT PP_Product_BOM_ID FROM PP_Product_BOMLine WHERE PP_Product_BOMLine_ID=?", PP_Product_BOMLine_ID);
    if (PP_Product_BOM_ID < 0)
        throw new Exception(CLogger.retrieveErrorString("Error: PrintBOM.parentImplotion()"));
    M_Product_ID = DB.getSQLValue(null, "SELECT M_Product_ID FROM PP_Product_BOM WHERE PP_Product_BOM_ID=?", PP_Product_BOM_ID);
    if (M_Product_ID < 0)
        throw new Exception(CLogger.retrieveErrorString("Error: PrintBOM.parentImplotion()"));
    tboml.setPP_Product_BOM_ID(PP_Product_BOM_ID);
    tboml.setPP_Product_BOMLine_ID(PP_Product_BOMLine_ID);
    tboml.setM_Product_ID(M_Product_ID);
    tboml.setLevelNo(LevelNo);
    tboml.setSel_Product_ID(p_M_Product_ID);
    tboml.setImplosion(p_implosion);
    if (LevelNo >= 11)
        tboml.setLevels(levels + ">" + LevelNo);
    else if (LevelNo >= 1)
        tboml.setLevels(levels.substring(0, LevelNo) + LevelNo);
    tboml.setSeqNo(SeqNo);
    tboml.setAD_PInstance_ID(AD_PInstance_ID);
    tboml.save();
    PreparedStatement stmt = null;
    ResultSet rs = null;
    String sql = "SELECT PP_Product_BOM_ID, M_Product_ID FROM PP_Product_BOM " + "WHERE IsActive = 'Y' AND M_Product_ID = ? ";
    try {
        stmt = DB.prepareStatement(sql, get_TrxName());
        stmt.setInt(1, M_Product_ID);
        rs = stmt.executeQuery();
        while (rs.next()) {
            SeqNo += 1;
            component(rs.getInt(2));
        }
    } catch (SQLException e) {
        log.log(Level.SEVERE, e.getLocalizedMessage() + sql, e);
        throw new Exception("SQLException: " + e.getLocalizedMessage());
    } finally {
        DB.close(rs, stmt);
        rs = null;
        stmt = null;
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) X_T_BOMLine(org.eevolution.model.X_T_BOMLine)

Aggregations

X_T_BOMLine (org.eevolution.model.X_T_BOMLine)6 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 MProduct (org.compiere.model.MProduct)3 Query (org.compiere.model.Query)3 ArrayList (java.util.ArrayList)2 MQuery (org.compiere.model.MQuery)2 MPPProductBOM (org.eevolution.model.MPPProductBOM)2 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)2 BigDecimal (java.math.BigDecimal)1 Arrays (java.util.Arrays)1 List (java.util.List)1 CostEngine (org.adempiere.engine.CostEngine)1 CostEngineFactory (org.adempiere.engine.CostEngineFactory)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 MAcctSchema (org.compiere.model.MAcctSchema)1 MCost (org.compiere.model.MCost)1 MCostElement (org.compiere.model.MCostElement)1 Env (org.compiere.util.Env)1