예제 #1
0
 private static String getTransactionList(final Account account) {
   switch (account.getAccountType()) {
     case INVEST:
     case MUTUAL:
       return INVTRANLIST;
     default:
       return BANKTRANLIST;
   }
 }
예제 #2
0
  void getBalances(final Account a, final Date[] dates1, final AccountType type) {

    for (Account child : a.getChildren()) {
      int len = child.getTransactionCount();
      if ((SHOW_EMPTY_ACCOUNT || len > 0) && type == child.getAccountType()) {
        String acctName = child.getName();

        BigDecimal acctBal =
            AccountBalanceDisplayManager.convertToSelectedBalanceMode(
                child.getAccountType(), child.getBalance(dates1[0], dates1[1], baseCommodity));

        // output account name and balance
        pl.add(formatAcctNameOut(acctName) + " " + formatDecimalOut(acctBal));

        balance.add(acctBal);
      }
      if (child.isParent()) {
        getBalances(child, dates1, type);
      }
    }
  }
예제 #3
0
파일: Import.java 프로젝트: CptMauli/jgnash
  void importAccounts(final XMLStreamReader reader) {

    logger.info("Begin Account import");

    try {
      parse:
      while (reader.hasNext()) {
        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            if (reader.getAttributeCount() > 0) {
              if (reader.getAttributeValue(0).contains("Account")) {
                logger.finest("Found the start of an Account");
                parseAccount(reader);
              }
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getLocalName().equals("objects")) {
              logger.finest("Found the end of the object list and accounts");
              break parse;
            }
            break;
          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, e.toString(), e);
    }

    logger.info("Linking accounts");

    Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

    for (Account account : parentMap.keySet()) {
      if (account.getAccountType() != AccountType.ROOT) {
        Account parent = accountMap.get(parentMap.get(account));
        if (!account.getParent().equals(parent)) {
          if (engine.moveAccount(account, parent)) {
            logger.log(
                Level.FINEST,
                "Moving {0} to {1}",
                new Object[] {account.getName(), parent.getName()});
          }
        }
      }
    }

    logger.info("Account import complete");
  }
예제 #4
0
 private static String getAccountFromAggregate(final Account account) {
   switch (account.getAccountType()) {
     case ASSET:
     case BANK:
     case CASH:
     case CHECKING:
     case SIMPLEINVEST:
       return BANKACCTFROM;
     case CREDIT:
     case LIABILITY:
       return CCACCTFROM;
     case INVEST:
     case MUTUAL:
       return INVACCTFROM;
     default:
       return "";
   }
 }
예제 #5
0
 private static String getStatementResponse(final Account account) {
   switch (account.getAccountType()) {
     case ASSET:
     case BANK:
     case CASH:
     case CHECKING:
     case SIMPLEINVEST:
       return STMTRS;
     case CREDIT:
     case LIABILITY:
       return CCSTMTRS;
     case INVEST:
     case MUTUAL:
       return INVSTMTRS;
     default:
       return "";
   }
 }
예제 #6
0
 private static String getBankingMessageSetAggregate(final Account account) {
   switch (account.getAccountType()) {
     case ASSET:
     case BANK:
     case CASH:
     case CHECKING:
     case SIMPLEINVEST:
       return BANKMSGSRSV1;
     case CREDIT:
     case LIABILITY:
       return CREDITCARDMSGSRSV1;
     case INVEST:
     case MUTUAL:
       return INVSTMTMSGSRSV1;
     default:
       return "";
   }
 }
  public AccountSecurityComboBox(final Account acc) {
    super();

    if (acc == null || acc.getAccountType().getAccountGroup() != AccountGroup.INVEST) {
      throw new IllegalArgumentException(
          Resource.get().getString("Message.Error.InvalidAccountGroup"));
    }

    this.account = acc;

    addAll(account.getSecurities());

    if (model.getSize() > 0) {
      setSelectedIndex(0);
    }

    registerListeners();
  }
