diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index 9819ecd0..3f8c9536 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -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)