Ejemplo n.º 1
0
        public ActionResult Create(Loan model)
        {
            TryUpdateModel(model);

            var currentLoans = _loansRepository.GetAll().Where(l => l.EGN == model.EGN).ToList();

            var currentLoansAmount = model.Amount;

            foreach (Loan oneLoan in currentLoans)
            {
                currentLoansAmount += oneLoan.Amount;
            }

            if (currentLoansAmount > 10000)
            {
                ModelState.AddModelError("Amount", "You cannot get loan, because all your loans exceed 10 000Lev BGN!");
                //ViewBag.ErrorMessage = "You cannot get loan, because all your loans exceed 10 000Lev BGN!";
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                model.ReceivedOn = DateTime.Now;

                _loansRepository.Save(model);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        //public void CurrentAccountCotRate()
        //{
        //    var month = financialDate.Month;
        //    var currentAccounts = _customerAccount.GetByAccountType(AccountType.Current);
        //    var currentConfig = _current.GetFirst();

        //    var COTGl = _glAccount.Get(currentConfig.IncomeGlAccountId);
        //    if (currentAccounts != null)
        //    {
        //        if (financialDate.Day == daysInMonth[month - 1])
        //        {
        //            foreach (var account in currentAccounts)
        //            {
        //                _post.DebitCustomerAccount(account.CotAccured, account.Id, account);
        //                _post.CreditGlAccount(account.CotAccured, COTGl);

        //                account.CotAccured = 0;
        //                _customerAccount.Save(account);
        //            }
        //        }
        //    }
        //}

        public void LoanAccountInterestRate()
        {
            var loanConfig = _loan.GetFirst();
            var loanAcct   = _loanAccount.GetAll();

            if (loanAcct != null)
            {
                var interestIncomeGlAccount = _glAccount.Get(loanConfig.IncomeGlAccountId);


                foreach (var account in loanAcct)
                {
                    var loanAccountId   = _customerAccount.GetByAccountNumber(account.AccountNumber);
                    var customerAccount = _customerAccount.Get(account.CustomerAccountId);

                    if (account.DurationInMonths * 30 != account.DaysCount)
                    {
                        //payment of interest
                        _post.CreditGlAccount(account.InterestDeduction, interestIncomeGlAccount);
                        _post.DebitCustomerAccount(account.InterestDeduction, account.CustomerAccountId, customerAccount);

                        account.InterestRemaining -= account.InterestDeduction;


                        //paying daily loan back
                        _post.DebitCustomerAccount(account.DailyLoanDeduction, account.CustomerAccountId, customerAccount);
                        _post.CreditCustomerAccount(account.DailyLoanDeduction, loanAccountId.Id, loanAccountId);

                        account.LoanBalance -= account.DailyLoanDeduction;

                        _loanAccount.Save(account);
                    }

                    if (account.DurationInMonths * 30 == account.DaysCount)
                    {
                        account.Status    = false;
                        account.DaysCount = 0;
                    }

                    //increases days if loan payment not reached
                    if (account.DurationInMonths * 30 != account.DaysCount)
                    {
                        account.DaysCount++;
                    }

                    _loanAccount.Update(account);
                }
            }
        }