예제 #8
0
  /**
   * Writes one bank transaction
   *
   * @param transaction <code>Transaction</code> to write
   */
  private void writeBankTransaction(final Transaction transaction) {
    indentedWriter.println(wrapOpen(STMTTRN), indentLevel++);
    indentedWriter.println(
        wrapOpen(TRNTYPE)
            + (transaction.getAmount(account).compareTo(BigDecimal.ZERO) == 1 ? CREDIT : DEBIT),
        indentLevel);

    indentedWriter.println(wrapOpen(DTPOSTED) + encodeDate(transaction.getDate()), indentLevel);
    indentedWriter.println(
        wrapOpen(TRNAMT) + transaction.getAmount(account).toPlainString(), indentLevel);
    indentedWriter.println(wrapOpen(REFNUM) + transaction.getUuid(), indentLevel);
    indentedWriter.println(wrapOpen(NAME) + transaction.getPayee(), indentLevel);
    indentedWriter.println(wrapOpen(MEMO) + transaction.getMemo(), indentLevel);

    // write the check number if applicable
    if (account.getAccountType() == AccountType.CHECKING && !transaction.getNumber().isEmpty()) {
      indentedWriter.println(wrapOpen(CHECKNUM) + transaction.getNumber(), indentLevel);
    }

    // write out the banks transaction id if previously imported
    writeFitID(transaction);

    indentedWriter.println(wrapClose(STMTTRN), --indentLevel);
  }
예제 #9
0
파일: Import.java 프로젝트: CptMauli/jgnash
  @SuppressWarnings({"unchecked", "ConstantConditions"})
  private void parseAccount(final XMLStreamReader reader) {

    assert reader.getAttributeCount() == 2;

    Map<String, Object> elementMap = new HashMap<>();

    /* still at start of the account.  Need to know when end is reached */
    QName parsingElement = reader.getName();

    String accountClass = reader.getAttributeValue(0);
    String accountId = reader.getAttributeValue(1);

    try {
      while (reader.hasNext()) {
        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            String element = reader.getLocalName();

            switch (element) {
              case "securities":
                logger.info("Parsing account securities");
                elementMap.put("securities", parseAccountSecurities(reader));
                break;
              case "amortize":
                logger.info("Parsing amortize object");
                elementMap.put("amortize", parseAmortizeObject(reader));
                break;
              case "locked":
                lockMap.put(accountId, Boolean.valueOf(reader.getElementText()));
                break;
              default:
                elementMap.put(element, reader.getElementText());
                break;
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getName().equals(parsingElement)) {
              logger.finest("Found the end of an Account");

              Account account = generateAccount(accountClass, elementMap);

              if (account != null) {
                accountMap.put(accountId, account);

                // do not put the root account into the parent map
                if (account.getAccountType() != AccountType.ROOT) {
                  parentMap.put(account, (String) elementMap.get("parentAccount"));
                }

                if (account.getAccountType() != AccountType.ROOT) {
                  Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

                  engine.addAccount(engine.getRootAccount(), account);

                  if (account.getAccountType() == AccountType.LIABILITY) {
                    Map<String, String> amortizeObject =
                        (Map<String, String>) elementMap.get("amortize");

                    if (amortizeObject != null) {
                      AOThread t = new AOThread(account, amortizeObject);
                      workQueue.add(t);
                    }
                  }
                }
              }
              return;
            }
            break;
          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, "Error importing account id: {0}", accountId);
      logger.log(Level.SEVERE, e.toString(), e);
    }
  }
