fix issue
This commit is contained in:
parent
28544df284
commit
ae2112f23a
3 changed files with 365 additions and 237 deletions
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Drawing;
|
using Amazon.S3.Model;
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Net.Http.Json;
|
|
||||||
using BMA.EHR.Application.Common.Interfaces;
|
using BMA.EHR.Application.Common.Interfaces;
|
||||||
using BMA.EHR.Application.Messaging;
|
using BMA.EHR.Application.Messaging;
|
||||||
using BMA.EHR.Application.Responses.Leaves;
|
using BMA.EHR.Application.Responses.Leaves;
|
||||||
|
|
@ -12,6 +10,10 @@ using BMA.EHR.Domain.Shared;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Nest;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
{
|
{
|
||||||
|
|
@ -27,6 +29,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
private readonly EmailSenderService _emailSenderService;
|
private readonly EmailSenderService _emailSenderService;
|
||||||
|
|
||||||
private readonly IApplicationDBContext _appDbContext;
|
private readonly IApplicationDBContext _appDbContext;
|
||||||
|
private readonly MinIOLeaveService _minIOService;
|
||||||
|
|
||||||
private readonly string URL = string.Empty;
|
private readonly string URL = string.Empty;
|
||||||
|
|
||||||
|
|
@ -40,7 +43,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
UserProfileRepository userProfileRepository,
|
UserProfileRepository userProfileRepository,
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
EmailSenderService emailSenderService,
|
EmailSenderService emailSenderService,
|
||||||
IApplicationDBContext appDbContext) : base(dbContext, httpContextAccessor)
|
IApplicationDBContext appDbContext,
|
||||||
|
MinIOLeaveService minIOService) : base(dbContext, httpContextAccessor)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
|
@ -51,6 +55,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
_appDbContext = appDbContext;
|
_appDbContext = appDbContext;
|
||||||
|
|
||||||
URL = (_configuration["API"]).Replace("/api/v1", "");
|
URL = (_configuration["API"]).Replace("/api/v1", "");
|
||||||
|
_minIOService = minIOService;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -197,6 +202,53 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public async Task AddLeaveDocumentAsync(Guid id, LeaveDocument doc)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var req = await _dbContext.Set<LeaveRequest>().FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
req!.LeaveDocument.Add(doc);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddApproversAsync(Guid id, List<LeaveRequestApprover> approvers)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var req = await _dbContext.Set<LeaveRequest>().FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
req!.Approvers.AddRange(approvers);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RemoveApproversAsync(Guid id, string type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var data = await _dbContext.Set<LeaveRequestApprover>()
|
||||||
|
.Where(x => x.LeaveRequest.Id == id && x.ApproveType.ToUpper() == type.ToUpper())
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
_dbContext.Set<LeaveRequestApprover>().RemoveRange(data);
|
||||||
|
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<List<LeaveRequest>> GetLeaveRequestByYearAsync(int year)
|
public async Task<List<LeaveRequest>> GetLeaveRequestByYearAsync(int year)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
|
|
@ -289,7 +341,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
.Where(x => x.LeaveYear == year)
|
.Where(x => x.LeaveYear == year)
|
||||||
.Where(x => x.LeaveTypeId == leaveTypeId)
|
.Where(x => x.LeaveTypeId == leaveTypeId)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var startFiscalDate = new DateTime(year - 1, 10, 1);
|
var startFiscalDate = new DateTime(year - 1, 10, 1);
|
||||||
|
|
|
||||||
|
|
@ -134,11 +134,15 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
var delete = leaveReq.Approvers.RemoveAll(x => x.ApproveType == type.Trim().ToUpper());
|
await _leaveRequestRepository.RemoveApproversAsync(id, type);
|
||||||
|
//var delete = leaveReq.Approvers.RemoveAll(x => x.ApproveType.ToUpper() == type.Trim().ToUpper());
|
||||||
|
//await _leaveRequestRepository.UpdateAsync(leaveReq);
|
||||||
|
|
||||||
|
var addList = new List<LeaveRequestApprover>();
|
||||||
|
|
||||||
foreach (var r in req)
|
foreach (var r in req)
|
||||||
{
|
{
|
||||||
leaveReq.Approvers.Add(new LeaveRequestApprover
|
addList.Add(new LeaveRequestApprover
|
||||||
{
|
{
|
||||||
Seq = r.Seq,
|
Seq = r.Seq,
|
||||||
Prefix = r.Prefix,
|
Prefix = r.Prefix,
|
||||||
|
|
@ -152,7 +156,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await _leaveRequestRepository.UpdateAsync(leaveReq);
|
await _leaveRequestRepository.AddApproversAsync(id, addList);
|
||||||
|
|
||||||
return Success();
|
return Success();
|
||||||
|
|
||||||
|
|
@ -503,245 +507,261 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
public async Task<ActionResult<ResponseObject>> EditLeaveRequestAsync(Guid id, [FromForm] CreateLeaveRequestDto req)
|
public async Task<ActionResult<ResponseObject>> EditLeaveRequestAsync(Guid id, [FromForm] CreateLeaveRequestDto req)
|
||||||
{
|
{
|
||||||
var oldData = await _leaveRequestRepository.GetByIdAsync(id);
|
try
|
||||||
if (oldData == null)
|
|
||||||
{
|
{
|
||||||
return Error(GlobalMessages.DataNotFound);
|
var oldData = await _leaveRequestRepository.GetByIdAsync(id);
|
||||||
}
|
if (oldData == null)
|
||||||
|
|
||||||
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
|
||||||
var thisYear = DateTime.Now.Year;
|
|
||||||
|
|
||||||
// var isDuplicate = await _leaveRequestRepository.CheckDuplicateLeave(userId, req.LeaveStartDate.Date, req.LeaveEndDate.Date);
|
|
||||||
// if (isDuplicate)
|
|
||||||
// {
|
|
||||||
// return Error("ไม่สามารถขอลาในช่วงเวลาเดียวกันได้");
|
|
||||||
// }
|
|
||||||
|
|
||||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken);
|
|
||||||
|
|
||||||
if (profile == null)
|
|
||||||
{
|
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
||||||
}
|
|
||||||
|
|
||||||
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
|
|
||||||
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
|
|
||||||
|
|
||||||
var leaveType = await _context.Set<LeaveType>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == req.Type); // _leaveTypeRepository.GetByIdAsync(req.Type);
|
|
||||||
if (leaveType == null)
|
|
||||||
{
|
|
||||||
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 leaveTotal = 0.0;
|
|
||||||
// if (req.LeaveRange != "ALL")
|
|
||||||
// leaveTotal = 0.5;
|
|
||||||
// else
|
|
||||||
// leaveTotal = sumLeave - sumHoliday - sumWeekend;
|
|
||||||
|
|
||||||
// ลองใช้ oldData
|
|
||||||
oldData.LeaveRange = req.LeaveRange;
|
|
||||||
oldData.LeaveRangeEnd = req.LeaveRangeEnd;
|
|
||||||
oldData.LeaveStartDate = req.LeaveStartDate;
|
|
||||||
oldData.LeaveEndDate = req.LeaveEndDate;
|
|
||||||
oldData.LeaveWrote = req.LeaveWrote ?? "";
|
|
||||||
oldData.LeaveDetail = req.LeaveDetail ?? "";
|
|
||||||
oldData.LeaveAddress = req.LeaveAddress ?? "";
|
|
||||||
oldData.LeaveNumber = req.LeaveNumber ?? "";
|
|
||||||
oldData.LeaveTotal = req.LeaveTotal;
|
|
||||||
oldData.LeaveSalaryText = req.LeaveSalaryText ?? "";
|
|
||||||
|
|
||||||
//oldData.CommanderPosition = req.CommanderPosition ?? "";
|
|
||||||
|
|
||||||
/*** remove old code
|
|
||||||
|
|
||||||
var leaveRequest = new LeaveRequest
|
|
||||||
{
|
|
||||||
Id = id,
|
|
||||||
Type = leaveType,
|
|
||||||
LeaveRange = req.LeaveRange,
|
|
||||||
LeaveStartDate = req.LeaveStartDate,
|
|
||||||
LeaveEndDate = req.LeaveEndDate,
|
|
||||||
LeaveWrote = req.LeaveWrote ?? "",
|
|
||||||
LeaveDetail = req.LeaveDetail ?? "",
|
|
||||||
LeaveAddress = req.LeaveAddress ?? "",
|
|
||||||
LeaveNumber = req.LeaveNumber ?? "",
|
|
||||||
//LeaveTotal = req.LeaveStartDate.DiffDay(req.LeaveEndDate),
|
|
||||||
LeaveTotal = req.LeaveTotal, // change to get value from request
|
|
||||||
|
|
||||||
|
|
||||||
LeaveSalaryText = req.LeaveSalaryText ?? "",
|
|
||||||
LeaveStatus = oldData.LeaveStatus,
|
|
||||||
KeycloakUserId = userId,
|
|
||||||
ApproveStep = oldData.ApproveStep
|
|
||||||
};
|
|
||||||
|
|
||||||
// assign old upload documents to new request
|
|
||||||
leaveRequest.LeaveDraftDocument = oldData.LeaveDraftDocument;
|
|
||||||
leaveRequest.LeaveDocument.AddRange(oldData.LeaveDocument);
|
|
||||||
leaveRequest.LeaveCancelDocument = oldData.LeaveCancelDocument;
|
|
||||||
|
|
||||||
// get leave last
|
|
||||||
leaveRequest.LeaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type);
|
|
||||||
|
|
||||||
**/
|
|
||||||
|
|
||||||
// upload document
|
|
||||||
if (req.LeaveDocument != null)
|
|
||||||
{
|
|
||||||
foreach (var d in req.LeaveDocument)
|
|
||||||
{
|
{
|
||||||
var doc = await _minIOService.UploadFileAsync(d);
|
return Error(GlobalMessages.DataNotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||||
|
var thisYear = DateTime.Now.Year;
|
||||||
|
|
||||||
|
// var isDuplicate = await _leaveRequestRepository.CheckDuplicateLeave(userId, req.LeaveStartDate.Date, req.LeaveEndDate.Date);
|
||||||
|
// if (isDuplicate)
|
||||||
|
// {
|
||||||
|
// return Error("ไม่สามารถขอลาในช่วงเวลาเดียวกันได้");
|
||||||
|
// }
|
||||||
|
|
||||||
|
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken);
|
||||||
|
|
||||||
|
if (profile == null)
|
||||||
|
{
|
||||||
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
|
||||||
|
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
|
||||||
|
|
||||||
|
var leaveType = await _context.Set<LeaveType>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == req.Type); // _leaveTypeRepository.GetByIdAsync(req.Type);
|
||||||
|
if (leaveType == null)
|
||||||
|
{
|
||||||
|
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 leaveTotal = 0.0;
|
||||||
|
// if (req.LeaveRange != "ALL")
|
||||||
|
// leaveTotal = 0.5;
|
||||||
|
// else
|
||||||
|
// leaveTotal = sumLeave - sumHoliday - sumWeekend;
|
||||||
|
|
||||||
|
// ลองใช้ oldData
|
||||||
|
oldData.LeaveRange = req.LeaveRange;
|
||||||
|
oldData.LeaveRangeEnd = req.LeaveRangeEnd;
|
||||||
|
oldData.LeaveStartDate = req.LeaveStartDate;
|
||||||
|
oldData.LeaveEndDate = req.LeaveEndDate;
|
||||||
|
oldData.LeaveWrote = req.LeaveWrote ?? "";
|
||||||
|
oldData.LeaveDetail = req.LeaveDetail ?? "";
|
||||||
|
oldData.LeaveAddress = req.LeaveAddress ?? "";
|
||||||
|
oldData.LeaveNumber = req.LeaveNumber ?? "";
|
||||||
|
oldData.LeaveTotal = req.LeaveTotal;
|
||||||
|
oldData.LeaveSalaryText = req.LeaveSalaryText ?? "";
|
||||||
|
|
||||||
|
//oldData.CommanderPosition = req.CommanderPosition ?? "";
|
||||||
|
|
||||||
|
/*** remove old code
|
||||||
|
|
||||||
|
var leaveRequest = new LeaveRequest
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Type = leaveType,
|
||||||
|
LeaveRange = req.LeaveRange,
|
||||||
|
LeaveStartDate = req.LeaveStartDate,
|
||||||
|
LeaveEndDate = req.LeaveEndDate,
|
||||||
|
LeaveWrote = req.LeaveWrote ?? "",
|
||||||
|
LeaveDetail = req.LeaveDetail ?? "",
|
||||||
|
LeaveAddress = req.LeaveAddress ?? "",
|
||||||
|
LeaveNumber = req.LeaveNumber ?? "",
|
||||||
|
//LeaveTotal = req.LeaveStartDate.DiffDay(req.LeaveEndDate),
|
||||||
|
LeaveTotal = req.LeaveTotal, // change to get value from request
|
||||||
|
|
||||||
|
|
||||||
|
LeaveSalaryText = req.LeaveSalaryText ?? "",
|
||||||
|
LeaveStatus = oldData.LeaveStatus,
|
||||||
|
KeycloakUserId = userId,
|
||||||
|
ApproveStep = oldData.ApproveStep
|
||||||
|
};
|
||||||
|
|
||||||
|
// assign old upload documents to new request
|
||||||
|
leaveRequest.LeaveDraftDocument = oldData.LeaveDraftDocument;
|
||||||
|
leaveRequest.LeaveDocument.AddRange(oldData.LeaveDocument);
|
||||||
|
leaveRequest.LeaveCancelDocument = oldData.LeaveCancelDocument;
|
||||||
|
|
||||||
|
// get leave last
|
||||||
|
leaveRequest.LeaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type);
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// switch from leave type
|
||||||
|
switch (leaveType.Code.Trim().ToUpper())
|
||||||
|
{
|
||||||
|
case "LV-004":
|
||||||
|
{
|
||||||
|
oldData.WifeDayName = req.WifeDayName ?? "";
|
||||||
|
oldData.WifeDayDateBorn = req.WifeDayDateBorn ?? "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "LV-005":
|
||||||
|
{
|
||||||
|
oldData.RestDayOldTotal =
|
||||||
|
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear - 1);
|
||||||
|
oldData.RestDayCurrentTotal =
|
||||||
|
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "LV-006":
|
||||||
|
{
|
||||||
|
oldData.OrdainDayStatus = req.OrdainDayStatus ?? false;
|
||||||
|
oldData.OrdainDayLocationName = req.OrdainDayLocationName ?? "";
|
||||||
|
oldData.OrdainDayLocationAddress = req.OrdainDayLocationAddress ?? "";
|
||||||
|
oldData.OrdainDayLocationNumber = req.OrdainDayLocationNumber ?? "";
|
||||||
|
if (req.OrdainDayOrdination != null)
|
||||||
|
oldData.OrdainDayOrdination = req.OrdainDayOrdination.Value;
|
||||||
|
|
||||||
|
oldData.OrdainDayBuddhistLentName = req.OrdainDayBuddhistLentName ?? "";
|
||||||
|
|
||||||
|
oldData.OrdainDayBuddhistLentAddress = req.OrdainDayBuddhistLentAddress ?? "";
|
||||||
|
|
||||||
|
oldData.LeaveBirthDate = profile.BirthDate;
|
||||||
|
oldData.LeaveGovernmentDate = profile.DateStart;
|
||||||
|
|
||||||
|
oldData.HajjDayStatus = req.HajjDayStatus ?? false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "LV-007":
|
||||||
|
{
|
||||||
|
oldData.AbsentDayLocation = req.AbsentDayLocation ?? "";
|
||||||
|
oldData.AbsentDaySummon = req.AbsentDaySummon ?? "";
|
||||||
|
if (req.AbsentDayRegistorDate != null)
|
||||||
|
oldData.AbsentDayRegistorDate = req.AbsentDayRegistorDate.Value;
|
||||||
|
|
||||||
|
oldData.AbsentDayGetIn = req.AbsentDayGetIn ?? "";
|
||||||
|
|
||||||
|
oldData.AbsentDayAt = req.AbsentDayAt ?? "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "LV-008":
|
||||||
|
{
|
||||||
|
var lastSalary = profile.ProfileSalary;
|
||||||
|
|
||||||
|
oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
||||||
|
oldData.LeaveSalaryText =
|
||||||
|
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
||||||
|
oldData.LeaveBirthDate = profile.BirthDate;
|
||||||
|
oldData.LeaveGovernmentDate = profile.DateStart;
|
||||||
|
|
||||||
|
oldData.StudyDaySubject = req.StudyDaySubject ?? "";
|
||||||
|
oldData.StudyDayDegreeLevel = req.StudyDayDegreeLevel ?? "";
|
||||||
|
oldData.StudyDayUniversityName = req.StudyDayUniversityName ?? "";
|
||||||
|
oldData.StudyDayCountry = req.StudyDayCountry ?? "";
|
||||||
|
oldData.StudyDayScholarship = req.StudyDayScholarship ?? "";
|
||||||
|
|
||||||
|
oldData.StudyDayTrainingSubject = req.StudyDayTrainingSubject ?? "";
|
||||||
|
oldData.StudyDayTrainingName = req.StudyDayTrainingName ?? "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "LV-010":
|
||||||
|
{
|
||||||
|
var lastSalary = profile.ProfileSalary;
|
||||||
|
|
||||||
|
oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
||||||
|
oldData.LeaveSalaryText =
|
||||||
|
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
||||||
|
|
||||||
|
oldData.CoupleDayName = req.CoupleDayName ?? "";
|
||||||
|
oldData.CoupleDayPosition = req.CoupleDayPosition ?? "";
|
||||||
|
oldData.CoupleDayLevel = req.CoupleDayLevel ?? "";
|
||||||
|
oldData.CoupleDayLevelCountry = req.CoupleDayLevelCountry ?? "";
|
||||||
|
oldData.CoupleDayCountryHistory = req.CoupleDayCountryHistory ?? "";
|
||||||
|
oldData.CoupleDayTotalHistory = req.CoupleDayTotalHistory ?? "";
|
||||||
|
|
||||||
|
if (req.CoupleDayStartDateHistory != null)
|
||||||
|
oldData.CoupleDayStartDateHistory = req.CoupleDayStartDateHistory.Value;
|
||||||
|
|
||||||
|
if (req.CoupleDayEndDateHistory != null)
|
||||||
|
oldData.CoupleDayEndDateHistory = req.CoupleDayEndDateHistory.Value;
|
||||||
|
|
||||||
|
oldData.CoupleDaySumTotalHistory = req.CoupleDaySumTotalHistory ?? "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add dear and oc_data
|
||||||
|
//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;
|
||||||
|
//}
|
||||||
|
|
||||||
|
oldData.LeaveTypeCode = leaveType.Code;
|
||||||
|
oldData.Dear = profile.Commander ?? "";
|
||||||
|
oldData.CommanderPosition = profile.CommanderPositionName ?? "";
|
||||||
|
|
||||||
|
|
||||||
|
oldData.PositionName = profile.Position == null ? "" : profile.Position;
|
||||||
|
oldData.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel;
|
||||||
|
oldData.OrganizationName = profile.Oc ?? "";
|
||||||
|
|
||||||
|
_context.Entry(oldData.Type).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
|
||||||
|
//_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// delete old
|
||||||
|
//await _leaveRequestRepository.DeleteAsync(oldData);
|
||||||
|
|
||||||
|
// save to database
|
||||||
|
await _leaveRequestRepository.UpdateAsync(oldData);
|
||||||
|
|
||||||
|
// upload document
|
||||||
|
if (req.LeaveDocument != null)
|
||||||
|
{
|
||||||
|
foreach (var d in req.LeaveDocument)
|
||||||
|
{
|
||||||
|
var doc = await _minIOService.UploadFileAsync(d);
|
||||||
|
if (doc != null)
|
||||||
|
{
|
||||||
|
// add new record
|
||||||
|
await _leaveRequestRepository.AddLeaveDocumentAsync(id, new LeaveDocument { Document = doc });
|
||||||
|
|
||||||
|
//oldData.LeaveDocument.Add(new LeaveDocument { Document = doc });
|
||||||
|
//var a = oldData.LeaveDocument.Last();
|
||||||
|
//_context.Entry(a).State = Microsoft.EntityFrameworkCore.EntityState.Added;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// upload draft document
|
||||||
|
if (req.LeaveDraftDocument != null)
|
||||||
|
{
|
||||||
|
var doc = await _minIOService.UploadFileAsync(req.LeaveDraftDocument);
|
||||||
if (doc != null)
|
if (doc != null)
|
||||||
{
|
{
|
||||||
oldData.LeaveDocument.Add(new LeaveDocument { Document = doc });
|
oldData.LeaveDraftDocument = doc;
|
||||||
var a = oldData.LeaveDocument.Last();
|
_context.Entry(oldData.LeaveDraftDocument).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
_context.Entry(a).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save to database
|
||||||
|
await _leaveRequestRepository.UpdateAsync(oldData);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// upload draft document
|
return Success(new { id = oldData.Id });
|
||||||
if (req.LeaveDraftDocument != null)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var doc = await _minIOService.UploadFileAsync(req.LeaveDraftDocument);
|
return Error(ex);
|
||||||
if (doc != null)
|
|
||||||
{
|
|
||||||
oldData.LeaveDraftDocument = doc;
|
|
||||||
_context.Entry(oldData.LeaveDraftDocument).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch from leave type
|
|
||||||
switch (leaveType.Code.Trim().ToUpper())
|
|
||||||
{
|
|
||||||
case "LV-004":
|
|
||||||
{
|
|
||||||
oldData.WifeDayName = req.WifeDayName ?? "";
|
|
||||||
oldData.WifeDayDateBorn = req.WifeDayDateBorn ?? "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "LV-005":
|
|
||||||
{
|
|
||||||
oldData.RestDayOldTotal =
|
|
||||||
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear - 1);
|
|
||||||
oldData.RestDayCurrentTotal =
|
|
||||||
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "LV-006":
|
|
||||||
{
|
|
||||||
oldData.OrdainDayStatus = req.OrdainDayStatus ?? false;
|
|
||||||
oldData.OrdainDayLocationName = req.OrdainDayLocationName ?? "";
|
|
||||||
oldData.OrdainDayLocationAddress = req.OrdainDayLocationAddress ?? "";
|
|
||||||
oldData.OrdainDayLocationNumber = req.OrdainDayLocationNumber ?? "";
|
|
||||||
if (req.OrdainDayOrdination != null)
|
|
||||||
oldData.OrdainDayOrdination = req.OrdainDayOrdination.Value;
|
|
||||||
|
|
||||||
oldData.OrdainDayBuddhistLentName = req.OrdainDayBuddhistLentName ?? "";
|
|
||||||
|
|
||||||
oldData.OrdainDayBuddhistLentAddress = req.OrdainDayBuddhistLentAddress ?? "";
|
|
||||||
|
|
||||||
oldData.LeaveBirthDate = profile.BirthDate;
|
|
||||||
oldData.LeaveGovernmentDate = profile.DateStart;
|
|
||||||
|
|
||||||
oldData.HajjDayStatus = req.HajjDayStatus ?? false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "LV-007":
|
|
||||||
{
|
|
||||||
oldData.AbsentDayLocation = req.AbsentDayLocation ?? "";
|
|
||||||
oldData.AbsentDaySummon = req.AbsentDaySummon ?? "";
|
|
||||||
if (req.AbsentDayRegistorDate != null)
|
|
||||||
oldData.AbsentDayRegistorDate = req.AbsentDayRegistorDate.Value;
|
|
||||||
|
|
||||||
oldData.AbsentDayGetIn = req.AbsentDayGetIn ?? "";
|
|
||||||
|
|
||||||
oldData.AbsentDayAt = req.AbsentDayAt ?? "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "LV-008":
|
|
||||||
{
|
|
||||||
var lastSalary = profile.ProfileSalary;
|
|
||||||
|
|
||||||
oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
|
||||||
oldData.LeaveSalaryText =
|
|
||||||
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
|
||||||
oldData.LeaveBirthDate = profile.BirthDate;
|
|
||||||
oldData.LeaveGovernmentDate = profile.DateStart;
|
|
||||||
|
|
||||||
oldData.StudyDaySubject = req.StudyDaySubject ?? "";
|
|
||||||
oldData.StudyDayDegreeLevel = req.StudyDayDegreeLevel ?? "";
|
|
||||||
oldData.StudyDayUniversityName = req.StudyDayUniversityName ?? "";
|
|
||||||
oldData.StudyDayCountry = req.StudyDayCountry ?? "";
|
|
||||||
oldData.StudyDayScholarship = req.StudyDayScholarship ?? "";
|
|
||||||
|
|
||||||
oldData.StudyDayTrainingSubject = req.StudyDayTrainingSubject ?? "";
|
|
||||||
oldData.StudyDayTrainingName = req.StudyDayTrainingName ?? "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "LV-010":
|
|
||||||
{
|
|
||||||
var lastSalary = profile.ProfileSalary;
|
|
||||||
|
|
||||||
oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
|
||||||
oldData.LeaveSalaryText =
|
|
||||||
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
|
||||||
|
|
||||||
oldData.CoupleDayName = req.CoupleDayName ?? "";
|
|
||||||
oldData.CoupleDayPosition = req.CoupleDayPosition ?? "";
|
|
||||||
oldData.CoupleDayLevel = req.CoupleDayLevel ?? "";
|
|
||||||
oldData.CoupleDayLevelCountry = req.CoupleDayLevelCountry ?? "";
|
|
||||||
oldData.CoupleDayCountryHistory = req.CoupleDayCountryHistory ?? "";
|
|
||||||
oldData.CoupleDayTotalHistory = req.CoupleDayTotalHistory ?? "";
|
|
||||||
|
|
||||||
if (req.CoupleDayStartDateHistory != null)
|
|
||||||
oldData.CoupleDayStartDateHistory = req.CoupleDayStartDateHistory.Value;
|
|
||||||
|
|
||||||
if (req.CoupleDayEndDateHistory != null)
|
|
||||||
oldData.CoupleDayEndDateHistory = req.CoupleDayEndDateHistory.Value;
|
|
||||||
|
|
||||||
oldData.CoupleDaySumTotalHistory = req.CoupleDaySumTotalHistory ?? "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add dear and oc_data
|
|
||||||
//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;
|
|
||||||
//}
|
|
||||||
|
|
||||||
oldData.LeaveTypeCode = leaveType.Code;
|
|
||||||
oldData.Dear = profile.Commander ?? "";
|
|
||||||
oldData.CommanderPosition = profile.CommanderPositionName ?? "";
|
|
||||||
|
|
||||||
|
|
||||||
oldData.PositionName = profile.Position == null ? "" : profile.Position;
|
|
||||||
oldData.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel;
|
|
||||||
oldData.OrganizationName = profile.Oc ?? "";
|
|
||||||
|
|
||||||
_context.Entry(oldData.Type).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
|
|
||||||
//_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// delete old
|
|
||||||
//await _leaveRequestRepository.DeleteAsync(oldData);
|
|
||||||
|
|
||||||
// save to database
|
|
||||||
await _leaveRequestRepository.UpdateAsync(oldData);
|
|
||||||
|
|
||||||
return Success(new { id = oldData.Id });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2249,6 +2269,37 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var commanders = rawData.Approvers.Where(x => x.ApproveType.ToUpper() == "COMMANDER")
|
||||||
|
.Select(x => new GetLeaveApproverDto
|
||||||
|
{
|
||||||
|
Seq = x.Seq,
|
||||||
|
Prefix = x.Prefix,
|
||||||
|
FirstName = x.FirstName,
|
||||||
|
LastName = x.LastName,
|
||||||
|
PositionName = x.PositionName,
|
||||||
|
ApproveStatus = x.ApproveStatus,
|
||||||
|
Comment = x.Comment,
|
||||||
|
ProfileId = x.ProfileId,
|
||||||
|
KeycloakId = x.KeycloakId
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var approvers = rawData.Approvers.Where(x => x.ApproveType.ToUpper() == "APPROVER")
|
||||||
|
.Select(x => new GetLeaveApproverDto
|
||||||
|
{
|
||||||
|
Seq = x.Seq,
|
||||||
|
Prefix = x.Prefix,
|
||||||
|
FirstName = x.FirstName,
|
||||||
|
LastName = x.LastName,
|
||||||
|
PositionName = x.PositionName,
|
||||||
|
ApproveStatus = x.ApproveStatus,
|
||||||
|
Comment = x.Comment,
|
||||||
|
ProfileId = x.ProfileId,
|
||||||
|
KeycloakId = x.KeycloakId
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
result.Approvers.AddRange(approvers);
|
||||||
|
result.Commanders.AddRange(commanders);
|
||||||
|
|
||||||
return Success(result);
|
return Success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,5 +141,30 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
|
||||||
public string? ProfileType { get; set; }
|
public string? ProfileType { get; set; }
|
||||||
|
|
||||||
public string? CommanderPosition { get; set; } = string.Empty;
|
public string? CommanderPosition { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public List<GetLeaveApproverDto> Commanders { get; set; } = new();
|
||||||
|
|
||||||
|
public List<GetLeaveApproverDto> Approvers { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetLeaveApproverDto
|
||||||
|
{
|
||||||
|
public int Seq { get; set; } = 0;
|
||||||
|
|
||||||
|
public string Prefix { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string FirstName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string LastName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string PositionName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public Guid ProfileId { get; set; } = Guid.Empty;
|
||||||
|
|
||||||
|
public Guid KeycloakId { get; set; } = Guid.Empty;
|
||||||
|
|
||||||
|
public string ApproveStatus { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Comment { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue