示例#1
0
  private void createReport() {
    Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Account root = engine.getRootAccount();

    baseCommodity = engine.getDefaultCurrency();

    numberFormat = CommodityFormat.getFullNumberFormat(baseCommodity);
    SimpleDateFormat df = new SimpleDateFormat("dd-MMMMM-yyyy");

    dates = getDates();

    // title and dates
    pl.add(rb.getString("Title.ProfitLoss"));
    pl.add("");
    pl.add("From " + df.format(dates[0]) + " To " + df.format(dates[1]));
    pl.add("");
    pl.add("");

    // Income
    pl.add("Income");
    pl.add("------------------------------------------------------");
    getBalances(root, dates, AccountType.INCOME);

    // Add up the  Gross Income.
    BigDecimal total1 = BigDecimal.ZERO;
    for (Object aBalance1 : balance) {
      total1 = total1.add((BigDecimal) aBalance1);
    }
    pl.add("------------------------------------------------------");
    pl.add(formatAcctNameOut(rb.getString("Word.GrossIncome")) + " " + formatDecimalOut(total1));
    pl.add("------------------------------------------------------");
    pl.add("");
    pl.add("");

    // Expense
    pl.add("Expenses");
    pl.add("------------------------------------------------------");
    balance = new ArrayList<>();
    getBalances(root, dates, AccountType.EXPENSE);

    // Add up the Gross Expenses
    BigDecimal total2 = BigDecimal.ZERO;
    for (Object aBalance : balance) {
      total2 = total2.add((BigDecimal) aBalance);
    }
    pl.add("------------------------------------------------------");
    pl.add(formatAcctNameOut(rb.getString("Word.GrossExpense")) + " " + formatDecimalOut(total2));
    pl.add("------------------------------------------------------");
    pl.add("");
    pl.add("");

    // Net Total
    pl.add("------------------------------------------------------");
    pl.add(
        formatAcctNameOut(rb.getString("Word.NetIncome"))
            + " "
            + formatDecimalOut(total1.add(total2)));
    pl.add("======================================================");
  }
  private void loadAccountTree() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

    if (engine != null) {
      RootAccount r = engine.getRootAccount();

      final TreeItem<Account> root = new TreeItem<>(r);
      root.setExpanded(true);

      treeTableView.setRoot(root);
      loadChildren(root);
    } else {
      treeTableView.setRoot(null);
    }
  }
  @Test
  public void testExportBudgetResultsModel() throws Exception {

    File file = File.createTempFile("budget", ".xml");
    file.deleteOnExit();

    Engine e =
        EngineFactory.bootLocalEngine(
            file.getName(), EngineFactory.DEFAULT, PASSWORD, DataStoreType.XML);
    CurrencyNode node = e.getDefaultCurrency();

    Account account1 = new Account(AccountType.EXPENSE, node);
    account1.setName("Expense 1");
    e.addAccount(e.getRootAccount(), account1);

    Account account2 = new Account(AccountType.EXPENSE, node);
    account2.setName("Expense 2");
    e.addAccount(e.getRootAccount(), account2);

    Budget budget = new Budget();
    budget.setName("My Budget");
    budget.setDescription("Test");
    budget.setBudgetPeriod(BudgetPeriod.MONTHLY);

    e.addBudget(budget);

    BudgetResultsModel model = new BudgetResultsModel(budget, 2012, node);

    BudgetResultsExport.exportBudgetResultsModel(
        new File(System.getProperty("java.io.tmpdir") + File.separator + "testworkbook.xls"),
        model);

    // file.delete();

    assertTrue(true);
  }
示例#4
0
  @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);
    }
  }
示例#5
0
  private Account generateAccount(final String accountClass, final Map<String, Object> elementMap) {

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

    CurrencyNode node = decodeCurrency((String) elementMap.get("commodity"));

    if (accountClass.equals("RootAccount")) {
      engine.setDefaultCurrency(node);
      return engine.getRootAccount();
    }

    Account account = null;

    switch (accountClass) {
      case "BankAccount":
        account = new Account(AccountType.BANK, node);
        break;
      case "ExpenseAccount":
        account = new Account(AccountType.EXPENSE, node);
        break;
      case "IncomeAccount":
        account = new Account(AccountType.INCOME, node);
        break;
      case "InvestmentAccount":
        {
          account = new Account(AccountType.INVEST, node);

          String[] securities = (String[]) elementMap.get("securities");

          if (securities != null) {
            for (String s : securities) {
              SecurityNode sNode = decodeSecurity(s);
              account.addSecurity(sNode);
            }
          }
          break;
        }
      case "MutualFundAccount":
        {
          account = new Account(AccountType.MUTUAL, node);

          String[] securities = (String[]) elementMap.get("securities");

          if (securities != null) {
            for (String s : securities) {
              SecurityNode sNode = decodeSecurity(s);
              account.addSecurity(sNode);
            }
          }
          break;
        }
      case "CreditAccount":
        account = new Account(AccountType.CREDIT, node);
        break;
      case "CashAccount":
        account = new Account(AccountType.CASH, node);
        break;
      case "EquityAccount":
        account = new Account(AccountType.EQUITY, node);
        break;
      case "LiabilityAccount":
        account = new Account(AccountType.LIABILITY, node);
        break;
      case "AssetAccount":
        account = new Account(AccountType.ASSET, node);
        break;
      default:
        break;
    }

    if (account != null) {
      account.setName((String) elementMap.get("name"));
      account.setDescription((String) elementMap.get("description"));
      account.setNotes((String) elementMap.get("notes"));
      account.setVisible(Boolean.parseBoolean((String) elementMap.get("visible")));
      account.setPlaceHolder(Boolean.parseBoolean((String) elementMap.get("placeHolder")));
      account.setAccountNumber((String) elementMap.get("code"));
    }
    return account;
  }