예제 #10
0
  public void exportAccount() {

    final Date exportDate = new Date();

    if (account == null || startDate == null || endDate == null || file == null) {
      throw new RuntimeException();
    }

    // force a correct file extension
    final String fileName = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".ofx";

    try (IndentedPrintWriter writer =
        new IndentedPrintWriter(
            new BufferedWriter(
                new OutputStreamWriter(
                    new FileOutputStream(fileName), Charset.forName("windows-1252"))))) {

      indentedWriter = writer;

      // write the required header
      for (String line : OFXHEADER) {
        writer.println(line, indentLevel);
      }
      writer.println();

      // start of data
      writer.println(wrapOpen(OFX), indentLevel++);

      // write sign-on response
      writer.println(wrapOpen(SIGNONMSGSRSV1), indentLevel++);
      writer.println(wrapOpen(SONRS), indentLevel++);
      writer.println(wrapOpen(STATUS), indentLevel++);
      writer.println(wrapOpen(CODE) + "0", indentLevel);
      writer.println(wrapOpen(SEVERITY) + "INFO", indentLevel);
      writer.println(wrapClose(STATUS), --indentLevel);
      writer.println(wrapOpen(DTSERVER) + encodeDate(exportDate), indentLevel);
      writer.println(wrapOpen(LANGUAGE) + "ENG", indentLevel);
      writer.println(wrapClose(SONRS), --indentLevel);
      writer.println(wrapClose(SIGNONMSGSRSV1), --indentLevel);

      writer.println(wrapOpen(getBankingMessageSetAggregate(account)), indentLevel++);
      writer.println(wrapOpen(getResponse(account)), indentLevel++);
      writer.println(wrapOpen(TRNUID) + "1", indentLevel);
      writer.println(wrapOpen(STATUS), indentLevel++);
      writer.println(wrapOpen(CODE) + "0", indentLevel);
      writer.println(wrapOpen(SEVERITY) + "INFO", indentLevel);
      writer.println(wrapClose(STATUS), --indentLevel);

      // begin start of statement response
      writer.println(wrapOpen(getStatementResponse(account)), indentLevel++);
      writer.println(wrapOpen(CURDEF) + account.getCurrencyNode().getSymbol(), indentLevel);

      // write account identification
      writer.println(wrapOpen(getAccountFromAggregate(account)), indentLevel++);

      switch (account.getAccountType()) {
        case INVEST:
        case MUTUAL:
          writer.println(
              wrapOpen(BROKERID),
              indentLevel); //  required for investment accounts, but jGnash does not manage a
                            // broker ID, normally a web URL
          break;
        default:
          writer.println(
              wrapOpen(BANKID) + account.getBankId(), indentLevel); // savings and checking only
          break;
      }

      writer.println(wrapOpen(ACCTID) + account.getAccountNumber(), indentLevel);

      // write the required account type
      switch (account.getAccountType()) {
        case CHECKING:
          writer.println(wrapOpen(ACCTTYPE) + CHECKING, indentLevel);
          break;
        case ASSET:
        case BANK:
        case CASH:
          writer.println(wrapOpen(ACCTTYPE) + SAVINGS, indentLevel);
          break;
        case CREDIT:
        case LIABILITY:
          writer.println(wrapOpen(ACCTTYPE) + CREDITLINE, indentLevel);
          break;
        case SIMPLEINVEST:
          writer.println(wrapOpen(ACCTTYPE) + MONEYMRKT, indentLevel);
          break;
        default:
          break;
      }

      writer.println(wrapClose(getAccountFromAggregate(account)), --indentLevel);

      // begin start of transaction list
      writer.println(wrapOpen(getTransactionList(account)), indentLevel++);
      writer.println(wrapOpen(DTSTART) + encodeDate(startDate), indentLevel);
      writer.println(wrapOpen(DTEND) + encodeDate(endDate), indentLevel);

      // write the transaction list
      if (account.getAccountType() == AccountType.INVEST
          || account.getAccountType() == AccountType.MUTUAL) {
        writeInvestmentTransactions();
      } else {
        writeBankTransactions();
      }

      // end of transaction list
      writer.println(wrapClose(getTransactionList(account)), --indentLevel);

      // write ledger balance
      writer.println(wrapOpen(LEDGERBAL), indentLevel++);
      writer.println(wrapOpen(BALAMT) + account.getBalance(endDate).toPlainString(), indentLevel);
      writer.println(wrapOpen(DTASOF) + encodeDate(exportDate), indentLevel);
      writer.println(wrapClose(LEDGERBAL), --indentLevel);

      // end of statement response
      writer.println(wrapClose(getStatementResponse(account)), --indentLevel);
      writer.println(wrapClose(getResponse(account)), --indentLevel);
      writer.println(wrapClose(getBankingMessageSetAggregate(account)), --indentLevel);

      // finished
      writer.println(wrapClose(OFX), --indentLevel);
    } catch (IOException e) {
      Logger.getLogger(OfxExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }