Refactor check-out status logic to improve clarity and handle edge cases for same-day and next-day check-outs
This commit is contained in:
parent
1a0e712a1c
commit
19000b2e42
1 changed files with 78 additions and 24 deletions
|
|
@ -1158,35 +1158,89 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
else
|
||||
{
|
||||
// fix issue : SIT ระบบบันทึกเวลาปฏิบัติงาน>>ลงเวลาเข้า-ออกงาน (กรณีลงเวลาออกอีกวัน) #921
|
||||
checkOutStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) <
|
||||
DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
|
||||
// "ABSENT" :
|
||||
checkout.CheckIn.Date < currentDate.Date ? "NORMAL" :
|
||||
DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) >=
|
||||
DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTime}") ?
|
||||
"NORMAL" :
|
||||
"ABSENT" :
|
||||
DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) <
|
||||
DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTimeMorning}") ?
|
||||
"ABSENT" :
|
||||
"NORMAL";
|
||||
var currentDateTime = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm"));
|
||||
var dutyEndTimeAfternoon = DateTime.Parse($"{checkout.CheckIn.ToString("yyyy-MM-dd")} {endTime}");
|
||||
var dutyEndTimeMorning = DateTime.Parse($"{checkout.CheckIn.ToString("yyyy-MM-dd")} {endTimeMorning}");
|
||||
|
||||
|
||||
if(currentDateTime.Date > checkout.CheckIn.Date)
|
||||
{
|
||||
// ถ้า check-out เป็นวันถัดไป สถานะปกติเสมอ
|
||||
checkOutStatus = "NORMAL";
|
||||
}
|
||||
else
|
||||
{
|
||||
// ถ้า check-out เป็นวันเดียวกับ check-in
|
||||
// ตรวจสอบเวลาว่าสิ้นสุดก่อนบ่ายหรือไม่
|
||||
if(currentDateTime < dutyEndTimeMorning) // ถ้าออกก่อนเวลาสิ้นสุดตอนเช้า ขาดราชการ
|
||||
{
|
||||
checkOutStatus = "ABSENT";
|
||||
}
|
||||
else if(currentDateTime >= dutyEndTimeAfternoon) // ถ้าออกหลังเวลาสิ้นสุดตอนบ่าย ปกติ
|
||||
{
|
||||
checkOutStatus = "NORMAL";
|
||||
}
|
||||
else
|
||||
{
|
||||
checkOutStatus = "ABSENT";
|
||||
}
|
||||
}
|
||||
// checkOutStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) <
|
||||
// DateTime.Parse($"{checkout.CheckIn.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
|
||||
// // "ABSENT" :
|
||||
// checkout.CheckIn.Date < currentDate.Date ? "NORMAL" :
|
||||
// DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) >=
|
||||
// DateTime.Parse($"{checkout.CheckIn.ToString("yyyy-MM-dd")} {endTime}") ?
|
||||
// "NORMAL" :
|
||||
// "ABSENT" :
|
||||
// DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) <
|
||||
// DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTimeMorning}") ?
|
||||
// "ABSENT" :
|
||||
// "NORMAL";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// fix issue : SIT ระบบบันทึกเวลาปฏิบัติงาน>>ลงเวลาเข้า-ออกงาน (กรณีลงเวลาออกอีกวัน) #921
|
||||
checkOutStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) <
|
||||
DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
|
||||
// "ABSENT" :
|
||||
checkout.CheckIn.Date < currentDate.Date ? "NORMAL" :
|
||||
DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) >=
|
||||
DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTime}") ?
|
||||
"NORMAL" :
|
||||
"ABSENT" :
|
||||
DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) <
|
||||
DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTimeMorning}") ?
|
||||
"ABSENT" :
|
||||
"NORMAL";
|
||||
var currentDateTime = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm"));
|
||||
var dutyEndTimeAfternoon = DateTime.Parse($"{checkout.CheckIn.ToString("yyyy-MM-dd")} {endTime}");
|
||||
var dutyEndTimeMorning = DateTime.Parse($"{checkout.CheckIn.ToString("yyyy-MM-dd")} {endTimeMorning}");
|
||||
|
||||
|
||||
if(currentDateTime.Date > checkout.CheckIn.Date)
|
||||
{
|
||||
// ถ้า check-out เป็นวันถัดไป สถานะปกติเสมอ
|
||||
checkOutStatus = "NORMAL";
|
||||
}
|
||||
else
|
||||
{
|
||||
// ถ้า check-out เป็นวันเดียวกับ check-in
|
||||
// ตรวจสอบเวลาว่าสิ้นสุดก่อนบ่ายหรือไม่
|
||||
if(currentDateTime < dutyEndTimeMorning) // ถ้าออกก่อนเวลาสิ้นสุดตอนเช้า ขาดราชการ
|
||||
{
|
||||
checkOutStatus = "ABSENT";
|
||||
}
|
||||
else if(currentDateTime >= dutyEndTimeAfternoon) // ถ้าออกหลังเวลาสิ้นสุดตอนบ่าย ปกติ
|
||||
{
|
||||
checkOutStatus = "NORMAL";
|
||||
}
|
||||
else
|
||||
{
|
||||
checkOutStatus = "ABSENT";
|
||||
}
|
||||
}
|
||||
// checkOutStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) <
|
||||
// DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
|
||||
// // "ABSENT" :
|
||||
// checkout.CheckIn.Date < currentDate.Date ? "NORMAL" :
|
||||
// DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) >=
|
||||
// DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTime}") ?
|
||||
// "NORMAL" :
|
||||
// "ABSENT" :
|
||||
// DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) <
|
||||
// DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTimeMorning}") ?
|
||||
// "ABSENT" :
|
||||
// "NORMAL";
|
||||
}
|
||||
|
||||
if (checkout_process != null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue