public ActionResult Edit(int Id, LoanAccountConfig loanConfig)
        {
            var glAccountRepository = new Repository <GLAccount>();

            ViewBag.Accounts = glAccountRepository.GetAll();
            try
            {
                using (ISession session = NHibernateHelper.Session)
                {
                    var updateConfig = session.Get <LoanAccountConfig>(Id);
                    var oldentity    = session.Get <LoanAccountConfig>(Id);
                    updateConfig.InterestIncomeGL  = loanConfig.InterestIncomeGL;
                    updateConfig.DebitInterestRate = loanConfig.DebitInterestRate;
                    updateConfig.LoanGL            = loanConfig.LoanGL;
                    updateConfig.DateAdded         = oldentity.DateAdded;
                    updateConfig.DateUpdated       = DateTime.Now;

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(updateConfig);
                        transaction.Commit();
                    }
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                //return View();
            }
            return(View());
        }
        public ActionResult CloseBusiness()
        {
            //TODO: check for null pointer
            var eod = eodRepo.GetById(1);

            if (eod != null)
            {
                if (!eod.IsOpen)
                {
                    ViewBag.IsBusinessClosed      = true;
                    ViewBag.BusinessClosedMessage = "Business is Closed already!!";
                }
                else
                {
                    ViewBag.IsBusinessClosed = false;
                    SavingAccountConfig  savingsConfig        = savingsAccConfigRepo.GetById(1);
                    CurrentAccountConfig currentAccountConfig = currentAccConfigRepo.GetById(1);
                    LoanAccountConfig    loansConfig          = loanAccConfigRepo.GetById(1);
                    if (savingsConfig == null || currentAccountConfig == null || loansConfig == null)
                    {
                        ViewBag.IsAllAccountsConfigured = false;
                        if (savingsConfig == null)
                        {
                            ViewBag.IsSavingsConfigured = false;
                        }
                        else
                        {
                            ViewBag.IsSavingsConfigured = true;
                        }
                        if (currentAccountConfig == null)
                        {
                            ViewBag.IsCurrentAccountConfigured = false;
                        }
                        else
                        {
                            ViewBag.IsCurrentAccountConfigured = true;
                        }
                        if (loansConfig == null)
                        {
                            ViewBag.IsLoanConfigured = false;
                        }
                        else
                        {
                            ViewBag.IsLoanConfigured = true;
                        }
                    }
                    else
                    {
                        ViewBag.IsAllAccountsConfigured = true;
                    }
                }
            }
            else
            {
                ViewBag.IsBusinessClosed = false;
            }

            ViewBag.CurrentFinancialDate = eodRepo.GetById(1).FinancialDate.ToString("dd, MMMM, yyyy");
            return(View(eod));
        }
 public LoanAccountConfigViewModel(LoanAccountConfig config)
 {
     if (config == null)
     {
         Id = 0;
     }
     else
     {
         Id                 = config.Id;
         DInterestRate      = config.DInterestRate;
         InterestIncomeGl   = config.InterestIncomeGl;
         InterestIncomeGlId = config.InterestIncomeGlId;
         Status             = config.Status;
     }
 }
