diff --git a/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs index 0de440aa..a2c68237 100644 --- a/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs @@ -809,6 +809,30 @@ namespace BMA.EHR.Application.Repositories.Reports if (period == null) throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var gender = (from r in await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Gender) + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + .Include(x => x.Request) + .ThenInclude(x => x.Period) + .Include(x => x.Request) + .ThenInclude(x => x.Organization) + .Include(x => x.RequestInsignia) + .ThenInclude(x => x.InsigniaType) + .ToListAsync() + where r.Request.Period == period + && r.IsApprove == true + && r.Status == "PENDING" + && r.RequestInsignia.InsigniaType != null + && r.RequestInsignia.InsigniaType.Name != "เหรียญบำเหน็จในราชการ" + select new + { + Male = r.Profile.Gender == null ? 0 : (r.Profile.Gender.Name == "ชาย" ? 1 : 0), + Female = r.Profile.Gender == null ? 0 : (r.Profile.Gender.Name == "หญิง" ? 1 : 0), + }) + .Distinct() + .ToList(); var data = (from r in await _dbContext.Set() .Include(x => x.Profile) .ThenInclude(x => x.Gender) @@ -833,8 +857,8 @@ namespace BMA.EHR.Application.Repositories.Reports ProfileId = r.Profile.Id, FullName = $"{r.Profile.Prefix?.Name}{r.Profile.FirstName} {r.Profile.LastName}", Gender = r.Profile.Gender == null ? null : r.Profile.Gender.Name, - Male = r.Profile.Gender == null ? 0 : (r.Profile.Gender.Name == "ชาย" ? 1 : 0), - Female = r.Profile.Gender == null ? 0 : (r.Profile.Gender.Name == "หญิง" ? 1 : 0), + Male = gender.Sum(x => x.Male), + Female = gender.Sum(x => x.Female), InsigniaId = r.RequestInsignia.Id, OCName = _organizationCommonRepository.GetOrganizationNameFullPath(r.Request.Organization.Id, false, false) })