public static string PostTeller(CustomerAccount account, GLAccount till, Double amt, PostingType pType, Configuration config) { string output = ""; switch (pType) { case PostingType.Deposit: CreditCustomerAccount(account, amt); GLPostingLogic.DebitGL(till, amt); output = "success"; break; case PostingType.Withdrawal: if (account.AccountType == AccountType.Savings) { if (account.Balance >= config.SavingsMinimumBalance + amt) { if (till.Balance >= amt) { GLPostingLogic.CreditGL(till, amt); DebitCustomerAccount(account, amt); output = "success"; account.SavingsWithdrawalCount++; } else { output = "Insufficient fund in the Till account"; } } else { output = "insufficient Balance in Customer's account, cannot withdraw!"; } } else if (account.AccountType == AccountType.Current) { if (account.Balance >= config.CurrentMinimumBalance + amt) { if (till.Balance >= amt) { GLPostingLogic.CreditGL(till, amt); DebitCustomerAccount(account, amt); output = "success"; Double x = (amt) / 1000; Double charge = (int)x * config.CurrentCOT; account.DailyCOTAccrued += charge; } else { output = "Insufficient fund in the Till account"; } } else { output = "insufficient Balance in Customer's account, cannot withdraw!"; } } else //for loan { output = "Please select a valid account"; } break; //break; default: break; } //end switch return(output); } //
public void ComputeSavingsInterestAccrued() { int presentDay = config.FinancialDate.Day; int presentMonth = config.FinancialDate.Month; int daysRemaining = 0; var accounts = context.CustomerAccounts.Where(a => a.AccountType == AccountType.Savings).ToList(); foreach (var account in accounts) { daysRemaining = daysInMonth[presentMonth - 1] - presentDay + 1; double interestRemainingForTheMonth = account.Balance * config.SavingsCreditInterestRate * daysRemaining / daysInMonth[presentMonth - 1]; //using I = PRT, where R is the rate per month. //calculate today's interest and add it to the account's dailyInterestAccrued double todaysInterest = interestRemainingForTheMonth / daysRemaining; account.DailyInterestAccrued += todaysInterest; //increments till month end. Disbursed if withdrawal limit is not exceeded GLPostingLogic.DebitGL(config.SavingsInterestExpenseGLAccount, todaysInterest); GLPostingLogic.CreditGL(config.SavingsInterestPayableGLAccount, todaysInterest); context.Entry(account).State = EntityState.Modified; context.Entry(config.SavingsInterestExpenseGLAccount).State = EntityState.Modified; context.Entry(config.SavingsInterestPayableGLAccount).State = EntityState.Modified; context.SaveChanges(); TransactionLogic.CreateTransaction(context, config.SavingsInterestExpenseGLAccount, todaysInterest, TransactionType.Debit); TransactionLogic.CreateTransaction(context, config.SavingsInterestPayableGLAccount, todaysInterest, TransactionType.Credit); } //monthly savings interest payment if (config.FinancialDate.Day == daysInMonth[presentMonth - 1]) // checks for month end to calculate the interest and pay it into the appropriate account. { bool customerIsCredited = false; foreach (var account in accounts) { GLPostingLogic.DebitGL(config.SavingsInterestPayableGLAccount, account.DailyInterestAccrued); //if the Withdrawal limit is not exceeded if (!(account.SavingsWithdrawalCount > 3)) //assuming the withdrawal limit is 3 { //Credit the customer ammount TellerPostingLogic.CreditCustomerAccount(account, account.DailyInterestAccrued); customerIsCredited = true; } else { GLPostingLogic.CreditGL(config.SavingsInterestExpenseGLAccount, account.DailyInterestAccrued); } account.SavingsWithdrawalCount = 0; //re-initialize to zero for the next month account.DailyInterestAccrued = 0; context.Entry(account).State = EntityState.Modified; context.Entry(config.SavingsInterestExpenseGLAccount).State = EntityState.Modified; context.Entry(config.SavingsInterestPayableGLAccount).State = EntityState.Modified; context.SaveChanges(); TransactionLogic.CreateTransaction(context, config.SavingsInterestPayableGLAccount, account.DailyInterestAccrued, TransactionType.Debit); if (customerIsCredited) { TransactionLogic.CreateTransaction(context, account, account.DailyInterestAccrued, TransactionType.Credit); } TransactionLogic.CreateTransaction(context, config.SavingsInterestExpenseGLAccount, account.DailyInterestAccrued, TransactionType.Credit); } } }