191 lines
9.7 KiB
C#
191 lines
9.7 KiB
C#
using BMA.EHR.Application.Common.Interfaces;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.Retirement;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BMA.EHR.Application.Repositories.Reports
|
|
{
|
|
public class RetireReportRepository
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly IApplicationDBContext _dbContext;
|
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
|
|
|
#endregion
|
|
|
|
#region " Constructor and Destructor "
|
|
|
|
public RetireReportRepository(IApplicationDBContext dbContext, IWebHostEnvironment hostEnvironment)
|
|
{
|
|
_dbContext = dbContext;
|
|
_hostingEnvironment = hostEnvironment;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
|
|
//public async Task<List<RetirementPeriod>> GetListRetirePeriodAsync(Guid Id)
|
|
//{
|
|
// try
|
|
// {
|
|
// // 1. query
|
|
// //var data = await _dbContext.Set<RetirementPeriod>()
|
|
// // .Include(x => x.RetirementProfiles)
|
|
// // .ThenInclude(x => x.Profile)
|
|
// // .ToListAsync();
|
|
|
|
// // 2. data not found throw exception
|
|
|
|
// // 3. Load Report File
|
|
|
|
// //return data;
|
|
// }
|
|
// catch
|
|
// {
|
|
// throw;
|
|
// }
|
|
//}
|
|
|
|
#region รายงานประกาศเกษียณ
|
|
public async Task<dynamic> GetProfileRetirementdAsync(Guid retireId)
|
|
{
|
|
var retire = await _dbContext.Set<RetirementPeriod>()
|
|
.Include(x => x.RetirementProfiles)
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retire == null)
|
|
{
|
|
var retireHistorys = await _dbContext.Set<RetirementPeriodHistory>().AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retireHistorys == null)
|
|
return null;
|
|
|
|
var profile_retireHistory = await _dbContext.Set<RetirementProfile>()
|
|
.Where(x => x.RetirementPeriod == retire)
|
|
.OrderBy(x => x.Order)
|
|
.Select(x => new
|
|
{
|
|
order = x.Order,
|
|
id = x.Id,
|
|
reason = x.Reason,
|
|
remove = x.Remove,
|
|
profileId = x.Profile.Id,
|
|
citizenId = x.Profile.CitizenId,
|
|
prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name,
|
|
fullName = $"{x.Profile.FirstName} {x.Profile.LastName}",
|
|
organizationOrganization = x.Profile.OrganizationOrganization,
|
|
oc = x.Profile.Oc,
|
|
position = x.Profile.Position == null ? null : x.Profile.Position.Name,
|
|
positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name,
|
|
positionExecutive = x.Profile.PositionExecutive,
|
|
posNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name,
|
|
positionEmployeePosition = x.Profile.PositionEmployeePosition,
|
|
positionEmployeeLevel = x.Profile.PositionEmployeeLevel,
|
|
positionEmployeeGroup = x.Profile.PositionEmployeeGroup,
|
|
posNoEmployee = x.Profile.PosNoEmployee,
|
|
})
|
|
.ToListAsync();
|
|
|
|
return new { retireHistorys.Id, retireHistorys.CreatedAt, Year = retireHistorys.Year.ToThaiYear().ToString().ToThaiNumber(), retireHistorys.Round, retireHistorys.Type, retireHistorys.TypeReport, Total = retireHistorys.Total.ToString().ToThaiNumber(), profile = profile_retireHistory };
|
|
|
|
}
|
|
else
|
|
{
|
|
var profile_retire = await _dbContext.Set<RetirementProfile>()
|
|
.Where(x => x.RetirementPeriod == retire)
|
|
.OrderBy(x => x.Order)
|
|
.Select(x => new
|
|
{
|
|
order = x.Order,
|
|
id = x.Id,
|
|
reason = x.Reason,
|
|
remove = x.Remove,
|
|
profileId = x.Profile.Id,
|
|
citizenId = x.Profile.CitizenId,
|
|
prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name,
|
|
fullName = $"{x.Profile.FirstName} {x.Profile.LastName}",
|
|
organizationOrganization = x.Profile.OrganizationOrganization,
|
|
oc = x.Profile.Oc,
|
|
position = x.Profile.Position == null ? null : x.Profile.Position.Name,
|
|
positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name,
|
|
positionExecutive = x.Profile.PositionExecutive,
|
|
posNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name,
|
|
positionEmployeePosition = x.Profile.PositionEmployeePosition,
|
|
positionEmployeeLevel = x.Profile.PositionEmployeeLevel,
|
|
positionEmployeeGroup = x.Profile.PositionEmployeeGroup,
|
|
posNoEmployee = x.Profile.PosNoEmployee,
|
|
})
|
|
.ToListAsync();
|
|
|
|
return new { retire.Id, retire.CreatedAt, Year = retire.Year.ToThaiYear().ToString().ToThaiNumber(), retire.Round, retire.Type, retire.TypeReport, Total = profile_retire.Count.ToString().ToThaiNumber(), profile = profile_retire };
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region รายงานบันทึกการถึงแก่กรรม
|
|
public async Task<dynamic> GetRetirementDeceasedAsync(Guid id)
|
|
{
|
|
var data = await _dbContext.Set<RetirementDeceased>().AsQueryable()
|
|
.Where(x => x.Id == id)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
ProfileId = p.Profile.Id,
|
|
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
|
|
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
|
|
p.Profile.FirstName,
|
|
p.Profile.LastName,
|
|
Position = p.Profile.Position == null ? null : p.Profile.Position.Name,
|
|
PositionId = p.Profile.Position == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Position.Id,
|
|
PositionType = p.Profile.PositionType == null ? null : p.Profile.PositionType.Name,
|
|
PositionTypeId = p.Profile.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.PositionType.Id,
|
|
p.Profile.PositionLine,
|
|
p.Profile.PositionLineId,
|
|
PositionLevel = p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name,
|
|
PositionLevelId = p.Profile.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.PositionLevel.Id,
|
|
p.Profile.PositionExecutive,
|
|
p.Profile.PositionExecutiveId,
|
|
Organization = p.Profile.Oc,
|
|
OrganizationId = p.Profile.OcId,
|
|
p.Number,
|
|
p.Date,
|
|
p.Location,
|
|
p.Reason,
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (data == null)
|
|
return null;
|
|
|
|
string Date = string.IsNullOrEmpty(data.Date.ToString()) ? "วันที่ - เดือน - พ.ศ. -" : DateTime.Parse(data.Date.ToString()).ToThaiFullDate().ToString().ToThaiNumber();
|
|
return new
|
|
{
|
|
data.Prefix,
|
|
data.FirstName,
|
|
data.LastName,
|
|
data.Position,
|
|
data.PositionExecutive,
|
|
data.PositionType,
|
|
data.PositionLine,
|
|
data.PositionLevel,
|
|
data.Organization,
|
|
data.PositionId,
|
|
data.PositionExecutiveId,
|
|
data.PositionTypeId,
|
|
data.PositionLineId,
|
|
data.PositionLevelId,
|
|
data.OrganizationId,
|
|
data.Number,
|
|
Date,
|
|
data.Location,
|
|
data.Reason,
|
|
};
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|