Ejemplo n.º 1
0
        public ActionResult Save(CustomerAccount account)
        {
            int userId = Convert.ToInt32(Request.Form["userId"]);
            int id     = Convert.ToInt32(Request.Form["id"]);

            if (ModelState.IsValid)
            {
                var accountInDb = _context.Get(account.Id);
                if (id == 0) //add account
                {
                    var customerId   = Request.Form["customerId"];
                    var customerName = _customerContext.GetByCustomerId(customerId).FullName;
                    account.CustomerId    = customerId;
                    account.CreatedAt     = DateTime.Now;
                    account.AccountName   = customerName;
                    account.IsOpen        = true;
                    account.AccountNumber = _context.GenerateAccountNumber(customerId, account.AccountType.ToString());
                    _context.Save(account);
                    TempData["Success"] = "Account Created Successfully";
                    return(RedirectToAction("Index"));
                }
                if (account.Id != 0)   //update account
                {
                    accountInDb.AccountName = account.AccountName;
                    accountInDb.BranchId    = account.BranchId;
                    accountInDb.Lien        = account.Lien;
                    _context.Update(account);
                    TempData["Success"] = "Update Successful";
                    return(RedirectToAction("Index"));
                }
            }
            var customer  = _customerContext.Get(userId);
            var branches  = _userContext.GetBranches().ToList();
            var viewModel = new NewCustomerAccountViewModel
            {
                Customer = customer,
                Branches = branches
            };

            return(View("CustomerAccountForm", viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Save(Loan loan)
        {
            var customerAccount = _customerAccContext.Get(Convert.ToInt32(Request.Form["customerId"]));
            var isLoanComplete  = _customerAccContext.CheckForLoanStatus(customerAccount);

            if (_accountTypeConfigContext.GetLoanConfig() != null && _bankConfigContext.GetConfig() != null)//check if bank and loan configurations are set
            {
                if (!isLoanComplete)
                {
                    TempData["Error"] = "Customer Has Unpaid Loan (Click Here To Review)";

                    var currentLoan = new Loan
                    {
                        CustomerAccount = customerAccount
                    };
                    return(View("LoanForm", currentLoan));
                }
                else
                {
                    var dInterestRate = _accountTypeConfigContext.GetLoanConfig().DInterestRate;

                    //Fill Loan Account Details
                    loan.Name              = customerAccount.AccountName;
                    loan.AccountNumber     = _customerAccContext.GenerateAccountNumber(customerAccount.CustomerId, "Loan");
                    loan.CustomerAccountId = customerAccount.Id;
                    loan.StartDate         = DateTime.Today;
                    loan.EndDate           = DateTime.Now.AddDays(loan.DurationInMonths * 30);
                    loan.Interest          = loan.LoanAmount * (dInterestRate / 100) *
                                             (Convert.ToDecimal(loan.DurationInMonths) / 12);
                    loan.InterestRemaining   = loan.Interest;
                    loan.InterestPayable     = loan.Interest / (loan.DurationInMonths * 30);
                    loan.LoanAmountRemaining = loan.LoanAmount; // debiting Loan Account
                    loan.LoanPayable         = loan.LoanAmount / (loan.DurationInMonths * 30);
                    loan.DayCount            = 0;
                    _context.Save(loan);


                    //create customer Loan Account
                    var customerLoanAcc = new CustomerAccount
                    {
                        CustomerId    = customerAccount.CustomerId,
                        AccountName   = customerAccount.AccountName,
                        AccountNumber = loan.AccountNumber,
                        BranchId      = customerAccount.BranchId,
                        Balance       = 0,
                        AccountType   = AccountType.Loan,
                        IsOpen        = true,
                        CreatedAt     = DateTime.Now,
                    };



                    _customerAccContext.CreditCustomer(customerAccount, loan.LoanAmount);
                    _customerAccContext.DebitCustomer(customerLoanAcc, loan.LoanAmount);

                    _customerAccContext.Save(customerLoanAcc);
                }

                TempData["Success"] = "Loan Taken Successfully";
                return(RedirectToAction("Index"));
            }
            TempData["ConfigError"] = "Setup Loan Configurations";

            var view = new Loan
            {
                CustomerAccount = customerAccount
            };

            return(View("LoanForm", view));
        }