/** 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();
      }
    }
  }
Example #2
0
 /**
  * Set Log of Process.
  *
  * <pre>
  *  - Translated Process Message
  *  - List of log entries
  *      Date - Number - Msg
  *  </pre>
  *
  * @param html if true with HTML markup
  * @return Log Info
  */
 public String getLogInfo(boolean html) {
   if (m_logs == null) return "";
   //
   StringBuilder sb = new StringBuilder();
   SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.Date);
   if (html) sb.append("<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\">");
   //
   for (int i = 0; i < m_logs.size(); i++) {
     if (html) sb.append("<tr>");
     else if (i > 0) sb.append("\n");
     //
     ProcessInfoLog log = m_logs.get(i);
     /**
      * if (log.getP_ID() != 0) sb.append(html ? "<td>" : "") .append(log.getP_ID()) .append(html ?
      * "</td>" : " \t"); *
      */
     //
     if (log.getP_Date() != null)
       sb.append(html ? "<td>" : "")
           .append(dateFormat.format(log.getP_Date()))
           .append(html ? "</td>" : " \t");
     //
     if (log.getP_Number() != null)
       sb.append(html ? "<td>" : "").append(log.getP_Number()).append(html ? "</td>" : " \t");
     //
     if (log.getP_Msg() != null)
       sb.append(html ? "<td>" : "")
           .append(Msg.parseTranslation(Env.getCtx(), log.getP_Msg()))
           .append(html ? "</td>" : "");
     //
     if (html) sb.append("</tr>");
   }
   if (html) sb.append("</table>");
   return sb.toString();
 } //	getLogInfo
Example #3
0
  public boolean validateSql() {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String sql = getSql();
    try {
      String countSql = Msg.parseTranslation(Env.getCtx(), sql.toString()); // 	Variables
      countSql =
          MRole.getDefault()
              .addAccessSQL(
                  countSql,
                  MTable.getTableName(Env.getCtx(), getAD_Table_ID()), // getTableName(),
                  MRole.SQL_FULLYQUALIFIED,
                  MRole.SQL_RO);

      pstmt = DB.prepareStatement(countSql, null);
      //	pstmt.setString(1, p_tableName);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        break;
      }
    } catch (SQLException e) {
      // ADialog.error(WindowNo, c, AD_Message)
      // Env.getUi().showError(0, null, sql.toString() + "<br> " + e.getMessage());
      log.log(Level.SEVERE, sql, e);
      // String error = e.toString();
      // show error to user and return: TODO
      return false;
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    return true;
  } // validate sql
Example #4
0
 /**
  * Execute Task and wait
  *
  * @return execution info
  */
 public String execute() {
   String cmd = Msg.parseTranslation(Env.getCtx(), getOS_Command()).trim();
   if (cmd == null || cmd.equals("")) return "Cannot execute '" + getOS_Command() + "'";
   //
   if (isServerProcess()) return executeRemote(cmd);
   return executeLocal(cmd);
 } //	execute
Example #5
0
  @Override
  protected boolean beforeSave(boolean newRecord) {
    if (isDefault()) {
      // @Trifon - Ensure that only one tax rate is set as Default!
      // @Mckay - Allow edits to the Default tax rate
      String whereClause =
          MTax.COLUMNNAME_C_TaxCategory_ID
              + "=? AND "
              + MTax.COLUMNNAME_C_Tax_ID
              + "<>? AND "
              + "IsDefault='Y'";
      List<MTax> list =
          new Query(getCtx(), I_C_Tax.Table_Name, whereClause, get_TrxName())
              .setParameters(getC_TaxCategory_ID(), getC_Tax_ID())
              .setOnlyActiveRecords(true)
              .list();
      if (list.size() >= 1) {
        log.saveError(
            "Error",
            Msg.parseTranslation(
                getCtx(), Msg.getMsg(Env.getCtx(), "OnlyOneTaxPerCategoryMarkedDefault")));
        return false;
      }
    }
    if (getC_Country_ID() > 0 && getC_CountryGroupFrom_ID() > 0) {
      setC_Country_ID(0);
    }
    if (getTo_Country_ID() > 0 && getC_CountryGroupTo_ID() > 0) {
      setTo_Country_ID(0);
    }

    return super.beforeSave(newRecord);
  }
