public static void CopyInto(this TranWithTags tran, TranWithTags destinationTran) { destinationTran.Timestamp = tran.Timestamp; destinationTran.Operation = tran.Operation; destinationTran.MyAccount = tran.MyAccount; destinationTran.MySecondAccount = tran.MySecondAccount; destinationTran.Amount = tran.Amount; destinationTran.Currency = tran.Currency; destinationTran.AmountInReturn = tran.AmountInReturn; destinationTran.CurrencyInReturn = tran.CurrencyInReturn; destinationTran.Tags?.Clear(); if (tran.Tags != null) { if (destinationTran.Tags == null) { destinationTran.Tags = new List <Account>(); } foreach (var tag in tran.Tags) { destinationTran.Tags.Add(tag); } } destinationTran.Comment = tran.Comment; }
public static decimal AmountForAccount(this TranWithTags tran, Account account, CurrencyCodes?currency) { switch (tran.Operation) { case OperationType.Доход: return(tran.MyAccount.Is(account) && tran.Currency == currency ? tran.Amount : 0); case OperationType.асход: return(tran.MyAccount.Is(account) && tran.Currency == currency ? -tran.Amount : 0); case OperationType.Перенос: if (tran.MyAccount.Is(account) && tran.Currency == currency) { return(-tran.Amount); } return(tran.MySecondAccount.Is(account) && tran.Currency == currency ? tran.Amount : 0); case OperationType.Обмен: if (tran.MyAccount.Is(account) && tran.Currency == currency) { return(-tran.Amount); } if (tran.MySecondAccount.Is(account) && tran.CurrencyInReturn == currency) { return(tran.AmountInReturn); } return(0); default: return(0); } }
public static TranWithTags Clone(this TranWithTags tran) { var result = new TranWithTags { Timestamp = tran.Timestamp, Operation = tran.Operation, MyAccount = tran.MyAccount, MySecondAccount = tran.MySecondAccount, Amount = tran.Amount, Currency = tran.Currency, AmountInReturn = tran.AmountInReturn, CurrencyInReturn = tran.CurrencyInReturn }; if (tran.Tags != null) { result.Tags = new List <Account>(); foreach (var tag in tran.Tags) { result.Tags.Add(tag); } } result.Comment = tran.Comment; return(result); }
// возвращает базовую категорию public static Account GetTranCategory(this TranWithTags tran, bool flag) { var rootName = flag ? "Все доходы" : "Все расходы"; var result = tran.Tags.FirstOrDefault(t => t.Is(rootName)); if (result != null) { return(UpToCategory(result, rootName)); } MessageBox.Show($"не задана категория {tran.Timestamp} {tran.Amount} {tran.Currency}", ""); return(null); }
public static bool CollectionContainsTag(this TranWithTags tran, Account tag) { if (tran.Tags.Contains(tag)) { return(true); } foreach (var child in tag.Children) { if (tran.Tags.Contains(child)) { return(true); } } return(false); }
// возвращает подробную категорию public static Account GetTranArticle(this TranWithTags tran, bool isIncome, bool batchProcessing = true) { var rootName = isIncome ? "Все доходы" : "Все расходы"; var result = tran.Tags.FirstOrDefault(t => t.Is(rootName)); if (result != null) { return(result); } MessageBox.Show( batchProcessing ? $"Нет категории для проводки \n {tran.Timestamp} {tran.Amount} {tran.Currency.ToString().ToLower()}" : "Не задана категория!", "Ошибка!"); return(null); }
public static MoneyBag MoneyBagForAccount(this TranWithTags tran, Account account) { var result = new MoneyBag(); switch (tran.Operation) { case OperationType.Доход: return(tran.MyAccount.Is(account) ? new MoneyBag(new Money(tran.Currency.GetValueOrDefault(), tran.Amount)) : null); case OperationType.асход: return(tran.MyAccount.Is(account) ? new MoneyBag(new Money(tran.Currency.GetValueOrDefault(), -tran.Amount)) : null); case OperationType.Перенос: if (tran.MyAccount.Is(account)) { result = result - new Money(tran.Currency.GetValueOrDefault(), tran.Amount); } if (tran.MySecondAccount.Is(account)) { result = result + new Money(tran.Currency.GetValueOrDefault(), tran.Amount); } return(result); case OperationType.Обмен: if (tran.MyAccount.Is(account)) { result = result - new Money(tran.Currency.GetValueOrDefault(), tran.Amount); } if (tran.MySecondAccount.Is(account)) { result = result + new Money(tran.CurrencyInReturn.GetValueOrDefault(), tran.AmountInReturn); } return(result); default: return(null); } }
public static decimal AmountForTag(this TranWithTags tran, Account tag, CurrencyCodes?currency, DateTime upToDateTime) { return(tran.Timestamp <= upToDateTime?AmountForAccount(tran, tag, currency) : 0); }
public static decimal AmountForTag(this TranWithTags tran, Account tag, CurrencyCodes?currency, Period period) { return(period.ContainsButTimeNotChecking(tran.Timestamp) ? AmountForAccount(tran, tag, currency) : 0); }
public static MoneyBag MoneyBagForAccount(this TranWithTags tran, Account account, DateTime upToDateTime) { return(tran.Timestamp <= upToDateTime?MoneyBagForAccount(tran, account) : null); }
public static bool HasntGotCategoryTagThoughItShould(this TranWithTags tran) { return((tran.Operation == OperationType.Доход || tran.Operation == OperationType.асход) && tran.GetTranArticle(tran.Operation == OperationType.Доход, false) == null); }
public static string DumpOfSecondAccount(this TranWithTags tran) { return(tran.Operation == OperationType.Перенос || tran.Operation == OperationType.Обмен ? tran.MySecondAccount.Name : ""); }
public static CurrencyCodes CurrencyOfSecondAccount(this TranWithTags tran) { return(tran.Operation == OperationType.Перенос ? tran.Currency.GetValueOrDefault() : tran.CurrencyInReturn.GetValueOrDefault()); }