コード例 #1
0
  /**
   * Import record using X_I_ProductPlanning table
   *
   * @param ipp X_I_ProductPlanning
   */
  private void importPurchaseProductPlanning(X_I_ProductPlanning ipp) {
    MProduct product = MProduct.get(getCtx(), ipp.getM_Product_ID());
    if (product.isPurchased()) {
      final StringBuffer whereClause = new StringBuffer();
      whereClause.append(MProductPO.COLUMNNAME_M_Product_ID).append("=? AND ");
      whereClause.append(MProductPO.COLUMNNAME_C_BPartner_ID).append("=?");
      MProductPO productPO =
          new Query(getCtx(), MProductPO.Table_Name, whereClause.toString(), get_TrxName())
              .setClient_ID()
              .setParameters(new Object[] {ipp.getM_Product_ID(), ipp.getC_BPartner_ID()})
              .first();

      if (productPO == null) {
        productPO = new MProductPO(getCtx(), 0, get_TrxName());
      }

      productPO.setAD_Org_ID(ipp.getAD_Org_ID());
      productPO.setM_Product_ID(ipp.getM_Product_ID());
      productPO.setC_BPartner_ID(ipp.getC_BPartner_ID());
      productPO.setOrder_Min(ipp.getOrder_Min());
      productPO.setOrder_Pack(ipp.getOrder_Pack());
      productPO.setDeliveryTime_Promised(ipp.getDeliveryTime_Promised().intValue());
      productPO.setVendorProductNo(ipp.getVendorProductNo());
      productPO.saveEx();
    }
  }
コード例 #2
0
 /** delete all imported records */
 private void deleteImportedRecords() {
   if (p_DeleteOldImported) {
     for (X_I_ProductPlanning ipp : getRecords(false, p_IsImportOnlyNoErrors)) {
       ipp.deleteEx(true);
     }
   }
 }
コード例 #3
0
  /**
   * get MPPProductPlanning unique instance based on X_I_ProductPlanning data
   *
   * @param ipp X_I_ProductPlanning
   * @return unique instance of MPPProductPlanning
   */
  private MPPProductPlanning getProductPlanning(X_I_ProductPlanning ipp) {

    final StringBuffer whereClause = new StringBuffer();
    ArrayList<Object> parameters = new ArrayList();

    MColumn[] cols = getProductPlanningColumns();

    int count = 0;

    for (MColumn col : cols) {
      // column primary key for MPPProductPlanning
      if (MPPProductPlanning.COLUMNNAME_AD_Org_ID.equals(col.getColumnName())
          || MPPProductPlanning.COLUMNNAME_S_Resource_ID.equals(col.getColumnName())
          || MPPProductPlanning.COLUMNNAME_M_Warehouse_ID.equals(col.getColumnName())
          || MPPProductPlanning.COLUMNNAME_M_Product_ID.equals(col.getColumnName())) {
        whereClause.append(col.getColumnName()).append("=?");
        parameters.add(ipp.get_Value(col.getColumnName()));
        if (count < 3) {
          whereClause.append(" AND ");
          count++;
        }
      }
    }

    return new Query(getCtx(), MPPProductPlanning.Table_Name, whereClause.toString(), get_TrxName())
        .setClient_ID()
        .setParameters(parameters)
        .firstOnly();
  }
コード例 #4
0
  /**
   * import record using X_I_ProductPlanning table
   *
   * @param ipp X_I_ProductPlanning
   */
  private void importProductPlanning(X_I_ProductPlanning ipp) {
    MPPProductPlanning pp = null;
    if (ipp.getPP_Product_Planning_ID() > 0) {
      pp = new MPPProductPlanning(getCtx(), ipp.getPP_Product_Planning_ID(), get_TrxName());
    } else {
      pp = getProductPlanning(ipp);
    }

    if (pp == null) {
      pp = new MPPProductPlanning(getCtx(), 0, get_TrxName());
    }
    fillValue(pp, ipp);
    if (ipp.getC_BPartner_ID() > 0 && ipp.getVendorProductNo() != null) {
      importPurchaseProductPlanning(ipp);
    }
  }
