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..1a44d328 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,94 @@ public interface IInsuranceListApplication #endregion Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); + Task ClientPrintOne(long id); +} + +public class InsuranceClientPrintViewModel +{ + public string Month { 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 +{ + /// + /// شماره بیمه + /// + 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 InsuranceShare { get; set; } + + } public class InsuranceClientSearchModel:PaginationRequest @@ -113,4 +202,11 @@ public class InsuranceClientListViewModel public int YearInt { get; set; } public string MonthName { get; set; } public int MonthInt { get; set; } + public int PersonnelCount { get; set; } + public int LeftWorkCount { get; set; } + public string AllInsuredShare { get; set; } + public string InsuredShare { get; set; } + public string EmployerShare { get; set; } + public string UnEmploymentInsurance { get; set; } + } \ No newline at end of file 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 7b2e6386..3f2eb9ac 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 && @@ -759,16 +761,15 @@ public class InsuranceListRepository : RepositoryBase, IIns { var createWarrning = new CheckoutWarningMessage( - "مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد", checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare); + "مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد", + checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare); _context.CheckoutWarningMessages.Add(createWarrning); } - + _context.SaveChanges(); } } - } - } _employeeInsurancListDataRepository.SaveChanges(); @@ -1777,46 +1778,76 @@ 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); + .Where(x => x.WorkshopId == workshopId); - if (searchModel.Year>0) + if (searchModel.Year > 0) { - query = query.Where(x => x.YearInt == searchModel.Year); - } + query = query.Where(x => x.Year == searchModel.Year.ToString("0000")); + } + if (searchModel.Month > 0) { - query = query.Where(x => x.MonthInt == searchModel.Month); + query = query.Where(x => x.Month == searchModel.Month.ToString("00")); } var res = new PagedResult { TotalCount = query.Count() }; + + var list = (await query.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync()); + + var insuranceListIds = list.Select(x => x.id).ToList(); + + var employeeData = await _context.EmployeeInsurancListDataSet + .Where(x => insuranceListIds.Contains(x.InsuranceListId)) + .GroupBy(x => x.InsuranceListId) + .Select(g => new + { + g.Key, + Count = g.Count(x=>x.LeftWorkDate != null) + }).ToListAsync(); + query = searchModel.Sorting switch { - "CreationDate-Max" => query.OrderByDescending(x => x.Id), - "CreationDate-Min" => query.OrderBy(x => x.Id), - "Month-Max" => query.OrderByDescending(x => x.MonthInt), - "Month-Min" => query.OrderBy(x => x.MonthInt), - "Year-Max" => query.OrderByDescending(x => x.YearInt), - "Year-Min" => query.OrderBy(x => x.YearInt), - _ => query.OrderByDescending(x => x.Id), + "CreationDate-Max" => query.OrderByDescending(x => x.id), + "CreationDate-Min" => query.OrderBy(x => x.id), + "Month-Max" => query.OrderByDescending(x => x.Month), + "Month-Min" => query.OrderBy(x => x.Month), + "Year-Max" => query.OrderByDescending(x => x.Year), + "Year-Min" => query.OrderBy(x => x.Year), + _ => query.OrderByDescending(x => x.id), }; - res.List =await query.ApplyPagination(searchModel.PageIndex,searchModel.PageSize).ToListAsync(); + + var resList = list + .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), + EmployerShare = x.EmployerShare.ToMoney(), + InsuredShare = x.InsuredShare.ToMoney(), + UnEmploymentInsurance = x.UnEmploymentInsurance.ToMoney(), + PersonnelCount = x.SumOfEmployees, + AllInsuredShare = (x.InsuredShare + + x.EmployerShare + + x.UnEmploymentInsurance).ToMoney(), + LeftWorkCount =employeeData.FirstOrDefault(e=>e.Key == x.id)?.Count ?? 0, + }).ToList(); + + + + res.List = resList; return res; } @@ -1882,10 +1913,10 @@ public class InsuranceListRepository : RepositoryBase, IIns 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.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) @@ -1965,6 +1996,77 @@ 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 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() + { + 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", + Month = insurance.Month, + Year = insurance.Year + + }; + 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 +{ }