From 5c3c9739d17c88a3ad4977e6aabfd68d19ce22a7 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 19 Jan 2026 15:30:28 +0330 Subject: [PATCH 1/5] fix regex and validation for rollcall history case details --- .../Repository/RollCallRepository.cs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index eb5e40f7..f0758afb 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -20,6 +20,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using _0_Framework.Exceptions; +using OfficeOpenXml.Packaging.Ionic.Zip; namespace CompanyManagment.EFCore.Repository; @@ -2297,26 +2298,33 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //این برای این هست که اگر بر اساس پرسنل جستجو شده بود و در titleId اگر به فرمت YYYY_MM اومد به این معنی هست که باید بر طبق ماه فیلتر بشه نه به صورت روزانه if (searchModel.EmployeeId is > 0) { - //TODO: set correct regex. - // if (!Regex.IsMatch(titleId, "")) - // throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + if (!Regex.IsMatch(titleId, @"^\d{4}_\d{2}$")) + throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + var splitDate = titleId.Split("_"); var year = Convert.ToInt32(splitDate.First()); var month = Convert.ToInt32(splitDate.Last()); var startDateFa = $"{year:D4}/{month:D2}/01"; + if (!startDateFa.TryToGeorgianDateTime(out startDate)) + { + throw new BadRequestException("تاریخ وارد شده نامعتبر است"); + } + var endDateFa = startDateFa.FindeEndOfMonth(); - - startDate = startDateFa.ToGeorgianDateTime(); - endDate = endDateFa.ToGeorgianDateTime(); + + if (!endDateFa.TryToGeorgianDateTime(out endDate)) + { + throw new BadRequestException("تاریخ وارد شده نامعتبر است"); + } query = query .Where(x => x.RollCallEmployee.EmployeeId == searchModel.EmployeeId); } else { - //TODO: set correct regex. - // if (!Regex.IsMatch(titleId, "")) - // throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + if (!Regex.IsMatch(titleId, @"^\d{4}/\d{2}/\d{2}$")) + throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + startDate = titleId.ToGeorgianDateTime(); endDate = startDate; From 5942075dd625c35955fd3bbf4681025968201a57 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 2 Feb 2026 17:31:37 +0330 Subject: [PATCH 2/5] refactor roll call case history controller and add total working hours endpoint --- ...er.cs => RollCallCaseHistoryController.cs} | 49 +++++++++++++++-- .../Company/RollCall/CaseHistory.cshtml.cs | 4 +- ServiceHost/Controllers/GeneralController.cs | 55 ++++--------------- 3 files changed, 57 insertions(+), 51 deletions(-) rename ServiceHost/Areas/Client/Controllers/RollCall/{CaseHistoryController.cs => RollCallCaseHistoryController.cs} (71%) diff --git a/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs b/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs similarity index 71% rename from ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs rename to ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs index 5f8b8b77..5bbf6c70 100644 --- a/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs +++ b/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs @@ -6,12 +6,12 @@ using ServiceHost.BaseControllers; namespace ServiceHost.Areas.Client.Controllers.RollCall; -public class CaseHistoryController : ClientBaseController +public class RollCallCaseHistoryController : ClientBaseController { private readonly IRollCallApplication _rollCallApplication; private readonly long _workshopId; - public CaseHistoryController(IRollCallApplication rollCallApplication, + public RollCallCaseHistoryController(IRollCallApplication rollCallApplication, IAuthHelper authHelper) { _rollCallApplication = rollCallApplication; @@ -50,6 +50,48 @@ public class CaseHistoryController : ClientBaseController { return await _rollCallApplication.GetCaseHistoryDetails(_workshopId, titleId, searchModel); } + + [HttpGet("total-working")] + public ActionResult> OnGetTotalWorking( + string startDate, + string startTime, + string endDate, + string endTime) + { + var op = new OperationResult(); + const string emptyValue = "-"; + + if (!TryParseDateTime(startDate, startTime, out var start) || + !TryParseDateTime(endDate, endTime, out var end)) + { + return op.Succcedded(emptyValue); + } + + if (start >= end) + { + return op.Succcedded(emptyValue); + } + + var duration = (end - start).ToFarsiHoursAndMinutes(emptyValue); + return op.Succcedded(duration); + } + + private static bool TryParseDateTime(string date, string time, out DateTime result) + { + result = default; + + try + { + var dateTime = date.ToGeorgianDateTime(); + var timeOnly = TimeOnly.Parse(time); + result = dateTime.AddTicks(timeOnly.Ticks); + return true; + } + catch + { + return false; + } + } // [HttpGet("excel")] // public async Task GetDownload(string titleId,RollCallCaseHistorySearchModel searchModel) @@ -61,7 +103,7 @@ public class CaseHistoryController : ClientBaseController // $"{workshopFullName} - {caseHistoryRollCallExcelForOneDay.DayOfWeekFa}،{caseHistoryRollCallExcelForOneDay.DateFa}.xlsx"); // // } - + // [HttpGet("edit")] // public ActionResult<> GetEditDetails(string date,long employeeId) // { @@ -82,5 +124,4 @@ public class CaseHistoryController : ClientBaseController // TotalRollCallsDuration = total.ToFarsiHoursAndMinutes("-") // }; // } - } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml.cs index 04e0d1b0..7b4f8966 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml.cs @@ -250,9 +250,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall var span = end - start; var hours = (int)span.TotalHours; var minutes = span.Minutes; - - - + if (hours > 0 && minutes > 0) { return new JsonResult(new diff --git a/ServiceHost/Controllers/GeneralController.cs b/ServiceHost/Controllers/GeneralController.cs index 7871eef9..01ed3d64 100644 --- a/ServiceHost/Controllers/GeneralController.cs +++ b/ServiceHost/Controllers/GeneralController.cs @@ -42,6 +42,15 @@ public class GeneralController : GeneralBaseController currentDate }); } + [HttpGet("persian-day-of-week")] + public ActionResult> OnGetDayOfWeek(string dateFa) + { + var op = new OperationResult(); + if (!dateFa.TryToGeorgianDateTime(out DateTime date)) + return op.Failed("تاریخ وارد شده نامعتبر است"); + + return op.Succcedded(date.DayOfWeek.DayOfWeeKToPersian()); + } // [HttpGet("pm-permissions")] // public IActionResult GetPMPermissions() @@ -96,44 +105,8 @@ public class GeneralController : GeneralBaseController var statusCode = isSuccess ? "1" : "0"; return $"{baseUrl}/callback?Status={statusCode}&transactionId={transactionId}"; } -} - -public class TokenReq -{ - public long Amount { get; set; } - - public string CallbackUrl { get; set; } - - [Display(Name = "شماره فاکتور")] - [MaxLength(100)] - [Required] - [Key] - // be ezaye har pazirande bayad yekta bashad - public string invoiceID { get; set; } - - [Required] public long terminalID { get; set; } - - /* - * JSON Bashad - * etelaate takmili site harchi - * nabayad char khas dashte bashe (*'"xp_%!+- ...) - */ - public string Payload { get; set; } = ""; - public string email { get; set; } -} - -public class TokenResp -{ - // if 0 = success - public int Status { get; set; } - public string AccessToken { get; set; } -} - -public class PayRequest -{ - [Required] [MaxLength(3000)] public string token { get; set; } - [Required] public long terminalID { get; set; } - public string nationalCode { get; set; } + + } public class SepehrGatewayPayResponse @@ -169,10 +142,4 @@ public class SepehrGatewayPayResponse public string issuerbank { get; set; } [Display(Name = " شماره کارت ")] public string cardnumber { get; set; } -} - -public class AdviceReq -{ - [Display(Name = " رسید دیجیتال ")] public string digitalreceipt { get; set; } - public long Tid { get; set; } } \ No newline at end of file From 88744bd4cf2e7d5bd65507b99092d3182de2dfb9 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 2 Feb 2026 17:54:33 +0330 Subject: [PATCH 3/5] add endpoint to download case history as Excel file --- .../RollCall/IRollCallApplication.cs | 10 +++++++ .../RollCallApplication.cs | 16 +++++++++-- .../RollCall/RollCallCaseHistoryController.cs | 27 ++++++++++--------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs b/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs index bdff1e85..31960578 100644 --- a/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs +++ b/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs @@ -131,6 +131,16 @@ namespace CompanyManagment.App.Contracts.RollCall Task> GetCaseHistoryTitles(long workshopId,RollCallCaseHistorySearchModel searchModel); Task> GetCaseHistoryDetails(long workshopId, string titleId, RollCallCaseHistorySearchModel searchModel); + + Task DownloadCaseHistoryExcel(long workshopId, string titleId, + RollCallCaseHistorySearchModel searchModel); + } + + public class RollCallCaseHistoryExcelDto + { + public byte[] Bytes { get; set; } + public string FileName { get; set; } + public string MimeType { get; set; } } public class RollCallCaseHistoryDetail diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index 7f145407..1397b15b 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -16,6 +16,7 @@ using Company.Domain.LeaveAgg; using Company.Domain.RollCallAgg; using Company.Domain.RollCallAgg.DomainService; using Company.Domain.RollCallEmployeeAgg; +using Company.Domain.WorkshopAgg; using CompanyManagment.App.Contracts.Checkout; using CompanyManagment.App.Contracts.Employee; using CompanyManagment.App.Contracts.RollCall; @@ -34,8 +35,9 @@ public class RollCallApplication : IRollCallApplication private readonly ICustomizeWorkshopSettingsRepository _customizeWorkshopSettingsRepository; private readonly ICustomizeWorkshopEmployeeSettingsRepository _customizeWorkshopEmployeeSettingsRepository; private readonly ICustomizeCheckoutTempRepository _customizeCheckoutTempRepository; + private readonly IWorkshopRepository _workshopRepository; - public RollCallApplication(IRollCallRepository rollCallRepository, IRollCallEmployeeRepository rollCallEmployeeRepository, IEmployeeRepository employeeRepository, ILeaveRepository leaveRepository, ICustomizeCheckoutRepository customizeCheckoutRepository, ICheckoutRepository checkoutRepository, IRollCallDomainService rollCallDomainService, ICustomizeWorkshopSettingsRepository customizeWorkshopSettingsRepository, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, ICustomizeCheckoutTempRepository customizeCheckoutTempRepository) + public RollCallApplication(IRollCallRepository rollCallRepository, IRollCallEmployeeRepository rollCallEmployeeRepository, IEmployeeRepository employeeRepository, ILeaveRepository leaveRepository, ICustomizeCheckoutRepository customizeCheckoutRepository, ICheckoutRepository checkoutRepository, IRollCallDomainService rollCallDomainService, ICustomizeWorkshopSettingsRepository customizeWorkshopSettingsRepository, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, ICustomizeCheckoutTempRepository customizeCheckoutTempRepository, IWorkshopRepository workshopRepository) { _rollCallRepository = rollCallRepository; _rollCallEmployeeRepository = rollCallEmployeeRepository; @@ -47,7 +49,8 @@ public class RollCallApplication : IRollCallApplication _customizeWorkshopSettingsRepository = customizeWorkshopSettingsRepository; _customizeWorkshopEmployeeSettingsRepository = customizeWorkshopEmployeeSettingsRepository; _customizeCheckoutTempRepository = customizeCheckoutTempRepository; - } + _workshopRepository = workshopRepository; + } public OperationResult Create(CreateRollCall command) { @@ -869,4 +872,13 @@ public class RollCallApplication : IRollCallApplication { return await _rollCallRepository.GetCaseHistoryDetails(workshopId, titleId, searchModel); } + + public async Task DownloadCaseHistoryExcel(long workshopId, string titleId, + RollCallCaseHistorySearchModel searchModel) + { + var data = await _rollCallRepository + .GetCaseHistoryDetails(workshopId, titleId, searchModel); + var workshopFullName = _workshopRepository.(workshopId); + byte[] excelBytes = RollCallExcelGenerator.CaseHistoryExcelForOneDay(data); + } } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs b/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs index 5bbf6c70..fc22ec04 100644 --- a/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs +++ b/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs @@ -1,6 +1,7 @@ using _0_Framework.Application; using CompanyManagement.Infrastructure.Excel.RollCall; using CompanyManagment.App.Contracts.RollCall; +using CompanyManagment.App.Contracts.Workshop; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; @@ -10,11 +11,12 @@ public class RollCallCaseHistoryController : ClientBaseController { private readonly IRollCallApplication _rollCallApplication; private readonly long _workshopId; - + private readonly IWorkshopApplication _workshopApplication; public RollCallCaseHistoryController(IRollCallApplication rollCallApplication, - IAuthHelper authHelper) + IAuthHelper authHelper, IWorkshopApplication workshopApplication) { _rollCallApplication = rollCallApplication; + _workshopApplication = workshopApplication; _workshopId = authHelper.GetWorkshopId(); } @@ -93,16 +95,17 @@ public class RollCallCaseHistoryController : ClientBaseController } } - // [HttpGet("excel")] - // public async Task GetDownload(string titleId,RollCallCaseHistorySearchModel searchModel) - // { - // var data = await _rollCallApplication.GetCaseHistoryDetails(_workshopId, titleId, searchModel); - // byte[] excelBytes = RollCallExcelGenerator.CaseHistoryExcelForOneDay(data); - // return File(excelBytes, - // "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - // $"{workshopFullName} - {caseHistoryRollCallExcelForOneDay.DayOfWeekFa}،{caseHistoryRollCallExcelForOneDay.DateFa}.xlsx"); - // - // } + [HttpGet("excel")] + public async Task GetDownload(string titleId, RollCallCaseHistorySearchModel searchModel) + { + var res =await _rollCallApplication.DownloadCaseHistoryExcel(_workshopId, titleId, searchModel); + + + return File(res.Bytes, + res.MimeType, + res.FileName); + + } // [HttpGet("edit")] // public ActionResult<> GetEditDetails(string date,long employeeId) From bf2a102a55592079b2096f5f48b333a5bf11d036 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 2 Feb 2026 19:07:11 +0330 Subject: [PATCH 4/5] add Excel export functionality for roll call case history --- .../RollCall/RollCallExcelGenerator.cs | 111 ++++++++++++++++++ .../CompanyManagment.Application.csproj | 1 + .../RollCallApplication.cs | 47 +++++++- ServiceHost/Properties/launchSettings.json | 2 +- 4 files changed, 155 insertions(+), 6 deletions(-) diff --git a/CompanyManagement.Infrastructure.Excel/RollCall/RollCallExcelGenerator.cs b/CompanyManagement.Infrastructure.Excel/RollCall/RollCallExcelGenerator.cs index 8c749dd4..8f0247a3 100644 --- a/CompanyManagement.Infrastructure.Excel/RollCall/RollCallExcelGenerator.cs +++ b/CompanyManagement.Infrastructure.Excel/RollCall/RollCallExcelGenerator.cs @@ -1,6 +1,12 @@ using _0_Framework.Excel; +using _0_Framework.Application; +using CompanyManagment.App.Contracts.RollCall; using OfficeOpenXml; using OfficeOpenXml.Drawing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; namespace CompanyManagement.Infrastructure.Excel.RollCall; @@ -308,6 +314,111 @@ public class RollCallExcelGenerator : ExcelGenerator return package.GetAsByteArray(); } + public static byte[] CaseHistoryExcelForEmployee(List data, string titleId) + { + if (!Regex.IsMatch(titleId, @"^\d{4}_\d{2}$")) + throw new ArgumentException("Invalid titleId format.", nameof(titleId)); + + var splitDate = titleId.Split("_"); + var year = Convert.ToInt32(splitDate.First()); + var month = Convert.ToInt32(splitDate.Last()); + + var startDateFa = $"{year:D4}/{month:D2}/01"; + var startDate = startDateFa.ToGeorgianDateTime(); + var endDateFa = startDateFa.FindeEndOfMonth(); + var endDate = endDateFa.ToGeorgianDateTime(); + + var dateRange = (int)(endDate.Date - startDate.Date).TotalDays + 1; + var dates = Enumerable.Range(0, dateRange).Select(x => startDate.AddDays(x)).ToList(); + + var safeData = data ?? new List(); + var first = safeData.FirstOrDefault(); + var totalWorkingTime = new TimeSpan(safeData.Sum(x => x.TotalWorkingTime.Ticks)); + + var viewModel = new CaseHistoryRollCallExcelForEmployeeViewModel + { + EmployeeId = first?.EmployeeId ?? 0, + DateGr = startDate, + PersonnelCode = first?.PersonnelCode, + EmployeeFullName = first?.EmployeeFullName, + PersianMonthName = month.ToFarsiMonthByIntNumber(), + PersianYear = year.ToString(), + TotalWorkingHoursFa = totalWorkingTime.ToFarsiHoursAndMinutes("-"), + TotalWorkingTimeSpan = $"{(int)totalWorkingTime.TotalHours}:{totalWorkingTime.Minutes:00}", + RollCalls = dates.Select((date, index) => + { + var item = index < safeData.Count ? safeData[index] : null; + var records = item?.Records ?? new List(); + + return new RollCallItemForEmployeeExcelViewModel + { + DateGr = date, + DateFa = date.ToFarsi(), + DayOfWeekFa = date.DayOfWeek.DayOfWeeKToPersian(), + PersonnelCode = item?.PersonnelCode, + EmployeeFullName = item?.EmployeeFullName, + IsAbsent = item?.Status == RollCallRecordStatus.Absent, + HasLeave = item?.Status == RollCallRecordStatus.Leaved, + IsHoliday = false, + TotalWorkingHours = (item?.TotalWorkingTime ?? TimeSpan.Zero).ToFarsiHoursAndMinutes("-"), + StartsItems = JoinRecords(records, r => r.StartTime), + EndsItems = JoinRecords(records, r => r.EndTime), + EnterTimeDifferences = JoinRecords(records, r => FormatSignedTimeSpan(r.EntryTimeDifference)), + ExitTimeDifferences = JoinRecords(records, r => FormatSignedTimeSpan(r.ExitTimeDifference)) + }; + }).ToList() + }; + + return CaseHistoryExcelForEmployee(viewModel); + } + + public static byte[] CaseHistoryExcelForOneDay(List data, string titleId) + { + if (!Regex.IsMatch(titleId, @"^\d{4}/\d{2}/\d{2}$")) + throw new ArgumentException("Invalid titleId format.", nameof(titleId)); + + var dateGr = titleId.ToGeorgianDateTime(); + var safeData = data ?? new List(); + + var viewModel = new CaseHistoryRollCallForOneDayViewModel + { + DateFa = titleId, + DateGr = dateGr, + DayOfWeekFa = dateGr.DayOfWeek.DayOfWeeKToPersian(), + RollCalls = safeData.Select(item => + { + var records = item.Records ?? new List(); + return new RollCallItemForOneDayExcelViewModel + { + EmployeeFullName = item.EmployeeFullName, + PersonnelCode = item.PersonnelCode, + StartsItems = JoinRecords(records, r => r.StartTime), + EndsItems = JoinRecords(records, r => r.EndTime), + TotalWorkingHours = item.TotalWorkingTime.ToFarsiHoursAndMinutes("-") + }; + }).ToList() + }; + + return CaseHistoryExcelForOneDay(viewModel); + } + + private static string JoinRecords(IEnumerable records, Func selector) + { + var safeRecords = records ?? Enumerable.Empty(); + var values = safeRecords.Select(selector).Where(x => !string.IsNullOrWhiteSpace(x)).ToList(); + return values.Count == 0 ? string.Empty : string.Join(Environment.NewLine, values); + } + + private static string FormatSignedTimeSpan(TimeSpan value) + { + if (value == TimeSpan.Zero) + return "-"; + + var abs = value.Duration(); + var sign = value.Ticks < 0 ? "-" : "+"; + return $"{(int)abs.TotalHours}:{abs.Minutes:00}{sign}"; + } + private string CalculateExitMinuteDifference(TimeSpan early, TimeSpan late) { if (early == TimeSpan.Zero && late == TimeSpan.Zero) diff --git a/CompanyManagment.Application/CompanyManagment.Application.csproj b/CompanyManagment.Application/CompanyManagment.Application.csproj index f6e0f038..d33e4227 100644 --- a/CompanyManagment.Application/CompanyManagment.Application.csproj +++ b/CompanyManagment.Application/CompanyManagment.Application.csproj @@ -13,6 +13,7 @@ + diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index 1397b15b..e987d47e 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.Domain.CustomizeCheckoutShared.Enums; +using _0_Framework.Exceptions; using Company.Domain.CheckoutAgg; using Company.Domain.CustomizeCheckoutAgg; using Company.Domain.CustomizeCheckoutTempAgg; @@ -17,6 +19,7 @@ using Company.Domain.RollCallAgg; using Company.Domain.RollCallAgg.DomainService; using Company.Domain.RollCallEmployeeAgg; using Company.Domain.WorkshopAgg; +using CompanyManagement.Infrastructure.Excel.RollCall; using CompanyManagment.App.Contracts.Checkout; using CompanyManagment.App.Contracts.Employee; using CompanyManagment.App.Contracts.RollCall; @@ -874,11 +877,45 @@ public class RollCallApplication : IRollCallApplication } public async Task DownloadCaseHistoryExcel(long workshopId, string titleId, - RollCallCaseHistorySearchModel searchModel) + RollCallCaseHistorySearchModel searchModel) { - var data = await _rollCallRepository - .GetCaseHistoryDetails(workshopId, titleId, searchModel); - var workshopFullName = _workshopRepository.(workshopId); - byte[] excelBytes = RollCallExcelGenerator.CaseHistoryExcelForOneDay(data); + var data = await _rollCallRepository + .GetCaseHistoryDetails(workshopId, titleId, searchModel); + string nameSecondPart = ""; + byte[] excelBytes; + + if (Regex.IsMatch(titleId, @"^\d{4}_\d{2}$")) + { + var splitDate = titleId.Split("_"); + var year = Convert.ToInt32(splitDate.First()); + var month = Convert.ToInt32(splitDate.Last()); + + var monthName = Convert.ToInt32(month).ToFarsiMonthByIntNumber(); + nameSecondPart = $"{year}/{monthName}"; + excelBytes = RollCallExcelGenerator.CaseHistoryExcelForEmployee(data, titleId); + } + else if (Regex.IsMatch(titleId, @"^\d{4}/\d{2}/\d{2}$")) + { + var oneDayDate = titleId.ToGeorgianDateTime(); + nameSecondPart = $" {oneDayDate.DayOfWeek.DayOfWeeKToPersian()}،{titleId}"; + excelBytes = RollCallExcelGenerator.CaseHistoryExcelForOneDay(data, titleId); + } + else + { + throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + } + + var workshopFullName = _workshopRepository.Get(workshopId)?.WorkshopFullName ?? "بدون کارگاه"; + + var fileName = $"{workshopFullName} - {nameSecondPart}.xlsx"; + + var res = new RollCallCaseHistoryExcelDto() + { + Bytes = excelBytes, + MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + FileName = fileName + }; + + return res; } } \ No newline at end of file diff --git a/ServiceHost/Properties/launchSettings.json b/ServiceHost/Properties/launchSettings.json index 788962e4..3c6abef3 100644 --- a/ServiceHost/Properties/launchSettings.json +++ b/ServiceHost/Properties/launchSettings.json @@ -19,7 +19,7 @@ "sqlDebugging": true, "dotnetRunMessages": "true", "nativeDebugging": true, - "applicationUrl": "https://localhost:5004;http://localhost:5003;", + "applicationUrl": "https://localhost:5004;http://localhost:5003;https://192.168.0.117:5005", "jsWebView2Debugging": false, "hotReloadEnabled": true }, From 3dace574ffaca65caa555b995bc6d1fde0d6597e Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 2 Feb 2026 19:08:25 +0330 Subject: [PATCH 5/5] refactor date parsing method in RollCallCaseHistoryController --- .../RollCall/RollCallCaseHistoryController.cs | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs b/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs index fc22ec04..ec8d347d 100644 --- a/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs +++ b/ServiceHost/Areas/Client/Controllers/RollCall/RollCallCaseHistoryController.cs @@ -78,28 +78,12 @@ public class RollCallCaseHistoryController : ClientBaseController return op.Succcedded(duration); } - private static bool TryParseDateTime(string date, string time, out DateTime result) - { - result = default; - - try - { - var dateTime = date.ToGeorgianDateTime(); - var timeOnly = TimeOnly.Parse(time); - result = dateTime.AddTicks(timeOnly.Ticks); - return true; - } - catch - { - return false; - } - } + [HttpGet("excel")] public async Task GetDownload(string titleId, RollCallCaseHistorySearchModel searchModel) { var res =await _rollCallApplication.DownloadCaseHistoryExcel(_workshopId, titleId, searchModel); - return File(res.Bytes, res.MimeType, @@ -127,4 +111,22 @@ public class RollCallCaseHistoryController : ClientBaseController // TotalRollCallsDuration = total.ToFarsiHoursAndMinutes("-") // }; // } + + + private static bool TryParseDateTime(string date, string time, out DateTime result) + { + result = default; + + try + { + var dateTime = date.ToGeorgianDateTime(); + var timeOnly = TimeOnly.Parse(time); + result = dateTime.AddTicks(timeOnly.Ticks); + return true; + } + catch + { + return false; + } + } } \ No newline at end of file