protected boolean beforeSave(boolean newRecord) {
   // TODO - Think about implement a determination of DocType similar to in MPayment.beforeSave()
   if (!newRecord) {
     MPayment[] pays;
     try {
       pays = getPayments(get_TrxName());
     } catch (SQLException e) {
       s_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
       return false;
     }
     for (int i = 0; i < pays.length; i++) {
       pays[i].setC_DocType_ID(getC_DocType_ID());
       pays[i].setDocumentNo(getDocumentNo());
       pays[i].setDateTrx(getDateTrx());
       pays[i].setDateAcct(getDateTrx());
       pays[i].setC_BPartner_ID(getC_BPartner_ID());
       pays[i].setIsReceipt(isReceipt());
       pays[i].setIsActive(isActive());
       if (!pays[i].save(get_TrxName())) {
         try {
           DB.rollback(false, get_TrxName());
         } catch (SQLException e) {
           s_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
         }
         return false;
       }
     }
   }
   return true;
 }
 /** Parses m_sqlOriginal and creates Array of m_sql statements */
 private void getSelectStatements() {
   String[] sqlIn = new String[] {m_sqlOriginal};
   String[] sqlOut = null;
   try {
     sqlOut = getSubSQL(sqlIn);
   } catch (Exception e) {
     log.log(Level.SEVERE, m_sqlOriginal, e);
     throw new IllegalArgumentException(m_sqlOriginal);
   }
   //	a sub-query was found
   while (sqlIn.length != sqlOut.length) {
     sqlIn = sqlOut;
     try {
       sqlOut = getSubSQL(sqlIn);
     } catch (Exception e) {
       log.log(Level.SEVERE, m_sqlOriginal, e);
       throw new IllegalArgumentException(sqlOut.length + ": " + m_sqlOriginal);
     }
   }
   m_sql = sqlOut;
   /**
    * List & check ** for (int i = 0; i < m_sql.length; i++) { if (m_sql[i].indexOf("SELECT ",2) !=
    * -1) log.log(Level.SEVERE, "#" + i + " Has embedded SQL - " + m_sql[i]); else log.fine("#" + i
    * + " - " + m_sql[i]); } /** *
    */
 } //	getSelectStatements
Beispiel #3
0
 /** PaySelect changed - load Bank */
 public void loadPaySelectInfo(int C_PaySelection_ID) {
   //  load Banks from PaySelectLine
   m_C_BankAccount_ID = -1;
   String sql =
       "SELECT ps.C_BankAccount_ID, b.Name || ' ' || ba.AccountNo," //	1..2
           + " c.ISO_Code, CurrentBalance, ba.PaymentExportClass " //	3..5
           + "FROM C_PaySelection ps"
           + " INNER JOIN C_BankAccount ba ON (ps.C_BankAccount_ID=ba.C_BankAccount_ID)"
           + " INNER JOIN C_Bank b ON (ba.C_Bank_ID=b.C_Bank_ID)"
           + " INNER JOIN C_Currency c ON (ba.C_Currency_ID=c.C_Currency_ID) "
           + "WHERE ps.C_PaySelection_ID=? AND ps.Processed='Y' AND ba.IsActive='Y'";
   try {
     PreparedStatement pstmt = DB.prepareStatement(sql, null);
     pstmt.setInt(1, C_PaySelection_ID);
     ResultSet rs = pstmt.executeQuery();
     if (rs.next()) {
       m_C_BankAccount_ID = rs.getInt(1);
       bank = rs.getString(2);
       currency = rs.getString(3);
       balance = rs.getBigDecimal(4);
       m_PaymentExportClass = rs.getString(5);
     } else {
       m_C_BankAccount_ID = -1;
       bank = "";
       currency = "";
       balance = Env.ZERO;
       m_PaymentExportClass = null;
       log.log(Level.SEVERE, "No active BankAccount for C_PaySelection_ID=" + C_PaySelection_ID);
     }
     rs.close();
     pstmt.close();
   } catch (SQLException e) {
     log.log(Level.SEVERE, sql, e);
   }
 } //  loadPaySelectInfo
