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; } ///