Beispiel #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("======================================================");
  }
Beispiel #2
0
  private SecurityNode decodeSecurity(final String symbol) {
    Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

    SecurityNode sNode = engine.getSecurity(symbol);

    if (sNode == null) {

      Commodity cNode = commodityMap.get(symbol);

      if (cNode != null) {

        logger.log(Level.INFO, "Converting a commodity into a security: {0}", symbol);

        sNode = new SecurityNode(engine.getDefaultCurrency());

        sNode.setDescription(cNode.description);
        sNode.setPrefix(cNode.prefix);
        sNode.setSuffix(cNode.suffix);
        sNode.setScale(cNode.scale);
        sNode.setSymbol(cNode.symbol);
        sNode.setQuoteSource(QuoteSource.YAHOO);

        engine.addSecurity(sNode);
      } else { // may be a currency... try to create a security

        CurrencyNode currency = decodeCurrency(symbol);

        if (currency != null) {

          logger.info("Converting a currency into a security");

          sNode = new SecurityNode();

          sNode.setDescription(currency.getDescription());
          sNode.setPrefix(currency.getPrefix());
          sNode.setSuffix(currency.getSuffix());
          sNode.setScale(currency.getScale());
          sNode.setSymbol(currency.getSymbol());

          sNode.setReportedCurrencyNode(currency);
          sNode.setQuoteSource(QuoteSource.YAHOO);

          engine.addSecurity(sNode);
        }
      }
    }

    if (sNode == null) {
      logger.log(Level.SEVERE, "Bad file, security {0} not mapped", symbol);
    }

    return sNode;
  }
  @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);
  }
Beispiel #4
0
  private void parseSecurityNode(final XMLStreamReader reader) {
    Map<String, String> elementMap = new HashMap<>();
    List<SecurityHistoryNode> history = null;

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

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

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            if (reader.getLocalName().equals("history")) {
              logger.finest("parse history");
              history = parseHistoryNodes(reader);
            } else {
              String element = reader.getLocalName();
              elementMap.put(element, reader.getElementText());
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getName().equals(parsingElement)) {
              logger.finest("Found the end of a SecurityNode");

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

              if (engine.getSecurity(elementMap.get("symbol")) == null) {

                SecurityNode node = new SecurityNode(engine.getDefaultCurrency());

                node.setSymbol(elementMap.get("symbol"));
                node.setDescription(elementMap.get("description"));
                node.setPrefix(elementMap.get("prefix"));
                node.setSuffix(elementMap.get("suffix"));
                node.setScale(Byte.parseByte(elementMap.get("scale")));
                node.setQuoteSource(QuoteSource.YAHOO);

                if (elementMap.get("reportedCurrency") != null) {
                  SecurityThread thread =
                      new SecurityThread(node, elementMap.get("reportedCurrency"));
                  workQueue.add(thread);
                }

                engine.addSecurity(node);
              }

              if (history != null) {
                SecurityNode node = engine.getSecurity(elementMap.get("symbol"));
                if (node != null) {
                  for (SecurityHistoryNode hNode : history) {
                    if (!engine.addSecurityHistory(node, hNode)) {
                      logger.warning("Failed to add security history");
                    }
                  }
                }
              }
              return;
            }
            break;

          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, "Exception at element: {0}", reader.getName().toString());
      logger.log(Level.SEVERE, e.toString(), e);
    }
  }