Search in sources :

Example 1 with MPPPeriod

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

the class ForecastRunCreate method generateForecastResult.

// doIt
/**
	 * Generate Forecast Result based on Forecast Detail and Forecast Definition
	 * 
	 * @param M_Warehouse_ID
	 * @return no records processed
	 */
private int generateForecastResult(int M_Warehouse_ID) {
    // Preview Calculate Data
    deleteData();
    // Get Period Base
    m_period_definition_base = new MPPPeriodDefinition(getCtx(), m_run.getRef_DefinitionPeriod_ID(), get_TrxName());
    m_period_definition_target = new MPPPeriodDefinition(getCtx(), m_run.getPP_PeriodDefinition_ID(), get_TrxName());
    m_forecast_rule = (MPPForecastRule) m_run.getPP_ForecastRule();
    // Get Periods
    List<MPPPeriod> m_period_history = m_period_definition_base.getPeriodsOfHistory(m_run.getPeriodHistory());
    // Generate Forecast Run Master
    int selection = generateForecastRunMaster(m_run, m_forecast_definition, m_period_history.get(m_period_history.size() - 1), m_period_history.get(0));
    if (selection <= 0)
        throw new IllegalArgumentException("@FindZeroRecords@");
    for (MPPForecastRunMaster master : MPPForecastRunMaster.getLines(getCtx(), p_PP_ForecastRun_ID, get_TrxName())) {
        // Generate Forecast Detail for each period
        for (MPPPeriod period : m_period_history) {
            // Create Forecast Run Detail
            createForecastRunDetail(master, period);
        }
    }
    // Create Forecast Run Entry based on Forecast Run Detail
    return createForecastRunResult(M_Warehouse_ID);
}
Also used : MPPPeriod(org.eevolution.model.MPPPeriod) MPPForecastRunMaster(org.eevolution.model.MPPForecastRunMaster) MPPPeriodDefinition(org.eevolution.model.MPPPeriodDefinition)

Example 2 with MPPPeriod

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

the class ForecastRunCreate method createForecastRunResult.

/**
	 * Create the Forecast Result
	 * 
	 * @param M_Warehouse_ID
	 * @return no records processed
	 */
private int createForecastRunResult(int M_Warehouse_ID) {
    // total record processed
    int records = 0;
    ForecastEngine engine = ForecastFactory.getForecastEngine(getAD_Client_ID());
    // Generate ForecastEntry based on forecast rule
    for (MPPForecastRunMaster master : MPPForecastRunMaster.getLines(getCtx(), p_PP_ForecastRun_ID, get_TrxName())) {
        DataSet series = new DataSet();
        series.setPeriods(m_run.getPeriodHistory());
        MProduct product = MProduct.get(getCtx(), master.getM_Product_ID());
        List<MPPForecastRunDetail> details = MPPForecastRunMaster.getDetails(getCtx(), master.get_ID(), get_TrxName());
        for (MPPForecastRunDetail detail : details) {
            MPPPeriod period = (MPPPeriod) detail.getPP_Period();
            DataElement data = new DataElement(master.get_ID(), period.getPeriodNo(), detail.getQtyCalculated(), null);
            series.addDataElement(data);
        }
        DataSet results = engine.getForecast(m_forecast_rule.getCalculationClass(), master.get_ID(), series, master.getFactorAlpha().doubleValue(), master.getFactorGamma().doubleValue(), master.getFactorBeta().doubleValue(), master.getFactorMultiplier().doubleValue(), master.getFactorScale().doubleValue(), master.getFactorUser().doubleValue());
        Enumeration<DataElement> elements = results.getDataElements();
        while (elements.hasMoreElements()) {
            DataElement element = elements.nextElement();
            MUOM uom = (MUOM) product.getC_UOM();
            MPPForecastRunResult result = new MPPForecastRunResult(getCtx(), 0, get_TrxName());
            result.setPP_ForecastRun_ID(m_run.get_ID());
            result.setPP_ForecastRunMaster_ID(element.getKey());
            result.setDescription(element.getDescription());
            BigDecimal qty = (BigDecimal) element.getValue();
            result.setQtyCalculated(qty);
            result.setQtyPlan(uom.round(qty, true));
            result.setIsActive(true);
            result.setPP_Period_ID(MPPPeriod.getIDByPeriodNo(m_period_definition_target, element.getPeriodNo()));
            result.setPeriodNo(element.getPeriodNo());
            result.saveEx();
            records++;
        }
    }
    // m_run.saveEx();
    return records;
}
Also used : MPPPeriod(org.eevolution.model.MPPPeriod) MProduct(org.compiere.model.MProduct) MUOM(org.compiere.model.MUOM) DataSet(org.eevolution.engine.forecast.DataSet) ForecastEngine(org.eevolution.engine.forecast.ForecastEngine) MPPForecastRunDetail(org.eevolution.model.MPPForecastRunDetail) BigDecimal(java.math.BigDecimal) DataElement(org.eevolution.engine.forecast.DataElement) MPPForecastRunMaster(org.eevolution.model.MPPForecastRunMaster) MPPForecastRunResult(org.eevolution.model.MPPForecastRunResult)

Example 3 with MPPPeriod

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

the class ForecastRunCreate method generateForcastRunLines.

/**
	 * Generate Forecast detail lines
	 * 
	 * @param frd
	 *            Forecast Detail
	 * @return no records processed
	 */
