public TransactionStat GetTransactionStats() { // TODO test this var transactions = this.GetWithEntities(); var transactionStat = new TransactionStat(); transactionStat.Transactions = transactions; DateTime?currentDate = null; foreach (var transaction in transactions) { if (!currentDate.HasValue || currentDate.Value.Month != transaction.AccountingDate.Month) // new date { currentDate = transaction.AccountingDate; transactionStat.MonthStats.Add(new MonthStat() { Date = new DateTime(currentDate.Value.Year, currentDate.Value.Month, 1), Expense = (transaction.Sum < 0 ? transaction.Sum.Value : 0), Income = (transaction.Sum > 0 ? transaction.Sum.Value : 0), Transactions = new List <Transaction>() { transaction }, TransactionLiterals = new List <string>() { this.GetTransactionLiteral(transaction) }, }); } else // not new date { var lastStat = transactionStat.MonthStats.Last(); if (transaction.Sum < 0) { lastStat.Expense += transaction.Sum; } else if (transaction.Sum > 0) { lastStat.Income += transaction.Sum; } lastStat.Transactions.Add(transaction); lastStat.TransactionLiterals.Add(this.GetTransactionLiteral(transaction)); } } return(transactionStat); }
/// <summary> /// Update /// </summary> /// <param name="stat">Stat</param> /// <param name="transactions">Transactions</param> public static void Update(this TransactionStat stat, Transaction[] transactions) { stat.LowPriorty = 0; // Neo3 haven't got free tx stat.HighPriorty = transactions.Length - stat.LowPriorty; }