Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Account"/> class.
 /// </summary>
 /// <param name="accountType">Type of the account.</param>
 /// <param name="interestCalculator">The interest calculator.</param>
 /// <param name="dateProvider">The date provider.</param>
 public Account(AccountType accountType,IInterestCalculator interestCalculator,IDateProvider dateProvider)
 {
     AccountType = accountType;
     transactionsList = new List<Transaction>();
     this.interestCalculator = interestCalculator;
     this.dateProvider = dateProvider;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Calcula el total de interés ganado en la cuenta.
        /// </summary>
        /// <returns>
        /// Interés ganado.
        /// </returns>
        public double GetInterestEarned()
        {
            double interestEarned;

            switch (this.Type)
            {
            case AccountType.Checking:
                _interestCalculator = new InterestCalculatorChecking();
                break;

            case AccountType.Savings:
                _interestCalculator = new InterestCalculatorSaving();
                break;

            case AccountType.MaxiSavings:
                _interestCalculator = new InterestCalculatorMaxiSaving();
                break;

            case AccountType.NewMaxiSavings:
                _interestCalculator = new InterestCalculatorNewMaxiSaving(this.LastWithdraw);
                break;
            }

            interestEarned = _interestCalculator.Calculate(Balance, this.DateCreate);
            return(interestEarned);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Account"/> class.
 /// </summary>
 /// <param name="accountType">Type of the account.</param>
 /// <param name="interestCalculator">The interest calculator.</param>
 /// <param name="dateProvider">The date provider.</param>
 public Account(AccountType accountType, IInterestCalculator interestCalculator, IDateProvider dateProvider)
 {
     AccountType             = accountType;
     transactionsList        = new List <Transaction>();
     this.interestCalculator = interestCalculator;
     this.dateProvider       = dateProvider;
 }
Exemplo n.º 4
0
 public RepaymentService(ILenderFileParser lenderFileParser, IInterestCalculator interestCalculator,
                         IRepaymentCalculator repaymentCalculator)
 {
     _lenderFileParser    = lenderFileParser;
     _interestCalculator  = interestCalculator;
     _repaymentCalculator = repaymentCalculator;
 }
Exemplo n.º 5
0
        public Workflow(ILogger logger,
                        ITwitterService twitterService,
                        IFootballAPIClient footballAPI,
                        IDatabaseOperations database,
                        ITweetBuilder tweetBuilder,
                        IInterestCalculator interestCalculator)
        {
            _logger             = logger;
            _twitterService     = twitterService;
            _footballAPI        = footballAPI;
            _database           = database;
            _tweetBuilder       = tweetBuilder;
            _interestCalculator = interestCalculator;

            _getMatchScoreFromAPIStep           = new GetMatchScoreFromAPI(_logger, _footballAPI);
            _getLastMatchCheckTimeStep          = new GetLastMatchCheckTimeFromDatabase(_logger, _database);
            _buildMatchTweetStep                = new BuildMatchTweet(_logger, _tweetBuilder);
            _getMatchesFromAPIStep              = new GetMatchesFromAPI(_logger, _footballAPI);
            _getMatchesToSearchFromDatabaseStep = new GetMatchesToSearchFromDatabase(_logger, _database);
            _getMatchStatsFromAPIStep           = new GetMatchStatsFromAPI(_logger, _footballAPI);
            _persistMatchesToDatabaseStep       = new PersistMatchesToDatabase(_logger, _database);
            _processMatchStatsStep              = new ProcessMatchStats(_logger, _interestCalculator);
            _sendMatchTweetStep           = new SendMatchTweet(_logger, _twitterService);
            _updateMatchTwitterStatusStep = new UpdateMatchTwitterStatus(_logger, _database);
        }
        public InterestController(
            IPersonService personService, ICardIssuerService cardIssuerService, IInterestCalculator interestCalculator
        )
        {
            this.personService = personService;
            this.cardIssuerService = cardIssuerService;

            this.interestCalculator = interestCalculator;
        }
Exemplo n.º 7
0
        public void ApplyInterestUpdatesTheBalance()
        {
            // Arange
            IInterestCalculator interestCalculator = Substitute.For <IInterestCalculator>();

            interestCalculator.Calculate().Returns(123);
            SavingsAccount savingsAccount = new SavingsAccount(interestCalculator);

            // Act
            savingsAccount.ApplyInterest();

            // Assert
            Assert.AreEqual(123, savingsAccount.Balance);
        }
 public ProcessMatchStats(ILogger logger, IInterestCalculator interestCalculator)
 {
     _logger             = logger;
     _interestCalculator = interestCalculator;
 }
 public PersonInterestCalculator(IInterestCalculator<Wallet> walletCalculator)
 {
     this.walletCalculator = walletCalculator ?? throw new ArgumentNullException(nameof(walletCalculator));
 }
 public WalletInterestCalculator(IInterestCalculator <CreditCard> creditCardInterestCalculator)
 {
     this.creditCardInterestCalculator = creditCardInterestCalculator ?? throw new ArgumentNullException(nameof(creditCardInterestCalculator));
 }
 public SavingsAccount(IInterestCalculator interestCalculator)
     : this(interestCalculator, null)
 {
 }
 public SavingsAccount(IInterestCalculator interestCalculator, IOverdraft overdraft)
 {
     _interestCalculator = interestCalculator;
     _overdraft          = overdraft;
 }
 public SavingsAccount(IInterestCalculator interestCalculator)
     : this(interestCalculator, null)
 {
 }
Exemplo n.º 14
0
 public void InjectCalculator(IInterestCalculator calc)
 {
     _calc = calc;
 }
 public void Init()
 {
     _interestCalculator = new InterestCalculator();
 }
Exemplo n.º 16
0
 public CreditCard(decimal balance, IInterestCalculator interestCalculator)
 {
     Balance            = balance;
     InterestCalculator = interestCalculator;
 }
 public SavingsAccount(IInterestCalculator interestCalculator, IOverdraft overdraft)
 {
     _interestCalculator = interestCalculator;
     _overdraft = overdraft;
 }
 public SavingsAccount(IInterestCalculator interestCalculator)
 {
     _interestCalculator = interestCalculator;
 }
Exemplo n.º 19
0
 public CreditCard(IInterestCalculator interestCalculator)
 {
     Balance            = 0;
     InterestCalculator = interestCalculator;
 }
Exemplo n.º 20
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime startDate    = ctlStartDate.Value.Date;
                DateTime endDate      = ctlEndDate.Value.Date;
                int      interestDays = endDate.Subtract(startDate).Days + 1;
                if (interestDays < 1)
                {
                    HostUI.ErrorMessageBox("Start date must be before end date.");
                    return;
                }
                IInterestCalculator calculator = (IInterestCalculator)cboInterestType.SelectedItem;
                if (calculator == null)
                {
                    HostUI.ErrorMessageBox("Please select an interest type.");
                    return;
                }
                string interestCatKey = GetInterestCategoryKey();
                if (interestCatKey == null)
                {
                    HostUI.ErrorMessageBox("Please select an interest category.");
                    return;
                }
                decimal annualRate;
                if (!decimal.TryParse(txtAnnualRate.Text, out annualRate))
                {
                    HostUI.ErrorMessageBox("Please enter a valid annual interest rate, like \"9.5\" for 9.5%.");
                    return;
                }

                // Compute daily balances from all selected registers
                decimal   startingBalance = 0M;
                decimal[] dailyTotals     = new decimal[interestDays];
                foreach (ListViewItem itm in lvwRegisters.CheckedItems)
                {
                    Register reg = (Register)itm.Tag;
                    foreach (BaseTrx baseTrx in new RegIterator <BaseTrx>(reg))
                    {
                        if (!baseTrx.IsFake && ((baseTrx is BankTrx) || (baseTrx is ReplicaTrx)))
                        {
                            if (baseTrx.TrxDate < startDate)
                            {
                                startingBalance += baseTrx.Amount;
                            }
                            else if (baseTrx.TrxDate <= endDate)
                            {
                                dailyTotals[baseTrx.TrxDate.Subtract(startDate).Days] += baseTrx.Amount;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                decimal[] dailyBalances    = new decimal[interestDays];
                decimal   prevBalance      = startingBalance;
                decimal   sumDailyBalances = 0M;
                for (int i = 0; i < interestDays; i++)
                {
                    dailyBalances[i]  = prevBalance + dailyTotals[i];
                    sumDailyBalances += dailyBalances[i];
                    prevBalance       = dailyBalances[i];
                }

                // Calculate interest
                decimal annualRateFraction = annualRate / 100M;
                decimal avgDailyBal        = Math.Round(sumDailyBalances / interestDays, 2);
                decimal totalInterest      = Math.Round(calculator.Calculate(startDate, dailyBalances, annualRateFraction), 2);
                string  memo = calculator.Memo(annualRateFraction, avgDailyBal);

                // Create bank trx in current register
                BankTrx  interestTrx    = new BankTrx(HostUI.GetCurrentRegister());
                DateTime dummy          = DateTime.MinValue;
                string   trxDescription = PersonalAcctExists ? "Interest:DIVIDE" : "Interest";
                interestTrx.NewStartNormal(true, "Inv", endDate, trxDescription, memo, BaseTrx.TrxStatus.Unreconciled,
                                           false, 0M, false, false, 0, "", "");
                interestTrx.AddSplit("", interestCatKey, "", "", Utilities.EmptyDate, Utilities.EmptyDate, "", "", totalInterest);
                if (!HostUI.AddNormalTrx(interestTrx, ref dummy, false, "Calculate Interest"))
                {
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                ErrorHandling.TopException(ex);
            }
        }
 public CalculateController(IInterestCalculator interestCalculator)
 {
     _interestCalculator = interestCalculator;
 }
Exemplo n.º 22
0
 public SavingsAccount(IInterestCalculator interestCalculator)
 {
     _interestCalculator = interestCalculator;
 }
 private InterestCalculatorStrategy(string type_of_calculator, IInterestCalculator interest_calculator)
 {
     dictionary.Add(type_of_calculator, interest_calculator);
 }
Exemplo n.º 24
0
 public InterestFactory(IInterestCalculator interestCalculator)
 {
     _interestCalculator = interestCalculator;
 }