コード例 #5
0
  /**
   * fill MPPProductPlanning using I_ProductPlanning's values
   *
   * @param pp MPPProductPlanning
   * @param ipp I_ProductPlanning
   */
  private void fillValue(MPPProductPlanning pp, X_I_ProductPlanning ipp) {

    for (MColumn col : getProductPlanningColumns()) {
      // if(!col.isUpdateable())
      // continue;

      if (MPPProductPlanning.COLUMNNAME_IsRequiredDRP.equals(col.getColumnName())
          || MPPProductPlanning.COLUMNNAME_IsRequiredMRP.equals(col.getColumnName())
          || MPPProductPlanning.COLUMNNAME_PP_Product_Planning_ID.equals(col.getColumnName())
          || MPPProductPlanning.COLUMNNAME_Updated.equals(col.getColumnName())
          || col.getAD_Reference_ID() == DisplayType.ID) continue;

      if (ipp.get_Value(col.getColumnName()) != null
          && pp.get_Value(col.getColumnName()).equals(ipp.get_Value(col.getColumnName()))) {
        continue;
      }

      pp.set_ValueOfColumn(col.getColumnName(), ipp.get_Value(col.getColumnName()));
    }
    pp.setIsRequiredDRP(false);
    pp.setIsRequiredMRP(false);
    String error = null;
    try {
      pp.saveEx();
      ipp.setPP_Product_Planning_ID(pp.getPP_Product_Planning_ID());
      ipp.saveEx();
    } catch (Exception e) {
      error = e.getMessage();
      ipp.setI_ErrorMsg(error);
      isImported = false;
      return;
    }

    isImported = true;
  }
コード例 #6
0
  /** 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();
      }
    }
  }
コード例 #7
0
  /** fill IDs values based on Search Key */
  private void fillIDValues() {
    for (X_I_ProductPlanning ppi : getRecords(false, p_IsImportOnlyNoErrors)) {
      if (ppi.getC_BPartner_ID() == 0)
        ppi.setC_BPartner_ID(
            getID(
                I_C_BPartner.Table_Name,
                I_C_BPartner.COLUMNNAME_Value + "=?",
                new Object[] {ppi.getBPartner_Value()}));
      if (ppi.getM_Product_ID() == 0)
        ppi.setM_Product_ID(
            getID(
                I_M_Product.Table_Name,
                I_M_Product.COLUMNNAME_Value + "=?",
                new Object[] {ppi.getProductValue()}));
      if (ppi.getM_Warehouse_ID() == 0)
        ppi.setM_Warehouse_ID(
            getID(
                I_M_Warehouse.Table_Name,
                I_M_Warehouse.COLUMNNAME_Value + "=?",
                new Object[] {ppi.getWarehouseValue()}));
      if (ppi.getAD_Org_ID() == 0)
        ppi.setAD_Org_ID(
            getID(
                I_AD_Org.Table_Name,
                I_AD_Org.COLUMNNAME_Value + "=?",
                new Object[] {ppi.getOrgValue()}));
      if (ppi.getDD_NetworkDistribution_ID() == 0)
        ppi.setDD_NetworkDistribution_ID(
            getID(
                I_DD_NetworkDistribution.Table_Name,
                I_DD_NetworkDistribution.COLUMNNAME_Value + "=?",
                new Object[] {ppi.getNetworkDistributionValue()}));
      if (ppi.getPP_Product_BOM_ID() == 0)
        ppi.setPP_Product_BOM_ID(
            getID(
                I_PP_Product_BOM.Table_Name,
                I_PP_Product_BOM.COLUMNNAME_Value + "=?",
                new Object[] {ppi.getProduct_BOM_Value()}));
      if (ppi.getM_Forecast_ID() == 0)
        ppi.setM_Forecast_ID(
            getID(
                I_M_Forecast.Table_Name,
                I_M_Forecast.COLUMNNAME_Name + "=?",
                new Object[] {ppi.getForecastValue()}));
      if (ppi.getS_Resource_ID() == 0)
        ppi.setS_Resource_ID(
            getID(
                I_S_Resource.Table_Name,
                I_S_Resource.COLUMNNAME_Value
                    + "=? AND "
                    + I_S_Resource.COLUMNNAME_ManufacturingResourceType
                    + "=?",
                new Object[] {ppi.getResourceValue(), "PT"}));

      ppi.saveEx();
    }
  }
コード例 #8
0
  /**
   * 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;
  }