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

            ViewBag.Accounts = glAccountRepository.GetAll();
            try
            {
                using (ISession session = NHibernateHelper.Session)
                {
                    var updateConfig = session.Get <CurrentAccountConfig>(Id);
                    var oldentity    = session.Get <LoanAccountConfig>(Id);
                    updateConfig.CreditInterestRate = currentConfig.CreditInterestRate;
                    updateConfig.InterestExpenseGL  = currentConfig.InterestExpenseGL;
                    updateConfig.MinimumBalance     = currentConfig.MinimumBalance;
                    updateConfig.COT                    = currentConfig.COT;
                    updateConfig.COTIncomeGL            = currentConfig.COTIncomeGL;
                    updateConfig.CustomerCurrentAccount = currentConfig.CustomerCurrentAccount;
                    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 Create(CurrentAccountConfig currentConfig)
        {
            // var glAccountRepository = new Repository<GLAccount>();
            var glAccountRepository = unitOfWork.EntityRepository <GLAccount>();

            ViewBag.Accounts = glAccountRepository.GetAll();
            try
            {
                using (ISession session = NHibernateHelper.Session)
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        currentConfig.DateAdded   = DateTime.Now;
                        currentConfig.DateUpdated = DateTime.Now;
                        session.Save(currentConfig);
                        transaction.Commit();
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception exception)
            {
            }
            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 CurrentAccountConfigViewModel(CurrentAccountConfig config)
 {
     if (config == null)
     {
         Id = 0;
     }
     else
     {
         Id                  = config.Id;
         CInterestRate       = config.CInterestRate;
         InterestExpenseGl   = config.InterestExpenseGl;
         InterestExpenseGlId = config.InterestExpenseGlId;
         COTIncomeGl         = config.COTIncomeGl;
         COTIncomeGlId       = config.COTIncomeGlId;
         InterestPayableGlId = (int)config.InterestPayableGlId;
         COT                 = config.COT;
         MinBalance          = config.MinBalance;
         Status              = config.Status;
     }
 }
Пример #5
0
 public void UpdateCurrent(CurrentAccountConfig currentConfig)
 {
     _currentAccContext.Save(currentConfig);
 }
Пример #6
0
 public void SaveCurrent(CurrentAccountConfig config)
 {
     _currentAccContext.Add(config);
     _currentAccContext.Save(config);
 }
Пример #7
0
        public ActionResult SaveCurrentConfig(CurrentAccountConfig config)
        {
            var glAccount             = new GlAccount();
            var configInDb            = _context.GetCurrentConfig();
            var interestExpenseGlInDb = _glAccountContext.Get(config.InterestExpenseGlId);
            var cotIncomeGlInDb       = _glAccountContext.Get(config.COTIncomeGlId);

            if (config.Id == 0)                          //setup new configuration
            {
                interestExpenseGlInDb.IsAssigned = true; // Update the Interest gl account to is assigned
                cotIncomeGlInDb.IsAssigned       = true; // update the income gl account
                _glAccountContext.Update(glAccount);

                config.Status = true;               //change the status of configuration to true
                _context.SaveCurrent(config);
                TempData["Success"] = "Configurations Created Successfully";

                return(RedirectToAction("CurrentAccount"));
            }

            if (config.Id != 0) //update current configuration
            {
                configInDb.CInterestRate       = config.CInterestRate;
                configInDb.MinBalance          = config.MinBalance;
                configInDb.COT                 = config.COT;
                configInDb.InterestPayableGlId = config.InterestPayableGlId;

                if (config.InterestExpenseGlId == 0) //check if any of the  gl accounts are the same
                {
                    configInDb.InterestExpenseGlId = configInDb.InterestExpenseGlId;
                }
                else
                {
                    var oldInterestExpenseGlInDb = _glAccountContext.Get(configInDb.InterestExpenseGlId); // free up the old gl accounts that was assigned
                    oldInterestExpenseGlInDb.IsAssigned = false;
                    _glAccountContext.Update(glAccount);

                    configInDb.InterestExpenseGlId = config.InterestExpenseGlId;

                    interestExpenseGlInDb.IsAssigned = true; // Update the  new gl account to is assigned
                    _glAccountContext.Update(glAccount);
                }
                if (config.COTIncomeGlId == 0)
                {
                    configInDb.COTIncomeGlId = configInDb.COTIncomeGlId;
                }
                else
                {
                    var oldIncomeGlInDb = _glAccountContext.Get(configInDb.COTIncomeGlId);
                    oldIncomeGlInDb.IsAssigned = false;
                    _glAccountContext.Update(glAccount);


                    configInDb.COTIncomeGlId   = config.COTIncomeGlId;
                    cotIncomeGlInDb.IsAssigned = true;
                    _glAccountContext.Update(glAccount);
                }

                TempData["Success"] = "Configurations Updated Successfully";
                _context.UpdateCurrent(config);
                return(RedirectToAction("CurrentAccount"));
            }
            return(RedirectToAction("CurrentAccount"));
        }
        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();
        }