1136 lines
69 KiB
C#
1136 lines
69 KiB
C#
using Amazon.S3.Model.Internal.MarshallTransformations;
|
|
using BMA.EHR.Application.Common.Interfaces;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Application.Responses;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.HR;
|
|
using BMA.EHR.Domain.Models.Insignias;
|
|
using BMA.EHR.Domain.Models.MetaData;
|
|
using BMA.EHR.Domain.Models.Organizations;
|
|
using BMA.EHR.Domain.Models.Retirement;
|
|
using BMA.EHR.Domain.Shared;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http.Metadata;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Net;
|
|
|
|
namespace BMA.EHR.Application.Repositories.Reports
|
|
{
|
|
public class InsigniaReportRepository
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly IApplicationDBContext _dbContext;
|
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
|
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
private readonly InsigniaPeriodsRepository _repositoryInsignia;
|
|
private readonly string CRLF = "\r\n";
|
|
|
|
#endregion
|
|
|
|
#region " Constructor and Destructor "
|
|
|
|
public InsigniaReportRepository(IApplicationDBContext dbContext,
|
|
OrganizationCommonRepository organizationCommonRepository,
|
|
InsigniaPeriodsRepository repositoryInsignia,
|
|
NotificationRepository repositoryNoti,
|
|
IWebHostEnvironment hostEnvironment)
|
|
{
|
|
_dbContext = dbContext;
|
|
_hostingEnvironment = hostEnvironment;
|
|
_repositoryNoti = repositoryNoti;
|
|
_organizationCommonRepository = organizationCommonRepository;
|
|
_repositoryInsignia = repositoryInsignia;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
// private string GetPositionByYear(string profileID, int year)
|
|
// {
|
|
// using (var ctx = new ApplicationDbContext())
|
|
// {
|
|
// var ret = (from x in ctx.ProfileSalaryPositions.AsQueryable()
|
|
// where x.IdNavigation.ProfileId == profileID &&
|
|
// x.IdNavigation.SalaryDateAnnounce.Value.Year == year
|
|
// orderby x.IdNavigation.Order descending
|
|
// select x)
|
|
// .Include(x => x.Position)
|
|
// .FirstOrDefault();
|
|
|
|
// if (ret != null)
|
|
// return ret.Position.Name;
|
|
// else
|
|
// return "ไม่ระบุ";
|
|
// }
|
|
// }
|
|
|
|
// private string GetPositionLevelByYear(string profileID, int year)
|
|
// {
|
|
// using (var ctx = new ApplicationDbContext())
|
|
// {
|
|
// var ret = (from x in ctx.ProfileSalaryPositionLevels.AsQueryable()
|
|
// where x.IdNavigation.ProfileId == profileID &&
|
|
// x.IdNavigation.SalaryDateAnnounce.Value.Year == year
|
|
// orderby x.IdNavigation.Order descending
|
|
// select x)
|
|
// .Include(x => x.PositionLevel)
|
|
// .FirstOrDefault();
|
|
|
|
// if (ret != null)
|
|
// return ret.PositionLevel.Name;
|
|
// else
|
|
// return "ไม่ระบุ";
|
|
// }
|
|
// }
|
|
|
|
// private string GetPositionTypeByYear(string profileID, int year)
|
|
// {
|
|
// using (var ctx = new ApplicationDbContext())
|
|
// {
|
|
// var ret = (from x in ctx.ProfileSalaryPositionTypes.AsQueryable()
|
|
// where x.IdNavigation.ProfileId == profileID &&
|
|
// x.IdNavigation.SalaryDateAnnounce.Value.Year == year
|
|
// orderby x.IdNavigation.Order descending
|
|
// select x)
|
|
// .Include(x => x.PositionType)
|
|
// .FirstOrDefault();
|
|
|
|
// if (ret != null)
|
|
// return ret.PositionType.Name;
|
|
// else
|
|
// return "ไม่ระบุ";
|
|
// }
|
|
// }
|
|
|
|
public async Task<dynamic> GetYearInsigniaPeriod(Guid id)
|
|
{
|
|
var period = await _dbContext.Set<InsigniaPeriod>()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (period == null)
|
|
throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
string thaiYear = period.Year.ToThaiYear().ToString().ToThaiNumber();
|
|
return thaiYear;
|
|
}
|
|
|
|
public async Task<dynamic> Get2YearInsigniaPeriod(Guid id)
|
|
{
|
|
var period = await _dbContext.Set<InsigniaPeriod>()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (period == null)
|
|
throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
string thaiYear = period.Year.ToThaiYear().ToString().ToThaiNumber();
|
|
return thaiYear.Substring(2);
|
|
}
|
|
|
|
public async Task<dynamic> GetInsigniaPeriod(Guid id)
|
|
{
|
|
var period = await _dbContext.Set<InsigniaPeriod>()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (period == null)
|
|
throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
return period;
|
|
}
|
|
|
|
public async Task<dynamic> GetDateInsigniaPeriod(Guid id)
|
|
{
|
|
var period = await _dbContext.Set<InsigniaPeriod>()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (period == null)
|
|
throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
return new
|
|
{
|
|
StartDater = period.StartDate.ToThaiFullDate().ToString().ToThaiNumber(),
|
|
EndDate = period.EndDate.ToThaiFullDate().ToString().ToThaiNumber(),
|
|
};
|
|
}
|
|
|
|
public async Task<dynamic> GetProfileInsignia(Guid id)
|
|
{
|
|
|
|
|
|
var profile = (from r in await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.Include(x => x.Position)
|
|
.ToListAsync()
|
|
where r.Id == id
|
|
select new
|
|
{
|
|
FullName = $"{r.Prefix?.Name}{r.FirstName} {r.LastName}",
|
|
Position = r.Position == null ? "-" : r.Position.Name,
|
|
OCName = r.OcId == null ? "-" : _organizationCommonRepository.GetOrganizationNameFullPath(r.OcId.Value, false, false),
|
|
BirthDate = r.BirthDate.ToThaiFullDate().ToString().ToThaiNumber(),
|
|
DateAppoint = !string.IsNullOrEmpty(r.DateAppoint.ToString()) ? DateTime.Parse((r.DateAppoint.Value.AddYears(25).AddDays(-1)).ToString()).ToThaiFullDate().ToString().ToThaiNumber() : string.Empty,
|
|
})
|
|
.FirstOrDefault();
|
|
if (profile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
return profile;
|
|
}
|
|
|
|
//39-แบบ ขร1 บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ ข้าราชการ ชั้นสายสะพาย
|
|
public async Task<dynamic> GetKhr1Report(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var data_insignia = await _dbContext.Set<InsigniaRequestProfile>()
|
|
// //.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 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();
|
|
|
|
//return insignia;
|
|
|
|
return new { };
|
|
}
|
|
|
|
public async Task<dynamic> GetKhr1TotalReport(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var data_insignia = await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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 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();
|
|
|
|
//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 { };
|
|
}
|
|
|
|
//40-แบบ ขร2 บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ ข้าราชการ ชั้นต่ำกว่าสายสะพาย
|
|
public async Task<dynamic> GetKhr2Report(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var data_insignia = await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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 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();
|
|
|
|
//return insignia;
|
|
|
|
return new { };
|
|
}
|
|
public async Task<dynamic> GetKhr2TotalReport(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var data_insignia = await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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 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();
|
|
|
|
//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 { };
|
|
}
|
|
|
|
//41-แบบ ขร3 บัญชีรายชื่อข้าราชการผู้ขอพระราชทานเครื่องราชฯ
|
|
public async Task<dynamic> GetKhr3Report(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var data = (from r in await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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();
|
|
|
|
//// 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 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<dynamic>();
|
|
|
|
//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);
|
|
// }
|
|
//}
|
|
|
|
//return ret;
|
|
|
|
return new { };
|
|
}
|
|
public async Task<dynamic> GetKhr3ReportV2(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var data = (from r in await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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();
|
|
|
|
//// 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 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<dynamic>();
|
|
|
|
//// 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,
|
|
// };
|
|
// data.Add(p);
|
|
// }
|
|
//}
|
|
|
|
//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),
|
|
// Data = grp.ToList(),
|
|
// }).ToList();
|
|
|
|
//return sumData;
|
|
|
|
return new { };
|
|
}
|
|
|
|
//42-แบบ ขร4 บัญชีแสดงคุณสมบัติของข้าราชการซึ่งเสนอขอเครื่องราชฯ
|
|
public async Task<dynamic> GetKhr4Report(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var teacher_data = (from r in await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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 insignia_data = (from r in await _dbContext.Set<InsigniaRequestProfile>()
|
|
//// .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 { };
|
|
}
|
|
|
|
//44-บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ
|
|
public async Task<dynamic> GetSummaryCoinReport(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var data_insignia = await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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 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();
|
|
|
|
//return insignia;
|
|
|
|
return new { };
|
|
}
|
|
public async Task<dynamic> GetSummaryTotalCoinReport(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var data_insignia = await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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 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();
|
|
|
|
//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 { };
|
|
}
|
|
|
|
//45-บัญชีแสดงรายชื่อผู้ขอพระราชทานเหรียญจักรพรรดิมาลา
|
|
public async Task<dynamic> GetCoinReport(Guid id)
|
|
{
|
|
//var period = await _dbContext.Set<InsigniaPeriod>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (period == null)
|
|
// throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
//var gender = (from r in await _dbContext.Set<InsigniaRequestProfile>()
|
|
// .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<InsigniaRequestProfile>()
|
|
// .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();
|
|
|
|
//// 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 { };
|
|
}
|
|
|
|
//46-ประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา
|
|
public async Task<dynamic> GetHistorySalaryReport(Guid id)
|
|
{
|
|
//var profile = await _dbContext.Set<Profile>()
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
//if (profile == null)
|
|
// throw new Exception(GlobalMessages.DataNotFound);
|
|
//var positions = await _dbContext.Set<PositionPath>()
|
|
// .ToListAsync();
|
|
//var organizations = await _dbContext.Set<OrganizationEntity>()
|
|
// .Include(x => x.Parent)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
// .ToListAsync();
|
|
|
|
//var data = (from r in await _dbContext.Set<ProfileSalary>()
|
|
// .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 { };
|
|
}
|
|
|
|
//noti ยื่นเสนอคน
|
|
public async Task NotifyInsignia()
|
|
{
|
|
var insigniaPeriods = await _dbContext.Set<InsigniaPeriod>()
|
|
.AsQueryable()
|
|
.ToListAsync();
|
|
foreach (var insigniaPeriod in insigniaPeriods)
|
|
{
|
|
if (insigniaPeriod.EndDate.AddDays(-insigniaPeriod.Amount).Date == DateTime.Now.Date)
|
|
{
|
|
await _repositoryNoti.PushNotificationAsync(
|
|
Guid.Parse("08dbc953-6441-408a-86d0-4df4ce449039"),
|
|
$"แจ้งเตือนรอบการเสนอขอ {insigniaPeriod.Name} รอบที่{insigniaPeriod.Round}",
|
|
$"แจ้งเตือนรอบการเสนอขอ {insigniaPeriod.Name} รอบที่{insigniaPeriod.Round}",
|
|
"",
|
|
true
|
|
);
|
|
await _repositoryNoti.PushNotificationAsync(
|
|
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
|
|
$"แจ้งเตือนรอบการเสนอขอ {insigniaPeriod.Name} รอบที่{insigniaPeriod.Round}",
|
|
$"แจ้งเตือนรอบการเสนอขอ {insigniaPeriod.Name} รอบที่{insigniaPeriod.Round}",
|
|
"",
|
|
true
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//ล็อกข้อมูล โอนคนไปบันทึกผล
|
|
public async Task LockInsignia()
|
|
{
|
|
var insigniaPeriods = await _dbContext.Set<InsigniaPeriod>()
|
|
.AsQueryable()
|
|
.Include(x => x.InsigniaRequests)
|
|
.Include(x => x.ReliefDoc)
|
|
.ToListAsync();
|
|
foreach (var insigniaPeriod in insigniaPeriods)
|
|
{
|
|
if (insigniaPeriod.EndDate.Date.AddDays(5) == DateTime.Now.Date)
|
|
continue;
|
|
insigniaPeriod.IsLock = true;
|
|
var insigniaNote = await _dbContext.Set<InsigniaNote>()
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
//.ThenInclude(x => x.Profile)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.FirstOrDefaultAsync(x => x.Year == insigniaPeriod.Year);
|
|
if (insigniaNote == null)
|
|
{
|
|
insigniaNote = new InsigniaNote
|
|
{
|
|
// Round = insigniaPeriod.Round,
|
|
Name = $"รอบการเสนอขอพระราชทานเครื่องราชฯ ปี {insigniaPeriod.Year + 543}",
|
|
Year = insigniaPeriod.Year,
|
|
// StartDate = insigniaPeriod.StartDate,
|
|
// EndDate = insigniaPeriod.EndDate,
|
|
// Amount = insigniaPeriod.Amount,
|
|
// ReliefDoc = insigniaPeriod.ReliefDoc,
|
|
CreatedFullName = "System Administrator",
|
|
CreatedUserId = "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = "System Administrator",
|
|
LastUpdateUserId = "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _dbContext.Set<InsigniaNote>().AddAsync(insigniaNote);
|
|
await _dbContext.SaveChangesAsync();
|
|
insigniaNote = await _dbContext.Set<InsigniaNote>()
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
//.ThenInclude(x => x.Profile)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNote.Id);
|
|
}
|
|
var requestOlds = await _dbContext.Set<InsigniaRequest>()
|
|
.Where(p => p.Period == insigniaPeriod)
|
|
.Where(p => p.RequestStatus == "st5")
|
|
.ToListAsync();
|
|
foreach (var requestOld in requestOlds)
|
|
{
|
|
var profileOlds = await _dbContext.Set<InsigniaRequestProfile>()
|
|
//.Include(x => x.Profile)
|
|
.Include(x => x.RequestInsignia)
|
|
.Where(p => p.Request == requestOld)
|
|
.ToListAsync();
|
|
|
|
foreach (var profileOld in profileOlds)
|
|
{
|
|
if (profileOld.Status == "DELETE" || profileOld.Status == "REJECT")
|
|
continue;
|
|
var noreProfileOld = insigniaNote.InsigniaNoteProfiles
|
|
.Where(x => x.ProfileId == profileOld.ProfileId)
|
|
.FirstOrDefault();
|
|
if (noreProfileOld != null)
|
|
{
|
|
noreProfileOld.RequestDate = profileOld.RequestDate;
|
|
noreProfileOld.Salary = profileOld.Salary;
|
|
noreProfileOld.IsApprove = profileOld.IsApprove;
|
|
noreProfileOld.RequestInsignia = profileOld.RequestInsignia;
|
|
noreProfileOld.CreatedFullName = "System Administrator";
|
|
noreProfileOld.CreatedUserId = "";
|
|
noreProfileOld.CreatedAt = DateTime.Now;
|
|
noreProfileOld.LastUpdateFullName = "System Administrator";
|
|
noreProfileOld.LastUpdateUserId = "";
|
|
noreProfileOld.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
if (profileOld.ProfileId == null)
|
|
continue;
|
|
await _dbContext.Set<InsigniaNoteProfile>().AddAsync(new InsigniaNoteProfile
|
|
{
|
|
RequestDate = profileOld.RequestDate,
|
|
Salary = profileOld.Salary,
|
|
IsApprove = profileOld.IsApprove,
|
|
Status = "PENDING",
|
|
ProfileId = profileOld.ProfileId,
|
|
RequestInsignia = profileOld.RequestInsignia,
|
|
OrganizationOrganizationSend = null,
|
|
InsigniaNote = insigniaNote,
|
|
CreatedFullName = "System Administrator",
|
|
CreatedUserId = "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = "System Administrator",
|
|
LastUpdateUserId = "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
}
|
|
|
|
//คำนวนผู้ได้รับเครื่องราชฯ
|
|
public async Task CalInsignaiRequestBkk()
|
|
{
|
|
var insigniaPeriods = await _dbContext.Set<InsigniaPeriod>()
|
|
.AsQueryable()
|
|
.ToListAsync();
|
|
foreach (var insigniaPeriod in insigniaPeriods)
|
|
{
|
|
if (insigniaPeriod.StartDate == DateTime.Now.Date)
|
|
continue;
|
|
var organizationType = await _dbContext.Set<OrganizationType>().Where(x => x.Name == "หน่วยงาน").FirstOrDefaultAsync();
|
|
if (organizationType == null)
|
|
continue;
|
|
var organizations = await _dbContext.Set<OrganizationEntity>().Where(x => x.OrganizationType == organizationType).ToListAsync();
|
|
foreach (var organization in organizations)
|
|
{
|
|
if (organization == null)
|
|
continue;
|
|
|
|
var result = await _repositoryInsignia.GetInsigniaRequest(insigniaPeriod.Id, organization.Id);
|
|
if (result != null)
|
|
{
|
|
Guid period = result.PeriodId;
|
|
string requestStatus = result.RequestStatus;
|
|
var candidate = await _repositoryInsignia.GetInsigniaCandidateBKK(insigniaPeriod.Id, organization.Id);
|
|
// ตรวจสอบว่ารายการอยู่ใน table insignia_request_new
|
|
if (requestStatus == null)
|
|
{
|
|
// บันทึกรายชื่อ
|
|
await _repositoryInsignia.InsertCandidate(period, organization.Id, candidate);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|