diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index 35558af3..8de9bf00 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -33,11 +33,78 @@ public static class Tools public static string[] DayNamesG = { "یکشنبه", "دو شنبه", "سه شنبه", "چهار شنبه", "پنج شنبه", "جمعه", "شنبه" }; /// - /// محاسبه سن + /// دریافت روزهای کارکرد پرسنل در لیست بیمه ماه مشخص شده + /// با کمک شروع بکار و ترک کار /// + /// + /// /// /// + /// /// + public static (int countWorkingDays,DateTime startWork,DateTime endWork,bool hasStartWorkInMonth,bool hasLeftWorkInMonth) GetEmployeeInsuranceWorkingDays(DateTime startWork,DateTime? leftWork,DateTime startDate, + DateTime endDate,long employeeId) + { + DateTime start = startDate; + DateTime end = endDate; + bool startWorkInMonth = false; + bool endWorkInMonth = false; + + //اگر شروع بکار پرسنل در ماه مشخص شده لیست بیمه بود + if (startWork >= startDate) + { + start = startWork; + startWorkInMonth = true; + } + + //اگر ترک کار پرسنل در ماه مشخص شده لیست بیمه بود + if (leftWork != null && leftWork.Value <= endDate) + { + end = leftWork.Value; + endWorkInMonth = true; + } + + int countDays = (int)(end - start).TotalDays +1; + + + //روزهای کارکرد پرسنل با آی دی های زیر دستی تعریف شد + switch (employeeId) + { + + //case 3812://ثابت- کسری حاجی پور + // countWorkingDays = 15; + // break; + case 40463://ثابت + countDays = 10; + break; + case 40469://ثابت + countDays = 7; + break; + case 9950://ثابت + countDays = 15; + break; + case 9640://ثابت + countDays = 15; + break; + case 40998://ثابت + countDays = 15; + break; + case 6219://ثابت + countDays = 15; + break; + //case 7897://ثابت + // countWorkingDays = 15; + } + + + return (countDays,start,end,startWorkInMonth,endWorkInMonth); + } + /// + /// محاسبه سن + /// + /// + /// + /// public static (int yearCount, int monthCount, int dayCount) GetAge(DateTime startDate, DateTime endDate) { diff --git a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs index 63d5b6a9..355184f9 100644 --- a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs +++ b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs @@ -35,6 +35,11 @@ public interface IInsuranceListRepository:IRepository /// public List OptimizedSearch(InsuranceListSearchModel searchModel); + /// + /// محاسبه پایه سنوات بیمه برای پرسنل + /// + /// + (int insuranceHistoryYearsCount, double baseYear) GetEmployeeInsuranceBaseYear(long employeeId, long workshopId, int countWorkingDay, DateTime listStartDate, DateTime endDate); #endregion #region client diff --git a/Company.Domain/LeftWorkInsuranceAgg/ILeftWorkInsuranceRepository.cs b/Company.Domain/LeftWorkInsuranceAgg/ILeftWorkInsuranceRepository.cs index 4e4c0f4e..5bd39f8e 100644 --- a/Company.Domain/LeftWorkInsuranceAgg/ILeftWorkInsuranceRepository.cs +++ b/Company.Domain/LeftWorkInsuranceAgg/ILeftWorkInsuranceRepository.cs @@ -34,11 +34,11 @@ public interface ILeftWorkInsuranceRepository : IRepository - /// دریافت ترک کار بیمه با آی دی کارگاه + /// دریافت شروع و ترک کار بیمه پرسنل و اطلاعات هویتی آن /// /// /// - List GetInsuranceleftWorks(long workshopId, DateTime startDate, DateTime endDate); + List GetEmployeeInsuranceLeftWorksAndInformation(long workshopId, DateTime startDate, DateTime endDate); #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/EmployeeDetailsForInsuranceListViewModel.cs b/CompanyManagment.App.Contracts/InsuranceList/EmployeeDetailsForInsuranceListViewModel.cs index 13f8712e..5bf4da84 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/EmployeeDetailsForInsuranceListViewModel.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/EmployeeDetailsForInsuranceListViewModel.cs @@ -183,7 +183,11 @@ public class EmployeeDetailsForInsuranceListViewModel public string JobCode { get; set; } public double HousingAllowance { get; set; } public double ConsumableItems { get; set; } - public double MaritalStatus { get; set; } + + /// + /// وضعیت تاهل + /// + public string MaritalStatus { get; set; } public bool IsMaritalStatusSet { get; set; } public int EndMonthCurrentDay { get; set; } public double SumOfDailyWage { get; set; } @@ -195,6 +199,9 @@ public class EmployeeDetailsForInsuranceListViewModel public bool HasLeftWorkInMonth { get; set; } public bool HasStartWorkInMonth { get; set; } public long EmployeeInsurancListDataId { get; set; } + /// + /// مشمول مزیا - عدم مشمول مزایا + /// public bool IncludeStatus { get; set; } /// @@ -236,7 +243,7 @@ public class EmployeeDetailsForInsuranceListViewModel /// حق تاهل /// DSW_SPOUSE /// - public string MarriedAllowance { get; set; } + public double MarriedAllowance { get; set; } ///// ///// مجموع پایه سنواتی کارکنان ///// DSK_INC diff --git a/CompanyManagment.App.Contracts/LeftWorkInsurance/ILeftWorkInsuranceApplication.cs b/CompanyManagment.App.Contracts/LeftWorkInsurance/ILeftWorkInsuranceApplication.cs index eebe2942..f9a3d9c3 100644 --- a/CompanyManagment.App.Contracts/LeftWorkInsurance/ILeftWorkInsuranceApplication.cs +++ b/CompanyManagment.App.Contracts/LeftWorkInsurance/ILeftWorkInsuranceApplication.cs @@ -32,13 +32,13 @@ public interface ILeftWorkInsuranceApplication OperationResult CheckBeforeSaveLeftWorkInsurance(long workshopId, long employeeId, string date, int type); - #region Insurance - /// - /// دریافت ترک کار بیمه با آی دی کارگاه - /// - /// - /// - List GetInsuranceleftWorks(long workshopId, DateTime startDate, DateTime endDate); + #region Insurance + /// + /// دریافت شروع و ترک کار بیمه پرسنل و اطلاعات هویتی آن + /// + /// + /// + List GetEmployeeInsuranceLeftWorksAndInformation(long workshopId, DateTime startDate, DateTime endDate); #endregion } \ No newline at end of file diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index 8f48f0b7..810edb35 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -8,6 +8,7 @@ using Company.Domain.DateSalaryAgg; using Company.Domain.DateSalaryItemAgg; using Company.Domain.EmployeeAgg; using Company.Domain.EmployeeChildrenAgg; +using Company.Domain.empolyerAgg; using Company.Domain.InsuranceEmployeeInfoAgg; using Company.Domain.InsuranceJobItemAgg; using Company.Domain.InsuranceListAgg; @@ -371,7 +372,7 @@ public class InsuranceListApplication: IInsuranceListApplication public MainEmployeeDetailsViewModel SearchEmployeeForCreateInsuranceList( EmployeeForCreateInsuranceListSearchModel searchModel) { var watch = new Stopwatch(); - watch.Start(); + var result = new MainEmployeeDetailsViewModel(); var workshopId = searchModel.WorkshopIds.FirstOrDefault(); //var employerId = _workShopRepository.GetDetails(workshopId).EmployerIdList.FirstOrDefault(); @@ -379,19 +380,74 @@ public class InsuranceListApplication: IInsuranceListApplication var isBolock = _contractingPartyApp.IsBlockCheckByWorkshopId(workshopId); double monthlybaseYear = 0; // اگر در این سال و ماه برای این کارگاه لیست بیمه ایجاد نشده بود - if (!_insuranceListRepositpry.Exists(x =>x.Year == searchModel.Year && x.Month == searchModel.Month && searchModel.WorkshopIds.Contains(x.WorkshopId))) + if (!_insuranceListRepositpry.Exists(x => + x.Year == searchModel.Year && x.Month == searchModel.Month && + searchModel.WorkshopIds.Contains(x.WorkshopId))) { - DateTime startdateGr = (searchModel.Year + "/" + searchModel.Month + "/01").ToGeorgianDateTime(); - DateTime endDateGr = (searchModel.Year + "/" + searchModel.Month + "/01").FindeEndOfMonth().ToGeorgianDateTime(); + DateTime startDateGr = (searchModel.Year + "/" + searchModel.Month + "/01").ToGeorgianDateTime(); + DateTime endDateGr = (searchModel.Year + "/" + searchModel.Month + "/01").FindeEndOfMonth() + .ToGeorgianDateTime(); - List list = new List(); + List list = new List(); + //مقادیر سالانه این تاریخ + var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDateGr, endDateGr, searchModel.Year); - // شروع بکار و ترک کار بیمه - var leftWorkInsuranceViewModel = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModel); - var leftWorkInsuranceViewModelList = _leftWorkInsuranceApplication.GetInsuranceleftWorks(workshopId, startdateGr, endDateGr); + + // دریافت اطلاعات هویتی و شروع و ترک کار کارکنان + var employeesInfoAndLeftWorks = + _leftWorkInsuranceApplication.GetEmployeeInsuranceLeftWorksAndInformation(workshopId, startDateGr, + endDateGr); + watch.Start(); + var computeResult = employeesInfoAndLeftWorks.Select(employee => + { + var dateOfBirth = employee.DateOfBirthGr.ToFarsi(); + var dateOfIssue = employee.DateOfIssueGr.ToFarsi(); + var leftDate = employee.LeftWorkDateGr != null ? employee.LeftWorkDateGr.Value.AddDays(-1) : new DateTime(); + var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employee.StartWorkDateGr, leftDate, startDateGr,endDateGr, employee.EmployeeId); + //به دست آوردن دستمزد روزانه با توجه به اینکه کارگاه مشاغل مقطوع است یا خیر + var dailyWage = searchModel.FixedSalary ? + Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, workshopId, employee.EmployeeId, startDateGr, endDateGr, employee.JobId, searchModel.Population, searchModel.InsuranceJobId)) + : ComputeDailyWage(yearlysaleries.DayliWage, employee.EmployeeId, workshopId, searchModel.Year); + return new EmployeeDetailsForInsuranceListViewModel + { + #region EmployeeInfo + + InsuranceEmployeeInformationId = employee.InsuranceEmployeeInformationId, + EmployeeId = employee.EmployeeId, + FName = employee.FName, + LName = employee.LName, + FatherName = employee.FatherName, + DateOfBirth = dateOfBirth == "1300/10/11" ? "" : dateOfBirth, + DateOfIssue = dateOfIssue, + DateOfBirthGr = employee.DateOfBirthGr, + DateOfIssueGr = employee.DateOfIssueGr, + PlaceOfIssue = employee.PlaceOfIssue, + IdNumber = employee.IdNumber, + Gender = employee.Gender, + NationalCode = employee.NationalCode, + Nationality = employee.Nationality, + InsuranceCode = employee.InsuranceCode, + + #endregion + + #region Compute + + IncludeStatus = employee.IncludeStatus, + DailyWage = GetRoundValue(dailyWage), + + #endregion + + + }; + }); + Console.WriteLine("New Compute : " + watch.Elapsed); + watch.Stop(); + + watch.Start(); + var leftWorkInsuranceViewModel = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModel); //int leftWorkInsuranceCount= leftWorkInsuranceViewModelList.Count(); - string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; + string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); var model = new YearlySalarySearchModel(); @@ -402,11 +458,10 @@ public class InsuranceListApplication: IInsuranceListApplication model.year = searchModel.Year; - //مقادیر سالانه این تاریخ - var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDate, endDate, searchModel.Year); + - foreach (var item in leftWorkInsuranceViewModelList) + foreach (var item in leftWorkInsuranceViewModel) { var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); @@ -615,7 +670,7 @@ public class InsuranceListApplication: IInsuranceListApplication - employeeDetailsForInsuranceObj.MarriedAllowance = "0"; + employeeDetailsForInsuranceObj.MarriedAllowance = 0; if (item.IncludeStatus) { @@ -683,13 +738,14 @@ public class InsuranceListApplication: IInsuranceListApplication result.IsExist = false; result.IsBlock = isBolock; result.MaritalStatus = yearlysaleries.MarriedAllowance; - } + Console.WriteLine("old heydari compute : " + watch.Elapsed); + } else { result.IsExist = true; result.IsBlock = isBolock; } - Console.WriteLine("SearchEmployeeForCreateInsuranceList : " + watch.Elapsed); + return result; } @@ -1038,7 +1094,7 @@ public class InsuranceListApplication: IInsuranceListApplication .Where(x => x.ItemName == "حق تاهل").FirstOrDefault(); item.HousingAllowance = housingAllowance.ItemValue; item.ConsumableItems = consumableItems.ItemValue; - item.MaritalStatus = maritalStatus.ItemValue; + item.MarriedAllowance = maritalStatus.ItemValue; item.YearlySalaryItem = yearlysalaryItem.ItemValue; } diff --git a/CompanyManagment.Application/LeftWorkInsuranceApplication.cs b/CompanyManagment.Application/LeftWorkInsuranceApplication.cs index ff73888a..8594755b 100644 --- a/CompanyManagment.Application/LeftWorkInsuranceApplication.cs +++ b/CompanyManagment.Application/LeftWorkInsuranceApplication.cs @@ -609,9 +609,9 @@ public class LeftWorkInsuranceApplication : ILeftWorkInsuranceApplication #region Insurance - public List GetInsuranceleftWorks(long workshopId, DateTime startDate, DateTime endDate) + public List GetEmployeeInsuranceLeftWorksAndInformation(long workshopId, DateTime startDate, DateTime endDate) { - return _leftWorkInsuranceRepository.GetInsuranceleftWorks(workshopId, startDate, endDate); + return _leftWorkInsuranceRepository.GetEmployeeInsuranceLeftWorksAndInformation(workshopId, startDate, endDate); } #endregion diff --git a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs index b4b2ec98..3137ce50 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs @@ -1177,4 +1177,14 @@ public class InsuranceListRepository : RepositoryBase, IIns #endregion + + public (int insuranceHistoryYearsCount, double baseYear) GetEmployeeInsuranceBaseYear(long employeeId, long workshopId, int countWorkingDay,DateTime listStartDate, DateTime endDate) + { + var lefts = _context.LeftWorkInsuranceList + .Where(x => x.EmployeeId == employeeId); + + + + return (0, 0); + } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/LeftWorkInsuranceRepository.cs b/CompanyManagment.EFCore/Repository/LeftWorkInsuranceRepository.cs index 4d7b20e5..992ede00 100644 --- a/CompanyManagment.EFCore/Repository/LeftWorkInsuranceRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeftWorkInsuranceRepository.cs @@ -695,7 +695,7 @@ public class LeftWorkInsuranceRepository : RepositoryBase GetInsuranceleftWorks(long workshopId, DateTime startDate, DateTime endDate) + public List GetEmployeeInsuranceLeftWorksAndInformation(long workshopId, DateTime startDate, DateTime endDate) { if (workshopId == 0) return []; @@ -713,7 +713,7 @@ public class LeftWorkInsuranceRepository : RepositoryBase left.JobId, job => job.id, (left, job) => new { left, job }) - .Join(_context.InsuranceEmployeeInformationSet, + .GroupJoin(_context.InsuranceEmployeeInformationSet.AsSplitQuery(), result => result.left.EmployeeId, employeeInfo => employeeInfo.EmployeeId, (result, employeeInfo) => new @@ -721,66 +721,35 @@ public class LeftWorkInsuranceRepository : RepositoryBase new EmployeeDetailsForInsuranceListViewModel + }) + .SelectMany(x => x.employeeInfo.DefaultIfEmpty(), (x, employeeInfo) => new { x, employeeInfo }) + .Select(result => new EmployeeDetailsForInsuranceListViewModel { - StartWorkDateGr = result.left.StartWorkDate, - LeftWorkDateGr = result.left.LeftWorkDate, - + StartWorkDateGr = result.x.left.StartWorkDate, + LeftWorkDateGr = result.x.left.LeftWorkDate, + IncludeStatus = result.x.left.IncludeStatus, + JobId = result.x.left.JobId, + JobName = result.x.job != null ? result.x.job.JobName : string.Empty, + JobCode = result.x.job != null ? result.x.job.JobCode : string.Empty, + InsuranceEmployeeInformationId = result.employeeInfo != null ? result.employeeInfo.id : 0, + EmployeeId = result.x.left.EmployeeId, - IncludeStatus = result.left.IncludeStatus, - JobId = result.left.JobId, - JobName = result.job != null ? result.job.JobName : string.Empty, - JobCode = result.job != null ? result.job.JobCode : string.Empty, - - - InsuranceEmployeeInformationId = result.employeeInfo.id, - EmployeeId = result.left.EmployeeId, - - FName = result.employeeInfo != null ? result.employeeInfo.FName : result.left.Employee.FName, - - LName = result.employeeInfo != null ? result.employeeInfo.LName : result.left.Employee.LName, - - - - + //اطلاعات هویتی + FName = result.employeeInfo != null ? result.employeeInfo.FName : result.x.left.Employee.FName, + LName = result.employeeInfo != null ? result.employeeInfo.LName : result.x.left.Employee.LName, + FatherName = result.employeeInfo != null ? result.employeeInfo.FatherName : result.x.left.Employee.FatherName, + DateOfBirthGr = result.employeeInfo != null ? result.employeeInfo.DateOfBirth : result.x.left.Employee.DateOfBirth, + DateOfIssueGr = result.employeeInfo != null ? result.employeeInfo.DateOfIssue : result.x.left.Employee.DateOfIssue, + PlaceOfIssue = result.employeeInfo != null ? result.employeeInfo.PlaceOfIssue : result.x.left.Employee.PlaceOfIssue, + IdNumber = result.employeeInfo != null ? result.employeeInfo.IdNumber : result.x.left.Employee.IdNumber, + Gender = result.employeeInfo != null ? result.employeeInfo.Gender : result.x.left.Employee.Gender, + NationalCode = result.x.left.Employee.NationalCode, + Nationality = result.x.left.Employee.Nationality, + InsuranceCode = result.x.left.Employee.InsuranceCode, + MaritalStatus = result.x.left.Employee.MaritalStatus, + IsMaritalStatusSet = !string.IsNullOrWhiteSpace(result.x.left.Employee.MaritalStatus) }).ToList(); - // FatherName = employeeInfoObject.FatherName - - // DateOfBirth = employeeInfoObject.DateOfBirth - - // DateOfIssue = employeeInfoObject.DateOfIssue - - // DateOfBirthGr = employeeInfoObject.DateOfBirthGr - - // DateOfIssueGr = employeeInfoObject.DateOfIssueGr - - // PlaceOfIssue = employeeInfoObject.PlaceOfIssue - - // IdNumber = employeeInfoObject.IdNumber - - // Gender = employeeInfoObject.Gender - - //LeftWorkInsuranceViewModel} - // { - // Id = left.id, - // //LeftWorkDate = left.LeftWorkDate != null ? left.LeftWorkDate.ToFarsi() : "", - // //StartWorkDate = left.StartWorkDate.ToFarsi(), - // StartWorkDateGr = left.StartWorkDate, - // LeftWorkDateGr = left.LeftWorkDate, - // EmployeeFullName = left.EmployeeFullName, - // WorkshopName = left.WorkshopName, - // WorkshopId = left.WorkshopId, - // EmployeeId = left.EmployeeId, - // IncludeStatus = left.IncludeStatus, - // JobId = left.JobId, - // JobName = job != null ? job.JobName : string.Empty, - // JobCode = job != null ? job.JobCode : string.Empty, - - //}); return query; }