Beispiel #4
0
 /**
  * ************************************************************************ Start Java Process
  * Class. instanciate the class implementing the interface ProcessCall. The class can be a
  * Server/Client class (when in Package org compiere.process or org.compiere.model) or a client
  * only class (e.g. in org.compiere.report)
  *
  * @return true if success
  */
 private boolean startProcess() {
   log.fine(m_pi.toString());
   boolean started = false;
   if (DB.isRemoteProcess()) {
     Server server = CConnection.get().getServer();
     try {
       if (server != null) { // 	See ServerBean
         m_pi = server.process(m_wscctx, m_pi);
         log.finest("server => " + m_pi);
         started = true;
       }
     } catch (UndeclaredThrowableException ex) {
       Throwable cause = ex.getCause();
       if (cause != null) {
         if (cause instanceof InvalidClassException)
           log.log(
               Level.SEVERE, "Version Server <> Client: " + cause.toString() + " - " + m_pi, ex);
         else
           log.log(Level.SEVERE, "AppsServer error(1b): " + cause.toString() + " - " + m_pi, ex);
       } else log.log(Level.SEVERE, " AppsServer error(1) - " + m_pi, ex);
       started = false;
     } catch (Exception ex) {
       Throwable cause = ex.getCause();
       if (cause == null) cause = ex;
       log.log(Level.SEVERE, "AppsServer error - " + m_pi, cause);
       started = false;
     }
   }
   //	Run locally
   if (!started && !m_IsServerProcess) {
     ProcessCall myObject = null;
     try {
       Class myClass = Class.forName(m_pi.getClassName());
       myObject = (ProcessCall) myClass.newInstance();
       if (myObject == null) m_pi.setSummary("No Instance for " + m_pi.getClassName(), true);
       else myObject.startProcess(m_wscctx, m_pi, m_trx);
       if (m_trx != null) {
         m_trx.commit();
         m_trx.close();
       }
     } catch (Exception e) {
       if (m_trx != null) {
         m_trx.rollback();
         m_trx.close();
       }
       m_pi.setSummary("Error starting Class " + m_pi.getClassName(), true);
       log.log(Level.SEVERE, m_pi.getClassName(), e);
     }
   }
   return !m_pi.isError();
 } //  startProcess
 /**
  * ************************************************************************ Create Missing
  * Document Types
  *
  * @param ctx context
  * @param AD_Client_ID client
  * @param sp server process
  * @param trx transaction
  */
 public static void createDocumentTypes(Ctx ctx, int AD_Client_ID, SvrProcess sp, Trx trx) {
   s_log.info("AD_Client_ID=" + AD_Client_ID);
   String sql =
       "SELECT rl.Value, rl.Name "
           + "FROM AD_Ref_List rl "
           + "WHERE rl.AD_Reference_ID=183"
           + " AND rl.IsActive='Y' AND NOT EXISTS "
           + " (SELECT * FROM C_DocType dt WHERE dt.AD_Client_ID=? AND rl.Value=dt.DocBaseType)";
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, trx);
     pstmt.setInt(1, AD_Client_ID);
     rs = pstmt.executeQuery();
     while (rs.next()) {
       String name = rs.getString(2);
       String value = rs.getString(1);
       s_log.config(name + "=" + value);
       MDocType dt = new MDocType(ctx, value, name, trx);
       if (dt.save()) {
         if (sp != null) sp.addLog(0, null, null, name);
         else s_log.fine(name);
       } else {
         if (sp != null) sp.addLog(0, null, null, "Not created: " + name);
         else s_log.warning("Not created: " + name);
       }
     }
   } catch (Exception e) {
     s_log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeResultSet(rs);
     DB.closeStatement(pstmt);
   }
 } //	createDocumentTypes
Beispiel #6
0
  /**
   * Apply Current Pattern
   *
   * @param next next
   */
  private void cmd_applyFormat(boolean next) {
    if (m_format == null || m_data.size() == 0) return;

    //	set position
    if (next) m_record++;
    else m_record--;

    if (m_record < 0) m_record = 0;
    else if (m_record >= m_data.size()) m_record = m_data.size() - 1;

    record.setValue(" " + String.valueOf(m_record + 1) + " ");

    //	Line Info

    String[] lInfo =
        m_format.parseLine(
            m_data.get(m_record).toString(), false, true, false); // 	no label, trace, no ignore

    int size = m_format.getRowCount();

    if (lInfo.length != size)
      log.log(Level.SEVERE, "FormatElements=" + size + " != Fields=" + lInfo.length);

    for (int i = 0; i < size; i++) {
      m_fields[i].setText(lInfo[i]);
      // m_fields[i].setCaretPosition(0);
    }
  } //	cmd_applyFormat
