private decimal GetOweAmount(long accountId, long sharedAccountId, DateTime month) { var expenses = ExpenseRepository.GetAccountExpenses(sharedAccountId); expenses = expenses.Where(e => e.SpentDate.Year == month.Year && e.SpentDate.Month == month.Month).ToList(); var transfers = SharedAccountRepository.GetSharedAccountMoneyTransfer(sharedAccountId); transfers = transfers.Where(t => t.ForYear == month.Year && t.ForMonth == month.Month).ToList(); var yourIncomeTotal = IncomeRepository.GetAccountIncome(accountId).Where(i => i.IncomeDate.Year == month.Year && i.IncomeDate.Month == month.Month).Sum(i => i.Amount); var partnerIncomeTotal = IncomeRepository.GetPartnerIncome(accountId).Where(i => i.IncomeDate.Year == month.Year && i.IncomeDate.Month == month.Month).Sum(i => i.Amount); var yourPercentage = yourIncomeTotal + partnerIncomeTotal == 0 ? 0 : yourIncomeTotal / (yourIncomeTotal + partnerIncomeTotal); var sharedSpentTotal = expenses.Sum(e => e.Amount); var yourSharedSpentTotal = expenses.Where(e => e.SpentAccountId == accountId).Sum(e => e.Amount); var yourIdealSpentTotal = yourPercentage * sharedSpentTotal; var youPayed = transfers.Where(t => t.PayerAccountId == accountId).Sum(t => t.Amount); var youRecieved = transfers.Where(t => t.PayedAccountId == accountId).Sum(t => t.Amount); var finalAmount = Math.Round(yourIdealSpentTotal - yourSharedSpentTotal, 2); finalAmount = finalAmount - youPayed + youRecieved; return(finalAmount); }
private void Debit(Account account, Account internalAccount, Movement movement) { MovementHelpers.Debit(HistoricMovementRepository, movement.Amount, account.Id, ObjectType.Account, account.CurrentBalance, internalAccount.Id, ObjectType.Account, internalAccount.CurrentBalance); account.CurrentBalance -= movement.Amount; BankAccountRepository.Update(account); internalAccount.CurrentBalance += movement.Amount; BankAccountRepository.Update(internalAccount); if (!movement.TargetAccountId.HasValue) { throw new ArgumentException("Target Income ID should not be null."); } var income = new Income { Description = "Transfer: " + movement.Description, Cost = movement.Amount, AccountId = movement.TargetAccountId.Value, DateIncome = movement.Date }; var mappedIncome = IncomeRepository.Create(income); movement.TargetIncomeId = mappedIncome.Id; }
public ActionResult DeleteIncome(string id) { var incomeRepository = new IncomeRepository(); incomeRepository.DeleteIncome(Convert.ToInt32(id)); return(RedirectToAction("Index")); }
public ActionResult EditIncome(int id) { var incomeRepository = new IncomeRepository(); var incomeItem = incomeRepository.FindIncome(id); var viewModel = new IncomeManagingViewModel(incomeItem); return(View(viewModel)); }
public ActionResult AddNewIncome(IncomeManagingViewModel item) { if (ModelState.IsValid) { var incomeRepository = new IncomeRepository(); incomeRepository.AddIncome(item.IncomeItem); } return(RedirectToAction("Index")); }
public Income CreateIncome(IncomeRequest Income) { var entityToInsert = new Income() { }; MergeIncome(entityToInsert, Income); IncomeRepository.Insert(entityToInsert); return(entityToInsert); }
public Income GetById(int IncomeId) { var Income = IncomeRepository.GetById(IncomeId); if (Income == null) { throw new BadRequestException(ErrorMessages.GastoNoEncontrado); } return(Income); }
public void Can_Retrieve_All_Saved_Income_From_Database() { using (var repo = new IncomeRepository(_context)) { _context.Staffs.Add(sampleManager); _context.SaveChanges(); var manager = _context.Staffs.Single(); repo.Create(new Income("income1", 2300, manager.Id)); //repo.Create(new Income("income2", 4300, manager.Id)); Assert.AreEqual(2, repo.GetAllIncome().Count()); } }
public void Can_Retrieve_Saved_Income_From_Database() { using (var repo = new IncomeRepository(_context)) { _context.Staffs.Add(sampleManager); _context.SaveChanges(); Staff manager = _context.Staffs.Single(); Income income = new Income("Web_Adverts", 2300, manager.Id); repo.Create(income); Income retrievedIncome = repo.GetIncome(manager.Incomes.Single().Id); Assert.AreEqual(2300, retrievedIncome.Amount); } }
public UnitOfWork(ApplicationDbContext context) { _context = context; Notifications = new NotificationRepository(_context); Income = new IncomeRepository(_context); IncomeCategory = new IncomeCategoryRepository(_context); ExpenseCategory = new ExpenseCategoryRepository(_context); Documents = new DocumentRepository(_context); Projects = new ProjectRepository(_context); Products = new ProductRepository(_context); Clients = new ClientRepository(_context); ProjectStatus = new ProjectStatusRepository(_context); ProjectSource = new ProjectSourceRepository(_context); }
public void Can_Retrieve_DateCreated_From_Saved_Income() { using (var repo = new IncomeRepository(_context)) { _context.Staffs.Add(sampleManager); _context.SaveChanges(); Staff manager = _context.Staffs.Single(); Income income = new Income("IMF_Grant", 45000, manager.Id); string currentDate = DateTime.Now.ToString("yyyy-MM-dd-HH"); repo.Create(income); Income retrievedIncome = manager.Incomes.Single(); Assert.AreEqual(currentDate, retrievedIncome.DateCreated.ToString("yyyy-MM-dd-HH")); } }
public PortfolioModel(PortfolioItemRepository portfolioItemRepository, SecurityDataRepository securityDataRepository, IncomeRepository incomeRepository) { _porfolioItemRepository = portfolioItemRepository; _securityDataRepository = securityDataRepository; _incomeRepository = incomeRepository; Messenger.Default.Register <LoadPortfolioMessage>(this, async(msg) => { IEnumerable <PortfolioItem> portfolioItemList = await this._porfolioItemRepository.GetAll(); IEnumerable <Income> incomeList = await this._incomeRepository.GetAll(); foreach (PortfolioItem item in portfolioItemList) { SecurityData data = null; if (item.Code != "RUR") { data = await this._securityDataRepository.GetById(item.Code); } else { data = new SecurityData() { MarketData = new MarketData() { LCURRENTPRICE = 1m } }; } item.Price = data.MarketData.LCURRENTPRICE != 0 ? data.MarketData.LCURRENTPRICE : data.SecurityInfo.PREVLEGALCLOSEPRICE; } decimal PorfolioPrice = portfolioItemList.Sum(p => p.Value); decimal IncomeTotal = incomeList.Sum(i => i.Value); foreach (PortfolioItem item in portfolioItemList) { item.Perc = Math.Round((item.Value / PorfolioPrice) * 100, 2); } Messenger.Default.Send <PortfolioLoadedMessage>(new PortfolioLoadedMessage() { PortfolioItems = portfolioItemList, PortfolioPrice = PorfolioPrice, IncomeTotal = IncomeTotal }); }); }
public void Can_Update_Saved_Income() { using (var repo = new IncomeRepository(_context)) { _context.Staffs.Add(sampleManager); _context.SaveChanges(); var manager = _context.Staffs.Single(); repo.Create(new Income("income1", 2300, manager.Id)); Income savedIncome = manager.Incomes.Single(); savedIncome.Description = ".Net_Conference_Revenues"; savedIncome.Amount = 3400; repo.Update(savedIncome); Assert.AreEqual(".Net_Conference_Revenues", manager.Incomes.Single().Description); } }
public void Can_Successfully_Create_New_Income_In_DataBase() { using (CashFlowEntities context = new CashFlowEntities()) using (var repo = new IncomeRepository(context)) using (var staffRepo = new StaffRepository(context)) using (DbContextTransaction transaction = context.Database.BeginTransaction()) { context.Staffs.Add(sampleManager); context.SaveChanges(); Income income = new Income("Web_Advertisment", 3000, sampleManager.Id); repo.Create(income); var dbIncome = sampleManager.Incomes.SingleOrDefault(); Assert.AreEqual(3000, dbIncome.Amount); transaction.Rollback(); } }
public IList <Income> GetAll() { var Incomes = IncomeRepository.GetAll(); if (Incomes == null) { throw new BadRequestException(ErrorMessages.GastoNoEncontrado); } var result = new List <Income>(); var enumerator = Incomes.GetEnumerator(); while (enumerator.MoveNext()) { result.Add(enumerator.Current); } return(result); }
private DashboardModel GetDashboardModel(long accountId, long?sharedAccountId, bool sharedDashboard) { var model = new DashboardModel(); var expenses = sharedDashboard ? ExpenseRepository.GetAccountExpenses(sharedAccountId.GetValueOrDefault()) : ExpenseRepository.GetAccountExpenses(accountId); var income = sharedDashboard ? IncomeRepository.GetAccountIncome(sharedAccountId.GetValueOrDefault()) : IncomeRepository.GetAccountIncome(accountId); model.SpentToday = GetTotalSpentAmount(expenses, ExpenseSummaryTimePeriod.Today); model.SpentThisWeek = GetTotalSpentAmount(expenses, ExpenseSummaryTimePeriod.ThisWeek); model.SpentThisMonth = GetTotalSpentAmount(expenses, ExpenseSummaryTimePeriod.ThisMonth); model.SpentThisYear = GetTotalSpentAmount(expenses, ExpenseSummaryTimePeriod.ThisYear); model.ExpensesLineChart = GetLineChart(expenses); model.IncomeLineChart = GetLineChart(income); model.PieChart = GetPieChart(expenses); model.BudgetOverviewList = sharedDashboard ? GetBudgetOverviewChart(expenses, sharedAccountId.GetValueOrDefault()) : GetBudgetOverviewChart(expenses, accountId); model.Shared = GetSharedDashboardModel(accountId, sharedAccountId, sharedDashboard); if (sharedDashboard || !sharedAccountId.HasValue) { model.SharedExpensesLineChart.Show = false; model.SpentExpensesLineChart.Show = false; } else { var spentExpenses = ExpenseRepository.GetAccountExpensesIncludeShared(accountId); spentExpenses.AddRange(GetMoneyTransferAsExpense(accountId, sharedAccountId.GetValueOrDefault())); var sharedExpenses = ExpenseRepository.GetAccountExpenses(accountId); sharedExpenses.AddRange(ExpenseRepository.GetAccountExpenses(sharedAccountId.GetValueOrDefault())); model.SpentExpensesLineChart = GetLineChart(spentExpenses); model.SharedExpensesLineChart = GetLineChart(sharedExpenses); } return(model); }
private void Credit(Account account, Account internalAccount, Movement movement) { MovementHelpers.Credit(HistoricMovementRepository, movement.Amount, account.Id, ObjectType.Account, account.CurrentBalance, internalAccount.Id, ObjectType.Account, internalAccount.CurrentBalance); account.CurrentBalance += movement.Amount; BankAccountRepository.Update(account); internalAccount.CurrentBalance -= movement.Amount; BankAccountRepository.Update(internalAccount); if (!movement.TargetIncomeId.HasValue) { throw new ArgumentException("Target Income ID should not be null."); } var income = IncomeRepository.GetById(movement.TargetIncomeId.Value); IncomeRepository.Delete(income); }
public UnitOfWork(PlutoContext context) { _ILog = Log.GetInstance; _context = context; AppUsers = new UserRepository(context); Students = new StudentRepository(context); PaymentHistories = new PaymentHistoryRepository(context); Payments = new PaymentRepository(context); studentclasses = new StudentClassRepository(context); departments = new DepartmentRepository(context); regions = new RegionRepository(context); studentstatuses = new StudentStatusRepository(context); employees = new EmployeeRepository(context); employeedocuments = new EmployeeDocumentRepository(context); payrollamounts = new PayrollAmountRepository(context); employeecategories = new EmployeeCategoryRepository(context); employeelevelsofeducation = new EmployeeLevelOfEducationRepository(context); payrollrates = new PayrollRateRepository(context); taxrates = new TaxRateRepository(context); ssnitrates = new SSNITRateRepository(context); studentsubjects = new StudentSubjectRepository(context); payrollallowances = new PayrollAllowancesRepository(context); employeetypes = new EmployeeTypeRepository(context); employeeloanhistories = new EmployeeLoanHistoryRepository(context); employeeloans = new EmployeeLoanRepository(context); exams = new ExamRepository(context); marks = new MarkRepository(context); externalhelper = new ExternalHelperRepository(context); hostels = new HostelRepository(context); libraries = new LibraryRepository(context); transports = new TransportRepository(context); expenses = new ExpenseRepository(context); expensecategories = new ExpenseCategoryRepository(context); incomes = new IncomeRepository(context); incomecategories = new IncomeCategoryRepository(context); books = new BookRepository(context); booktypes = new BookTypeRepository(context); rooms = new RoomRepository(context); payrolldates = new PayrollDateRepository(context); allowances = new AllowanceRepository(context); }
public void SetProgressBar(DateTime date) { if (date <= DateTime.Now) { // Set progress bar width ExpenseRepository expenses = new ExpenseRepository(); double sumExpenses = expenses.GetItems().Where(e => (e.UserId == controller.user.Id && e.Date.Day == date.Day && e.Date.Month == date.Month && e.Date.Year == date.Year)).Sum(e => e.AmountOfMoney); progressBar.Value = sumExpenses; // need to be done: setting max value of progress bar IncomeRepository incomes = new IncomeRepository(); double sumIncomes = incomes.GetItems().Where(i => (i.UserId == controller.user.Id && i.Date.Month == date.Month)).Sum(i => i.MoneyCount); progressBar.Maximum = Math.Round(sumIncomes / 30.0); CheckProgressBarStatus(sumExpenses, progressBar.Maximum); } else { MessageBox.Show("Wrong date, can't set progress bar"); } }
public ActionResult SaveIncome(string source, string type, string amount, string date) { var accountId = HttpContext.Session.Get <long>(SessionHelper.SessionKeyAccountId); if (accountId == default) { return(RedirectToAction("Login", "Account", new { id = LoginHelper.BudgetApp })); } if (string.IsNullOrWhiteSpace(source)) { return(Json(new { status = false, message = "Source is required" })); } if (string.IsNullOrWhiteSpace(type)) { return(Json(new { status = false, message = "Type is required" })); } if (string.IsNullOrWhiteSpace(amount)) { return(Json(new { status = false, message = "Amount is required" })); } if (!decimal.TryParse(amount, out decimal amountValue)) { return(Json(new { status = false, message = "Amount is required" })); } if (string.IsNullOrWhiteSpace(date)) { return(Json(new { status = false, message = "Date is required" })); } if (!DateTime.TryParse(date, out DateTime dateValue)) { return(Json(new { status = false, message = "Date is required" })); } var sourceId = IncomeSourceHelper.GetOrAddIncomeSourceId(source); var typeId = IncomeTypeHelper.GetIncomeTypeId(type); IncomeRepository.AddIncome(accountId, sourceId, typeId, amountValue, dateValue); return(Json(new { status = true, message = "Income Added" })); }
public Income UpdateIncome(Income originalIncome, IncomeRequest Income) { this.MergeIncome(originalIncome, Income); IncomeRepository.Update(originalIncome); return(originalIncome); }
public IncomesController(IncomeRepository incomeRepository, BudgetRepository budgetRepository, IMapper mapper) { this.incomeRepository = incomeRepository; this.budgetRepository = budgetRepository; this.mapper = mapper; }
public IncomeService(IncomeRepository repository) { _repository = repository; }
public IncomeService(IncomeRepository incomeRepository, WalletRepository walletRepository, IMapper mapper) { _incomeRepository = incomeRepository; _walletRepository = walletRepository; _mapper = mapper; }
public IList <Income> GetByConsortiumId(int consortiumId, DateTime startDate, DateTime endDate) { return(IncomeRepository.GetByConsortiumId(consortiumId, startDate, endDate).ToList()); }
public IncomeServices(IncomeRepository incomeRepository) { this.incomeRepository = incomeRepository; }
public NexcoController() { _incomeRepository = new IncomeRepository(); }
/// <summary> /// Initializes a new instance of the <see cref="IncomeController"/> class. /// </summary> /// <param name="context">The db context</param> public IncomeController(ExpenseTrackerDBContext context) : base(context, new IncomeRepository(context)) { this.incomeRepository = this.repository as IncomeRepository; }
public IncomeService() { _incomeRepository = new IncomeRepository(); }
public void DeleteIncome(int IncomeId) { var Income = IncomeRepository.GetById(IncomeId); IncomeRepository.Delete(Income); }