示例#1
0
  /**
   * Converts transaction to XML DOM corresponding to OFX Statement transaction and returns the
   * element node for the transaction. The Unique ID of the account is needed in order to properly
   * export double entry transactions
   *
   * @param doc XML document to which transaction should be added
   * @param accountUID Unique Identifier of the account which called the method.
   * @return Element in DOM corresponding to transaction
   */
  public Element toOfx(Document doc, String accountUID) {
    Element transactionNode = doc.createElement("STMTTRN");
    Element type = doc.createElement("TRNTYPE");
    type.appendChild(doc.createTextNode(mType.toString()));
    transactionNode.appendChild(type);

    Element datePosted = doc.createElement("DTPOSTED");
    datePosted.appendChild(doc.createTextNode(OfxExporter.getOfxFormattedTime(mTimestamp)));
    transactionNode.appendChild(datePosted);

    Element dateUser = doc.createElement("DTUSER");
    dateUser.appendChild(doc.createTextNode(OfxExporter.getOfxFormattedTime(mTimestamp)));
    transactionNode.appendChild(dateUser);

    Element amount = doc.createElement("TRNAMT");
    amount.appendChild(doc.createTextNode(mAmount.toPlainString()));
    transactionNode.appendChild(amount);

    Element transID = doc.createElement("FITID");
    transID.appendChild(doc.createTextNode(mTransactionUID));
    transactionNode.appendChild(transID);

    Element name = doc.createElement("NAME");
    name.appendChild(doc.createTextNode(mName));
    transactionNode.appendChild(name);

    if (mDescription != null && mDescription.length() > 0) {
      Element memo = doc.createElement("MEMO");
      memo.appendChild(doc.createTextNode(mDescription));
      transactionNode.appendChild(memo);
    }

    if (mDoubleEntryAccountUID != null && mDoubleEntryAccountUID.length() > 0) {
      Element bankId = doc.createElement("BANKID");
      bankId.appendChild(doc.createTextNode(OfxExporter.APP_ID));

      // select the proper account as the double account
      String doubleAccountUID =
          mDoubleEntryAccountUID.equals(accountUID) ? mAccountUID : mDoubleEntryAccountUID;

      Element acctId = doc.createElement("ACCTID");
      acctId.appendChild(doc.createTextNode(doubleAccountUID));

      Element accttype = doc.createElement("ACCTTYPE");
      AccountsDbAdapter acctDbAdapter = new AccountsDbAdapter(GnuCashApplication.getAppContext());
      OfxAccountType ofxAccountType =
          Account.convertToOfxAccountType(acctDbAdapter.getAccountType(doubleAccountUID));
      accttype.appendChild(doc.createTextNode(ofxAccountType.toString()));
      acctDbAdapter.close();

      Element bankAccountTo = doc.createElement("BANKACCTTO");
      bankAccountTo.appendChild(bankId);
      bankAccountTo.appendChild(acctId);
      bankAccountTo.appendChild(accttype);

      transactionNode.appendChild(bankAccountTo);
    }

    return transactionNode;
  }
示例#2
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    assert actionBar != null;
    actionBar.setTitle(R.string.title_split_editor);
    setHasOptionsMenu(true);

    mCalculatorKeyboard =
        new CalculatorKeyboard(getActivity(), mKeyboardView, R.xml.calculator_keyboard);
    mSplitItemViewList = new ArrayList<>();

    // we are editing splits for a new transaction.
    // But the user may have already created some splits before. Let's check
    List<String> splitStrings = getArguments().getStringArrayList(UxArgument.SPLIT_LIST);
    List<Split> splitList = new ArrayList<>();
    if (splitStrings != null) {
      for (String splitString : splitStrings) {
        splitList.add(Split.parseSplit(splitString));
      }
    }

    initArgs();
    if (!splitList.isEmpty()) {
      // aha! there are some splits. Let's load those instead
      loadSplitViews(splitList);
      mImbalanceWatcher.afterTextChanged(null);
    } else {
      final String currencyCode = mAccountsDbAdapter.getAccountCurrencyCode(mAccountUID);
      Split split =
          new Split(new Money(mBaseAmount.abs(), Commodity.getInstance(currencyCode)), mAccountUID);
      AccountType accountType = mAccountsDbAdapter.getAccountType(mAccountUID);
      TransactionType transactionType =
          Transaction.getTypeForBalance(accountType, mBaseAmount.signum() < 0);
      split.setType(transactionType);
      View view = addSplitView(split);
      view.findViewById(R.id.input_accounts_spinner).setEnabled(false);
      view.findViewById(R.id.btn_remove_split).setVisibility(View.GONE);
      TransactionsActivity.displayBalance(
          mImbalanceTextView, new Money(mBaseAmount.negate(), mCommodity));
    }
  }