/// <summary> /// Load the given file into a <see cref="StatementModel" />. /// </summary> /// <param name="fileName">The file to load.</param> /// <param name="accountType"> /// The account type to classify these transactions. This is useful when merging one statement to another. For example, /// merging a cheque account /// export with visa account export, each can be classified using an account type. /// </param> public StatementModel Load(string fileName, AccountType accountType) { this.importUtilities.AbortIfFileDoesntExist(fileName, this.userMessageBox); var transactions = new List<Transaction>(); foreach (string line in ReadLines(fileName)) { if (string.IsNullOrWhiteSpace(line)) { continue; } string[] split = line.Split(','); decimal amount; NamedTransaction transactionType = FetchTransactionType(split, 1, 2, out amount); var transaction = new Transaction { AccountType = accountType, Reference1 = this.importUtilities.SafeArrayFetchString(split, 0), TransactionType = transactionType, Amount = amount, Description = this.importUtilities.SafeArrayFetchString(split, 3), Date = this.importUtilities.SafeArrayFetchDate(split, 4), }; transactions.Add(transaction); } return new StatementModel(this.logger) { FileName = fileName, LastImport = DateTime.Now, }.LoadTransactions(transactions); }
public void ShowDialog(Transaction transaction, Guid correlationId) { Transaction = transaction; MessengerInstance.Send( new ShellDialogRequestMessage( BudgetAnalyserFeature.Transactions, this, ShellDialogType.Ok) { CorrelationId = correlationId, Title = "Edit Transaction", }); }
public void ShowDialog(Transaction transaction, Guid correlationId) { Transaction = transaction; this.originalBucket = Transaction.BudgetBucket; Buckets = this.bucketRepo.Buckets.Where(b => b.Active); MessengerInstance.Send( new ShellDialogRequestMessage( BudgetAnalyserFeature.Transactions, this, ShellDialogType.SaveCancel) { CorrelationId = correlationId, Title = "Edit Transaction" }); }
public void SplitTransaction_ShouldCallStatementModel_GivenValidParams() { this.testData = new StatementModelTestHarness(); this.testData.LoadTransactions(new List<Transaction>()); var transaction = new Transaction { Account = StatementModelTestData.VisaAccount }; Arrange(); this.subject.SplitTransaction(transaction, 100, 200, StatementModelTestData.CarMtcBucket, StatementModelTestData.HairBucket); Assert.AreEqual(1, ((StatementModelTestHarness)this.testData).SplitTransactionWasCalled); }
public void ShowDialog(Transaction originalTransaction, Guid correlationId) { BudgetBuckets = this.bucketRepo.Buckets; this.dialogCorrelationId = correlationId; OriginalTransaction = originalTransaction; SplinterAmount1 = OriginalTransaction.Amount; SplinterAmount2 = 0M; SplinterBucket2 = SplinterBucket1 = OriginalTransaction.BudgetBucket; var dialogRequest = new ShellDialogRequestMessage(BudgetAnalyserFeature.Transactions, this, ShellDialogType.SaveCancel) { CorrelationId = correlationId, Title = "Split Transaction" }; MessengerInstance.Send(dialogRequest); }
private static bool MatchTransactionText(string textFilter, Transaction t) { if (!string.IsNullOrWhiteSpace(t.Description)) { if (t.Description.IndexOf(textFilter, StringComparison.CurrentCultureIgnoreCase) >= 0) { return true; } } if (!string.IsNullOrWhiteSpace(t.Reference1)) { if (t.Reference1.IndexOf(textFilter, StringComparison.CurrentCultureIgnoreCase) >= 0) { return true; } } if (!string.IsNullOrWhiteSpace(t.Reference2)) { if (t.Reference2.IndexOf(textFilter, StringComparison.CurrentCultureIgnoreCase) >= 0) { return true; } } if (!string.IsNullOrWhiteSpace(t.Reference3)) { if (t.Reference3.IndexOf(textFilter, StringComparison.CurrentCultureIgnoreCase) >= 0) { return true; } } return false; }
private static string ExtractNarrative(Transaction t) { if (!string.IsNullOrWhiteSpace(t.Description)) { return t.Description; } if (t.TransactionType != null) { return t.TransactionType.ToString(); } return string.Empty; }
public static bool IsAutoMatchingTransaction(Transaction statementTransaction, IEnumerable<LedgerTransaction> ledgerTransactions) { return ledgerTransactions.Any( l => l.AutoMatchingReference == statementTransaction.Reference1 || l.AutoMatchingReference == $"{MatchedPrefix}{statementTransaction.Reference1}"); }
internal override void SplitTransaction(Transaction originalTransaction, decimal splinterAmount1, decimal splinterAmount2, BudgetBucket splinterBucket1, BudgetBucket splinterBucket2) { SplitTransactionWasCalled++; }
internal override void RemoveTransaction(Transaction transaction) { RemoveTransactionWasCalled++; }
/// <summary> /// Splits the provided transaction into two. The provided transactions is removed, and two new transactions are /// created. Both transactions must add up to the existing transaction amount. /// </summary> /// <exception cref="System.ArgumentNullException"> /// </exception> public void SplitTransaction(Transaction originalTransaction, decimal splinterAmount1, decimal splinterAmount2, BudgetBucket splinterBucket1, BudgetBucket splinterBucket2) { if (originalTransaction == null) { throw new ArgumentNullException(nameof(originalTransaction)); } if (splinterBucket1 == null) { throw new ArgumentNullException(nameof(splinterBucket1)); } if (splinterBucket2 == null) { throw new ArgumentNullException(nameof(splinterBucket2)); } StatementModel.SplitTransaction( originalTransaction, splinterAmount1, splinterAmount2, splinterBucket1, splinterBucket2); }
/// <summary> /// Removes the provided transaction from the currently loaded Budget Analyser Statement. /// </summary> /// <param name="transactionToRemove">The transaction to remove.</param> /// <exception cref="System.ArgumentNullException"></exception> public void RemoveTransaction(Transaction transactionToRemove) { if (transactionToRemove == null) { throw new ArgumentNullException(nameof(transactionToRemove)); } StatementModel.RemoveTransaction(transactionToRemove); }
public StatementModelBuilder AppendTransaction(Transaction transaction) { this.additionalTransactions.Add(transaction); return this; }
/// <summary> /// Load the given file into a <see cref="StatementModel" />. /// </summary> /// <param name="fileName">The file to load.</param> /// <param name="account"> /// The account to classify these transactions. This is useful when merging one statement to another. For example, /// merging a cheque account export with visa account export, each can be classified using an account. /// </param> public async Task<StatementModel> LoadAsync(string fileName, Account account) { try { this.importUtilities.AbortIfFileDoesntExist(fileName); } catch (FileNotFoundException ex) { throw new KeyNotFoundException(ex.Message, ex); } var transactions = new List<Transaction>(); var firstTime = true; foreach (var line in await ReadLinesAsync(fileName)) { if (firstTime) { // File contains column headers firstTime = false; continue; } if (string.IsNullOrWhiteSpace(line)) { continue; } string[] split = line.Split(','); var transaction = new Transaction { Account = account, Description = this.importUtilities.FetchString(split, DescriptionIndex), Reference1 = this.importUtilities.FetchString(split, Reference1Index), Reference2 = this.importUtilities.FetchString(split, Reference2Index), Reference3 = this.importUtilities.FetchString(split, Reference3Index), Amount = this.importUtilities.FetchDecimal(split, AmountIndex), Date = this.importUtilities.FetchDate(split, DateIndex) }; transaction.TransactionType = FetchTransactionType(split, transaction.Amount); transactions.Add(transaction); } var statement = new StatementModel(this.logger) { StorageKey = fileName, LastImport = DateTime.Now }.LoadTransactions(transactions); return statement; }