Merge branch 'develop' of github.com:Frappet/BMA-EHR-BackEnd into develop
This commit is contained in:
commit
5e4394fd33
2 changed files with 85 additions and 55 deletions
|
|
@ -271,6 +271,19 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return data.Sum(x => x.LeaveTotal);
|
return data.Sum(x => x.LeaveTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public async Task<double> GetSumApproveLeaveByTypeForUserAsync(Guid keycloakUserId, Guid leaveTypeId, int year)
|
||||||
|
//{
|
||||||
|
// var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
|
// .Include(x => x.Type)
|
||||||
|
// .Where(x => x.KeycloakUserId == keycloakUserId)
|
||||||
|
// .Where(x => x.Type.Id == leaveTypeId)
|
||||||
|
// .Where(x => x.LeaveStartDate.Year == year)
|
||||||
|
// .Where(x => x.LeaveStatus == "APPROVE")
|
||||||
|
// .ToListAsync();
|
||||||
|
|
||||||
|
// return data.Sum(x => x.LeaveTotal);
|
||||||
|
//}
|
||||||
|
|
||||||
public async Task<DateTime?> GetLeaveLastByTypeForUserAsync(Guid keycloakUserId, Guid leaveTypeId)
|
public async Task<DateTime?> GetLeaveLastByTypeForUserAsync(Guid keycloakUserId, Guid leaveTypeId)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||||
|
|
|
||||||
|
|
@ -393,6 +393,19 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
// else
|
// else
|
||||||
// leaveTotal = sumLeave - sumHoliday - sumWeekend;
|
// leaveTotal = sumLeave - sumHoliday - sumWeekend;
|
||||||
|
|
||||||
|
// ลองใช้ oldData
|
||||||
|
oldData.LeaveRange = req.LeaveRange;
|
||||||
|
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 ?? "";
|
||||||
|
|
||||||
|
/*** remove old code
|
||||||
|
|
||||||
var leaveRequest = new LeaveRequest
|
var leaveRequest = new LeaveRequest
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
|
|
@ -422,6 +435,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
// get leave last
|
// get leave last
|
||||||
leaveRequest.LeaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type);
|
leaveRequest.LeaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type);
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
// upload document
|
// upload document
|
||||||
if (req.LeaveDocument != null)
|
if (req.LeaveDocument != null)
|
||||||
{
|
{
|
||||||
|
|
@ -430,8 +445,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
var doc = await _minIOService.UploadFileAsync(d);
|
var doc = await _minIOService.UploadFileAsync(d);
|
||||||
if (doc != null)
|
if (doc != null)
|
||||||
{
|
{
|
||||||
leaveRequest.LeaveDocument.Add(new LeaveDocument { Document = doc });
|
oldData.LeaveDocument.Add(new LeaveDocument { Document = doc });
|
||||||
var a = leaveRequest.LeaveDocument.Last();
|
var a = oldData.LeaveDocument.Last();
|
||||||
_context.Entry(a).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
_context.Entry(a).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -443,8 +458,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
var doc = await _minIOService.UploadFileAsync(req.LeaveDraftDocument);
|
var doc = await _minIOService.UploadFileAsync(req.LeaveDraftDocument);
|
||||||
if (doc != null)
|
if (doc != null)
|
||||||
{
|
{
|
||||||
leaveRequest.LeaveDraftDocument = doc;
|
oldData.LeaveDraftDocument = doc;
|
||||||
_context.Entry(leaveRequest.LeaveDraftDocument).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
_context.Entry(oldData.LeaveDraftDocument).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -453,91 +468,91 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
{
|
{
|
||||||
case "LV-004":
|
case "LV-004":
|
||||||
{
|
{
|
||||||
leaveRequest.WifeDayName = req.WifeDayName ?? "";
|
oldData.WifeDayName = req.WifeDayName ?? "";
|
||||||
leaveRequest.WifeDayDateBorn = req.WifeDayDateBorn ?? "";
|
oldData.WifeDayDateBorn = req.WifeDayDateBorn ?? "";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "LV-005":
|
case "LV-005":
|
||||||
{
|
{
|
||||||
leaveRequest.RestDayOldTotal =
|
oldData.RestDayOldTotal =
|
||||||
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear - 1);
|
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear - 1);
|
||||||
leaveRequest.RestDayCurrentTotal =
|
oldData.RestDayCurrentTotal =
|
||||||
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear);
|
await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "LV-006":
|
case "LV-006":
|
||||||
{
|
{
|
||||||
leaveRequest.OrdainDayStatus = req.OrdainDayStatus ?? false;
|
oldData.OrdainDayStatus = req.OrdainDayStatus ?? false;
|
||||||
leaveRequest.OrdainDayLocationName = req.OrdainDayLocationName ?? "";
|
oldData.OrdainDayLocationName = req.OrdainDayLocationName ?? "";
|
||||||
leaveRequest.OrdainDayLocationAddress = req.OrdainDayLocationAddress ?? "";
|
oldData.OrdainDayLocationAddress = req.OrdainDayLocationAddress ?? "";
|
||||||
leaveRequest.OrdainDayLocationNumber = req.OrdainDayLocationNumber ?? "";
|
oldData.OrdainDayLocationNumber = req.OrdainDayLocationNumber ?? "";
|
||||||
if (req.OrdainDayOrdination != null)
|
if (req.OrdainDayOrdination != null)
|
||||||
leaveRequest.OrdainDayOrdination = req.OrdainDayOrdination.Value;
|
oldData.OrdainDayOrdination = req.OrdainDayOrdination.Value;
|
||||||
|
|
||||||
leaveRequest.OrdainDayBuddhistLentName = req.OrdainDayBuddhistLentName ?? "";
|
oldData.OrdainDayBuddhistLentName = req.OrdainDayBuddhistLentName ?? "";
|
||||||
|
|
||||||
leaveRequest.OrdainDayBuddhistLentAddress = req.OrdainDayBuddhistLentAddress ?? "";
|
oldData.OrdainDayBuddhistLentAddress = req.OrdainDayBuddhistLentAddress ?? "";
|
||||||
|
|
||||||
leaveRequest.LeaveBirthDate = profile.BirthDate;
|
oldData.LeaveBirthDate = profile.BirthDate;
|
||||||
leaveRequest.LeaveGovernmentDate = profile.DateStart;
|
oldData.LeaveGovernmentDate = profile.DateStart;
|
||||||
|
|
||||||
leaveRequest.HajjDayStatus = req.HajjDayStatus ?? false;
|
oldData.HajjDayStatus = req.HajjDayStatus ?? false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "LV-007":
|
case "LV-007":
|
||||||
{
|
{
|
||||||
leaveRequest.AbsentDayLocation = req.AbsentDayLocation ?? "";
|
oldData.AbsentDayLocation = req.AbsentDayLocation ?? "";
|
||||||
leaveRequest.AbsentDaySummon = req.AbsentDaySummon ?? "";
|
oldData.AbsentDaySummon = req.AbsentDaySummon ?? "";
|
||||||
if (req.AbsentDayRegistorDate != null)
|
if (req.AbsentDayRegistorDate != null)
|
||||||
leaveRequest.AbsentDayRegistorDate = req.AbsentDayRegistorDate.Value;
|
oldData.AbsentDayRegistorDate = req.AbsentDayRegistorDate.Value;
|
||||||
|
|
||||||
leaveRequest.AbsentDayGetIn = req.AbsentDayGetIn ?? "";
|
oldData.AbsentDayGetIn = req.AbsentDayGetIn ?? "";
|
||||||
|
|
||||||
leaveRequest.AbsentDayAt = req.AbsentDayAt ?? "";
|
oldData.AbsentDayAt = req.AbsentDayAt ?? "";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "LV-008":
|
case "LV-008":
|
||||||
{
|
{
|
||||||
var lastSalary = profile.ProfileSalary;
|
var lastSalary = profile.ProfileSalary;
|
||||||
|
|
||||||
leaveRequest.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
||||||
leaveRequest.LeaveSalaryText =
|
oldData.LeaveSalaryText =
|
||||||
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
||||||
leaveRequest.LeaveBirthDate = profile.BirthDate;
|
oldData.LeaveBirthDate = profile.BirthDate;
|
||||||
leaveRequest.LeaveGovernmentDate = profile.DateStart;
|
oldData.LeaveGovernmentDate = profile.DateStart;
|
||||||
|
|
||||||
leaveRequest.StudyDaySubject = req.StudyDaySubject ?? "";
|
oldData.StudyDaySubject = req.StudyDaySubject ?? "";
|
||||||
leaveRequest.StudyDayDegreeLevel = req.StudyDayDegreeLevel ?? "";
|
oldData.StudyDayDegreeLevel = req.StudyDayDegreeLevel ?? "";
|
||||||
leaveRequest.StudyDayUniversityName = req.StudyDayUniversityName ?? "";
|
oldData.StudyDayUniversityName = req.StudyDayUniversityName ?? "";
|
||||||
leaveRequest.StudyDayCountry = req.StudyDayCountry ?? "";
|
oldData.StudyDayCountry = req.StudyDayCountry ?? "";
|
||||||
leaveRequest.StudyDayScholarship = req.StudyDayScholarship ?? "";
|
oldData.StudyDayScholarship = req.StudyDayScholarship ?? "";
|
||||||
|
|
||||||
leaveRequest.StudyDayTrainingSubject = req.StudyDayTrainingSubject ?? "";
|
oldData.StudyDayTrainingSubject = req.StudyDayTrainingSubject ?? "";
|
||||||
leaveRequest.StudyDayTrainingName = req.StudyDayTrainingName ?? "";
|
oldData.StudyDayTrainingName = req.StudyDayTrainingName ?? "";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "LV-010":
|
case "LV-010":
|
||||||
{
|
{
|
||||||
var lastSalary = profile.ProfileSalary;
|
var lastSalary = profile.ProfileSalary;
|
||||||
|
|
||||||
leaveRequest.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value;
|
||||||
leaveRequest.LeaveSalaryText =
|
oldData.LeaveSalaryText =
|
||||||
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false);
|
||||||
|
|
||||||
leaveRequest.CoupleDayName = req.CoupleDayName ?? "";
|
oldData.CoupleDayName = req.CoupleDayName ?? "";
|
||||||
leaveRequest.CoupleDayPosition = req.CoupleDayPosition ?? "";
|
oldData.CoupleDayPosition = req.CoupleDayPosition ?? "";
|
||||||
leaveRequest.CoupleDayLevel = req.CoupleDayLevel ?? "";
|
oldData.CoupleDayLevel = req.CoupleDayLevel ?? "";
|
||||||
leaveRequest.CoupleDayLevelCountry = req.CoupleDayLevelCountry ?? "";
|
oldData.CoupleDayLevelCountry = req.CoupleDayLevelCountry ?? "";
|
||||||
leaveRequest.CoupleDayCountryHistory = req.CoupleDayCountryHistory ?? "";
|
oldData.CoupleDayCountryHistory = req.CoupleDayCountryHistory ?? "";
|
||||||
leaveRequest.CoupleDayTotalHistory = req.CoupleDayTotalHistory ?? "";
|
oldData.CoupleDayTotalHistory = req.CoupleDayTotalHistory ?? "";
|
||||||
|
|
||||||
if (req.CoupleDayStartDateHistory != null)
|
if (req.CoupleDayStartDateHistory != null)
|
||||||
leaveRequest.CoupleDayStartDateHistory = req.CoupleDayStartDateHistory.Value;
|
oldData.CoupleDayStartDateHistory = req.CoupleDayStartDateHistory.Value;
|
||||||
|
|
||||||
if (req.CoupleDayEndDateHistory != null)
|
if (req.CoupleDayEndDateHistory != null)
|
||||||
leaveRequest.CoupleDayEndDateHistory = req.CoupleDayEndDateHistory.Value;
|
oldData.CoupleDayEndDateHistory = req.CoupleDayEndDateHistory.Value;
|
||||||
|
|
||||||
leaveRequest.CoupleDaySumTotalHistory = req.CoupleDaySumTotalHistory ?? "";
|
oldData.CoupleDaySumTotalHistory = req.CoupleDaySumTotalHistory ?? "";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -552,13 +567,13 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
approver = list.First().Name;
|
approver = list.First().Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
leaveRequest.LeaveTypeCode = leaveType.Code;
|
oldData.LeaveTypeCode = leaveType.Code;
|
||||||
leaveRequest.Dear = approver;
|
oldData.Dear = approver;
|
||||||
leaveRequest.PositionName = profile.Position == null ? "" : profile.Position;
|
oldData.PositionName = profile.Position == null ? "" : profile.Position;
|
||||||
leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName;
|
oldData.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName;
|
||||||
leaveRequest.OrganizationName = profile.Oc ?? "";
|
oldData.OrganizationName = profile.Oc ?? "";
|
||||||
|
|
||||||
_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
|
_context.Entry(oldData.Type).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
|
||||||
//_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
//_context.Entry(leaveRequest.Type).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -567,9 +582,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
//await _leaveRequestRepository.DeleteAsync(oldData);
|
//await _leaveRequestRepository.DeleteAsync(oldData);
|
||||||
|
|
||||||
// save to database
|
// save to database
|
||||||
await _leaveRequestRepository.UpdateAsync(leaveRequest);
|
await _leaveRequestRepository.UpdateAsync(oldData);
|
||||||
|
|
||||||
return Success(new { id = leaveRequest.Id });
|
return Success(new { id = oldData.Id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -712,6 +727,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
var totalDay = req.StartLeaveDate.DiffDay(req.EndLeaveDate.Date);
|
var totalDay = req.StartLeaveDate.DiffDay(req.EndLeaveDate.Date);
|
||||||
var sumWeekend = _holidayRepository.GetWeekEndCount(req.StartLeaveDate.Date, req.EndLeaveDate.Date, category);
|
var sumWeekend = _holidayRepository.GetWeekEndCount(req.StartLeaveDate.Date, req.EndLeaveDate.Date, category);
|
||||||
|
|
||||||
|
var sumApproveLeave = await _leaveRequestRepository.GetSumApproveLeaveByTypeForUserAsync(userId, req.Type, req.StartLeaveDate.Year);
|
||||||
|
|
||||||
var isLeave = false;
|
var isLeave = false;
|
||||||
|
|
||||||
switch (leaveType.Code.ToUpper().Trim())
|
switch (leaveType.Code.ToUpper().Trim())
|
||||||
|
|
@ -728,7 +745,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
isLeave = (totalDay - sumWorkDay - sumWeekend) <= 15;
|
isLeave = (totalDay - sumWorkDay - sumWeekend) <= 15;
|
||||||
break;
|
break;
|
||||||
case "LV-005":
|
case "LV-005":
|
||||||
isLeave = (totalDay - sumWorkDay - sumWeekend) <= 10;
|
isLeave = (totalDay - sumWorkDay - sumWeekend - sumApproveLeave) <= 10;
|
||||||
break;
|
break;
|
||||||
case "LV-006":
|
case "LV-006":
|
||||||
isLeave = totalDay <= 120;
|
isLeave = totalDay <= 120;
|
||||||
|
|
@ -1560,7 +1577,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
approver = list.First().Name;
|
approver = list.First().Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveByTypeForUserAsync(userId, rawData.Type.Id, thisYear);
|
var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveByTypeForUserAsync(rawData.KeycloakUserId, rawData.Type.Id, thisYear);
|
||||||
|
|
||||||
var sumLeave = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate);
|
var sumLeave = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate);
|
||||||
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
|
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue