private void OutputOneTransaction(BankTrx trx, string exportAccountName, PayeeDef payee, string intuitTrxType, bool usePayeeOnTrx) { OutputNormalTrx(trx, intuitTrxType, exportAccountName, usePayeeOnTrx ? payee.ExportName : "", trx.Amount); foreach (TrxSplit split in trx.Splits) { OutputSplit(split, intuitTrxType, ""); } OutputLine("ENDTRNS"); }
private void OutputNormalTrx(BankTrx trx) { PayeeDef payee = Payees[TrimPayeeName(trx.Description).ToLower()]; TrxOutputType usage = GetPayeeUsage(trx); string exportAccountName = Categories[GetBalanceSheetExportKey(trx.Register.Account.AccountKey.ToString())].ExportName; switch (usage) { case TrxOutputType.Check: if (ContainsPayablesSplit(trx.Splits)) { OutputTransactionPerSplit(trx, exportAccountName, payee, "CHECK", usePayeeOnSplit: SplitIsToAccountsPayable); } else { OutputOneTransaction(trx, exportAccountName, payee, "CHECK", usePayeeOnTrx: true); } break; case TrxOutputType.Deposit: OutputOneTransaction(trx, exportAccountName, payee, "DEPOSIT", usePayeeOnTrx: false); break; case TrxOutputType.JournalEntry: if (ContainsPayablesSplit(trx.Splits)) { OutputTransactionPerSplit(trx, exportAccountName, payee, "GENERAL JOURNAL", usePayeeOnSplit: SplitIsToAccountsPayable); } else { OutputOneTransaction(trx, exportAccountName, payee, "GENERAL JOURNAL", usePayeeOnTrx: true); } break; case TrxOutputType.Bill: OutputOneTransaction(trx, exportAccountName, payee, "BILL", usePayeeOnTrx: true); break; case TrxOutputType.BillCredit: OutputOneTransaction(trx, exportAccountName, payee, "BILL REFUND", usePayeeOnTrx: true); break; } }
private void OutputTransactionPerSplit(BankTrx trx, string exportAccountName, PayeeDef payee, string intuitTrxType, Func <TrxSplit, bool> usePayeeOnSplit) { foreach (TrxSplit split in trx.Splits) { // Notice we pass the split amount instead of the trx amount, because every split // of this transaction type must be a separate transaction in an IIF file. OutputNormalTrx(trx, intuitTrxType, exportAccountName, payee.ExportName, split.Amount); OutputSplit(split, intuitTrxType, usePayeeOnSplit(split) ? payee.ExportName : ""); OutputLine("ENDTRNS"); } }
/// <summary> /// Determine all names associated with the transaction, and add any /// new ones to the list that must be defined in the IIF file. /// Does not actually output anything to the IIF file here. /// </summary> /// <param name="trx"></param> private void AnalyzeNormalTrx(BankTrx trx) { PayeeDef payee; string trimmedPayee = TrimPayeeName(trx.Description); string normalizedPayee = trimmedPayee.ToLower(); if (!Payees.TryGetValue(normalizedPayee, out payee)) { payee = new PayeeDef(trimmedPayee, MakeUniquePayeeExportName(trimmedPayee)); Payees.Add(normalizedPayee, payee); } if (trx.TrxDate >= StartDate) { switch (GetPayeeUsage(trx)) { case TrxOutputType.JournalEntry: payee.UsedForGeneralJournal = true; break; case TrxOutputType.Check: payee.UsedForCheck = true; break; } } foreach (TrxSplit split in trx.Splits) { CatDef cat; // Create CatDef objects for balance sheet accounts as well as income/expense accounts. string catExportKey = GetCatExportKey(split.CategoryKey); if (!Categories.TryGetValue(catExportKey, out cat)) { string catName = CatTrans.KeyToValue1(split.CategoryKey); // Categories includes balance sheet accounts StringTransElement catElem = this.Company.Categories.get_GetElement(this.Company.Categories.FindIndexOfKey(split.CategoryKey)); // A null intuitCatType value will cause this category to NOT be output to the IIF file. // This is how we prevent categories that are actually asset, liability and equity accounts // from being output to the IIF as income, expense or COGS account. string intuitCatType; if (split.CategoryKey.IndexOf('.') >= 0) { intuitCatType = null; } else { string catType; intuitCatType = null; if (!catElem.ExtraValues.TryGetValue(CategoryTranslator.TypeKey, out catType)) { catType = CategoryTranslator.TypeOfficeExpense; } if (catType == CategoryTranslator.TypeCOGS) { intuitCatType = "COGS"; } else if (catType == CategoryTranslator.TypeOtherIncome) { intuitCatType = "EXINC"; } else if (catType == CategoryTranslator.TypeOtherExpense) { intuitCatType = "EXEXP"; } else if (catType == CategoryTranslator.TypeTaxes) { intuitCatType = "EXEXP"; } else if (catName.ToUpper().StartsWith("E:")) { intuitCatType = "EXP"; } else if (catName.ToUpper().StartsWith("I:")) { intuitCatType = "INC"; } } cat = new CatDef(catName, MakeCatExportName(split, catName), intuitCatType); Categories.Add(catExportKey, cat); } } }