diff --git a/Company.Domain/LeftWorkInsuranceAgg/ILeftWorkInsuranceRepository.cs b/Company.Domain/LeftWorkInsuranceAgg/ILeftWorkInsuranceRepository.cs index de06adce..4e4c0f4e 100644 --- a/Company.Domain/LeftWorkInsuranceAgg/ILeftWorkInsuranceRepository.cs +++ b/Company.Domain/LeftWorkInsuranceAgg/ILeftWorkInsuranceRepository.cs @@ -31,4 +31,14 @@ public interface ILeftWorkInsuranceRepository : IRepository + /// دریافت ترک کار بیمه با آی دی کارگاه + /// + /// + /// + List GetInsuranceleftWorks(long workshopId, DateTime startDate, DateTime endDate); + + #endregion } \ No newline at end of file diff --git a/Company.Domain/YearlySalaryAgg/IYearlySalaryRepository.cs b/Company.Domain/YearlySalaryAgg/IYearlySalaryRepository.cs index 02e354c0..25c5c6f7 100644 --- a/Company.Domain/YearlySalaryAgg/IYearlySalaryRepository.cs +++ b/Company.Domain/YearlySalaryAgg/IYearlySalaryRepository.cs @@ -51,7 +51,14 @@ public interface IYearlySalaryRepository : IRepository Task HolidayGregorian(DateTime gregorianDate); Task HolidayShamsi(string shamsiDate); - #endregion + #endregion + + + #region Insurance + + InsuranceYearlySalaryModel GetInsuranceItems(DateTime startDate, DateTime endDate, string year); + + #endregion + - } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/LeftWorkInsurance/ILeftWorkInsuranceApplication.cs b/CompanyManagment.App.Contracts/LeftWorkInsurance/ILeftWorkInsuranceApplication.cs index c9cc6081..eebe2942 100644 --- a/CompanyManagment.App.Contracts/LeftWorkInsurance/ILeftWorkInsuranceApplication.cs +++ b/CompanyManagment.App.Contracts/LeftWorkInsurance/ILeftWorkInsuranceApplication.cs @@ -31,4 +31,14 @@ public interface ILeftWorkInsuranceApplication OperationResult CheckEditLeftWorkInsurance(long workshopId, long employeeId, string date, int type); OperationResult CheckBeforeSaveLeftWorkInsurance(long workshopId, long employeeId, string date, int type); + + #region Insurance + /// + /// دریافت ترک کار بیمه با آی دی کارگاه + /// + /// + /// + List GetInsuranceleftWorks(long workshopId, DateTime startDate, DateTime endDate); + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/YearlySalary/IYearlySalaryApplication.cs b/CompanyManagment.App.Contracts/YearlySalary/IYearlySalaryApplication.cs index 3e2fd568..d068375a 100644 --- a/CompanyManagment.App.Contracts/YearlySalary/IYearlySalaryApplication.cs +++ b/CompanyManagment.App.Contracts/YearlySalary/IYearlySalaryApplication.cs @@ -19,4 +19,10 @@ public interface IYearlySalaryApplication Task HolidayGregorian(DateTime gregorianDate); Task HolidayShamsi(string shamsiDate); + + #region Insurance + + InsuranceYearlySalaryModel GetInsuranceItems(DateTime startDate, DateTime endDate, string year); + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/YearlySalary/InsuranceYearlySalaryModel.cs b/CompanyManagment.App.Contracts/YearlySalary/InsuranceYearlySalaryModel.cs new file mode 100644 index 00000000..093d2053 --- /dev/null +++ b/CompanyManagment.App.Contracts/YearlySalary/InsuranceYearlySalaryModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CompanyManagment.App.Contracts.YearlySalary; + +public class InsuranceYearlySalaryModel +{ + public double DayliWage { get; set; } + public double HousingAllowance { get; set; } + public double ConsumableItems { get; set; } + public double MarriedAllowance { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index bd6b909c..8f48f0b7 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -381,42 +381,30 @@ public class InsuranceListApplication: IInsuranceListApplication // اگر در این سال و ماه برای این کارگاه لیست بیمه ایجاد نشده بود if (!_insuranceListRepositpry.Exists(x =>x.Year == searchModel.Year && x.Month == searchModel.Month && searchModel.WorkshopIds.Contains(x.WorkshopId))) { - List list = new List(); - - // شروع بکار و ترک کار بیمه - var leftWorkInsuranceViewModelList =_leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModel); + DateTime startdateGr = (searchModel.Year + "/" + searchModel.Month + "/01").ToGeorgianDateTime(); + DateTime endDateGr = (searchModel.Year + "/" + searchModel.Month + "/01").FindeEndOfMonth().ToGeorgianDateTime(); - int leftWorkInsuranceCount= leftWorkInsuranceViewModelList.Count(); + List list = new List(); + + // شروع بکار و ترک کار بیمه + var leftWorkInsuranceViewModel = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModel); + var leftWorkInsuranceViewModelList = _leftWorkInsuranceApplication.GetInsuranceleftWorks(workshopId, startdateGr, endDateGr); + //int leftWorkInsuranceCount= leftWorkInsuranceViewModelList.Count(); string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); var model = new YearlySalarySearchModel(); var startDate = startMonthCurrent.ToGeorgianDateTime(); + var endDate = endMonthCurrent.ToGeorgianDateTime(); model.StartDateGr = startDate; model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); model.year = searchModel.Year; //مقادیر سالانه این تاریخ - var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); + var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDate, endDate, searchModel.Year); - var yearlysalaryItem = new YearlysalaryItemViewModel(); - var housingAllowance = new YearlysalaryItemViewModel(); - var consumableItems = new YearlysalaryItemViewModel(); - var maritalStatus = new YearlysalaryItemViewModel(); - if (yearSalaryObj != null) - { - yearlysalaryItem = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "مزد روزانه").FirstOrDefault(); - housingAllowance = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "کمک هزینه مسکن").FirstOrDefault(); - consumableItems = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "کمک هزینه اقلام").FirstOrDefault(); - maritalStatus = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "حق تاهل").FirstOrDefault(); - - } foreach (var item in leftWorkInsuranceViewModelList) { @@ -425,7 +413,8 @@ public class InsuranceListApplication: IInsuranceListApplication var employeeDetailsForInsuranceObj = new EmployeeDetailsForInsuranceListViewModel(); employeeDetailsForInsuranceObj.HasConfilictJobs = false; - employeeDetailsForInsuranceObj.IsMaritalStatusSet = // آیا وضعیت تاهل پرسنل ست شده است + // آیا وضعیت تاهل پرسنل ست شده است + employeeDetailsForInsuranceObj.IsMaritalStatusSet = !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); //دزیافت اطلاعات هویتی پرسنل //در صورت نداشن دیتا از جدول پرسنل پر می شود @@ -593,17 +582,17 @@ public class InsuranceListApplication: IInsuranceListApplication double dailyWage = employeeDetailsForInsuranceObj.DailyWage; if (searchModel.FixedSalary) { - dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, item.WorkshopId,item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); + dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, workshopId,item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); employeeDetailsForInsuranceObj.HasConfilictJobs = (dailyWage == 0 ? true : false); } #endregion - if (yearlysalaryItem != null) + if (yearlysaleries != null) { if(!searchModel.FixedSalary ) { //dailyWage= yearlysalaryItem.ItemValue; - dailyWage = ComputeDailyWage(yearlysalaryItem.ItemValue, item.EmployeeId,item.WorkshopId, searchModel.Year) ; + dailyWage = ComputeDailyWage(yearlysaleries.DayliWage, item.EmployeeId,workshopId, searchModel.Year) ; //(double basic, int totalYears) basicResult = BasicYear(item.EmployeeId, workshopId, startDate); //var basic = basicResult.basic; @@ -618,10 +607,10 @@ public class InsuranceListApplication: IInsuranceListApplication employeeDetailsForInsuranceObj.DailyWageStr = employeeDetailsForInsuranceObj.DailyWage.ToMoney(); employeeDetailsForInsuranceObj.DailyWagePlusBaseYears = "0"; employeeDetailsForInsuranceObj.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); - employeeDetailsForInsuranceObj.HousingAllowance = housingAllowance.ItemValue; - employeeDetailsForInsuranceObj.ConsumableItems = consumableItems.ItemValue; + employeeDetailsForInsuranceObj.HousingAllowance = yearlysaleries.HousingAllowance; + employeeDetailsForInsuranceObj.ConsumableItems = yearlysaleries.ConsumableItems; employeeDetailsForInsuranceObj.EndMonthCurrentDay = endMonthCurrentDay; - employeeDetailsForInsuranceObj.YearlySalaryItem = yearlysalaryItem.ItemValue; + employeeDetailsForInsuranceObj.YearlySalaryItem = yearlysaleries.DayliWage; employeeDetailsForInsuranceObj.MonthlyBaseYearsStr = monthlybaseYear.ToMoney(); @@ -630,8 +619,8 @@ public class InsuranceListApplication: IInsuranceListApplication if (item.IncludeStatus) { - var marital = employeeObject.MaritalStatus == "متاهل" ? maritalStatus.ItemValue : 0; - employeeDetailsForInsuranceObj.MonthlyBenefits = GetMonthlyBenefits(endMonthCurrentDay, consumableItems.ItemValue, housingAllowance.ItemValue, marital, countWorkingDays); + var marital = employeeObject.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0; + employeeDetailsForInsuranceObj.MonthlyBenefits = GetMonthlyBenefits(endMonthCurrentDay, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marital, countWorkingDays); } else { @@ -693,7 +682,7 @@ public class InsuranceListApplication: IInsuranceListApplication result.EmployeeDetailsForInsuranceList = list; result.IsExist = false; result.IsBlock = isBolock; - result.MaritalStatus = maritalStatus.ItemValue; + result.MaritalStatus = yearlysaleries.MarriedAllowance; } else { diff --git a/CompanyManagment.Application/LeftWorkInsuranceApplication.cs b/CompanyManagment.Application/LeftWorkInsuranceApplication.cs index 9b155cea..ff73888a 100644 --- a/CompanyManagment.Application/LeftWorkInsuranceApplication.cs +++ b/CompanyManagment.Application/LeftWorkInsuranceApplication.cs @@ -447,30 +447,17 @@ public class LeftWorkInsuranceApplication : ILeftWorkInsuranceApplication public List SearchForCreateInsuranceList( EmployeeForCreateInsuranceListSearchModel searchModel) { - var resultList = new List(); + string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; + var resultList = new List(); var leftWorkInsuranceList = _leftWorkInsuranceRepository.SearchForCreateInsuranceList(searchModel); - //foreach (var item in leftWorkInsuranceList) - //{ - // item.StartWorkDate = item.StartWorkDateGr.ToFarsi(); - // if (item.LeftWorkDateGr != null) - // { - // item.LeftWorkDate = item.LeftWorkDateGr.ToFarsi(); - // item.EndWorkDate = GetBeforeDate(item.LeftWorkDate); - // item.IsActiveWorkshop = false; - // } - // else - // { - // item.IsActiveWorkshop = true; - // } - //} //انتخاب ماه و سال برای ثبت بیمه اجباری است if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month)) { string yearAndMonth = searchModel.Year + "/" + searchModel.Month; - string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; + // string endMonthCurrent = searchModel.Year + "/" + searchModel.Month + startMonthCurrent.FindeEndOfMonth(); var year = Convert.ToInt32(searchModel.Year); @@ -619,4 +606,15 @@ public class LeftWorkInsuranceApplication : ILeftWorkInsuranceApplication return _leftWorkInsuranceRepository.CheckBeforeSaveLeftWorkInsurance(workshopId, employeeId, date.ToGeorgianDateTime(), type); } + + #region Insurance + + public List GetInsuranceleftWorks(long workshopId, DateTime startDate, DateTime endDate) + { + return _leftWorkInsuranceRepository.GetInsuranceleftWorks(workshopId, startDate, endDate); + } + + #endregion + + } \ No newline at end of file diff --git a/CompanyManagment.Application/YearlySalaryApplication.cs b/CompanyManagment.Application/YearlySalaryApplication.cs index d2344aaf..82afe137 100644 --- a/CompanyManagment.Application/YearlySalaryApplication.cs +++ b/CompanyManagment.Application/YearlySalaryApplication.cs @@ -148,4 +148,19 @@ public class YearlySalaryApplication : IYearlySalaryApplication { return _yearlySalaryRepository.HolidayShamsi(shamsiDate); } + + #region Insurance + /// + /// دریافت مقادیر برای استفاده در بیمه + /// + /// + /// + /// + /// + public InsuranceYearlySalaryModel GetInsuranceItems(DateTime startDate, DateTime endDate, string year) + { + return _yearlySalaryRepository.GetInsuranceItems(startDate, endDate, year); + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/LeftWorkInsuranceRepository.cs b/CompanyManagment.EFCore/Repository/LeftWorkInsuranceRepository.cs index 522cc889..4d7b20e5 100644 --- a/CompanyManagment.EFCore/Repository/LeftWorkInsuranceRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeftWorkInsuranceRepository.cs @@ -10,6 +10,7 @@ using Company.Domain.PersonnelCodeAgg; using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.App.Contracts.LeftWorkInsurance; using CompanyManagment.App.Contracts.PersonnleCode; +using Microsoft.EntityFrameworkCore; namespace CompanyManagment.EFCore.Repository; @@ -691,4 +692,98 @@ public class LeftWorkInsuranceRepository : RepositoryBase GetInsuranceleftWorks(long workshopId, DateTime startDate, DateTime endDate) + { + if (workshopId == 0) + return []; + var query = _context.LeftWorkInsuranceList.Include(x => x.Employee) + .Where(x => x.WorkshopId == workshopId) + .Where(x => + ((x.LeftWorkDate != null && x.LeftWorkDate != DateTime.MinValue) && + ((DateTime)x.LeftWorkDate >= startDate && + (DateTime)x.LeftWorkDate <= endDate)) || + ((x.LeftWorkDate != null && x.LeftWorkDate != DateTime.MinValue) && + (DateTime)x.LeftWorkDate >= endDate) || + (x.LeftWorkDate == null || x.LeftWorkDate == DateTime.MinValue)) + .Where(x => x.StartWorkDate <= endDate) + .Join(_context.Jobs, + left => left.JobId, + job => job.id, + (left, job) => new { left, job }) + .Join(_context.InsuranceEmployeeInformationSet, + result => result.left.EmployeeId, + employeeInfo => employeeInfo.EmployeeId, + (result, employeeInfo) => new + { + result.left, + result.job, + employeeInfo + + } + + ).Select(result => new EmployeeDetailsForInsuranceListViewModel + { + StartWorkDateGr = result.left.StartWorkDate, + LeftWorkDateGr = result.left.LeftWorkDate, + + + 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, + + + + + }).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; + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs b/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs index 04cd0a1d..55877021 100644 --- a/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs +++ b/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs @@ -3472,5 +3472,27 @@ public class YearlySalaryRepository : RepositoryBase, IYearl #endregion + + + #region Insurance + + public InsuranceYearlySalaryModel GetInsuranceItems(DateTime startDate, DateTime endDate, string year) + { + var query = _context.YearlySalaries + .Where(x => x.StartDate <= startDate && x.EndDate >= endDate && x.Year == year) + .Include(x => x.YearlySalaryItemsList) + .Select(x=> new InsuranceYearlySalaryModel + { + DayliWage = x.YearlySalaryItemsList.FirstOrDefault(item=>item.ItemName == "مزد روزانه").ItemValue, + ConsumableItems = x.YearlySalaryItemsList.FirstOrDefault(item => item.ItemName == "کمک هزینه اقلام").ItemValue, + HousingAllowance = x.YearlySalaryItemsList.FirstOrDefault(item => item.ItemName == "کمک هزینه مسکن").ItemValue, + MarriedAllowance = x.YearlySalaryItemsList.Any(item => item.ItemName == "حق تاهل")? x.YearlySalaryItemsList.FirstOrDefault(item => item.ItemName == "حق تاهل").ItemValue : 0, + + }).FirstOrDefault(); + + return query; + } + + #endregion }