Beispiel #1
0
        public IEnumerable <TraceableIncome> GetMonthlyIncomes()
        {
            List <Income>          incomes  = IncomeClass.Instance().ParseIncomes();
            List <TraceableIncome> tIncomes = new List <TraceableIncome>();

            foreach (Income income in incomes)
            {
                TraceableIncome tIncome = new TraceableIncome()
                {
                    amount = income.amount,
                    year   = income.date.Year,
                    month  = income.date.Month,
                    dateID = (income.date.Year * 100) + income.date.Month
                };
                tIncomes.Add(tIncome);
            }
            var traceableIncomes = from income in tIncomes
                                   group income.amount by income.dateID into incomeGroup
                                   select new TraceableIncome {
                dateID = incomeGroup.Key,
                amount = incomeGroup.Sum(),
                month  = incomeGroup.Key % 100,
                year   = incomeGroup.Key / 100
            };

            return(traceableIncomes.ToList <TraceableIncome>());
        }
Beispiel #2
0
        public IEnumerable <TraceableBalance> GetMonthlyBalances() //Gets list of every year-month balances
        {
            List <TraceableIncome>  tIncomes  = (List <TraceableIncome>)IncomeClass.Instance().GetMonthlyIncomes();
            List <TraceableExpense> tExpenses = (List <TraceableExpense>)ExpenseClass.Instance().GetMonthlyExpenses();
            List <TraceableBalance> tBalances = new List <TraceableBalance>();

            for (int i = 0; i < tIncomes.Count; i++)
            {
                if (tIncomes[i].dateID == tExpenses[i].dateID)
                {
                    TraceableBalance tBalance = new TraceableBalance()
                    {
                        amount = tIncomes[i].amount - tExpenses[i].amount,
                        year   = tIncomes[i].year,
                        month  = tIncomes[i].month,
                        dateID = tIncomes[i].dateID
                    };
                    tBalances.Add(tBalance);
                }
                else
                {
                    throw new Exception("Balances cannot be calculated because of missing income or expense data, or errors in parsing data");
                }
            }
            return(tBalances);
        }
Beispiel #3
0
        private static IncomeClass _instance = null; //Singleton pattern

        public static IncomeClass Instance()         //Lazy Load initiation
        {
            if (_instance == null)
            {
                _instance = new IncomeClass();
            }
            return(_instance);
        }
Beispiel #4
0
        public decimal MonthlyIncome()
        {
            List <Income> income = IncomeClass.Instance().ParseIncomes();

            decimal incomeTotal = 0;

            foreach (IncomeClass.Income oneIncome in income)
            {
                if (oneIncome.date.CheckIfCurrentMonth())
                {
                    incomeTotal += oneIncome.amount;
                }
            }

            return(incomeTotal);
        }
Beispiel #5
0
        private string ChartRepresenation(string _write)
        {
            List <ExpenseClass.Expense> _expenses = ExpenseClass.Instance().ParseExpenses();
            List <IncomeClass.Income>   _incomes  = IncomeClass.Instance().ParseIncomes();
            var expenses = Expenses(_expenses);
            var incomes  = Incomes(_incomes);

            if (expenses.Count() == incomes.Count())
            {
                _write = CalculateEqual(expenses, incomes, _write);
            }
            else if (incomes.Count() > expenses.Count())
            {
                _write = CalculateIncomeMore(expenses, incomes, _write);
            }
            else
            {
                _write = CalculateExpenseMore(expenses, incomes, _write);
            }
            return(_write);
        }
Beispiel #6
0
 public decimal GetMonthlyBalance()
 {
     return(IncomeClass.Instance().MonthlyIncome() - ExpenseClass.Instance().MonthlyExpenses());
 }
Beispiel #7
0
 public decimal GetMonthlyIncome()
 {
     return(IncomeClass.Instance().MonthlyIncome());
 }