/** import record using X_I_ProductPlanning table */ private void importRecords() { for (X_I_ProductPlanning ipp : getRecords(false, p_IsImportOnlyNoErrors)) { if (ipp.getM_Product_ID() > 0 && ipp.getS_Resource_ID() > 0 && ipp.getM_Warehouse_ID() > 0) { importProductPlanning(ipp); } else if (ipp.getForecastValue() == null || ipp.getM_Forecast_ID() == 0) { String error = ""; if (ipp.getM_Product_ID() == 0) { error = error + " @M_Product_ID@ @NotFound@ ,"; } if (ipp.getS_Resource_ID() == 0) { error = error + " @S_Resource_ID@ @NotFound@ ,"; } if (ipp.getM_Warehouse_ID() == 0) { error = error + " @M_Waehouse_ID@ @NotFound@"; } ipp.setI_ErrorMsg(Msg.parseTranslation(getCtx(), error)); isImported = false; ipp.saveEx(); return; } if (ipp.getForecastValue() == null) { isImported = true; } else if (ipp.getM_Forecast_ID() > 0 && ipp.getM_Warehouse_ID() > 0 && ipp.getM_Product_ID() > 0 && ipp.getQty().signum() > 0) { importForecast(ipp); } else { String error = ""; if (ipp.getM_Forecast_ID() == 0) { error = error + " @M_Forecast_ID@ @NotFound@ ,"; } if (ipp.getM_Warehouse_ID() == 0) { error = error + " @M_Warehouse_ID@ @NotFound@ ,"; } if (ipp.getQty().signum() <= 0) { error = error + " @Qty@ @Error@"; } ipp.setI_ErrorMsg(Msg.parseTranslation(getCtx(), error)); isImported = false; ipp.saveEx(); return; } if (isImported) { ipp.setI_IsImported(true); ipp.setProcessed(true); ipp.saveEx(); } } }
/** * Import Forecast Record using X_I_ProductPlanning table * * @param ipp X_I_ProductPlanning */ private void importForecast(X_I_ProductPlanning ipp) { if (ipp.getForecastValue() == null && ipp.getM_Forecast_ID() == 0) { ipp.setI_ErrorMsg(Msg.getMsg(getCtx(), "@M_Forecast_ID@ @NotFound@")); ipp.saveEx(); isImported = false; return; } MForecast forecast = new MForecast(getCtx(), ipp.getM_Forecast_ID(), get_TrxName()); final StringBuffer whereClause = new StringBuffer(); whereClause .append(X_M_ForecastLine.COLUMNNAME_M_Forecast_ID) .append("=? AND ") .append(X_M_ForecastLine.COLUMNNAME_M_Product_ID) .append("=? AND ") .append(X_M_ForecastLine.COLUMNNAME_M_Warehouse_ID) .append("=? AND ") .append(X_M_ForecastLine.COLUMNNAME_DatePromised) .append("=? AND ") .append(X_M_ForecastLine.COLUMNNAME_SalesRep_ID) .append("=?"); X_M_ForecastLine forecastLine = null; if (ipp.getM_ForecastLine_ID() > 0) { forecastLine = new X_M_ForecastLine(getCtx(), ipp.getM_ForecastLine_ID(), get_TrxName()); } else { forecastLine = new Query(getCtx(), X_M_ForecastLine.Table_Name, whereClause.toString(), get_TrxName()) .setClient_ID() .setParameters( new Object[] { ipp.getM_Forecast_ID(), ipp.getM_Product_ID(), ipp.getM_Warehouse_ID(), ipp.getDatePromised(), ipp.getSalesRep_ID() }) .first(); } if (forecastLine == null) { forecastLine = new X_M_ForecastLine(getCtx(), 0, get_TrxName()); } forecastLine.setM_Forecast_ID(ipp.getM_Forecast_ID()); forecastLine.setAD_Org_ID(ipp.getAD_Org_ID()); forecastLine.setM_Product_ID(ipp.getM_Product_ID()); forecastLine.setM_Warehouse_ID(ipp.getM_Warehouse_ID()); forecastLine.setC_Period_ID( MPeriod.getC_Period_ID(getCtx(), ipp.getDatePromised(), ipp.getAD_Org_ID())); forecastLine.setDatePromised(ipp.getDatePromised()); forecastLine.setSalesRep_ID(ipp.getSalesRep_ID()); forecastLine.setQty(ipp.getQty()); forecastLine.saveEx(); ipp.setM_ForecastLine_ID(forecastLine.getM_ForecastLine_ID()); ipp.saveEx(); isImported = true; }