Exemple #1
0
        public List <LegacyDailyNum> GetDailyPurchases(int userId)
        {
            var dailyPurchases =
                (from posting in _context.PostingForUser(userId)
                 join subcategory in _context.Subcategory on posting.SubcategoryId equals subcategory.SubcategoryId
                 join category in _context.Category on subcategory.CategoryId equals category.CategoryId
                 where category.Type == CategoryProperties.Type.Out
                 group posting by new { posting.Date.Year, posting.Date.Month, posting.Date.Day } into g
                 select new
            {
                g.Key.Year,
                g.Key.Month,
                g.Key.Day,
                Num = g.Count()
            }).ToList().Select(dp => new LegacyDailyNum
            {
                Year         = dp.Year,
                Month        = dp.Month,
                Day          = dp.Day,
                NumPurchases = dp.Num
            }).ToList();

            dailyPurchases.RemoveAll(p => UserSpecifics.ShouldDailyPurchaseMonthBeRemoved(new MonthAndYear(p.Year, p.Month), userId));

            return(dailyPurchases.ToList());
        }
        public void ShouldReturnThreeValues_WhenItIsUser1()
        {
            var userId = 1;

            var ids = UserSpecifics.GetTaxSubcategoryIds(userId);

            Assert.AreEqual(3, ids.Count);
        }
        public void ShouldReturnEmptyList_WhenItIsNotUser1()
        {
            var userId = _fixture.Create <int>() + 1;

            var ids = UserSpecifics.GetTaxSubcategoryIds(userId);

            CollectionAssert.IsEmpty(ids);
        }
Exemple #4
0
        public List <LegacyMonthlySumup> GetSumup(int userId)
        {
            var monthlyResults = _postingQueryRepository.Sumup(userId)
                                 .OrderBy(x => x.MonthAndYear.Year).ThenBy(x => x.MonthAndYear.Month).ThenBy(x => x.Type).ToList();

            Dictionary <MonthAndYear, double> monthlySalery = GetMonthlySalery(userId);

            var monthlyValues = new Dictionary <MonthAndYear, (double pureInWithoutPension, double pureOut)>();
            var monthly       = new List <LegacyMonthlySumup>();

            foreach (var data in monthlyResults.GroupBy(x => x.MonthAndYear))
            {
                var monthAndYear = data.Key;

                var @in  = data.SingleOrDefault(x => x.Type == "in")?.Sum ?? 0;
                var @out = data.SingleOrDefault(x => x.Type == "out")?.Sum ?? 0;
                var tax  = data.SingleOrDefault(x => x.Type == "tax")?.Sum ?? 0;

                double extra = UserSpecifics.CreateExtraLine(userId, monthAndYear, @in, tax);

                var pureIn  = @in - tax;
                var pureOut = @out - tax;

                var pensionRate = UserSpecifics.GetPensionRate(userId, monthAndYear);
                monthlySalery.TryGetValue(monthAndYear, out var salery);
                var selfPaidPension = salery * pensionRate;

                var pureInWithoutPension = @in - selfPaidPension - tax;
                if (pureInWithoutPension < 0 && UserSpecifics.HideNegativeInWithoutPension(userId))
                {
                    pureInWithoutPension = 0;
                }

                monthlyValues.Add(monthAndYear, (pureInWithoutPension, pureOut));

                var savingProcentage      = Calculate.SavingsRate(pureIn, pureOut);
                var savingsWithoutPension = Calculate.SavingsRate(pureInWithoutPension, pureOut);
                var savingsLastYear       = SavingsRateLastYear(monthAndYear, monthlyValues);

                var expensesLastYear = AverageExpensesLastYear(monthAndYear, monthlyValues);

                monthly.Add(new LegacyMonthlySumup
                {
                    Year    = monthAndYear.Year,
                    Month   = monthAndYear.Month,
                    In      = Math.Round(@in, 2),
                    Out     = Math.Round(@out, 2),
                    PureOut = Math.Round(pureOut, 2),
                    Savings = Math.Round(savingProcentage, 2),
                    SavingsWithoutOwnContribution = Math.Round(savingsWithoutPension, 2),
                    SavingsLastYear  = Math.Round(savingsLastYear, 2),
                    ExpensesLastYear = Math.Round(expensesLastYear, 2),
                    Extra            = Math.Round(extra, 2),
                });
            }

            return(monthly);
        }
Exemple #5
0
        private Dictionary <MonthAndYear, double> GetMonthlySalery(int userId)
        {
            if (!UserSpecifics.ShouldCalculateSelfPaidPension(userId))
            {
                return(new Dictionary <MonthAndYear, double>());
            }

            var subcategoryId = UserSpecifics.GetSalerySubcategoryId(userId);
            var monthlySalery = _postingQueryRepository.GetSubcategoryMonthlySum(userId, subcategoryId);

            return(monthlySalery);
        }
Exemple #6
0
        public List <LegacyMonthlySumPerDay> GetMonthlyAverageDailyPurchases(int userId)
        {
            var taxSubcategoryIds = UserSpecifics.GetTaxSubcategoryIds(userId);

            var sums = GetMonthlySubcategorySum(userId,
                                                category => category.Type == CategoryProperties.Type.Out,
                                                subcategory => !taxSubcategoryIds.Contains(subcategory.SubcategoryId))
                       .Select(x => new LegacyMonthlySumPerDay
            {
                Year      = x.Key.Year,
                Month     = x.Key.Month,
                SumPerDay = Math.Round(x.Value.Values.Sum() / DateTime.DaysInMonth(x.Key.Year, x.Key.Month), 2)
            })
                       .ToList();

            return(sums);
        }
Exemple #7
0
        public List <MonthlyTypeSum> Sumup(int userId)
        {
            var taxSubcategoryIds = UserSpecifics.GetTaxSubcategoryIds(userId);

            var inAndOut = (from p in _context.PostingForUser(userId)
                            join s in _context.Subcategory on p.SubcategoryId equals s.SubcategoryId
                            join c in _context.Category on s.CategoryId equals c.CategoryId
                            group p.Amount by new { p.Date.Year, p.Date.Month, c.Type } into g
                            select new
            {
                g.Key.Year,
                g.Key.Month,
                g.Key.Type,
                Sum = g.Sum()
            }).ToList();

            var tax = (from p in _context.PostingForUser(userId)
                       join s in _context.Subcategory on p.SubcategoryId equals s.SubcategoryId
                       join c in _context.Category on s.CategoryId equals c.CategoryId
                       where c.Type == CategoryProperties.Type.Out &&
                       taxSubcategoryIds.Contains(s.SubcategoryId)
                       group p.Amount by new { p.Date.Year, p.Date.Month } into g
                       select new
            {
                g.Key.Year,
                g.Key.Month,
                Type = "tax",
                Sum = g.Sum()
            }
                       ).ToList();

            return(inAndOut.Union(tax).Select(x => new MonthlyTypeSum
            {
                MonthAndYear = (x.Year, x.Month),
                Type = x.Type,
                Sum = x.Sum,
            }).ToList());