Exemple #1
0
        public async Task <IAccountEstimationProjection> Get(AccountEstimation accountEstimation, bool showExpiredFunds = false)
        {
            var balance = await _currentBalanceRepository.Get(accountEstimation.EmployerAccountId);

            var commitments = _commitmentModelListBuilder.Build(accountEstimation.EmployerAccountId, accountEstimation.Apprenticeships);

            var actualProjections = await _accountProjectionRepository.Get(accountEstimation.EmployerAccountId);

            var employerCommitmentsModel = new EmployerCommitmentsModel
            {
                SendingEmployerTransferCommitments = commitments
                                                     .Where(m => m.FundingSource == Models.Payments.FundingSource.Transfer || m.FundingSource == 0)
                                                     .ToList(),
                LevyFundedCommitments = commitments
                                        .Where(m => m.FundingSource == Models.Payments.FundingSource.Levy)
                                        .ToList()
            };

            var levyFundsIn = actualProjections?.FirstOrDefault()?.LevyFundsIn ?? 0;

            var employerCommitments = new EmployerCommitments(accountEstimation.EmployerAccountId, employerCommitmentsModel);
            var accountEstimationProjectionCommitments = new AccountEstimationProjectionCommitments(employerCommitments, actualProjections);

            return(new AccountEstimationProjection(new Account(accountEstimation.EmployerAccountId, balance.Amount, levyFundsIn, balance.TransferAllowance, balance.RemainingTransferBalance), accountEstimationProjectionCommitments, _dateTimeService, showExpiredFunds));
        }
        public async Task RefreshCurrentBalance(long accountId)
        {
            var currentBalance = await _currentBalanceRepository.Get(accountId);

            if (!await currentBalance.RefreshBalance())
            {
                return;
            }
            await _currentBalanceRepository.Store(currentBalance);
        }
Exemple #3
0
        public async Task <AccountProjection> InitialiseProjection(long employerAccountId)
        {
            var levy = await _levyDataSession.GetLatestLevyAmount(employerAccountId);

            if (levy < 0)
            {
                levy = await _levyDataSession.GetLatestPositiveLevyAmount(employerAccountId);
            }

            var balance = await _currentBalanceRepository.Get(employerAccountId);

            return(new AccountProjection(new Account(employerAccountId, balance.Amount, levy, balance.TransferAllowance, balance.TransferAllowance), balance.EmployerCommitments));
        }
        public async Task Handle(GenerateAccountProjectionCommand message)
        {
            _logger.Debug($"Getting balances for account: {message.EmployerAccountId}");
            _telemetry.AddEmployerAccountId(message.EmployerAccountId);
            var currentBalance = await _currentBalanceRepository.Get(message.EmployerAccountId);


            var refreshBalance = await _accountProjectionService.GetOriginalProjectionSource(message.EmployerAccountId,
                                                                                             message.ProjectionSource) == ProjectionSource.PaymentPeriodEnd ? currentBalance.RefreshBalance(true, true) : currentBalance.RefreshBalance(true);

            if (!await refreshBalance)
            {
                _telemetry.TrackEvent("Account Balance Already Refreshed");
                _logger.Warn($"Failed to refresh the account balance for account {message.EmployerAccountId}.  It's possible the account has been refreshed recently.");
                return;
            }
            await _currentBalanceRepository.Store(currentBalance);

            _telemetry.TrackEvent("Refreshed Account Balance");
            _logger.Info($"Finished updating recorded balance for account: {message.EmployerAccountId}");
        }