public async Task <DepositContractDetailsModel> GetDepositContractDetailsAsync(Guid contractNumber) { var now = _currentDateTimeProvider.Now(); var query = from contract in _context.DepositContracts.Include(x => x.Customer) where !contract.Customer.IsDeleted where contract.ContractNumber == contractNumber join transaction in _context.Transactions.Where(x => x.CreatedAt <= now) on contract.ContractNumber equals transaction.ContractNumber into contractTransactions from transaction in contractTransactions.DefaultIfEmpty() select new { Contract = contract, Transaction = transaction }; var queryResult = await query.ToListAsync(); var deposit = queryResult .GroupBy( x => x.Contract.ContractNumber, (key, value) => new { value.FirstOrDefault()?.Contract, Transactions = value.Select(x => x.Transaction).Where(x => x != null).ToList() }) .SingleOrDefault(); if (deposit?.Contract == null) { return(null); } var depositDetails = _mapper.Map <DepositContractDetailsModel>(deposit.Contract); depositDetails.Transactions = _mapper.Map <List <TransactionReportModel> >(deposit.Transactions); return(depositDetails); }
public ActionResult <DateTime> Now() { var now = _currentDateTimeProvider.Now(); return(Ok(now)); }
private async Task <IList <Transaction> > ProcessDepositsAndLoansAsync() { var now = _currentDateTimeProvider.Now(); var today = _currentDateTimeProvider.Now().Date; var isLastDayOfMonth = DateTime.DaysInMonth(today.Year, today.Month) == today.Day; var bankDevelopmentFunds = await _context.Accounts .Where(x => x.Type == AccountType.BankDevelopmentFund) .ToDictionaryAsync(x => x.CurrencyId, x => x); // Process irrevocable deposits at ProgramEndDate, // process revocable deposits at ProgramEndDate and the last day of each month var depositContractsQuery = _context.DepositContracts .Include(x => x.DepositAccount) .Include(x => x.RegularAccount) .Include(x => x.LatestInterestTransaction) .Where(x => !x.IsCompleted && !x.IsRevoked && x.ProgramStartDate < today && x.ProgramEndDate >= today) .Where(x => x.DepositTypeId == (int)MainDepositType.Irrevocable && x.ProgramEndDate == today || x.DepositTypeId == (int)MainDepositType.Revocable && (x.ProgramEndDate == today || isLastDayOfMonth)); var depositContracts = (await depositContractsQuery.ToListAsync()) .GroupBy(x => x.DepositTypeId) .ToDictionary(x => x.Key, x => x.ToList()); var loanContractPaymentsToProcessLatestTransactionDate = today.AddDays(-_configuration.GetValue <int>("LoanTermDays")).Date; // If any cached loan contracts to process exist, take cached versions, not the ones from DB. var localLoanContracts = GetQueryForLoanContractsToProcess( _context.ChangeTracker.Entries <LoanContract>() .Where(x => x.State == EntityState.Modified) .Select(x => x.Entity) .AsQueryable(), loanContractPaymentsToProcessLatestTransactionDate, today).ToList(); var localLoanContractsIds = localLoanContracts.Select(x => x.ContractNumber).ToList(); var loadedLoanContracts = await GetQueryForLoanContractsToProcess(_context.LoanContracts, loanContractPaymentsToProcessLatestTransactionDate, today) .Where(x => !localLoanContractsIds.Contains(x.ContractNumber)) .ToListAsync(); var loanContracts = loadedLoanContracts.Union(localLoanContracts); var loanContractsDictionary = loanContracts .GroupBy(x => x.LoanTypeId) .ToDictionary(x => x.Key, x => x.ToList()); var transactions = new List <Transaction>(); if (depositContracts.TryGetValue((int)MainDepositType.Irrevocable, out var irrevocableDeposits)) { transactions.AddRange(ProcessIrrevocableDeposits(irrevocableDeposits, bankDevelopmentFunds, now)); } if (depositContracts.TryGetValue((int)MainDepositType.Revocable, out var revocableDeposits)) { transactions.AddRange(ProcessRevocableDeposits(revocableDeposits, bankDevelopmentFunds, now)); } if (loanContractsDictionary.TryGetValue((int)MainLoanType.Annuity, out var annuityLoans)) { transactions.AddRange(ProcessAnnuityLoans(annuityLoans, bankDevelopmentFunds, now)); } if (loanContractsDictionary.TryGetValue((int)MainLoanType.Differential, out var differentialLoans)) { transactions.AddRange(ProcessDifferentialLoans(differentialLoans, bankDevelopmentFunds, now)); } return(transactions); }
protected bool BeTodayDateOrLater(DateTime dateTime) { return(dateTime >= CurrentDateTimeProvider.Now().Date); }