Package nu.lazy8.ledger.jdbc

Examples of nu.lazy8.ledger.jdbc.DataConnection


   * @param  compId           Description of the Parameter
   * @param  isSortByAccType  Description of the Parameter
   */
  BalanceResultTable(JFrame view, java.sql.Date startDateIn, java.sql.Date stopDateIn,
      int compId, boolean isSortByAccType) {
    DataConnection dc = DataConnection.getInstance(view);
    if (dc == null || !dc.bIsConnectionMade) {
      return;
    }
    try {
      Statement st = dc.con.createStatement();
      String select = "SELECT APP.Account.Account,AccDesc,TypeName,IsInBalanceReport " +
          "FROM APP.Account,AccountType WHERE AccountType.AccTypeId=APP.Account.IsAsset " +
          "AND AccountType.CompId=APP.Account.CompId AND AccountType.CompId=" +
          compId;
      if (isSortByAccType) {
        select = select + " ORDER BY IsInBalanceReport DESC,SortOrder,APP.Account.Account";
      } else {
        select = select + " ORDER BY APP.Account.Account";
      }
      ResultSet rs = st.executeQuery(dc.filterSQL(select));
      if (rs.next()) {
        //count how many rows
        int numRows = 0;
        rs.last();
        numRows = rs.getRow();
View Full Code Here


   */
  protected void ImportFile() {
    if (!isAllRequiredFieldsMatched()) {
      return;
    }
    DataConnection dc = DataConnection.getInstance(view);
    if (dc == null || !dc.bIsConnectionMade) {
      return;
    }
    String[] t;
    int rowCount = 0;
View Full Code Here

  protected StringBuffer TestSetup() {
    StringBuffer resultMessage = new StringBuffer();
    if (!isAllRequiredFieldsMatched()) {
      return resultMessage;
    }
    DataConnection dc = DataConnection.getInstance(view);
    if (dc == null || !dc.bIsConnectionMade) {
      return resultMessage;
    }
    //load from the file
    String[] t;
View Full Code Here

   * @param  workDialog  Description of the Parameter
   */
  private void UpgradeAccounts(WorkingDialog workDialog) {
    //convert all the accounts IsAsset field to show more asset/debt/income/expense
    try {
      DataConnection dc = new DataConnection(null);
      if (dc == null || !dc.bIsConnectionMade) {
        return;
      }
      Statement st = dc.con.createStatement();
      ResultSet rsAccounts = st.executeQuery(dc.filterSQL(
          "SELECT APP.Account.Account FROM APP.Account WHERE " +
          "(IsAsset=0 AND (APP.Account.Account<3000 OR APP.Account.Account>=10000)) " +
          "OR (IsAsset=1 AND (APP.Account.Account<1000 OR APP.Account.Account>=3000)) "));
      int numEuBasErrors = 0;
      if (rsAccounts.next()) {
        rsAccounts.last();
        numEuBasErrors = rsAccounts.getRow();
      }
      st = dc.con.createStatement();
      rsAccounts = st.executeQuery(dc.filterSQL(
          "SELECT CompId,APP.Account.Account,AccDesc,IsAsset FROM APP.Account"));
      int numRows = 0;
      if (rsAccounts.next()) {
        rsAccounts.last();
        numRows = rsAccounts.getRow();
        rsAccounts.beforeFirst();
      }
      if (numRows > 0) {
        int ACCOUNT_TYPE_ASSET = 0;
        int ACCOUNT_TYPE_DEBT = 1;
        int ACCOUNT_TYPE_INCOME = 2;
        int ACCOUNT_TYPE_EXPENSE = 3;
        boolean isEuBasAccounting = true;
        if ((numEuBasErrors * 100 / numRows) > 10) {
          //more then 10% errors
          isEuBasAccounting = false;
        }
        //attempt to see if this is a EU BAS 2000 account. system
        rsAccounts.beforeFirst();
        while (rsAccounts.next()) {
          //sum up account
          workDialog.SetProgress(100 * rsAccounts.getRow() / numRows);
          int oldIsAsset = rsAccounts.getInt(4);
          int defaultIsAsset = 0;
          int AccountNum = rsAccounts.getInt(2);
          if (isEuBasAccounting) {
            //assume this is the EU bas 2000 accounting system
            //these numbers are hard coded now because at this point, the AccountType
            //table does not exist.
            if (AccountNum < 2000) {
              defaultIsAsset = ACCOUNT_TYPE_ASSET;
            } else if (AccountNum >= 2000 && AccountNum < 3000) {
              defaultIsAsset = ACCOUNT_TYPE_DEBT;
            } else if ((AccountNum >= 3000 && AccountNum < 4000)
                 || (AccountNum >= 8000 && AccountNum < 8400)
                 || (AccountNum >= 8700 && AccountNum < 8750)
                 || (AccountNum >= 8800 && AccountNum < 8900)
                 || (AccountNum >= 8990 && AccountNum < 9000)) {
              defaultIsAsset = ACCOUNT_TYPE_INCOME;
            } else if ((AccountNum >= 4000 && AccountNum < 8000)
                 || (AccountNum >= 8400 && AccountNum < 8700)
                 || (AccountNum >= 8750 && AccountNum < 8800)
                 || (AccountNum >= 8900 && AccountNum < 8990)) {
              defaultIsAsset = ACCOUNT_TYPE_EXPENSE;
            } else {
              if (oldIsAsset == 0) {
                defaultIsAsset = ACCOUNT_TYPE_INCOME;
              } else {
                defaultIsAsset = ACCOUNT_TYPE_ASSET;
              }
            }
          } else {
            Statement st2 = dc.con.createStatement();
            ResultSet rsSumAccounts = st2.executeQuery(dc.filterSQL(
                "SELECT Sum(Amount.Amount * ((2 * Amount.IsDebit) - 1) ) AS SumOfAmount1 " +
                "FROM Amount WHERE CompId=" + rsAccounts.getInt(1)
                 + " AND Amount.Account=" + AccountNum));
            if (oldIsAsset == 0) {
              defaultIsAsset = ACCOUNT_TYPE_INCOME;
            } else {
              defaultIsAsset = ACCOUNT_TYPE_ASSET;
            }
            if (rsSumAccounts.next()) {
              double amount = rsSumAccounts.getDouble(1);
              if (oldIsAsset == 0) {
                if (amount >= 0) {
                  defaultIsAsset = ACCOUNT_TYPE_EXPENSE;
                } else {
                  defaultIsAsset = ACCOUNT_TYPE_INCOME;
                }
              } else {
                if (amount >= 0) {
                  defaultIsAsset = ACCOUNT_TYPE_ASSET;
                } else {
                  defaultIsAsset = ACCOUNT_TYPE_DEBT;
                }
              }
            }
          }
          Statement st3 = dc.con.createStatement();
          st3.executeUpdate(dc.filterSQL(
              "UPDATE APP.Account SET IsAsset=" + defaultIsAsset + " WHERE CompId="
               + rsAccounts.getInt(1) + " AND APP.Account.Account=" + AccountNum));
        }
      }
    } catch (Exception eee) {
View Full Code Here

   *  Description of the Method
   *
   * @param  view  Description of the Parameter
   */
  public static void createBackupCompanyFrame(JFrame view) {
    DataConnection dc = DataConnection.getInstance(view);
    if (dc == null || !dc.bIsConnectionMade) {
      return;
    }
    DatabaseBackup db = new DatabaseBackup(
        dc.con);
View Full Code Here

   *  Description of the Method
   *
   * @param  view  Description of the Parameter
   */
  public static void createBackupFrame(JFrame view) {
    DataConnection dc = DataConnection.getInstance(view);
    if (dc == null || !dc.bIsConnectionMade) {
      return;
    }
    DatabaseBackup db = new DatabaseBackup(
        dc.con);
View Full Code Here

   *  Description of the Method
   *
   * @param  view  Description of the Parameter
   */
  public static void createRestoreCompanyFrame(JFrame view) {
    DataConnection dc = DataConnection.getInstance(view);
    if (dc == null || !dc.bIsConnectionMade) {
      return;
    }
    DatabaseBackup db = new DatabaseBackup(
        dc.con);
View Full Code Here

   *  Description of the Method
   *
   * @param  view  Description of the Parameter
   */
  public static void createRestoreFrame(JFrame view) {
    DataConnection dc = DataConnection.getInstance(view);
    if (dc == null || !dc.bIsConnectionMade) {
      return;
    }
    DatabaseBackup db = new DatabaseBackup(
        dc.con);
View Full Code Here

        SetupInfo.setBoolProperty(SetupInfo.WARNING_BEFORE_RE_ADDING, true);
        SetupInfo.store();
        //lots of database changes to make
        //need a connection to the database
        try {
          DataConnection dc = new DataConnection(null);
          if (dc == null || !dc.bIsConnectionMade) {
            JOptionPane.showMessageDialog(null,
                Translator.getTranslation("Could not connect to the database.  Do not attempt to continue."),
                Translator.getTranslation("Must restart"),
                JOptionPane.PLAIN_MESSAGE);
            isInStart=false;
            return;
          }
          new UseEquityHelpDialog(null, false);
          //every company must have these new account types entered
          Statement st ;
          PreparedStatement prepSt;
          DataConnection.AddDefaultAccountTypes(0);
          //copy old Customer table into new Customer2 table
          st = dc.con.createStatement();
          ResultSet rsOldCustomers = st.executeQuery(dc.filterSQL(
              "SELECT CompId,CustId,CustName,CustDesc  FROM Customer"));
          while (rsOldCustomers.next()) {
            prepSt = dc.con.prepareStatement("INSERT INTO Customer2 (CompId,CustId,CustName,CustDesc,DefaultAcc) VALUES (?,?,?,?,?)");
            prepSt.setInt(1, rsOldCustomers.getInt(1));
            prepSt.setInt(2, rsOldCustomers.getInt(2));
            prepSt.setString(3, rsOldCustomers.getString(3));
            prepSt.setString(4, rsOldCustomers.getString(4));
            prepSt.setInt(5, 0);
            prepSt.executeUpdate();
            SystemLog.ErrorPrintln("Copied row from old customer to new=" + rsOldCustomers.getString(3));
          }
          //delete the old Customer table
          st = dc.con.createStatement();
          st.executeUpdate("DROP TABLE Customer");
          SystemLog.ErrorPrintln("Dropped old table Customer");
        } catch (Exception e) {
          e.printStackTrace();
          //we need to continue because otherwise this is a lock stoping proper usage of lazy8ledger forever
          //return;
        }
      }//}}}
     
      //{{{ Update to 2.20
      if (SetupInfo.getProperty("lazy8ledger.lastRunVersion").compareTo("2.20") < 0) {
        //lots of database changes to make
        //need a connection to the database
        WorkingDialog workDialog = new WorkingDialog(null);
        workDialog.setVisible(true);
        try {
          DataConnection dc = new DataConnection(null);
          if (dc == null || !dc.bIsConnectionMade) {
            JOptionPane.showMessageDialog(null,
                Translator.getTranslation("Could not connect to the database.  Do not attempt to continue."),
                Translator.getTranslation("Must restart"),
                JOptionPane.PLAIN_MESSAGE);
            isInStart=true;
            return;
          }
          //copy old Activity table into new Activity2 table
          //UniqNumGenerator uniqnum = new UniqNumGenerator(); // commented out since never used
          Statement st = dc.con.createStatement();
          ResultSet rsOldTrans = st.executeQuery(dc.filterSQL(
              "SELECT CompId,Act_id,RegDate,InvDate,Notes,FileInfo FROM Activity ORDER BY CompId,Act_id"));
          rsOldTrans.last();
          int numRecs=rsOldTrans.getRow();
          rsOldTrans.beforeFirst();
          while (rsOldTrans.next()) {
View Full Code Here

   */
  public static void AdjustAllPeriodIds(int inCompId) {
    WorkingDialog workDialog = new WorkingDialog(null);
    workDialog.setVisible(true);
    try {
      DataConnection dc = new DataConnection(null);
      if (dc == null || !dc.bIsConnectionMade) {
        return;
      }
      //get rid of all uniq num posts for period ids
      dc.con.createStatement().executeQuery(dc.filterSQL(
        "DELETE FROM UniqNum WHERE UniqName LIKE 'PeriodId=%'"));
      //adjust the periodid for each activity
      UniqNumGenerator uniqnum = new UniqNumGenerator();
      ResultSet rsPeriods=null;
      String select="SELECT CompId,Act_id,InvDate FROM Activity2 ";
      if (inCompId>0)
        select+=" WHERE CompId=" + inCompId;
      select+=" ORDER BY CompId,Act_id";
      ResultSet rsOldTrans = dc.con.createStatement().executeQuery(dc.filterSQL(select));
      int lastCompId=-1;
      rsOldTrans.last();
      int numRecs=rsOldTrans.getRow();
      rsOldTrans.beforeFirst();
      while (rsOldTrans.next()) {
        if (lastCompId!=rsOldTrans.getInt(1)){
          //get all the periods for the CompId
          lastCompId=rsOldTrans.getInt(1);
          rsPeriods=dc.con.createStatement().executeQuery(dc.filterSQL(
            "SELECT StartPeriod,EndPeriod FROM AccountingPeriods WHERE CompId=" + lastCompId));
        }
        Date invoiceDate=rsOldTrans.getDate(3);
        int periodId=0;
        rsPeriods.beforeFirst();
        //find the appropriate period if it exists.
        while (rsPeriods.next()) {
          if (invoiceDate.compareTo(rsPeriods.getDate(1))>=0 && invoiceDate.compareTo(rsPeriods.getDate(2))<=0){
            //increment period id counter
            periodId=uniqnum.GetUniqueNumber("PeriodId="+ rsPeriods.getDate(1) + "-"
              + rsPeriods.getDate(2), 1, 999999999,new Integer(lastCompId));
            break; //we found the period we need
          }
        }
        dc.con.createStatement().executeQuery(dc.filterSQL(
          "UPDATE Activity2 SET PeriodId=" + periodId + " WHERE CompId=" + lastCompId + " AND Act_id=" + rsOldTrans.getInt(2)));
        workDialog.SetProgress((rsOldTrans.getRow() * 100) / (numRecs));
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of nu.lazy8.ledger.jdbc.DataConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.