diff --git a/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs index eb4e982f..078cc2bb 100644 --- a/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs @@ -3,6 +3,7 @@ using BMA.EHR.Application.Responses; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.HR; using BMA.EHR.Domain.Models.Insignias; +using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Models.Retirement; using BMA.EHR.Domain.Shared; @@ -78,6 +79,27 @@ namespace BMA.EHR.Application.Repositories.Reports }; } + public async Task GetProfileInsignia(Guid id) + { + var profile = (from r in await _dbContext.Set() + .Include(x => x.Prefix) + .Include(x => x.Position) + .ToListAsync() + where r.Id == id + select new + { + FullName = $"{r.Prefix?.Name}{r.FirstName} {r.LastName}", + Position = r.Position == null ? "-" : r.Position.Name, + OCName = r.OcId == null ? "-" : _organizationCommonRepository.GetOrganizationNameFullPath(r.OcId.Value, false, false), + BirthDate = r.BirthDate.ToThaiFullDate().ToString().ToThaiNumber(), + }) + .FirstOrDefault(); + if (profile == null) + throw new Exception(GlobalMessages.DataNotFound); + + return profile; + } + //39-แบบ ขร1 บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ ข้าราชการ ชั้นสายสะพาย public async Task GetKhr1Report(Guid id) { @@ -268,9 +290,9 @@ namespace BMA.EHR.Application.Repositories.Reports ProfileId = r.Profile.Id, FullName = $"{r.Profile.Prefix?.Name}{r.Profile.FirstName} {r.Profile.LastName}", ShowProfileId = r.Profile.Id, - Type = r.Profile.PositionType?.Name, + Type = r.Profile.PositionType == null ? "-" : r.Profile.PositionType.Name, AcademicStanding = "", - Level = r.Profile.PositionLevel?.Name, + Level = r.Profile.PositionLevel == null ? "-" : r.Profile.PositionLevel.Name, DateStart = r.Profile.DateStart == null ? null : r.Profile.DateStart.Value.ToThaiShortDate(), SalaryAmount = r.Profile.Salaries.Count() == 0 ? 0 : r.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount, @@ -430,6 +452,44 @@ namespace BMA.EHR.Application.Repositories.Reports return data; } + //46-ประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา + public async Task GetHistorySalaryReport(Guid id) + { + var profile = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (profile == null) + throw new Exception(GlobalMessages.DataNotFound); + var positions = await _dbContext.Set() + .ToListAsync(); + var organizations = await _dbContext.Set() + .Include(x => x.Parent) + .ThenInclude(x => x.OrganizationOrganization) + .ToListAsync(); + + var data = (from r in await _dbContext.Set() + .Include(x => x.Profile) + .ToListAsync() + join p in positions on r.PositionId equals p.Id into pGroup + from p in pGroup.DefaultIfEmpty() + join o in organizations on r.OcId equals o.Id into oGroup + from o in oGroup.DefaultIfEmpty() + where r.Profile == profile + select new + { + DateTh = r.Date == null ? "-" : r.Date.Value.ToThaiShortDate().ToString().ToThaiNumber(), + Position = p.Name, + OCName = o.Parent == null ? "-" : (o.Parent.OrganizationOrganization == null ? "-" : o.Parent.OrganizationOrganization.Name), + Age = r.Date == null ? "-" : r.Date.Value.CalculateAgeStrV2(0, 0).ToThaiNumber(), + Amount = r.Amount == null ? null : r.Amount.Value.ToNumericText().ToThaiNumber(), + Date = r.Date, + }) + .Distinct() + .OrderBy(x => x.Date) + .ToList(); + + return data; + } + #endregion } }