Example #6
0
 /**
  * Before Save
  *
  * @param newRecord new
  * @return true
  */
 protected boolean beforeSave(boolean newRecord) {
   //	Org Consistency
   if (newRecord || is_ValueChanged("C_CashBook_ID") || is_ValueChanged("M_Warehouse_ID")) {
     MCashBook cb = MCashBook.get(getCtx(), getC_CashBook_ID(), get_TrxName());
     if (cb.getAD_Org_ID() != getAD_Org_ID()) {
       log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@: @C_CashBook_ID@"));
       return false;
     }
     MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID(), get_TrxName());
     if (wh.getAD_Org_ID() != getAD_Org_ID()) {
       log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@: @M_Warehouse_ID@"));
       return false;
     }
   }
   return true;
 } //	beforeSave
Example #7
0
  @Override
  protected boolean beforeSave(boolean newRecord) {
    //	Check Storage
    if (!newRecord
        && //
        ((is_ValueChanged("IsActive") && !isActive()) // 	now not active
            || (is_ValueChanged("IsStocked") && !isStocked()) // 	now not stocked
            || (is_ValueChanged("ProductType") // 	from Item
                && PRODUCTTYPE_Item.equals(get_ValueOld("ProductType"))))) {
      MStorage[] storages = MStorage.getOfProduct(getCtx(), get_ID(), get_TrxName());
      BigDecimal OnHand = Env.ZERO;
      BigDecimal Ordered = Env.ZERO;
      BigDecimal Reserved = Env.ZERO;
      for (int i = 0; i < storages.length; i++) {
        OnHand = OnHand.add(storages[i].getQtyOnHand());
        Ordered = Ordered.add(storages[i].getQtyOrdered());
        Reserved = Reserved.add(storages[i].getQtyReserved());
      }
      String errMsg = "";
      if (OnHand.signum() != 0) errMsg = "@QtyOnHand@ = " + OnHand;
      if (Ordered.signum() != 0) errMsg += " - @QtyOrdered@ = " + Ordered;
      if (Reserved.signum() != 0) errMsg += " - @QtyReserved@" + Reserved;
      if (errMsg.length() > 0) {
        log.saveError("Error", Msg.parseTranslation(getCtx(), errMsg));
        return false;
      }
    } //	storage

    // it checks if UOM has been changed , if so disallow the change if the condition is true.
    if ((!newRecord) && is_ValueChanged("C_UOM_ID") && hasInventoryOrCost()) {
      log.saveError("Error", Msg.getMsg(getCtx(), "SaveUomError"));
      return false;
    }

    //	Reset Stocked if not Item
    // AZ Goodwill: Bug Fix isStocked always return false
    // if (isStocked() && !PRODUCTTYPE_Item.equals(getProductType()))
    if (!PRODUCTTYPE_Item.equals(getProductType())) setIsStocked(false);

    //	UOM reset
    if (m_precision != null && is_ValueChanged("C_UOM_ID")) m_precision = null;

    // AttributeSetInstance reset
    if (is_ValueChanged(COLUMNNAME_M_AttributeSet_ID)) {
      MAttributeSetInstance asi =
          new MAttributeSetInstance(getCtx(), getM_AttributeSetInstance_ID(), get_TrxName());
      setM_AttributeSetInstance_ID(0);
      // Delete the old m_attributesetinstance
      try {
        asi.deleteEx(true, get_TrxName());
      } catch (AdempiereException ex) {
        log.saveError("Error", "Error deleting the AttributeSetInstance");
        return false;
      }
    }

    return true;
  } //	beforeSave
Example #8
0
 /**
  * Get Excel Report
  *
  * @param rule
  * @param sql
  * @param trxName
  * @param attachments
  * @return summary message to be added into mail content
  * @throws Exception
  */
 private String getExcelReport(
     MAlertRule rule, String sql, String trxName, Collection<File> attachments) throws Exception {
   ArrayList<ArrayList<Object>> data = getData(sql, trxName);
   if (data.size() <= 1) return null;
   // File
   File file = rule.createReportFile("xls");
   //
   ArrayExcelExporter exporter = new ArrayExcelExporter(getCtx(), data);
   exporter.export(file, null, false);
   attachments.add(file);
   String msg = rule.getName() + " (@SeeAttachment@ " + file.getName() + ")" + Env.NL;
   return Msg.parseTranslation(Env.getCtx(), msg);
 }
 /**
  * Perform process.
  *
  * @return Message (clear text)
  * @throws Exception if not successful
  */
 protected String doIt() throws Exception {
   log.info("C_InvoicePaySchedule_ID=" + getRecord_ID());
   MInvoicePaySchedule[] schedule =
       MInvoicePaySchedule.getInvoicePaySchedule(getCtx(), 0, getRecord_ID(), null);
   if (schedule.length == 0)
     throw new IllegalArgumentException("InvoicePayScheduleValidate - No Schedule");
   //	Get Invoice
   MInvoice invoice = new MInvoice(getCtx(), schedule[0].getC_Invoice_ID(), null);
   if (invoice.get_ID() == 0)
     throw new IllegalArgumentException("InvoicePayScheduleValidate - No Invoice");
   //
   BigDecimal total = Env.ZERO;
   for (int i = 0; i < schedule.length; i++) {
     BigDecimal due = schedule[i].getDueAmt();
     if (due != null) total = total.add(due);
   }
   boolean valid = invoice.getGrandTotal().compareTo(total) == 0;
   invoice.setIsPayScheduleValid(valid);
   invoice.save();
   //	Schedule
   for (int i = 0; i < schedule.length; i++) {
     if (schedule[i].isValid() != valid) {
       schedule[i].setIsValid(valid);
       schedule[i].save();
     }
   }
   String msg = "@OK@";
   if (!valid)
     msg =
         "@GrandTotal@ = "
             + invoice.getGrandTotal()
             + " <> @Total@ = "
             + total
             + "  - @Difference@ = "
             + invoice.getGrandTotal().subtract(total);
   return Msg.parseTranslation(getCtx(), msg);
 } //	doIt
 public AdempierePOSException(String message) {
   super(Msg.parseTranslation(Env.getCtx(), message));
 }
