Exemplo n.º 1
0
  @Override
  public TransactionEntry buildTransactionEntry() {
    TransactionEntry entry = new TransactionEntry();

    entry.setMemo(memoField.getText());

    entry.setDebitAccount(getAccount());
    entry.setCreditAccount(accountPanel.getSelectedAccount());

    entry.setDebitAmount(amountField.getDecimal().abs().negate());

    if (hasEqualCurrencies()) {
      entry.setCreditAmount(amountField.getDecimal().abs());
    } else {
      entry.setCreditAmount(accountPanel.getExchangedAmount().abs());
    }

    entry.setTransactionTag(TransactionTag.INVESTMENT_FEE);

    if (reconciledButton.isSelected()) {
      entry.setReconciled(account, ReconciledState.RECONCILED);
    } else {
      entry.setReconciled(account, ReconciledState.NOT_RECONCILED);
    }

    return entry;
  }
Exemplo n.º 2
0
  @FXML
  private void convertAction() {
    final Optional<Account> accountOptional =
        StaticAccountsMethods.selectAccount(null, accountProperty.get());
    if (accountOptional.isPresent()) {
      final Account opp = accountOptional.get();

      final Transaction t = new Transaction();

      t.setDate(datePicker.getValue());
      t.setNumber(numberComboBox.getValue());
      t.setPayee(payeeTextField.getText());

      final TransactionEntry entry = new TransactionEntry();
      entry.setMemo(memoTextField.getText());

      if (amountField.getDecimal().signum() >= 0) {
        entry.setCreditAccount(accountProperty.get());
        entry.setDebitAccount(opp);
      } else {
        entry.setDebitAccount(accountProperty.get());
        entry.setCreditAccount(opp);
      }

      entry.setCreditAmount(amountField.getDecimal().abs());
      entry.setDebitAmount(amountField.getDecimal().abs().negate());

      t.addTransactionEntry(entry);

      ReconcileManager.reconcileTransaction(accountProperty.get(), t, getReconciledState());

      TransactionDialog.showAndWait(
          accountProperty.get(),
          t,
          optional -> {
            if (optional.isPresent()) {
              final Transaction tran = optional.get();
              final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
              Objects.requireNonNull(engine);

              if (engine.removeTransaction(modTrans)) {
                engine.addTransaction(tran);
              }
              clearForm();
            }
          });
    }
  }
