using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects; using AccountManagement.Domain.MediaAgg; using Company.Domain.CheckoutAgg; using Company.Domain.DateSalaryAgg; using Company.Domain.DateSalaryItemAgg; using Company.Domain.EmployeeAgg; using Company.Domain.EmployeeChildrenAgg; using Company.Domain.EmployeeInsurancListDataAgg; using Company.Domain.empolyerAgg; using Company.Domain.InsuranceEmployeeInfoAgg; using Company.Domain.InsuranceJobItemAgg; using Company.Domain.InsuranceListAgg; using Company.Domain.InsuranceListAgg.ValueObjects; using Company.Domain.InsurancWorkshopInfoAgg; using Company.Domain.LeftWorkAgg; using Company.Domain.LeftWorkInsuranceAgg; using Company.Domain.WorkshopAgg; using CompanyManagment.App.Contracts.DateSalary; using CompanyManagment.App.Contracts.DateSalaryItem; using CompanyManagment.App.Contracts.EmployeeInsurancListData; using CompanyManagment.App.Contracts.InsuranceEmployeeInfo; using CompanyManagment.App.Contracts.InsuranceJobItem; using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.App.Contracts.InsuranceList.Enums; using CompanyManagment.App.Contracts.InsuranceYearlySalary; using CompanyManagment.App.Contracts.LeftWorkInsurance; using CompanyManagment.App.Contracts.PersonalContractingParty; using CompanyManagment.App.Contracts.YearlySalary; using CompanyManagment.App.Contracts.YearlySalaryItems; using CompanyManagment.EFCore.Migrations; using MD.PersianDateTime.Standard; using Microsoft.AspNetCore.Authorization.Infrastructure; using Microsoft.AspNetCore.Http; namespace CompanyManagment.Application; public class InsuranceListApplication : IInsuranceListApplication { //private readonly ITransactionManager _transactionManager; private readonly IInsuranceListRepository _insuranceListRepositpry; private readonly IEmployeeInsurancListDataRepository _employeeInsurancListDataRepository; private readonly IInsuranceEmployeeInfoRepository _insuranceEmployeeInfoRepository; private readonly IEmployeeRepository _employeeRepository; private readonly IWorkshopRepository _workShopRepository; private readonly ILeftWorkInsuranceApplication _leftWorkInsuranceApplication; private readonly IInsuranceEmployeeInfoApplication _insuranceEmployeeInfoApplication; private readonly IEmployeeInsurancListDataApplication _employeeInsurancListDataApplication; private readonly IYearlySalaryApplication _yearlySalaryApplication; private readonly IYearlySalaryItemApplication _yearlySalaryItemApplication; private readonly IInsuranceWorkshopInfoRepository _insuranceWorkshopInfoRepository; private readonly IInsuranceJobItemRepositpry _insuranceJobItemRepository; private readonly IDateSalaryRepository _dateSalaryRepository; private readonly IDateSalaryItemRepository _dateSalaryItemRepository; private readonly IPersonalContractingPartyApp _contractingPartyApp; private readonly ILeftWorkInsuranceRepository _leftWorkInsuranceRepository; private readonly IInsuranceYearlySalaryApplication _insuranceYearlySalaryApplication; private readonly ICheckoutRepository _checkoutRepository; private readonly IMediaRepository _mediaRepository; public InsuranceListApplication(IInsuranceListRepository insuranceListRepositpry, IEmployeeInsurancListDataRepository employeeInsurancListDataRepository, IInsuranceEmployeeInfoRepository insuranceEmployeeInfoRepository, IEmployeeRepository employeeRepository, IWorkshopRepository workShopRepository, ILeftWorkInsuranceApplication leftWorkInsuranceApplication, IInsuranceEmployeeInfoApplication insuranceEmployeeInfoApplication, IEmployeeInsurancListDataApplication employeeInsurancListDataApplication, IYearlySalaryApplication yearlySalaryApplication, IYearlySalaryItemApplication yearlySalaryItemApplication, IInsuranceWorkshopInfoRepository insuranceWorkshopInfoRepository, IInsuranceJobItemRepositpry insuranceJobItemRepository, IDateSalaryRepository dateSalaryRepository, IDateSalaryItemRepository dateSalaryItemRepository, IPersonalContractingPartyApp contractingPartyApp, ILeftWorkInsuranceRepository leftWorkInsuranceRepository, IInsuranceYearlySalaryApplication insuranceYearlySalaryApplication, ICheckoutRepository checkoutRepository, IMediaRepository mediaRepository) { // _transactionManager = transactionManager; _insuranceListRepositpry = insuranceListRepositpry; _employeeInsurancListDataRepository = employeeInsurancListDataRepository; _insuranceEmployeeInfoRepository = insuranceEmployeeInfoRepository; _employeeRepository = employeeRepository; _workShopRepository = workShopRepository; _leftWorkInsuranceApplication = leftWorkInsuranceApplication; _insuranceEmployeeInfoApplication = insuranceEmployeeInfoApplication; _employeeInsurancListDataApplication = employeeInsurancListDataApplication; _yearlySalaryApplication = yearlySalaryApplication; _yearlySalaryItemApplication = yearlySalaryItemApplication; _insuranceWorkshopInfoRepository = insuranceWorkshopInfoRepository; _insuranceJobItemRepository = insuranceJobItemRepository; _dateSalaryRepository = dateSalaryRepository; _dateSalaryItemRepository = dateSalaryItemRepository; _contractingPartyApp = contractingPartyApp; _leftWorkInsuranceRepository = leftWorkInsuranceRepository; _insuranceYearlySalaryApplication = insuranceYearlySalaryApplication; _checkoutRepository = checkoutRepository; _mediaRepository = mediaRepository; } public OperationResult Create(CreateInsuranceList command) { var operation = new OperationResult(); if (command.WorkshopId == 0) { return operation.Failed(" انتخاب کارگاه اجباری می باشد "); } if (command.Month == "0") { return operation.Failed(" انتخاب ماه اجباری می باشد "); } if (command.Year == "0") { return operation.Failed("انتخاب سال اجباری می باشد "); } else if (_insuranceListRepositpry.Exists(x => x.WorkshopId == command.WorkshopId && x.Month == command.Month && x.Year == command.Year)) { return operation.Failed(" لیست بیمه برای کارگاه، سال و ماه انتخاب شده قبلا ایجاد شده است "); } else { #region EmployeeDetailsForInsurance if (command.EmployeeDetailsForInsuranceList != null && command.EmployeeDetailsForInsuranceList.Count > 0) { foreach (var item in command.EmployeeDetailsForInsuranceList) { if (item.InsuranceEmployeeInformationId == 0) { var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); createInsuranceEmployeeInfo.EmployeeId = item.EmployeeId; createInsuranceEmployeeInfo.FName = item.FName; createInsuranceEmployeeInfo.LName = item.LName; createInsuranceEmployeeInfo.FatherName = item.FatherName; createInsuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; createInsuranceEmployeeInfo.NationalCode = item.NationalCode; createInsuranceEmployeeInfo.IdNumber = item.IdNumber; createInsuranceEmployeeInfo.Gender = item.Gender; createInsuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; createInsuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); createInsuranceEmployeeInfo.DateOfIssueGr = item.DateOfIssue.ToGeorgianDateTime(); _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); } else { var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); insuranceEmployeeInfo.Id = item.InsuranceEmployeeInformationId; insuranceEmployeeInfo.EmployeeId = item.EmployeeId; insuranceEmployeeInfo.FName = item.FName; insuranceEmployeeInfo.LName = item.LName; insuranceEmployeeInfo.FatherName = item.FatherName; insuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; insuranceEmployeeInfo.NationalCode = item.NationalCode; insuranceEmployeeInfo.IdNumber = item.IdNumber; insuranceEmployeeInfo.Gender = item.Gender; insuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; insuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); insuranceEmployeeInfo.DateOfIssueGr = item.DateOfIssue.ToGeorgianDateTime(); _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); } } } else { return operation.Failed(" لیست پرسنل در کارگاه و تاریخ انتخاب شده خالی است "); } #endregion string startMonthCurrent = command.Year + "/" + command.Month + "/01"; string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); command.StartDate = startMonthCurrent.ToGeorgianDateTime(); command.EndDate = endMonthCurrent.ToGeorgianDateTime(); #region InsuranceList operation = _insuranceListRepositpry.CreateInsuranceList(command); #endregion return operation; } } public OperationResult Edit(EditInsuranceList command) { var operation = new OperationResult(); if (command.WorkshopId == 0) { return operation.Failed(" انتخاب کارگاه اجباری می باشد "); } if (command.Month == "0") { return operation.Failed(" انتخاب ماه اجباری می باشد "); } if (command.Year == "0") { return operation.Failed("انتخاب سال اجباری می باشد "); } else if (_insuranceListRepositpry.Exists(x => x.id != command.Id && x.WorkshopId == command.WorkshopId && x.Month == command.Month && x.Year == command.Year)) { return operation.Failed(" لیست بیمه برای کارگاه، سال و ماه انتخاب شده قبلا ایجاد شده است "); } else { #region EmployeeDetailsForInsurance if (command.EmployeeDetailsForInsuranceList != null && command.EmployeeDetailsForInsuranceList.Count > 0) { foreach (var item in command.EmployeeDetailsForInsuranceList) { if (item.InsuranceEmployeeInformationId == 0) { var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); createInsuranceEmployeeInfo.EmployeeId = item.EmployeeId; createInsuranceEmployeeInfo.FName = item.FName; createInsuranceEmployeeInfo.LName = item.LName; createInsuranceEmployeeInfo.FatherName = item.FatherName; createInsuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; createInsuranceEmployeeInfo.NationalCode = item.NationalCode; createInsuranceEmployeeInfo.IdNumber = item.IdNumber; createInsuranceEmployeeInfo.Gender = item.Gender; createInsuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; createInsuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); createInsuranceEmployeeInfo.DateOfIssueGr = !string.IsNullOrEmpty(item.DateOfIssue) ? item.DateOfIssue.ToGeorgianDateTime() : "1300/10/11".ToGeorgianDateTime(); _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); } else { var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); insuranceEmployeeInfo.Id = item.InsuranceEmployeeInformationId; insuranceEmployeeInfo.EmployeeId = item.EmployeeId; insuranceEmployeeInfo.FName = item.FName; insuranceEmployeeInfo.LName = item.LName; insuranceEmployeeInfo.FatherName = item.FatherName; insuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; insuranceEmployeeInfo.NationalCode = item.NationalCode; insuranceEmployeeInfo.IdNumber = item.IdNumber; insuranceEmployeeInfo.Gender = item.Gender; insuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; insuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); insuranceEmployeeInfo.DateOfIssueGr = !string.IsNullOrEmpty(item.DateOfIssue) ? item.DateOfIssue.ToGeorgianDateTime() : "1300/10/11".ToGeorgianDateTime(); ; _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); } } } else { return operation.Failed(" لیست پرسنل در کارگاه و تاریخ انتخاب شده خالی است "); } #endregion string startMonthCurrent = command.Year + "/" + command.Month + "/01"; string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); command.StartDate = startMonthCurrent.ToGeorgianDateTime(); command.EndDate = endMonthCurrent.ToGeorgianDateTime(); #region InsuranceList operation = _insuranceListRepositpry.EditInsuranceList(command); #endregion if (command.InsuranceWorkshopInfo != null) { var insuranceWorkshopInfoObj = _insuranceWorkshopInfoRepository.Get(command.InsuranceWorkshopInfo.InsuranceWorkshopInfoId); insuranceWorkshopInfoObj.Edit(command.InsuranceWorkshopInfo.WorkshopName, command.InsuranceWorkshopInfo.InsuranceCode, command.InsuranceWorkshopInfo.AgreementNumber, command.InsuranceWorkshopInfo.EmployerName, command.InsuranceWorkshopInfo.Address, command.InsuranceWorkshopInfo.ListNumber); _insuranceWorkshopInfoRepository.SaveChanges(); } return operation; } } public EditInsuranceList GetDetails(long id) { var insuranceListDetails = _insuranceListRepositpry.GetDetails(id); string startMonthCurrent = insuranceListDetails.Year + "/" + insuranceListDetails.Month + "/01"; string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); var year = Convert.ToInt32(insuranceListDetails.Year); var month = Convert.ToInt32(insuranceListDetails.Month); var day = 1; var persianCurrentStartDate = new PersianDateTime(year, month, day); var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); var model = new YearlySalarySearchModel(); model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); model.year = insuranceListDetails.Year; var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); var yearlysalaryItem = new YearlysalaryItemViewModel(); var housingAllowance = new YearlysalaryItemViewModel(); var consumableItems = new YearlysalaryItemViewModel(); if (yearSalaryObj != null) { yearlysalaryItem = _yearlySalaryItemApplication .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "مزد روزانه"); housingAllowance = _yearlySalaryItemApplication .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "کمک هزینه مسکن"); consumableItems = _yearlySalaryItemApplication .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "کمک هزینه اقلام"); } foreach (var item in insuranceListDetails.EmployeeDetailsForInsuranceList) { item.IncludeStatus = _leftWorkInsuranceApplication.GetLeftPersonelByWorkshopIdAndEmployeeId(insuranceListDetails.WorkshopId, item.EmployeeId).IncludeStatus; if (!string.IsNullOrEmpty(item.LeftWorkDate)) { var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); if (persianLeftDateUser <= persianCurrentEndDate) item.HasLeftWorkInMonth = true; else item.HasLeftWorkInMonth = false; } else { item.HasLeftWorkInMonth = false; } var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); if (persianStartDateUser < persianCurrentStartDate) item.HasStartWorkInMonth = false; else item.HasStartWorkInMonth = true; item.StartMonthCurrent = startMonthCurrent; item.DailyWageStr = item.DailyWage.ToMoney(); item.HousingAllowance = housingAllowance.ItemValue; item.ConsumableItems = consumableItems.ItemValue; item.EndMonthCurrentDay = dayMonthCurrent; } insuranceListDetails.EmployeeDetailsForInsuranceList = insuranceListDetails.EmployeeDetailsForInsuranceList.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) .ThenBy(x => x.LName).ToList(); insuranceListDetails.AllInsuredShare = insuranceListDetails.InsuredShare + insuranceListDetails.EmployerShare + insuranceListDetails.UnEmploymentInsurance; insuranceListDetails.LeftWorkEmployees = _leftWorkInsuranceRepository.GetEmployeesWithContractExitOnly(insuranceListDetails.WorkshopId); return insuranceListDetails; } public List Search(InsuranceListSearchModel searchModel) { return _insuranceListRepositpry.OptimizedSearch(searchModel); //var result = _insuranceListRepositpry.Search(searchModel); //result = result.Select(x => new InsuranceListViewModel() //{ // Id = x.Id, // Year = x.Year, // Month = x.Month.GetMonthByNumber(), // MonthNumber = x.MonthNumber, // WorkShopCode = x.WorkShopCode, // WorkShopName = x.WorkShopName, // WorkShopId = x.WorkShopId, // TypeOfInsuranceSend = x.TypeOfInsuranceSend, // FixedSalary = x.FixedSalary, // StrFixedSalary = x.StrFixedSalary, // EmployerName = x.EmployerName, // Branch = x.Branch, // City = x.City, // ConfirmSentlist = x.ConfirmSentlist, // EmployerId = x.EmployerId, // IsBlockCantracingParty = _contractingPartyApp.IsBlockByEmployerId(x.EmployerId), //}).ToList(); //return result; } /// /// محاسبه جدول پرسنل در مودال ایجاد لیست بیمه /// /// /// public MainEmployeeDetailsViewModel SearchEmployeeForCreateInsuranceList(EmployeeForCreateInsuranceListSearchModel searchModel) { var watch = new Stopwatch(); var result = new MainEmployeeDetailsViewModel(); var workshopId = searchModel.WorkshopIds.FirstOrDefault(); var workshop = _workShopRepository.GetDetails(workshopId); //var isBolock = _contractingPartyApp.IsBlockByEmployerId(employerId); 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))) { var startMonthFa = $"{searchModel.Year}/{searchModel.Month.PadLeft(2, '0')}/01"; DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); DateTime endDateGr = startMonthFa.FindeEndOfMonth() .ToGeorgianDateTime(); int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2)); //مقادیر سالانه این تاریخ var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDateGr, endDateGr, searchModel.Year); // دریافت اطلاعات هویتی و شروع و ترک کار کارکنان var employeesInfoAndLeftWorks = _leftWorkInsuranceApplication.GetEmployeeInsuranceLeftWorksAndInformation(workshopId, startDateGr, endDateGr); var employeeInsurancDataPreviusList = _insuranceListRepositpry.GetEmployeeInsuranceDataAmonthAgo(startDateGr, workshopId); watch.Start(); var computeResult = employeesInfoAndLeftWorks.Select(employee => { var dateOfBirth = employee.DateOfBirthGr.ToFarsi(); var dateOfIssue = employee.DateOfIssueGr.ToFarsi(); var leftDate = employee.LeftWorkDateGr?.AddDays(-1) ?? new DateTime(); bool isManager = employee.JobId is 10 or 16 or 17 or 18 or 3498; //آیا در کارگاه تیک محاسبه اضافه کار یا حق اولاد زده شده است؟ bool hasWorkshopOverTimeOrFamilyAllowance = workshop.InsuranceCheckoutFamilyAllowance || workshop.InsuranceCheckoutOvertime; //آیا پرسنل فیش حقوق دارد //این مورد زمانی چک می شود که تیک محاسبه در کارگاه زده شده باشد // در غیر اینصورت بصورت پیشفرض دارای فیش حقوق در نظر گرفته می شود bool employeeHasCheckout = true; double familyAllowance = 0; double overTimePay = 0; double rotatingShift = 0; double nightWork = 0; double fridayWork = 0; double yearsPay = 0; if (hasWorkshopOverTimeOrFamilyAllowance && (leftDate >= startDateGr || employee.LeftWorkDateGr == null)) { var checkout = _checkoutRepository.HasCheckout(workshopId, employee.EmployeeId, searchModel.Year, searchModel.Month); if (checkout.hasChekout) { familyAllowance = checkout.FamilyAlloance; overTimePay = checkout.OverTimePay; rotatingShift = checkout.RotatingShift; nightWork = checkout.Nightwork; fridayWork = checkout.Fridaywork; yearsPay = checkout.YraesPay; } else { //چون کارفرما فیش حقوقی ندارد //ولی در لیست بیمه حضور دارد //برای جلوگیری از هشدار فرانت کارفرما را داری فیش حقوقی فرض میکنیم employeeHasCheckout = isManager == false ? false : true; } } var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employee.StartWorkDateGr, leftDate, startDateGr, endDateGr, employee.EmployeeId); var leftWorkFa = workingDays.hasLeftWorkInMonth ? employee.LeftWorkDateGr.ToFarsi() : ""; var startWorkFa = employee.StartWorkDateGr.ToFarsi(); //به دست آوردن دستمزد روزانه با توجه به اینکه کارگاه مشاغل مقطوع است یا خیر double dailyWage = 0; if (searchModel.FixedSalary) { var res = GetDailyWageFixedSalary(searchModel.Year, workshopId, employee.EmployeeId, startDateGr, endDateGr, employee.JobId, searchModel.Population, searchModel.InsuranceJobId); dailyWage = res ?? 0; } else { var res = ComputeDailyWage(yearlysaleries.DayliWage, employee.EmployeeId, workshopId, searchModel.Year); dailyWage = res; } //بدست آوردن پایه سنوات var baseYears = _insuranceListRepositpry.GetEmployeeInsuranceBaseYear(employee.EmployeeId, workshopId, workingDays.countWorkingDays, startDateGr, endDateGr, workingDays.startWork, workingDays.endWork, workingDays.hasLeftWorkInMonth); //آیا کارفرما یا مدیر عامل است؟ baseYears.baseYear = isManager ? 0 : baseYears.baseYear; Console.WriteLine(employee.JobId + " - " + baseYears.baseYear); //جمع مزد روزانه و پایه سنوات var dailyWagePlusBaseYears = dailyWage + baseYears.baseYear; //دستمزد ماهانه با محاسبه پایه سنوات var monthlySalary = GetRoundValue(dailyWagePlusBaseYears * workingDays.countWorkingDays); //حق تاهل var marriedAllowance = employee.MaritalStatus == "متاهل" && !isManager ? yearlysaleries.MarriedAllowance : 0; //محاسبه مزایای ماهانه var monthlyBenefits = GetMonthlyBenefits(endOfMonth, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marriedAllowance, workingDays.countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, employee.JobId, employee.EmployeeId, employee.IncludeStatus); //if (employee.EmployeeId is 7999)// سید عباس خوشکلام سلیمان // monthlyBenefits = 80869389; //if (employee.EmployeeId is 43787)// شهرام براهیمی سیقلان // monthlyBenefits = 54748472; if (workshop.InsuranceCheckoutOvertime && employeeHasCheckout && !isManager) { monthlyBenefits = GetRoundValue(monthlyBenefits += overTimePay); } //سرای ملک // نرجس خالی // 39692467 if (employee.EmployeeId == 45280) monthlyBenefits += 39692467; var marriedAllowanceCompute = MarriedAllowance(employee.MaritalStatus, employee.JobId, employee.IncludeStatus, workingDays.countWorkingDays, yearlysaleries.MarriedAllowance, endOfMonth); //محاسبه جمع مزایای مشمول و دستمزد ماهانه var benefitsIncludedContinuous = monthlyBenefits + monthlySalary; //benefitsIncludedContinuous = employee.JobId != 16 ? benefitsIncludedContinuous : 0; //محاسبه حق بیمه سهم بیمه شده var insuranceShare = (benefitsIncludedContinuous * 7) / 100; //محاسبه حق بیمه سهم کارفرما var employerShare = (benefitsIncludedContinuous * 20) / 100; // محاسبه بیمه بیکاری var unEmploymentInsurance = (benefitsIncludedContinuous * 3) / 100; var employeeListData = employeeInsurancDataPreviusList .FirstOrDefault(e => e.EmployeeId == employee.EmployeeId); //مزیای عیر مشمول لیست قبل //var benefitsIncludedNonContinuous = // employeeListData != null ? employeeListData.BenefitsIncludedNonContinuous : 0; double benefitsIncludedNonContinuous = 0; if (workshop.InsuranceCheckoutFamilyAllowance && employeeHasCheckout && !isManager) { double addOptionsfromCheckout = familyAllowance; //استثنا کارگته بازرگانی سیم آهن مهراکو //if (workshopId == 666) //{ // addOptionsfromCheckout = familyAllowance + rotatingShift + nightWork + fridayWork + yearsPay; //} benefitsIncludedNonContinuous = GetRoundValue(benefitsIncludedNonContinuous + addOptionsfromCheckout); } var includedAndNotIncluded = benefitsIncludedContinuous + benefitsIncludedNonContinuous; return new EmployeeDetailsForInsuranceListViewModel { #region EmployeeInfo EmployeeHasCheckout = employeeHasCheckout, 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, // آیا وضعیت تاهل پرسنل ست شده است IsMaritalStatusSet = !string.IsNullOrWhiteSpace(employee.MaritalStatus), MaritalStatus = employee.MaritalStatus, StartMonthCurrent = startMonthFa, WorkingDays = workingDays.countWorkingDays, StartWorkDate = startWorkFa, StartWorkDateGr = employee.StartWorkDateGr, LeftWorkDate = leftWorkFa, LeftWorkDateGr = workingDays.hasLeftWorkInMonth ? employee.LeftWorkDateGr : null, JobId = employee.JobId, JobName = employee.JobName, JobCode = employee.JobCode, HasStartWorkInMonth = workingDays.hasStartWorkInMonth, HasLeftWorkInMonth = workingDays.hasLeftWorkInMonth, #endregion #region Compute //مشمول مزایا بودن IncludeStatus = employee.IncludeStatus, //دستمزد روزانه DailyWage = GetRoundValue(dailyWage), DailyWageStr = dailyWage.ToMoney(), HasConfilictJobs = dailyWage == 0, //پایه سنوات BaseYears = baseYears.baseYear, //مجموع مزد روزانه و پایه سنوات DailyWagePlusBaseYears = dailyWagePlusBaseYears, //حق تاهل MarriedAllowance = marriedAllowanceCompute, //دستمزد ماهانه MonthlySalary = monthlySalary, //مزایای ماهانه MonthlyBenefits = monthlyBenefits, //جمع مزایای مشمول و دستمزد ماهانه BenefitsIncludedContinuous = benefitsIncludedContinuous, //مزایای غیر مشمول * BenefitsIncludedNonContinuous = benefitsIncludedNonContinuous, // جمع کل دستمزد و مزایای ماهانه مشمول و غیر مشمول * IncludedAndNotIncluded = includedAndNotIncluded, //حق بیمه سهم بیمه شده InsuranceShare = GetRoundValue(insuranceShare), //حق بیمه سهم کارفرما EmployerShare = GetRoundValue(employerShare), //بیمه بیکاری UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance), //کمک هزینه مسکن HousingAllowance = yearlysaleries.HousingAllowance, //کمک هزینه اقلام ConsumableItems = yearlysaleries.ConsumableItems, EndMonthCurrentDay = endOfMonth, YearlySalaryItem = yearlysaleries.DayliWage, MonthlyBaseYearsStr = "0", MonthlyBaseYears = 0, OverTimePay = overTimePay, FamilyAllowance = familyAllowance #endregion }; }).ToList(); Console.WriteLine("New Compute : " + watch.Elapsed); watch.Stop(); watch.Start(); #region Old_heydari //List list = new List(); //var leftWorkInsuranceViewModel = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModel); ////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; //foreach (var item in leftWorkInsuranceViewModel) //{ // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); // var employeeDetailsForInsuranceObj = new EmployeeDetailsForInsuranceListViewModel(); // employeeDetailsForInsuranceObj.HasConfilictJobs = false; // // آیا وضعیت تاهل پرسنل ست شده است // employeeDetailsForInsuranceObj.IsMaritalStatusSet = // !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); // //دزیافت اطلاعات هویتی پرسنل // //در صورت نداشن دیتا از جدول پرسنل پر می شود // #region PersonnelInfo // if (_insuranceEmployeeInfoRepository.Exists(x => x.EmployeeId == item.EmployeeId)) // { // var employeeInfoObject = _insuranceEmployeeInfoApplication.GetDetailsByEmployeeId(item.EmployeeId); // employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = employeeInfoObject.Id; // employeeDetailsForInsuranceObj.EmployeeId = employeeInfoObject.EmployeeId; // employeeDetailsForInsuranceObj.FName = employeeInfoObject.FName; // employeeDetailsForInsuranceObj.LName = employeeInfoObject.LName; // employeeDetailsForInsuranceObj.FatherName = employeeInfoObject.FatherName; // employeeDetailsForInsuranceObj.DateOfBirth = employeeInfoObject.DateOfBirth; // employeeDetailsForInsuranceObj.DateOfIssue = employeeInfoObject.DateOfIssue; // employeeDetailsForInsuranceObj.DateOfBirthGr = employeeInfoObject.DateOfBirthGr; // employeeDetailsForInsuranceObj.DateOfIssueGr = employeeInfoObject.DateOfIssueGr; // employeeDetailsForInsuranceObj.PlaceOfIssue = employeeInfoObject.PlaceOfIssue; // employeeDetailsForInsuranceObj.IdNumber = employeeInfoObject.IdNumber; // employeeDetailsForInsuranceObj.Gender = employeeInfoObject.Gender; // //از جدول پرسنل پر می شود // employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; //employeeInfoObject.NationalCode; // employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; // employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; //employeeInfoObject.InsuranceCode; // } // else // { // // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); // employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = 0; // //employeeDetailsForInsuranceObj.EmployeeInsurancListDataId = 0; // employeeDetailsForInsuranceObj.EmployeeId = employeeObject.Id; // employeeDetailsForInsuranceObj.FName = employeeObject.FName; // employeeDetailsForInsuranceObj.LName = employeeObject.LName; // employeeDetailsForInsuranceObj.FatherName = employeeObject.FatherName; // employeeDetailsForInsuranceObj.DateOfBirth = (employeeObject.DateOfBirth == "1300/10/11" ? "" : employeeObject.DateOfBirth); // employeeDetailsForInsuranceObj.DateOfIssue = employeeObject.DateOfIssue; // employeeDetailsForInsuranceObj.PlaceOfIssue = employeeObject.PlaceOfIssue; // employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; // employeeDetailsForInsuranceObj.IdNumber = employeeObject.IdNumber; // employeeDetailsForInsuranceObj.Gender = employeeObject.Gender; // employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; // employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; // } // #endregion // //روزهای کارکرد پرسنل // #region ComputingWorkingDays // int startWork = 0; // int endWork = 0; // var year = Convert.ToInt32(searchModel.Year); // var month = Convert.ToInt32(searchModel.Month); // var day = 1; // var persianCurrentStartDate = new PersianDateTime(year, month, day); // var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); // var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); // //آخرین روز ماه جاری // var endMonthCurrentDay = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); // var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); // var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); // var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); // var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); // if (persianStartDateUser < persianCurrentStartDate) // employeeDetailsForInsuranceObj.HasStartWorkInMonth = false; // else // employeeDetailsForInsuranceObj.HasStartWorkInMonth = true; // //اگر شروع به کار کاربر از ابتدای ماه جاری کمتر باشد // if (persianStartDateUser <= persianCurrentStartDate) // { // startWork = 1; // } // else // { // startWork = dayStartDateUser; // } // if (!string.IsNullOrEmpty(item.LeftWorkDate)) // { // var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); // var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); // var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); // var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); // var persianEndDateUser = persianLeftDateUser.AddDays(-1); // var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); // //if (persianLeftDateUser <= persianCurrentEndDate) // // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; // //else // // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; // //ترک کارش در ماه و سال جاری بود نمایش داده شود // if (!item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) // { // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; // item.LeftWorkDate = string.Empty; // item.LeftWorkDateGr = null; // } // else // { // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; // } // //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد // if (persianEndDateUser >= persianCurrentEndDate) // { // endWork = endMonthCurrentDay; // } // else // { // endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); // } // } // else // { // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; // endWork = endMonthCurrentDay; // } // int countWorkingDays = 0; // for (int i = startWork; i <= endWork; i++) // { // countWorkingDays = countWorkingDays + 1; // } // //farokhiChanges // //روزهای کارکرد پرسنل با آی دی های زیر دستی تعریف شد // switch (item.EmployeeId) // { // //case 3812://ثابت- کسری حاجی پور // // countWorkingDays = 15; // // break; // case 40463://ثابت // countWorkingDays = 10; // break; // case 40469://ثابت // countWorkingDays = 7; // break; // case 9950://ثابت // countWorkingDays = 15; // break; // case 9640://ثابت // countWorkingDays = 15; // break; // case 40998://ثابت // countWorkingDays = 15; // break; // case 6219://ثابت // countWorkingDays = 15; // break; // //case 7897://ثابت // // countWorkingDays = 15; // break; // } // #endregion // employeeDetailsForInsuranceObj.IncludeStatus = item.IncludeStatus; // #region InsuranceJob // double dailyWage = employeeDetailsForInsuranceObj.DailyWage; // if (searchModel.FixedSalary) // { // 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 (yearlysaleries != null) // { // if (!searchModel.FixedSalary) // { // //dailyWage= yearlysalaryItem.ItemValue; // dailyWage = ComputeDailyWage(yearlysaleries.DayliWage, item.EmployeeId, workshopId, searchModel.Year); // //(double basic, int totalYears) basicResult = BasicYear(item.EmployeeId, workshopId, startDate); // //var basic = basicResult.basic; // //if (basicResult.totalYears > 0) // //{ // // monthlybaseYear = GetMonthlyBaseYear(basicResult.basic, countWorkingDays); // //} // } // employeeDetailsForInsuranceObj.DailyWage = GetRoundValue(dailyWage); // employeeDetailsForInsuranceObj.BaseYears = 0; // employeeDetailsForInsuranceObj.DailyWageStr = employeeDetailsForInsuranceObj.DailyWage.ToMoney(); // employeeDetailsForInsuranceObj.DailyWagePlusBaseYears = 0; // employeeDetailsForInsuranceObj.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); // employeeDetailsForInsuranceObj.HousingAllowance = yearlysaleries.HousingAllowance; // employeeDetailsForInsuranceObj.ConsumableItems = yearlysaleries.ConsumableItems; // employeeDetailsForInsuranceObj.EndMonthCurrentDay = endMonthCurrentDay; // employeeDetailsForInsuranceObj.YearlySalaryItem = yearlysaleries.DayliWage; // employeeDetailsForInsuranceObj.MonthlyBaseYearsStr = monthlybaseYear.ToMoney(); // employeeDetailsForInsuranceObj.MarriedAllowance = 0; // if (item.IncludeStatus) // { // var marital = employeeObject.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0; // employeeDetailsForInsuranceObj.MonthlyBenefits = GetMonthlyBenefits(endMonthCurrentDay, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId); // } // else // { // employeeDetailsForInsuranceObj.MonthlyBenefits = 0; // } // if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت // { // employeeDetailsForInsuranceObj.MonthlyBenefits = 0; // } // //farokhiChanges // if (item.EmployeeId == 42783) // employeeDetailsForInsuranceObj.MonthlyBenefits = 53082855; // employeeDetailsForInsuranceObj.BenefitsIncludedContinuous = employeeDetailsForInsuranceObj.MonthlyBenefits + employeeDetailsForInsuranceObj.MonthlySalary; // //حق بیمه سهم بیمه شده // var insuranceShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 7) / 100; // employeeDetailsForInsuranceObj.InsuranceShare = GetRoundValue(insuranceShare); //Math.Round(insuranceShare, MidpointRounding.ToPositiveInfinity); // //حق بیمه سهم کارفرما // var employerShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 20) / 100; // employeeDetailsForInsuranceObj.EmployerShare = GetRoundValue(employerShare); //Math.Round(employerShare, MidpointRounding.ToPositiveInfinity); // //if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId==10)//کمک دولت // //{employeeDetailsForInsuranceObj.InsuranceShare = 0;} // var unEmploymentInsurance = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 3) / 100; // employeeDetailsForInsuranceObj.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); // employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous; // employeeDetailsForInsuranceObj.IncludedAndNotIncluded = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous + employeeDetailsForInsuranceObj.BenefitsIncludedContinuous; // } // employeeDetailsForInsuranceObj.StartMonthCurrent = startMonthCurrent; // employeeDetailsForInsuranceObj.WorkingDays = countWorkingDays; // employeeDetailsForInsuranceObj.StartWorkDate = item.StartWorkDate; // employeeDetailsForInsuranceObj.LeftWorkDate = item.LeftWorkDate; // employeeDetailsForInsuranceObj.JobId = item.JobId; // employeeDetailsForInsuranceObj.JobName = item.JobName; // employeeDetailsForInsuranceObj.JobCode = item.JobCode; // if (!string.IsNullOrWhiteSpace(item.LeftWorkDate)) // employeeDetailsForInsuranceObj.LeftWorkDateGr = item.LeftWorkDateGr; // employeeDetailsForInsuranceObj.StartWorkDateGr = item.StartWorkDateGr; // //farokhiChanges // if (item.EmployeeId == 42783) // employeeDetailsForInsuranceObj.MonthlyBenefits = 53082855; // list.Add(employeeDetailsForInsuranceObj); //} //result.EmployeeDetailsForInsuranceList = list.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) // .ThenBy(x => x.LName).ToList(); #endregion result.EmployeeDetailsForInsuranceList = computeResult.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) .ThenBy(x => x.LName).ToList(); Console.WriteLine("ToList compute : " + watch.Elapsed); result.IsExist = false; result.IsBlock = isBolock; result.MaritalStatus = yearlysaleries.MarriedAllowance; } else { result.IsExist = true; result.IsBlock = isBolock; } return result; } public double MarriedAllowance(string maritalStatus, long jobId, bool includedStatus, int countWorkingDays, double marriedAlowance, int endMonthCurrentDay) { bool isManager = jobId is 10 or 16 or 17 or 18 or 3498; if (isManager)//اگر مدیر عامل بود return 0; if (maritalStatus != "متاهل")//اگر مجرد بود return 0; if (countWorkingDays == endMonthCurrentDay) return (marriedAlowance); return endMonthCurrentDay switch { 29 => GetRoundValue((marriedAlowance / 29) * countWorkingDays), 30 => GetRoundValue((marriedAlowance / 30) * countWorkingDays), 31 => GetRoundValue((marriedAlowance / 31) * countWorkingDays), _ => marriedAlowance }; } public OperationResult CreateEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command) { var result = new OperationResult(); try { //_transactionManager.BeginTransaction(); var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); createInsuranceEmployeeInfo.EmployeeId = command.EmployeeId; createInsuranceEmployeeInfo.FName = command.FName; createInsuranceEmployeeInfo.LName = command.LName; createInsuranceEmployeeInfo.FatherName = command.FatherName; createInsuranceEmployeeInfo.PlaceOfIssue = command.PlaceOfIssue; createInsuranceEmployeeInfo.NationalCode = command.NationalCode; createInsuranceEmployeeInfo.IdNumber = command.IdNumber; createInsuranceEmployeeInfo.Gender = command.Gender; createInsuranceEmployeeInfo.InsuranceCode = command.InsuranceCode; createInsuranceEmployeeInfo.DateOfBirthGr = command.DateOfBirth.ToGeorgianDateTime(); createInsuranceEmployeeInfo.DateOfIssueGr = command.DateOfIssue.ToGeorgianDateTime(); result = _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); //var createEmployeeInsuranceListData = new CreateEmployeeInsurancListData(); //createEmployeeInsuranceListData.InsuranceListId = command.InsuranceListId; //createEmployeeInsuranceListData.EmployeeId = command.EmployeeId; ////روزهای کارکرد پرسنل //createEmployeeInsuranceListData.WorkingDays = command.WorkingDays; //// دستمزد روزانه //createEmployeeInsuranceListData.DailyWage = command.DailyWage; ////دستمزد ماهانه //createEmployeeInsuranceListData.MonthlySalary = command.MonthlySalary; ////مزایای ماهانه //createEmployeeInsuranceListData.MonthlyBenefits = command.MonthlyBenefits; ////دستمزد و مزایای ماهانه مشمول //createEmployeeInsuranceListData.MonthlyBenefitsIncluded = command.MonthlyBenefitsIncluded; //// مزایای مشمول مستمر //createEmployeeInsuranceListData.BenefitsIncludedContinuous = command.BenefitsIncludedContinuous; ////مزایای مشمول غیر مستمر //createEmployeeInsuranceListData.BenefitsIncludedNonContinuous = command.BenefitsIncludedNonContinuous; ////سهم بیمه حق کارگر //createEmployeeInsuranceListData.InsuranceShare = command.InsuranceShare; //// تاریخ شروع به کار //createEmployeeInsuranceListData.StartWorkDate = command.StartWorkDate.ToGeorgian(); ////تاریخ ترک کار //if() //createEmployeeInsuranceListData.LeftWorkDate = command.LeftWorkDate.ToGeorgian(); //// آی دی شغل //createEmployeeInsuranceListData.JobId = command.JobId; //result = _employeeInsurancListDataApplication.Create(createEmployeeInsuranceListData); // _transactionManager.CommitTransaction(); } catch (Exception ex) { result.IsSuccedded = false; result.Message = "ثبت اطلاعات با خطا مواجه شد"; // _transactionManager.RollbackTransaction(); } return result; } public OperationResult EditEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command) { var result = new OperationResult(); try { //_transactionManager.BeginTransaction(); var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); insuranceEmployeeInfo.Id = command.InsuranceEmployeeInformationId; insuranceEmployeeInfo.EmployeeId = command.EmployeeId; insuranceEmployeeInfo.FName = command.FName; insuranceEmployeeInfo.LName = command.LName; insuranceEmployeeInfo.FatherName = command.FatherName; insuranceEmployeeInfo.PlaceOfIssue = command.PlaceOfIssue; insuranceEmployeeInfo.NationalCode = command.NationalCode; insuranceEmployeeInfo.IdNumber = command.IdNumber; insuranceEmployeeInfo.Gender = command.Gender; insuranceEmployeeInfo.InsuranceCode = command.InsuranceCode; insuranceEmployeeInfo.DateOfBirthGr = command.DateOfBirth.ToGeorgianDateTime(); insuranceEmployeeInfo.DateOfIssueGr = command.DateOfIssue.ToGeorgianDateTime(); result = _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); // var createEmployeeInsuranceListData = new EditEmployeeInsurancListData(); // createEmployeeInsuranceListData.InsuranceListId = command.InsuranceListId; //// createEmployeeInsuranceListData.Id = command.EmployeeInsurancListDataId; // createEmployeeInsuranceListData.EmployeeId = command.EmployeeId; // //روزهای کارکرد پرسنل // createEmployeeInsuranceListData.WorkingDays = command.WorkingDays; // // دستمزد روزانه // createEmployeeInsuranceListData.DailyWage = command.DailyWage; // //دستمزد ماهانه // createEmployeeInsuranceListData.MonthlySalary = command.MonthlySalary; // //مزایای ماهانه // createEmployeeInsuranceListData.MonthlyBenefits = command.MonthlyBenefits; // //دستمزد و مزایای ماهانه مشمول // createEmployeeInsuranceListData.MonthlyBenefitsIncluded = command.MonthlyBenefitsIncluded; // // مزایای مشمول مستمر // createEmployeeInsuranceListData.BenefitsIncludedContinuous = command.BenefitsIncludedContinuous; // //مزایای مشمول غیر مستمر // createEmployeeInsuranceListData.BenefitsIncludedNonContinuous = command.BenefitsIncludedNonContinuous; // //سهم بیمه حق کارگر // createEmployeeInsuranceListData.InsuranceShare = command.InsuranceShare; // // تاریخ شروع به کار // createEmployeeInsuranceListData.StartWorkDate = command.StartWorkDate.ToGeorgian(); // //تاریخ ترک کار // createEmployeeInsuranceListData.LeftWorkDate = command.LeftWorkDate.ToGeorgian(); // // آی دی شغل // createEmployeeInsuranceListData.JobId = command.JobId; // result = _employeeInsurancListDataApplication.Edit(createEmployeeInsuranceListData); // _transactionManager.CommitTransaction(); } catch (Exception ex) { result.IsSuccedded = false; result.Message = "ثبت اطلاعات با خطا مواجه شد"; // _transactionManager.RollbackTransaction(); } return result; } public OperationResult Remove(long id) { return _insuranceListRepositpry.Remove(id); } public EditInsuranceList GetDetailsForEdit(long id) { var insuranceListDetails = _insuranceListRepositpry.GetDetailsForEdit(id); //string startMonthCurrent = insuranceListDetails.Year + "/" + insuranceListDetails.Month + "/01"; //string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); //var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); //var year = Convert.ToInt32(insuranceListDetails.Year); //var month = Convert.ToInt32(insuranceListDetails.Month); //var day = 1; //var persianCurrentStartDate = new PersianDateTime(year, month, day); //var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); //var model = new YearlySalarySearchModel(); //model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); //model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); //model.year = insuranceListDetails.Year; //var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); //var yearlysalaryItem = new YearlysalaryItemViewModel(); //var housingAllowance = new YearlysalaryItemViewModel(); //var consumableItems = 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(); //} return insuranceListDetails; } public double GetRoundValue(double value) { string strValue = value.ToString(); if (strValue.IndexOf('.') > -1) { string a = strValue.Substring(strValue.IndexOf('.') + 1, 1); if (int.Parse(a) > 5) { return (Math.Round(value, MidpointRounding.ToPositiveInfinity)); } else { return (Math.Round(value, MidpointRounding.ToNegativeInfinity)); } } return value; } //محاسبه پرسنل در جدول - DSKWOR EDIT public MainEmployeeDetailsViewModel SearchEmployeeListForEditByInsuranceListId(EmployeeForEditInsuranceListSearchModel searchModel) { var mainEmployeeDetailsViewModel = new MainEmployeeDetailsViewModel(); var mainEmployeeDetailsViewModel2 = new MainEmployeeDetailsViewModel(); var mainEmployeeDetailsViewModelForNewPersonel = new MainEmployeeDetailsViewModel(); List ids = searchModel.WorkshopIds.Where(x => x != searchModel.WorkshopId).ToList(); searchModel.Month = searchModel.Month.PadLeft(2, '0'); if (!_insuranceListRepositpry.Exists(x => x.Year == searchModel.Year && x.Month == searchModel.Month && (ids != null && ids.Count > 0 && ids.Contains(x.WorkshopId)))) { mainEmployeeDetailsViewModel = _insuranceListRepositpry.SearchEmployeeListForEditByInsuranceListId(searchModel); var employeeForCreateInsurance = new EmployeeForCreateInsuranceListSearchModel(); employeeForCreateInsurance.Month = searchModel.Month; employeeForCreateInsurance.Year = searchModel.Year; employeeForCreateInsurance.WorkshopIds = ids; #region OtherWorkshop if (ids != null && ids.Count > 0)//اگر ورکشاپهای دیگر را انتخاب کرد { mainEmployeeDetailsViewModel2 = SearchEmployeeForCreateInsuranceList(employeeForCreateInsurance); } #endregion #region NewPersonel //اگر افراد جدیدی به لیست بیمه اضافه شوند. var searchModelForCreate = new EmployeeForCreateInsuranceListSearchModel(); searchModelForCreate.Month = searchModel.Month; searchModelForCreate.Year = searchModel.Year; searchModelForCreate.WorkshopIds = new List() { searchModel.WorkshopId }; var leftWorkInsuranceViewModelList = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModelForCreate); var newEmployeeId = leftWorkInsuranceViewModelList.Select(x => x.EmployeeId).ToList(); var oldEmployeeId = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Select(x => x.EmployeeId).ToList(); if (!newEmployeeId.SequenceEqual(oldEmployeeId)) { var employeeAddIds = new List(); var employeeRemoveIds = new List(); //var employeeAddIds = newEmployeeId.Except(oldEmployeeId).ToList(); //var employeeRemoveIds = newEmployeeId.Where(x => !oldEmployeeId.Any(z => z == x)).ToList(); foreach (var newitem in newEmployeeId) { if (!oldEmployeeId.Any(x => x == newitem)) { employeeAddIds.Add(newitem); } } foreach (var olditem in oldEmployeeId) { if (!newEmployeeId.Any(x => x == olditem)) { employeeRemoveIds.Add(olditem); } } if (employeeAddIds != null && employeeAddIds.Count > 0) { leftWorkInsuranceViewModelList = leftWorkInsuranceViewModelList.Where(x => employeeAddIds.Contains(x.EmployeeId)).ToList(); mainEmployeeDetailsViewModelForNewPersonel = GetEmployeeForInsuranceList(leftWorkInsuranceViewModelList, searchModel); if (mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList != null && mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList.Count > 0) { mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Union(mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList).ToList(); } } if (employeeRemoveIds != null && employeeRemoveIds.Count > 0) { mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel .EmployeeDetailsForInsuranceList.Where(x => !employeeRemoveIds.Contains(x.EmployeeId)) .ToList(); } } #endregion string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); var year = Convert.ToInt32(searchModel.Year); var month = Convert.ToInt32(searchModel.Month); var day = 1; var persianCurrentStartDate = new PersianDateTime(year, month, day); var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); var model = new YearlySalarySearchModel(); model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); model.year = searchModel.Year; var yearlysalaryItem = new YearlysalaryItemViewModel(); var housingAllowance = new YearlysalaryItemViewModel(); var consumableItems = new YearlysalaryItemViewModel(); var maritalStatus = new YearlysalaryItemViewModel(); foreach (var item in mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList) { var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); item.HasConfilictJobs = false; item.IncludeStatus = item.IncludeStatus; int startWork = 0; int endWork = 0; item.IsMaritalStatusSet = // آیا وضعیت تاهل پرسنل ست شده است !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); #region HasConfilictLeftWork bool hasConfilict = false; // // اگر شروع به کار و ترک کارش در جدول ترک کار تغییر کرده باشد if (item.HasConfilictLeftWork)//item.LeftWorkDate != item.StrLeftWorkDateNew || (item.StartWorkDate != item.StrStartWorkDateNew && !string.IsNullOrEmpty(item.StrStartWorkDateNew) ) ||(item.JobId!=item.JobIdNew && item.JobIdNew!=0)) { if (item.LeftWorkDate != item.StrLeftWorkDateNew) { item.LeftWorkDate = item.StrLeftWorkDateNew; item.LeftWorkDateGr = item.LeftWorkDateNew; } if (item.StartWorkDate != item.StrStartWorkDateNew && !string.IsNullOrEmpty(item.StrStartWorkDateNew)) { item.StartWorkDate = item.StrStartWorkDateNew; item.StartWorkDateGr = item.StartWorkDateNew; } if (item.JobId != item.JobIdNew && item.JobIdNew != 0) { item.JobId = item.JobIdNew; item.JobCode = item.JobCodeNew; item.JobName = item.JobNameNew; } item.IncludeStatus = item.IncludeStatusNew;//(item.IncludeStatus==item.IncludeStatusNew); hasConfilict = true; } #endregion var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); 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(); item.HousingAllowance = housingAllowance.ItemValue; item.ConsumableItems = consumableItems.ItemValue; //item.MarriedAllowance = maritalStatus.ItemValue; item.YearlySalaryItem = yearlysalaryItem.ItemValue; } //ترک کارش در ماه و سال جاری بود نمایش داده شود if (!string.IsNullOrEmpty(item.LeftWorkDate) && !item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) { item.LeftWorkDate = string.Empty; item.LeftWorkDateGr = null; } if (!string.IsNullOrEmpty(item.LeftWorkDate)) //&& item.LeftWorkDate.Substring(5, 2)==searchModel.Month && item.LeftWorkDate.Substring(0, 4) == searchModel.Year) { // item.HasLeftWorkInMonth = true; var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); var persianEndDateUser = persianLeftDateUser.AddDays(-1); var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); if (persianLeftDateUser <= persianCurrentEndDate) item.HasLeftWorkInMonth = true; else item.HasLeftWorkInMonth = false; //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد if (persianEndDateUser >= persianCurrentEndDate) { endWork = dayMonthCurrent; } else { endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); } } else { // item.HasLeftWorkInMonth = false; endWork = dayMonthCurrent; } var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); if (persianStartDateUser <= persianCurrentStartDate) { startWork = 1; } else { startWork = dayStartDateUser; } if (persianStartDateUser < persianCurrentStartDate) item.HasStartWorkInMonth = false; else item.HasStartWorkInMonth = true; if (hasConfilict) //اگر ترک کار شخص تغییر کرده بود، دوباره محاسبه شود { item.StartMonthCurrent = startMonthCurrent; item.HousingAllowance = housingAllowance.ItemValue; item.ConsumableItems = consumableItems.ItemValue; item.DailyWage = ComputeDailyWage(yearlysalaryItem.ItemValue, item.EmployeeId, searchModel.WorkshopId, searchModel.Year); item.DailyWageStr = item.DailyWage.ToMoney(); } else { item.DailyWageStr = item.DailyWage.ToMoney(); } item.EndMonthCurrentDay = dayMonthCurrent; if (hasConfilict || searchModel.FixedSalary || searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist") { #region InsuranceJob double dailyWage = item.DailyWage; if (searchModel.FixedSalary) { dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, searchModel.WorkshopId, item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); item.HasConfilictJobs = (dailyWage == 0 ? true : false); } #endregion if (hasConfilict) { int countWorkingDays = 0; for (int i = startWork; i <= endWork; i++) { countWorkingDays = countWorkingDays + 1; } item.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); item.WorkingDays = countWorkingDays; if (item.IncludeStatus) { var marital = employeeObject.MaritalStatus == "متاهل" ? maritalStatus.ItemValue : 0; item.MonthlyBenefits = GetMonthlyBenefits(dayMonthCurrent, consumableItems.ItemValue, housingAllowance.ItemValue, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId, item.IncludeStatus); } else { item.MonthlyBenefits = 0; } } if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت { item.MonthlyBenefits = 0; } item.BenefitsIncludedContinuous = item.MonthlyBenefits + item.MonthlySalary; var insuranceShare = (item.BenefitsIncludedContinuous * 7) / 100; item.InsuranceShare = GetRoundValue(insuranceShare); //} var employerShare = (item.BenefitsIncludedContinuous * 20) / 100; item.EmployerShare = GetRoundValue(employerShare); var unEmploymentInsurance = (item.BenefitsIncludedContinuous * 3) / 100; item.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); // item.BenefitsIncludedNonContinuous = item.BenefitsIncludedContinuous; item.IncludedAndNotIncluded = item.BenefitsIncludedContinuous + item.BenefitsIncludedNonContinuous; } } if (mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList != null && mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList.Count > 0) mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Union(mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList).OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth).ThenBy(x => x.LName).ToList(); else mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth).ThenBy(x => x.LName).ToList(); mainEmployeeDetailsViewModel.IsExist = false; mainEmployeeDetailsViewModel.MaritalStatus = maritalStatus.ItemValue; } else { mainEmployeeDetailsViewModel.IsExist = true; } return mainEmployeeDetailsViewModel; } public MainEmployeeDetailsViewModel GetEmployeeListForEditByInsuranceListId( EmployeeForEditInsuranceListSearchModel searchModel) { var result = new MainEmployeeDetailsViewModel(); var workshopId = searchModel.WorkshopIds.FirstOrDefault(); var startMonthFa = $"{searchModel.Year}/{searchModel.Month.PadLeft(2, '0')}/01"; DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); DateTime endDateGr = startMonthFa.FindeEndOfMonth() .ToGeorgianDateTime(); int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2)); //مقادیر سالانه این تاریخ var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDateGr, endDateGr, searchModel.Year); // دریافت اطلاعات هویتی و شروع و ترک کار کارکنان //var employeesInfoAndLeftWorks = // _leftWorkInsuranceApplication.GetEmployeeInsuranceLeftWorksAndInformation(workshopId, startDateGr, // endDateGr); var employeeInsurancDataPreviusList = _insuranceListRepositpry.GetEmployeeInsuranceDataForEdit(searchModel.InsuranceId, startDateGr, endDateGr); var computeResult = employeeInsurancDataPreviusList.Select(employeeData => { var dateOfBirth = employeeData.DateOfBirthGr.ToFarsi(); var dateOfIssue = employeeData.DateOfIssueGr.ToFarsi(); var leftDate = employeeData.LeftWorkDateGr != null ? employeeData.LeftWorkDateGr.Value.AddDays(-1) : new DateTime(); var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employeeData.StartWorkDateGr, leftDate, startDateGr, endDateGr, employeeData.EmployeeId); var leftWorkFa = workingDays.hasLeftWorkInMonth ? employeeData.LeftWorkDateGr.ToFarsi() : ""; var startWorkFa = employeeData.StartWorkDateGr.ToFarsi(); var workshop = _workShopRepository.GetDetails(workshopId); //آیا کارفرما است bool isManager = employeeData.JobId is 10 or 16 or 17 or 18 or 3498; //محاسبه حق بیمه سهم کارفرما var employerShare = (employeeData.BenefitsIncludedContinuous * 20) / 100; // محاسبه بیمه بیکاری var unEmploymentInsurance = (employeeData.BenefitsIncludedContinuous * 3) / 100; //آیا در کارگاه تیک محاسبه اضافه کار یا حق اولاد زده شده است؟ //این مورد زمانی چک می شود که تیک محاسبه در کارگاه زده شده باشد // در غیر اینصورت بصورت پیشفرض دارای فیش حقوق در نظر گرفته می شود bool hasWorkshopOverTimeOrFamilyAllowance = workshop.InsuranceCheckoutFamilyAllowance || workshop.InsuranceCheckoutOvertime; bool employeeHasCheckout = true; bool hasOverTimePay = false; bool hasFamilyAllowance = false; if (hasWorkshopOverTimeOrFamilyAllowance && (leftDate >= startDateGr || employeeData.LeftWorkDateGr == null)) { var checkout = _checkoutRepository.HasCheckout(workshopId, employeeData.EmployeeId, searchModel.Year, searchModel.Month); if (checkout.hasChekout) { if (checkout.OverTimePay > 0) hasOverTimePay = true; if (checkout.FamilyAlloance > 0) hasFamilyAllowance = true; } else { employeeHasCheckout = isManager == false ? false : true; } } bool familyAllowanceIsSet = true; bool overTimePayIsSet = true; if (workshop.InsuranceCheckoutFamilyAllowance && employeeHasCheckout && employeeData.FamilyAllowance == 0 && hasFamilyAllowance && !isManager) { familyAllowanceIsSet = false; } if (workshop.InsuranceCheckoutOvertime && employeeHasCheckout && employeeData.OverTimePay == 0 && hasOverTimePay && !isManager) { overTimePayIsSet = false; } return new EmployeeDetailsForInsuranceListViewModel { #region EmployeeInfo EmployeeHasCheckout = employeeHasCheckout, EmployeeInsurancListDataId = employeeData.EmployeeInsurancListDataId, InsuranceEmployeeInformationId = employeeData.InsuranceEmployeeInformationId, EmployeeId = employeeData.EmployeeId, FName = employeeData.FName, LName = employeeData.LName, FatherName = employeeData.FatherName, DateOfBirth = dateOfBirth == "1300/10/11" ? "" : dateOfBirth, DateOfIssue = dateOfIssue, DateOfBirthGr = employeeData.DateOfBirthGr, DateOfIssueGr = employeeData.DateOfIssueGr, PlaceOfIssue = employeeData.PlaceOfIssue, IdNumber = employeeData.IdNumber, Gender = employeeData.Gender, NationalCode = employeeData.NationalCode, Nationality = employeeData.Nationality, InsuranceCode = employeeData.InsuranceCode, // آیا وضعیت تاهل پرسنل ست شده است IsMaritalStatusSet = !string.IsNullOrWhiteSpace(employeeData.MaritalStatus), MaritalStatus = employeeData.MaritalStatus, StartMonthCurrent = startMonthFa, WorkingDays = workingDays.countWorkingDays, StartWorkDate = startWorkFa, StartWorkDateGr = employeeData.StartWorkDateGr, LeftWorkDate = leftWorkFa, LeftWorkDateGr = workingDays.hasLeftWorkInMonth ? employeeData.LeftWorkDateGr : null, JobId = employeeData.JobId, JobName = employeeData.JobName, JobCode = employeeData.JobCode, HasStartWorkInMonth = workingDays.hasStartWorkInMonth, HasLeftWorkInMonth = workingDays.hasLeftWorkInMonth, #endregion #region Compute //مشمول مزایا بودن IncludeStatus = employeeData.IncludeStatus, //دستمزد روزانه DailyWage = GetRoundValue(employeeData.DailyWage), DailyWageStr = employeeData.DailyWage.ToMoney(), //HasConfilictJobs = dailyWage == 0, //پایه سنوات BaseYears = employeeData.BaseYears, //مجموع مزد روزانه و پایه سنوات DailyWagePlusBaseYears = employeeData.DailyWagePlusBaseYears, //حق تاهل MarriedAllowance = employeeData.MarriedAllowance, //دستمزد ماهانه MonthlySalary = employeeData.MonthlySalary, //مزایای ماهانه MonthlyBenefits = employeeData.MonthlyBenefits, //مزایای مشمول BenefitsIncludedContinuous = employeeData.BenefitsIncludedContinuous, //مزایای غیر مشمول BenefitsIncludedNonContinuous = employeeData.BenefitsIncludedNonContinuous, // جمع کل دستمزد و مزایای ماهانه مشمول و غیر مشمول IncludedAndNotIncluded = employeeData.IncludedAndNotIncluded, //حق بیمه سهم بیمه شده InsuranceShare = GetRoundValue(employeeData.InsuranceShare), //حق بیمه سهم کارفرما EmployerShare = GetRoundValue(employerShare), //بیمه بیکاری UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance), //کمک هزینه مسکن HousingAllowance = yearlysaleries.HousingAllowance, //کمک هزینه اقلام ConsumableItems = yearlysaleries.ConsumableItems, EndMonthCurrentDay = endOfMonth, YearlySalaryItem = yearlysaleries.DayliWage, MonthlyBaseYearsStr = "0", MonthlyBaseYears = 0, OverTimeIsSet = overTimePayIsSet, FamilyAllowanceIsSet = familyAllowanceIsSet #endregion }; }); result.EmployeeDetailsForInsuranceList = computeResult.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) .ThenBy(x => x.LName).ToList(); result.IsExist = false; result.MaritalStatus = yearlysaleries.MarriedAllowance; return result; } public OperationResult ConfirmInsuranceList(long id) { OperationResult result = new OperationResult(); try { result = _insuranceListRepositpry.ConfirmInsuranceList(id); result.Message = "تایید ارسال لیست بیمه با موفقیت انجام شد"; } catch (Exception) { result.Message = "تایید ارسال لیست بیمه با خطا انجام شد"; } return result; } public double? GetDailyWageFixedSalary(string year, long workshopId, long employeeId, DateTime? startDateGr, DateTime? endDateGr, long jobId, string population, long? insuranceJobId) { double? result = 0; string month = $"{startDateGr.ToFarsi()}".Substring(5, 2); //اگر مشاغل مقطوع بود و شغلش کارفرما بود // در جدول لیست بیمه قبلی چک شود try { if (workshopId == 318 && year == "1403") { double percent = 0; switch (jobId) { case 39: percent = 1.75; return 4180000; break; case 466: percent = 1.6; return 3822000; break; case 1192 or 398 or 8: percent = 1.5; return 3583000; break; } //var dateSaleryviewModel = new DateSalarySearchModel(); //dateSaleryviewModel.StartDateGr = startDateGr; //dateSaleryviewModel.EndDateGr = endDateGr; //var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); //// && _dateSalary.Id >0 //if (_dateSalary != null) //{ // var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); // dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; // dateSaleryItemviewModel.Percent = percent; // var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); // if (dateSalaryItem != null) // result = dateSalaryItem[0].Salary; //} } if (jobId == 10) //کارفرما { InsuranceListSearchModel searchModel = new InsuranceListSearchModel(); var workshop = _workShopRepository.GetDetails(workshopId); if (workshop.FixedSalary) { var inJob = _insuranceJobItemRepository .GetInsuranceJobItemByInsuranceJobId((long)workshop.InsuranceJobId, year, month); if (workshop.Population == "MoreThan500") { var max = inJob.MaxBy(x => x.PercentageMoreThan); var dateSaleryviewModel = new DateSalarySearchModel(); dateSaleryviewModel.StartDateGr = startDateGr; dateSaleryviewModel.EndDateGr = endDateGr; var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); if (_dateSalary != null) { var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; dateSaleryItemviewModel.Percent = max.PercentageMoreThan; var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); if (dateSalaryItem != null) result = dateSalaryItem[0].Salary; } } else { var max = inJob.MaxBy(x => x.PercentageLessThan); var dateSaleryviewModel = new DateSalarySearchModel(); dateSaleryviewModel.StartDateGr = startDateGr; dateSaleryviewModel.EndDateGr = endDateGr; var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); if (_dateSalary != null) { var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; dateSaleryItemviewModel.Percent = max.PercentageLessThan; var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); if (dateSalaryItem != null) result = dateSalaryItem[0].Salary; } } } //var insuransList = _insuranceListRepositpry.GetInsuranceListByWorkshopIdAndYear(workshopId, year); //var employeeInsurancListData = _employeeInsurancListDataRepository.GetEmployeeInsurancListDataByEmployeeIdAndInsuranceListId(employeeId, insuransList.Id); //if (employeeInsurancListData != null ) //{ // result = employeeInsurancListData.DailyWage; //} } else { var searchModel = new InsuranceJobItemSearchModel(); searchModel.InsuranceJobId = (long)insuranceJobId; var JobItem = _insuranceJobItemRepository.GetInsuranceJobItemByInsuranceJobIdForFixedSalary((long)insuranceJobId, jobId, year, month); if (JobItem != null && JobItem.Id != 0) { double percent = 0; if (population == "MoreThan500") percent = JobItem.PercentageMoreThan; else if (population == "LessThan500") percent = JobItem.PercentageLessThan; var dateSaleryviewModel = new DateSalarySearchModel(); dateSaleryviewModel.StartDateGr = startDateGr; dateSaleryviewModel.EndDateGr = endDateGr; var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); // && _dateSalary.Id >0 if (_dateSalary != null) { var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; dateSaleryItemviewModel.Percent = percent; var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); if (dateSalaryItem != null) result = dateSalaryItem[0].Salary; } } } } catch (Exception) { result = 0; } return result; } /// /// محاسبه مزایای ماهانه مشمول /// /// /// /// /// /// /// /// /// /// public double GetMonthlyBenefits(int endMonthCurrentDay, double consumableItemsItemValue, double housingAllowanceItemValue, double maritalStatus, int countWorkingDays, string typeOfInsuranceSendWorkshop, long jobId, long employeeId, bool includeStatus) { //ToDo //افزودن شرط مشمول مزایای //اگر پرسنل کارفرما بود و نوع لیست کارگاه کمک دولت بود مزایا محاسبه نشود //اگر تیک مشمول مزایا در ترک کار خاموش بود مزایا نگیرد bool isManager = jobId is 10 or 16 or 17 or 18 or 3498; if (isManager && !includeStatus) return 0; //پرسنل استثناء سیدعسکر موسوی زاده - فروشگاه ولی عصر if (employeeId == 1496) return 0; //پرسنل استثناء if (employeeId == 42783) return 53082855; //if(employeeId == 8859) // return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 31) * countWorkingDays); //مزایای ماهانه با توجه به پایان ماه که 30 یا 31 روزه است، متفاوت می باشد //برای ماه 29 روزه هم تقسیم بر 30 می شود. if (countWorkingDays == endMonthCurrentDay) return (consumableItemsItemValue + housingAllowanceItemValue + maritalStatus); else if (endMonthCurrentDay == 29)//farokhiChanges در خط پایین عدد 30 رو به 29 تغییر دادم return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 29) * countWorkingDays); else if (endMonthCurrentDay == 30)//farokhiChanges این شرط و خط زیر رو اضافه کردم return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 30) * countWorkingDays); else if (endMonthCurrentDay == 31)//farokhiChanges این شرط و خط زیر رو اضافه کردم return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 31) * countWorkingDays); else return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / endMonthCurrentDay) * countWorkingDays); } public double ComputeDailyWage(double yearlysalaryItemValue, long employeeId, long workshopId, string year) { double dailyWage = yearlysalaryItemValue; InsuranceListSearchModel searchModel = new InsuranceListSearchModel(); var insuransList = _insuranceListRepositpry.GetInsuranceListByWorkshopIdAndYear(workshopId, year); if (insuransList != null) { var employeeInsurancListData = _employeeInsurancListDataRepository.GetEmployeeInsurancListDataByEmployeeIdAndInsuranceListId(employeeId, insuransList.Id); if (employeeInsurancListData != null && employeeInsurancListData.DailyWage > dailyWage) { dailyWage = employeeInsurancListData.DailyWage; } } dailyWage = employeeId == 6536 ? 9399512 : dailyWage; return dailyWage; } public MainEmployeeDetailsViewModel GetEmployeeForInsuranceList(List leftWorkInsuranceViewModelList, EmployeeForEditInsuranceListSearchModel searchModel) { var result = new MainEmployeeDetailsViewModel(); List list = new List(); int leftWorkInsuranceCount = leftWorkInsuranceViewModelList.Count(); string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); var model = new YearlySalarySearchModel(); model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); model.year = searchModel.Year; var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); 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) { var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); var employeeDetailsForInsuranceObj = new EmployeeDetailsForInsuranceListViewModel(); employeeDetailsForInsuranceObj.HasConfilictJobs = false; employeeDetailsForInsuranceObj.IsMaritalStatusSet = // آیا وضعیت تاهل پرسنل ست شده است !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); if (_insuranceEmployeeInfoRepository.Exists(x => x.EmployeeId == item.EmployeeId)) { var employeeInfoObject = _insuranceEmployeeInfoApplication.GetDetailsByEmployeeId(item.EmployeeId); employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = employeeInfoObject.Id; employeeDetailsForInsuranceObj.EmployeeId = employeeInfoObject.EmployeeId; employeeDetailsForInsuranceObj.FName = employeeInfoObject.FName; employeeDetailsForInsuranceObj.LName = employeeInfoObject.LName; employeeDetailsForInsuranceObj.FatherName = employeeInfoObject.FatherName; employeeDetailsForInsuranceObj.DateOfBirth = employeeInfoObject.DateOfBirth; employeeDetailsForInsuranceObj.DateOfIssue = employeeInfoObject.DateOfIssue; employeeDetailsForInsuranceObj.DateOfBirthGr = employeeInfoObject.DateOfBirthGr; employeeDetailsForInsuranceObj.DateOfIssueGr = employeeInfoObject.DateOfIssueGr; employeeDetailsForInsuranceObj.PlaceOfIssue = employeeInfoObject.PlaceOfIssue; employeeDetailsForInsuranceObj.IdNumber = employeeInfoObject.IdNumber; employeeDetailsForInsuranceObj.Gender = employeeInfoObject.Gender; //از جدول پرسنل پر می شود employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; //employeeInfoObject.NationalCode; employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; //employeeInfoObject.InsuranceCode; } else { // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = 0; //employeeDetailsForInsuranceObj.EmployeeInsurancListDataId = 0; employeeDetailsForInsuranceObj.EmployeeId = employeeObject.Id; employeeDetailsForInsuranceObj.FName = employeeObject.FName; employeeDetailsForInsuranceObj.LName = employeeObject.LName; employeeDetailsForInsuranceObj.FatherName = employeeObject.FatherName; employeeDetailsForInsuranceObj.DateOfBirth = employeeObject.DateOfBirth == "1300/10/11" ? "" : employeeObject.DateOfBirth; employeeDetailsForInsuranceObj.DateOfIssue = employeeObject.DateOfIssue; employeeDetailsForInsuranceObj.PlaceOfIssue = employeeObject.PlaceOfIssue; employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; employeeDetailsForInsuranceObj.IdNumber = employeeObject.IdNumber; employeeDetailsForInsuranceObj.Gender = employeeObject.Gender; employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; } #region ComputingWorkingDays int startWork = 0; int endWork = 0; var year = Convert.ToInt32(searchModel.Year); var month = Convert.ToInt32(searchModel.Month); var day = 1; var persianCurrentStartDate = new PersianDateTime(year, month, day); var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); //آخرین روز ماه جاری var endMonthCurrentDay = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); if (persianStartDateUser < persianCurrentStartDate) employeeDetailsForInsuranceObj.HasStartWorkInMonth = false; else employeeDetailsForInsuranceObj.HasStartWorkInMonth = true; //اگر شروع به کار کاربر از ابتدای ماه جاری کمتر باشد if (persianStartDateUser <= persianCurrentStartDate) { startWork = 1; } else { startWork = dayStartDateUser; } if (!string.IsNullOrEmpty(item.LeftWorkDate)) { var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); var persianEndDateUser = persianLeftDateUser.AddDays(-1); var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); //if (persianLeftDateUser <= persianCurrentEndDate) // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; //else // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; //ترک کارش در ماه و سال جاری بود نمایش داده شود if (!item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) { employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; item.LeftWorkDate = string.Empty; item.LeftWorkDateGr = null; } else { employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; } //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد if (persianEndDateUser >= persianCurrentEndDate) { endWork = endMonthCurrentDay; } else { endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); } } else { employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; endWork = endMonthCurrentDay; } int countWorkingDays = 0; for (int i = startWork; i <= endWork; i++) { countWorkingDays = countWorkingDays + 1; } //farokhiChanges //روزهای کارکرد پرسنل با آی دی های زیر دستی تعریف شد switch (item.EmployeeId) { //case 3812://ثابت // countWorkingDays = 15; // break; case 40463://ثابت countWorkingDays = 10; break; case 40469://ثابت countWorkingDays = 7; break; //case 9950://ثابت // countWorkingDays = 15; break; case 9640://ثابت countWorkingDays = 15; break; case 40998://ثابت countWorkingDays = 15; break; case 6219://ثابت countWorkingDays = 15; break; //case 7897://ثابت // countWorkingDays = 15; // break; } ; #endregion employeeDetailsForInsuranceObj.IncludeStatus = item.IncludeStatus; #region InsuranceJob 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)); employeeDetailsForInsuranceObj.HasConfilictJobs = (dailyWage == 0 ? true : false); } #endregion if (yearlysalaryItem != null) { if (!searchModel.FixedSalary) { //dailyWage= yearlysalaryItem.ItemValue; dailyWage = ComputeDailyWage(yearlysalaryItem.ItemValue, item.EmployeeId, item.WorkshopId, searchModel.Year); } employeeDetailsForInsuranceObj.DailyWage = GetRoundValue(dailyWage); employeeDetailsForInsuranceObj.DailyWageStr = employeeDetailsForInsuranceObj.DailyWage.ToMoney(); employeeDetailsForInsuranceObj.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); employeeDetailsForInsuranceObj.HousingAllowance = housingAllowance.ItemValue; employeeDetailsForInsuranceObj.ConsumableItems = consumableItems.ItemValue; employeeDetailsForInsuranceObj.EndMonthCurrentDay = endMonthCurrentDay; employeeDetailsForInsuranceObj.YearlySalaryItem = yearlysalaryItem.ItemValue; if (item.IncludeStatus) { var marital = employeeObject.MaritalStatus == "متاهل" ? maritalStatus.ItemValue : 0; employeeDetailsForInsuranceObj.MonthlyBenefits = GetMonthlyBenefits(endMonthCurrentDay, consumableItems.ItemValue, housingAllowance.ItemValue, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId, item.IncludeStatus); } else { employeeDetailsForInsuranceObj.MonthlyBenefits = 0; } if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت { employeeDetailsForInsuranceObj.MonthlyBenefits = 0; } employeeDetailsForInsuranceObj.BenefitsIncludedContinuous = employeeDetailsForInsuranceObj.MonthlyBenefits + employeeDetailsForInsuranceObj.MonthlySalary; //if ((!item.IncludeStatus &&(item.JobId == 10 || item.JobId == 17 || item.JobId == 18 || item.JobId == 16)) ||(item.IncludeStatus && item.JobId == 10)) // 10 --> karfarma //{ // var insuranceShare2 =(employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 27) / 100; // employeeDetailsForInsuranceObj.InsuranceShare =GetRoundValue(insuranceShare2); //} //else //{ var insuranceShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 7) / 100; employeeDetailsForInsuranceObj.InsuranceShare = GetRoundValue(insuranceShare); //Math.Round(insuranceShare, MidpointRounding.ToPositiveInfinity); //} var employerShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 20) / 100; employeeDetailsForInsuranceObj.EmployerShare = GetRoundValue(employerShare); //Math.Round(employerShare, MidpointRounding.ToPositiveInfinity); //if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId==10)//کمک دولت //{employeeDetailsForInsuranceObj.InsuranceShare = 0;} var unEmploymentInsurance = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 3) / 100; employeeDetailsForInsuranceObj.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous; employeeDetailsForInsuranceObj.IncludedAndNotIncluded = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous + employeeDetailsForInsuranceObj.BenefitsIncludedContinuous; } employeeDetailsForInsuranceObj.StartMonthCurrent = startMonthCurrent; employeeDetailsForInsuranceObj.WorkingDays = countWorkingDays; employeeDetailsForInsuranceObj.StartWorkDate = item.StartWorkDate; employeeDetailsForInsuranceObj.LeftWorkDate = item.LeftWorkDate; employeeDetailsForInsuranceObj.JobId = item.JobId; employeeDetailsForInsuranceObj.JobName = item.JobName; employeeDetailsForInsuranceObj.JobCode = item.JobCode; if (!string.IsNullOrWhiteSpace(item.LeftWorkDate)) employeeDetailsForInsuranceObj.LeftWorkDateGr = item.LeftWorkDateGr; employeeDetailsForInsuranceObj.StartWorkDateGr = item.StartWorkDateGr; list.Add(employeeDetailsForInsuranceObj); } list = list.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) .ThenBy(x => x.LName).ToList(); result.EmployeeDetailsForInsuranceList = list; result.IsExist = false; result.MaritalStatus = maritalStatus.ItemValue; //} //else //{ // result.IsExist = true; //} return result; } #region Client public List SearchForClient(InsuranceListSearchModel searchModel) { var result = _insuranceListRepositpry.SearchForClient(searchModel); return result; } #endregion //farokhiChanges public (double basic, int totalYear) BasicYear(long employeeId, long worshopId, DateTime startDate) { var totalYears = _leftWorkInsuranceRepository.TotalWorkingYears(employeeId, worshopId, startDate); var baseSalary = _insuranceYearlySalaryApplication.GetBaseYearByDate(startDate, totalYears); return (baseSalary, totalYears); } public double GetMonthlyBaseYear(double dayliBase, int countWorkingDays) { double res = GetRoundValue(dayliBase * countWorkingDays); return res; } #region Mahan public async Task ConfirmInsuranceOperation(InsuranceListConfirmOperation command) { // Improved version of the ConfirmInsuranceOperation method's main logic async Task CreateMediaAsync(InsuranceList insuranceList, string insuranceType, IFormFile file) { var path = Path.Combine(_mediaRepository.BasePath, "InsuranceList", $"{insuranceList.Year}_{insuranceList.Month}", insuranceList.id.ToString()); Directory.CreateDirectory(path); string uniqueFileName = $"{insuranceType}_{Path.GetFileNameWithoutExtension(file.FileName)}_{DateTime.Now.Ticks}{Path.GetExtension(file.FileName)}"; string filePath = Path.Combine(path, uniqueFileName); await using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); } var type = Path.GetExtension(filePath); var media = new Media(filePath, type, "فایل", "InsuranceList"); await _mediaRepository.CreateAsync(media); await _mediaRepository.SaveChangesAsync(); return media.id; } var op = new OperationResult(); var insuranceList = _insuranceListRepositpry.Get(command.InsuranceListId); if (insuranceList == null) return op.Failed("لیست بیمه پیدا نشد"); bool completeDebt = false, completeInspection = false, completeApproval = false; // Debt Section if (command.Debt.Type != InsuranceListDebtType.None) { var debt = command.Debt; if (string.IsNullOrWhiteSpace(debt.DebtDate)) return op.Failed("لطفا تاریخ بدهی را وارد کنید"); if (!debt.DebtDate.TryToGeorgianDateTime(out var debtDateGr)) return op.Failed("تاریخ بدهی نامعتبر است"); if (debt.DebtFile is not { Length: > 0 } && debt.DebtFileMediaId <= 0) return op.Failed("لطفا فایل بدهی را وارد کنید"); if (debt.DebtFile is { Length: > 20_000_000 }) return op.Failed("حجم فایل نمیتواند از 20 مگابایت بیشتر باشد"); var debtAmount = debt.Amount.MoneyToDouble(); if (debtAmount <= 0) return op.Failed("مبلغ بدهی نامعتبر است"); var mediaId = command.Debt.DebtFileMediaId; if (debt.DebtFile is { Length: > 0 }) { mediaId = await CreateMediaAsync(insuranceList, "debt", debt.DebtFile); } var debtEntity = new InsuranceListDebt(debt.Type, debtDateGr, debtAmount, mediaId); insuranceList.SetDebt(debtEntity); completeDebt = true; } // Inspection Section if (command.Inspection.Type != InsuranceListInspectionType.None) { var inspection = command.Inspection; if (string.IsNullOrWhiteSpace(inspection.LastInspectionDate)) return op.Failed("لطفا تاریخ بازرسی را وارد کنید"); if (!inspection.LastInspectionDate.TryToGeorgianDateTime(out var inspectionDateGr)) return op.Failed("تاریخ بازرسی نامعتبر است"); if (inspection.InspectionFile is not { Length: > 0 } && inspection.InspectionFileMediaId <= 0) return op.Failed("لطفا فایل بازرسی را وارد کنید"); if (inspection.InspectionFile is { Length: > 20_000_000 }) return op.Failed("حجم فایل نمیتواند از 20 مگابایت بیشتر باشد"); var mediaId = inspection.InspectionFileMediaId; if (inspection.InspectionFile is { Length: > 0 }) { mediaId = await CreateMediaAsync(insuranceList, "inspection", inspection.InspectionFile); } var inspectionEntity = new InsuranceListInspection(inspection.Type, inspectionDateGr, mediaId); insuranceList.SetInspection(inspectionEntity); completeInspection = true; } // Approval Section if (command.Approval.ApprovalStatus != InsuranceListEmployerApprovalStatus.None) { var approval = command.Approval; if (approval.ApprovalStatus == InsuranceListEmployerApprovalStatus.VerbalApproval) { if (string.IsNullOrWhiteSpace(approval.Description)) return op.Failed("لطفا توضیحات را وارد کنید"); if (approval.Description.Length < 15) return op.Failed("توضیحات باید حداقل 15 کاراکتر باشد"); } var approvalEntity = new InsuranceListEmployerApproval(approval.ApprovalStatus, approval.Description); insuranceList.SetEmployerApproval(approvalEntity); completeApproval = true; } // Final Confirmation if (command.ConfirmSentList) { if (!(completeApproval && completeDebt && completeInspection)) return op.Failed("تا زمانی که تمامی بخش ها پر نشده باشد نمیتوانید لیست را ارسال کنید"); insuranceList.SetConfirmSentlist(true); } else { insuranceList.SetConfirmSentlist(false); } await _insuranceListRepositpry.SaveChangesAsync(); return op.Succcedded(); } public Task GetInsuranceOperationDetails(long id) { return _insuranceListRepositpry.GetInsuranceOperationDetails(id); } public Task GetTabCounts(InsuranceListSearchModel searchModel) { return _insuranceListRepositpry.GetTabCounts(searchModel); } public async Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel) { return await _insuranceListRepositpry.GetNotCreatedWorkshop(searchModel); } #endregion }