Example #11
0
  @Override
  protected boolean beforeDelete() {
    if (PRODUCTTYPE_Resource.equals(getProductType()) && getS_Resource_ID() > 0) {
      throw new AdempiereException("@S_Resource_ID@<>0");
    }
    //	Check Storage
    if (isStocked() || PRODUCTTYPE_Item.equals(getProductType())) {
      MStorage[] storages = MStorage.getOfProduct(getCtx(), get_ID(), get_TrxName());
      BigDecimal OnHand = Env.ZERO;
      BigDecimal Ordered = Env.ZERO;
      BigDecimal Reserved = Env.ZERO;
      for (int i = 0; i < storages.length; i++) {
        OnHand = OnHand.add(storages[i].getQtyOnHand());
        Ordered = OnHand.add(storages[i].getQtyOrdered());
        Reserved = OnHand.add(storages[i].getQtyReserved());
      }
      String errMsg = "";
      if (OnHand.signum() != 0) errMsg = "@QtyOnHand@ = " + OnHand;
      if (Ordered.signum() != 0) errMsg += " - @QtyOrdered@ = " + Ordered;
      if (Reserved.signum() != 0) errMsg += " - @QtyReserved@" + Reserved;
      if (errMsg.length() > 0) {
        log.saveError("Error", Msg.parseTranslation(getCtx(), errMsg));
        return false;
      }
    }
    //	delete costing
    MProductCosting[] costings = MProductCosting.getOfProduct(getCtx(), get_ID(), get_TrxName());
    for (int i = 0; i < costings.length; i++) costings[i].delete(true, get_TrxName());

    MCost.delete(this);

    // [ 1674225 ] Delete Product: Costing deletion error
    /*MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(),getAD_Client_ID(), get_TrxName());
    for(int i=0; i<mass.length; i++)
    {
    	// Get Cost Elements
    	MCostElement[] ces = MCostElement.getMaterialWithCostingMethods(this);
    	MCostElement ce = null;
    	for(int j=0; j<ces.length; j++)
    	{
    		if(MCostElement.COSTINGMETHOD_StandardCosting.equals(ces[i].getCostingMethod()))
    		{
    			ce = ces[i];
    			break;
    		}
    	}

    	if(ce == null)
    		continue;

    	MCost mcost = MCost.get(this, 0, mass[i], 0, ce.getM_CostElement_ID());
    	mcost.delete(true, get_TrxName());
    }*/

    // @Trifon Delete Product UOM Conversion
    final String whereClause = MProduct.COLUMNNAME_M_Product_ID + "=?";
    List<MUOMConversion> conversions =
        new Query(getCtx(), I_C_UOM_Conversion.Table_Name, whereClause, get_TrxName())
            .setClient_ID()
            .setParameters(get_ID())
            .setOnlyActiveRecords(false)
            .list();
    for (MUOMConversion conversion : conversions) {
      conversion.deleteEx(true);
    }
    // @Trifon Delete Product Downloads
    List<MProductDownload> downloads =
        new Query(getCtx(), I_M_ProductDownload.Table_Name, whereClause, get_TrxName())
            .setClient_ID()
            .setParameters(get_ID())
            .setOnlyActiveRecords(false)
            .list();
    for (MProductDownload download : downloads) {
      download.deleteEx(true);
    }

    //
    return delete_Accounting("M_Product_Acct");
  } //	beforeDelete