hrms-api-backend/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs
Suphonchai Phoonsawat 1ae6f5e8d1 fix api
2024-06-20 13:37:25 +07:00

1315 lines
84 KiB
C#

using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Responses.Reports;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.OrganizationEmployee;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Repositories.Commands
{
public class CommandReportRepository : GenericRepository<Guid, Command>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly UserProfileRepository _userProfileRepository;
#endregion
#region " Constructor and Destuctor "
public CommandReportRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor,
OrganizationCommonRepository organizationCommonRepository,
UserProfileRepository userProfileRepository) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_organizationCommonRepository = organizationCommonRepository;
_userProfileRepository = userProfileRepository;
}
#endregion
#region " Properties "
protected Guid UserOrganizationId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
else
return Guid.Empty;
}
}
#endregion
#region " Methods "
public async Task<List<CommandType01Response>> GetCommandType01AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementProfile>()
.Include(x => x.PlacementEducations)
.Include(x => x.Placement)
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x.Organization)
// .Include(x => x.PositionPath)
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionNumber)
// .Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType01Response
{
Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" :
p.PlacementEducations.FirstOrDefault().Degree,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Oc = p.root == null ? "" : p.root,
PositionName = p.positionName == null ? "" : p.positionName,
PositionLevel = p.posLevelName == null ? "" : p.posLevelName,
PositionType = p.posTypeName == null ? "" : p.posTypeName,
PositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
Salary = p.Amount == null ? "0" : p.Amount.Value.ToNumericNoDecimalText().ToThaiNumber().ToThaiNumber(),
AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(),
ExamNumber = p.ExamNumber == null ? "0" : p.ExamNumber.Value.ToString().ToThaiNumber(),
PlacementName = $"{p.Placement.Name.ToThaiNumber()} ครั้งที่ {p.Placement.Round.ToThaiNumber()}/{p.Placement.Year.ToThaiYear().ToString().ToThaiNumber()}",
RemarkHorizontal = p.RemarkHorizontal,
RemarkVertical = p.RemarkVertical,
}).ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType01Response>> GetCommandType02AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementProfile>()
.Include(x => x.PlacementEducations)
.Include(x => x.Placement)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType01Response
{
Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" :
p.PlacementEducations.FirstOrDefault().Degree,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Oc = p.root == null ? "" : p.root,
PositionName = p.positionName == null ? "" : p.positionName,
PositionLevel = p.posLevelName == null ? "" : p.posLevelName,
PositionType = p.posTypeName == null ? "" : p.posTypeName,
PositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
Salary = p.Amount == null ? "" : p.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(),
ExamNumber = p.ExamNumber == null ? "" : p.ExamNumber.Value.ToString().ToThaiNumber(),
PlacementName = $"{p.Placement.Name.ToThaiNumber()} ครั้งที่ {p.Placement.Round.ToThaiNumber()}/{p.Placement.Year.ToThaiYear().ToString().ToThaiNumber()}",
RemarkHorizontal = p.RemarkHorizontal,
RemarkVertical = p.RemarkVertical,
}).ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType03AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementProfile>()
.Include(x => x.PlacementEducations)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
orderby r.Sequence
select new CommandType03Response
{
Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" :
p.PlacementEducations.FirstOrDefault().Degree,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
Probation = pf.IsProbation ? "(อยู่ระหว่างปฏิบัติหน้าที่ราชการ)" : "",
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name.ToThaiNumber(),
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? "" : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
NewOc = p.root == null ? "" : p.root,
NewPositionName = p.positionName == null ? "" : p.positionName,
NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName,
NewPositionType = p.posTypeName == null ? "" : p.posTypeName,
NewPositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(),
RemarkHorizontal = p.RemarkHorizontal,
RemarkVertical = p.RemarkVertical,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType04AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementProfile>()
.Include(x => x.PlacementEducations)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
orderby r.Sequence
select new CommandType03Response
{
Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" :
p.PlacementEducations.FirstOrDefault().Degree,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name.ToThaiNumber(),
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? "" : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
NewOc = p.root == null ? "" : p.root,
NewPositionName = p.positionName == null ? "" : p.positionName,
NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName,
NewPositionType = p.posTypeName == null ? "" : p.posTypeName,
NewPositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType05_06AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementAppointment>()
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x.Organization)
// .Include(x => x.PositionPath)
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionNumber)
// .Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
// join pf in _dbContext.Set<Profile>()
// .Include(x => x.Position)
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionType)
// .Include(x => x.PosNo)
// .Include(x => x.Salaries)
// .Include(x => x.Educations)
// on r.CitizenId equals pf.CitizenId
orderby r.Sequence
select new CommandType03Response
{
Education = p.EducationOld == null ? "-" : p.EducationOld,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = p.rootOld == null ? "" : p.rootOld,
OldPositionName = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld,
OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld,
OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld,
OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
OldSalaryDate = p.PositionDate == null ? "" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),
NewOc = p.root == null ? "" : p.root,
NewPositionName = p.position == null ? "" : p.position,
NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName,
NewPositionType = p.posTypeName == null ? "" : p.posTypeName,
NewPositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(),
Reason = p.Reason == null ? "-" : p.Reason,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType07AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementAppointment>()
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x.Organization)
// .Include(x => x.PositionPath)
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionNumber)
// .Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
// join pf in _dbContext.Set<Profile>()
// .Include(x => x.Position)
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionType)
// .Include(x => x.PosNo)
// .Include(x => x.Salaries)
// .Include(x => x.Educations)
// on r.CitizenId equals pf.CitizenId
orderby r.Sequence
select new CommandType03Response
{
// Education = pf.Educations == null || pf.Educations.Count == 0 ? "" :
// pf.Educations.OrderByDescending(x => x.StartDate).FirstOrDefault().Degree,
Education = p.EducationOld == null ? "-" : p.EducationOld,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = p.rootOld == null ? "" : p.rootOld,
OldPositionName = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld,
OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld,
OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld,
OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
OldSalaryDate = p.PositionDate == null ? "" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),
NewOc = p.root == null ? "" : p.root,
NewPositionName = p.position == null ? "" : p.position,
NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName,
NewPositionType = p.posTypeName == null ? "" : p.posTypeName,
NewPositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(),
Reason = p.Reason == null ? "-" : p.Reason,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType08AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementOther>()
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType03Response
{
Education = p.EducationOld == null ? "-" : p.EducationOld,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = p.rootOld == null ? "" : p.rootOld,
OldPositionName = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld,
OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld,
OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld,
OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
OldSalaryDate = p.PositionDate == null ? "" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),
NewOc = p.rootOld == null ? "" : p.rootOld,
NewPositionName = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
NewPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld,
NewPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld,
NewPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld,
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.PositionDate == null ? "" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),
LeaveDate = p.LeaveDate == null ? "" : p.LeaveDate.Value.ToThaiShortDate2().ToThaiNumber(),
Reason = p.Reason == null ? "-" : p.Reason,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType09AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementOther>()
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType03Response
{
Education = p.EducationOld == null ? "-" : p.EducationOld,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = p.rootOld == null ? "" : p.rootOld,
OldPositionName = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld,
OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld,
OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld,
OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
OldSalaryDate = p.PositionDate == null ? "" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),
NewOc = p.rootOld == null ? "" : p.rootOld,
NewPositionName = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
NewPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld,
NewPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld,
NewPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld,
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.PositionDate == null ? "" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),
LeaveDate = p.LeaveDate == null ? "" : p.LeaveDate.Value.ToThaiShortDate2().ToThaiNumber(),
MilitaryDate = p.MilitaryDate == null ? "" : p.MilitaryDate.Value.ToThaiShortDate2().ToThaiNumber(),
Reason = p.Reason == null ? "-" : p.Reason,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType11Response>> GetCommandType11Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.Select(r => new CommandType11Response
{
CommandNo = r.Command.CommandNo.ToThaiNumber(),
CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(),
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PlacementCommandIssuer = r.Command.PlacementCommandIssuer ?? "",
PlacementCommandNo = r.Command.PlacementCommandNo == null ? "" : r.Command.PlacementCommandNo.ToThaiNumber(),
PlacementCommandDate = r.Command.PlacementCommandDate == null ? "" : r.Command.PlacementCommandDate.Value.ToThaiFullDate3().ToThaiNumber(),
Subject = $"เรื่อง {r.Command.CommandSubject}",
})
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
return raw_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType11Response>> GetCommandType12Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.Select(r => new CommandType11Response
{
CommandNo = r.Command.CommandNo.ToThaiNumber(),
CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(),
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PlacementCommandIssuer = r.Command.PlacementCommandIssuer ?? "",
PlacementCommandNo = r.Command.PlacementCommandNo == null ? "" : r.Command.PlacementCommandNo.ToThaiNumber(),
PlacementCommandDate = r.Command.PlacementCommandDate == null ? "" : r.Command.PlacementCommandDate.Value.ToThaiFullDate3().ToThaiNumber(),
Subject = $"เรื่อง {r.Command.CommandSubject}",
})
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
return raw_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType13Response>> GetCommandType13AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementTransfer>()
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType13Response
{
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Organization = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
PositionName = p.PositionOld == null ? "" : p.PositionOld,
PositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld,
PositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld,
PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld,
Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
//Salary = pf.Salaries == null || pf.Salaries.Count == 0 ? "" : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
ActiveDate = p.Date == null ? "" : p.Date.Value.ToThaiShortDate2().ToThaiNumber(),
ReceiveOrganizationName = r.Command!.ReceiveOrganizationName ?? "",
Reason = p.Reason ?? ""
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType14AttachmentAsync(Guid id)
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementReceive>()
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x.Organization)
// .Include(x => x.PositionPath)
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionNumber)
// .Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType03Response
{
Education = p.EducationOld == null ? "-" : p.EducationOld,
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = p.OrganizationPositionOld ?? "",
OldPositionName = p.OrganizationPositionOld ?? "",
OldPositionLevel = p.PositionLevelOld ?? "",
OldPositionType = p.PositionTypeOld ?? "",
OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(),
OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
NewOc = p.root == null ? "" : p.root,
NewPositionName = p.position == null ? "" : p.position,
NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName,
NewPositionType = p.posTypeName == null ? "" : p.posTypeName,
NewPositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(),
Reason = p.Reason == null ? "-" : p.Reason,
})
.ToList();
return report_data;
}
public async Task<List<CommandType15Response>> GetCommandType15AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementOfficer>()
//.Include(p => p.Profile)
//.ThenInclude(p => p.Position)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType15Response
{
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
// PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.Organization == null ? "" : p.Organization,
StartDate = p.DateStart == null ? "" : p.DateStart.Value.ToThaiShortDate2().ToThaiNumber(),
EndDate = p.DateEnd == null ? "" : p.DateEnd.Value.ToThaiShortDate2().ToThaiNumber(),
Reason = p.Reason == null ? "" : p.Reason.ToThaiNumber()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType16Response>> GetCommandType16Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementRepatriation>()
//.Include(p => p.Profile)
//.ThenInclude(p => p.Position)
//.Include(p => p.Profile)
//.ThenInclude(p => p.Salaries)
//.Include(p => p.Profile)
//.ThenInclude(p => p.Prefix)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType16Response
{
CommandNo = r.Command.CommandNo.ToThaiNumber(),
CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(),
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
GovAidCommandNo = r.Command.GovAidCommandNo == null ? "" : r.Command.GovAidCommandNo.ToThaiNumber(),
GovAidCommandDate = r.Command.GovAidCommandDate == null ? "" :
r.Command.GovAidCommandDate.Value.ToThaiFullDate3().ToThaiNumber(),
StartDate = p.Date == null ? "" : p.Date.Value.ToThaiFullDate3().ToThaiNumber(),
ActiveDate = p.DateRepatriation == null ? "" : p.DateRepatriation.Value.ToThaiFullDate3().ToThaiNumber(),
FullName = $"{p.prefix}{p.firstName!} {p.lastName!}",
Subject = $"เรื่อง {r.Command.CommandSubject}",
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType17Response>> GetCommandType17AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementResign>()
//.Include(p => p.Profile)
//.ThenInclude(p => p.Position)
//.Include(p => p.Profile)
//.ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType17Response
{
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.PositionOld ?? "",
Organization = p.OrganizationPositionOld ?? "",
PositionLevel = p.PositionLevelOld ?? "",
PositionType = p.PositionTypeOld ?? "",
PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(),
ActiveDate = p.ActiveDate == null ? "" : p.ActiveDate.Value.ToThaiShortDate2().ToThaiNumber(),
Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
//Salary = p.Profile.Salaries == null || p.Profile.Salaries.Count == 0 ? "" : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
Remark = p.Reason ?? "",
RemarkHorizontal = p.RemarkHorizontal,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType18Response>> GetCommandType18Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementOut>()
// .Include(p => p.Profile)
// .ThenInclude(p => p.Position)
// .Include(p => p.Profile)
// .ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType18Response
{
CommandNo = r.Command.CommandNo.ToThaiNumber(),
CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(),
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
// PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld,
PositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld,
PositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld,
PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(),
Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
//Salary = p.Profile.Salaries == null || p.Profile.Salaries.Count == 0 ? "" : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
Fault = r.Command.Fault == null ? "" : r.Command.Fault.ToThaiNumber(),
GuiltyBasis = r.Command.GuiltyBasis == null ? "" : r.Command.GuiltyBasis.ToThaiNumber(),
ConclusionFireNo = r.Command.ConclusionFireNo == null ? "" : r.Command!.ConclusionFireNo.ToThaiNumber(),
ConclusionFireDate = r.Command.ConclusionFireDate == null ? "" : r.Command.ConclusionFireDate.Value.ToThaiFullDate3().ToThaiNumber(),
ConclusionFireResolution = r.Command.ConclusionFireResolution == null ? "" : r.Command.ConclusionFireResolution.ToThaiNumber(),
Subject = $"เรื่อง {r.Command.CommandSubject}",
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType18Response>> GetCommandType19Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementDischarge>()
.Include(p => p.Profile)
.ThenInclude(p => p.Position)
.Include(p => p.Profile)
.ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType18Response
{
CommandNo = r.Command.CommandNo.ToThaiNumber(),
CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(),
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.OrganizationPositionOld ?? "",
PositionLevel = p.PositionLevelOld ?? "",
PositionType = p.PositionTypeOld ?? "",
PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(),
Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
//Salary = p.Profile.Salaries == null || p.Profile.Salaries.Count == 0 ? "" : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
Fault = r.Command.Fault == null ? "" : r.Command.Fault.ToThaiNumber(),
GuiltyBasis = r.Command.GuiltyBasis == null ? "" : r.Command.GuiltyBasis.ToThaiNumber(),
ConclusionFireNo = r.Command.ConclusionFireNo == null ? "" : r.Command!.ConclusionFireNo.ToThaiNumber(),
ConclusionFireDate = r.Command.ConclusionFireDate == null ? "" : r.Command.ConclusionFireDate.Value.ToThaiFullDate3().ToThaiNumber(),
ConclusionFireResolution = r.Command.ConclusionFireResolution == null ? "" : r.Command.ConclusionFireResolution.ToThaiNumber(),
Subject = $"เรื่อง {r.Command.CommandSubject}",
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType18Response>> GetCommandType20Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementExpulsion>()
.Include(p => p.Profile)
.ThenInclude(p => p.Position)
.Include(p => p.Profile)
.ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id
select new CommandType18Response
{
CommandNo = r.Command.CommandNo.ToThaiNumber(),
CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(),
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.OrganizationPositionOld ?? "",
PositionLevel = p.PositionLevelOld ?? "",
PositionType = p.PositionTypeOld ?? "",
PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(),
Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
//Salary = p.Profile.Salaries == null || p.Profile.Salaries.Count == 0 ? "" : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
Fault = r.Command.Fault == null ? "" : r.Command.Fault.ToThaiNumber(),
GuiltyBasis = r.Command.GuiltyBasis == null ? "" : r.Command.GuiltyBasis.ToThaiNumber(),
ConclusionFireNo = r.Command.ConclusionFireNo == null ? "" : r.Command!.ConclusionFireNo.ToThaiNumber(),
ConclusionFireDate = r.Command.ConclusionFireDate == null ? "" : r.Command.ConclusionFireDate.Value.ToThaiFullDate3().ToThaiNumber(),
ConclusionFireResolution = r.Command.ConclusionFireResolution == null ? "" : r.Command.ConclusionFireResolution.ToThaiNumber()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType21Response>> GetCommandType21AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<OrganizationEmployeeProfile>()
.Include(x => x.Profile)
.ThenInclude(x => x.Position)
.Include(x => x.Profile)
.ThenInclude(x => x.PositionLevel)
.Include(x => x.Profile)
.ThenInclude(x => x.PositionType)
.Include(x => x.Profile)
.ThenInclude(x => x.PosNo)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.OrganizationAgency)
.ThenInclude(x => x.OrganizationOrganization)
//.Include(x => x.OrgEmployee)
//.ThenInclude(x => x.PosNo)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.PositionEmployeePosition)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.OrganizationPositionEmployeeLevels)
.ThenInclude(x => x.PositionEmployeeLevel)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType21Response
{
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId.ToThaiNumber(),
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Organization = p.OrgEmployee == null || p.OrgEmployee!.OrganizationAgency == null || p.OrgEmployee!.OrganizationAgency!.OrganizationOrganization == null ? "" : p.OrgEmployee!.OrganizationAgency!.OrganizationOrganization!.Name,
PositionName = p.OrgEmployee == null || p.OrgEmployee.PositionEmployeePosition == null ? "" : p.OrgEmployee.PositionEmployeePosition.Name.ToThaiNumber(),
PositionLevel = p.OrgEmployee == null || p.OrgEmployee.OrganizationPositionEmployeeLevels == null ? "" : p.OrgEmployee.OrganizationPositionEmployeeLevels.First().PositionEmployeeLevel.Name.ToThaiNumber(),
PositionType = p.Profile.PositionType == null ? "" : p.Profile.PositionType.Name.ToThaiNumber(),
PositionNumber = p.OrgEmployee.PosNo == null ? "" : p.OrgEmployee.PosNo.ToThaiNumber(),
Salary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
RetireDate = p.Profile.BirthDate.CalculateRetireDate().ToThaiFullDate3().ToThaiNumber(),
CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType22Response>> GetCommandType22AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementAppointment>()
// .Include(x => x.Profile)
// .ThenInclude(x => x.Position)
// .Include(x => x.Profile)
// .ThenInclude(x => x.PositionLevel)
// .Include(x => x.Profile)
// .ThenInclude(x => x.PositionType)
// .Include(x => x.Profile)
// .ThenInclude(x => x.PosNo)
// .Include(x => x.OrgEmployee)
// .ThenInclude(x => x.OrganizationAgency)
// .ThenInclude(x => x.OrganizationOrganization)
// //.Include(x => x.OrgEmployee)
// //.ThenInclude(x => x.PosNo)
// .Include(x => x.OrgEmployee)
// .ThenInclude(x => x.PositionEmployeePosition)
// .Include(x => x.OrgEmployee)
// .ThenInclude(x => x.OrganizationPositionEmployeeLevels)
// .ThenInclude(x => x.PositionEmployeeLevel)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType22Response
{
Seq = r.Sequence.ToString().ToThaiNumber(),
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Organization = p.rootOld,
OldPositionName = p.OrganizationPositionOld,
OldPositionLevel = p.PositionLevelOld,
OldPositionNumber = p.PositionNumberOld == null ? null : p.PositionNumberOld.ToThaiNumber(),
OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
NewOc = p.root == null ? "" : p.root,
NewPositionName = p.position == null ? "" : p.position,
NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName,
// NewPositionType = p.posTypeName == null ? "" : p.posTypeName,
NewPositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
Reason = p.Reason == null ? "-" : p.Reason,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType21Response>> GetCommandType23AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementResign>()
//.Include(x => x.Profile)
//.ThenInclude(x => x.Position)
//.Include(x => x.Profile)
//.ThenInclude(x => x.PositionLevel)
//.Include(x => x.Profile)
//.ThenInclude(x => x.PositionType)
//.Include(x => x.Profile)
//.ThenInclude(x => x.PosNo)
//.Include(x => x.Profile)
//.ThenInclude(x => x.PositionEmployeePosition)
//.Include(x => x.Profile)
//.ThenInclude(x => x.PositionEmployeeLevel)
//.Include(x => x.OrgEmployee)
//.ThenInclude(x => x.OrganizationAgency)
//.ThenInclude(x => x.OrganizationOrganization)
//.Include(x => x.OrgEmployee)
//.ThenInclude(x => x.PosNo)
//.Include(x => x.OrgEmployee)
//.ThenInclude(x => x.PositionEmployeePosition)
//.Include(x => x.OrgEmployee)
//.ThenInclude(x => x.OrganizationPositionEmployeeLevels)
//.ThenInclude(x => x.PositionEmployeeLevel)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType21Response
{
Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId.ToThaiNumber(),
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Organization = p.OrganizationPositionOld ?? "",
PositionName = p.PositionOld ?? "",
PositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld.ToThaiNumber(),
PositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld.ToThaiNumber(),
PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(),
Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
RetireDate = p.ActiveDate == null ? "" : p.ActiveDate.Value.ToThaiFullDate3().ToThaiNumber(),
CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(),
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType22Response>> GetCommandType24AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementAppointment>()
// .Include(x => x.Profile)
// .ThenInclude(x => x.Position)
// .Include(x => x.Profile)
// .ThenInclude(x => x.PositionLevel)
// .Include(x => x.Profile)
// .ThenInclude(x => x.PositionType)
// .Include(x => x.Profile)
// .ThenInclude(x => x.PosNo)
// .Include(x => x.OrgEmployee)
// .ThenInclude(x => x.OrganizationAgency)
// .ThenInclude(x => x.OrganizationOrganization)
// //.Include(x => x.OrgEmployee)
// //.ThenInclude(x => x.PosNo)
// .Include(x => x.OrgEmployee)
// .ThenInclude(x => x.PositionEmployeePosition)
// .Include(x => x.OrgEmployee)
// .ThenInclude(x => x.OrganizationPositionEmployeeLevels)
// .ThenInclude(x => x.PositionEmployeeLevel)
on r.RefPlacementProfileId equals p.Id
orderby r.Sequence
select new CommandType22Response
{
Seq = r.Sequence.ToString().ToThaiNumber(),
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Organization = p.OrganizationPositionOld,
OldPositionName = p.OrganizationPositionOld,
OldPositionLevel = p.PositionLevelOld,
OldPositionNumber = p.PositionNumberOld == null ? null : p.PositionNumberOld.ToThaiNumber(),
OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
NewOc = p.root == null ? "" : p.root,
NewPositionName = p.position == null ? "" : p.position,
NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName,
// NewPositionType = p.posTypeName == null ? "" : p.posTypeName,
NewPositionNumber = p.posMasterNo == null ? "" :
p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() :
p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "",
NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
Reason = p.Reason == null ? "-" : p.Reason,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<CommandType23Response?> GetCommandType25AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
orderby r.Sequence
select new CommandType23Response
{
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Positionname = pf.Position == null ? "" : pf.Position.Name,
Positionno = pf.PosNo == null ? "" : pf.PosNo.Name,
Organizationname = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
Salary = pf.Salaries == null || pf.Salaries.Count == 0 || pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount == null ? "" : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
}).FirstOrDefault();
return report_data;
}
catch
{
throw;
}
}
#endregion
}
}