Add BeginningLeaveDays and BeginningLeaveCount to LeaveBeginning DTOs and update controller logic #2304 #2305
This commit is contained in:
parent
2410574d42
commit
a2ac05ed61
3 changed files with 100 additions and 1 deletions
|
|
@ -202,6 +202,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
item.LeaveDays,
|
item.LeaveDays,
|
||||||
item.LeaveDaysUsed,
|
item.LeaveDaysUsed,
|
||||||
item.LeaveCount,
|
item.LeaveCount,
|
||||||
|
item.BeginningLeaveDays,
|
||||||
|
item.BeginningLeaveCount,
|
||||||
item.CreatedAt,
|
item.CreatedAt,
|
||||||
item.CreatedFullName,
|
item.CreatedFullName,
|
||||||
item.LastUpdatedAt,
|
item.LastUpdatedAt,
|
||||||
|
|
@ -396,6 +398,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
leaveBeginning.LeaveDays = req.LeaveDays;
|
leaveBeginning.LeaveDays = req.LeaveDays;
|
||||||
leaveBeginning.LeaveDaysUsed = req.LeaveDaysUsed;
|
leaveBeginning.LeaveDaysUsed = req.LeaveDaysUsed;
|
||||||
leaveBeginning.LeaveCount = req.LeaveCount;
|
leaveBeginning.LeaveCount = req.LeaveCount;
|
||||||
|
leaveBeginning.BeginningLeaveDays = req.BeginningLeaveDays;
|
||||||
|
leaveBeginning.BeginningLeaveCount = req.BeginningLeaveCount;
|
||||||
|
|
||||||
leaveBeginning.ProfileId = req.ProfileId;
|
leaveBeginning.ProfileId = req.ProfileId;
|
||||||
leaveBeginning.Prefix = profile.Prefix;
|
leaveBeginning.Prefix = profile.Prefix;
|
||||||
|
|
@ -465,6 +469,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
leaveBeginning.LeaveDays = req.LeaveDays;
|
leaveBeginning.LeaveDays = req.LeaveDays;
|
||||||
leaveBeginning.LeaveDaysUsed = req.LeaveDaysUsed;
|
leaveBeginning.LeaveDaysUsed = req.LeaveDaysUsed;
|
||||||
leaveBeginning.LeaveCount = req.LeaveCount;
|
leaveBeginning.LeaveCount = req.LeaveCount;
|
||||||
|
leaveBeginning.BeginningLeaveDays = req.BeginningLeaveDays;
|
||||||
|
leaveBeginning.BeginningLeaveCount = req.BeginningLeaveCount;
|
||||||
|
|
||||||
leaveBeginning.ProfileId = req.ProfileId;
|
leaveBeginning.ProfileId = req.ProfileId;
|
||||||
leaveBeginning.Prefix = profile.Prefix;
|
leaveBeginning.Prefix = profile.Prefix;
|
||||||
|
|
@ -492,6 +498,84 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPut("schedule")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<ActionResult<ResponseObject>> ScheduleLeaveBeginning([FromBody] EditLeaveBeginningDto req)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var profile = await _userProfileRepository.GetProfileByProfileIdAsync(req.ProfileId, AccessToken);
|
||||||
|
if(profile == null)
|
||||||
|
{
|
||||||
|
return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
// check duplicate
|
||||||
|
var oldData = await _context.LeaveBeginnings.FirstOrDefaultAsync(x => x.ProfileId == req.ProfileId
|
||||||
|
&& x.LeaveTypeId == req.LeaveTypeId
|
||||||
|
&& x.LeaveYear == req.LeaveYear);
|
||||||
|
|
||||||
|
if (oldData is not null)
|
||||||
|
{
|
||||||
|
//return Error("ไม่สามารถบันทึกข้อมูล เนื่องจากมีข้อมูลในระบบแล้ว");
|
||||||
|
oldData.LeaveTypeId = req.LeaveTypeId;
|
||||||
|
oldData.LeaveYear = req.LeaveYear;
|
||||||
|
oldData.LeaveDays = req.LeaveDays;
|
||||||
|
oldData.LeaveDaysUsed = req.LeaveDaysUsed;
|
||||||
|
oldData.LeaveCount = req.LeaveCount;
|
||||||
|
oldData.BeginningLeaveDays = req.BeginningLeaveDays;
|
||||||
|
oldData.BeginningLeaveCount = req.BeginningLeaveCount;
|
||||||
|
|
||||||
|
oldData.ProfileId = req.ProfileId;
|
||||||
|
oldData.Prefix = profile.Prefix;
|
||||||
|
oldData.FirstName = profile.FirstName;
|
||||||
|
oldData.LastName = profile.LastName;
|
||||||
|
oldData.RootDnaId = profile.RootDnaId;
|
||||||
|
oldData.Child1DnaId = profile.Child1DnaId;
|
||||||
|
oldData.Child2DnaId = profile.Child2DnaId;
|
||||||
|
oldData.Child3DnaId = profile.Child3DnaId;
|
||||||
|
oldData.Child4DnaId = profile.Child4DnaId;
|
||||||
|
|
||||||
|
oldData.LastUpdateUserId = "";
|
||||||
|
oldData.LastUpdateFullName = FullName ?? "";
|
||||||
|
oldData.LastUpdatedAt = DateTime.Now;
|
||||||
|
|
||||||
|
await _leaveBeginningRepository.UpdateAsync(oldData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var leaveBeginning = new LeaveBeginning();
|
||||||
|
leaveBeginning.LeaveTypeId = req.LeaveTypeId;
|
||||||
|
leaveBeginning.LeaveYear = req.LeaveYear;
|
||||||
|
leaveBeginning.LeaveDays = req.LeaveDays;
|
||||||
|
leaveBeginning.LeaveDaysUsed = req.LeaveDaysUsed;
|
||||||
|
leaveBeginning.LeaveCount = req.LeaveCount;
|
||||||
|
leaveBeginning.BeginningLeaveDays = req.BeginningLeaveDays;
|
||||||
|
leaveBeginning.BeginningLeaveCount = req.BeginningLeaveCount;
|
||||||
|
|
||||||
|
leaveBeginning.ProfileId = req.ProfileId;
|
||||||
|
leaveBeginning.Prefix = profile.Prefix;
|
||||||
|
leaveBeginning.FirstName = profile.FirstName;
|
||||||
|
leaveBeginning.LastName = profile.LastName;
|
||||||
|
|
||||||
|
leaveBeginning.RootDnaId = profile.RootDnaId;
|
||||||
|
leaveBeginning.Child1DnaId = profile.Child1DnaId;
|
||||||
|
leaveBeginning.Child2DnaId = profile.Child2DnaId;
|
||||||
|
leaveBeginning.Child3DnaId = profile.Child3DnaId;
|
||||||
|
leaveBeginning.Child4DnaId = profile.Child4DnaId;
|
||||||
|
|
||||||
|
leaveBeginning.CreatedUserId = "";
|
||||||
|
leaveBeginning.CreatedFullName = FullName ?? "";
|
||||||
|
leaveBeginning.CreatedAt = DateTime.Now;
|
||||||
|
|
||||||
|
await _leaveBeginningRepository.AddAsync(leaveBeginning);
|
||||||
|
}
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Error(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,19 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveBeginnings
|
||||||
[Required, Comment("ปีงบประมาณ")]
|
[Required, Comment("ปีงบประมาณ")]
|
||||||
public int LeaveYear { get; set; } = 0;
|
public int LeaveYear { get; set; } = 0;
|
||||||
|
|
||||||
[Required, Comment("จำนวนวันลายกมา")]
|
[Required, Comment("จำนวนวันลาที่ได้รับ")]
|
||||||
public double LeaveDays { get; set; } = 0.0;
|
public double LeaveDays { get; set; } = 0.0;
|
||||||
|
|
||||||
[Required, Comment("จำนวนวันลาที่ใช้ไป")]
|
[Required, Comment("จำนวนวันลาที่ใช้ไป")]
|
||||||
public double LeaveDaysUsed { get; set; } = 0.0;
|
public double LeaveDaysUsed { get; set; } = 0.0;
|
||||||
|
|
||||||
|
[Required, Comment("จำนวนครั้งที่ลาสะสม")]
|
||||||
|
public int LeaveCount { get; set; } = 0;
|
||||||
|
|
||||||
|
[Required, Comment("จำนวนวันลายกมา")]
|
||||||
|
public double BeginningLeaveDays { get; set; } = 0.0;
|
||||||
|
|
||||||
|
[Comment("จำนวนครั้งที่ลายกมา")]
|
||||||
|
public int BeginningLeaveCount { get; set; } = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,5 +22,11 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveBeginnings
|
||||||
|
|
||||||
[Required, Comment("จำนวนครั้งที่ลาสะสม")]
|
[Required, Comment("จำนวนครั้งที่ลาสะสม")]
|
||||||
public int LeaveCount { get; set; } = 0;
|
public int LeaveCount { get; set; } = 0;
|
||||||
|
|
||||||
|
[Required, Comment("จำนวนวันลายกมา")]
|
||||||
|
public double BeginningLeaveDays { get; set; } = 0.0;
|
||||||
|
|
||||||
|
[Comment("จำนวนครั้งที่ลายกมา")]
|
||||||
|
public int BeginningLeaveCount { get; set; } = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue