Пример #1
0
        public string GenerateBudget(int index)
        {
            var data = "";
            var list = _fileManager.LoadBudget();

            var from = list[index].From.ConvertToDate();
            var to   = list[index].To.ConvertToDate();


            var expenses = _fileManager.ReadPayments("Expense");

            if (!expenses.Any())
            {
                return("");
            }


            data = "Budget for " + list[index].Category;
            var total = 0.00;

            total = expenses
                    .Where(x => x.Category == list[index].Category)
                    .Where(x => x.Date >= list[index].From)
                    .Where(x => x.Date <= list[index].To)
                    .Sum(x => x.Amount);

            data += "\r\n" + total + "/" + list[index].Sum + " €" + "\r\n" + Math.Round(total * 100 / list[index].Sum, 2) + "%" + "\r\n" +
                    from.ToString("yyyy/MM/dd") + " - " + to.ToString("yyyy/MM/dd");

            return(data);
        }
Пример #2
0
        public string GenerateIncomeStatistics(FileManager manager)
        {
            var list = manager.ReadPayments("Income");

            if (!list.Any())
            {
                return("No income data found!");
            }

            var data  = "Income statistics: \r\n\r\n";
            var total = list.Sum(x => x.Amount);
            var sums  = new Dictionary <string, double>();

            foreach (var category in Enum.GetNames(typeof(IncomeCategories)))
            {
                sums.Add(category, list.Where(x => x.Category == category).Sum(x => x.Amount));
            }

            foreach (var category in Enum.GetNames(typeof(IncomeCategories)))
            {
                var percent = total == 0
                    ? " (" + string.Format("{0:0.00}", 0) + "%)"
                    : " (" + string.Format("{0:0.00}", sums[category] / total * 100) + "%)";
                data += category + " " + string.Format("{0:0.00}", sums[category]) + percent + "\r\n";
            }
            return(data);
        }