public ActionResult Edit(GlCategoryManagement category) { if (category.Id == 0) { _category.Save(category); } else { var categoryInDb = _category.Get(category.Id); var getGlCat = _glAccount.GetCatName(categoryInDb.Name); var glAccount = _glAccount.Get(getGlCat.Id); categoryInDb.Name = Request.Form["catName"]; categoryInDb.Description = Request.Form["catDescription"]; glAccount.CategoryManagementId = categoryInDb.Name; _category.Update(category); _glAccount.Update(glAccount); } return(RedirectToAction("Index", "GlCategoryManagement")); }
public GlAccount Get(int id) { var values = _db.Get(id); return(values); }
public void AccountInterestRate() { var day = financialDate.Day; var month = financialDate.Month; var daysRemaining = 0; var savingsConfig = _savings.GetFirst(); var currentConfig = _current.GetFirst(); var savingsAccount = _customerAccount.GetByAccountType(AccountType.Savings); var currentAccount = _customerAccount.GetByAccountType(AccountType.Current); if (savingsAccount != null) { var savingsInterestGl = _glAccount.Get(savingsConfig.GlAccountId); var savingsInterestPayableGl = _glAccount.Get(savingsConfig.SavingsInterestPayableGlId); decimal todaysInterest = 0; foreach (var account in savingsAccount) { daysRemaining = daysInMonth[month - 1] - day + 1; decimal interestRemainingforTheMonth = account.Balance * (savingsConfig.CreditInterestRate / 100) * ((decimal)daysRemaining / daysInMonth[month - 1]); if (daysRemaining != 0) { todaysInterest = interestRemainingforTheMonth / daysRemaining; } account.InterestGot += todaysInterest; _post.DebitGlAccount(todaysInterest, savingsInterestGl); _post.CreditGlAccount(todaysInterest, savingsInterestPayableGl); _customerAccount.Save(account); } if (day == daysInMonth[month - 1]) { foreach (var account in savingsAccount) { _post.DebitGlAccount(account.InterestGot, savingsInterestPayableGl); _post.CreditCustomerAccount(account.InterestGot, account.Id, account); account.InterestGot = 0; _customerAccount.Save(account); } } } if (currentAccount != null) { var currentInterestGl = _glAccount.Get(currentConfig.ExpenseGlAccountId); var currentInterestPayableGl = _glAccount.Get(currentConfig.CurrentInterestPayableGlId); var COTGl = _glAccount.Get(currentConfig.IncomeGlAccountId); foreach (var account in currentAccount) { decimal todaysInterest = 0; daysRemaining = daysInMonth[month - 1] - day + 1; decimal interestRemainingforTheMonth = account.Balance * (savingsConfig.CreditInterestRate / 100) * ((decimal)daysRemaining / daysInMonth[month - 1]); if (daysRemaining != 0) { todaysInterest = interestRemainingforTheMonth / daysRemaining; } account.InterestGot += todaysInterest; _post.DebitGlAccount(todaysInterest, currentInterestGl); _post.CreditGlAccount(todaysInterest, currentInterestPayableGl); _customerAccount.Save(account); } if (day == daysInMonth[month - 1]) { foreach (var account in currentAccount) { //remove cot accrued first _post.DebitCustomerAccount(account.CotAccured, account.Id, account); _post.CreditGlAccount(account.CotAccured, COTGl); account.CotAccured = 0; _customerAccount.Save(account); //add interest for current account _post.DebitGlAccount(account.InterestGot, currentInterestPayableGl); _post.CreditCustomerAccount(account.InterestGot, account.Id, account); account.InterestGot = 0; _customerAccount.Save(account); } } } }
public ActionResult Save(TellerPosting tellerPosting) { bool status = false; string message = ""; var checkConfig = _config.checkConfig(); if (checkConfig) { //Getting values from form tellerPosting.Amount = Convert.ToDecimal(Request.Form["Amount"], CultureInfo.InvariantCulture); tellerPosting.Narration = Request.Form["Narration"]; tellerPosting.DateOfPosting = DateTime.Now; tellerPosting.Type = (PostingType)Convert.ToInt32(Request.Form["Type"]); tellerPosting.CustomerId = Convert.ToInt32(Request.Form["Id"]); tellerPosting.UserId = Convert.ToInt32(Request.Form["tellerId"]); var customerAccount = _contextAccount.Get(tellerPosting.CustomerId); var amount = tellerPosting.Amount; var customerId = tellerPosting.CustomerId; var userId = tellerPosting.UserId; var datePosted = tellerPosting.DateOfPosting; var tillAccountId = Convert.ToInt32(Session["ID"]); var tillAccount = _tillAccount.GetUserId(tillAccountId); var tillGlAccountId = tillAccount.AccountManagementId; var tellerGlAccount = _glContext.Get(tillGlAccountId); if (tellerPosting.Type == PostingType.Withdrawal) { if (tellerGlAccount.AccountBalance < tellerPosting.Amount) { ModelState.AddModelError("Account", "Insufficient funds in till account"); return(View()); } if (customerAccount.Balance < tellerPosting.Amount) { ModelState.AddModelError("Account", "Insufficient funds in customer account"); return(View()); } if (customerAccount.Balance < amount + customerAccount.CurrentLien) { ModelState.AddModelError("Account", "Cannot Withdraw This Amount"); return(View()); } var withdraw = _logic.Withdrawal(amount, customerId, userId, tellerPosting, datePosted); if (withdraw != true) { ViewBag.Message = "Withdraw Failed"; ViewBag.Status = false; return(View()); } message = "Withdrawal Successful"; status = true; ViewBag.Message = message; ViewBag.Status = status; return(RedirectToAction("Index", "TellerPosting")); } var deposit = _logic.Deposit(amount, customerId, userId, tellerPosting, datePosted); if (deposit != true) { ViewBag.Message = "Deposit Failed"; ViewBag.Status = false; return(View()); } message = "Deposit Successful"; status = true; ViewBag.Message = message; ViewBag.Status = status; } else { TempData["Error"] = "A Configuration is not set"; return(View()); } return(RedirectToAction("Index", "TellerPosting")); }
public ActionResult Create(GlPosting savePost) { bool status = false; string message = ""; GlPostingViewModels viewModel = new GlPostingViewModels() { CreditAccount = _contextAccount.GetAll(), DebitAccount = _contextAccount.GetAll() }; try { //getting values from form savePost.Amount = Convert.ToDecimal(Request.Form["Amount"], CultureInfo.InvariantCulture); savePost.DebitAccountNarration = Request.Form["DebitNarration"]; savePost.DebitAccountId = Convert.ToInt32(Request.Form["Debit"]); savePost.CreditAccountNarration = Request.Form["CreditNarration"]; savePost.CreditAccountId = Convert.ToInt32(Request.Form["Credit"]); savePost.UserId = Convert.ToInt32(Request.Form["Id"]); savePost.DatePosted = DateTime.Now; var checkingAccounts = _logic.CheckAccount(savePost.DebitAccountId, savePost.CreditAccountId); if (checkingAccounts) { ModelState.AddModelError("AccountEqual", "Accounts are the same, Please check again"); return(View(viewModel)); } var creditAcct = _contextAccount.Get(savePost.CreditAccountId); var debitAcct = _contextAccount.Get(savePost.DebitAccountId); var amount = savePost.Amount; //Validating amount in account if (creditAcct.Name.ToLower().Contains("till") || creditAcct.Name.ToLower().Contains("vault")) { if (creditAcct.AccountBalance < amount) { ModelState.AddModelError("AccountEqual", "You are posting an insufficient amount"); return(View(viewModel)); } } //getting account code used var creditacctcode = creditAcct.AccCode.ToString()[0].ToString(); var debitacctcode = debitAcct.AccCode.ToString()[0].ToString(); //Posting logic _logic.CreditPost(amount, creditAcct, creditacctcode); _logic.DebitPost(amount, debitAcct, debitacctcode); //save post into database _logic.SavePost(savePost); _contextAccount.Update(creditAcct); _contextAccount.Update(debitAcct); message = "Post Complete"; status = true; ViewBag.Message = message; ViewBag.Status = status; return(View(viewModel)); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } }