Exemplo n.º 1
0
        /// <summary>
        /// Calculate interest rate for an account to a specific time
        /// The interest rate for Saving account is 6% monthly
        /// The interest rate for Home loan account is 3.99% annually
        /// </summary>
        /// <param name="account">Customer account</param>
        /// <param name="toDate">Calculate interest to this date</param>
        /// <returns>The added value</returns>
        public decimal CalculateInterestToDate(IAccount account, DateTimeOffset toDate)
        {
            if (!DoesAccountExists(account) || toDate.Date > DateTimeOffset.Now.Date)
            {
                return(0);
            }

            DateTimeOffset date = account.OpenedDate;

            IStatementRow lastTransactionLog = TransactionLog.Where(x => x.Account.AccountNumber == account.AccountNumber).OrderByDescending(x => x.Date).FirstOrDefault();

            if (lastTransactionLog != null)
            {
                date = lastTransactionLog.Date;
            }

            int days = (toDate - date.Date).Days;

            if (account.AccountNumber.StartsWith(LOAN_ACCOUNT_PREFIX))
            {
                return(((account.Balance * LOAN_RATE / days) * 100) / 365);
            }
            else
            {
                return(((account.Balance * SAVINGS_RATE / days) * 100) / 365);
            }
        }
Exemplo n.º 2
0
 private static void showTransactionInfo(IStatementRow transaction, ReadifyBank bank)
 {
     Console.WriteLine(string.Format("Transaction info: Account: {0}, Date: {1}, " +
                                     "Amount: {2}, Balance: {3}, Description: {4}",
                                     transaction.Account.AccountNumber, transaction.Date,
                                     transaction.Amount, transaction.Balance,
                                     transaction.Description));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Calculate interest rate for an account to a specific time
        /// The interest rate for Saving account is 6% monthly
        /// The interest rate for Home loan account is 3.99% annually
        /// </summary>
        /// <param name="account">Customer account</param>
        /// <param name="toDate">Calculate interest to this date</param>
        /// <returns>The added value</returns>
        public decimal CalculateInterestToDate(IAccount account, DateTimeOffset toDate)
        {
            if (!checkAcc(account) || isEarlier(toDate, DateTimeOffset.Now))
            {
                return(-1);
            }

            IStatementRow lastStatement = transactionLog.Where(x => x.Account.AccountNumber == account.AccountNumber).Last();

            int days = (toDate - lastStatement.Date).Days;

            if (account.AccountNumber.StartsWith("LN"))
            {
                return(days * INTEREST_RATE_LN / 365 * account.Balance);
            }
            else
            {
                return(days * INTEREST_RATE_SV / 365 * account.Balance);
            }
        }