/**
   * Modify a transaction before it is used to complete the panel for auto fill. The supplied
   * transaction must be a new or cloned transaction. It can't be a transaction that lives in the
   * map. The returned transaction can be the supplied reference or may be a new instance
   *
   * @param t The transaction to modify
   * @return the modified transaction
   */
  private Transaction modifyTransactionForAutoComplete(final Transaction t) {

    // tweak the transaction
    t.setNumber(null);
    t.setReconciled(ReconciledState.NOT_RECONCILED); // clear both sides

    // set the last date as required
    if (!Options.rememberLastDateProperty().get()) {
      t.setDate(LocalDate.now());
    } else {
      t.setDate(datePicker.getValue());
    }

    // preserve any transaction entries that may have been entered first
    if (amountField.getLength() > 0) {
      Transaction newTrans = buildTransaction();
      t.clearTransactionEntries();
      t.addTransactionEntries(newTrans.getTransactionEntries());
    }

    // preserve any preexisting memo field info
    if (memoTextField.getLength() > 0) {
      t.setMemo(memoTextField.getText());
    }

    // Do not copy over attachments
    t.setAttachment(null);

    return t;
  }
Beispiel #2
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");
  }