public int generateForcastRunLines(MPPForecastRunDetail frd) {
    List<Object> parameters = new ArrayList<Object>();
    StringBuffer insertSQL = new StringBuffer();
    MPPPeriod period = (MPPPeriod) frd.getPP_Period();
    insertSQL.append("INSERT INTO ").append(MPPForecastRunLine.Table_Name).append(" frl (");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_PP_ForecastRunLine_ID).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_PP_ForecastRun_ID).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_PP_ForecastRunDetail_ID).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_AD_Client_ID).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_AD_Org_ID).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_C_SalesHistory_ID).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_PP_Period_ID).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_Created).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_CreatedBy).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_Updated).append(",");
    insertSQL.append(MPPForecastRunLine.COLUMNNAME_UpdatedBy).append(")");
    insertSQL.append(" SELECT DISTINCT ");
    insertSQL.append("nextidfunc(").append(MSequence.get(getCtx(), MPPForecastRunLine.Table_Name).get_ID()).append(",'Y')").append(",");
    insertSQL.append(frd.getPP_ForecastRun_ID()).append(",");
    insertSQL.append(frd.getPP_ForecastRunDetail_ID()).append(",");
    insertSQL.append(MSalesHistory.COLUMNNAME_AD_Client_ID).append(",");
    insertSQL.append(MSalesHistory.COLUMNNAME_AD_Org_ID).append(",");
    insertSQL.append(MSalesHistory.COLUMNNAME_C_SalesHistory_ID).append(",");
    insertSQL.append(period.getPP_Period_ID()).append(",");
    insertSQL.append("SYSDATE").append(",");
    insertSQL.append(Env.getAD_User_ID(getCtx())).append(",");
    insertSQL.append("SYSDATE").append(",");
    insertSQL.append(Env.getAD_User_ID(getCtx()));
    insertSQL.append(" FROM ").append(MSalesHistory.Table_Name);
    insertSQL.append(" WHERE ");
    insertSQL.append(MSalesHistory.COLUMNNAME_M_Product_ID).append("=? AND ");
    insertSQL.append(MSalesHistory.COLUMNNAME_M_Warehouse_ID).append("=? AND ");
    insertSQL.append(MSalesHistory.COLUMNNAME_DateInvoiced).append(" BETWEEN ? AND ? ");
    parameters.add(frd.getPP_ForecastRunMaster().getM_Product_ID());
    parameters.add(m_run.getM_WarehouseSource_ID());
    parameters.add(period.getStartDate());
    parameters.add(period.getEndDate());
    return DB.executeUpdateEx(insertSQL.toString(), parameters.toArray(), get_TrxName());
}
Also used : MPPPeriod(org.eevolution.model.MPPPeriod) ArrayList(java.util.ArrayList)

Example 4 with MPPPeriod

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

the class ImportForecast method importForecast.

/**
	 * Import Forecast using X_I_Forecast table
	 * 
	 * @param X_I_Forecast
	 *            X_I_Forecast
	 * @return MForecastLine Forecast Line
	 */
private MForecastLine importForecast(X_I_Forecast ifl) {
    MForecastLine fl = new MForecastLine(getCtx(), ifl.getM_ForecastLine_ID(), get_TrxName());
    MForecast f = (MForecast) ifl.getM_Forecast();
    if (fl == null || fl.get_ID() <= 0) {
        fl = new MForecastLine(Env.getCtx(), 0, get_TrxName());
        fl.setAD_Org_ID(ifl.getAD_Org_ID());
        fl.setM_Forecast_ID(ifl.getM_Forecast_ID());
        fl.setM_Product_ID(ifl.getM_Product_ID());
        fl.setM_Warehouse_ID(ifl.getM_Warehouse_ID());
    }
    fl.setQty(ifl.getQty());
    fl.setIsActive(true);
    fl.setSalesRep_ID(ifl.getSalesRep_ID());
    fl.setDatePromised(ifl.getDatePromised());
    MPPPeriod period = MPPPeriod.findByCalendar(getCtx(), ifl.getDatePromised(), f.getPP_Calendar_ID(), get_TrxName());
    if (period == null) {
        ifl.setI_ErrorMsg(Msg.parseTranslation(ifl.getCtx(), "@PP_Period_ID@ @NotFound@ @To@ @DatePromised@" + ifl.getDatePromised()));
        isImported = false;
        return null;
    }
    fl.setPP_Period_ID(period.get_ID());
    fl.saveEx();
    isImported = true;
    return fl;
}
Also used : MPPPeriod(org.eevolution.model.MPPPeriod) MForecastLine(org.compiere.model.MForecastLine) MForecast(org.compiere.model.MForecast)

Aggregations

MPPPeriod (org.eevolution.model.MPPPeriod)4 MPPForecastRunMaster (org.eevolution.model.MPPForecastRunMaster)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 MForecast (org.compiere.model.MForecast)1 MForecastLine (org.compiere.model.MForecastLine)1 MProduct (org.compiere.model.MProduct)1 MUOM (org.compiere.model.MUOM)1 DataElement (org.eevolution.engine.forecast.DataElement)1 DataSet (org.eevolution.engine.forecast.DataSet)1 ForecastEngine (org.eevolution.engine.forecast.ForecastEngine)1 MPPForecastRunDetail (org.eevolution.model.MPPForecastRunDetail)1 MPPForecastRunResult (org.eevolution.model.MPPForecastRunResult)1 MPPPeriodDefinition (org.eevolution.model.MPPPeriodDefinition)1