Exemple #4
0
        public ActionResult SaveLoanConfig(LoanAccountConfig config)
        {
            var interestIncomeGl     = new GlAccount();
            var configInDb           = _context.GetLoanConfig();
            var interestIncomeGlInDb = _glAccountContext.Get(config.InterestIncomeGlId);

            if (config.Id == 0)                         //setup new configuration
            {
                interestIncomeGlInDb.IsAssigned = true; // Update the gl account to is assigned
                _glAccountContext.Update(interestIncomeGl);

                config.Status = true;
                _context.SaveLoan(config);
                TempData["Success"] = "Configurations Created Successfully";

                return(RedirectToAction("LoanAccount"));
            }

            if (config.Id != 0) //update current configuration
            {
                configInDb.DInterestRate = config.DInterestRate;
                if (config.InterestIncomeGlId == 0) //check if gl account is the same
                {
                    configInDb.InterestIncomeGl = configInDb.InterestIncomeGl;
                }
                else
                {
                    var oldGlAccountInDb = _glAccountContext.Get(configInDb.InterestIncomeGlId); // free up the old gl account that was assigned
                    oldGlAccountInDb.IsAssigned = false;
                    _glAccountContext.Update(interestIncomeGl);

                    configInDb.InterestIncomeGlId = config.InterestIncomeGlId;


                    interestIncomeGlInDb.IsAssigned = true; // Update the  new gl account to is assigned
                    _glAccountContext.Update(interestIncomeGl);
                }

                TempData["Success"] = "Configurations Updated Successfully";
                _context.UpdateLoan(config);
                return(RedirectToAction("LoanAccount"));
            }
            return(RedirectToAction("LoanAccount"));
        }
        public ActionResult Create(LoanAccountConfig loanConfig)
        {
            var glAccountRepository = new Repository <GLAccount>();

            ViewBag.Accounts = glAccountRepository.GetAll();
            try
            {
                using (ISession session = NHibernateHelper.Session)
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        loanConfig.DateAdded   = DateTime.Now;
                        loanConfig.DateUpdated = DateTime.Now;
                        session.Save(loanConfig);
                        transaction.Commit();
                    }
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception exception)
            {
            }
            return(View());
        }
 public void UpdateLoan(LoanAccountConfig loanConfig)
 {
     _loanAccContext.Save(loanConfig);
 }
 public void SaveLoan(LoanAccountConfig config)
 {
     _loanAccContext.Add(config);
     _loanAccContext.Save(config);
 }
        private void RunEOD(SavingAccountConfig savingsConfig, CurrentAccountConfig currentAccountConfig, LoanAccountConfig loansConfig)
        {
            var sac         = savingsAccConfigRepo.GetById(1);
            var cac         = currentAccConfigRepo.GetById(1);
            var lac         = loanAccConfigRepo.GetById(1);
            var cotIncomeGL = cac.COTIncomeGL;
            var currentInterestExpenseGL  = cac.InterestExpenseGL;
            var savingInterestExpenseGL   = sac.InterestExpenseGL;
            var loanInterestIncomeGL      = lac.InterestIncomeGL;
            var glAccountRepository       = new Repository <GLAccount>();
            var customerAccountRepository = new Repository <CustomerAccount>();
            var customerAccounts          = customerAccountRepository.GetAll().ToList();
            var loanAccountRepository     = new Repository <LoanAccount>();
            var loanAccounts     = loanAccountRepository.GetAll().ToList();
            var savingGLAccount  = sac.CustomerSavingAccount;
            var currentGLAccount = cac.CustomerCurrentAccount;
            var loanGLAccount    = lac.LoanGL;

            using (ISession session = NHibernateHelper.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    if (customerAccounts == null || cotIncomeGL == null || currentInterestExpenseGL == null ||
                        savingInterestExpenseGL == null || savingGLAccount == null || currentGLAccount == null)
                    {
                        throw new Exception("Create All GL Accounts and customer accounts");
                    }

                    foreach (var accounts in customerAccounts)
                    {
                        var acctType    = accounts.AccountType;
                        var acctBalance = accounts.AccountBalance;
                        var acctStatus  = accounts.AccountStatus;
                        var loanAccount = loanAccounts.Where(x => x.CustomerAccount.Id == accounts.Id).FirstOrDefault();
                        if (acctStatus == Status.Inactive.ToString())
                        {
                            break;
                        }
                        switch (acctType)
                        {
                        case AccountType.Savings:
                            if (acctStatus == Status.Inactive.ToString())
                            {
                                break;
                            }
                            else
                            {
                                if (acctBalance < sac.MinimumBalance)
                                {
                                    break;
                                }

                                var dailyRate = Math.Round((sac.CreditInterestRate / 360), 2);
                                var InterestOnSavingsAccount = Math.Round((acctBalance * dailyRate) / 100, 2);
                                acctBalance            += InterestOnSavingsAccount;
                                acctBalance            += InterestOnSavingsAccount;
                                accounts.AccountBalance = acctBalance;

                                /*glAccount to debit and credit
                                 * debit savingsMirror,current mirror account
                                 * credit InterestExpense
                                 */
                                savingGLAccount.AccountBalance         -= InterestOnSavingsAccount;
                                savingInterestExpenseGL.AccountBalance -= InterestOnSavingsAccount;
                            }
                            break;

                        case AccountType.Current:
                            if (acctStatus == Status.Inactive.ToString())
                            {
                                break;
                            }
                            else
                            {
                                if (acctBalance < cac.MinimumBalance)
                                {
                                    break;
                                }

                                var dailyRate = Math.Round(cac.CreditInterestRate / 360, 2);
                                var interestOnCurrentAccount = Math.Round((acctBalance * dailyRate) / 100);
                                acctBalance                              = acctBalance + interestOnCurrentAccount;
                                accounts.AccountBalance                  = acctBalance;
                                currentGLAccount.AccountBalance         -= interestOnCurrentAccount;
                                currentInterestExpenseGL.AccountBalance -= interestOnCurrentAccount;
                                cotIncomeGL.AccountBalance              += cac.COT;
                                currentGLAccount.AccountBalance         -= cac.COT;
                            }
                            break;

                        default:
                            break;
                        }
                        if (loanAccount != null)
                        {
                            if (lac == null)
                            {
                                throw new Exception("Please create loan Account configurations to complete EOD process");
                            }
                            if (loanInterestIncomeGL == null || loanGLAccount == null)
                            {
                                throw new Exception("Please Check creation of all loan gl accounts to enable properly documention of loan process");
                            }

                            var interestOnLoan       = (lac.DebitInterestRate * loanAccount.PrincipalAmount * loanAccount.Duration) / (360 * 100);
                            var loanTenureMths       = ((double)loanAccount.Duration / 30);
                            var mnthlyInterestOnLoan = interestOnLoan / loanTenureMths;
                            var dailyInterestOnLoan  = mnthlyInterestOnLoan / 30;
                            //Debit InterestReceivable
                            //interestReceivable.AccountBalance += dailyInterestOnLoan;
                            //Credit InterestIncome
                            loanInterestIncomeGL.AccountBalance += dailyInterestOnLoan;
                            var amountPayable = loanAccount.PrincipalAmount + interestOnLoan;
                            // if (loanAccount.LoanDueDate == businessStatus.FinancialDate)
                            {
                                if (accounts.AccountBalance < amountPayable)
                                {
                                    //Debit Income(Interest Income)
                                    loanGLAccount.AccountBalance -= interestOnLoan;
                                }
                                else
                                {
                                    accounts.AccountBalance -= amountPayable;
                                    //  loanGLAccount.AccountBalance -= loanAccount.PrincipalAmount;
                                }
                            }
                        }

                        glAccountRepository.Update(cac.CustomerCurrentAccount, cac.CustomerCurrentAccount.Id);
                        glAccountRepository.Update(sac.CustomerSavingAccount, sac.CustomerSavingAccount.Id);
                        glAccountRepository.Update(lac.LoanGL, lac.LoanGL.Id);
                        glAccountRepository.Update(cac.COTIncomeGL, cac.COTIncomeGL.Id);
                        glAccountRepository.Update(cac.InterestExpenseGL, cac.InterestExpenseGL.Id);
                        glAccountRepository.Update(sac.InterestExpenseGL, sac.InterestExpenseGL.Id);
                        //accounts updated
                    }
                    var eod = eodRepo.GetById(1);
                    eod.IsOpen        = false;
                    eod.FinancialDate = eodRepo.GetById(1).FinancialDate;
                    var newFinDate = eod.FinancialDate.AddDays(1);
                    eod.FinancialDate = newFinDate;
                    eodRepo.Update(eod, eod.Id);
                    //eod updated
                }
            }
        }
        public ActionResult CloseBusiness(int?id)
        {
            var eod = eodRepo.GetById(1);

            if (!eod.IsOpen == true)
            {
                ViewBag.IsBusinessClosed      = true;
                ViewBag.BusinessClosedMessage = "Business is Closed already!!";
            }
            else
            {
                ViewBag.IsBusinessClosed = false;
                SavingAccountConfig  savingsConfig        = savingsAccConfigRepo.GetById(1);//
                CurrentAccountConfig currentAccountConfig = currentAccConfigRepo.GetById(1);
                LoanAccountConfig    loansConfig          = loanAccConfigRepo.GetById(1);
                if (savingsConfig == null || currentAccountConfig == null || loansConfig == null)
                {
                    ViewBag.IsAllAccountsConfigured = false;
                    if (savingsConfig == null)
                    {
                        ViewBag.IsSavingsConfigured = false;
                    }
                    else
                    {
                        ViewBag.IsSavingsConfigured = true;
                    }
                    if (currentAccountConfig == null)
                    {
                        ViewBag.IsCurrentAccountConfigured = false;
                    }
                    else
                    {
                        ViewBag.IsCurrentAccountConfigured = true;
                    }
                    if (loansConfig == null)
                    {
                        ViewBag.IsLoanConfigured = false;
                    }
                    else
                    {
                        ViewBag.IsLoanConfigured = true;
                    }
                }
                else
                {
                    ViewBag.IsAllAccountsConfigured = true;
                }
                if (ViewBag.IsAllAccountsConfigured)
                {
                    RunEOD(savingsConfig, currentAccountConfig, loansConfig);
                    eod.IsOpen                    = false;
                    eod.FinancialDate             = DateTime.Now;
                    ViewBag.CurrentFinancialDate  = eod.FinancialDate.ToString("dd,MMMM,yyyy");
                    MvcApplication.IsBusinessOpen = false;
                    ViewBag.IsBusinessClosed      = true;
                    ViewBag.BusinessClosedMessage = "Business was closed successfully";
                }
            }

            ViewBag.CurrentFinancialDate = eodRepo.GetById(1).FinancialDate.ToString("dd, MMMM, yyyy");
            return(RedirectToAction("Business", "EOD"));
            //return View();
        }
Exemple #10
0
 public double InterestAmount(LoanAccountConfig loanAccConfig, double amount, int duration)
 {
     return(Math.Round((amount * loanAccConfig.DebitInterestRate * duration) / (100 * 365), 2));
 }