diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 539fdfd7..319ff4e3 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -7171,166 +7171,181 @@ namespace BMA.EHR.Application.Repositories.Commands foreach (var recv in command.Receivers) { - var data = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (data == null) - throw new Exception(GlobalMessages.DataNotFound); - - data.IsActive = false; - data.IsLeave = true; - data.LeaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; - data.LeaveDate = command.CommandAffectDate; - - var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var baseAPI = _configuration["API"]; + var apiUrl = $"{baseAPI}/org/profile/command19/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งปลดออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); + var _res = await client.PostAsJsonAsync(apiUrl, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งปลดออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var data = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (data == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //data.IsActive = false; + //data.IsLeave = true; + //data.LeaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; + //data.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งปลดออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - data.Salaries.Add(salary); + //data.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == data.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == data.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = data.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = data.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = data.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = data.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } - var dataSend = command.Receivers.Select(x => new - { - PersonId = x.RefPlacementProfileId, - Id = x.RefDisciplineId, - }); + //var dataSend = command.Receivers.Select(x => new + //{ + // PersonId = x.RefPlacementProfileId, + // Id = x.RefDisciplineId, + //}); - var baseAPI = _configuration["API"]; - var apiUrl = $"{baseAPI}/discipline/result/report/up/resume"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - var req = new HttpRequestMessage(HttpMethod.Post, apiUrl); - var res = await client.PostAsJsonAsync(apiUrl, new { result = dataSend }); - var result = await res.Content.ReadAsStringAsync(); - } + //var baseAPI = _configuration["API"]; + //var apiUrl = $"{baseAPI}/discipline/result/report/up/resume"; + //using (var client = new HttpClient()) + //{ + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); + // var req = new HttpRequestMessage(HttpMethod.Post, apiUrl); + // var res = await client.PostAsJsonAsync(apiUrl, new { result = dataSend }); + // var result = await res.Content.ReadAsStringAsync(); + //} // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -7371,167 +7386,182 @@ namespace BMA.EHR.Application.Repositories.Commands foreach (var recv in command.Receivers) { - var data = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (data == null) - throw new Exception(GlobalMessages.DataNotFound); - - data.IsActive = false; - data.IsLeave = true; - data.LeaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; - data.LeaveDate = command.CommandAffectDate; - - var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var baseAPI = _configuration["API"]; + var apiUrl = $"{baseAPI}/org/profile/command20/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งไล่ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); + var _res = await client.PostAsJsonAsync(apiUrl, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งไล่ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var data = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) - OcId = lastSarary == null ? null : lastSarary.OcId, + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //if (data == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //data.IsActive = false; + //data.IsLeave = true; + //data.LeaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; + //data.LeaveDate = command.CommandAffectDate; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; + + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งไล่ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - data.Salaries.Add(salary); + //data.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == data.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == data.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = data.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = data.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = data.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = data.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } - var dataSend = command.Receivers.Select(x => new - { - PersonId = x.RefPlacementProfileId, - Id = x.RefDisciplineId, - }); + //var dataSend = command.Receivers.Select(x => new + //{ + // PersonId = x.RefPlacementProfileId, + // Id = x.RefDisciplineId, + //}); - var baseAPI = _configuration["API"]; - var apiUrl = $"{baseAPI}/discipline/result/report/up/resume"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - var req = new HttpRequestMessage(HttpMethod.Post, apiUrl); - var res = await client.PostAsJsonAsync(apiUrl, new { result = dataSend }); - var result = await res.Content.ReadAsStringAsync(); - } + //var baseAPI = _configuration["API"]; + //var apiUrl = $"{baseAPI}/discipline/result/report/up/resume"; + //using (var client = new HttpClient()) + //{ + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); + // var req = new HttpRequestMessage(HttpMethod.Post, apiUrl); + // var res = await client.PostAsJsonAsync(apiUrl, new { result = dataSend }); + // var result = await res.Content.ReadAsStringAsync(); + //} // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -8450,149 +8480,163 @@ namespace BMA.EHR.Application.Repositories.Commands var payload_str = JsonConvert.SerializeObject(payload); foreach (var recv in command.Receivers) { - var dataProfile = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (dataProfile == null) - throw new Exception(GlobalMessages.DataNotFound); - - dataProfile.IsActive = false; - dataProfile.IsLeave = true; - dataProfile.LeaveReason = "ได้รับโทษทางวินัย พักจากราชการ"; - dataProfile.LeaveDate = command.CommandAffectDate; - - var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var apiUrl2 = $"{baseAPI}/org/profile/command25/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งพักจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2); + var _res = await client.PostAsJsonAsync(apiUrl2, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งพักจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var dataProfile = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (dataProfile == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //dataProfile.IsActive = false; + //dataProfile.IsLeave = true; + //dataProfile.LeaveReason = "ได้รับโทษทางวินัย พักจากราชการ"; + //dataProfile.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งพักจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - dataProfile.Salaries.Add(salary); + //dataProfile.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -8648,149 +8692,163 @@ namespace BMA.EHR.Application.Repositories.Commands var payload_str = JsonConvert.SerializeObject(payload); foreach (var recv in command.Receivers) { - var dataProfile = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (dataProfile == null) - throw new Exception(GlobalMessages.DataNotFound); - - dataProfile.IsActive = false; - dataProfile.IsLeave = true; - dataProfile.LeaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน"; - dataProfile.LeaveDate = command.CommandAffectDate; - - var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var apiUrl2 = $"{baseAPI}/org/profile/command26/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งให้ออกจากราชการไว้ก่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2); + var _res = await client.PostAsJsonAsync(apiUrl2, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งให้ออกจากราชการไว้ก่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var dataProfile = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (dataProfile == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //dataProfile.IsActive = false; + //dataProfile.IsLeave = true; + //dataProfile.LeaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน"; + //dataProfile.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งให้ออกจากราชการไว้ก่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - dataProfile.Salaries.Add(salary); + //dataProfile.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -8846,149 +8904,163 @@ namespace BMA.EHR.Application.Repositories.Commands var payload_str = JsonConvert.SerializeObject(payload); foreach (var recv in command.Receivers) { - var dataProfile = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (dataProfile == null) - throw new Exception(GlobalMessages.DataNotFound); - - dataProfile.IsActive = false; - dataProfile.IsLeave = true; - dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ภาคทัณฑ์"; - dataProfile.LeaveDate = command.CommandAffectDate; - - var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var apiUrl2 = $"{baseAPI}/org/profile/command27/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งลงโทษ ภาคทัณฑ์ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2); + var _res = await client.PostAsJsonAsync(apiUrl2, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งลงโทษ ภาคทัณฑ์ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var dataProfile = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (dataProfile == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //dataProfile.IsActive = false; + //dataProfile.IsLeave = true; + //dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ภาคทัณฑ์"; + //dataProfile.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งลงโทษ ภาคทัณฑ์ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - dataProfile.Salaries.Add(salary); + //dataProfile.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -9044,149 +9116,163 @@ namespace BMA.EHR.Application.Repositories.Commands var payload_str = JsonConvert.SerializeObject(payload); foreach (var recv in command.Receivers) { - var dataProfile = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (dataProfile == null) - throw new Exception(GlobalMessages.DataNotFound); - - dataProfile.IsActive = false; - dataProfile.IsLeave = true; - dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ตัดเงินเดือน"; - dataProfile.LeaveDate = command.CommandAffectDate; - - var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var apiUrl2 = $"{baseAPI}/org/profile/command28/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งลงโทษ ตัดเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2); + var _res = await client.PostAsJsonAsync(apiUrl2, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งลงโทษ ตัดเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var dataProfile = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (dataProfile == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //dataProfile.IsActive = false; + //dataProfile.IsLeave = true; + //dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ตัดเงินเดือน"; + //dataProfile.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งลงโทษ ตัดเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - dataProfile.Salaries.Add(salary); + //dataProfile.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -9242,149 +9328,163 @@ namespace BMA.EHR.Application.Repositories.Commands var payload_str = JsonConvert.SerializeObject(payload); foreach (var recv in command.Receivers) { - var dataProfile = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (dataProfile == null) - throw new Exception(GlobalMessages.DataNotFound); - - dataProfile.IsActive = false; - dataProfile.IsLeave = true; - dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ลดขั้นเงินเดือน"; - dataProfile.LeaveDate = command.CommandAffectDate; - - var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var apiUrl2 = $"{baseAPI}/org/profile/command29/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2); + var _res = await client.PostAsJsonAsync(apiUrl2, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var dataProfile = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (dataProfile == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //dataProfile.IsActive = false; + //dataProfile.IsLeave = true; + //dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ลดขั้นเงินเดือน"; + //dataProfile.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - dataProfile.Salaries.Add(salary); + //dataProfile.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -9440,149 +9540,163 @@ namespace BMA.EHR.Application.Repositories.Commands var payload_str = JsonConvert.SerializeObject(payload); foreach (var recv in command.Receivers) { - var dataProfile = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (dataProfile == null) - throw new Exception(GlobalMessages.DataNotFound); - - dataProfile.IsActive = false; - dataProfile.IsLeave = true; - dataProfile.LeaveReason = "ได้รับโทษทางวินัย เพิ่มโทษ"; - dataProfile.LeaveDate = command.CommandAffectDate; - - var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var apiUrl2 = $"{baseAPI}/org/profile/command30/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งเพิ่มโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2); + var _res = await client.PostAsJsonAsync(apiUrl2, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งเพิ่มโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var dataProfile = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (dataProfile == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //dataProfile.IsActive = false; + //dataProfile.IsLeave = true; + //dataProfile.LeaveReason = "ได้รับโทษทางวินัย เพิ่มโทษ"; + //dataProfile.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งเพิ่มโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - dataProfile.Salaries.Add(salary); + //dataProfile.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -9638,149 +9752,163 @@ namespace BMA.EHR.Application.Repositories.Commands var payload_str = JsonConvert.SerializeObject(payload); foreach (var recv in command.Receivers) { - var dataProfile = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (dataProfile == null) - throw new Exception(GlobalMessages.DataNotFound); - - dataProfile.IsActive = false; - dataProfile.IsLeave = true; - dataProfile.LeaveReason = "ได้รับโทษทางวินัย งดโทษ"; - dataProfile.LeaveDate = command.CommandAffectDate; - - var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var apiUrl2 = $"{baseAPI}/org/profile/command31/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งงดโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2); + var _res = await client.PostAsJsonAsync(apiUrl2, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งงดโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var dataProfile = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (dataProfile == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //dataProfile.IsActive = false; + //dataProfile.IsLeave = true; + //dataProfile.LeaveReason = "ได้รับโทษทางวินัย งดโทษ"; + //dataProfile.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งงดโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - dataProfile.Salaries.Add(salary); + //dataProfile.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); @@ -9836,149 +9964,163 @@ namespace BMA.EHR.Application.Repositories.Commands var payload_str = JsonConvert.SerializeObject(payload); foreach (var recv in command.Receivers) { - var dataProfile = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (dataProfile == null) - throw new Exception(GlobalMessages.DataNotFound); - - dataProfile.IsActive = false; - dataProfile.IsLeave = true; - dataProfile.LeaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง"; - dataProfile.LeaveDate = command.CommandAffectDate; - - var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary != null && lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary + var apiUrl2 = $"{baseAPI}/org/profile/command32/{recv.RefPlacementProfileId}"; + using (var client = new HttpClient()) { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary == null ? null : lastSarary.Amount, - PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2); + var _res = await client.PostAsJsonAsync(apiUrl2, new + { + profileId = recv.RefPlacementProfileId, + date = command.CommandAffectDate, + refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + salaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + }); + var _result = await _res.Content.ReadAsStringAsync(); + } + //var dataProfile = await _dbContext.Set() + // .Include(x => x.Salaries) + // .ThenInclude(x => x.PositionLevel) + // .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - OcId = lastSarary == null ? null : lastSarary.OcId, + //if (dataProfile == null) + // throw new Exception(GlobalMessages.DataNotFound); - PositionId = lastSarary == null ? null : lastSarary.PositionId, + //dataProfile.IsActive = false; + //dataProfile.IsLeave = true; + //dataProfile.LeaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง"; + //dataProfile.LeaveDate = command.CommandAffectDate; - PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, - PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, - PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, - PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + //var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + //var order = 1; + //if (lastSarary != null && lastSarary.Order != null) + // order = lastSarary.Order.Value + 1; - CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", - CommandTypeName = command.CommandType.Name, + //var salary = new ProfileSalary + //{ + // Order = order, + // Date = command.CommandAffectDate, + // Amount = lastSarary == null ? null : lastSarary.Amount, + // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, + // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, + // SalaryClass = "", + // SalaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + // OcId = lastSarary == null ? null : lastSarary.OcId, + + // PositionId = lastSarary == null ? null : lastSarary.PositionId, + + // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, + // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, + // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, + // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, + // PosNoId = lastSarary == null ? null : lastSarary.PosNoId, + + // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + // CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + // PositionEmployeeGroupId = null, + // PositionEmployeeLevelId = null, + // PositionEmployeePositionId = null, + // PositionEmployeePositionSideId = null, + // PosNoEmployee = "", - //PositionPathSideId = lastSarary ==null? null : lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary ==null? null : lastSarary.PositionExecutiveSideId, + // //PositionPathSideId = lastSarary ==null? null : lastSarary.PositionPathSideId == null, + // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, + // //PositionExecutiveSideId = lastSarary ==null? null : lastSarary.PositionExecutiveSideId, - IsActive = true, - CreatedAt = DateTime.Now, - CreatedFullName = FullName ?? "System Administrator", - CreatedUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", + // IsActive = true, + // CreatedAt = DateTime.Now, + // CreatedFullName = FullName ?? "System Administrator", + // CreatedUserId = UserId ?? "", + // LastUpdatedAt = DateTime.Now, + // LastUpdateFullName = FullName ?? "System Administrator", + // LastUpdateUserId = UserId ?? "", - }; + //}; - if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - dataProfile.Salaries.Add(salary); + //dataProfile.Salaries.Add(salary); - // remove profile position - var profilePosition = await _dbContext.Set() - .Include(x => x.Profile) - .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); - if (profilePosition != null) - _dbContext.Set().Remove(profilePosition); + //// remove profile position + //var profilePosition = await _dbContext.Set() + // .Include(x => x.Profile) + // .Include(x => x.OrganizationPosition) + // .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id); + //if (profilePosition != null) + // _dbContext.Set().Remove(profilePosition); - await _dbContext.SaveChangesAsync(); + //await _dbContext.SaveChangesAsync(); - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + //// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + //// Send noti inbox and email + //var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + //_emailSenderService.SendMail(subject, body, "dev@frappet.com"); - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = dataProfile.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = dataProfile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().Add(noti); + //await _dbContext.SaveChangesAsync(); } // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); - if (pf != null) - { - if (cc.IsSendInbox) - { - var inbox = new Inbox - { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = payload_str, - }; - _dbContext.Set().Add(inbox); - } + //foreach (var cc in command.Deployments) + //{ + // var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + // if (pf != null) + // { + // if (cc.IsSendInbox) + // { + // var inbox = new Inbox + // { + // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Payload = payload_str, + // }; + // _dbContext.Set().Add(inbox); + // } - if (cc.IsSendMail) - { - // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ - // Send noti inbox and email - var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - } + // if (cc.IsSendMail) + // { + // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // // Send noti inbox and email + // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + // _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + // } - var noti = new Notification - { - Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Type = "LINK", - Payload = payload_str, - }; - _dbContext.Set().Add(noti); - } - } + // var noti = new Notification + // { + // Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = pf.Id, + // Type = "LINK", + // Payload = payload_str, + // }; + // _dbContext.Set().Add(noti); + // } + //} // change command status var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5);