Beispiel #7
0
 /**
  * ************************************************************************ Start Workflow.
  *
  * @param AD_Workflow_ID workflow
  * @return true if started
  */
 private boolean startWorkflow(int AD_Workflow_ID) {
   log.fine(AD_Workflow_ID + " - " + m_pi);
   boolean started = false;
   if (DB.isRemoteProcess()) {
     log.info("trying to running on the server");
     Server server = CConnection.get().getServer();
     try {
       if (server != null) { // 	See ServerBean
         log.info("running on the server");
         m_pi = server.workflow(m_wscctx, m_pi, AD_Workflow_ID);
         log.finest("server => " + m_pi);
         started = true;
       }
     } catch (Exception ex) {
       log.log(Level.SEVERE, "AppsServer error", ex);
       started = false;
     }
   }
   //	Run locally
   if (!started && !m_IsServerProcess) {
     log.info("running locally");
     MWorkflow wf = MWorkflow.get(m_wscctx, AD_Workflow_ID);
     MWFProcess wfProcess = null;
     if (m_pi.isBatch()) wfProcess = wf.start(m_pi); // 	may return null
     else wfProcess = wf.startWait(m_pi); // 	may return null
     started = wfProcess != null;
   }
   return started;
 } //  startWorkflow
Beispiel #8
0
 /**
  * Generate LDAPResult
  *
  * @param dn Distinguished Name
  * @param resultProtocol Result protocol/operation code
  * @param resultCode Result code
  * @param errMsg Error Message
  * @return reponse
  */
 private void generateResult(String dn, int resultProtocol, int resultCode, String errMsg) {
   try {
     m_encoder.beginSeq(48); // Hard coded here for Envelope header
     m_encoder.encodeInt(m_ldapMsg.getMsgId());
     m_encoder.beginSeq(resultProtocol);
     m_encoder.encodeInt(resultCode, 10); // Enumeration - 10
     // Adding LDAPDN
     m_encoder.encodeString(dn, true);
     // Adding error message
     m_encoder.encodeString(errMsg == null ? "" : errMsg, true);
     m_encoder.endSeq();
     m_encoder.endSeq();
     log.fine(
         "#"
             + m_ldapMsg.getMsgId()
             + ": "
             + "dn="
             + dn
             + ", op="
             + resultProtocol
             + ", result="
             + resultCode
             + ", errMsg="
             + errMsg);
   } catch (Exception ex) {
     log.log(Level.SEVERE, "", ex);
   }
 } // generateResult
 /*
  * Write to file
  *
  * @param sb string buffer
  * @param fileName file name
  */
 private void writeToFile(StringBuffer sb, String fileName) {
   try {
     new File(fileName.substring(0, fileName.lastIndexOf("/"))).mkdirs();
     File out = new File(fileName);
     Writer fw = new OutputStreamWriter(new FileOutputStream(out, false), "UTF-8");
     for (int i = 0; i < sb.length(); i++) {
       char c = sb.charAt(i);
       // after
       if (c == ';' || c == '}') {
         fw.write(c);
         if (sb.substring(i + 1).startsWith("//")) fw.write('\t');
         else fw.write(NL);
       }
       // before & after
       else if (c == '{') {
         fw.write(NL);
         fw.write(c);
         fw.write(NL);
       } else fw.write(c);
     }
     fw.flush();
     fw.close();
     float size = out.length();
     size /= 1024;
     log.info(out.getAbsolutePath() + " - " + size + " kB");
   } catch (Exception ex) {
     log.log(Level.SEVERE, fileName, ex);
     throw new RuntimeException(ex);
   }
 }
