Beispiel #1
0
        public BalanceListingModel GetBalances()
        {
            BalanceListingModel   model                = new BalanceListingModel();
            DebtCardsListingModel debtsCardModel       = new DebtCardsListingModel();
            DebtCardServices      debtCardServices     = new DebtCardServices();
            TransactionsServices  transactionsServices = new TransactionsServices();
            float countRemaningLimit = 0;
            var   context = new HBMContext();
            float incomes = 0, expenses = 0;
            int   valueCompare = 0;

            debtsCardModel.DebtCards    = debtCardServices.GetAllDebtCards();
            debtsCardModel.Transactions = transactionsServices.GetAllTransactions();

            DateTime now             = DateTime.Today;
            DateTime searchTermStart = new DateTime(now.Year, now.Month, 1);

            foreach (var transactions in context.Transactions)
            {
                valueCompare = DateTime.Compare(transactions.Date, (DateTime)now);
                if (valueCompare <= 0)
                {
                    valueCompare = DateTime.Compare((DateTime)searchTermStart, transactions.Date);
                    {
                        if (valueCompare <= 0) //daty zgodne
                        {
                            if (transactions.Budgets.KBudgetID == 1)
                            {
                                incomes += transactions.Price;
                            }
                            else
                            {
                                expenses += transactions.Price;
                            }
                        }
                    }
                }
            }


            foreach (var debts in debtsCardModel.DebtCards)
            {
                float remaning = debts.Limit;
                foreach (var transactionsDebts in debtsCardModel.Transactions)
                {
                    valueCompare = DateTime.Compare(transactionsDebts.Date, (DateTime)now);
                    if (valueCompare <= 0)
                    {
                        valueCompare = DateTime.Compare((DateTime)searchTermStart, transactionsDebts.Date);
                        {
                            if (valueCompare <= 0) //daty zgodne
                            {
                                if (transactionsDebts.BudgetsName == debts.Name)
                                {
                                    remaning   -= transactionsDebts.Price;
                                    debts.Price = remaning;
                                }
                            }
                        }
                    }
                }
                model.DebtCardRemaning = debts.Limit - remaning;
                countRemaningLimit    += model.DebtCardRemaning;
            }

            model.Incomes  = incomes;
            model.Expenses = expenses;

            model.DebtCardRemaning = countRemaningLimit;

            return(model);
        }