public PostingAuthController(AppContext dbParam, CustomerAccountLogic custActLogicParam, TellerPostingLogic telPostLogicParam, FinancialReportLogic reportLogicParam, BusinessLogic busLogicParam) { db = dbParam; custActLogic = custActLogicParam; telPostLogic = telPostLogicParam; reportLogic = reportLogicParam; busLogic = busLogicParam; }
public PostingAuthController(AppContext dbParam, CustomerAccountLogic custActLogicParam, TellerPostingLogic telPostLogicParam, FinancialReportLogic reportLogicParam, BusinessLogic busLogicParam) { db = new AppContext(); custActLogic = new CustomerAccountLogic(); telPostLogic = new TellerPostingLogic(); reportLogic = new FinancialReportLogic(); busLogic = new BusinessLogic(); }
public PostingAuthController() { db = new AppContext(); custActLogic = new CustomerAccountLogic(); telPostLogic = new TellerPostingLogic(); reportLogic = new FinancialReportLogic(); busLogic = new BusinessLogic(); }
public ActionResult Create(TellerPostingViewModel model) { if (config.IsBusinessOpen == false) { return(View("BusinessClosed")); } if (ModelState.IsValid) { TellerPosting tellerPost = new TellerPosting(); tellerPost.CreditAmount = model.CreditAmount; tellerPost.DebitAmount = model.DebitAmount; tellerPost.CustomerAccount = context.CustomerAccounts.Find(model.CustomerAccountID); tellerPost.Narration = model.Narration; tellerPost.TransactionDate = DateTime.Now; tellerPost.PostingType = (PostingType)model.PostingType; string currentUserId = User.Identity.GetUserId(); ApplicationUser currentUser = context.Users.FirstOrDefault(x => x.Id == currentUserId); tellerPost.TillAccount = currentUser.GLAccount; string result = TellerPostingLogic.PostTeller(tellerPost.CustomerAccount, tellerPost.TillAccount, tellerPost.CreditAmount, tellerPost.PostingType, config); if (result == "success") { context.TellerPostings.Add(tellerPost); context.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Message = result; return(View(model)); } return(View(model)); }
public ActionResult PostTransaction(TellerPosting model) { EodLogic logic = new EodLogic(); if (logic.isBusinessClosed()) { return(PartialView("_Closed")); } if (ModelState.IsValid) { try { if (model.Amount <= 0) { return(PartialView("_IncorrectData")); } var loggedInTeller = getLoggedInUser(); if (loggedInTeller == null) { return(PartialView("_UnauthorizedTeller")); } var tillAct = new TellerMgtRepository().GetUserTill(loggedInTeller); if (tillAct == null) { return(PartialView("_UnauthorizedTeller")); } var act = (CustomerAccount)Session["custAccount"]; var account = custActRepo.GetByAccountNumber(act.AccountNumber); if (account == null) { ViewBag.ErrorMessage = "Invalid account selected"; return(PartialView("_InvalidAccount")); } model.Date = DateTime.Now; TellerPosting telPosting = new TellerPosting { Amount = model.Amount, Narration = model.Narration, Date = DateTime.Now, PostingType = model.PostingType, CustomerAccount = account, PostInitiator = loggedInTeller }; //check for balance sufficiency upon withdrawal if (model.PostingType == TellerPostingType.Withdrawal) { if (new CustomerAccountLogic().CustomerAccountHasSufficientBalance(account, model.Amount)) { if (!(tillAct.AccountBalance >= model.Amount)) { return(PartialView("_TellerInsufficientBalance")); } string result = new TellerPostingLogic().PostTeller(account, tillAct, model.Amount, model.PostingType); if (!result.Equals("success")) { return(PartialView("_UnknownError")); } tpRepo.Insert(telPosting); new CustomerAccountRepository().Update(account); new GlAccountRepository().Update(tillAct); RemoveAccountFromSession(); return(PartialView("_SuccessPost")); } else //no sufficient balance { ViewBag.ErrorMessage = "Insufficient balance"; return(PartialView("_InsufficientBalance")); } } else //deposit { string result = new TellerPostingLogic().PostTeller(account, tillAct, model.Amount, model.PostingType); if (!result.Equals("success")) { return(PartialView("_UnknownError")); } tpRepo.Insert(telPosting); new CustomerAccountRepository().Update(account); new GlAccountRepository().Update(tillAct); RemoveAccountFromSession(); return(PartialView("_SuccessPost")); } } catch (Exception ex) { ErrorLogger.Log("Message= " + ex.Message + "\nInner Exception= " + ex.InnerException + "\n"); return(PartialView("Error")); } } ViewBag.CustomerAccountId = new SelectList(custActRepo.GetAll().Where(a => a.AccountType != AccountType.Loan), "ID", "AccountNumber"); return(PartialView("_IncorrectData")); }//
protected void searchsubmit_OnServerClick(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(TextBoxNameCustAcctNo.Value)) { throw new Exception("Account Number field is required"); } if (string.IsNullOrWhiteSpace(TextBoxNameAmount.Value)) { throw new Exception("Amount field is required"); } if (string.IsNullOrWhiteSpace(TextBoxNameDuration.Value)) { throw new Exception("Duration field is required"); } if (string.IsNullOrWhiteSpace(TextBoxNameCustAcctName.Value)) { throw new Exception("Account Name field is required"); } if (DropDownListPaymentSchedule.SelectedValue == Core.PaymentSchedule.Days.ToString()) { if (string.IsNullOrWhiteSpace(TextBoxNameNumberOfDays.Value)) { throw new Exception("Number of Days field is required"); } } CustomerAccounts checkclosedoropen = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICustomerAccountsDb>() .SearchbyAccountNumber(TextBoxNameCustAcctNo.Value); if (checkclosedoropen.IsClosed == false) { if (string.IsNullOrWhiteSpace(TextBoxId.Value)) { LoanAccount loanAccount = new LoanAccount(); CustomerAccounts customerAccounts = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICustomerAccountsDb>() .SearchbyAccountNumber(TextBoxNameCustAcctNo.Value); //LoanConfig getLoanById = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<ILoanConfigDb>() // .RetrieveById(1); IList <LoanConfig> getLoanByIds = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ILoanConfigDb>() .RetrieveAll(); IList <EOD> eods = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IEODDb>().RetrieveAll(); TextBoxNameCustAcctName.Value = customerAccounts.AccountName; loanAccount.LinkedAccount = new CustomerAccounts(); loanAccount.LinkedAccount.Id = customerAccounts.Id; loanAccount.LoanConfig = new LoanConfig(); //loanAccount.LoanConfig.Id = getLoanById.Id; loanAccount.LoanConfig.Id = getLoanByIds[0].Id; loanAccount.AccountName = TextBoxNameCustAcctName.Value; loanAccount.LoanAmount = double.Parse(TextBoxNameAmount.Value); loanAccount.LoanDuration = double.Parse(TextBoxNameDuration.Value); loanAccount.LoanInterest = getLoanByIds[0].debitInterestRate; DateTime today = DateTime.Now; loanAccount.LoanStartDate = today; loanAccount.LoanDueDate = today.AddDays(loanAccount.LoanDuration); Random rand = new Random(); String randomPart = Convert.ToString(rand.Next(10000, 99999)); String customerId = customerAccounts.Customer.Id.ToString(); loanAccount.AccountNumber = '3' + customerId + randomPart; loanAccount.Balance = loanAccount.Balance + double.Parse(TextBoxNameAmount.Value); loanAccount.DateAdded = DateTime.Now; loanAccount.DateUpdated = DateTime.Now; loanAccount.PaymentSchedule = (PaymentSchedule)Enum.Parse(typeof(PaymentSchedule), DropDownListPaymentSchedule.SelectedValue); loanAccount.LoanStatus = LoanStatus.BeingPaid; loanAccount.TransactionDate = eods[0].FinancialDate; if (DropDownListPaymentSchedule.SelectedValue == Core.PaymentSchedule.Days.ToString()) { loanAccount.NumberOfDays = int.Parse(TextBoxNameNumberOfDays.Value); } GlAccount glAccount = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>() .RetrieveById(int.Parse(DropDownListLoanAccount.SelectedValue)); GlPostingLogic glPostingLogic = new GlPostingLogic(); glAccount.Balance = glPostingLogic.DebitGlAccount(glAccount, loanAccount.LoanAmount); User user = new User(); user = (User)Session["User"]; //Code to update balance in savings account GL var updateSavingsGlBalance = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ISavingsConfigDb>() .RetrieveByBranch(user.Branch.Id); updateSavingsGlBalance.SavingsAccountGL.Balance = glPostingLogic.CreditGlAccount(updateSavingsGlBalance.SavingsAccountGL, loanAccount.LoanAmount); //Put Code to update balance in current account GL here: var updateCurrentGlBalance = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICurrentConfigDb>() .RetrieveByBranch(user.Branch.Id); updateCurrentGlBalance.currentAccountGL.Balance = glPostingLogic.CreditGlAccount(updateCurrentGlBalance.currentAccountGL, loanAccount.LoanAmount); IList <EOD> eod = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IEODDb>().RetrieveAll(); //Code to Save savings Transaction in GL Posting: GlPosting savingsGlPosting = new GlPosting(); savingsGlPosting.Amount = loanAccount.LoanAmount; savingsGlPosting.CreditNarration = String.Format("{0} Credited", updateSavingsGlBalance.SavingsAccountGL.GlAccountName); savingsGlPosting.DebitNarration = String.Format("{0} Debited", glAccount.GlAccountName); savingsGlPosting.GlAccountToCredit = new GlAccount(); savingsGlPosting.GlAccountToCredit.Id = updateSavingsGlBalance.SavingsAccountGL.Id; savingsGlPosting.GlAccountToDebit = new GlAccount(); savingsGlPosting.GlAccountToDebit.Id = glAccount.Id; savingsGlPosting.TransactionDate = eod[0].FinancialDate; savingsGlPosting.DateAdded = DateTime.Now; savingsGlPosting.DateUpdated = DateTime.Now; //Code to Save Current A/C Transaction in GL Posting: GlPosting currentGlPosting = new GlPosting(); currentGlPosting.Amount = loanAccount.LoanAmount; currentGlPosting.CreditNarration = String.Format("{0} Credited", updateCurrentGlBalance.currentAccountGL.GlAccountName); currentGlPosting.DebitNarration = String.Format("{0} Debited", glAccount.GlAccountName); currentGlPosting.GlAccountToCredit = new GlAccount(); currentGlPosting.GlAccountToCredit.Id = updateCurrentGlBalance.currentAccountGL.Id; currentGlPosting.GlAccountToDebit = new GlAccount(); currentGlPosting.GlAccountToDebit.Id = glAccount.Id; currentGlPosting.TransactionDate = eod[0].FinancialDate; currentGlPosting.DateAdded = DateTime.Now; currentGlPosting.DateUpdated = DateTime.Now; TellerPostingLogic tellerPostingLogic = new TellerPostingLogic(); var updateCustAcctBal = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICustomerAccountsDb>() .SearchbyAccountNumber(TextBoxNameCustAcctNo.Value); updateCustAcctBal.Balance = tellerPostingLogic.CreditCustomerAccounts(customerAccounts, loanAccount.LoanAmount); Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ILoanAccountDb>().InsertData(loanAccount); Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>().UpdateData(glAccount); Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ICustomerAccountsDb>().UpdateData(updateCustAcctBal); if (customerAccounts.AccountType == AccountType.Savings) { Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>() .UpdateData(updateSavingsGlBalance.SavingsAccountGL); } if (customerAccounts.AccountType == AccountType.Current) { Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>() .UpdateData(updateCurrentGlBalance.currentAccountGL); } if (customerAccounts.AccountType == AccountType.Savings) { Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlPostingDb>() .InsertData(savingsGlPosting); } if (customerAccounts.AccountType == AccountType.Current) { Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlPostingDb>() .InsertData(currentGlPosting); } } else { } TextBoxNameCustAcctNo.Value = String.Empty; TextBoxNameCustAcctName.Value = String.Empty; TextBoxNameAmount.Value = String.Empty; TextBoxNameDuration.Value = String.Empty; if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message")) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Loan Disbursed Successfully." + "', function(){location = '/ManageCustomerAcct/AddLoanAcct.aspx';});</script>", false); } } else if (checkclosedoropen.IsClosed) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Customer Account is closed. Open Account" + "', function(){location = '/ManageCustomerAcct/AddLoanAcct.aspx';});</script>", false); } } catch (Exception ex) { if (DropDownListLoanAccount.SelectedValue == "0") { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Loan Account Not Selected. Please Select a Loan Account " + "', function(){});</script>", false); } //if (DropDownListPaymentSchedule.SelectedValue == "10") //{ // Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Payment Schedule Not Selected. Please Select a Payment Schedule" + "', function(){});</script>", false); //} string errorMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message; if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message")) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", @"<script type='text/javascript'>alertify.alert('Message', """ + errorMessage.Replace("\n", "").Replace("\r", "") + @""", function(){});</script>", false); } } }