แก้ Defect

This commit is contained in:
Suphonchai Phoonsawat 2023-11-24 14:21:33 +07:00
parent 5ae67ee02e
commit 0096e6dd5b
8 changed files with 184 additions and 97 deletions

View file

@ -140,13 +140,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
return data.Count;
}
public async Task<List<ProcessUserTimeStamp>> GetTimeStampHistoryForAdminAsync(DateTime startDate, DateTime endDate, int page = 1, int pageSize = 10, string keyword = "")
public async Task<List<ProcessUserTimeStamp>> GetTimeStampHistoryForAdminAsync(DateTime startDate, DateTime endDate)
{
var data = await _dbContext.Set<ProcessUserTimeStamp>()
.Where(u => u.CheckIn.Date >= startDate.Date && u.CheckIn.Date <= endDate.Date)
.OrderBy(u => u.CheckIn)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToListAsync();
return data;

View file

@ -84,26 +84,24 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
return data;
}
public async Task<List<UserTimeStamp>> GetTimeStampHistoryAsync(Guid keycloakId, int year, int page = 1, int pageSize = 10, string keyword = "")
public async Task<List<UserTimeStamp>> GetTimeStampHistoryAsync(Guid keycloakId, int year)
{
var data = await _dbContext.Set<UserTimeStamp>()
.Where(u => u.KeycloakUserId == keycloakId)
.Where(u => u.CheckIn.Year == year)
.OrderBy(u => u.CheckIn)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToListAsync();
return data;
}
public async Task<List<UserTimeStamp>> GetTimeStampHistoryForAdminAsync(DateTime startDate, DateTime endDate, int page = 1, int pageSize = 10, string keyword = "")
public async Task<List<UserTimeStamp>> GetTimeStampHistoryForAdminAsync(DateTime startDate, DateTime endDate)
{
var data = await _dbContext.Set<UserTimeStamp>()
.Where(u => u.CheckIn.Date >= startDate.Date && u.CheckIn.Date <= endDate.Date)
.OrderBy(u => u.CheckIn)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToListAsync();
return data;

View file

@ -129,7 +129,7 @@ namespace BMA.EHR.DisciplineComplaint.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (_data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
var disciplineComplaintDocs = new List<dynamic>();
foreach (var doc in _data.DisciplineComplaintDocs)
@ -241,9 +241,9 @@ namespace BMA.EHR.DisciplineComplaint.Service.Controllers
{
var data = await _context.DisciplineComplaints.Include(x => x.DisciplineComplaint_Profiles).Where(x => x.Id == id).FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
data.RespondentType = req.respondentType.Trim().ToUpper();
data.Organization = req.organizationId;
@ -309,7 +309,7 @@ namespace BMA.EHR.DisciplineComplaint.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
_context.DisciplineComplaints.Remove(data);
// var _docId = data.Document.Id;
// await _context.SaveChangesAsync();
@ -333,9 +333,9 @@ namespace BMA.EHR.DisciplineComplaint.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), StatusCodes.Status500InternalServerError);
data.Status = "STOP";
await _context.SaveChangesAsync();
@ -361,9 +361,9 @@ namespace BMA.EHR.DisciplineComplaint.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถส่งต่อไปสืบสวนได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถส่งต่อไปสืบสวนได้"), StatusCodes.Status500InternalServerError);
data.Status = "SEND_INVESTIGATE";
var disciplineInvestigate = new Domain.Models.Discipline.DisciplineInvestigate
@ -449,9 +449,9 @@ namespace BMA.EHR.DisciplineComplaint.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "STOP")
return Error(new Exception("รายการนี้ยังไม่ถูกยุติเรื่อง"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("รายการนี้ยังไม่ถูกยุติเรื่อง"), StatusCodes.Status500InternalServerError);
data.Status = "NEW";
await _context.SaveChangesAsync();
@ -473,9 +473,9 @@ namespace BMA.EHR.DisciplineComplaint.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
@ -523,9 +523,9 @@ namespace BMA.EHR.DisciplineComplaint.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
var dataDoc = data.DisciplineComplaint_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
if (dataDoc != null)
{

View file

@ -90,7 +90,7 @@ namespace BMA.EHR.DisciplineComplaint_Channel.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
return Success(data);
}
@ -133,11 +133,11 @@ namespace BMA.EHR.DisciplineComplaint_Channel.Service.Controllers
{
var data = await _context.DisciplineComplaint_Channels.Where(x => x.Id == id).FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
var dupicateData = await _context.DisciplineComplaint_Channels.Where(x => x.Id != id && x.Name == req.name).FirstOrDefaultAsync();
if (dupicateData != null)
return Error(new Exception("ชื่อประเภทนี้มีอยู่ในระบบแล้ว"), (int)StatusCodes.Status400BadRequest);
return Error(new Exception("ชื่อประเภทนี้มีอยู่ในระบบแล้ว"), StatusCodes.Status400BadRequest);
data.Name = req.name;
data.LastUpdateFullName = FullName ?? "System Administrator";
@ -160,7 +160,7 @@ namespace BMA.EHR.DisciplineComplaint_Channel.Service.Controllers
{
var data = await _context.DisciplineComplaint_Channels.Where(x => x.Id == id).FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
_context.DisciplineComplaint_Channels.Remove(data);
await _context.SaveChangesAsync();
return Success();

View file

@ -105,7 +105,7 @@ namespace BMA.EHR.DisciplineDirector.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
return Success(data);
}
@ -153,7 +153,7 @@ namespace BMA.EHR.DisciplineDirector.Service.Controllers
{
var data = await _context.DisciplineDirectors.Where(x => x.Id == id).FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
data.Prefix = req.prefix;
data.FirstName = req.firstName;
@ -181,7 +181,7 @@ namespace BMA.EHR.DisciplineDirector.Service.Controllers
{
var data = await _context.DisciplineDirectors.Where(x => x.Id == id).FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
_context.DisciplineDirectors.Remove(data);
await _context.SaveChangesAsync();
return Success();

View file

@ -137,7 +137,7 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (_data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
var disciplineInvestigateDocComplaints = new List<dynamic>();
foreach (var doc in _data.DisciplineInvestigateDocComplaints)
@ -187,9 +187,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
{
var data = await _context.DisciplineInvestigates.Include(x => x.DisciplineInvestigate_Profiles).Where(x => x.Id == id).FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
data.Title = req.title;
data.Description = req.description;
@ -273,7 +273,7 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (_data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
var disciplineInvestigateDocs = new List<dynamic>();
foreach (var doc in _data.DisciplineInvestigateDocs)
@ -335,9 +335,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
data.InvestigationDetail = req.investigationDetail.Trim().ToUpper();
data.InvestigationDetailOther = req.investigationDetailOther;
@ -390,11 +390,11 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), StatusCodes.Status500InternalServerError);
if (data.InvestigationStatusResult == null || data.InvestigationStatusResult.Trim().ToUpper() != "NO_CAUSE")
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), StatusCodes.Status500InternalServerError);
data.Status = "STOP";
await _context.SaveChangesAsync();
@ -416,9 +416,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถส่งต่อไปสืบสวนได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถส่งต่อไปสืบสวนได้"), StatusCodes.Status500InternalServerError);
data.Status = "SEND_INVESTIGATE";
await _context.SaveChangesAsync();
@ -440,9 +440,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "STOP")
return Error(new Exception("รายการนี้ยังไม่ถูกยุติเรื่อง"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("รายการนี้ยังไม่ถูกยุติเรื่อง"), StatusCodes.Status500InternalServerError);
data.Status = "NEW";
await _context.SaveChangesAsync();
@ -464,9 +464,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
@ -514,9 +514,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
var dataDoc = data.DisciplineInvestigate_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
if (dataDoc != null)
{
@ -543,9 +543,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
@ -596,9 +596,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
var dataDoc = data.DisciplineInvestigate_DocComplaints.Where(x => x.Document.Id == docId).FirstOrDefault();
if (dataDoc != null)
{
@ -629,9 +629,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
@ -679,9 +679,9 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
if (data.Status.Trim().ToUpper() != "NEW")
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
var dataDoc = data.DisciplineInvestigateRelevant_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
if (dataDoc != null)
{

View file

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System.ComponentModel.DataAnnotations;
using System.DirectoryServices.ActiveDirectory;
using System.Security.Claims;
using System.Security.Permissions;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
@ -402,7 +403,7 @@ namespace BMA.EHR.Leave.Service.Controllers
if (currentCheckIn != null)
{
return Error(new Exception("ไม่สามารถลงเวลาได้ เนืองจากมีการลงเวลาในวันนี้แล้ว!"), (int)StatusCodes.Status400BadRequest);
return Error(new Exception("ไม่สามารถลงเวลาได้ เนืองจากมีการลงเวลาในวันนี้แล้ว!"), StatusCodes.Status400BadRequest);
}
@ -457,7 +458,7 @@ namespace BMA.EHR.Leave.Service.Controllers
}
else
{
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
}
if (checkout_process != null)
@ -475,7 +476,7 @@ namespace BMA.EHR.Leave.Service.Controllers
}
else
{
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
}
}
@ -499,18 +500,27 @@ namespace BMA.EHR.Leave.Service.Controllers
{
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
// TODO : รอดุึงรอบที่ผูกกับ user
var duty = await _dutyTimeRepository.GetDefaultAsync();
if (duty == null)
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId);
if (profile == null)
{
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
if (defaultRound == null)
{
return Error("ไม่พบรอบการลงเวลาทำงาน Default", StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
// TODO : รอดุึงรอบที่ผูกกับ user
var duty = userRound ?? defaultRound;
var checkin_base = DateTime.Parse($"{DateTime.Now.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}");
var checkout_base = DateTime.Parse($"{DateTime.Now.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}");
var data = (await _userTimeStampRepository.GetTimeStampHistoryAsync(userId, year, page, pageSize, keyword))
var data = (await _userTimeStampRepository.GetTimeStampHistoryAsync(userId, year))
.Select(d => new CheckInHistoryDto
{
CheckInId = d.Id,
@ -533,7 +543,17 @@ namespace BMA.EHR.Leave.Service.Controllers
})
.ToList();
return Success(data);
if (keyword != "")
{
data = data.Where(x => (x.CheckInLocation.Contains(keyword) || x.CheckOutLocation.Contains(keyword))).ToList();
}
var pageData = data
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
return Success(new { data = pageData, total = data.Count });
}
/// <summary>
@ -552,14 +572,14 @@ namespace BMA.EHR.Leave.Service.Controllers
{
if (startDate.Date > endDate.Date)
{
return Error(new Exception("วันเริ่มต้นต้องมีค่าน้อยกว่าหรือเท่ากับวันสิ้นสุด"), (int)StatusCodes.Status400BadRequest);
return Error(new Exception("วันเริ่มต้นต้องมีค่าน้อยกว่าหรือเท่ากับวันสิ้นสุด"), StatusCodes.Status400BadRequest);
}
var count = await _userTimeStampRepository.CountRecordAsync();
//var count = await _userTimeStampRepository.CountRecordAsync();
var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}";
var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate, page, pageSize, keyword))
var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate))
.Select(d => new CheckInHistoryForAdminDto
{
Id = d.Id,
@ -581,8 +601,18 @@ namespace BMA.EHR.Leave.Service.Controllers
})
.ToList();
if (keyword != "")
{
data = data.Where(x => x.FullName.Contains(keyword)).ToList();
}
return Success(new { data = data, total = count });
var pageData = data
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
return Success(new { data = pageData, total = data.Count });
}
/// <summary>
@ -600,6 +630,8 @@ namespace BMA.EHR.Leave.Service.Controllers
public async Task<ActionResult<ResponseObject>> GetTimeRecordAsync([Required] Guid id)
{
var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}";
var d = (await _userTimeStampRepository.GetTimeStampById(id));
if (d == null)
{
@ -607,24 +639,52 @@ namespace BMA.EHR.Leave.Service.Controllers
}
else
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(d.KeycloakUserId);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
if (defaultRound == null)
{
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var duty = userRound ?? defaultRound;
var result = new CheckInDetailForAdminDto
{
Id = d.Id,
FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId),
CheckInDate = d.CheckIn.Date,
CheckInTime = d.CheckIn.ToString("HH:mm:ss"),
CheckInLocation = d.CheckInPOI,
CheckInTime = d.CheckIn.ToString("HH:mm"),
CheckInPOI = d.CheckInPOI,
CheckInLat = d.CheckInLat,
CheckInLon = d.CheckInLon,
CheckInImg = $"{imgUrl}/{d.CheckInImageUrl}",
CheckInStatus = DateTime.Parse(d.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
"LATE" :
"NORMAL",
CheckInDescription = d.CheckInRemark ?? "",
CheckOutDate = d.CheckOut == null ? null : d.CheckOut.Value.Date,
CheckOutTime = d.CheckOut == null ? "" : d.CheckOut.Value.ToString("HH:mm:ss"),
CheckOutLocation = d.CheckOut == null ? "" : d.CheckOutPOI,
CheckOutTime = d.CheckOut == null ? "" : d.CheckOut.Value.ToString("HH:mm"),
CheckOutPOI = d.CheckOut == null ? "" : d.CheckOutPOI,
CheckOutLat = d.CheckOut == null ? null : d.CheckOutLat,
CheckOutLon = d.CheckOut == null ? null : d.CheckOutLon,
CheckOutImg = d.CheckOut == null ? "" : $"{imgUrl}/{d.CheckOutImageUrl}",
CheckOutStatus = d.CheckOut == null ? null :
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
"LATE" :
"NORMAL",
CheckOutDescription = d.CheckOutRemark ?? "",
};
return Success(result);
@ -649,33 +709,41 @@ namespace BMA.EHR.Leave.Service.Controllers
{
if (startDate.Date > endDate.Date)
{
return Error(new Exception("วันเริ่มต้นต้องมีค่าน้อยกว่าหรือเท่ากับวันสิ้นสุด"), (int)StatusCodes.Status400BadRequest);
return Error(new Exception("วันเริ่มต้นต้องมีค่าน้อยกว่าหรือเท่ากับวันสิ้นสุด"), StatusCodes.Status400BadRequest);
}
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
// TODO : รอดุึงรอบที่ผูกกับ user
var duty = await _dutyTimeRepository.GetDefaultAsync();
if (duty == null)
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId);
if (profile == null)
{
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
if (defaultRound == null)
{
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var duty = userRound ?? defaultRound;
var checkin_base = DateTime.Parse($"{DateTime.Now.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}");
var checkout_base = DateTime.Parse($"{DateTime.Now.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}");
var count = await _processUserTimeStampRepository.GetTimeStampHistoryForAdminCountAsync(startDate, endDate);
//var count = await _processUserTimeStampRepository.GetTimeStampHistoryForAdminCountAsync(startDate, endDate);
var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}";
var data = (await _processUserTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate, page, pageSize, keyword))
var data = (await _processUserTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate))
.Select(d => new CheckInProcessHistoryForAdminDto
{
Id = d.Id,
FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId),
CheckInDate = d.CheckIn.Date,
CheckInTime = d.CheckIn.ToString("HH:mm:ss"),
CheckInTime = d.CheckIn.ToString("HH:mm"),
CheckInLocation = d.CheckInPOI,
CheckInLat = d.CheckInLat,
CheckInLon = d.CheckInLon,
@ -686,7 +754,7 @@ namespace BMA.EHR.Leave.Service.Controllers
//CheckInImageUrl = $"{imgUrl}/{d.CheckInImageUrl}",
CheckOutDate = d.CheckOut == null ? null : d.CheckOut.Value.Date,
CheckOutTime = d.CheckOut == null ? "" : d.CheckOut.Value.ToString("HH:mm:ss"),
CheckOutTime = d.CheckOut == null ? "" : d.CheckOut.Value.ToString("HH:mm"),
CheckOutLocation = d.CheckOut == null ? "" : d.CheckOutPOI,
CheckOutLat = d.CheckOut == null ? null : d.CheckOutLat,
CheckOutLon = d.CheckOut == null ? null : d.CheckOutLon,
@ -696,11 +764,25 @@ namespace BMA.EHR.Leave.Service.Controllers
"NORMAL",
//CheckOutImageUrl = d.CheckOut == null ? "" : $"{imgUrl}/{d.CheckOutImageUrl}",
})
.Where(x => x.CheckInStatus == status || x.CheckOutStatus == status)
.ToList();
if (keyword != "")
{
data = data.Where(x => x.FullName.Contains(keyword)).ToList();
}
return Success(new { data = data, total = count });
if (status.Trim().ToUpper() != "ALL")
{
data = data.Where(x => x.CheckInStatus == status || x.CheckOutStatus == status).ToList();
}
var pageData = data
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
return Success(new { data = pageData, total = data.Count });
}
#endregion
@ -766,14 +848,14 @@ namespace BMA.EHR.Leave.Service.Controllers
{
if (req.EffectiveDate.Date < DateTime.Now.Date)
{
return Error(new Exception("วันมีผลต้องมากกว่าหรือเท่ากับวันที่ปัจจุบัน"), (int)StatusCodes.Status400BadRequest);
return Error(new Exception("วันที่มีผลต้องมากกว่าหรือเท่ากับวันที่ปัจจุบัน"), StatusCodes.Status400BadRequest);
}
var old = await _userDutyTimeRepository.GetExist(req.ProfileId, req.EffectiveDate);
if (old != null)
{
return Error(new Exception("ไม่สามารถทำรายการได้ เนื่องจากมีการกำหนดรอบการทำงานในวันที่นี้ไว้แล้ว"), (int)StatusCodes.Status400BadRequest);
return Error(new Exception("ไม่สามารถทำรายการได้ เนื่องจากมีการกำหนดรอบการทำงานในวันที่นี้ไว้แล้ว"), StatusCodes.Status400BadRequest);
}
var data = new UserDutyTime
@ -852,7 +934,7 @@ namespace BMA.EHR.Leave.Service.Controllers
{
if (req.CheckDate.Date > DateTime.Now.Date)
{
return Error("ไม่สามารถขอลงเวลากรณีพิเศษในวันที่มากกว่าวันที่ปัจจุบันได้", (int)StatusCodes.Status400BadRequest);
return Error("ไม่สามารถขอลงเวลากรณีพิเศษในวันที่มากกว่าวันที่ปัจจุบันได้", StatusCodes.Status400BadRequest);
}
var request = new AdditionalCheckRequest
@ -886,7 +968,7 @@ namespace BMA.EHR.Leave.Service.Controllers
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
if (getDefaultRound == null)
{
return Error("ไม่พบรอบลงเวลา Default", (int)StatusCodes.Status404NotFound);
return Error("ไม่พบรอบลงเวลา Default", StatusCodes.Status404NotFound);
}
var result = new List<GetAdditionalCheckRequestDto>();
@ -896,7 +978,7 @@ namespace BMA.EHR.Leave.Service.Controllers
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, (int)StatusCodes.Status404NotFound);
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var checkInData = await _userTimeStampRepository.GetTimestampByDateAsync(data.KeycloakUserId, data.CheckDate);
@ -971,13 +1053,13 @@ namespace BMA.EHR.Leave.Service.Controllers
{
if (req.Reason == null || req.Reason == string.Empty)
{
return Error("กรุณากรอกเหตุผล", (int)StatusCodes.Status400BadRequest);
return Error("กรุณากรอกเหตุผล", StatusCodes.Status400BadRequest);
}
var requestData = await _additionalCheckRequestRepository.GetByIdAsync(id);
if (requestData == null)
{
return Error(GlobalMessages.DataNotFound, (int)StatusCodes.Status404NotFound);
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
requestData.Status = "APPROVE";
@ -1016,7 +1098,7 @@ namespace BMA.EHR.Leave.Service.Controllers
processTimeStamp.CheckInRemark = req.Reason;
processTimeStamp.CheckInLat = 0;
processTimeStamp.CheckInLon = 0;
processTimeStamp.CheckInPOI = "ลงเวลากรณีพิเศษ";
processTimeStamp.CheckInPOI = "ลงเวลากรณีพิเศษ";
}
if (requestData.CheckOutEdit)
@ -1047,13 +1129,13 @@ namespace BMA.EHR.Leave.Service.Controllers
{
if (req.Reason == null || req.Reason == string.Empty)
{
return Error("กรุณากรอกเหตุผล", (int)StatusCodes.Status400BadRequest);
return Error("กรุณากรอกเหตุผล", StatusCodes.Status400BadRequest);
}
var requestData = await _additionalCheckRequestRepository.GetByIdAsync(id);
if (requestData == null)
{
return Error(GlobalMessages.DataNotFound, (int)StatusCodes.Status404NotFound);
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
requestData.Status = "REJECT";

View file

@ -8,9 +8,11 @@
public DateTime? CheckInDate { get; set; } = DateTime.MinValue;
public string? CheckInStatus { get; set; } = string.Empty;
public string? CheckInTime { get; set; } = "00:00";
public string? CheckInLocation { get; set; } = string.Empty;
public string? CheckInPOI { get; set; } = string.Empty;
public double? CheckInLat { get; set; } = 0;
@ -18,16 +20,22 @@
public string? CheckInImg { get; set; } = string.Empty;
public string CheckInDescription { get; set; } = string.Empty;
public DateTime? CheckOutDate { get; set; } = DateTime.MinValue;
public string? CheckOutStatus { get; set; } = string.Empty;
public string? CheckOutTime { get; set; } = "00:00";
public string? CheckOutLocation { get; set; } = string.Empty;
public string? CheckOutPOI { get; set; } = string.Empty;
public double? CheckOutLat { get; set; } = 0;
public double? CheckOutLon { get; set; } = 0;
public string? CheckOutImg { get; set; } = string.Empty;
public string? CheckOutDescription { get; set; } = string.Empty;
}
}