Example #1
0
        private void LoadOrCreateDefaultBudget()
        {
            Diagnostics.Start();
            using (var tx = Database.GetTransaction())
            {
                var cashFlowList = CachedService.GetAllCashFlows();

                var sql = PetaPoco.Sql.Builder
                          .Select("*")
                          .From("Budget")
                          .Where("@0 BETWEEN DateFrom AND DateTo", BudgetDate.Date);
                Budget = Database.FirstOrDefault <Budget>(sql);
                if (Budget == null)
                {
                    Budget = Budget.CreateEmptyForDate(BudgetDate, cashFlowList);
                    Database.Save(Budget);
                }

                tx.Complete();
                PublishRefreshRequest(Budget);
            }

            Budget.PropertyChanged += (s, e) =>
            {
                Save(s as Budget);
            };
            Diagnostics.Stop();
        }
        public override void LoadData()
        {
            CashFlows.Clear();
            var cashFlowList = CachedService.GetAllCashFlows().Where(x => x.Id != CashFlowToDelete.Id);

            cashFlowList.ForEach(x => CashFlows.Add(x));
            SelectedCashFlow = CashFlows.FirstOrDefault();
        }
Example #3
0
        private void LoadCashFlows()
        {
            Diagnostics.Start();
            ExpensesGridCashFlows.IsNotifying = false;
            ExpensesGridCashFlows.Clear();
            CashFlows.Clear();
            var cashFlowList = CachedService.GetAllCashFlows();

            cashFlowList.ForEach(x => ExpensesGridCashFlows.Add(x));
            cashFlowList.ForEach(x => CashFlows.Add(x));

            ExpensesGridCashFlows.IsNotifying = true;
            SelectedExpenseCashFlow           = CashFlows.FirstOrDefault();

            NotifyOfPropertyChange(() => ExpensesGridCashFlows);
            Diagnostics.Stop();
        }
Example #4
0
 private void ShowWizard()
 {
     Shell.ShowDialog <BudgetEquationWizardShellViewModel, BudgetEquationWizardVM>(
         new
     {
         ValueTypes                = ValueTypes.ToList(),
         OperatorTypes             = OperatorTypes.ToList(),
         Incomes                   = CachedService.GetAllIncomes().ToList(),
         Savings                   = CachedService.GetAllSavings().ToList(),
         CashFlows                 = CachedService.GetAllCashFlows().ToList(),
         CashFlowGroups            = CachedService.GetAllCashFlowGroups().ToList(),
         Equations                 = Equations.ToList(),
         Equation                  = EquationToEdit,
         BudgetCalculatorEvaluator = BudgetCalculatorEvaluator,
     },
         null,
         null);
 }
        private void LoadBudgetPlanItems()
        {
            Diagnostics.Start();
            var cashFlows = CachedService.GetAllCashFlows();

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("BudgetPlan")
                      .InnerJoin("Budget")
                      .On("Budget.Id = BudgetPlan.BudgetId")
                      .InnerJoin("CashFlow")
                      .On("CashFlow.Id = BudgetPlan.CashFlowId")
                      .InnerJoin("CashFlowGroup")
                      .On("CashFlow.CashFlowGroupId = CashFlowGroup.Id")
                      .Where("BudgetPlan.BudgetId = @0", Budget.Id);
            var budgetPlans = Database.Query <BudgetPlan, Budget, CashFlow, CashFlowGroup>(sql).ToList();

            Budget.BudgetPlanItems.Clear();
            ((BindableCollectionExt <BudgetPlan>)Budget.BudgetPlanItems).AddRange(budgetPlans);

            DetachFromBudgetPlanItems();
            AllBudgetPlanList.Clear();
            foreach (var cashFlow in cashFlows)
            {
                var planItems = budgetPlans.Where(x => x.CashFlow.Id == cashFlow.Id).ToList();
                AllBudgetPlanList.Add(new BudgetPlanItemVM(Budget, cashFlow, planItems));
            }

            BudgetPlanListGrouped.Clear();
            cashFlows.GroupBy(x => x.GroupName).ForEach(cf =>
            {
                var groupBudgetPlanItems = AllBudgetPlanList.Where(x => x.GroupName == cf.Key).ToList();
                var groupedItem          = new BudgetPlanGroupItemVM(groupBudgetPlanItems)
                {
                    GroupName = cf.Key,
                };
                BudgetPlanListGrouped.Add(groupedItem);
            });

            AttachToBudgetPlanItems();
            Diagnostics.Stop();
        }
