From 8436f70aa0a40252c730980f3f39bb9f84c64627 Mon Sep 17 00:00:00 2001 From: mahan Date: Tue, 11 Nov 2025 19:26:45 +0330 Subject: [PATCH 1/2] Refactor and enhance contract handling logic - Added `DailyWage`, `AvgWorkingHour`, and `FamilyAllowance` properties to `GetContractListForClientResponse`. - Refactored `WorkingHoursWeekly` conversion logic by introducing a reusable `WeeklyHourConvertor` method in `ContractRepository`. - Updated query result mapping to include new properties and utilize `WeeklyHourConvertor` for `AvgWorkingHour`. - Improved code readability and maintainability by centralizing repetitive logic. --- .../GetContractListForClientResponse.cs | 3 + .../Repository/ContractRepository.cs | 61 +++++++++++-------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/CompanyManagment.App.Contracts/Contract/GetContractListForClientResponse.cs b/CompanyManagment.App.Contracts/Contract/GetContractListForClientResponse.cs index d7efa472..58e21ad9 100644 --- a/CompanyManagment.App.Contracts/Contract/GetContractListForClientResponse.cs +++ b/CompanyManagment.App.Contracts/Contract/GetContractListForClientResponse.cs @@ -9,4 +9,7 @@ public class GetContractListForClientResponse public string ContractStart { get; set; } public string ContractEnd { get; set; } public bool IsSigned { get; set; } + public string DailyWage { get; set; } + public string AvgWorkingHour { get; set; } + public string FamilyAllowance { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/ContractRepository.cs b/CompanyManagment.EFCore/Repository/ContractRepository.cs index 0a563b28..a998860b 100644 --- a/CompanyManagment.EFCore/Repository/ContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/ContractRepository.cs @@ -1082,30 +1082,7 @@ public class ContractRepository : RepositoryBase, IContractRepos var weeklyDouble = 0.0; var weekly = c.WorkingHoursWeekly; - if (!string.IsNullOrWhiteSpace(weekly) && - weekly != "24 - 12" && weekly != "24 - 24" && weekly != "36 - 12" && weekly != "48 - 24") - { - if (weekly.Contains("/")) - { - weeklyDouble = double.Parse(weekly); - var minute = (int)((weeklyDouble % 1) * 60); - var hour = (int)(weeklyDouble); - c.WorkingHoursWeekly = hour + " " + "ساعت و" + " " + minute + " " + "دقیقه"; - } - else if (weekly.Contains(".")) - { - weeklyDouble = double.Parse(weekly, CultureInfo.InvariantCulture); - var minute = (int)((weeklyDouble % 1) * 60); - var hour = (int)(weeklyDouble); - c.WorkingHoursWeekly = hour + " " + "ساعت و" + " " + minute + " " + "دقیقه"; - } - else - { - c.WorkingHoursWeekly = c.WorkingHoursWeekly + " " + "ساعت"; - } - - - } + c.WorkingHoursWeekly = WeeklyHourConvertor(weekly); var emp = workshopEmpList.Where(x => x.WorkshopId == c.WorkshopIds) .Select(x => x.EmployerId).ToList(); c.Employers = _employerRepository.GetEmployers(emp); @@ -1162,6 +1139,37 @@ public class ContractRepository : RepositoryBase, IContractRepos return query; } + private static string WeeklyHourConvertor(string weekly) + { + double weeklyDouble; + if (!string.IsNullOrWhiteSpace(weekly) && + weekly != "24 - 12" && weekly != "24 - 24" && weekly != "36 - 12" && weekly != "48 - 24") + { + if (weekly.Contains("/")) + { + weeklyDouble = double.Parse(weekly); + var minute = (int)((weeklyDouble % 1) * 60); + var hour = (int)(weeklyDouble); + return hour + " " + "ساعت و" + " " + minute + " " + "دقیقه"; + } + else if (weekly.Contains(".")) + { + weeklyDouble = double.Parse(weekly, CultureInfo.InvariantCulture); + var minute = (int)((weeklyDouble % 1) * 60); + var hour = (int)(weeklyDouble); + return hour + " " + "ساعت و" + " " + minute + " " + "دقیقه"; + } + else + { + return weekly + " " + "ساعت"; + } + + + } + + return ""; + } + public IQueryable GetWorkshopEmployer() { return _context.WorkshopEmployers.Select(x => new WorkshopEmployerViewModel @@ -1602,7 +1610,10 @@ public class ContractRepository : RepositoryBase, IContractRepos ContractEnd = c.ContractEnd.ToFarsi(), ContractNo = c.ContractNo, IsSigned = c.Signature == "1", - EmployeeFullName = employeeFullName + EmployeeFullName = employeeFullName, + AvgWorkingHour = WeeklyHourConvertor(c.WorkingHoursWeekly), + DailyWage = c.DayliWage, + FamilyAllowance = c.FamilyAllowance }; }).ToList() }; From 0fbd5c9d3ec3277c35246c6aaf7843d07918fe6c Mon Sep 17 00:00:00 2001 From: mahan Date: Tue, 11 Nov 2025 19:29:51 +0330 Subject: [PATCH 2/2] Add print methods and ContractPrintViewModel class Updated the `IContractApplication` interface: - Added `PrintOneAsync(long id)` and `PrintAllAsync(List ids)` methods. - Corrected formatting of `DeleteAllContarcts(List ids)`. - Grouped changes under the `NewChangeByHeydari` region. Introduced the `ContractPrintViewModel` class (currently empty). Implemented `PrintOneAsync` and `PrintAllAsync` in `ContractApplication` with `NotImplementedException`. These changes prepare the codebase for contract printing functionality. --- .../Contract/IContractApplication.cs | 14 ++++++++++---- .../ContractApplication.cs | 10 ++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CompanyManagment.App.Contracts/Contract/IContractApplication.cs b/CompanyManagment.App.Contracts/Contract/IContractApplication.cs index 8e17f094..b6038104 100644 --- a/CompanyManagment.App.Contracts/Contract/IContractApplication.cs +++ b/CompanyManagment.App.Contracts/Contract/IContractApplication.cs @@ -56,16 +56,22 @@ public interface IContractApplication /// Task> GetContractListForClient(GetContractListForClientRequest searchModel); - - #endregion + Task PrintOneAsync(long id); + Task> PrintAllAsync(List ids); - #region NewChangeByHeydari + #endregion - OperationResult DeleteAllContarcts(List ids); + #region NewChangeByHeydari + + OperationResult DeleteAllContarcts(List ids); OperationResult DeleteContarcts(long id); List CheckHasCheckout(List ids); List CheckHasSignature(List ids); List SearchForMainContract(ContractSearchModel searchModel); #endregion +} + +public class ContractPrintViewModel +{ } \ No newline at end of file diff --git a/CompanyManagment.Application/ContractApplication.cs b/CompanyManagment.Application/ContractApplication.cs index b5936feb..48acc0bf 100644 --- a/CompanyManagment.Application/ContractApplication.cs +++ b/CompanyManagment.Application/ContractApplication.cs @@ -3112,6 +3112,16 @@ public class ContractApplication : IContractApplication return await _contractRepository.GetContractListForClient(searchModel); } + public Task PrintOneAsync(long id) + { + throw new NotImplementedException(); + } + + public Task> PrintAllAsync(List ids) + { + throw new NotImplementedException(); + } + #endregion #region NewChangeByHeydari