예제 #1
0
 internal void Merge(BudgetData b)
 {
     this.budget  += b.budget;
     this.actual  += b.actual;
     this.average += b.average;
     budgeted.AddRange(b.budgeted);
 }
예제 #2
0
        public BudgetData GetBudgetData(DateTime date, string name)
        {
            BudgetData data;

            if (!map.TryGetValue(name, out data))
            {
                // starting a new budget month
                data            = new BudgetData(name);
                data.BudgetDate = date;
                map[name]       = data;
            }
            return(data);
        }
예제 #3
0
        private BudgetData AddTransaction(Transaction t, bool isCategoryTransfer)
        {
            // We do not use "transaction.Date" because sometimes a transaction can be pulled into a different month's budget because it makes more
            // sense depending on what the transaction is about.  For example you might buy an expensive item on the 31st of the month and return it
            // on the 3rd of the next month because it was defective. This would normally create a spike in your budget graph and a weird profit in the
            // next month, so instead of that you can just move the transaction from the 3rd into the previous month's budget balance and so it disappears
            // completely rather than creating noise in your budget.
            DateTime date = t.BudgetBalanceDate.HasValue ? t.BudgetBalanceDate.Value : new DateTime(t.Date.Year, t.Date.Month, 1);
            string   name = date.ToString("MM/yyyy");

            BudgetData data = null;

            if (isCategoryTransfer)
            {
                // then this was a budget transfer into the category
                data = GetBudgetData(date, name);
                data.AddBudget(t);
            }
            else if (t.IsSplit)
            {
                bool added = false;
                foreach (Split s in t.Splits)
                {
                    if (!(s.IsBudgeted))
                    {
                        continue;
                    }
                    if (ExpenseCategoryMatchesFilter(s.Category))
                    {
                        data = GetBudgetData(date, name);
                        if (!added)
                        {
                            data.Add(t);
                            added = true;
                        }
                        data.Actual -= (double)s.amount;
                        sum         += (double)s.amount;
                    }
                }
            }
            else if (ExpenseCategoryMatchesFilter(t.Category))
            {
                data = GetBudgetData(date, name);
                data.AddActual(t);
                sum -= (double)t.amount;
            }
            return(data);
        }