示例#1
0
  /**
   * Builds a QIF entry representing this transaction
   *
   * @return String QIF representation of this transaction
   */
  public String toQIF() {
    final String newLine = "\n";

    AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(GnuCashApplication.getAppContext());

    // all transactions are double transactions
    String splitAccountFullName = QifHelper.getImbalanceAccountName(mAmount.getCurrency());
    if (mDoubleEntryAccountUID != null && mDoubleEntryAccountUID.length() > 0) {
      splitAccountFullName = accountsDbAdapter.getFullyQualifiedAccountName(mDoubleEntryAccountUID);
    }

    StringBuffer transactionQifBuffer = new StringBuffer();
    transactionQifBuffer
        .append(QifHelper.DATE_PREFIX)
        .append(QifHelper.formatDate(mTimestamp))
        .append(newLine);
    transactionQifBuffer.append(QifHelper.MEMO_PREFIX).append(mName).append(newLine);

    transactionQifBuffer
        .append(QifHelper.SPLIT_CATEGORY_PREFIX)
        .append(splitAccountFullName)
        .append(newLine);
    if (mDescription != null && mDescription.length() > 0) {
      transactionQifBuffer.append(QifHelper.SPLIT_MEMO_PREFIX).append(mDescription).append(newLine);
    }
    transactionQifBuffer
        .append(QifHelper.SPLIT_AMOUNT_PREFIX)
        .append(mAmount.asString())
        .append(newLine);
    transactionQifBuffer.append(QifHelper.ENTRY_TERMINATOR).append(newLine);

    accountsDbAdapter.close();
    return transactionQifBuffer.toString();
  }