public async Task AutoResolveMappingErrors(ScopeOptions scope, Guid commissionStatementId, Guid policyId) { var policy = await _context.Policy.FindAsync(policyId); var organisationQuery = ScopeQuery.GetOrganisationEntityQuery(_context, scope); var query = from commissionError in GetCommissionErrorEditQuery(scope) where commissionError.CommissionStatementId == commissionStatementId select commissionError; var errors = await query.ToListAsync(); foreach (var error in errors) { var policyNumbers = policy.NumberAliases.ToList(); policyNumbers.Add(policy.Number); if (!policyNumbers.Any(p => p.IgnoreCaseEquals(error.Data.PolicyNumber))) { continue; } error.ClientId = policy.ClientId; error.PolicyId = policyId; await ResolveMappingError(scope, error); } }
public async Task <PagedItems <Organisation> > GetOrganisations(OrganisationQueryOptions queryOptions) { var query = from organisation in ScopeQuery.GetOrganisationEntityQuery(_context, queryOptions.Scope) select new Organisation() { Id = organisation.Id, Name = organisation.Name, ApplicationIds = organisation.ApplicationIds, Config = organisation.Config, }; var pagedItems = new PagedItems <Organisation>(); if (queryOptions.BranchId.HasValue) { var branch = await _context.Branch.FirstOrDefaultAsync(b => b.Id == queryOptions.BranchId.Value); if (branch != null) { query = query.Where(o => o.Id == branch.OrganisationId); } } //Get total items pagedItems.TotalItems = await query.CountAsync(); //Ordering query = query.OrderBy(queryOptions.SortOptions.Column, queryOptions.SortOptions.Direction); //Paging pagedItems.Items = await query.TakePage(queryOptions.PageOptions.Number, queryOptions.PageOptions.Size).ToListAsync(); return(pagedItems); }
private IQueryable <OrganisationEntity> GetOrganisationEnitiyQuery(ScopeOptions scope) { var query = from organisation in ScopeQuery.GetOrganisationEntityQuery(_context, scope) select organisation; return(query); }
public async Task <Result> UpdateOrganisation(ScopeOptions scope, OrganisationEdit organisation) { var validator = new OrganisationValidator(_context, false, organisation.Id); var result = validator.Validate(organisation).GetResult(); if (!result.Success) { return(result); } //Only organisation scope if (scope.Scope == Scope.Branch || scope.Scope == Scope.User) { return(new Result()); } var entity = await ScopeQuery .GetOrganisationEntityQuery(_context, scope) .FirstOrDefaultAsync(o => o.Id == organisation.Id); if (entity == null) { return(new Result()); } entity = MapModelToEntity(organisation, entity); await _context.SaveChangesAsync(); return(result); }
private IQueryable <CommissionStatementEntity> GetCommissionStatementEntityQuery(ScopeOptions scope) { var organisationQuery = ScopeQuery.GetOrganisationEntityQuery(_context, scope); var query = from organisation in organisationQuery join commissionStatement in _context.CommissionStatement on organisation.Id equals commissionStatement.OrganisationId select commissionStatement; return(query); }
private IQueryable <CommissionStatementEdit> GetCommissionStatementEditQuery(ScopeOptions scope) { var organisationQuery = ScopeQuery.GetOrganisationEntityQuery(_context, scope); var query = from commissionStatement in GetCommissionStatementEntityQuery(scope) select new CommissionStatementEdit() { Id = commissionStatement.Id, CompanyId = commissionStatement.CompanyId, AmountIncludingVAT = commissionStatement.AmountIncludingVAT, VAT = commissionStatement.VAT, Date = commissionStatement.Date, Processed = commissionStatement.Processed, Notes = commissionStatement.Notes, }; return(query); }
public async Task <PagedCommissionStatements> GetCommissionStatements(CommissionStatementQueryOptions queryOptions) { var organisationQuery = ScopeQuery.GetOrganisationEntityQuery(_context, queryOptions.Scope); var query = from organisation in organisationQuery join commissionStatement in _context.CommissionStatement on organisation.Id equals commissionStatement.OrganisationId select commissionStatement; //Apply filters ---------------------------------------------------------------------------------------- if (queryOptions.CommissionStatementId.HasValue) { query = query.Where(c => c.Id == queryOptions.CommissionStatementId); } if (queryOptions.CompanyId.Any()) { query = query.Where(c => queryOptions.CompanyId.Contains(c.CompanyId)); } if (queryOptions.Processed.HasValue) { query = query.Where(c => c.Processed == queryOptions.Processed); } if (queryOptions.StartDate.HasValue) { query = query.Where(c => c.Date >= queryOptions.StartDate.Value.Date); } if (queryOptions.EndDate.HasValue) { query = query.Where(c => c.Date <= queryOptions.EndDate.Value.Date); } if (!string.IsNullOrWhiteSpace(queryOptions.Notes)) { query = query.Where(m => EF.Functions.Like(m.Notes, queryOptions.Notes)); } //------------------------------------------------------------------------------------------------------ var pagedItems = new PagedCommissionStatements(); //Get total items pagedItems.TotalItems = await query.CountAsync(); //Aggregations var userQuery = ScopeQuery.GetUserEntityQuery(_context, queryOptions.Scope); var commissionQuery = from user in userQuery join commission in _context.Commission on user.Id equals commission.UserId join commissionStatement in query on commission.CommissionStatementId equals commissionStatement.Id select new { CommissionStatementId = commission.CommissionStatementId, AmountIncludingVAT = commission.AmountIncludingVAT, VAT = commission.VAT, }; var aggQuery = from commission in commissionQuery select new { SumAmountIncludingVAT = commissionQuery.Select(c => (decimal?)c.AmountIncludingVAT).Sum(), SumVAT = commissionQuery.Select(c => (decimal?)c.VAT).Sum(), }; var aggregates = await aggQuery.FirstOrDefaultAsync(); if (aggregates != null) { pagedItems.SumAmountIncludingVAT = aggregates.SumAmountIncludingVAT.Value; pagedItems.SumVAT = aggregates.SumVAT.Value; } var modelQuery = from commissionStatement in query select new CommissionStatement() { Id = commissionStatement.Id, CompanyId = commissionStatement.CompanyId, AmountIncludingVAT = commissionStatement.AmountIncludingVAT, VAT = commissionStatement.VAT, Date = commissionStatement.Date, Processed = commissionStatement.Processed, Notes = commissionStatement.Notes, ActualAmountIncludingVAT = commissionQuery.Where(c => c.CommissionStatementId == commissionStatement.Id).Select(c => c.AmountIncludingVAT).Sum(), ActualVAT = commissionQuery.Where(c => c.CommissionStatementId == commissionStatement.Id).Select(c => c.VAT).Sum(), CommissionCount = commissionQuery.Where(c => c.CommissionStatementId == commissionStatement.Id).Count(), MappingErrorCount = commissionStatement.CommissionErrors.Count(), CompanyName = commissionStatement.Company.Name }; //Ordering modelQuery = modelQuery.OrderBy(queryOptions.SortOptions.Column, queryOptions.SortOptions.Direction); //Paging pagedItems.Items = await modelQuery.TakePage(queryOptions.PageOptions.Number, queryOptions.PageOptions.Size).ToListAsync();; return(pagedItems); }