/** * 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; }