แก้ ลาออกลูกจ้าง

This commit is contained in:
kittapath 2024-11-15 15:11:14 +07:00
parent c18d9a392a
commit b303d3c11b
12 changed files with 20556 additions and 68 deletions

View file

@ -140,8 +140,8 @@ namespace BMA.EHR.Leave.Service.Controllers
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
//var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
//var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type);
if (leaveType == null)
@ -149,9 +149,9 @@ namespace BMA.EHR.Leave.Service.Controllers
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var sumLeave = req.LeaveStartDate.DiffDay(req.LeaveEndDate);
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(req.LeaveStartDate, req.LeaveEndDate, category);
var sumWeekend = _holidayRepository.GetWeekEndCount(req.LeaveStartDate, req.LeaveEndDate, category);
//var sumLeave = req.LeaveStartDate.DiffDay(req.LeaveEndDate);
//var sumHoliday = await _holidayRepository.GetHolidayCountAsync(req.LeaveStartDate, req.LeaveEndDate, category);
//var sumWeekend = _holidayRepository.GetWeekEndCount(req.LeaveStartDate, req.LeaveEndDate, category);
// var leaveTotal = 0.0;
// if (req.LeaveRange != "ALL")
@ -195,6 +195,12 @@ namespace BMA.EHR.Leave.Service.Controllers
Child2 = profile.Child2,
Child3 = profile.Child3,
Child4 = profile.Child4,
ProfileId = profile.Id,
ProfileType = profile.ProfileType,
Amount = profile.Amount,
BirthDate = profile.BirthDate,
DateAppoint = profile.DateAppoint,
};
// get leave last
@ -1543,17 +1549,35 @@ namespace BMA.EHR.Leave.Service.Controllers
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/workflow/add-workflow";
using (var client = new HttpClient())
if (profile.ProfileType == "OFFICER")
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
using (var client = new HttpClient())
{
refId = id,
sysName = "SYS_LEAVE_LIST",
posLevelName = profile.PosLevel?.PosLevelName ?? "",
posTypeName = profile.PosType?.PosTypeName ?? "",
});
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
refId = id,
sysName = "SYS_LEAVE_LIST",
posLevelName = profile.PosLevel?.PosLevelName ?? "",
posTypeName = profile.PosType?.PosTypeName ?? "",
});
}
}
else
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
refId = id,
sysName = "SYS_LEAVE_LIST_EMP",
posLevelName = "EMP",
posTypeName = "EMP",
});
}
}
return Success();
@ -1599,66 +1623,76 @@ namespace BMA.EHR.Leave.Service.Controllers
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetLeaveRequestForAdminByIdAsync(Guid id)
{
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_LEAVE_LIST");
if (getWorkflow == false)
var rawData = await _leaveRequestRepository.GetByIdAsync(id);
if (rawData == null)
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
if (rawData.ProfileType =="OFFICER")
{
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_LEAVE_LIST");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_LEAVE_LIST");
if (getWorkflow == false)
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_LEAVE_LIST");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
}
}
else
{
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_LEAVE_LIST_EMP");
if (getWorkflow == false)
{
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_LEAVE_LIST");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
}
}
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
var rawData = await _leaveRequestRepository.GetByIdAsync(id);
var thisYear = DateTime.Now.Year;
if (rawData == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
//var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken);
//if (profile == null)
//{
// return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
//}
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
//var userCalendar = await _userCalendarRepository.GetExist(Guid.Parse(rawData.ProfileId));
//var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
var lastSalary = profile.ProfileSalary;
var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount ?? 0;
//var lastSalary = profile.ProfileSalary;
//var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount ?? 0;
var lastLeaveRequest =
await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync(rawData.KeycloakUserId,
rawData.Type.Id);
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken);
var approver = string.Empty;
if (rootOc != null)
{
var list = await _commandRepository.GetOrgApproverAsync(rootOc ?? Guid.Empty);
if (list.Count > 0)
approver = list.First().Name;
}
//var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken);
//var approver = string.Empty;
//if (rootOc != null)
//{
//var list = await _commandRepository.GetOrgApproverAsync(rootOc ?? Guid.Empty);
//if (list.Count > 0)
//approver = list.First().Name;
//}
var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveByTypeForUserAsync(rawData.KeycloakUserId, rawData.Type.Id, thisYear);
var sumLeave = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate);
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
var sumWeekend = _holidayRepository.GetWeekEndCount(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
//var sumLeave = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate);
//var sumHoliday = await _holidayRepository.GetHolidayCountAsync(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
//var sumWeekend = _holidayRepository.GetWeekEndCount(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
var result = new GetLeaveRequestForAdminByIdDto
{
Id = rawData.Id,
ReasonCommander = rawData.LeaveComment ?? "",
ReasonOligarch = rawData.LeaveDirectorComment ?? "",
ProfileType = rawData.ProfileType,
LeaveTypeName = rawData.Type.Name,
LeaveTypeId = rawData.Type.Id,
FullName = $"{rawData.Prefix}{rawData.FirstName} {rawData.LastName}",
@ -1682,11 +1716,11 @@ namespace BMA.EHR.Leave.Service.Controllers
//LeaveTotal = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate),
LeaveTotal = rawData.LeaveTotal,
LeaveBirthDate = profile.BirthDate,
LeaveGovernmentDate = profile.DateAppoint == null ? null : profile.DateAppoint.Value,
LeaveBirthDate = rawData.BirthDate == null ? null : rawData.BirthDate.Value,
LeaveGovernmentDate = rawData.DateAppoint == null ? null : rawData.DateAppoint.Value,
LeaveSalary = lastSalary == null ? 0 : lastSalaryAmount,
LeaveSalaryText = lastSalary == null ? "" : ((int)lastSalaryAmount).ToThaiBahtText(false),
LeaveSalary = (double)(rawData.Amount == null ? 0 : rawData.Amount),
LeaveSalaryText = rawData.Amount == null ? "" : ((int)rawData.Amount).ToThaiBahtText(false),
WifeDayName = rawData.WifeDayName,
WifeDayDateBorn = rawData.WifeDayDateBorn,