Exemplo n.º 3
0
  private Transaction generateTransaction(
      final String transactionClass, final Map<String, String> elementMap) {
    // logger.finest("Being generateTransaction");
    switch (transactionClass) {
      case "SplitTransaction":
        logger.finest("Found SplitTransaction");
        splitList.add(elementMap);
        return null;
      case "SplitEntryTransaction":
        logger.finest("Found SplitEntryTransaction");
        splitEntryList.add(elementMap);
        return null;
    }

    // logger.finest("Building base transation");

    Transaction transaction = null;

    Date actDate = decodeDate(elementMap.get("actTransDate"));
    Date date = decodeDate(elementMap.get("voucherDate"));
    String memo = elementMap.get("memo");
    String payee = elementMap.get("payee");
    String number = elementMap.get("number");
    CurrencyNode node = decodeCurrency(elementMap.get("commodity"));

    // logger.finest(transactionClass);

    if (transactionClass.equals("AddXTransaction")
        || transactionClass.equals("RemoveXTransaction")) {
      BigDecimal price = new BigDecimal(elementMap.get("price"));
      BigDecimal quantity = new BigDecimal(elementMap.get("quantity"));
      Account investmentAccount = accountMap.get(elementMap.get("investmentAccount"));
      boolean reconciled = Boolean.parseBoolean(elementMap.get("reconciled"));
      SecurityNode sNode =
          EngineFactory.getEngine(EngineFactory.DEFAULT).getSecurity(elementMap.get("security"));

      transaction = new InvestmentTransaction();

      AbstractInvestmentTransactionEntry entry;

      if (transactionClass.equals("AddXTransaction")) {
        entry = new TransactionEntryAddX(investmentAccount, sNode, price, quantity);
      } else {
        entry = new TransactionEntryRemoveX(investmentAccount, sNode, price, quantity);
      }

      entry.setMemo(memo);

      transaction.setDate(date);
      transaction.setDateEntered(actDate);
      transaction.setPayee(payee);
      transaction.addTransactionEntry(entry);

      transaction.setReconciled(
          investmentAccount,
          reconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
    }

    if (transactionClass.equals("SplitXTransaction")
        || transactionClass.equals("MergeXTransaction")) {
      BigDecimal price = new BigDecimal(elementMap.get("price"));
      BigDecimal quantity = new BigDecimal(elementMap.get("quantity"));
      Account investmentAccount = accountMap.get(elementMap.get("investmentAccount"));
      boolean reconciled = Boolean.parseBoolean(elementMap.get("reconciled"));
      SecurityNode sNode =
          EngineFactory.getEngine(EngineFactory.DEFAULT).getSecurity(elementMap.get("security"));

      transaction = new InvestmentTransaction();

      AbstractInvestmentTransactionEntry entry;

      if (transactionClass.equals("SplitXTransaction")) {
        entry = new TransactionEntrySplitX(investmentAccount, sNode, price, quantity);
      } else {
        entry = new TransactionEntryMergeX(investmentAccount, sNode, price, quantity);
      }

      entry.setMemo(memo);

      transaction.setDate(date);
      transaction.setDateEntered(actDate);
      transaction.setPayee(payee);
      transaction.addTransactionEntry(entry);

      transaction.setReconciled(
          investmentAccount,
          reconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
    }

    if (transactionClass.equals("BuyXTransaction") || transactionClass.equals("SellXTransaction")) {
      BigDecimal fees = new BigDecimal(elementMap.get("fees"));
      BigDecimal price = new BigDecimal(elementMap.get("price"));
      BigDecimal quantity = new BigDecimal(elementMap.get("quantity"));
      Account investmentAccount = accountMap.get(elementMap.get("investmentAccount"));
      Account account = accountMap.get(elementMap.get("account"));
      boolean accountReconciled = Boolean.parseBoolean(elementMap.get("accountReconciled"));
      boolean investmentAccountReconciled =
          Boolean.parseBoolean(elementMap.get("investmentAccountReconciled"));
      SecurityNode sNode =
          EngineFactory.getEngine(EngineFactory.DEFAULT).getSecurity(elementMap.get("security"));

      BigDecimal exchangeRate = BigDecimal.ONE;

      if (sNode != null) {

        if (transactionClass.equals("BuyXTransaction")) {
          transaction =
              TransactionFactory.import1xBuyXTransaction(
                  account,
                  investmentAccount,
                  sNode,
                  price,
                  quantity,
                  exchangeRate,
                  fees,
                  date,
                  memo);
        } else {
          transaction =
              TransactionFactory.import1xSellXTransaction(
                  account,
                  investmentAccount,
                  sNode,
                  price,
                  quantity,
                  exchangeRate,
                  fees,
                  date,
                  memo);
        }

        transaction.setDateEntered(actDate);
        transaction.setPayee(payee);

        transaction.setReconciled(
            investmentAccount,
            investmentAccountReconciled
                ? ReconciledState.RECONCILED
                : ReconciledState.NOT_RECONCILED);
        transaction.setReconciled(
            account,
            accountReconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
      }
    }

    if (transactionClass.equals("DividendTransaction")) {

      BigDecimal amount = new BigDecimal(elementMap.get("amount"));
      Account investmentAccount = accountMap.get(elementMap.get("investmentAccount"));
      Account account = accountMap.get(elementMap.get("account"));
      boolean accountReconciled = Boolean.parseBoolean(elementMap.get("accountReconciled"));
      boolean investmentAccountReconciled =
          Boolean.parseBoolean(elementMap.get("investmentAccountReconciled"));
      SecurityNode sNode =
          EngineFactory.getEngine(EngineFactory.DEFAULT).getSecurity(elementMap.get("security"));

      transaction =
          TransactionFactory.generateDividendXTransaction(
              investmentAccount,
              investmentAccount,
              account,
              sNode,
              amount,
              amount.negate(),
              amount,
              date,
              memo,
              accountReconciled);

      ReconcileManager.reconcileTransaction(
          investmentAccount,
          transaction,
          investmentAccountReconciled
              ? ReconciledState.RECONCILED
              : ReconciledState.NOT_RECONCILED);

      ReconcileManager.reconcileTransaction(
          account,
          transaction,
          accountReconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
    }

    if (transactionClass.equals("ReinvestDivTransaction")) {
      BigDecimal fees = new BigDecimal(elementMap.get("fees"));
      BigDecimal price = new BigDecimal(elementMap.get("price"));
      BigDecimal quantity = new BigDecimal(elementMap.get("quantity"));
      SecurityNode sNode =
          EngineFactory.getEngine(EngineFactory.DEFAULT).getSecurity(elementMap.get("security"));
      Account investmentAccount = accountMap.get(elementMap.get("investmentAccount"));
      boolean reconciled = Boolean.parseBoolean(elementMap.get("reconciled"));

      transaction = new InvestmentTransaction();

      AbstractInvestmentTransactionEntry entry =
          new TransactionEntryReinvestDivX(investmentAccount, sNode, price, quantity);

      entry.setMemo(memo);

      transaction.setDate(date);
      transaction.setDateEntered(actDate);
      transaction.setPayee(payee);

      transaction.addTransactionEntry(entry);

      if (fees.compareTo(BigDecimal.ZERO) > 0) {
        TransactionEntry fTran = new TransactionEntry(investmentAccount, fees.negate());
        fTran.setMemo(memo);
        fTran.setTransactionTag(TransactionTag.INVESTMENT_FEE);

        transaction.addTransactionEntry(fTran);
      }

      transaction.setReconciled(
          investmentAccount,
          reconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
    }
    switch (transactionClass) {
      case "SingleEntryTransaction":
        {
          BigDecimal amount = new BigDecimal(elementMap.get("amount"));
          Account account = accountMap.get(elementMap.get("account"));
          boolean reconciled = Boolean.parseBoolean(elementMap.get("reconciled"));
          transaction =
              TransactionFactory.generateSingleEntryTransaction(
                  account, amount, date, reconciled, memo, payee, number);
          transaction.setDateEntered(actDate);
          break;
        }
      case "DoubleEntryTransaction":
        {
          Account creditAccount = accountMap.get(elementMap.get("creditAccount"));
          Account debitAccount = accountMap.get(elementMap.get("debitAccount"));
          BigDecimal amount = new BigDecimal(elementMap.get("amount"));
          boolean creditReconciled = Boolean.parseBoolean(elementMap.get("creditReconciled"));
          boolean debitReconciled = Boolean.parseBoolean(elementMap.get("debitReconciled"));
          transaction = new Transaction();
          transaction.setDate(date);
          transaction.setDateEntered(actDate);
          transaction.setNumber(number);
          transaction.setPayee(payee);
          TransactionEntry entry = new TransactionEntry();
          entry.setMemo(memo);
          entry.setCreditAccount(creditAccount);
          entry.setDebitAccount(debitAccount);
          if (creditAccount.getCurrencyNode().equals(node)) {
            entry.setCreditAmount(amount);
          } else {
            BigDecimal exchangeRate = new BigDecimal(elementMap.get("exchangeRate"));
            entry.setCreditAmount(amount.multiply(exchangeRate));
          }
          if (debitAccount.getCurrencyNode().equals(node)) {
            entry.setDebitAmount(amount.negate());
          } else {
            BigDecimal exchangeRate = new BigDecimal(elementMap.get("exchangeRate"));
            entry.setDebitAmount(amount.multiply(exchangeRate).negate());
          }
          transaction.addTransactionEntry(entry);
          transaction.setReconciled(
              creditAccount,
              creditReconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
          transaction.setReconciled(
              debitAccount,
              debitReconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);
          break;
        }
    }
    return transaction;
  }
Exemplo n.º 4
0
  void importTransactions(final XMLStreamReader reader) {

    logger.info("Begin transaction import");

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

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

    logger.log(Level.INFO, "Generating {0} Split Transactions", splitList.size());

    /* loop through the lists and add split transactions */
    for (Iterator<Map<String, String>> i = splitList.iterator(); i.hasNext(); ) {

      Map<String, String> map = i.next();

      String id = map.get(ID);

      Transaction transaction = new Transaction();

      transaction.setDate(decodeDate(map.get("voucherDate")));
      transaction.setDateEntered(decodeDate(map.get("actTransDate")));
      transaction.setNumber(map.get("number"));
      transaction.setPayee(map.get("payee"));
      transaction.setMemo(map.get("memo"));

      for (Iterator<Map<String, String>> j = this.splitEntryList.iterator(); j.hasNext(); ) {
        Map<String, String> entryMap = j.next();

        if (entryMap.get("parent").equals(id)) {

          TransactionEntry entry = new TransactionEntry();

          entry.setMemo(entryMap.get("memo"));

          Account creditAccount = accountMap.get(entryMap.get("creditAccount"));
          Account debitAccount = accountMap.get(entryMap.get("debitAccount"));

          boolean creditReconciled = Boolean.parseBoolean(entryMap.get("creditReconciled"));
          boolean debitReconciled = Boolean.parseBoolean(entryMap.get("debitReconciled"));

          entry.setCreditAccount(creditAccount);
          entry.setDebitAccount(debitAccount);

          CurrencyNode node = decodeCurrency(entryMap.get("commodity"));
          BigDecimal amount = new BigDecimal(entryMap.get("amount"));

          if (creditAccount.getCurrencyNode().equals(node)) {
            entry.setCreditAmount(amount);
          } else {
            BigDecimal exchangeRate = new BigDecimal(entryMap.get("exchangeRate"));
            entry.setCreditAmount(amount.multiply(exchangeRate));
          }

          if (debitAccount.getCurrencyNode().equals(node)) {
            entry.setDebitAmount(amount.negate());
          } else {
            BigDecimal exchangeRate = new BigDecimal(entryMap.get("exchangeRate"));
            entry.setDebitAmount(amount.multiply(exchangeRate).negate());
          }

          transaction.addTransactionEntry(entry);

          transaction.setReconciled(
              creditAccount,
              creditReconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);

          transaction.setReconciled(
              debitAccount,
              debitReconciled ? ReconciledState.RECONCILED : ReconciledState.NOT_RECONCILED);

          j.remove();
        }
      }

      assert transaction.size() > 0;

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

      if (!engine.addTransaction(transaction)) {
        logger.log(Level.SEVERE, "Failed to import transaction: {0}", id);
      }

      i.remove();
    }

    logger.info("Transaction import complete");
  }