// GET: Dashboard/Balance public ActionResult Index(DateTime?searchTermStart = null, DateTime?searchTermEnd = null) { BalanceListingModel model = new BalanceListingModel(); model.SearchTermStart = searchTermStart; model.SearchTermEnd = searchTermEnd; if (searchTermStart != null && searchTermEnd != null) { model = GetBalancesByDate(searchTermStart, searchTermEnd); } else { model = GetBalances(); } return(View(model)); }
public ActionResult CharterBar(BalanceListingModel model) { var context = new HBMContext(); ArrayList xValue = new ArrayList(); ArrayList yValue = new ArrayList(); // balance = GetBalances(); xValue.Add("Przychody"); xValue.Add("Wydatki"); yValue.Add(model.Incomes); yValue.Add(model.Expenses); new Chart(width: 600, height: 400, theme: Color.CHARTS_THEME) .AddSeries("Default", xValue: xValue, yValues: yValue) .Write("bmp"); return(null); ///*64, 165, 191, 228*/ /////163, 163, 163, 163 }
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); }
public JsonResult Action(DebtCardsActionModel model) { JsonResult json = new JsonResult(); var result = false; if (model.ID > 0) //we are trying to edit a record { var debtCards = debtCardServices.GetDebtCardsByID(model.ID); debtCards.Name = model.Name; debtCards.Limit = model.Limit; debtCards.PlannedTimeRefund = model.PlannedTimeRefund; result = debtCardServices.UpdateDebtCards(debtCards); ScheduledTransaction scheduledTransaction = new ScheduledTransaction(); ScheduledTransactionsServices scheduledTransactionsServices = new ScheduledTransactionsServices(); BalanceListingModel balanceModel = new BalanceListingModel(); BalanceController balanceController = new BalanceController(); balanceModel = balanceController.GetBalances(); DebtCardsListingModel debtsCardModel = new DebtCardsListingModel(); debtsCardModel.DebtCards = debtCardServices.GetAllDebtCards(); debtsCardModel.Transactions = transactionsServices.SearchTransactions("", null, 0, "", 0, null); foreach (var debts in debtsCardModel.DebtCards) { float remaning = debts.Limit; foreach (var transactions in debtsCardModel.Transactions) { if (transactions.BudgetsName == debts.Name) { remaning = remaning - transactions.Price; debts.Price = remaning; } } scheduledTransaction.Price = debts.Price; } scheduledTransaction.TransactionName = "Spłata karty"; scheduledTransaction.Recipient = "Bank"; scheduledTransaction.Data = model.PlannedTimeRefund; scheduledTransactionsServices.UpdateScheduledTransaction(scheduledTransaction); } else //we are trying to create a record { DebtCard debtCards = new DebtCard(); debtCards.Name = model.Name; debtCards.Limit = model.Limit; debtCards.PlannedTimeRefund = model.PlannedTimeRefund; result = debtCardServices.SaveDebtCards(debtCards); //Create Scheduled Transactions ScheduledTransaction scheduledTransaction = new ScheduledTransaction(); ScheduledTransactionsServices scheduledTransactionsServices = new ScheduledTransactionsServices(); BalanceListingModel balanceModel = new BalanceListingModel(); BalanceController balanceController = new BalanceController(); balanceModel = balanceController.GetBalances(); DebtCardsListingModel debtsCardModel = new DebtCardsListingModel(); debtsCardModel.DebtCards = debtCardServices.GetAllDebtCards(); debtsCardModel.Transactions = transactionsServices.SearchTransactions("", null, 0, "", 0, null); foreach (var debts in debtsCardModel.DebtCards) { float remaning = debts.Limit; foreach (var transactions in debtsCardModel.Transactions) { if (transactions.BudgetsName == debts.Name) { remaning = remaning - transactions.Price; debts.Price = remaning; } } if (debts.Price == 0) { scheduledTransaction.Price = debts.Price; } else { scheduledTransaction.Price = debts.Price; } } scheduledTransaction.TransactionName = "Spłata karty"; scheduledTransaction.Recipient = "Bank"; scheduledTransaction.Data = model.PlannedTimeRefund; scheduledTransactionsServices.SaveScheduledTransaction(scheduledTransaction); } if (result) { json.Data = new { Success = true }; } else { json.Data = new { Success = false, Message = "Unable to perform action on DebtCard." }; } return(json); }