/**
   * 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;
  }