コード例 #1
0
        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;
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
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);
        }
コード例 #4
0
        // возвращает базовую категорию
        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);
        }
コード例 #5
0
 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);
 }
コード例 #6
0
        // возвращает подробную категорию
        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);
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
 public static decimal AmountForTag(this TranWithTags tran, Account tag, CurrencyCodes?currency, DateTime upToDateTime)
 {
     return(tran.Timestamp <= upToDateTime?AmountForAccount(tran, tag, currency) : 0);
 }
コード例 #9
0
 public static decimal AmountForTag(this TranWithTags tran, Account tag, CurrencyCodes?currency, Period period)
 {
     return(period.ContainsButTimeNotChecking(tran.Timestamp) ? AmountForAccount(tran, tag, currency) : 0);
 }
コード例 #10
0
 public static MoneyBag MoneyBagForAccount(this TranWithTags tran, Account account, DateTime upToDateTime)
 {
     return(tran.Timestamp <= upToDateTime?MoneyBagForAccount(tran, account) : null);
 }
コード例 #11
0
 public static bool HasntGotCategoryTagThoughItShould(this TranWithTags tran)
 {
     return((tran.Operation == OperationType.Доход || tran.Operation == OperationType.асход) &&
            tran.GetTranArticle(tran.Operation == OperationType.Доход, false) == null);
 }
コード例 #12
0
 public static string DumpOfSecondAccount(this TranWithTags tran)
 {
     return(tran.Operation == OperationType.Перенос || tran.Operation == OperationType.Обмен
         ? tran.MySecondAccount.Name
         : "");
 }
コード例 #13
0
 public static CurrencyCodes CurrencyOfSecondAccount(this TranWithTags tran)
 {
     return(tran.Operation == OperationType.Перенос
         ? tran.Currency.GetValueOrDefault()
         : tran.CurrencyInReturn.GetValueOrDefault());
 }