From 8436f70aa0a40252c730980f3f39bb9f84c64627 Mon Sep 17 00:00:00 2001 From: mahan Date: Tue, 11 Nov 2025 19:26:45 +0330 Subject: [PATCH 1/7] 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/7] 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 From 3ce4cf3966b23586c0027e5fc196544e1dbd9db4 Mon Sep 17 00:00:00 2001 From: mahan Date: Thu, 18 Dec 2025 13:34:31 +0330 Subject: [PATCH 3/7] add insurance print api for client --- .../IInsuranceListRepository.cs | 1 + .../IInsuranceListApplication.cs | 80 +++++++++++++++++++ .../InsuranceListApplication.cs | 5 ++ .../Repository/InsuranceListRepository.cs | 48 +++++++++++ .../Client/Controllers/InsuranceController.cs | 11 +++ 5 files changed, 145 insertions(+) diff --git a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs index b8b95235..93d9f588 100644 --- a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs +++ b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs @@ -78,6 +78,7 @@ public interface IInsuranceListRepository:IRepository #endregion Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); + Task ClientPrintOne(long id); } diff --git a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs index 1a36dafb..7896a271 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using _0_Framework.Application; using CompanyManagment.App.Contracts.InsuranceList; +using CompanyManagment.App.Contracts.Workshop; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -96,6 +97,85 @@ public interface IInsuranceListApplication #endregion Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); + Task ClientPrintOne(long id); +} + +public class InsuranceClientPrintViewModel +{ + public List Items { get; set; } + public string EmployerShare { get; set; } + public string InsuredShare { get; set; } + public string UnEmploymentInsurance { get; set; } + public string AllInsuredShare { get; set; } +} +public class InsuranceClientPrintItemsViewModel +{ + /// + /// شماره بیمه + /// + public string InsuranceCode { get; set; } + /// + /// نام و نام خانوادگی + /// + public string FullName { get; set; } + /// + /// شغل + /// + public string JobName { get; set; } + /// + /// کد ملی + /// + public string NationalCode { get; set; } + /// + /// شروع به کار + /// + public string StartWork { get; set; } + /// + /// ترک کار + /// + public string LeftWork { get; set; } + /// + /// روزهای کارکرد + /// + public string WorkingDays { get; set; } + /// + /// دستمزد روزانه + /// + public string DailyWage { get; set; } + /// + /// پایه سنوات روزانه + /// + public string BaseYears { get; set; } + /// + /// دستمزد ماهانه + /// + public string MonthlySalary { get; set; } + /// + /// مزایای ماهیانه مشمول + /// + public string MonthlyBenefits { get; set; } + /// + /// حق تاهل + /// + public string MarriedAllowance { get; set; } + /// + /// حقوق و مزایای ماهیانه مشمول + /// + public string BenefitsIncludedContinuous { get; set; } + /// + /// حقوق و مزایای ماهیانه غیر مشمول + /// + public string BenefitsIncludedNonContinuous { get; set; } + /// + /// مجموع مزایای ماهیانه مشمول و غیر مشمول + /// + public string IncludedAndNotIncluded { get; set; } + /// + /// حق بیمه سهم بیمه شده + /// + public string EmployerShare { get; set; } + + } public class InsuranceClientSearchModel:PaginationRequest diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index 5a3c5fb0..d0fbb990 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -2381,5 +2381,10 @@ public class InsuranceListApplication : IInsuranceListApplication return await _insuranceListRepositpry.GetNotCreatedWorkshop(searchModel); } + public async Task ClientPrintOne(long id) + { + return await _insuranceListRepositpry.ClientPrintOne(id); + } + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs index da63d47b..0836a912 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs @@ -1960,6 +1960,54 @@ public class InsuranceListRepository : RepositoryBase, IIns return res; } + public async Task ClientPrintOne(long id) + { + var insurance = await _context.InsuranceListSet.FirstOrDefaultAsync(x => x.id == id); + if (insurance == null) + return null; + var employeeInsurance = _context.EmployeeInsurancListDataSet.Where(x=>x.InsuranceListId == insurance.id); + + var employeeIds =await employeeInsurance.Select(x=>x.EmployeeId).ToListAsync(); + var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).ToListAsync(); + var jobIds = employeeInsurance.Select(x => x.JobId).ToList(); + var jobs = await _context.Jobs.Where(x => jobIds.Contains(x.id)).ToDictionaryAsync(x=>x.id,x=>x.JobName); + + var employeeData = employeeInsurance.ToList().Select(x => + { + var employee = employees.FirstOrDefault(e => e.id == x.EmployeeId); + return new InsuranceClientPrintItemsViewModel() + { + BaseYears = x.BaseYears.ToMoney(), + BenefitsIncludedContinuous = x.BenefitsIncludedContinuous.ToMoney(), + BenefitsIncludedNonContinuous = x.BenefitsIncludedNonContinuous.ToMoney(), + DailyWage = x.DailyWage.ToMoney(), + IncludedAndNotIncluded = (x.BenefitsIncludedNonContinuous + x.BenefitsIncludedContinuous).ToMoney(), + WorkingDays = x.WorkingDays.ToString(), + MarriedAllowance = x.MarriedAllowance.ToMoney(), + StartWork = x.StartWorkDate.ToFarsi(), + LeftWork = x.LeftWorkDate.ToFarsi(), + MonthlyBenefits = x.MonthlyBenefits.ToMoney(), + MonthlySalary = x.MonthlySalary.ToMoney(), + NationalCode = employee.NationalCode, + InsuranceCode = employee.InsuranceCode, + JobName = jobs.GetValueOrDefault(x.JobId, ""), + FullName = employee.FullName, + }; + }).ToList(); + + var result = new InsuranceClientPrintViewModel() + { + Items = employeeData.ToList(), + AllInsuredShare = (insurance.InsuredShare + + insurance.EmployerShare + + insurance.UnEmploymentInsurance).ToMoney(), + EmployerShare = insurance.EmployerShare.ToMoney(), + InsuredShare = insurance.InsuredShare.ToMoney(), + UnEmploymentInsurance = insurance.UnEmploymentInsurance.ToMoney(), + }; + return result; + } + /// /// /// diff --git a/ServiceHost/Areas/Client/Controllers/InsuranceController.cs b/ServiceHost/Areas/Client/Controllers/InsuranceController.cs index 00f8ee06..8c991778 100644 --- a/ServiceHost/Areas/Client/Controllers/InsuranceController.cs +++ b/ServiceHost/Areas/Client/Controllers/InsuranceController.cs @@ -19,4 +19,15 @@ public class InsuranceController:ClientBaseController var insurances =await _insuranceListApplication.GetInsuranceClientList(searchModel); return Ok(insurances); } + + [HttpGet("print-one")] + public async Task> ClientPrintList(long id) + { + InsuranceClientPrintViewModel res = await _insuranceListApplication.ClientPrintOne(id); + return res; + } +} + +public class InsuranceClientViewModel +{ } From 293ea0f6f427c1095767c2e4bbb44f8006181c05 Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 20 Dec 2025 10:13:13 +0330 Subject: [PATCH 4/7] feat: enhance insurance client print model with additional properties and update related logic --- .../IInsuranceListApplication.cs | 11 +- .../Repository/InsuranceListRepository.cs | 274 ++++++++++-------- 2 files changed, 157 insertions(+), 128 deletions(-) diff --git a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs index 7896a271..7964628d 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs @@ -102,11 +102,20 @@ public interface IInsuranceListApplication public class InsuranceClientPrintViewModel { + public string Monht { get; set; } + public string Year { get; set; } + public string WorkshopName { get; set; } + public string ListNo { get; set; } + public string AgreementNumber { get; set; } + public string WorkshopInsuranceCode { get; set; } + public string WorkshopEmployerName { get; set; } + public string WorkshopAddress { get; set; } public List Items { get; set; } public string EmployerShare { get; set; } public string InsuredShare { get; set; } public string UnEmploymentInsurance { get; set; } public string AllInsuredShare { get; set; } + } public class InsuranceClientPrintItemsViewModel { @@ -173,7 +182,7 @@ public class InsuranceClientPrintItemsViewModel /// /// حق بیمه سهم بیمه شده /// - public string EmployerShare { get; set; } + public string InsuranceShare { get; set; } } diff --git a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs index 0836a912..82a83509 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs @@ -176,18 +176,20 @@ public class InsuranceListRepository : RepositoryBase, IIns if (item.InsuranceShare.ToMoney() != checkout.InsuranceDeduction.ToMoney()) { checkout.SetUpdateNeeded(); - if (!_context.CheckoutWarningMessages.Any(x => x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning != TypeOfCheckoutWarning.InsuranceEmployeeShare)) + if (!_context.CheckoutWarningMessages.Any(x => + x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning != + TypeOfCheckoutWarning.InsuranceEmployeeShare)) { var createWarrning = new CheckoutWarningMessage( - "مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد", checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare); + "مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد", + checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare); _context.CheckoutWarningMessages.Add(createWarrning); } _context.SaveChanges(); } } - } } @@ -729,7 +731,7 @@ public class InsuranceListRepository : RepositoryBase, IIns var id = insuranceListObj.id; if (command.EmployeeInsurancListDataList != null && command.EmployeeInsurancListDataList.Count > 0) { - var farisMonthName = Tools.ToFarsiMonthByNumber(command.Month); + var farisMonthName = Tools.ToFarsiMonthByNumber(command.Month); var checkouts = _context.CheckoutSet.Where(x => x.WorkshopId == command.WorkshopId && x.Year == command.Year && x.Month == farisMonthName && @@ -755,20 +757,21 @@ public class InsuranceListRepository : RepositoryBase, IIns if (item.InsuranceShare.ToMoney() != checkout.InsuranceDeduction.ToMoney()) { checkout.SetUpdateNeeded(); - if (!_context.CheckoutWarningMessages.Any(x => x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning != TypeOfCheckoutWarning.InsuranceEmployeeShare)) + if (!_context.CheckoutWarningMessages.Any(x => + x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning != + TypeOfCheckoutWarning.InsuranceEmployeeShare)) { var createWarrning = new CheckoutWarningMessage( - "مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد", checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare); + "مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد", + checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare); _context.CheckoutWarningMessages.Add(createWarrning); } - + _context.SaveChanges(); } } - } - } _employeeInsurancListDataRepository.SaveChanges(); @@ -1777,26 +1780,28 @@ public class InsuranceListRepository : RepositoryBase, IIns return res; } - public async Task> GetInsuranceClientList(InsuranceClientSearchModel searchModel) + public async Task> GetInsuranceClientList( + InsuranceClientSearchModel searchModel) { var workshopId = _authHelper.GetWorkshopId(); var query = _context.InsuranceListSet .Select(x => new InsuranceClientListViewModel - { - Id = x.id, - WorkShopId = x.WorkshopId, - Year = x.Year, - YearInt = Convert.ToInt32(x.Year), - Month = x.Month, - MonthName = x.Month.ToFarsiMonthByNumber(), - MonthInt = Convert.ToInt32(x.Month), - }).Where(x => x.WorkShopId == workshopId); + { + Id = x.id, + WorkShopId = x.WorkshopId, + Year = x.Year, + YearInt = Convert.ToInt32(x.Year), + Month = x.Month, + MonthName = x.Month.ToFarsiMonthByNumber(), + MonthInt = Convert.ToInt32(x.Month), + }).Where(x => x.WorkShopId == workshopId); - if (searchModel.Year>0) + if (searchModel.Year > 0) { query = query.Where(x => x.YearInt == searchModel.Year); - } + } + if (searchModel.Month > 0) { query = query.Where(x => x.MonthInt == searchModel.Month); @@ -1816,7 +1821,7 @@ public class InsuranceListRepository : RepositoryBase, IIns "Year-Min" => query.OrderBy(x => x.YearInt), _ => query.OrderByDescending(x => x.Id), }; - res.List =await query.ApplyPagination(searchModel.PageIndex,searchModel.PageSize).ToListAsync(); + res.List = await query.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); return res; } @@ -1846,41 +1851,41 @@ public class InsuranceListRepository : RepositoryBase, IIns .Include(x => x.LeftWorkInsurances) .Where(x => x.LeftWorkInsurances.Any(l => l.StartWorkDate <= firstDayOfMonth && (l.LeftWorkDate == null || l.LeftWorkDate >= firstDayOfMonth))); - - - var query = notCreatedWorkshop.Select(result=>new InsuranceListViewModel - { - Year = searchModel.Year, - Month = searchModel.Month, - WorkShopId = result.id, - WorkShopCode = result.InsuranceWorkshopInfo != null - ? result.InsuranceWorkshopInfo.InsuranceCode - : result.InsuranceCode, - WorkShopName = result.InsuranceWorkshopInfo != null - ? result.InsuranceWorkshopInfo.WorkshopName - : result.WorkshopFullName, - TypeOfInsuranceSend = result.TypeOfInsuranceSend == "NormalList" ? "عادی" : - result.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : - result.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", - FixedSalary = result.FixedSalary, - StrFixedSalary = result.FixedSalary ? "دارد" : "ندارد", - EmployerName = result.InsuranceWorkshopInfo != null - ? result.InsuranceWorkshopInfo.EmployerName - : result.WorkshopFullName, - Branch = "", - City = "", - ArchiveCode = result.ArchiveCode, - }); - - - if (!string.IsNullOrEmpty(searchModel.Month) && searchModel.Month != "0") - query = query.Where(x => x.Month == searchModel.Month).OrderByDescending(x => x.WorkShopName) - .ThenByDescending(x => x.EmployerName).ThenByDescending(x => x.Year); - if (!string.IsNullOrEmpty(searchModel.Year) && searchModel.Year != "0") - query = query.Where(x => x.Year == searchModel.Year).OrderByDescending(x => x.EmployerName) - .ThenByDescending(x => x.WorkShopName).ThenByDescending(x => x.Month); - + + var query = notCreatedWorkshop.Select(result => new InsuranceListViewModel + { + Year = searchModel.Year, + Month = searchModel.Month, + WorkShopId = result.id, + WorkShopCode = result.InsuranceWorkshopInfo != null + ? result.InsuranceWorkshopInfo.InsuranceCode + : result.InsuranceCode, + WorkShopName = result.InsuranceWorkshopInfo != null + ? result.InsuranceWorkshopInfo.WorkshopName + : result.WorkshopFullName, + TypeOfInsuranceSend = result.TypeOfInsuranceSend == "NormalList" ? "عادی" : + result.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : + result.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", + FixedSalary = result.FixedSalary, + StrFixedSalary = result.FixedSalary ? "دارد" : "ندارد", + EmployerName = result.InsuranceWorkshopInfo != null + ? result.InsuranceWorkshopInfo.EmployerName + : result.WorkshopFullName, + Branch = "", + City = "", + ArchiveCode = result.ArchiveCode, + }); + + + if (!string.IsNullOrEmpty(searchModel.Month) && searchModel.Month != "0") + query = query.Where(x => x.Month == searchModel.Month).OrderByDescending(x => x.WorkShopName) + .ThenByDescending(x => x.EmployerName).ThenByDescending(x => x.Year); + + if (!string.IsNullOrEmpty(searchModel.Year) && searchModel.Year != "0") + query = query.Where(x => x.Year == searchModel.Year).OrderByDescending(x => x.EmployerName) + .ThenByDescending(x => x.WorkShopName).ThenByDescending(x => x.Month); + if (!string.IsNullOrEmpty(searchModel.WorkShopCode)) query = query.Where(x => x.WorkShopCode == searchModel.WorkShopCode).OrderByDescending(x => x.Year) @@ -1925,37 +1930,37 @@ public class InsuranceListRepository : RepositoryBase, IIns var workshopList = await query.Skip(searchModel.PageIndex).Take(30).ToListAsync(); - var workshopIds = workshopList.Select(x=>x.WorkShopId); - - var employers =await _context.WorkshopEmployers - .Where(x=>workshopIds.Contains(x.WorkshopId)) - .GroupBy(x=>x.WorkshopId) - .Select(x=>x.First()).ToListAsync(); - - var res = workshopList.Select(x => - { - var employer = employers.FirstOrDefault(e => e.WorkshopId ==x.WorkShopId)?.Employer; - - return new InsuranceListViewModel - { - WorkShopId = x.WorkShopId, - WorkShopCode = x.WorkShopCode, - WorkShopName = x.WorkShopName, - EmployerName = employer != null - ? employer.FullName - : (x.EmployerName), - Year = searchModel.Year, - Month = searchModel.Month, - TypeOfInsuranceSend = x.TypeOfInsuranceSend == "NormalList" ? "عادی" : - x.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : - x.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", - FixedSalary = (bool)x.FixedSalary, - StrFixedSalary = (bool)x.FixedSalary ? "دارد" : "ندارد", - EmployerId = employer?.id ?? 0, - ArchiveCode = x.ArchiveCode, - City = x.City, - }; - }).ToList(); + var workshopIds = workshopList.Select(x => x.WorkShopId); + + var employers = await _context.WorkshopEmployers + .Where(x => workshopIds.Contains(x.WorkshopId)) + .GroupBy(x => x.WorkshopId) + .Select(x => x.First()).ToListAsync(); + + var res = workshopList.Select(x => + { + var employer = employers.FirstOrDefault(e => e.WorkshopId == x.WorkShopId)?.Employer; + + return new InsuranceListViewModel + { + WorkShopId = x.WorkShopId, + WorkShopCode = x.WorkShopCode, + WorkShopName = x.WorkShopName, + EmployerName = employer != null + ? employer.FullName + : (x.EmployerName), + Year = searchModel.Year, + Month = searchModel.Month, + TypeOfInsuranceSend = x.TypeOfInsuranceSend == "NormalList" ? "عادی" : + x.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : + x.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", + FixedSalary = (bool)x.FixedSalary, + StrFixedSalary = (bool)x.FixedSalary ? "دارد" : "ندارد", + EmployerId = employer?.id ?? 0, + ArchiveCode = x.ArchiveCode, + City = x.City, + }; + }).ToList(); return res; } @@ -1965,47 +1970,62 @@ public class InsuranceListRepository : RepositoryBase, IIns var insurance = await _context.InsuranceListSet.FirstOrDefaultAsync(x => x.id == id); if (insurance == null) return null; - var employeeInsurance = _context.EmployeeInsurancListDataSet.Where(x=>x.InsuranceListId == insurance.id); - - var employeeIds =await employeeInsurance.Select(x=>x.EmployeeId).ToListAsync(); - var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).ToListAsync(); - var jobIds = employeeInsurance.Select(x => x.JobId).ToList(); - var jobs = await _context.Jobs.Where(x => jobIds.Contains(x.id)).ToDictionaryAsync(x=>x.id,x=>x.JobName); - - var employeeData = employeeInsurance.ToList().Select(x => + + var employeeInsurance = _context.EmployeeInsurancListDataSet.Where(x => x.InsuranceListId == insurance.id); + + var workshop = await _context.Workshops + .Include(x => x.InsuranceWorkshopInfo) + .FirstOrDefaultAsync(x => x.id == insurance.WorkshopId); + + var employeeIds = await employeeInsurance.Select(x => x.EmployeeId).ToListAsync(); + var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).ToListAsync(); + var jobIds = employeeInsurance.Select(x => x.JobId).ToList(); + var jobs = await _context.Jobs.Where(x => jobIds.Contains(x.id)).ToDictionaryAsync(x => x.id, x => x.JobName); + + var employeeData = employeeInsurance.ToList().Select(x => + { + var employee = employees.FirstOrDefault(e => e.id == x.EmployeeId); + return new InsuranceClientPrintItemsViewModel() { - var employee = employees.FirstOrDefault(e => e.id == x.EmployeeId); - return new InsuranceClientPrintItemsViewModel() - { - BaseYears = x.BaseYears.ToMoney(), - BenefitsIncludedContinuous = x.BenefitsIncludedContinuous.ToMoney(), - BenefitsIncludedNonContinuous = x.BenefitsIncludedNonContinuous.ToMoney(), - DailyWage = x.DailyWage.ToMoney(), - IncludedAndNotIncluded = (x.BenefitsIncludedNonContinuous + x.BenefitsIncludedContinuous).ToMoney(), - WorkingDays = x.WorkingDays.ToString(), - MarriedAllowance = x.MarriedAllowance.ToMoney(), - StartWork = x.StartWorkDate.ToFarsi(), - LeftWork = x.LeftWorkDate.ToFarsi(), - MonthlyBenefits = x.MonthlyBenefits.ToMoney(), - MonthlySalary = x.MonthlySalary.ToMoney(), - NationalCode = employee.NationalCode, - InsuranceCode = employee.InsuranceCode, - JobName = jobs.GetValueOrDefault(x.JobId, ""), - FullName = employee.FullName, - }; - }).ToList(); - - var result = new InsuranceClientPrintViewModel() - { - Items = employeeData.ToList(), - AllInsuredShare = (insurance.InsuredShare + - insurance.EmployerShare + - insurance.UnEmploymentInsurance).ToMoney(), - EmployerShare = insurance.EmployerShare.ToMoney(), - InsuredShare = insurance.InsuredShare.ToMoney(), - UnEmploymentInsurance = insurance.UnEmploymentInsurance.ToMoney(), - }; - return result; + BaseYears = x.BaseYears.ToMoney(), + BenefitsIncludedContinuous = x.BenefitsIncludedContinuous.ToMoney(), + BenefitsIncludedNonContinuous = x.BenefitsIncludedNonContinuous.ToMoney(), + DailyWage = x.DailyWage.ToMoney(), + IncludedAndNotIncluded = (x.BenefitsIncludedNonContinuous + x.BenefitsIncludedContinuous).ToMoney(), + WorkingDays = x.WorkingDays.ToString(), + MarriedAllowance = x.MarriedAllowance.ToMoney(), + StartWork = x.StartWorkDate.ToFarsi(), + LeftWork = x.LeftWorkDate.ToFarsi(), + MonthlyBenefits = x.MonthlyBenefits.ToMoney(), + MonthlySalary = x.MonthlySalary.ToMoney(), + NationalCode = employee.NationalCode, + InsuranceCode = employee.InsuranceCode, + JobName = jobs.GetValueOrDefault(x.JobId, ""), + FullName = employee.FullName, + InsuranceShare = x.InsuranceShare.ToMoney(), + }; + }).ToList(); + + var result = new InsuranceClientPrintViewModel() + { + Items = employeeData.ToList(), + AllInsuredShare = (insurance.InsuredShare + + insurance.EmployerShare + + insurance.UnEmploymentInsurance).ToMoney(), + EmployerShare = insurance.EmployerShare.ToMoney(), + InsuredShare = insurance.InsuredShare.ToMoney(), + UnEmploymentInsurance = insurance.UnEmploymentInsurance.ToMoney(), + WorkshopName = workshop.InsuranceWorkshopInfo.WorkshopName, + WorkshopAddress = workshop.InsuranceWorkshopInfo.Address, + WorkshopEmployerName = workshop.InsuranceWorkshopInfo.EmployerName, + WorkshopInsuranceCode = workshop.InsuranceWorkshopInfo.InsuranceCode, + AgreementNumber = workshop.InsuranceWorkshopInfo.AgreementNumber, + ListNo = "01", + Monht = insurance.Month, + Year = insurance.Year + + }; + return result; } /// From b0d174a575181ebb4ffc71ca981b37cbbfdaed80 Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 20 Dec 2025 13:04:30 +0330 Subject: [PATCH 5/7] feat: implement contract printing methods and view models --- .../ContractAgg/IContractRepository.cs | 2 + .../Contract/IContractApplication.cs | 69 +++++++++++++++++++ .../ContractApplication.cs | 8 +-- .../Repository/ContractRepository.cs | 16 +++++ 4 files changed, 91 insertions(+), 4 deletions(-) diff --git a/Company.Domain/ContractAgg/IContractRepository.cs b/Company.Domain/ContractAgg/IContractRepository.cs index fbffa304..585d9e13 100644 --- a/Company.Domain/ContractAgg/IContractRepository.cs +++ b/Company.Domain/ContractAgg/IContractRepository.cs @@ -51,6 +51,7 @@ public interface IContractRepository : IRepository Task> GetContractListForClient(GetContractListForClientRequest searchModel); + Task> PrintAllAsync(List ids); #endregion #region NewChangeByHeydari @@ -66,6 +67,7 @@ public interface IContractRepository : IRepository ContractViweModel GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime startOfMonth, DateTime endOfMonth); List GetByWorkshopIdInDates(long workshopId, DateTime contractStart, DateTime contractEnd); #endregion + } diff --git a/CompanyManagment.App.Contracts/Contract/IContractApplication.cs b/CompanyManagment.App.Contracts/Contract/IContractApplication.cs index b6038104..38c2fc2b 100644 --- a/CompanyManagment.App.Contracts/Contract/IContractApplication.cs +++ b/CompanyManagment.App.Contracts/Contract/IContractApplication.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using _0_Framework.Application; using CompanyManagment.App.Contracts.Workshop; using System.Threading.Tasks; +using _0_Framework.Application.Enums; + namespace CompanyManagment.App.Contracts.Contract; public interface IContractApplication @@ -74,4 +76,71 @@ public interface IContractApplication public class ContractPrintViewModel { + public string ContractNo { get; set; } + public ContractPrintEmployerViewModel Employer { get; set; } + public ContractPrintEmployeeViewModel Employee { get; set; } + public ContractPrintTypeOfContractViewModel TypeOfContract { get; set; } + public ContractPrintFeesViewModel Fees { get; set; } + public string ConditionAndDetials { get; set; } + + +} + +public class ContractPrintFeesViewModel +{ + public string DailyWage { get; set; } + public string FamilyAllowance { get; set; } + public string ConsumableItems { get; set; } + public string HousingAllowance { get; set; } +} + +public class ContractPrintTypeOfContractViewModel +{ + public string ContractType { get; set; } + public string JobName { get; set; } + public string SetContractDate { get; set; } + public string ContarctStart { get; set; } + public string ContractEnd { get; set; } + public string WorkingHoursWeekly { get; set; } + public List WorkshopAddress { get; set; } + + + +} + +public class ContractPrintEmployeeViewModel +{ + public string FullName { get; set; } + public string NationalCode { get; set; } + public string IdNumber { get; set; } + public string DateOfBirth { get; set; } + public string FatherName { get; set; } + public string LevelOfEducation { get; set; } + public string Address { get; set; } + + +} + +public class ContractPrintEmployerViewModel +{ + public LegalType LegalType { get; set; } + public ContractPrintRealEmployerViewModel RealEmployer { get; set; } + public ContractPrintLegalEmployerViewModel LegalEmployer { get; set; } + public string WorkshopName { get; set; } + public string Address { get; set; } + +} + +public class ContractPrintLegalEmployerViewModel +{ + public string CompanyName { get; set; } + public string NationalId { get; set; } + public string RegisterId { get; set; } +} + +public class ContractPrintRealEmployerViewModel +{ + public string FullName { get; set; } + public string NationalCode { get; set; } + public string IdNumber { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/ContractApplication.cs b/CompanyManagment.Application/ContractApplication.cs index 48acc0bf..4229d01e 100644 --- a/CompanyManagment.Application/ContractApplication.cs +++ b/CompanyManagment.Application/ContractApplication.cs @@ -3112,14 +3112,14 @@ public class ContractApplication : IContractApplication return await _contractRepository.GetContractListForClient(searchModel); } - public Task PrintOneAsync(long id) + public async Task PrintOneAsync(long id) { - throw new NotImplementedException(); + return (await _contractRepository.PrintAllAsync([id])).FirstOrDefault(); } - public Task> PrintAllAsync(List ids) + public async Task> PrintAllAsync(List ids) { - throw new NotImplementedException(); + return await _contractRepository.PrintAllAsync(ids); } #endregion diff --git a/CompanyManagment.EFCore/Repository/ContractRepository.cs b/CompanyManagment.EFCore/Repository/ContractRepository.cs index a998860b..66991e45 100644 --- a/CompanyManagment.EFCore/Repository/ContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/ContractRepository.cs @@ -1621,6 +1621,22 @@ public class ContractRepository : RepositoryBase, IContractRepos return result; } + public async Task> PrintAllAsync(List ids) + { + var query =await _context.Contracts.Include(x => x.Employer) + .Include(x => x.Employee).Where(x => ids.Contains(x.id)) + .ToListAsync(); + + var res = query.Select(x=> + { + var employer = + return new ContractPrintViewModel() + { + Employer = + }; + }) + } + #endregion #region NewChangeByHeydari From 20c00893b6916d528d92001bb0e542daea0921ad Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 20 Dec 2025 14:23:23 +0330 Subject: [PATCH 6/7] feat: add API endpoint for printing contract details and enhance contract print logic --- .../ContractApplication.cs | 2 + .../Repository/ContractRepository.cs | 75 ++++++++++++++++++- .../Client/Controllers/ContractController.cs | 7 ++ 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/CompanyManagment.Application/ContractApplication.cs b/CompanyManagment.Application/ContractApplication.cs index 4229d01e..c8ed4524 100644 --- a/CompanyManagment.Application/ContractApplication.cs +++ b/CompanyManagment.Application/ContractApplication.cs @@ -2712,7 +2712,9 @@ public class ContractApplication : IContractApplication var emp = workshopEmpList.Where(x => x.WorkshopId == res.WorkshopIds) .Select(x => x.EmployerId).ToList(); + res.Employers = _employerRepository.GetEmployers(emp); + var workshopSelect = _workshopApplication.GetDetails(res.WorkshopIds); var workshop = new WorkshopViewModel() { diff --git a/CompanyManagment.EFCore/Repository/ContractRepository.cs b/CompanyManagment.EFCore/Repository/ContractRepository.cs index 66991e45..08a8a43f 100644 --- a/CompanyManagment.EFCore/Repository/ContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/ContractRepository.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Linq; using System.Threading.Tasks; using _0_Framework.Application; +using _0_Framework.Application.Enums; using _0_Framework.Exceptions; using _0_Framework.InfraStructure; using Company.Domain.ContractAgg; @@ -1627,14 +1628,80 @@ public class ContractRepository : RepositoryBase, IContractRepos .Include(x => x.Employee).Where(x => ids.Contains(x.id)) .ToListAsync(); - var res = query.Select(x=> + var workshopIds = query.Select(x => x.WorkshopIds).Distinct().ToList(); + + var workshops = await _context.Workshops + .Where(x => workshopIds.Contains(x.id)) + .ToListAsync(); + + List exceptionWorkshops = [516,63,38,39]; + var res = query.Select(x => { - var employer = + var workshop = workshops.FirstOrDefault(w => w.id == x.WorkshopIds); + + var employerRes = new ContractPrintEmployerViewModel() + { + WorkshopName = workshop!.WorkshopName, + Address =$"{workshop.State} - {workshop.City} - {workshop.Address}", + LegalType = x.Employer.IsLegal == "حقیقی" ? LegalType.Real : LegalType.Legal, + LegalEmployer = x.Employer.IsLegal == "حقیقی" + ? null + : new ContractPrintLegalEmployerViewModel() + { + NationalId = x.Employer.NationalId, + RegisterId = x.Employer.RegisterId, + CompanyName = x.Employer.LName, + }, + RealEmployer = x.Employer.IsLegal == "حقیقی" + ? new ContractPrintRealEmployerViewModel() + { + FullName = x.Employer.FullName, + IdNumber = x.Employer.IdNumber, + NationalCode = x.Employer.Nationalcode + } + : null, + + }; + var employeeRes = new ContractPrintEmployeeViewModel() + { + Address =$"{x.Employee.State} - {x.Employee.City} - {x.Employee.Address}" , + FullName = x.Employee.FullName, + IdNumber = x.Employee.IdNumber, + NationalCode = x.Employee.NationalCode, + DateOfBirth = x.Employee.DateOfBirth.ToFarsi(), + FatherName = x.Employee.FatherName, + LevelOfEducation = x.Employee.LevelOfEducation + }; + + var typeOfContract = new ContractPrintTypeOfContractViewModel() + { + ContarctStart = x.ContarctStart.ToFarsi(), + ContractEnd = x.ContractEnd.ToFarsi(), + JobName = x.JobType, + ContractType = x.ContractType, + SetContractDate = x.SetContractDate.ToFarsi(), + WorkingHoursWeekly = WeeklyHourConvertor(x.WorkingHoursWeekly), + WorkshopAddress = [x.WorkshopAddress1, x.WorkshopAddress2], + }; + ContractPrintFeesViewModel fees= new ContractPrintFeesViewModel() + { + DailyWage = x.DayliWage, + FamilyAllowance = x.FamilyAllowance, + HousingAllowance = x.HousingAllowance, + ConsumableItems = x.ConsumableItems, + }; return new ContractPrintViewModel() { - Employer = + Employer = employerRes, + Employee = employeeRes, + TypeOfContract = typeOfContract, + Fees = fees, + ContractNo = x.ContractNo, + ConditionAndDetials = exceptionWorkshops.Contains(x.WorkshopIds) ? "بر اساس ماده 190 قانون کار جمهوری اسلامی ایران ، پرسنل اقرار مینماید کلیه مبالغ پیش بینی شده در قانون کار را وفق قرارداد منعقده دریافت مینماید. این مبالغ قسمتی بصورت مستقیم از سوی کارفرما و قسمتی بر اساس شرایط کارگاه از محل درآمد حاصله از مشتری اخذ میگردد . با توجه به شرایط کارگاه کلیه مبالغ بصورت واریز به حساب و وجه نقد رایج کشور ، تواما به پرسنل پرداخت میگردد. امضا تصفیه حساب دارای مبالغ ، توسط پرسنل نشانگر تصفیه قطعی ایشان میباشد.": "", + }; - }) + }).ToList(); + return res; } #endregion diff --git a/ServiceHost/Areas/Client/Controllers/ContractController.cs b/ServiceHost/Areas/Client/Controllers/ContractController.cs index 95d24437..523289e1 100644 --- a/ServiceHost/Areas/Client/Controllers/ContractController.cs +++ b/ServiceHost/Areas/Client/Controllers/ContractController.cs @@ -24,4 +24,11 @@ public class ContractController:ClientBaseController return res; } + [HttpGet("print/{id}")] + public async Task> PrintOne(long id) + { + var res = await _contractApplication.PrintOneAsync(id); + return res; + } + } \ No newline at end of file From 0dd2dc7c43d4e1860b01d06ab82e399c7561688f Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 20 Dec 2025 15:21:34 +0330 Subject: [PATCH 7/7] add workshopCode on client contract print --- CompanyManagment.App.Contracts/Contract/IContractApplication.cs | 1 + CompanyManagment.EFCore/Repository/ContractRepository.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/CompanyManagment.App.Contracts/Contract/IContractApplication.cs b/CompanyManagment.App.Contracts/Contract/IContractApplication.cs index 38c2fc2b..c2f10398 100644 --- a/CompanyManagment.App.Contracts/Contract/IContractApplication.cs +++ b/CompanyManagment.App.Contracts/Contract/IContractApplication.cs @@ -128,6 +128,7 @@ public class ContractPrintEmployerViewModel public ContractPrintLegalEmployerViewModel LegalEmployer { get; set; } public string WorkshopName { get; set; } public string Address { get; set; } + public string WorkshopCode { get; set; } } diff --git a/CompanyManagment.EFCore/Repository/ContractRepository.cs b/CompanyManagment.EFCore/Repository/ContractRepository.cs index 08a8a43f..c684138e 100644 --- a/CompanyManagment.EFCore/Repository/ContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/ContractRepository.cs @@ -1660,6 +1660,7 @@ public class ContractRepository : RepositoryBase, IContractRepos NationalCode = x.Employer.Nationalcode } : null, + WorkshopCode = workshop.InsuranceCode }; var employeeRes = new ContractPrintEmployeeViewModel()