Esempio n. 1
0
        public void AccountInterestRate()
        {
            var day           = financialDate.Day;
            var month         = financialDate.Month;
            var daysRemaining = 0;
            var savingsConfig = _savings.GetFirst();
            var currentConfig = _current.GetFirst();

            var savingsAccount = _customerAccount.GetByAccountType(AccountType.Savings);
            var currentAccount = _customerAccount.GetByAccountType(AccountType.Current);

            if (savingsAccount != null)
            {
                var     savingsInterestGl        = _glAccount.Get(savingsConfig.GlAccountId);
                var     savingsInterestPayableGl = _glAccount.Get(savingsConfig.SavingsInterestPayableGlId);
                decimal todaysInterest           = 0;

                foreach (var account in savingsAccount)
                {
                    daysRemaining = daysInMonth[month - 1] - day + 1;

                    decimal interestRemainingforTheMonth =
                        account.Balance * (savingsConfig.CreditInterestRate / 100) *
                        ((decimal)daysRemaining / daysInMonth[month - 1]);

                    if (daysRemaining != 0)
                    {
                        todaysInterest = interestRemainingforTheMonth / daysRemaining;
                    }

                    account.InterestGot += todaysInterest;

                    _post.DebitGlAccount(todaysInterest, savingsInterestGl);
                    _post.CreditGlAccount(todaysInterest, savingsInterestPayableGl);
                    _customerAccount.Save(account);
                }

                if (day == daysInMonth[month - 1])
                {
                    foreach (var account in savingsAccount)
                    {
                        _post.DebitGlAccount(account.InterestGot, savingsInterestPayableGl);
                        _post.CreditCustomerAccount(account.InterestGot, account.Id, account);

                        account.InterestGot = 0;
                        _customerAccount.Save(account);
                    }
                }
            }
            if (currentAccount != null)
            {
                var currentInterestGl        = _glAccount.Get(currentConfig.ExpenseGlAccountId);
                var currentInterestPayableGl = _glAccount.Get(currentConfig.CurrentInterestPayableGlId);

                var COTGl = _glAccount.Get(currentConfig.IncomeGlAccountId);

                foreach (var account in currentAccount)
                {
                    decimal todaysInterest = 0;
                    daysRemaining = daysInMonth[month - 1] - day + 1;

                    decimal interestRemainingforTheMonth =
                        account.Balance * (savingsConfig.CreditInterestRate / 100) *
                        ((decimal)daysRemaining / daysInMonth[month - 1]);
                    if (daysRemaining != 0)
                    {
                        todaysInterest = interestRemainingforTheMonth / daysRemaining;
                    }

                    account.InterestGot += todaysInterest;

                    _post.DebitGlAccount(todaysInterest, currentInterestGl);
                    _post.CreditGlAccount(todaysInterest, currentInterestPayableGl);
                    _customerAccount.Save(account);
                }

                if (day == daysInMonth[month - 1])
                {
                    foreach (var account in currentAccount)
                    {
                        //remove cot accrued first
                        _post.DebitCustomerAccount(account.CotAccured, account.Id, account);
                        _post.CreditGlAccount(account.CotAccured, COTGl);
                        account.CotAccured = 0;
                        _customerAccount.Save(account);

                        //add interest for current account
                        _post.DebitGlAccount(account.InterestGot, currentInterestPayableGl);
                        _post.CreditCustomerAccount(account.InterestGot, account.Id, account);

                        account.InterestGot = 0;

                        _customerAccount.Save(account);
                    }
                }
            }
        }