diff --git a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs index 857885fe..a78c2923 100644 --- a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs +++ b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs @@ -33,7 +33,7 @@ namespace BMA.EHR.Application.Repositories _documentService = documentService; _userProfileRepository = userProfileRepository; - _insigniaLists = _dbContext.Set().Include(x => x.InsigniaType).ToList(); + _insigniaLists = _dbContext.Set().AsNoTracking().Include(x => x.InsigniaType).ToList(); } public async Task> FindByNameAsync(string name) @@ -934,6 +934,7 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.OrderBy(x => x.Order).FirstOrDefault().Amount, PostionSalaryAmount = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : p.ProfileSalary!.OrderByDescending(x => x.Order).FirstOrDefault()!.PositionSalaryAmount, + ProfileInsignia = p.ProfileInsignia }); // check วันที่บรรจะต้องน้อยกว่า 29/5/ปี-5 @@ -941,6 +942,12 @@ namespace BMA.EHR.Application.Repositories where p.ProfileDateAppoint <= new DateTime(period.Year - 5, 5, 29) && p.LastInsigniaId == Guid.Parse("00000000-0000-0000-0000-000000000000") && p.PositionLevelName == "ปฏิบัติงาน" // ปฏิบัติงาน + && p.ProfileInsignia != null + && p.ProfileInsignia.Count > 0 + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("เบญจมาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) select p) .ToList() .Select(p => new InsigniaResultSet @@ -973,9 +980,13 @@ namespace BMA.EHR.Application.Repositories && p.PosLevel.PosLevelName == "ปฏิบัติงาน" && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("เบญจมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("เบญจมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("เบญจมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -1044,9 +1055,13 @@ namespace BMA.EHR.Application.Repositories && p.PosLevel.PosLevelName == "ปฏิบัติงาน" && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("จัตุรถาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("จัตุรถาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("จัตุรถาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -1110,9 +1125,13 @@ namespace BMA.EHR.Application.Repositories && p.PosLevel.PosLevelName == "ปฏิบัติงาน" && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("จัตุรถาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("จัตุรถาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("จัตุรถาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -1286,9 +1305,10 @@ namespace BMA.EHR.Application.Repositories && p.PosLevel.PosLevelName == "ชำนาญงาน" && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ตริตาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) select new { ProfileId = p.Id, @@ -1356,9 +1376,13 @@ namespace BMA.EHR.Application.Repositories && p.PosLevel.PosLevelName == "ชำนาญงาน" && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ตริตาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ตริตาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -1495,9 +1519,13 @@ namespace BMA.EHR.Application.Repositories && p.PosLevel.PosLevelName == "อาวุโส" && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -1567,9 +1595,13 @@ namespace BMA.EHR.Application.Repositories && p.PosLevel.PosLevelName == "อาวุโส" && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -1706,9 +1738,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "อาวุโส" || p.PosLevel.PosLevelName == "อาวุโส (เฉพาะสายงาน)") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -1778,9 +1814,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "อาวุโส" || p.PosLevel.PosLevelName == "อาวุโส (เฉพาะสายงาน)") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -1854,9 +1894,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "อาวุโส" || p.PosLevel.PosLevelName == "อาวุโส (เฉพาะสายงาน)") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -2017,7 +2061,11 @@ namespace BMA.EHR.Application.Repositories var s1 = (from p in allProfilesByRoot where p.PosType.PosTypeName == "วิชาการ" - + && p.ProfileInsignia.Count > 0 + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) select new { ProfileId = p.Id, @@ -2046,7 +2094,7 @@ namespace BMA.EHR.Application.Repositories .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) .OrderByDescending(x => x.Year) .FirstOrDefault().InsigniaId.Value).Name, - "ประถมาภรณ์ช้างเผือก"), + "ตริตาภรณ์มงกุฎไทย"), PositionLevel = p.PosLevel == null ? "" : p.PosLevel.PosLevelName, PositionType = p.PosType == null ? "" : p.PosType.PosTypeName, @@ -2137,9 +2185,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ชำนาญการ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ตริตาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ตริตาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -2212,9 +2264,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ชำนาญการ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -2288,9 +2344,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ชำนาญการ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -2308,8 +2368,8 @@ namespace BMA.EHR.Application.Repositories GetInsigniaById(p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId.Value).Id, Salary = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? null : p.ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)).OrderByDescending(x => x.Order).FirstOrDefault() != null ? - p.ProfileSalary.Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)).OrderByDescending(x => x.Order).FirstOrDefault().Amount : + p.ProfileSalary.Where(x => x.Date.Value <= new DateTime(period.Year - 5, 4, 29)).OrderByDescending(x => x.Order).FirstOrDefault() != null ? + p.ProfileSalary.Where(x => x.Date.Value <= new DateTime(period.Year - 5, 4, 29)).OrderByDescending(x => x.Order).FirstOrDefault().Amount : p.ProfileSalary.OrderBy(x => x.Order).FirstOrDefault().Amount, PosNo = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? "" : p.ProfileSalary!.OrderByDescending(x => x.Order).FirstOrDefault()!.PosNo, @@ -2449,9 +2509,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ชำนาญการพิเศษ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -2524,9 +2588,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ชำนาญการพิเศษ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -2673,9 +2741,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "เชี่ยวชาญ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -2749,9 +2821,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "เชี่ยวชาญ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -2826,9 +2902,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "เชี่ยวชาญ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -2987,9 +3067,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ทรงคุณวุฒิ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -3069,9 +3153,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ทรงคุณวุฒิ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id select new { ProfileId = p.Id, @@ -3153,9 +3241,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ทรงคุณวุฒิ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -3320,9 +3412,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ทรงคุณวุฒิ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -3402,9 +3498,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ทรงคุณวุฒิ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id select new { ProfileId = p.Id, @@ -3485,9 +3585,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ทรงคุณวุฒิ") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -3649,9 +3753,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ต้น") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -3725,9 +3833,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ต้น") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -3870,9 +3982,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "สูง") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -3947,9 +4063,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "สูง") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -4025,9 +4145,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "สูง") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id select new { ProfileId = p.Id, @@ -4186,9 +4310,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ต้น") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id select new { ProfileId = p.Id, @@ -4263,9 +4391,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ต้น") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -4340,9 +4472,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "ต้น") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id select new { ProfileId = p.Id, @@ -4470,9 +4606,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "สูง") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -4552,9 +4692,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "สูง") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาวชิรมงกุฎ").Id select new { ProfileId = p.Id, @@ -4634,9 +4778,13 @@ namespace BMA.EHR.Application.Repositories && (p.PosLevel.PosLevelName == "สูง") // อาวุโส && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year) - .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id) + .ToList() + .Count() == 0) + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + // .OrderByDescending(x => x.Year) + // .FirstOrDefault().InsigniaId.Value != GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id select new { ProfileId = p.Id, @@ -5288,7 +5436,7 @@ namespace BMA.EHR.Application.Repositories var result_candidate = new List(); - //if (ocId != Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3")) return result_candidate; + if (ocId != Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3")) return result_candidate; var type_coin = await GetCoinCandidate(periodId, ocId); var employee_type1 = await GetEmployeeInsignia_Type1(periodId, ocId); @@ -5793,6 +5941,7 @@ namespace BMA.EHR.Application.Repositories MarkDiscipline = h.MarkDiscipline, MarkLeave = h.MarkLeave, MarkRate = h.MarkRate, + Salary = h.Salary == null ? 0 : h.Salary.Value, // Docs = GetDocFile(h.Profile.Id), MatchingConditions = h.MatchingConditions == null || h.MatchingConditions == "" ? null : JsonConvert.DeserializeObject>(h.MatchingConditions) }) @@ -5804,15 +5953,15 @@ namespace BMA.EHR.Application.Repositories Id = h.Id, CitizenId = h.Profile.CitizenId, ProfileId = h.Profile.Id, - ProfileType = h.Profile.ProfileType, + ProfileType = "officer", + //ProfileType = h.Profile.ProfileType, FullName = $"{h.Profile.Prefix}{h.Profile.FirstName} {h.Profile.LastName}", Position = h.Profile.Position, PosNo = h.Profile.ProfileSalary == null || h.Profile.ProfileSalary.Count == 0 ? "" : h.Profile.ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().PosNo, Rank = h.Profile.PosLevel.PosLevelName, - Salary = h.Profile.ProfileSalary == null || h.Profile.ProfileSalary.Count == 0 ? "0" : - h.Profile.ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().Amount.ToString(), + Salary = h.Salary.ToString(), LastInsignia = h.Profile.ProfileInsignia == null || h.Profile.ProfileInsignia.Count == 0 ? "" : GetInsigniaById(h.Profile.ProfileInsignia.OrderByDescending(x => x.Year).FirstOrDefault().Id.Value).Name, RequestInsignia = h.RequestInsignia, diff --git a/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs index 689dd96c..dbb3e3c5 100644 --- a/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Reports/InsigniaReportRepository.cs @@ -10,6 +10,7 @@ using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Models.Retirement; using BMA.EHR.Domain.Shared; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Metadata; using Microsoft.EntityFrameworkCore; using System.Net; @@ -27,6 +28,9 @@ namespace BMA.EHR.Application.Repositories.Reports private readonly InsigniaPeriodsRepository _repositoryInsignia; private readonly string CRLF = "\r\n"; + private readonly UserProfileRepository _userProfileRepository; + private readonly IHttpContextAccessor _httpContextAccessor; + #endregion #region " Constructor and Destructor " @@ -35,18 +39,25 @@ namespace BMA.EHR.Application.Repositories.Reports OrganizationCommonRepository organizationCommonRepository, InsigniaPeriodsRepository repositoryInsignia, NotificationRepository repositoryNoti, - IWebHostEnvironment hostEnvironment) + IWebHostEnvironment hostEnvironment, + UserProfileRepository userProfileRepository, + IHttpContextAccessor httpContextAccessor) { _dbContext = dbContext; _hostingEnvironment = hostEnvironment; _repositoryNoti = repositoryNoti; _organizationCommonRepository = organizationCommonRepository; _repositoryInsignia = repositoryInsignia; + _userProfileRepository = userProfileRepository; + _httpContextAccessor = httpContextAccessor; } #endregion + private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"]; + #region " Methods " + // private string GetPositionByYear(string profileID, int year) // { // using (var ctx = new ApplicationDbContext()) @@ -149,7 +160,7 @@ 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) @@ -173,342 +184,338 @@ namespace BMA.EHR.Application.Repositories.Reports //39-แบบ ขร1 บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ ข้าราชการ ชั้นสายสะพาย public async Task GetKhr1Report(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (period == null) + throw new Exception(GlobalMessages.InsigniaPeriodNotFound); - //var data_insignia = await _dbContext.Set() - // //.Include(x => x.Profile) - // .Where(x => x.Request.Period == period) - // .Where(x => x.IsApprove == true) - // .Where(x => x.Status == "PENDING") - // .Where(x => x.RequestInsignia.InsigniaType != null) - // .Where(x => x.RequestInsignia.InsigniaType.Name == "ชั้นสายสะพาย") - // .Select(x => new - // { - // Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, - // RequestInsigniaName = x.RequestInsignia.Name, - // OcId = x.Request.Organization.Id - // }) - // .ToListAsync(); + var data_insignia = await _dbContext.Set() + //.Include(x => x.Profile) + .Where(x => x.Request.Period.Id == period.Id) + .Where(x => x.IsApprove == true) + .Where(x => x.Status == "PENDING") + .Where(x => x.RequestInsignia.InsigniaType != null) + .Where(x => x.RequestInsignia.InsigniaType.Name == "ชั้นสายสะพาย") + .Select(x => new + { + //Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, + Gendor = _userProfileRepository.GetOfficerProfileById(x.ProfileId, AccessToken).Gender ?? "", + RequestInsigniaName = x.RequestInsignia.Name, + OcId = x.Request.OrganizationId + }) + .ToListAsync(); - //var insignia = (from r in data_insignia - // group r by new { OcId = r.OcId } into g - // select new - // { - // RowNo = 1, - // DepartmentName = _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), - // G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "มหาปรมาภรณ์ช้างเผือก" ? 1 : 0), - // G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "มหาปรมาภรณ์ช้างเผือก" ? 1 : 0), - // G2Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "มหาวชิรมงกุฎ" ? 1 : 0), - // G2Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "มหาวชิรมงกุฎ" ? 1 : 0), - // G3Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ประถมาภรณ์ช้างเผือก" ? 1 : 0), - // G3Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ประถมาภรณ์ช้างเผือก" ? 1 : 0), - // G4Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ประถมาภรณ์มงกุฎไทย" ? 1 : 0), - // G4Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ประถมาภรณ์มงกุฎไทย" ? 1 : 0), - // G5Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), - // G5Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), - // Remark = "", - // }).ToList(); + var insignia = (from r in data_insignia + group r by new { OcId = r.OcId } into g + select new + { + RowNo = 1, + DepartmentName = _userProfileRepository.GetOc(g.Key.OcId, 0, AccessToken).Root,// _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), + G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "มหาปรมาภรณ์ช้างเผือก" ? 1 : 0), + G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "มหาปรมาภรณ์ช้างเผือก" ? 1 : 0), + G2Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "มหาวชิรมงกุฎ" ? 1 : 0), + G2Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "มหาวชิรมงกุฎ" ? 1 : 0), + G3Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ประถมาภรณ์ช้างเผือก" ? 1 : 0), + G3Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ประถมาภรณ์ช้างเผือก" ? 1 : 0), + G4Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ประถมาภรณ์มงกุฎไทย" ? 1 : 0), + G4Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ประถมาภรณ์มงกุฎไทย" ? 1 : 0), + G5Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), + G5Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), + Remark = "", + }).ToList(); - //return insignia; - - return new { }; + return insignia; } public async Task GetKhr1TotalReport(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (period == null) + throw new Exception(GlobalMessages.InsigniaPeriodNotFound); - //var data_insignia = await _dbContext.Set() - // .Include(x => x.Profile) - // .Where(x => x.Request.Period == period) - // .Where(x => x.IsApprove == true) - // .Where(x => x.Status == "PENDING") - // .Where(x => x.RequestInsignia.InsigniaType != null) - // .Where(x => x.RequestInsignia.InsigniaType.Name == "ชั้นสายสะพาย") - // .Select(x => new - // { - // Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, - // RequestInsigniaName = x.RequestInsignia.Name, - // OcId = x.Request.Organization.Id - // }) - // .ToListAsync(); + var data_insignia = await _dbContext.Set() + //.Include(x => x.Profile) + .Where(x => x.Request.Period.Id == period.Id) + .Where(x => x.IsApprove == true) + .Where(x => x.Status == "PENDING") + .Where(x => x.RequestInsignia.InsigniaType != null) + .Where(x => x.RequestInsignia.InsigniaType.Name == "ชั้นสายสะพาย") + .Select(x => new + { + //Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, + Gendor = _userProfileRepository.GetOfficerProfileById(x.ProfileId, AccessToken).Gender ?? "", + RequestInsigniaName = x.RequestInsignia.Name, + OcId = x.Request.OrganizationId + }) + .ToListAsync(); - //var insignia = (from r in data_insignia - // group r by new { OcId = r.OcId } into g - // select new - // { - // RowNo = 1, - // DepartmentName = _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), - // G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "มหาปรมาภรณ์ช้างเผือก" ? 1 : 0), - // G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "มหาปรมาภรณ์ช้างเผือก" ? 1 : 0), - // G2Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "มหาวชิรมงกุฎ" ? 1 : 0), - // G2Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "มหาวชิรมงกุฎ" ? 1 : 0), - // G3Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ประถมาภรณ์ช้างเผือก" ? 1 : 0), - // G3Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ประถมาภรณ์ช้างเผือก" ? 1 : 0), - // G4Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ประถมาภรณ์มงกุฎไทย" ? 1 : 0), - // G4Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ประถมาภรณ์มงกุฎไทย" ? 1 : 0), - // G5Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), - // G5Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), - // Remark = "", - // }).ToList(); + var insignia = (from r in data_insignia + group r by new { OcId = r.OcId } into g + select new + { + RowNo = 1, + DepartmentName = _userProfileRepository.GetOc(g.Key.OcId, 0, AccessToken).Root,// _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), + G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "มหาปรมาภรณ์ช้างเผือก" ? 1 : 0), + G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "มหาปรมาภรณ์ช้างเผือก" ? 1 : 0), + G2Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "มหาวชิรมงกุฎ" ? 1 : 0), + G2Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "มหาวชิรมงกุฎ" ? 1 : 0), + G3Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ประถมาภรณ์ช้างเผือก" ? 1 : 0), + G3Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ประถมาภรณ์ช้างเผือก" ? 1 : 0), + G4Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ประถมาภรณ์มงกุฎไทย" ? 1 : 0), + G4Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ประถมาภรณ์มงกุฎไทย" ? 1 : 0), + G5Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), + G5Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), + Remark = "", + }).ToList(); - //return new - //{ - // G1Male = insignia.Sum(x => x.G1Male), - // G1Female = insignia.Sum(x => x.G1Female), - // G2Male = insignia.Sum(x => x.G2Male), - // G2Female = insignia.Sum(x => x.G2Female), - // G3Male = insignia.Sum(x => x.G3Male), - // G3Female = insignia.Sum(x => x.G3Female), - // G4Male = insignia.Sum(x => x.G4Male), - // G4Female = insignia.Sum(x => x.G4Female), - // G5Male = insignia.Sum(x => x.G5Male), - // G5Female = insignia.Sum(x => x.G5Female), - // Remark = "", - //}; - - return new { }; + return new + { + G1Male = insignia.Sum(x => x.G1Male), + G1Female = insignia.Sum(x => x.G1Female), + G2Male = insignia.Sum(x => x.G2Male), + G2Female = insignia.Sum(x => x.G2Female), + G3Male = insignia.Sum(x => x.G3Male), + G3Female = insignia.Sum(x => x.G3Female), + G4Male = insignia.Sum(x => x.G4Male), + G4Female = insignia.Sum(x => x.G4Female), + G5Male = insignia.Sum(x => x.G5Male), + G5Female = insignia.Sum(x => x.G5Female), + Remark = "", + }; } //40-แบบ ขร2 บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ ข้าราชการ ชั้นต่ำกว่าสายสะพาย public async Task GetKhr2Report(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (period == null) + throw new Exception(GlobalMessages.InsigniaPeriodNotFound); - //var data_insignia = await _dbContext.Set() - // .Include(x => x.Profile) - // .Where(x => x.Request.Period == period) - // .Where(x => x.IsApprove == true) - // .Where(x => x.Status == "PENDING") - // .Where(x => x.RequestInsignia.InsigniaType != null) - // .Where(x => x.RequestInsignia.InsigniaType.Name == "ชั้นต่ำกว่าสายสะพาย") - // .Select(x => new - // { - // Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, - // RequestInsigniaName = x.RequestInsignia.Name, - // OcId = x.Request.Organization.Id - // }) - // .ToListAsync(); + var data_insignia = await _dbContext.Set() + //.Include(x => x.Profile) + .Where(x => x.Request.Period.Id == period.Id) + .Where(x => x.IsApprove == true) + .Where(x => x.Status == "PENDING") + .Where(x => x.RequestInsignia.InsigniaType != null) + .Where(x => x.RequestInsignia.InsigniaType.Name == "ชั้นต่ำกว่าสายสะพาย") + .Select(x => new + { + //Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, + Gendor = _userProfileRepository.GetOfficerProfileById(x.ProfileId, AccessToken).Gender ?? "", + RequestInsigniaName = x.RequestInsignia.Name, + OcId = x.Request.OrganizationId + }) + .ToListAsync(); - //var insignia = (from r in data_insignia - // group r by new { OcId = r.OcId } into g - // select new - // { - // RowNo = 1, - // DepartmentName = _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), - // G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ทวีติยาภรณ์ช้างเผือก" ? 1 : 0), - // G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ทวีติยาภรณ์ช้างเผือก" ? 1 : 0), - // G2Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ทวีติยาภรณ์มงกุฎไทย" ? 1 : 0), - // G2Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ทวีติยาภรณ์มงกุฎไทย" ? 1 : 0), - // G3Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ตริตาภรณ์ช้างเผือก" ? 1 : 0), - // G3Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ตริตาภรณ์ช้างเผือก" ? 1 : 0), - // G4Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ตริตาภรณ์มงกุฎไทย" ? 1 : 0), - // G4Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ตริตาภรณ์มงกุฎไทย" ? 1 : 0), - // G5Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "จัตุรถาภรณ์ช้างเผือก" ? 1 : 0), - // G5Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "จัตุรถาภรณ์ช้างเผือก" ? 1 : 0), - // G6Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "จัตุรถาภรณ์มงกุฎไทย" ? 1 : 0), - // G6Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "จัตุรถาภรณ์มงกุฎไทย" ? 1 : 0), - // G7Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เบญจมาภรณ์ช้างเผือก" ? 1 : 0), - // G7Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เบญจมาภรณ์ช้างเผือก" ? 1 : 0), - // G8Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เบญจมาภรณ์มงกุฎไทย" ? 1 : 0), - // G8Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เบญจมาภรณ์มงกุฎไทย" ? 1 : 0), - // G9Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), - // G9Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), - // Remark = "", - // }).ToList(); + var insignia = (from r in data_insignia + group r by new { OcId = r.OcId } into g + select new + { + RowNo = 1, + DepartmentName = _userProfileRepository.GetOc(g.Key.OcId, 0, AccessToken).Root,// _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), + G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ทวีติยาภรณ์ช้างเผือก" ? 1 : 0), + G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ทวีติยาภรณ์ช้างเผือก" ? 1 : 0), + G2Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ทวีติยาภรณ์มงกุฎไทย" ? 1 : 0), + G2Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ทวีติยาภรณ์มงกุฎไทย" ? 1 : 0), + G3Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ตริตาภรณ์ช้างเผือก" ? 1 : 0), + G3Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ตริตาภรณ์ช้างเผือก" ? 1 : 0), + G4Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ตริตาภรณ์มงกุฎไทย" ? 1 : 0), + G4Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ตริตาภรณ์มงกุฎไทย" ? 1 : 0), + G5Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "จัตุรถาภรณ์ช้างเผือก" ? 1 : 0), + G5Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "จัตุรถาภรณ์ช้างเผือก" ? 1 : 0), + G6Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "จัตุรถาภรณ์มงกุฎไทย" ? 1 : 0), + G6Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "จัตุรถาภรณ์มงกุฎไทย" ? 1 : 0), + G7Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เบญจมาภรณ์ช้างเผือก" ? 1 : 0), + G7Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เบญจมาภรณ์ช้างเผือก" ? 1 : 0), + G8Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เบญจมาภรณ์มงกุฎไทย" ? 1 : 0), + G8Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เบญจมาภรณ์มงกุฎไทย" ? 1 : 0), + G9Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), + G9Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), + Remark = "", + }).ToList(); - //return insignia; - - return new { }; + return insignia; } public async Task GetKhr2TotalReport(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (period == null) + throw new Exception(GlobalMessages.InsigniaPeriodNotFound); - //var data_insignia = await _dbContext.Set() - // .Include(x => x.Profile) - // .Where(x => x.Request.Period == period) - // .Where(x => x.IsApprove == true) - // .Where(x => x.Status == "PENDING") - // .Where(x => x.RequestInsignia.InsigniaType != null) - // .Where(x => x.RequestInsignia.InsigniaType.Name == "ชั้นต่ำกว่าสายสะพาย") - // .Select(x => new - // { - // Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, - // RequestInsigniaName = x.RequestInsignia.Name, - // OcId = x.Request.Organization.Id - // }) - // .ToListAsync(); + var data_insignia = await _dbContext.Set() + //.Include(x => x.Profile) + .Where(x => x.Request.Period.Id == period.Id) + .Where(x => x.IsApprove == true) + .Where(x => x.Status == "PENDING") + .Where(x => x.RequestInsignia.InsigniaType != null) + .Where(x => x.RequestInsignia.InsigniaType.Name == "ชั้นต่ำกว่าสายสะพาย") + .Select(x => new + { + //Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, + Gendor = _userProfileRepository.GetOfficerProfileById(x.ProfileId, AccessToken).Gender ?? "", + RequestInsigniaName = x.RequestInsignia.Name, + OcId = x.Request.OrganizationId + }) + .ToListAsync(); - //var insignia = (from r in data_insignia - // group r by new { OcId = r.OcId } into g - // select new - // { - // RowNo = 1, - // DepartmentName = _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), - // G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ทวีติยาภรณ์ช้างเผือก" ? 1 : 0), - // G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ทวีติยาภรณ์ช้างเผือก" ? 1 : 0), - // G2Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ทวีติยาภรณ์มงกุฎไทย" ? 1 : 0), - // G2Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ทวีติยาภรณ์มงกุฎไทย" ? 1 : 0), - // G3Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ตริตาภรณ์ช้างเผือก" ? 1 : 0), - // G3Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ตริตาภรณ์ช้างเผือก" ? 1 : 0), - // G4Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ตริตาภรณ์มงกุฎไทย" ? 1 : 0), - // G4Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ตริตาภรณ์มงกุฎไทย" ? 1 : 0), - // G5Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "จัตุรถาภรณ์ช้างเผือก" ? 1 : 0), - // G5Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "จัตุรถาภรณ์ช้างเผือก" ? 1 : 0), - // G6Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "จัตุรถาภรณ์มงกุฎไทย" ? 1 : 0), - // G6Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "จัตุรถาภรณ์มงกุฎไทย" ? 1 : 0), - // G7Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เบญจมาภรณ์ช้างเผือก" ? 1 : 0), - // G7Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เบญจมาภรณ์ช้างเผือก" ? 1 : 0), - // G8Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เบญจมาภรณ์มงกุฎไทย" ? 1 : 0), - // G8Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เบญจมาภรณ์มงกุฎไทย" ? 1 : 0), - // G9Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), - // G9Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), - // Remark = "", - // }).ToList(); + var insignia = (from r in data_insignia + group r by new { OcId = r.OcId } into g + select new + { + RowNo = 1, + DepartmentName = _userProfileRepository.GetOc(g.Key.OcId, 0, AccessToken).Root,// _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), + G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ทวีติยาภรณ์ช้างเผือก" ? 1 : 0), + G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ทวีติยาภรณ์ช้างเผือก" ? 1 : 0), + G2Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ทวีติยาภรณ์มงกุฎไทย" ? 1 : 0), + G2Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ทวีติยาภรณ์มงกุฎไทย" ? 1 : 0), + G3Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ตริตาภรณ์ช้างเผือก" ? 1 : 0), + G3Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ตริตาภรณ์ช้างเผือก" ? 1 : 0), + G4Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "ตริตาภรณ์มงกุฎไทย" ? 1 : 0), + G4Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "ตริตาภรณ์มงกุฎไทย" ? 1 : 0), + G5Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "จัตุรถาภรณ์ช้างเผือก" ? 1 : 0), + G5Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "จัตุรถาภรณ์ช้างเผือก" ? 1 : 0), + G6Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "จัตุรถาภรณ์มงกุฎไทย" ? 1 : 0), + G6Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "จัตุรถาภรณ์มงกุฎไทย" ? 1 : 0), + G7Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เบญจมาภรณ์ช้างเผือก" ? 1 : 0), + G7Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เบญจมาภรณ์ช้างเผือก" ? 1 : 0), + G8Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เบญจมาภรณ์มงกุฎไทย" ? 1 : 0), + G8Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เบญจมาภรณ์มงกุฎไทย" ? 1 : 0), + G9Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), + G9Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), + Remark = "", + }).ToList(); - //return new - //{ - // G1Male = insignia.Sum(x => x.G1Male), - // G1Female = insignia.Sum(x => x.G1Female), - // G2Male = insignia.Sum(x => x.G2Male), - // G2Female = insignia.Sum(x => x.G2Female), - // G3Male = insignia.Sum(x => x.G3Male), - // G3Female = insignia.Sum(x => x.G3Female), - // G4Male = insignia.Sum(x => x.G4Male), - // G4Female = insignia.Sum(x => x.G4Female), - // G5Male = insignia.Sum(x => x.G5Male), - // G5Female = insignia.Sum(x => x.G5Female), - // G6Male = insignia.Sum(x => x.G6Male), - // G6Female = insignia.Sum(x => x.G6Female), - // G7Male = insignia.Sum(x => x.G7Male), - // G7Female = insignia.Sum(x => x.G7Female), - // G8Male = insignia.Sum(x => x.G8Male), - // G8Female = insignia.Sum(x => x.G8Female), - // G9Male = insignia.Sum(x => x.G9Male), - // G9Female = insignia.Sum(x => x.G9Female), - // Remark = "", - //}; - - return new { }; + return new + { + G1Male = insignia.Sum(x => x.G1Male), + G1Female = insignia.Sum(x => x.G1Female), + G2Male = insignia.Sum(x => x.G2Male), + G2Female = insignia.Sum(x => x.G2Female), + G3Male = insignia.Sum(x => x.G3Male), + G3Female = insignia.Sum(x => x.G3Female), + G4Male = insignia.Sum(x => x.G4Male), + G4Female = insignia.Sum(x => x.G4Female), + G5Male = insignia.Sum(x => x.G5Male), + G5Female = insignia.Sum(x => x.G5Female), + G6Male = insignia.Sum(x => x.G6Male), + G6Female = insignia.Sum(x => x.G6Female), + G7Male = insignia.Sum(x => x.G7Male), + G7Female = insignia.Sum(x => x.G7Female), + G8Male = insignia.Sum(x => x.G8Male), + G8Female = insignia.Sum(x => x.G8Female), + G9Male = insignia.Sum(x => x.G9Male), + G9Female = insignia.Sum(x => x.G9Female), + Remark = "", + }; } //41-แบบ ขร3 บัญชีรายชื่อข้าราชการผู้ขอพระราชทานเครื่องราชฯ public async Task GetKhr3Report(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (period == null) + throw new Exception(GlobalMessages.InsigniaPeriodNotFound); - //var data = (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 - // { - // InsigniaInitial = r.RequestInsignia.ShortName, - // InsigniaName = r.RequestInsignia.Name, - // 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), - // InsigniaId = r.RequestInsignia.Id, - // OCName = _organizationCommonRepository.GetOrganizationNameFullPath(r.Request.Organization.Id, false, false) - // }) - // .Distinct() - // .ToList(); + var data = (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 + { + InsigniaInitial = r.RequestInsignia.ShortName, + InsigniaName = r.RequestInsignia.Name, + ProfileId = r.ProfileId, + FullName = $"{_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).FirstName} {_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).LastName}", // $"{r.Profile.Prefix?.Name}{r.Profile.FirstName} {r.Profile.LastName}", + Gender = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender == null ? null : _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender, + Male = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender == null ? 0 : (_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender == "ชาย" ? 1 : 0), + Female = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender == null ? 0 : (_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender == "หญิง" ? 1 : 0), + InsigniaId = r.RequestInsignia.Id, + OCName = _userProfileRepository.GetOc(r.Request.OrganizationId, 0, AccessToken).Root, + // _organizationCommonRepository.GetOrganizationNameFullPath(r.Request.Organization.Id, false, false) + }) + .Distinct() + .ToList(); - //// loop to add temp row with 50 rows per page - //var insigniaList = data.Select(x => new { InsigniaId = x.InsigniaId, InsigniaInitial = x.InsigniaInitial, InsigniaName = x.InsigniaName }) - // .Distinct().ToList(); + // loop to add temp row with 50 rows per page + var insigniaList = data.Select(x => new { InsigniaId = x.InsigniaId, InsigniaInitial = x.InsigniaInitial, InsigniaName = x.InsigniaName }) + .Distinct().ToList(); - //var tmpOC = data.First().OCName; + var tmpOC = data.First().OCName; - //var sumData = (from x in data - // group x by x.InsigniaName into grp - // select new - // { - // InsigniaName = grp.Key, - // SumMale = grp.Sum(x => x.Male), - // SumFemale = grp.Sum(x => x.Female) - // }).ToList(); + var sumData = (from x in data + group x by x.InsigniaName into grp + select new + { + InsigniaName = grp.Key, + SumMale = grp.Sum(x => x.Male), + SumFemale = grp.Sum(x => x.Female) + }).ToList(); - //var ret = new List(); + var ret = new List(); - //foreach (var item in data) - //{ - // var p = new - // { - // InsigniaInitial = item.InsigniaInitial, - // InsigniaName = item.InsigniaName, - // ProfileId = item.ProfileId, - // FullName = item.FullName, - // Gender = item.Gender, - // Male = item.Male, - // Female = item.Female, - // InsigniaId = item.InsigniaId, - // OCName = item.OCName, - // SumMale = sumData.FirstOrDefault(x => x.InsigniaName == item.InsigniaName) == null ? 0 : sumData.FirstOrDefault(x => x.InsigniaName == item.InsigniaName)!.SumMale, - // SumFemale = sumData.FirstOrDefault(x => x.InsigniaName == item.InsigniaName) == null ? 0 : sumData.FirstOrDefault(x => x.InsigniaName == item.InsigniaName)!.SumFemale, - // }; - // ret.Add(p); - //} + foreach (var item in data) + { + var p = new + { + InsigniaInitial = item.InsigniaInitial, + InsigniaName = item.InsigniaName, + ProfileId = item.ProfileId, + FullName = item.FullName, + Gender = item.Gender, + Male = item.Male, + Female = item.Female, + InsigniaId = item.InsigniaId, + OCName = item.OCName, + SumMale = sumData.FirstOrDefault(x => x.InsigniaName == item.InsigniaName) == null ? 0 : sumData.FirstOrDefault(x => x.InsigniaName == item.InsigniaName)!.SumMale, + SumFemale = sumData.FirstOrDefault(x => x.InsigniaName == item.InsigniaName) == null ? 0 : sumData.FirstOrDefault(x => x.InsigniaName == item.InsigniaName)!.SumFemale, + }; + ret.Add(p); + } - //foreach (var ins in insigniaList) - //{ - // var count = data.Where(x => x.InsigniaId == ins.InsigniaId).Count(); - // var mod_val = count <= 50 ? 50 - count : count % 50.0; - // for (int i = 0; i < mod_val; i++) - // { - // var p = new - // { - // InsigniaInitial = ins.InsigniaInitial, - // InsigniaName = ins.InsigniaName, - // ProfileId = Guid.Parse("00000000-0000-0000-0000-000000000000"), - // FullName = "", - // Gender = "", - // Male = 0, - // Female = 0, - // InsigniaId = ins.InsigniaId, - // // OCName = "" - // OCName = tmpOC, - // SumMale = sumData.FirstOrDefault(x => x.InsigniaName == ins.InsigniaName) == null ? 0 : sumData.FirstOrDefault(x => x.InsigniaName == ins.InsigniaName)!.SumMale, - // SumFemale = sumData.FirstOrDefault(x => x.InsigniaName == ins.InsigniaName) == null ? 0 : sumData.FirstOrDefault(x => x.InsigniaName == ins.InsigniaName)!.SumFemale, - // }; - // ret.Add(p); - // } - //} + foreach (var ins in insigniaList) + { + var count = data.Where(x => x.InsigniaId == ins.InsigniaId).Count(); + var mod_val = count <= 50 ? 50 - count : count % 50.0; + for (int i = 0; i < mod_val; i++) + { + var p = new + { + InsigniaInitial = ins.InsigniaInitial, + InsigniaName = ins.InsigniaName, + ProfileId = Guid.Parse("00000000-0000-0000-0000-000000000000"), + FullName = "", + Gender = "", + Male = 0, + Female = 0, + InsigniaId = ins.InsigniaId, + // OCName = "" + OCName = tmpOC, + SumMale = sumData.FirstOrDefault(x => x.InsigniaName == ins.InsigniaName) == null ? 0 : sumData.FirstOrDefault(x => x.InsigniaName == ins.InsigniaName)!.SumMale, + SumFemale = sumData.FirstOrDefault(x => x.InsigniaName == ins.InsigniaName) == null ? 0 : sumData.FirstOrDefault(x => x.InsigniaName == ins.InsigniaName)!.SumFemale, + }; + ret.Add(p); + } + } - //return ret; + return ret; - return new { }; } public async Task GetKhr3ReportV2(Guid id) { @@ -628,295 +635,294 @@ namespace BMA.EHR.Application.Repositories.Reports //42-แบบ ขร4 บัญชีแสดงคุณสมบัติของข้าราชการซึ่งเสนอขอเครื่องราชฯ public async Task GetKhr4Report(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (period == null) + throw new Exception(GlobalMessages.InsigniaPeriodNotFound); - //var teacher_data = (from r in await _dbContext.Set() - // .Include(x => x.Profile) - // .ThenInclude(x => x.Salaries) - // .Include(x => x.Profile) - // .ThenInclude(x => x.Gender) - // .Include(x => x.Profile) - // .ThenInclude(x => x.Prefix) - // .Include(x => x.Profile) - // .ThenInclude(x => x.PositionType) - // .Include(x => x.Profile) - // .ThenInclude(x => x.PositionLevel) - // .Include(x => x.Request) - // .ThenInclude(x => x.Period) - // .Include(x => x.RequestInsignia) - // .ThenInclude(x => x.InsigniaType) - // .Include(x => x.Request) - // .ThenInclude(x => x.Organization) - // .ToListAsync() - // where r.Request.Period == period - // && r.IsApprove == true - // && r.Status == "PENDING" - // && r.RequestInsignia.InsigniaType != null - // && r.RequestInsignia.InsigniaType.Name != "เหรียญบำเหน็จในราชการ" - // select new - // { - // InsigniaInitial = r.RequestInsignia.ShortName, - // InsigniaName = r.RequestInsignia.Name, - // ProfileId = r.Profile.Id, - // CitizenId = r.Profile.CitizenId == null ? null : r.Profile.CitizenId.ToThaiNumber(), - // FullName = $"{r.Profile.Prefix?.Name}{r.Profile.FirstName} {r.Profile.LastName}", - // ShowProfileId = r.Profile.Id, - // Type = r.Profile.PositionType == null ? "-" : r.Profile.PositionType.Name, - // AcademicStanding = "", - // Level = r.Profile.PositionLevel == null ? "-" : r.Profile.PositionLevel.Name, - // DateStart = r.Profile.DateStart == null ? null : r.Profile.DateStart.Value.ToThaiShortDate().ToThaiNumber(), - // SalaryAmount = r.Profile.Salaries.Count() == 0 ? "-" : - // Convert.ToInt32(r.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount).ToNumericText().ToThaiNumber(), - // InsigniaRecv = "", - // InsigniaRecvDate = "", - // InsigniaRequest = r.RequestInsignia.ShortName, - // Remark = "", - // Position = r.Profile.Position?.Name + - // (r.Profile.PositionType == null ? null : " ประเภท" + r.Profile.PositionType?.Name) + - // (r.Profile.PositionLevel == null ? null : " สังกัด" + r.Profile.PositionLevel?.Name) + - // (r.Request.Organization == null ? null : " ระดับ" + CRLF + _organizationCommonRepository.GetOrganizationNameFullPath(r.Request.Organization.Id, false, false)) - // , - // OCName = _organizationCommonRepository.GetOrganizationNameFullPath(r.Request.Organization.Id, false, false) - // }) - // .Distinct() - // .ToList(); + var teacher_data = (from r in await _dbContext.Set() + //.Include(x => x.Profile) + //.ThenInclude(x => x.Salaries) + //.Include(x => x.Profile) + //.ThenInclude(x => x.Gender) + //.Include(x => x.Profile) + //.ThenInclude(x => x.Prefix) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionType) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionLevel) + .Include(x => x.Request) + .ThenInclude(x => x.Period) + .Include(x => x.RequestInsignia) + .ThenInclude(x => x.InsigniaType) + .Include(x => x.Request) + //.ThenInclude(x => x.Organization) + .ToListAsync() + where r.Request.Period == period + && r.IsApprove == true + && r.Status == "PENDING" + && r.RequestInsignia.InsigniaType != null + && r.RequestInsignia.InsigniaType.Name != "เหรียญบำเหน็จในราชการ" + select new + { + InsigniaInitial = r.RequestInsignia.ShortName, + InsigniaName = r.RequestInsignia.Name, + ProfileId = r.ProfileId, + CitizenId = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).CitizenId.ToThaiNumber(), // r.Profile.CitizenId == null ? null : r.Profile.CitizenId.ToThaiNumber(), + FullName = $"{_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Prefix}{_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).FirstName} {_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).LastName}", + // $"{r.Profile.Prefix?.Name}{r.Profile.FirstName} {r.Profile.LastName}", + ShowProfileId = r.ProfileId, + Type = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).PosType.PosTypeName, + AcademicStanding = "", + Level = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).PosLevel.PosLevelName, + DateStart = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).DateStart.Value.ToThaiShortDate().ToThaiNumber(), + SalaryAmount = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).ProfileSalary.Count() == 0 || + _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).ProfileSalary == null ? "-" : + Convert.ToInt32(_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().Amount).ToNumericText().ToThaiNumber(), + InsigniaRecv = "", + InsigniaRecvDate = "", + InsigniaRequest = r.RequestInsignia.ShortName, + Remark = "", + Position = (_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Position ?? "") + + (" ประเภท" + _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).PosType?.PosTypeName) + + (" ระดับ" + _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).PosLevel?.PosLevelName) + + (" สังกัด" + CRLF + _userProfileRepository.GetOc(r.Request.OrganizationId, 0, AccessToken).Root) + , + OCName = _userProfileRepository.GetOc(r.Request.OrganizationId, 0, AccessToken).Root, + }) + .Distinct() + .ToList(); - //// var insignia_data = (from r in await _dbContext.Set() - //// .Include(x => x.Profile) - //// .ThenInclude(x => x.Gender) - //// .Include(x => x.Profile) - //// .ThenInclude(x => x.Insignias) - //// .ThenInclude(x => x.Insignia) - //// .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 - //// { - //// InsigniaInitial = r.RequestInsignia.ShortName, - //// InsigniaName = r.RequestInsignia.Name, - //// ProfileId = r.Profile.Id, - //// CitizenId = r.Profile.CitizenId, - //// FullName = $"", - //// ShowProfileId = Guid.Parse("00000000-0000-0000-0000-000000000000"), - //// Type = "", - //// AcademicStanding = "", - //// Level = "", - //// DateStart = "", - //// SalaryAmount = new double?(0), - //// InsigniaRecv = r.Profile.Insignias.Count() == 0 ? null : - //// (r.Profile.Insignias.OrderByDescending(x => x.Year).FirstOrDefault().Insignia == null ? null : r.Profile.Insignias.OrderByDescending(x => x.Year).FirstOrDefault().Insignia.ShortName), - //// InsigniaRecvDate = r.Profile.Insignias.Count() == 0 ? null : - //// (r.Profile.Insignias.OrderByDescending(x => x.Year).FirstOrDefault().DateAnnounce == null ? null : r.Profile.Insignias.OrderByDescending(x => x.Year).FirstOrDefault().DateAnnounce.Value.ToThaiShortDate()), - //// InsigniaRequest = "", - //// Remark = "", - //// Position = "", - //// // Position = GetPositionByYear(r.Profile.Id, r.Request.Period.Year) + " ประเภท" + - //// // GetPositionTypeByYear(r.Profile.Id, r.Request.Period.Year) + " ระดับ" + - //// // GetPositionLevelByYear(r.Profile.Id, r.Request.Period.Year), - //// OCName = _organizationCommonRepository.GetOrganizationNameFullPath(r.Request.Organization.Id, false, false) - //// }) - //// .Distinct() - //// .ToList(); + // var insignia_data = (from r in await _dbContext.Set() + // .Include(x => x.Profile) + // .ThenInclude(x => x.Gender) + // .Include(x => x.Profile) + // .ThenInclude(x => x.Insignias) + // .ThenInclude(x => x.Insignia) + // .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 + // { + // InsigniaInitial = r.RequestInsignia.ShortName, + // InsigniaName = r.RequestInsignia.Name, + // ProfileId = r.Profile.Id, + // CitizenId = r.Profile.CitizenId, + // FullName = $"", + // ShowProfileId = Guid.Parse("00000000-0000-0000-0000-000000000000"), + // Type = "", + // AcademicStanding = "", + // Level = "", + // DateStart = "", + // SalaryAmount = new double?(0), + // InsigniaRecv = r.Profile.Insignias.Count() == 0 ? null : + // (r.Profile.Insignias.OrderByDescending(x => x.Year).FirstOrDefault().Insignia == null ? null : r.Profile.Insignias.OrderByDescending(x => x.Year).FirstOrDefault().Insignia.ShortName), + // InsigniaRecvDate = r.Profile.Insignias.Count() == 0 ? null : + // (r.Profile.Insignias.OrderByDescending(x => x.Year).FirstOrDefault().DateAnnounce == null ? null : r.Profile.Insignias.OrderByDescending(x => x.Year).FirstOrDefault().DateAnnounce.Value.ToThaiShortDate()), + // InsigniaRequest = "", + // Remark = "", + // Position = "", + // // Position = GetPositionByYear(r.Profile.Id, r.Request.Period.Year) + " ประเภท" + + // // GetPositionTypeByYear(r.Profile.Id, r.Request.Period.Year) + " ระดับ" + + // // GetPositionLevelByYear(r.Profile.Id, r.Request.Period.Year), + // OCName = _organizationCommonRepository.GetOrganizationNameFullPath(r.Request.Organization.Id, false, false) + // }) + // .Distinct() + // .ToList(); - //// var data2 = teacher_data.Union(insignia_data).ToList(); - //return teacher_data; - - return new { }; + // var data2 = teacher_data.Union(insignia_data).ToList(); + return teacher_data; } //44-บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ public async Task GetSummaryCoinReport(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (period == null) + throw new Exception(GlobalMessages.InsigniaPeriodNotFound); - //var data_insignia = await _dbContext.Set() - // .Include(x => x.Profile) - // .Where(x => x.Request.Period == period) - // .Where(x => x.IsApprove == true) - // .Where(x => x.Status == "PENDING") - // .Where(x => x.RequestInsignia.InsigniaType != null) - // .Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ") - // .Select(x => new - // { - // Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, - // RequestInsigniaName = x.RequestInsignia.Name, - // InsigniaInitial = $"{x.RequestInsignia.Name}({x.RequestInsignia.ShortName})", - // OcId = x.Request.Organization.Id - // }) - // .ToListAsync(); + var data_insignia = await _dbContext.Set() + //.Include(x => x.Profile) + .Where(x => x.Request.Period.Id == period.Id) + .Where(x => x.IsApprove == true) + .Where(x => x.Status == "PENDING") + .Where(x => x.RequestInsignia.InsigniaType != null) + .Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ") + .Select(x => new + { + //Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, + Gendor = _userProfileRepository.GetOfficerProfileById(x.ProfileId, AccessToken).Gender ?? "", + RequestInsigniaName = x.RequestInsignia.Name, + InsigniaInitial = $"{x.RequestInsignia.Name}({x.RequestInsignia.ShortName})", + OcId = x.Request.OrganizationId + }) + .ToListAsync(); - //var insignia = (from r in data_insignia - // group r by new { OcId = r.OcId, InsigniaInitial = r.InsigniaInitial } into g - // select new - // { - // RowNo = 1, - // DepartmentName = _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), - // InsigniaInitial = g.Key.InsigniaInitial, - // G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เหรียญจักรพรรดิมาลา" ? 1 : 0).ToString().ToThaiNumber(), - // G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เหรียญจักรพรรดิมาลา" ? 1 : 0).ToString().ToThaiNumber(), - // G2Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0).ToString().ToThaiNumber(), - // G2Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0).ToString().ToThaiNumber(), - // Remark = "", - // }).ToList(); + var insignia = (from r in data_insignia + group r by new { OcId = r.OcId, InsigniaInitial = r.InsigniaInitial } into g + select new + { + RowNo = 1, + DepartmentName = _userProfileRepository.GetOc(g.Key.OcId, 0, AccessToken).Root, //_organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), + InsigniaInitial = g.Key.InsigniaInitial, + G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เหรียญจักรพรรดิมาลา" ? 1 : 0).ToString().ToThaiNumber(), + G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เหรียญจักรพรรดิมาลา" ? 1 : 0).ToString().ToThaiNumber(), + G2Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0).ToString().ToThaiNumber(), + G2Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0).ToString().ToThaiNumber(), + Remark = "", + }).ToList(); - //return insignia; - - return new { }; + return insignia; } public async Task GetSummaryTotalCoinReport(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + if (period == null) + throw new Exception(GlobalMessages.InsigniaPeriodNotFound); - //var data_insignia = await _dbContext.Set() - // .Include(x => x.Profile) - // .Where(x => x.Request.Period == period) - // .Where(x => x.IsApprove == true) - // .Where(x => x.Status == "PENDING") - // .Where(x => x.RequestInsignia.InsigniaType != null) - // .Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ") - // .Select(x => new - // { - // Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, - // RequestInsigniaName = x.RequestInsignia.Name, - // OcId = x.Request.Organization.Id - // }) - // .ToListAsync(); + var data_insignia = await _dbContext.Set() + //.Include(x => x.Profile) + .Where(x => x.Request.Period.Id == period.Id) + .Where(x => x.IsApprove == true) + .Where(x => x.Status == "PENDING") + .Where(x => x.RequestInsignia.InsigniaType != null) + .Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ") + .Select(x => new + { + //Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name, + Gendor = _userProfileRepository.GetOfficerProfileById(x.ProfileId, AccessToken).Gender ?? "", + RequestInsigniaName = x.RequestInsignia.Name, + OcId = x.Request.OrganizationId + }) + .ToListAsync(); - //var insignia = (from r in data_insignia - // group r by new { OcId = r.OcId } into g - // select new - // { - // RowNo = 1, - // DepartmentName = _organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), - // G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เหรียญจักรพรรดิมาลา" ? 1 : 0), - // G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เหรียญจักรพรรดิมาลา" ? 1 : 0), - // G2Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), - // G2Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), - // Remark = "", - // }).ToList(); + var insignia = (from r in data_insignia + group r by new { OcId = r.OcId } into g + select new + { + RowNo = 1, + DepartmentName = _userProfileRepository.GetOc(g.Key.OcId, 0, AccessToken).Root, //_organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), + G1Male = g.Sum(x => x.Gendor == "ชาย" && x.RequestInsigniaName == "เหรียญจักรพรรดิมาลา" ? 1 : 0), + G1Female = g.Sum(x => x.Gendor == "หญิง" && x.RequestInsigniaName == "เหรียญจักรพรรดิมาลา" ? 1 : 0), + G2Male = g.Sum(x => x.Gendor == "ชาย" ? 1 : 0), + G2Female = g.Sum(x => x.Gendor == "หญิง" ? 1 : 0), + Remark = "", + }).ToList(); - //return new - //{ - // G1Male = insignia.Sum(x => x.G1Male).ToString().ToThaiNumber(), - // G1Female = insignia.Sum(x => x.G1Female).ToString().ToThaiNumber(), - // G2Male = insignia.Sum(x => x.G2Male).ToString().ToThaiNumber(), - // G2Female = insignia.Sum(x => x.G2Female).ToString().ToThaiNumber(), - // Remark = "", - //}; + return new + { + G1Male = insignia.Sum(x => x.G1Male).ToString().ToThaiNumber(), + G1Female = insignia.Sum(x => x.G1Female).ToString().ToThaiNumber(), + G2Male = insignia.Sum(x => x.G2Male).ToString().ToThaiNumber(), + G2Female = insignia.Sum(x => x.G2Female).ToString().ToThaiNumber(), + Remark = "", + }; - return new { }; + //return new { }; } //45-บัญชีแสดงรายชื่อผู้ขอพระราชทานเหรียญจักรพรรดิมาลา public async Task GetCoinReport(Guid id) { - //var period = await _dbContext.Set() - // .FirstOrDefaultAsync(x => x.Id == id); - //if (period == null) - // throw new Exception(GlobalMessages.InsigniaPeriodNotFound); + var period = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == id); + 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) - // .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 - // { - // InsigniaInitial = r.RequestInsignia.ShortName, - // InsigniaName = r.RequestInsignia.Name, - // 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 = gender.Sum(x => x.Male), - // Female = gender.Sum(x => x.Female), - // InsigniaId = r.RequestInsignia.Id, - // OCName = _organizationCommonRepository.GetOrganizationNameFullPath(r.Request.Organization.Id, false, false) - // }) - // .Distinct() - // .ToList(); + 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 = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender == "ชาย" ? 1 : 0, + Female = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender == "หญิง" ? 1 : 0, + }) + .Distinct() + .ToList(); + var data = (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 + { + InsigniaInitial = r.RequestInsignia.ShortName, + InsigniaName = r.RequestInsignia.Name, + ProfileId = r.ProfileId, + FullName = $"{_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Prefix}{_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).FirstName} {_userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).LastName}", + // $"{r.Profile.Prefix?.Name}{r.Profile.FirstName} {r.Profile.LastName}", + Gender = _userProfileRepository.GetOfficerProfileById(r.ProfileId, AccessToken).Gender, + Male = gender.Sum(x => x.Male), + Female = gender.Sum(x => x.Female), + InsigniaId = r.RequestInsignia.Id, + OCName = _userProfileRepository.GetOc(r.Request.OrganizationId, 0, AccessToken).Root, //_organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false), + }) + .Distinct() + .ToList(); - //// loop to add temp row with 50 rows per page - //var insigniaList = data.Select(x => new { InsigniaId = x.InsigniaId, InsigniaInitial = x.InsigniaInitial, InsigniaName = x.InsigniaName }) - // .Distinct().ToList(); + // loop to add temp row with 50 rows per page + var insigniaList = data.Select(x => new { InsigniaId = x.InsigniaId, InsigniaInitial = x.InsigniaInitial, InsigniaName = x.InsigniaName }) + .Distinct().ToList(); - //foreach (var ins in insigniaList) - //{ - // var count = data.Where(x => x.InsigniaId == ins.InsigniaId).Count(); - // var mod_val = count <= 50 ? 50 - count : 50 - (count % 50.0); - // for (int i = 0; i < mod_val; i++) - // { - // var p = new - // { - // InsigniaInitial = ins.InsigniaInitial, - // InsigniaName = ins.InsigniaName, - // ProfileId = Guid.Parse("00000000-0000-0000-0000-000000000000"), - // FullName = "", - // Gender = "", - // Male = 0, - // Female = 0, - // InsigniaId = ins.InsigniaId, - // OCName = "" - // }; - // data.Add(p); - // } - //} - //return data.OrderBy(x => x.InsigniaName); - - return new { }; + foreach (var ins in insigniaList) + { + var count = data.Where(x => x.InsigniaId == ins.InsigniaId).Count(); + var mod_val = count <= 50 ? 50 - count : 50 - (count % 50.0); + for (int i = 0; i < mod_val; i++) + { + var p = new + { + InsigniaInitial = ins.InsigniaInitial, + InsigniaName = ins.InsigniaName, + ProfileId = Guid.Parse("00000000-0000-0000-0000-000000000000"), + FullName = "", + Gender = "", + Male = 0, + Female = 0, + InsigniaId = ins.InsigniaId, + OCName = "" + }; + data.Add(p); + } + } + return data.OrderBy(x => x.InsigniaName); } //46-ประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา @@ -924,8 +930,12 @@ namespace BMA.EHR.Application.Repositories.Reports { //var profile = await _dbContext.Set() // .FirstOrDefaultAsync(x => x.Id == id); - //if (profile == null) - // throw new Exception(GlobalMessages.DataNotFound); + + var profile = _userProfileRepository.GetOfficerProfileById(id, AccessToken); + + if (profile == null) + throw new Exception(GlobalMessages.DataNotFound); + //var positions = await _dbContext.Set() // .ToListAsync(); //var organizations = await _dbContext.Set() @@ -933,31 +943,21 @@ namespace BMA.EHR.Application.Repositories.Reports // .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 == null ? "-" : p.Name, - // OCName = o == null || o.Parent == null ? "-" : (o.Parent.OrganizationOrganization == null ? "-" : o.Parent.OrganizationOrganization.Name), - // Age = r.Date == null ? "-" : (r.Date.Value.Year - r.Profile.BirthDate.Year).ToNumericText().ToThaiNumber(), - // Amount = r.Amount == null ? null : r.Amount.Value.ToNumericText().ToThaiNumber(), - // Date = r.Date, - // Remark = "", - // }) - // .Distinct() - // .OrderBy(x => x.Date) - // .ToList(); - - //return data; - - return new { }; + var s_data = profile.ProfileSalary.ToList() + .Select(r => new + { + Date = r.Date, + DateTh = r.Date == null ? "-" : r.Date.Value.ToThaiShortDate().ToString().ToThaiNumber(), + Position = r.Position, + OCName = "", + Age = r.Date == null ? "-" : (r.Date.Value.Year - profile.BirthDate.Year).ToNumericText().ToThaiNumber(), + Amount = r.Amount == null ? null : r.Amount.Value.ToNumericText().ToThaiNumber(), + Remark = "" + }) + .Distinct() + .OrderBy(x => x.Date) + .ToList(); + return s_data; } //noti ยื่นเสนอคน @@ -1126,7 +1126,7 @@ namespace BMA.EHR.Application.Repositories.Reports await _repositoryInsignia.InsertCandidate(period, organization.Id, candidate); } - + } } } diff --git a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs index 143ac660..71a53a03 100644 --- a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs +++ b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs @@ -90,6 +90,8 @@ namespace BMA.EHR.Application.Responses.Profiles public string PositionLevel { get; set; } = string.Empty; public string PositionType { get; set; } = string.Empty; + + public string Position { get; set; } = string.Empty; } public class ProfileInsignia diff --git a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs index a4b632d2..bca4efeb 100644 --- a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs @@ -2208,7 +2208,7 @@ namespace BMA.EHR.Insignia.Service.Controllers if (!Directory.Exists(tmpDir)) Directory.CreateDirectory(tmpDir); - var exportFile = Path.Combine(tmpDir, $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx"); + var exportFile = Path.Combine(tmpDir, $"InsigniaRequestList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx"); try { // copy template @@ -2233,7 +2233,7 @@ namespace BMA.EHR.Insignia.Service.Controllers workSheet.Cells[row, 8].Value = profile.BirthDate.ToThaiDate(); workSheet.Cells[row, 9].Value = profile.DateAppoint == null ? null : profile.DateAppoint.Value.ToThaiDate(); // workSheet.Cells[row, 10].Value = null; - // workSheet.Cells[row, 11].Value = item.Profile.Position == null ? null : item.Profile.Position.Name; + //workSheet.Cells[row, 11].Value = item.Profile.Position == null ? null : item.Profile.Position.Name; workSheet.Cells[row, 12].Value = ""; workSheet.Cells[row, 13].Value = profile.PosLevel == null ? null : profile.PosLevel.PosLevelName; workSheet.Cells[row, 14].Value = ""; @@ -2265,7 +2265,7 @@ namespace BMA.EHR.Insignia.Service.Controllers } catch (Exception ex) { - return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์สอบได้!!"); + return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์ขอพระราชทานเครื่องราชย์ได้!!"); } finally { @@ -2277,7 +2277,7 @@ namespace BMA.EHR.Insignia.Service.Controllers /// /// Download รายชื่อข้าราชการสามัญฯ ที่มีสิทธิ์ยื่นขอพระราชทานเครื่องราชอิสริยาภรณ์ /// - /// Id รอบเครื่องราช + /// Id การขอเครื่องราช (Request) /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง @@ -2287,27 +2287,8 @@ namespace BMA.EHR.Insignia.Service.Controllers public async Task> DownloadExcelInsigniaByFilter([FromBody] ExportFileInsigniaRequest req, Guid RequestId) { var insigniaPeriod = await _context.InsigniaRequests - //.Include(x => x.Organization) - //.ThenInclude(x => x.OrganizationOrganization) .Include(x => x.RequestProfiles) - //.ThenInclude(x => x.Profile) - //.ThenInclude(x => x.Prefix) - //.Include(x => x.RequestProfiles) - //.ThenInclude(x => x.Profile) - //.ThenInclude(x => x.Position) - //.Include(x => x.RequestProfiles) - //.ThenInclude(x => x.Profile) - //.ThenInclude(x => x.PositionLevel) - //.Include(x => x.RequestProfiles) - //.ThenInclude(x => x.Profile) - //.ThenInclude(x => x.Salaries) - //.ThenInclude(x => x.PositionLevel) - //.Include(x => x.RequestProfiles) - //.ThenInclude(x => x.Profile) - //.ThenInclude(x => x.Insignias) - //.ThenInclude(x => x.Insignia) - //.Include(x => x.RequestProfiles) - //.ThenInclude(x => x.RequestInsignia) + .ThenInclude(x => x.RequestInsignia) .FirstOrDefaultAsync(x => x.Id == RequestId); if (insigniaPeriod == null) return Error(GlobalMessages.InsigniaPeriodNotFound); @@ -2318,7 +2299,7 @@ namespace BMA.EHR.Insignia.Service.Controllers if (!Directory.Exists(tmpDir)) Directory.CreateDirectory(tmpDir); - var exportFile = Path.Combine(tmpDir, $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx"); + var exportFile = Path.Combine(tmpDir, $"InsigniaRequestList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx"); try { // copy template @@ -2340,7 +2321,7 @@ namespace BMA.EHR.Insignia.Service.Controllers foreach (var item in requestProfiles) { var profile = _userProfileRepository.GetOfficerProfileById(item.ProfileId, AccessToken); - workSheet.Cells[row, 1].Value = "-"; + workSheet.Cells[row, 1].Value = _userProfileRepository.GetOc(insigniaPeriod.OrganizationId, 0, AccessToken).Root; workSheet.Cells[row, 2].Value = profile.CitizenId; workSheet.Cells[row, 3].Value = profile.Prefix == null ? "-" : ((profile.Prefix == "นาย" || profile.Prefix == "นาง" || profile.Prefix == "นางสาว") ? profile.Prefix : "-"); workSheet.Cells[row, 4].Value = profile.Prefix == null ? "-" : ((profile.Prefix == "นาย" || profile.Prefix == "นาง" || profile.Prefix == "นางสาว") ? "-" : profile.Prefix); @@ -2382,7 +2363,7 @@ namespace BMA.EHR.Insignia.Service.Controllers } catch (Exception ex) { - return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์สอบได้!!"); + return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์ขอพระราชทานเครื่องราชย์ได้!!"); } finally { diff --git a/BMA.EHR.Insignia.Service/appsettings.json b/BMA.EHR.Insignia.Service/appsettings.json index a37fde2a..9524abdd 100644 --- a/BMA.EHR.Insignia.Service/appsettings.json +++ b/BMA.EHR.Insignia.Service/appsettings.json @@ -15,10 +15,10 @@ "ConnectionStrings": { //"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB", //"DefaultConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" - "DefaultConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", - "ExamConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_exam_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", - "LeaveConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_leave_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", - "DisciplineConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_discipline_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" + "DefaultConnection": "server=192.168.1.81;user=root;password=adminVM123;port=4063;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", + "ExamConnection": "server=192.168.1.81;user=root;password=adminVM123;port=4063;database=bma_ehr_exam_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", + "LeaveConnection": "server=192.168.1.81;user=root;password=adminVM123;port=4063;database=bma_ehr_leave_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;", + "DisciplineConnection": "server=192.168.1.81;user=root;password=adminVM123;port=4063;database=bma_ehr_discipline_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;" }, "Jwt": { "Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI", @@ -43,5 +43,5 @@ "Node": { "API": "https://bma-ehr.frappet.synology.me/api/v1/probation" }, - "API": "https://bma-ehr.frappet.synology.me/api/v1" + "API": "https://bma-ehr.frappet.com/api/v1" } diff --git a/BMA.EHR.Report.Service/appsettings.json b/BMA.EHR.Report.Service/appsettings.json index af177b76..4e60742a 100644 --- a/BMA.EHR.Report.Service/appsettings.json +++ b/BMA.EHR.Report.Service/appsettings.json @@ -57,5 +57,5 @@ ] }, "APIPROBATION": "https://bma-ehr.frappet.synology.me/api/v1/probation/", - "API": "https://bma-ehr.frappet.synology.me/api/v1/" + "API": "https://bma-ehr.frappet.synology.me/api/v1" } \ No newline at end of file