Example #6
0
        public void UpdateForeignDescriptions(BudgetCalculatorEquation equation)
        {
            foreach (var item in equation.Items)
            {
                switch (item.ValueType)
                {
                case CalculatorValueType.CalculatorEquationValue:
                    var eq = CachedService.GetAllEquations().FirstOrDefault(x => x.Id == item.ForeignId);
                    if (eq != null)
                    {
                        item.ForeignDescription = eq.Name;
                    }
                    break;

                case CalculatorValueType.BudgetExpensesValueOfType:
                    var cf = CachedService.GetAllCashFlows().FirstOrDefault(x => x.Id == item.ForeignId);
                    if (cf != null)
                    {
                        item.ForeignDescription = cf.Name;
                    }
                    break;
                }
            }
        }
Example #7
0
        public void AttachEvaluator(BudgetCalculatorItem calculatorItem)
        {
            CashFlow      cashFlow      = null;
            CashFlowGroup cashFlowGroup = null;

            switch (calculatorItem.ValueType)
            {
            case CalculatorValueType.BudgetTotalRevenuesValue:
                calculatorItem.Evaluator = () => Budget.TotalSumOfRevenues;
                break;

            case CalculatorValueType.BudgetIncomesValue:
            case CalculatorValueType.BudgetIncomesValueOfType:
                var income = CachedService.GetAllIncomes().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
                calculatorItem.Evaluator = () => GetSumOfBudgetIncomes(income);
                break;

            case CalculatorValueType.BudgetSavingsValue:
            case CalculatorValueType.BudgetSavingsValueOfType:
                var saving = CachedService.GetAllSavings().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
                calculatorItem.Evaluator = () => GetSumOfBudgetSavings(saving);
                break;

            case CalculatorValueType.BudgetExpensesValueOfType:
                cashFlow = CachedService.GetAllCashFlows().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
                if (cashFlow == null)
                {
                    throw new NullReferenceException(string.Format("Błąd obliczania równania {0}. Brak kategorii.", calculatorItem.Equation.Name));
                }
                calculatorItem.Evaluator = () => GetSumOfBudgetExpenses(cashFlow);
                break;

            case CalculatorValueType.BudgetExpensesWithDescription:
                calculatorItem.Evaluator = () => GetSumOfBudgetExpensesWithDescription(calculatorItem.Text);
                break;

            case CalculatorValueType.CalculatorEquationValue:
                var calculatorEquation = Equations.FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
                if (calculatorEquation == null)
                {
                    throw new NullReferenceException(string.Format("Nie udało się odnaleźć równania powiązanego z równaniem: {0}", calculatorItem.Name));
                }
                calculatorItem.Evaluator = () => Calculate(calculatorEquation);
                break;

            case CalculatorValueType.BudgetPlanValue:
                calculatorItem.Evaluator = () => Budget.TotalBudgetPlanValue;
                break;

            case CalculatorValueType.BudgetPlanValueOfCategory:
                cashFlow = CachedService.GetAllCashFlows().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
                if (cashFlow == null)
                {
                    throw new NullReferenceException(string.Format("Błąd obliczania równania {0}. Brak kategorii.", calculatorItem.Equation.Name));
                }
                calculatorItem.Evaluator = () => GetSumOfBudgetPlansOfCategory(cashFlow);
                break;

            case CalculatorValueType.BudgetPlanValueOfGroup:
                cashFlowGroup = CachedService.GetAllCashFlowGroups().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
                if (cashFlowGroup == null)
                {
                    throw new NullReferenceException(string.Format("Błąd obliczania równania {0}. Brak grupy.", calculatorItem.Equation.Name));
                }
                calculatorItem.Evaluator = () => GetSumOfBudgetPlansOfGroup(cashFlowGroup);
                break;
            }
        }