diff --git a/BMA.EHR.Leave/BMA.EHR.Leave.csproj b/BMA.EHR.Leave/BMA.EHR.Leave.csproj index 8d70a25d..83132dd1 100644 --- a/BMA.EHR.Leave/BMA.EHR.Leave.csproj +++ b/BMA.EHR.Leave/BMA.EHR.Leave.csproj @@ -81,4 +81,10 @@ + + + PreserveNewest + + + diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 4cdec83e..c41273ed 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -11,6 +11,7 @@ using BMA.EHR.Domain.Shared; using BMA.EHR.Leave.Service.DTOs.Reports; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Routing.Template; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OfficeOpenXml; @@ -2157,12 +2158,15 @@ namespace BMA.EHR.Leave.Service.Controllers var org = _userProfileRepository.GetOc(Guid.Parse(req.nodeId), req.node, AccessToken); var organizationName = $"{(!string.IsNullOrEmpty(org.Child4) ? org.Child4 + "/" : "")}{(!string.IsNullOrEmpty(org.Child3) ? org.Child3 + "/" : "")}{(!string.IsNullOrEmpty(org.Child2) ? org.Child2 + "/" : "")}{(!string.IsNullOrEmpty(org.Child1) ? org.Child1 + "/" : "")}{org.Root ?? ""}"; var dateTimeStamp = $"ประจำ ณ วัน{req.StartDate.Date.GetThaiDayOfWeek()} ที่ {req.StartDate.Date.ToThaiShortDate()}{enddate}"; - //var template = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", "TimeStampRecords.xlsx"); - //FileInfo reportFile = new FileInfo(template); - using (var package = new ExcelPackage()) + + var templatePath = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", "TimeStampRecords.xlsx"); + byte[] templateBytes = System.IO.File.ReadAllBytes(templatePath); + //using (var package = new ExcelPackage(fileInfo)) + using (var stream = new MemoryStream(templateBytes)) + using (var package = new ExcelPackage(stream)) { - //var worksheet = package.Workbook.Worksheets[0]; - var worksheet = package.Workbook.Worksheets.Add("Sheet1"); + //var worksheet = package.Workbook.Worksheets.Add("Sheet1"); + var worksheet = package.Workbook.Worksheets["Sheet1"] ?? package.Workbook.Worksheets[0]; worksheet.Cells["A1:J1"].Merge = true; worksheet.Cells["A2:J2"].Merge = true; @@ -2174,7 +2178,7 @@ namespace BMA.EHR.Leave.Service.Controllers range.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; range.Style.Font.Bold = true; } - worksheet.Cells[1, 1].Value = "แบบการลงเวลาปฏิบัติราชการ"; + //worksheet.Cells[1, 1].Value = "แบบการลงเวลาปฏิบัติราชการ"; worksheet.Cells[2, 1].Value = organizationName; worksheet.Cells[3, 1].Value = dateTimeStamp; @@ -2188,16 +2192,16 @@ namespace BMA.EHR.Leave.Service.Controllers range.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; range.Style.Font.Bold = true; } - worksheet.Cells[4, 1].Value = "ลำดับที่"; - worksheet.Cells[4, 2].Value = "ชื่อ - สกุล"; - worksheet.Cells[4, 3].Value = "รอบ"; - worksheet.Cells[4, 4].Value = "วันที่เข้างาน"; - worksheet.Cells[4, 5].Value = "พิกัด"; - worksheet.Cells[4, 6].Value = "เวลามา"; - worksheet.Cells[4, 7].Value = "วันที่ออกงาน"; - worksheet.Cells[4, 8].Value = "พิกัด"; - worksheet.Cells[4, 9].Value = "เวลากลับ"; - worksheet.Cells[4, 10].Value = "หมายเหตุ"; + //worksheet.Cells[4, 1].Value = "ลำดับที่"; + //worksheet.Cells[4, 2].Value = "ชื่อ - สกุล"; + //worksheet.Cells[4, 3].Value = "รอบ"; + //worksheet.Cells[4, 4].Value = "วันที่เข้างาน"; + //worksheet.Cells[4, 5].Value = "พิกัด"; + //worksheet.Cells[4, 6].Value = "เวลามา"; + //worksheet.Cells[4, 7].Value = "วันที่ออกงาน"; + //worksheet.Cells[4, 8].Value = "พิกัด"; + //worksheet.Cells[4, 9].Value = "เวลากลับ"; + //worksheet.Cells[4, 10].Value = "หมายเหตุ"; int startRow = 5; foreach (var emp in employees) { diff --git a/BMA.EHR.Leave/Reports/TimeStampRecords.xlsx b/BMA.EHR.Leave/Reports/TimeStampRecords.xlsx index 3c84bb60..ee4527d5 100644 Binary files a/BMA.EHR.Leave/Reports/TimeStampRecords.xlsx and b/BMA.EHR.Leave/Reports/TimeStampRecords.xlsx differ diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs index 0472cbdc..660d16ef 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs @@ -2118,18 +2118,19 @@ namespace BMA.EHR.Retirement.Service.Controllers { var retirePeriodOfficer = await _context.RetirementPeriods .Include(x => x.RetirementRawProfiles.Where(y => y.Remove != "REMOVE")) - .Where(x => x.Year == year && x.Type.Trim().ToUpper().Contains(type)) + .Where(x => x.Year == year && (x.Type ?? "").Trim().ToUpper().Contains(type) && x.Round == 1) .FirstOrDefaultAsync(); if (retirePeriodOfficer == null) return Error("ไม่พบรอบประกาศเกษียณอายุราชการ"); - var data = retirePeriodOfficer.RetirementRawProfiles - .Select(x => new - { - profileId = x.profileId - }) - .ToList(); + var data = new + { + signDate = retirePeriodOfficer.SignDate ?? null, + profiles = retirePeriodOfficer.RetirementRawProfiles + .Select(x => new { profileId = x.profileId }) + .ToList() + }; return Success(data); } diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index d8f2adf0..0a381ce2 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -3047,6 +3047,7 @@ namespace BMA.EHR.Retirement.Service.Controllers commandCode = r.commandCode, commandName = r.commandName, remark = r.remark, + resignId = p.RetirementResign.Id, }).ToList(); var baseAPIOrg = _configuration["API"]; @@ -3077,23 +3078,23 @@ namespace BMA.EHR.Retirement.Service.Controllers } else { - // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; - // using (var client = new HttpClient()) - // { - // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - // client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - // var _res = await client.PostAsJsonAsync(apiUrlOrg, new - // { - // data = resultData, - // }); - // var _result = await _res.Content.ReadAsStringAsync(); - // if (_res.IsSuccessStatusCode) - // { - data.ForEach(profile => profile.Status = "DONE"); - data.ForEach(profile => profile.RetirementResign.Status = "CANCEL"); - await _context.SaveChangesAsync(); - // } - // } + var apiUrlOrg = $"{baseAPIOrg}/org/command/cancel-resign"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + resignId = resultData.Select(x => x.resignId).ToList(), + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => profile.RetirementResign.Status = "CANCEL"); + await _context.SaveChangesAsync(); + } + } } return Success(); } diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index 8600ed2e..439611bf 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -2542,6 +2542,7 @@ namespace BMA.EHR.Retirement.Service.Controllers commandCode = r.commandCode, commandName = r.commandName, remark = r.remark, + resignId = p.RetirementResignEmployee.Id }).ToList(); var baseAPIOrg = _configuration["API"]; @@ -2573,23 +2574,23 @@ namespace BMA.EHR.Retirement.Service.Controllers } else { - // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave"; - // using (var client = new HttpClient()) - // { - // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - // client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - // var _res = await client.PostAsJsonAsync(apiUrlOrg, new - // { - // data = resultData, - // }); - // var _result = await _res.Content.ReadAsStringAsync(); - // if (_res.IsSuccessStatusCode) - // { - data.ForEach(profile => profile.Status = "DONE"); - data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL"); - await _context.SaveChangesAsync(); - // } - // } + var apiUrlOrg = $"{baseAPIOrg}/org/command/cancel-resign"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + resignId = resultData.Select(x => x.resignId).ToList(), + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL"); + await _context.SaveChangesAsync(); + } + } } return Success(); }