Beispiel #10
0
  /**
   * Find all the year records in a Calendar, it need not be a standard period (used in MRP)
   *
   * @param C_Calendar_ID calendar
   * @param ctx context
   * @param trx trx
   * @return MYear[]
   */
  public static MYear[] getAllYearsInCalendar(int C_Calendar_ID, Ctx ctx, Trx trx) {

    List<MYear> years = new ArrayList<MYear>();
    String sql = "SELECT * FROM C_Year WHERE " + "IsActive='Y' AND C_Calendar_ID = ? ";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, trx);
      pstmt.setInt(1, C_Calendar_ID);
      rs = pstmt.executeQuery();
      while (rs.next()) years.add(new MYear(ctx, rs, trx));

    } catch (Exception e) {
      s_log.log(Level.SEVERE, sql, e);
    } finally {

      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }

    MYear[] retValue = new MYear[years.size()];
    years.toArray(retValue);
    return retValue;
  }
Beispiel #11
0
  /**
   * Returns the previous period
   *
   * @param period MPeriod
   * @param periodCount Count
   * @param trx trx
   * @param ctx Ctx
   * @return MPeriod
   */
  public static MPeriod getPreviousPeriod(MPeriod period, Ctx ctx, Trx trx) {

    MPeriod newPeriod = null;
    String sql =
        "SELECT * FROM C_Period WHERE "
            + "C_Period.IsActive='Y' AND PeriodType='S' "
            + "AND C_Period.C_Year_ID IN "
            + "(SELECT C_Year_ID FROM C_Year WHERE C_Year.C_Calendar_ID = ? ) "
            + "AND ((C_Period.C_Year_ID * 1000) + C_Period.PeriodNo) "
            + " < ((? * 1000) + ?) ORDER BY C_Period.C_Year_ID DESC, C_Period.PeriodNo DESC";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, trx);
      pstmt.setInt(1, period.getC_Calendar_ID());
      pstmt.setInt(2, period.getC_Year_ID());
      pstmt.setInt(3, period.getPeriodNo());
      rs = pstmt.executeQuery();
      if (rs.next()) newPeriod = new MPeriod(ctx, rs, trx);
    } catch (Exception e) {
      s_log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
    return newPeriod;
  }
Beispiel #12
0
  /**
   * Execute Task locally and wait
   *
   * @param cmd command
   * @return execution info
   */
  public String executeLocal(String cmd) {
    log.config(cmd);
    if (m_task != null && m_task.isAlive()) m_task.interrupt();

    m_task = new Task(cmd);
    m_task.start();

    StringBuffer sb = new StringBuffer();
    while (true) {
      //  Give it a bit of time
      try {
        Thread.sleep(500);
      } catch (InterruptedException ioe) {
        log.log(Level.SEVERE, cmd, ioe);
      }
      //  Info to user
      sb.append(m_task.getOut())
          .append("\n-----------\n")
          .append(m_task.getErr())
          .append("\n-----------");

      //  Are we done?
      if (!m_task.isAlive()) break;
    }
    log.config("done");
    return sb.toString();
  } //	executeLocal
 /**
  * Loop detection of product category tree.
  *
  * @param productCategoryId
  * @param newParentCategoryId
  * @param newParentCategoryId New Parent Category
  * @return "" or error message
  */
 public boolean hasLoopInTree() {
   int productCategoryId = getM_Product_Category_ID();
   int newParentCategoryId = getM_Product_Category_Parent_ID();
   //	get values
   ResultSet rs = null;
   PreparedStatement pstmt = null;
   String sql =
       " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
   final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
   try {
     pstmt = DB.prepareStatement(sql, null);
     rs = pstmt.executeQuery();
     while (rs.next()) {
       if (rs.getInt(1) == productCategoryId)
         categories.add(new SimpleTreeNode(rs.getInt(1), newParentCategoryId));
       categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
     }
     if (hasLoop(newParentCategoryId, categories, productCategoryId)) return true;
   } catch (SQLException e) {
     s_log.log(Level.SEVERE, sql, e);
     return true;
   } finally {
     DB.close(rs, pstmt);
     rs = null;
     pstmt = null;
   }
   return false;
 } //	hasLoopInTree
  /** Refresh Query */
  private void refresh() {
    String sql = m_sql;
    int pos = m_sql.lastIndexOf(" ORDER BY ");
    if (!showAll.isSelected()) {
      sql = m_sql.substring(0, pos) + s_sqlWhereSameWarehouse;
      if (s_sqlMinLife.length() > 0) sql += s_sqlMinLife;
      sql += m_sql.substring(pos);
    }
    //
    log.finest(sql);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, m_M_Product_ID);
      if (!showAll.isSelected()) {
        pstmt.setInt(2, m_M_Warehouse_ID);
      }

      rs = pstmt.executeQuery();
      m_table.loadTable(rs);
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    enableButtons();
  }
Beispiel #15
0
  /** Answer Button */
  private void cmd_button() {
    log.config("Activity=" + m_activity);
    if (m_activity == null) return;
    //
    MWFNode node = m_activity.getNode();
    if (MWFNode.ACTION_UserWindow.equals(node.getAction())) {
      int AD_Window_ID = node.getAD_Window_ID(); // Explicit Window
      String ColumnName = m_activity.getPO().get_TableName() + "_ID";
      int Record_ID = m_activity.getRecord_ID();
      MQuery query = MQuery.getEqualQuery(ColumnName, Record_ID);
      boolean IsSOTrx = m_activity.isSOTrx();
      //
      log.info(
          "Zoom to AD_Window_ID=" + AD_Window_ID + " - " + query + " (IsSOTrx=" + IsSOTrx + ")");

      AEnv.zoom(AD_Window_ID, query);
    } else if (MWFNode.ACTION_UserForm.equals(node.getAction())) {
      int AD_Form_ID = node.getAD_Form_ID();

      Window form = ADForm.openForm(AD_Form_ID);
      AEnv.showWindow(form);
    } else if (MWFNode.ACTION_SmartBrowse.equals(node.getAction())) {
      int AD_Browse_ID = node.getAD_Browse_ID();

      Window browse = WBrowser.openBrowse(AD_Browse_ID);
      AEnv.showWindow(browse);
    } else log.log(Level.SEVERE, "No User Action:" + node.getAction());
  } //	cmd_button
Beispiel #16
0
  public ArrayList<KeyNamePair> getPaySelectionData() {
    ArrayList<KeyNamePair> data = new ArrayList<KeyNamePair>();

    log.config("");
    int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());

    //  Load PaySelect
    String sql =
        "SELECT C_PaySelection_ID, Name || ' - ' || TotalAmt FROM C_PaySelection "
            + "WHERE AD_Client_ID=? AND Processed='Y' AND IsActive='Y'"
            + "ORDER BY PayDate DESC";
    try {
      PreparedStatement pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, AD_Client_ID);
      ResultSet rs = pstmt.executeQuery();
      //
      while (rs.next()) {
        KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
        data.add(pp);
      }
      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }

    return data;
  }
Beispiel #17
0
  /** Bank changed - load PaymentRule */
  public ArrayList<ValueNamePair> loadPaymentRule(int C_PaySelection_ID) {
    ArrayList<ValueNamePair> data = new ArrayList<ValueNamePair>();

    // load PaymentRule for Bank
    int AD_Reference_ID = 195; //  MLookupInfo.getAD_Reference_ID("All_Payment Rule");
    Language language = Language.getLanguage(Env.getAD_Language(Env.getCtx()));
    MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID);
    String sql =
        info.Query.substring(0, info.Query.indexOf(" ORDER BY"))
            + " AND "
            + info.KeyColumn
            + " IN (SELECT PaymentRule FROM C_PaySelectionCheck WHERE C_PaySelection_ID=?) "
            + info.Query.substring(info.Query.indexOf(" ORDER BY"));
    try {
      PreparedStatement pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, C_PaySelection_ID);
      ResultSet rs = pstmt.executeQuery();
      //
      while (rs.next()) {
        ValueNamePair pp = new ValueNamePair(rs.getString(2), rs.getString(3));
        data.add(pp);
      }
      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }

    if (data.size() == 0)
      log.config("PaySel=" + C_PaySelection_ID + ", BAcct=" + m_C_BankAccount_ID + " - " + sql);

    return data;
  } //  loadPaymentRule
  /**
   * Action Listener - start dialog
   *
   * @param e Event
   */
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(RecordInfo.CHANGE_LOG_COMMAND)) {
      RecordInfo.start(m_mField);
      return;
    }
    if (!m_button.isEnabled()) return;
    m_button.setEnabled(false);
    //
    Integer oldValue = (Integer) getValue();
    int S_ResourceAssignment_ID = oldValue == null ? 0 : oldValue.intValue();
    MResourceAssignment ma = new MResourceAssignment(Env.getCtx(), S_ResourceAssignment_ID, null);

    //	Start VAssignment Dialog
    if (S_ResourceAssignment_ID != 0) {
      VAssignmentDialog vad = new VAssignmentDialog(Env.getFrame(this), ma, true, true);
      ma = vad.getMResourceAssignment();
    }
    //	Start InfoSchedule directly
    else {
      InfoSchedule is = new InfoSchedule(Env.getFrame(this), ma, true);
      ma = is.getMResourceAssignment();
    }

    //	Set Value
    if (ma != null && ma.getS_ResourceAssignment_ID() != 0) {
      setValue(new Integer(ma.getS_ResourceAssignment_ID()));
      try {
        fireVetoableChange(this.getName(), new Object(), getValue());
      } catch (PropertyVetoException pve) {
        log.log(Level.SEVERE, "", pve);
      }
    }
    m_button.setEnabled(true);
    requestFocus();
  } //	actionPerformed
Beispiel #19
0
 /**
  * Return Editor value
  *
  * @return value value (big decimal or integer)
  */
 public Object getValue() {
   if (m_text == null || m_text.getText() == null || m_text.getText().length() == 0) return null;
   String value = m_text.getText();
   //	return 0 if text deleted
   if (value == null || value.length() == 0) {
     if (!m_modified) return null;
     if (m_displayType == DisplayType.Integer) return new Integer(0);
     return Env.ZERO;
   }
   if (value.equals(".") || value.equals(",") || value.equals("-")) value = "0";
   // arboleda - solve bug [ 1759771 ] Parse exception when you enter ".." in a numeric field
   if (value.equals("..")) {
     value = "0";
     m_text.setText(".");
   }
   try {
     Number number = m_format.parse(value);
     value = number.toString(); // 	converts it to US w/o thousands
     BigDecimal bd = new BigDecimal(value);
     if (m_displayType == DisplayType.Integer) return new Integer(bd.intValue());
     if (bd.signum() == 0) return bd;
     return bd.setScale(m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP);
   } catch (Exception e) {
     log.log(Level.SEVERE, "Value=" + value, e);
   }
   m_text.setText(m_format.format(0));
   if (m_displayType == DisplayType.Integer) return new Integer(0);
   return Env.ZERO;
 } //	getValue
  /**
   * Fill m_Values with Ref_List values
   *
   * @param AD_Reference_ID reference
   */
  private void readReference(int AD_Reference_ID) {
    m_values = new HashMap<String, String>();

    String SQL;
    if (Env.isBaseLanguage(Env.getCtx(), "AD_Ref_List"))
      SQL = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=?";
    else
      SQL =
          "SELECT l.Value, t.Name FROM AD_Ref_List l, AD_Ref_List_Trl t "
              + "WHERE l.AD_Ref_List_ID=t.AD_Ref_List_ID"
              + " AND t.AD_Language='"
              + Env.getAD_Language(Env.getCtx())
              + "'"
              + " AND l.AD_Reference_ID=?";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(SQL, null);
      pstmt.setInt(1, AD_Reference_ID);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        String value = rs.getString(1);
        String name = rs.getString(2);
        m_values.put(value, name);
      }

    } catch (SQLException e) {
      logger.log(Level.SEVERE, SQL, e);
    } finally {
      DB.close(rs, pstmt);
    }
  } //  readReference
