From 6afb95fe1bde985530c9f73ff5695ff2d1bcb76c Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 24 Jan 2025 10:18:41 +0700 Subject: [PATCH] =?UTF-8?q?fix=20issue=20:=20SIT=20=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=9A=E0=B8=9A=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B6?= =?UTF-8?q?=E0=B8=81=E0=B9=80=E0=B8=A7=E0=B8=A5=E0=B8=B2=E0=B8=9B=E0=B8=8F?= =?UTF-8?q?=E0=B8=B4=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=87=E0=B8=B2?= =?UTF-8?q?=E0=B8=99>>=E0=B8=A5=E0=B8=87=E0=B9=80=E0=B8=A7=E0=B8=A5?= =?UTF-8?q?=E0=B8=B2=E0=B8=81=E0=B8=A3=E0=B8=93=E0=B8=B5=E0=B8=9E=E0=B8=B4?= =?UTF-8?q?=E0=B9=80=E0=B8=A8=E0=B8=A9=20(=E0=B9=84=E0=B8=A1=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=B5=E0=B9=81=E0=B8=88=E0=B9=89=E0=B8=87=E0=B9=80?= =?UTF-8?q?=E0=B8=95=E0=B8=B7=E0=B8=AD=E0=B8=99=E0=B9=84=E0=B8=9B=E0=B8=A2?= =?UTF-8?q?=E0=B8=B1=E0=B8=87=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=9A=E0=B8=B1?= =?UTF-8?q?=E0=B8=87=E0=B8=84=E0=B8=B1=E0=B8=9A=E0=B8=9A=E0=B8=B1=E0=B8=8D?= =?UTF-8?q?=E0=B8=8A=E0=B8=B2)=20#969?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdditionalCheckRequestRepository.cs | 102 ++++++++++++------ .../Profiles/GetProfileByKeycloakIdDto.cs | 4 + .../Controllers/LeaveRequestController.cs | 47 +++++++- 3 files changed, 116 insertions(+), 37 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs index ceae6c2b..0952daae 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs @@ -73,47 +73,79 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants var userId = UserId != null ? Guid.Parse(UserId) : Guid.Empty; var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken ?? ""); - var profile_id = profile == null ? Guid.Empty : profile.Id; - var rootOc = _userProfileRepository.GetRootOcId(profile_id, AccessToken); - var approver = string.Empty; - var list = new List(); - if (rootOc != null) + // fix issue : SIT ระบบบันทึกเวลาปฏิบัติงาน>>ลงเวลากรณีพิเศษ (ไม่มีแจ้งเตือนไปยังผู้บังคับบัญชา) #969 + // send noti + inbox + mail + // send inbox and notification + var subject_str = $"มีการขออนุมัติลงเวลากรณีพิเศษ"; + var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix}{profile.FirstName} {profile.LastName} ในวันที่ {entity.CheckDate.Date.ToThaiShortDate2()}"; + + var subject = subject_str; + var body = body_str; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + + + var inbox = new Inbox { - list = await _commandRepository.GetOrgApproverAsync(rootOc ?? Guid.Empty); - } - if (list.Count > 0) + Subject = subject_str, + Body = body_str, + ReceiverUserId = profile.CommanderId == Guid.Empty || profile.CommanderId == null ? Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6") : profile.CommanderId.Value, + Payload = "", + }; + _appContext.Set().Add(inbox); + + var noti = new Notification { - var appr = list.FirstOrDefault(); - - // send inbox and notification - var subject_str = $"มีการขออนุมัติลงเวลากรณีพิเศษ"; - var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix}{profile.FirstName} {profile.LastName} ในวันที่ {entity.CheckDate.Date.ToThaiShortDate2()}"; - - var subject = subject_str; - var body = body_str; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + Body = body_str, + ReceiverUserId = profile.CommanderId == Guid.Empty || profile.CommanderId == null ? Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6") : profile.CommanderId.Value, + Type = "", + Payload = "", + }; + _appContext.Set().Add(noti); + await _appContext.SaveChangesAsync(); - var inbox = new Inbox - { - Subject = subject_str, - Body = body_str, - ReceiverUserId = appr.Id == Guid.Empty ? Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6") : appr.Id, - Payload = "", - }; - _appContext.Set().Add(inbox); + //var profile_id = profile == null ? Guid.Empty : profile.Id; - var noti = new Notification - { - Body = body_str, - ReceiverUserId = appr.Id == Guid.Empty ? Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6") : appr.Id, - Type = "", - Payload = "", - }; - _appContext.Set().Add(noti); - await _appContext.SaveChangesAsync(); - } + //var rootOc = _userProfileRepository.GetRootOcId(profile_id, AccessToken); + //var approver = string.Empty; + //var list = new List(); + //if (rootOc != null) + //{ + // list = await _commandRepository.GetOrgApproverAsync(rootOc ?? Guid.Empty); + //} + //if (list.Count > 0) + //{ + // var appr = list.FirstOrDefault(); + + // // send inbox and notification + // var subject_str = $"มีการขออนุมัติลงเวลากรณีพิเศษ"; + // var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix}{profile.FirstName} {profile.LastName} ในวันที่ {entity.CheckDate.Date.ToThaiShortDate2()}"; + + // var subject = subject_str; + // var body = body_str; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + + + // var inbox = new Inbox + // { + // Subject = subject_str, + // Body = body_str, + // ReceiverUserId = appr.Id == Guid.Empty ? Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6") : appr.Id, + // Payload = "", + // }; + // _appContext.Set().Add(inbox); + + // var noti = new Notification + // { + // Body = body_str, + // ReceiverUserId = appr.Id == Guid.Empty ? Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6") : appr.Id, + // Type = "", + // Payload = "", + // }; + // _appContext.Set().Add(noti); + // await _appContext.SaveChangesAsync(); + //} return entity; } diff --git a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs index d43b35bf..12641e9d 100644 --- a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs +++ b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs @@ -58,6 +58,10 @@ namespace BMA.EHR.Application.Responses.Profiles public double? PositionSalaryAmount { get; set; } public string? Commander { get; set; } + public Guid? CommanderId { get; set; } + + public Guid? CommanderKeycloak { get; set; } + } public class PosLevel diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index b1f30fec..9f4f7a61 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -703,12 +703,55 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } + var govAge = (profile?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date); + var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type); if (leaveType == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } + var leaveLimit = 0; + if (leaveType.Code.Trim().ToUpper() == "LV-005") + { + if (govAge >= 180) + { + if (govAge >= 3650) leaveLimit = 30; + else leaveLimit = 20; + } + else + { + leaveLimit = 0; + } + //var leavePrevYear = (await _leaveRequestRepository.GetSumApproveLeaveAsync(thisYear)).Where(x => x.LeaveTypeCode == "LV-005" && x.KeycloakUserId == userId).FirstOrDefault(); + //var leavePrevYearRemain = 0; + + + ////var leavePrevYearRemain = 10 - (leavePrevYear == null ? 0 : leavePrevYear.SumLeaveDay); // หายอดวันลาที่เหลือของปีก่อน + + //if (govAge >= 180) + // if (govAge >= 3650) + // { + // // ถ้าอายุราชการเกิน 10 ปี ได้บวกเพิ่มอีก 10 วัน + // isLeave = (totalDay - (sumWorkDay + sumWeekend) + sumApproveLeave) <= (20 + leavePrevYearRemain); + // if (!isLeave) message = "จำนวนวันลาเกินที่กำหนด"; + // } + // else + // { + // isLeave = (totalDay - (sumWorkDay + sumWeekend) + sumApproveLeave) <= (10 + leavePrevYearRemain); + // if (!isLeave) message = "จำนวนวันลาเกินที่กำหนด"; + // } + + //else + //{ + // leavePrevYearRemain + //} + + } + else + leaveLimit = leaveType.Limit; + + var sumLeave = await _leaveRequestRepository.GetSumLeaveByTypeForUserAsync(userId, req.Type, thisYear); var restOldDay = await _leaveRequestRepository.GetRestDayTotalByYearForUserAsync(userId, thisYear - 1); @@ -738,9 +781,9 @@ namespace BMA.EHR.Leave.Service.Controllers PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel, OrganizationName = profile.Root ?? "", //profile.Oc ?? "", - LeaveLimit = leaveType.Limit, + LeaveLimit = leaveLimit, LeaveTotal = sumLeave, - LeaveRemain = leaveType.Limit - sumLeave, + LeaveRemain = leaveLimit - sumLeave, RestDayTotalOld = restOldDay, BirthDate = profile.BirthDate.Date, DateAppoint = profile.DateAppoint == null ? null : profile.DateAppoint.Value.Date,