Beispiel #21
0
  /**
   * Find the periods in a calendar year it need not be a standard period (used in MRP)
   *
   * @param C_Year_ID Year
   * @param periodType Period Type
   * @param ctx context
   * @param trx trx
   * @return MPeriod[]
   */
  public static MPeriod[] getAllPeriodsInYear(int C_Year_ID, String periodType, Ctx ctx, Trx trx) {

    List<MPeriod> periods = new ArrayList<MPeriod>();
    String sql = "SELECT * FROM C_Period WHERE IsActive='Y'";

    sql = sql + " AND C_Year_ID = ?";

    if (periodType != null) sql = sql + " AND PeriodType = ? ";

    sql = sql + " order by StartDate ";

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, trx);
      pstmt.setInt(1, C_Year_ID);

      if (periodType != null) pstmt.setString(2, periodType);

      rs = pstmt.executeQuery();
      while (rs.next()) periods.add(new MPeriod(ctx, rs, trx));
    } catch (Exception e) {
      s_log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
    MPeriod[] retValue = new MPeriod[periods.size()];
    periods.toArray(retValue);
    return retValue;
  }
  @Override
  public void init(int WindowNo, FormFrame frame) {
    m_WindowNo = WindowNo;
    m_frame = frame;
    log.info(
        "WinNo="
            + m_WindowNo
            + " - AD_Client_ID="
            + m_AD_Client_ID
            + ", AD_Org_ID="
            + m_AD_Org_ID
            + ", By="
            + m_by);
    Env.getCtx().setIsSOTrx(m_WindowNo, false);
    trans = Trx.get("XX_ModifyDebtCredit");

    try {
      //	UI
      jbInit();
      dynInit();
      frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
      frame.getContentPane().add(statusBar, BorderLayout.SOUTH);

    } catch (Exception e) {
      log.log(Level.SEVERE, "", e);
    }
  }
  /**
   * @author Fernando de O Moraes (fernando.moraes @ faire.com.br)
   * @return
   */
  private MCity[] getCCity() {
    ArrayList<MCity> list = new ArrayList<MCity>();
    String sql = "SELECT * FROM C_City WHERE C_Region_ID=? ORDER BY Name";
    try {

      PreparedStatement stmt = DB.prepareStatement(sql, null);
      stmt.setInt(1, m_location.getC_Region_ID());

      ResultSet rs = stmt.executeQuery();
      while (rs.next()) {
        MCity r = new MCity(Env.getCtx(), rs, null);
        list.add(r);
      }

      rs.close();
      stmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }

    MCity[] retValue = new MCity[list.size()];
    list.toArray(retValue);
    // Arrays.sort(retValue);

    return retValue;
  }
Beispiel #24
0
 /**
  * Uses PackInHandler to update AD.
  *
  * @param fileName xml file to read
  * @return status message
  */
 public String importXML(String fileName, Properties ctx, String trxName) throws Exception {
   log.info("importXML:" + fileName);
   File in = new File(fileName);
   if (!in.exists()) {
     String msg = "File does not exist: " + fileName;
     log.info("importXML:" + msg);
     return msg;
   }
   try {
     log.info("starting");
     System.setProperty(
         "javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
     PackInHandler handler = new PackInHandler();
     handler.set_TrxName(trxName);
     handler.setCtx(ctx);
     handler.setProcess(this);
     SAXParserFactory factory = SAXParserFactory.newInstance();
     SAXParser parser = factory.newSAXParser();
     String msg = "Start Parser";
     log.info(msg);
     parser.parse(in, handler);
     msg = "End Parser";
     log.info(msg);
     return "OK.";
   } catch (Exception e) {
     log.log(Level.SEVERE, "importXML:", e);
     throw e;
   }
 }
  void dynDepartament() {
    KeyNamePair cat = (KeyNamePair) categoryCombo.getSelectedItem();
    departmentCombo.removeActionListener(this);
    departmentCombo.removeAllItems();

    String sql = "SELECT XX_VMR_DEPARTMENT_ID, VALUE||'-'||NAME " + " FROM XX_VMR_DEPARTMENT ";

    if (cat != null && cat.getKey() != -1) {
      sql += " WHERE XX_VMR_CATEGORY_ID = " + cat.getKey();
    }
    sql += " ORDER BY VALUE||'-'||NAME ";
    sql = MRole.getDefault().addAccessSQL(sql, "", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();

      departmentCombo.addItem(new KeyNamePair(-1, null));
      while (rs.next()) {
        departmentCombo.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
      }
      rs.close();
      pstmt.close();

      departmentCombo.addActionListener(this);
      departmentCombo.setEnabled(true);
      departmentCombo.setEditable(true);
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
  }
Beispiel #26
0
 /**
  * Get Restriction Lines
  *
  * @param reload reload data
  * @return array of lines
  */
 public MGoalRestriction[] getRestrictions(boolean reload) {
   if (m_restrictions != null && !reload) return m_restrictions;
   ArrayList<MGoalRestriction> list = new ArrayList<MGoalRestriction>();
   //
   String sql =
       "SELECT * FROM PA_GoalRestriction "
           + "WHERE PA_Goal_ID=? AND IsActive='Y' "
           + "ORDER BY Org_ID, C_BPartner_ID, M_Product_ID";
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, get_Trx());
     pstmt.setInt(1, getPA_Goal_ID());
     rs = pstmt.executeQuery();
     while (rs.next()) list.add(new MGoalRestriction(getCtx(), rs, get_Trx()));
   } catch (Exception e) {
     log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeStatement(pstmt);
     DB.closeResultSet(rs);
   }
   //
   m_restrictions = new MGoalRestriction[list.size()];
   list.toArray(m_restrictions);
   return m_restrictions;
 } //	getRestrictions
 /**
  * ************************************************************************ Write to file
  *
  * @param sb string buffer
  * @param fileName file name
  */
 private void writeToFile(StringBuffer sb, String fileName) {
   try {
     File out = new File(fileName);
     FileWriter fw = new FileWriter(out);
     for (int i = 0; i < sb.length(); i++) {
       char c = sb.charAt(i);
       //	after
       if (c == ';' || c == '}') {
         fw.write(c);
         if (sb.substring(i + 1).startsWith("//")) fw.write('\t');
         else fw.write(Env.NL);
       }
       //	before & after
       else if (c == '{') {
         fw.write(Env.NL);
         fw.write(c);
         fw.write(Env.NL);
       } else fw.write(c);
     }
     fw.flush();
     fw.close();
     float size = out.length();
     size /= 1024;
     log.info(out.getAbsolutePath() + " - " + size + " kB");
   } catch (Exception ex) {
     log.log(Level.SEVERE, fileName, ex);
   }
 } //	writeToFile
Beispiel #28
0
  /**
   * Initialize Panel
   *
   * @param WindowNo window
   */
  protected void initForm() {
    log.info("");
    try {
      jbInit();
      dynInit();

      this.setWidth("100%");
      this.setClosable(true);
      this.setTitle("Import File Loader");
      this.setBorder("normal");

      Borderlayout layout = new Borderlayout();
      layout.setHeight("100%");
      layout.setWidth("100%");
      this.appendChild(layout);
      North north = new North();
      layout.appendChild(north);
      north.appendChild(northPanel);
      Center center = new Center();
      center.setFlex(true);
      layout.appendChild(center);
      center.appendChild(centerPanel);
      South south = new South();
      layout.appendChild(south);
      south.appendChild(confirmPanel);
    } catch (Exception e) {
      log.log(Level.SEVERE, "init", e);
    }
  } //	init
Beispiel #29
0
  @Override
  public void loadData(Object... params) {
    if (sql == null)
      throw new IllegalStateException(
          "Table not initialized. Please use prepareTable method first");

    int selectedId = getSelectedId();

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      DB.setParameters(pstmt, params);
      rs = pstmt.executeQuery();
      this.loadTable(rs);
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }

    selectById(selectedId);
  }
Beispiel #30
0
  /** Reload/Load file */
  private void cmd_reloadFile() {
    if (m_file_istream == null) return;

    m_data.clear();
    rawData.setText("");

    try {
      //  see NaturalAccountMap

      ListItem listitem = fCharset.getSelectedItem();
      Charset charset = null;

      if (listitem == null) return;

      charset = (Charset) listitem.getValue();
      BufferedReader in = new BufferedReader(new InputStreamReader(m_file_istream, charset), 10240);

      //	not safe see p108 Network pgm
      String s = null;
      String concat = "";

      while ((s = in.readLine()) != null) {
        m_data.add(s);

        concat += s;
        concat += "\n";

        if (m_data.size() < MAX_LOADED_LINES) {
          rawData.setValue(concat);
        }
      }
      in.close();
    } catch (Exception e) {
      log.log(Level.SEVERE, "", e);
      bFile.setLabel(Msg.getMsg(Env.getCtx(), "FileImportFile"));
    }

    int index = 1; // 	second line as first may be heading

    if (m_data.size() == 1) index = 0;

    int length = 0;

    if (m_data.size() > 0) length = m_data.get(index).toString().length();

    info.setValue(
        Msg.getMsg(Env.getCtx(), "Records")
            + "="
            + m_data.size()
            + ", "
            + Msg.getMsg(Env.getCtx(), "Length")
            + "="
            + length
            + "   ");

    // setCursor (Cursor.getDefaultCursor());

    log.config("Records=" + m_data.size() + ", Length=" + length);
  } //	cmd_loadFile