From 48cc07bf2a8dd0dc2ddad915660b113153ad62b2 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Thu, 22 Jan 2026 16:09:27 +0330 Subject: [PATCH 01/13] GetContractsAndIncludeDataDataToCreateCheckout --- .../CheckoutAgg/ICheckoutRepository.cs | 9 + .../GetContractAndIncludesDataToCreateDto.cs | 6 + .../Checkout/ICheckoutApplication.cs | 8 + .../CheckoutApplication.cs | 24 +- .../Repository/CheckoutRepository.cs | 1452 +++++++++++++++++ .../Admin/Controllers/CheckoutController.cs | 18 +- 6 files changed, 1501 insertions(+), 16 deletions(-) create mode 100644 CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index 167c323c..e9a0125a 100644 --- a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs +++ b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs @@ -107,5 +107,14 @@ public interface ICheckoutRepository : IRepository /// Task> CheckoutPrint(List ids); + /// + /// دریافت قردادها و جداول وابسته برای ایجاد فیش + /// + /// + /// + /// + Task> GetContractsAndIncludeDataDataToCreateCheckout( + List ids, string month); + #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs b/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs new file mode 100644 index 00000000..8c916d79 --- /dev/null +++ b/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs @@ -0,0 +1,6 @@ +namespace CompanyManagment.App.Contracts.Checkout.Dto; + +public class GetContractAndIncludesDataToCreateDto +{ + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs index 5b938ead..2a74d2dd 100644 --- a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs +++ b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs @@ -106,6 +106,14 @@ public interface ICheckoutApplication /// Task>> GetContractToCreateCheckout(long workshopId, string year, string month, long employeeId); + /// + /// ایجاد فیش حقوقی + /// + /// + /// + /// + /// + Task CreateCheckoutApi(List ids, string year, string month); #endregion } diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index deb70a9f..240b5668 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -789,7 +789,7 @@ public class CheckoutApplication : ICheckoutApplication } - public async Task CreateCheckoutApi(List ContractsId, string ConvertYear, string ConvertMonth) + public async Task CreateCheckoutApi(List ids, string year, string month) { var op = new OperationResult(); @@ -798,26 +798,26 @@ public class CheckoutApplication : ICheckoutApplication #region Validation - if (!string.IsNullOrWhiteSpace(ConvertYear) && string.IsNullOrWhiteSpace(ConvertMonth)) + if (!string.IsNullOrWhiteSpace(year) && string.IsNullOrWhiteSpace(month)) return op.Failed("ماه را انتخاب کنید"); - if (string.IsNullOrWhiteSpace(ConvertYear) && !string.IsNullOrWhiteSpace(ConvertMonth)) + if (string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month)) return op.Failed("سال را انتخاب کنید"); - if (string.IsNullOrWhiteSpace(ConvertYear) && string.IsNullOrWhiteSpace(ConvertMonth)) + if (string.IsNullOrWhiteSpace(year) && string.IsNullOrWhiteSpace(month)) { - ConvertYear = "0"; - ConvertMonth = "0"; + year = "0"; + month = "0"; var today = DateTime.Now; var FaToday = today.ToFarsi(); - var year = FaToday.Substring(0, 4); - var month = FaToday.Substring(5, 2); + var convertedYear = FaToday.Substring(0, 4); + var convertedMonth = FaToday.Substring(5, 2); - ConvertYear = year; - ConvertMonth = month; + year = convertedYear; + month = convertedMonth; } - if (ContractsId.Count == 0) + if (ids.Count == 0) return op.Failed("هیچ موردی انتخاب نشده اشت"); #endregion @@ -829,6 +829,8 @@ public class CheckoutApplication : ICheckoutApplication #endregion + var getContcatsData = + _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, month); return op.Succcedded(); } #endregion diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 95cd3c8e..97ee960a 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -1,6 +1,7 @@ using _0_Framework.Application; using _0_Framework.InfraStructure; using Company.Domain.CheckoutAgg; +using Company.Domain.EmployeeAgg; using Company.Domain.LeftWorkAgg; using Company.Domain.RollCallAgg; using Company.Domain.RollCallEmployeeAgg; @@ -10,6 +11,7 @@ using CompanyManagment.App.Contracts.Checkout; using CompanyManagment.App.Contracts.Checkout.Dto; using CompanyManagment.App.Contracts.Contract; using CompanyManagment.App.Contracts.Employee; +using CompanyManagment.App.Contracts.EmployeeComputeOptions; using CompanyManagment.App.Contracts.HolidayItem; using CompanyManagment.App.Contracts.InstitutionPlan; using CompanyManagment.App.Contracts.InsuranceList; @@ -35,6 +37,7 @@ using System.Linq; using System.Reflection.Metadata.Ecma335; using System.Threading.Tasks; using System.Xml.XPath; +using static CompanyManagment.EFCore.Repository.ContractRepository; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace CompanyManagment.EFCore.Repository; @@ -2759,7 +2762,1456 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos return employees; } + public async Task> GetContractsAndIncludeDataDataToCreateCheckout(List ids, string month) + { + var op = new OperationResult(); + var watch = new Stopwatch(); + watch.Start(); + //دریافت قراداد ها + var contracts =await _context.Contracts.Where(x => ids.Contains(x.id)).AsNoTracking().ToListAsync(); + if (!contracts.Any()) + return op.Failed("قرادادی یافت نشد"); + var employeeIds = contracts.Select(x => x.EmployeeId).ToList(); + var workshopId = contracts.First().WorkshopIds; + //دریافت اطلاعات کارگاه + var workshop = await _context.Workshops.FirstAsync(x => x.id == workshopId); + + //دریافت اطلاعات پرسنل ها + var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).AsNoTracking().ToListAsync(); + //دریافت اطلاعت ساعت کاری + #region WorkingHours + var getWorkingHours = await _context.WorkingHoursSet.Where(x => ids.Contains(x.ContractId)) + .Include(x => x.WorkingHoursItemsList) + .AsNoTracking() + .ToListAsync(); + if (!getWorkingHours.Any()) + return op.Failed("ساعات کاری قراداد یافت نشد"); + + var workingHoursList = new List(); + foreach (var workingHours in getWorkingHours) + { + if (workingHours != null) + { + var items = workingHours?.WorkingHoursItemsList; + + if (workingHours.ShiftWork == "1" || workingHours.ShiftWork == "2") + { + var shanbeh = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0") ? true : false; + var yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0") ? true : false; + var doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0") ? true : false; + var seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0") ? true : false; + var cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0") ? true : false; + var pangshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0") ? true : false; + var jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0") ? true : false; + + var RestTime = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "0")?.RestTime + : null; + var RestTimeYekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "1")?.RestTime + : null; + var RestTimeDoshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "2")?.RestTime + : null; + var RestTimeSeshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "3")?.RestTime + : null; + var RestTimeCheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "4")?.RestTime + : null; + var RestTimePanjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "5")?.RestTime + : null; + var RestTimeJomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "6")?.RestTime + : null; + + var SingleShift1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "0")?.Start1 + : null; + var SingleShift2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "0")?.End1 + : null; + var TowShifts1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "0")?.Start2 + : null; + var TowShifts2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "0")?.End2 + : null; + + var SingleShift1Yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "1")?.Start1 + : null; + var SingleShift2Yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "1")?.End1 + : null; + var TowShifts1Yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "1")?.Start2 + : null; + var TowShifts2Yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "1")?.End2 + : null; + + var SingleShift1Doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "2")?.Start1 + : null; + var SingleShift2Doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "2")?.End1 + : null; + var TowShifts1Doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "2")?.Start2 + : null; + var TowShifts2Doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "2")?.End2 + : null; + + var SingleShift1Seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "3")?.Start1 + : null; + var SingleShift2Seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "3")?.End1 + : null; + var TowShifts1Seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "3")?.Start2 + : null; + var TowShifts2Seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "3")?.End2 + : null; + + var SingleShift1Cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "4")?.Start1 + : null; + var SingleShift2Cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "4")?.End1 + : null; + var TowShifts1Cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "4")?.Start2 + : null; + var TowShifts2Cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "4")?.End2 + : null; + + var SingleShift1Panjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "5")?.Start1 + : null; + var SingleShift2Panjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "5")?.End1 + : null; + var TowShifts1Panjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "5")?.Start2 + : null; + var TowShifts2Panjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "5")?.End2 + : null; + + var SingleShift1Jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "6")?.Start1 + : null; + var SingleShift2Jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "6")?.End1 + : null; + var TowShifts1Jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "6")?.Start2 + : null; + var TowShifts2Jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0") + ? items.FirstOrDefault(x => x.DayOfWork == "6")?.End2 + : null; + + var result = new CreateWorkingHoursTemp + { + WorknigHoursId = workingHours.id, + ShiftWork = "4", + ShiftWorkTemp = "1", + + #region week1 + + //week1 + Shanbe1 = shanbeh, + YekShanbe1 = yekshanbeh, + DoShanbe1 = doshanbeh, + SeShanbe1 = seshanbeh, + CheharShanbe1 = cheharshanbeh, + PanjShanbe1 = pangshanbeh, + Jome1 = jomeh, + + RestTimeShanbe1 = RestTime, + RestTimeYekShanbe1 = RestTimeYekshanbeh, + RestTimeDoShanbe1 = RestTimeDoshanbeh, + RestTimeSeShanbe1 = RestTimeSeshanbeh, + RestTimeCheharShanbe1 = RestTimeCheharshanbeh, + RestTimePanjShanbe1 = RestTimePanjshanbeh, + RestTimeJome1 = RestTimeJomeh, + + SingleShift1Shanbe1 = SingleShift1, + SingleShift2Shanbe1 = SingleShift2, + TowShifts1Shanbe1 = TowShifts1, + TowShifts2Shanbe1 = TowShifts2, + + SingleShift1YekShanbe1 = SingleShift1Yekshanbeh, + SingleShift2YekShanbe1 = SingleShift2Yekshanbeh, + TowShifts1YekShanbe1 = TowShifts1Yekshanbeh, + TowShifts2YekShanbe1 = TowShifts2Yekshanbeh, + + SingleShift1DoShanbe1 = SingleShift1Doshanbeh, + SingleShift2DoShanbe1 = SingleShift2Doshanbeh, + TowShifts1DoShanbe1 = TowShifts1Doshanbeh, + TowShifts2DoShanbe1 = TowShifts2Doshanbeh, + + SingleShift1SeShanbe1 = SingleShift1Seshanbeh, + SingleShift2SeShanbe1 = SingleShift2Seshanbeh, + TowShifts1SeShanbe1 = TowShifts1Seshanbeh, + TowShifts2SeShanbe1 = TowShifts2Seshanbeh, + + SingleShift1CheharShanbe1 = SingleShift1Cheharshanbeh, + SingleShift2CheharShanbe1 = SingleShift2Cheharshanbeh, + TowShifts1CheharShanbe1 = TowShifts1Cheharshanbeh, + TowShifts2CheharShanbe1 = TowShifts2Cheharshanbeh, + + SingleShift1PanjShanbe1 = SingleShift1Panjshanbeh, + SingleShift2PanjShanbe1 = SingleShift2Panjshanbeh, + TowShifts1PanjShanbe1 = TowShifts1Panjshanbeh, + TowShifts2PanjShanbe1 = TowShifts2Panjshanbeh, + + SingleShift1Jome1 = SingleShift1Jomeh, + SingleShift2Jome1 = SingleShift2Jomeh, + TowShifts1Jome1 = TowShifts1Jomeh, + TowShifts2Jome1 = TowShifts2Jomeh, + + #endregion + + #region week2 + + //week2 + Shanbe2 = shanbeh, + YekShanbe2 = yekshanbeh, + DoShanbe2 = doshanbeh, + SeShanbe2 = seshanbeh, + CheharShanbe2 = cheharshanbeh, + PanjShanbe2 = pangshanbeh, + Jome2 = jomeh, + + RestTimeShanbe2 = RestTime, + RestTimeYekShanbe2 = RestTimeYekshanbeh, + RestTimeDoShanbe2 = RestTimeDoshanbeh, + RestTimeSeShanbe2 = RestTimeSeshanbeh, + RestTimeCheharShanbe2 = RestTimeCheharshanbeh, + RestTimePanjShanbe2 = RestTimePanjshanbeh, + RestTimeJome2 = RestTimeJomeh, + + + SingleShift1Shanbe2 = SingleShift1, + SingleShift2Shanbe2 = SingleShift2, + TowShifts1Shanbe2 = TowShifts1, + TowShifts2Shanbe2 = TowShifts2, + + SingleShift1YekShanbe2 = SingleShift1Yekshanbeh, + SingleShift2YekShanbe2 = SingleShift2Yekshanbeh, + TowShifts1YekShanbe2 = TowShifts1Yekshanbeh, + TowShifts2YekShanbe2 = TowShifts2Yekshanbeh, + + SingleShift1DoShanbe2 = SingleShift1Doshanbeh, + SingleShift2DoShanbe2 = SingleShift2Doshanbeh, + TowShifts1DoShanbe2 = TowShifts1Doshanbeh, + TowShifts2DoShanbe2 = TowShifts2Doshanbeh, + + SingleShift1SeShanbe2 = SingleShift1Seshanbeh, + SingleShift2SeShanbe2 = SingleShift2Seshanbeh, + TowShifts1SeShanbe2 = TowShifts1Seshanbeh, + TowShifts2SeShanbe2 = TowShifts2Seshanbeh, + + SingleShift1CheharShanbe2 = SingleShift1Cheharshanbeh, + SingleShift2CheharShanbe2 = SingleShift2Cheharshanbeh, + TowShifts1CheharShanbe2 = TowShifts1Cheharshanbeh, + TowShifts2CheharShanbe2 = TowShifts2Cheharshanbeh, + + SingleShift1PanjShanbe2 = SingleShift1Panjshanbeh, + SingleShift2PanjShanbe2 = SingleShift2Panjshanbeh, + TowShifts1PanjShanbe2 = TowShifts1Panjshanbeh, + TowShifts2PanjShanbe2 = TowShifts2Panjshanbeh, + + SingleShift1Jome2 = SingleShift1Jomeh, + SingleShift2Jome2 = SingleShift2Jomeh, + TowShifts1Jome2 = TowShifts1Jomeh, + TowShifts2Jome2 = TowShifts2Jomeh, + + #endregion + + + #region week3 + + //week3 + Shanbe3 = shanbeh, + YekShanbe3 = yekshanbeh, + DoShanbe3 = doshanbeh, + SeShanbe3 = seshanbeh, + CheharShanbe3 = cheharshanbeh, + PanjShanbe3 = pangshanbeh, + Jome3 = jomeh, + + RestTimeShanbe3 = RestTime, + RestTimeYekShanbe3 = RestTimeYekshanbeh, + RestTimeDoShanbe3 = RestTimeDoshanbeh, + RestTimeSeShanbe3 = RestTimeSeshanbeh, + RestTimeCheharShanbe3 = RestTimeCheharshanbeh, + RestTimePanjShanbe3 = RestTimePanjshanbeh, + RestTimeJome3 = RestTimeJomeh, + + + SingleShift1Shanbe3 = SingleShift1, + SingleShift2Shanbe3 = SingleShift2, + TowShifts1Shanbe3 = TowShifts1, + TowShifts2Shanbe3 = TowShifts2, + + SingleShift1YekShanbe3 = SingleShift1Yekshanbeh, + SingleShift2YekShanbe3 = SingleShift2Yekshanbeh, + TowShifts1YekShanbe3 = TowShifts1Yekshanbeh, + TowShifts2YekShanbe3 = TowShifts2Yekshanbeh, + + SingleShift1DoShanbe3 = SingleShift1Doshanbeh, + SingleShift2DoShanbe3 = SingleShift2Doshanbeh, + TowShifts1DoShanbe3 = TowShifts1Doshanbeh, + TowShifts2DoShanbe3 = TowShifts2Doshanbeh, + + SingleShift1SeShanbe3 = SingleShift1Seshanbeh, + SingleShift2SeShanbe3 = SingleShift2Seshanbeh, + TowShifts1SeShanbe3 = TowShifts1Seshanbeh, + TowShifts2SeShanbe3 = TowShifts2Seshanbeh, + + SingleShift1CheharShanbe3 = SingleShift1Cheharshanbeh, + SingleShift2CheharShanbe3 = SingleShift2Cheharshanbeh, + TowShifts1CheharShanbe3 = TowShifts1Cheharshanbeh, + TowShifts2CheharShanbe3 = TowShifts2Cheharshanbeh, + + SingleShift1PanjShanbe3 = SingleShift1Panjshanbeh, + SingleShift2PanjShanbe3 = SingleShift2Panjshanbeh, + TowShifts1PanjShanbe3 = TowShifts1Panjshanbeh, + TowShifts2PanjShanbe3 = TowShifts2Panjshanbeh, + + SingleShift1Jome3 = SingleShift1Jomeh, + SingleShift2Jome3 = SingleShift2Jomeh, + TowShifts1Jome3 = TowShifts1Jomeh, + TowShifts2Jome3 = TowShifts2Jomeh, + + #endregion + + #region week4 + + //week4 + Shanbe4 = shanbeh, + YekShanbe4 = yekshanbeh, + DoShanbe4 = doshanbeh, + SeShanbe4 = seshanbeh, + CheharShanbe4 = cheharshanbeh, + PanjShanbe4 = pangshanbeh, + Jome4 = jomeh, + + RestTimeShanbe4 = RestTime, + RestTimeYekShanbe4 = RestTimeYekshanbeh, + RestTimeDoShanbe4 = RestTimeDoshanbeh, + RestTimeSeShanbe4 = RestTimeSeshanbeh, + RestTimeCheharShanbe4 = RestTimeCheharshanbeh, + RestTimePanjShanbe4 = RestTimePanjshanbeh, + RestTimeJome4 = RestTimeJomeh, + + + SingleShift1Shanbe4 = SingleShift1, + SingleShift2Shanbe4 = SingleShift2, + TowShifts1Shanbe4 = TowShifts1, + TowShifts2Shanbe4 = TowShifts2, + + SingleShift1YekShanbe4 = SingleShift1Yekshanbeh, + SingleShift2YekShanbe4 = SingleShift2Yekshanbeh, + TowShifts1YekShanbe4 = TowShifts1Yekshanbeh, + TowShifts2YekShanbe4 = TowShifts2Yekshanbeh, + + SingleShift1DoShanbe4 = SingleShift1Doshanbeh, + SingleShift2DoShanbe4 = SingleShift2Doshanbeh, + TowShifts1DoShanbe4 = TowShifts1Doshanbeh, + TowShifts2DoShanbe4 = TowShifts2Doshanbeh, + + SingleShift1SeShanbe4 = SingleShift1Seshanbeh, + SingleShift2SeShanbe4 = SingleShift2Seshanbeh, + TowShifts1SeShanbe4 = TowShifts1Seshanbeh, + TowShifts2SeShanbe4 = TowShifts2Seshanbeh, + + SingleShift1CheharShanbe4 = SingleShift1Cheharshanbeh, + SingleShift2CheharShanbe4 = SingleShift2Cheharshanbeh, + TowShifts1CheharShanbe4 = TowShifts1Cheharshanbeh, + TowShifts2CheharShanbe4 = TowShifts2Cheharshanbeh, + + SingleShift1PanjShanbe4 = SingleShift1Panjshanbeh, + SingleShift2PanjShanbe4 = SingleShift2Panjshanbeh, + TowShifts1PanjShanbe4 = TowShifts1Panjshanbeh, + TowShifts2PanjShanbe4 = TowShifts2Panjshanbeh, + + SingleShift1Jome4 = SingleShift1Jomeh, + SingleShift2Jome4 = SingleShift2Jomeh, + TowShifts1Jome4 = TowShifts1Jomeh, + TowShifts2Jome4 = TowShifts2Jomeh, + + #endregion + }; + //تفکیک ساعت استراحت + + #region TafkikRest + + #region Week1 + + var restTimeShanbe1 = result.RestTimeShanbe1; + result.RestTimeShanbe1 = restTimeShanbe1.RestTimeSplit(); + result.RestTimeShanbe1Min = restTimeShanbe1.RestTimeMinSplit(); + var restTimeYekShanbe1 = result.RestTimeYekShanbe1; + result.RestTimeYekShanbe1 = restTimeYekShanbe1.RestTimeSplit(); + result.RestTimeYekShanbe1Min = restTimeYekShanbe1.RestTimeMinSplit(); + var restTimeDoShanbe1 = result.RestTimeDoShanbe1; + result.RestTimeDoShanbe1 = restTimeDoShanbe1.RestTimeSplit(); + result.RestTimeDoShanbe1Min = restTimeDoShanbe1.RestTimeMinSplit(); + var restTimeSeShanbe1 = result.RestTimeSeShanbe1; + result.RestTimeSeShanbe1 = restTimeSeShanbe1.RestTimeSplit(); + result.RestTimeSeShanbe1Min = restTimeSeShanbe1.RestTimeMinSplit(); + var restTimeCheharShanbe1 = result.RestTimeCheharShanbe1; + result.RestTimeCheharShanbe1 = restTimeCheharShanbe1.RestTimeSplit(); + result.RestTimeCheharShanbe1Min = restTimeCheharShanbe1.RestTimeMinSplit(); + var restTimePanjShanbe1 = result.RestTimePanjShanbe1; + result.RestTimePanjShanbe1 = restTimePanjShanbe1.RestTimeSplit(); + result.RestTimePanjShanbe1Min = restTimePanjShanbe1.RestTimeMinSplit(); + var restTimeJome1 = result.RestTimeJome1; + result.RestTimeJome1 = restTimeJome1.RestTimeSplit(); + result.RestTimeJome1Min = restTimeJome1.RestTimeMinSplit(); + + #endregion + + #region week2 + + var restTimeShanbe2 = result.RestTimeShanbe2; + result.RestTimeShanbe2 = restTimeShanbe2.RestTimeSplit(); + result.RestTimeShanbe2Min = restTimeShanbe2.RestTimeMinSplit(); + var restTimeYekShanbe2 = result.RestTimeYekShanbe2; + result.RestTimeYekShanbe2 = restTimeYekShanbe2.RestTimeSplit(); + result.RestTimeYekShanbe2Min = restTimeYekShanbe2.RestTimeMinSplit(); + var restTimeDoShanbe2 = result.RestTimeDoShanbe2; + result.RestTimeDoShanbe2 = restTimeDoShanbe2.RestTimeSplit(); + result.RestTimeDoShanbe2Min = restTimeDoShanbe2.RestTimeMinSplit(); + var restTimeSeShanbe2 = result.RestTimeSeShanbe2; + result.RestTimeSeShanbe2 = restTimeSeShanbe2.RestTimeSplit(); + result.RestTimeSeShanbe2Min = restTimeSeShanbe2.RestTimeMinSplit(); + var restTimeCheharShanbe2 = result.RestTimeCheharShanbe2; + result.RestTimeCheharShanbe2 = restTimeCheharShanbe2.RestTimeSplit(); + result.RestTimeCheharShanbe2Min = restTimeCheharShanbe2.RestTimeMinSplit(); + var restTimePanjShanbe2 = result.RestTimePanjShanbe2; + result.RestTimePanjShanbe2 = restTimePanjShanbe2.RestTimeSplit(); + result.RestTimePanjShanbe2Min = restTimePanjShanbe2.RestTimeMinSplit(); + var restTimeJome2 = result.RestTimeJome2; + result.RestTimeJome2 = restTimeJome2.RestTimeSplit(); + result.RestTimeJome2Min = restTimeJome2.RestTimeMinSplit(); + + #endregion + + #region week3 + + var restTimeShanbe3 = result.RestTimeShanbe3; + result.RestTimeShanbe3 = restTimeShanbe3.RestTimeSplit(); + result.RestTimeShanbe3Min = restTimeShanbe3.RestTimeMinSplit(); + var restTimeYekShanbe3 = result.RestTimeYekShanbe3; + result.RestTimeYekShanbe3 = restTimeYekShanbe3.RestTimeSplit(); + result.RestTimeYekShanbe3Min = restTimeYekShanbe3.RestTimeMinSplit(); + var restTimeDoShanbe3 = result.RestTimeDoShanbe3; + result.RestTimeDoShanbe3 = restTimeDoShanbe3.RestTimeSplit(); + result.RestTimeDoShanbe3Min = restTimeDoShanbe3.RestTimeMinSplit(); + var restTimeSeShanbe3 = result.RestTimeSeShanbe3; + result.RestTimeSeShanbe3 = restTimeSeShanbe3.RestTimeSplit(); + result.RestTimeSeShanbe3Min = restTimeSeShanbe3.RestTimeMinSplit(); + var restTimeCheharShanbe3 = result.RestTimeCheharShanbe3; + result.RestTimeCheharShanbe3 = restTimeCheharShanbe3.RestTimeSplit(); + result.RestTimeCheharShanbe3Min = restTimeCheharShanbe3.RestTimeMinSplit(); + var restTimePanjShanbe3 = result.RestTimePanjShanbe3; + result.RestTimePanjShanbe3 = restTimePanjShanbe3.RestTimeSplit(); + result.RestTimePanjShanbe3Min = restTimePanjShanbe3.RestTimeMinSplit(); + var restTimeJome3 = result.RestTimeJome3; + result.RestTimeJome3 = restTimeJome3.RestTimeSplit(); + result.RestTimeJome3Min = restTimeJome3.RestTimeMinSplit(); + + #endregion + + #region week4 + + var restTimeShanbe4 = result.RestTimeShanbe4; + result.RestTimeShanbe4 = restTimeShanbe4.RestTimeSplit(); + result.RestTimeShanbe4Min = restTimeShanbe4.RestTimeMinSplit(); + var restTimeYekShanbe4 = result.RestTimeYekShanbe4; + result.RestTimeYekShanbe4 = restTimeYekShanbe4.RestTimeSplit(); + result.RestTimeYekShanbe4Min = restTimeYekShanbe4.RestTimeMinSplit(); + var restTimeDoShanbe4 = result.RestTimeDoShanbe4; + result.RestTimeDoShanbe4 = restTimeDoShanbe4.RestTimeSplit(); + result.RestTimeDoShanbe4Min = restTimeDoShanbe4.RestTimeMinSplit(); + var restTimeSeShanbe4 = result.RestTimeSeShanbe4; + result.RestTimeSeShanbe4 = restTimeSeShanbe4.RestTimeSplit(); + result.RestTimeSeShanbe4Min = restTimeSeShanbe4.RestTimeMinSplit(); + var restTimeCheharShanbe4 = result.RestTimeCheharShanbe4; + result.RestTimeCheharShanbe4 = restTimeCheharShanbe4.RestTimeSplit(); + result.RestTimeCheharShanbe4Min = restTimeCheharShanbe4.RestTimeMinSplit(); + var restTimePanjShanbe4 = result.RestTimePanjShanbe4; + result.RestTimePanjShanbe4 = restTimePanjShanbe4.RestTimeSplit(); + result.RestTimePanjShanbe4Min = restTimePanjShanbe4.RestTimeMinSplit(); + var restTimeJome4 = result.RestTimeJome4; + result.RestTimeJome4 = restTimeJome4.RestTimeSplit(); + result.RestTimeJome4Min = restTimeJome4.RestTimeMinSplit(); + + #endregion + + #endregion + + workingHoursList.Add(result); ; + } + + if (workingHours.ShiftWork == "4") + { + var result = new CreateWorkingHoursTemp + { + WorknigHoursId = workingHours.id, + ShiftWork = workingHours.ShiftWork, + ShiftWorkTemp = "4", + + //week1 + Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1") ? true : false, + YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1") ? true : false, + DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1") ? true : false, + SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1") ? true : false, + CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1") ? true : false, + PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1") ? true : false, + Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1") ? true : false, + + RestTimeShanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.RestTime + : null, + RestTimeYekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.RestTime + : null, + RestTimeDoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.RestTime + : null, + RestTimeSeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.RestTime + : null, + RestTimeCheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.RestTime + : null, + RestTimePanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.RestTime + : null, + RestTimeJome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.RestTime + : null, + + SingleShift1Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.Start1 + : null, + SingleShift2Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.End1 + : null, + TowShifts1Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.Start2 + : null, + TowShifts2Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.End2 + : null, + + SingleShift1YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.Start1 + : null, + SingleShift2YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.End1 + : null, + TowShifts1YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.Start2 + : null, + TowShifts2YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.End2 + : null, + + SingleShift1DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.Start1 + : null, + SingleShift2DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.End1 + : null, + TowShifts1DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.Start2 + : null, + TowShifts2DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.End2 + : null, + + SingleShift1SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.Start1 + : null, + SingleShift2SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.End1 + : null, + TowShifts1SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.Start2 + : null, + TowShifts2SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.End2 + : null, + + SingleShift1CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.Start1 + : null, + SingleShift2CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.End1 + : null, + TowShifts1CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.Start2 + : null, + TowShifts2CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.End2 + : null, + + SingleShift1PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.Start1 + : null, + SingleShift2PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.End1 + : null, + TowShifts1PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.Start2 + : null, + TowShifts2PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.End2 + : null, + + SingleShift1Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.Start1 + : null, + SingleShift2Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.End1 + : null, + TowShifts1Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.Start2 + : null, + TowShifts2Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.End2 + : null, + + //week2 + Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2") ? true : false, + YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2") ? true : false, + DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2") ? true : false, + SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2") ? true : false, + CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2") ? true : false, + PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2") ? true : false, + Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2") ? true : false, + + RestTimeShanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.RestTime + : null, + RestTimeYekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.RestTime + : null, + RestTimeDoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.RestTime + : null, + RestTimeSeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.RestTime + : null, + RestTimeCheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.RestTime + : null, + RestTimePanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.RestTime + : null, + RestTimeJome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.RestTime + : null, + + SingleShift1Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.Start1 + : null, + SingleShift2Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.End1 + : null, + TowShifts1Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.Start2 + : null, + TowShifts2Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.End2 + : null, + + SingleShift1YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.Start1 + : null, + SingleShift2YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.End1 + : null, + TowShifts1YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.Start2 + : null, + TowShifts2YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.End2 + : null, + + SingleShift1DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.Start1 + : null, + SingleShift2DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.End1 + : null, + TowShifts1DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.Start2 + : null, + TowShifts2DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.End2 + : null, + + SingleShift1SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.Start1 + : null, + SingleShift2SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.End1 + : null, + TowShifts1SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.Start2 + : null, + TowShifts2SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.End2 + : null, + + SingleShift1CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.Start1 + : null, + SingleShift2CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.End1 + : null, + TowShifts1CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.Start2 + : null, + TowShifts2CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.End2 + : null, + + SingleShift1PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.Start1 + : null, + SingleShift2PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.End1 + : null, + TowShifts1PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.Start2 + : null, + TowShifts2PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.End2 + : null, + + SingleShift1Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.Start1 + : null, + SingleShift2Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.End1 + : null, + TowShifts1Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.Start2 + : null, + TowShifts2Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.End2 + : null, + + //week3 + Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3") ? true : false, + YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3") ? true : false, + DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3") ? true : false, + SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3") ? true : false, + CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3") ? true : false, + PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3") ? true : false, + Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3") ? true : false, + + RestTimeShanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.RestTime + : null, + RestTimeYekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.RestTime + : null, + RestTimeDoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.RestTime + : null, + RestTimeSeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.RestTime + : null, + RestTimeCheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.RestTime + : null, + RestTimePanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.RestTime + : null, + RestTimeJome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.RestTime + : null, + + SingleShift1Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.Start1 + : null, + SingleShift2Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.End1 + : null, + TowShifts1Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.Start2 + : null, + TowShifts2Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.End2 + : null, + + SingleShift1YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.Start1 + : null, + SingleShift2YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.End1 + : null, + TowShifts1YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.Start2 + : null, + TowShifts2YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.End2 + : null, + + SingleShift1DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.Start1 + : null, + SingleShift2DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.End1 + : null, + TowShifts1DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.Start2 + : null, + TowShifts2DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.End2 + : null, + + SingleShift1SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.Start1 + : null, + SingleShift2SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.End1 + : null, + TowShifts1SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.Start2 + : null, + TowShifts2SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.End2 + : null, + + SingleShift1CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.Start1 + : null, + SingleShift2CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.End1 + : null, + TowShifts1CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.Start2 + : null, + TowShifts2CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.End2 + : null, + + SingleShift1PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.Start1 + : null, + SingleShift2PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.End1 + : null, + TowShifts1PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.Start2 + : null, + TowShifts2PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.End2 + : null, + + SingleShift1Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.Start1 + : null, + SingleShift2Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.End1 + : null, + TowShifts1Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.Start2 + : null, + TowShifts2Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.End2 + : null, + + + //week4 + Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4") ? true : false, + YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4") ? true : false, + DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4") ? true : false, + SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4") ? true : false, + CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4") ? true : false, + PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4") ? true : false, + Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4") ? true : false, + + RestTimeShanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.RestTime + : null, + RestTimeYekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.RestTime + : null, + RestTimeDoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.RestTime + : null, + RestTimeSeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.RestTime + : null, + RestTimeCheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.RestTime + : null, + RestTimePanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.RestTime + : null, + RestTimeJome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.RestTime + : null, + + SingleShift1Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.Start1 + : null, + SingleShift2Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.End1 + : null, + TowShifts1Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.Start2 + : null, + TowShifts2Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.End2 + : null, + + SingleShift1YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.Start1 + : null, + SingleShift2YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.End1 + : null, + TowShifts1YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.Start2 + : null, + TowShifts2YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.End2 + : null, + + SingleShift1DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.Start1 + : null, + SingleShift2DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.End1 + : null, + TowShifts1DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.Start2 + : null, + TowShifts2DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.End2 + : null, + + SingleShift1SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.Start1 + : null, + SingleShift2SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.End1 + : null, + TowShifts1SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.Start2 + : null, + TowShifts2SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.End2 + : null, + + SingleShift1CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.Start1 + : null, + SingleShift2CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.End1 + : null, + TowShifts1CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.Start2 + : null, + TowShifts2CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.End2 + : null, + + SingleShift1PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.Start1 + : null, + SingleShift2PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.End1 + : null, + TowShifts1PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.Start2 + : null, + TowShifts2PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.End2 + : null, + + SingleShift1Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.Start1 + : null, + SingleShift2Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.End1 + : null, + TowShifts1Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.Start2 + : null, + TowShifts2Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4") + ? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.End2 + : null + }; + //تفکیک ساعت استراحت + + #region TafkikRest + + #region Week1 + + var restTimeShanbe1 = result.RestTimeShanbe1; + result.RestTimeShanbe1 = restTimeShanbe1.RestTimeSplit(); + result.RestTimeShanbe1Min = restTimeShanbe1.RestTimeMinSplit(); + var restTimeYekShanbe1 = result.RestTimeYekShanbe1; + result.RestTimeYekShanbe1 = restTimeYekShanbe1.RestTimeSplit(); + result.RestTimeYekShanbe1Min = restTimeYekShanbe1.RestTimeMinSplit(); + var restTimeDoShanbe1 = result.RestTimeDoShanbe1; + result.RestTimeDoShanbe1 = restTimeDoShanbe1.RestTimeSplit(); + result.RestTimeDoShanbe1Min = restTimeDoShanbe1.RestTimeMinSplit(); + var restTimeSeShanbe1 = result.RestTimeSeShanbe1; + result.RestTimeSeShanbe1 = restTimeSeShanbe1.RestTimeSplit(); + result.RestTimeSeShanbe1Min = restTimeSeShanbe1.RestTimeMinSplit(); + var restTimeCheharShanbe1 = result.RestTimeCheharShanbe1; + result.RestTimeCheharShanbe1 = restTimeCheharShanbe1.RestTimeSplit(); + result.RestTimeCheharShanbe1Min = restTimeCheharShanbe1.RestTimeMinSplit(); + var restTimePanjShanbe1 = result.RestTimePanjShanbe1; + result.RestTimePanjShanbe1 = restTimePanjShanbe1.RestTimeSplit(); + result.RestTimePanjShanbe1Min = restTimePanjShanbe1.RestTimeMinSplit(); + var restTimeJome1 = result.RestTimeJome1; + result.RestTimeJome1 = restTimeJome1.RestTimeSplit(); + result.RestTimeJome1Min = restTimeJome1.RestTimeMinSplit(); + + #endregion + + #region week2 + + var restTimeShanbe2 = result.RestTimeShanbe2; + result.RestTimeShanbe2 = restTimeShanbe2.RestTimeSplit(); + result.RestTimeShanbe2Min = restTimeShanbe2.RestTimeMinSplit(); + var restTimeYekShanbe2 = result.RestTimeYekShanbe2; + result.RestTimeYekShanbe2 = restTimeYekShanbe2.RestTimeSplit(); + result.RestTimeYekShanbe2Min = restTimeYekShanbe2.RestTimeMinSplit(); + var restTimeDoShanbe2 = result.RestTimeDoShanbe2; + result.RestTimeDoShanbe2 = restTimeDoShanbe2.RestTimeSplit(); + result.RestTimeDoShanbe2Min = restTimeDoShanbe2.RestTimeMinSplit(); + var restTimeSeShanbe2 = result.RestTimeSeShanbe2; + result.RestTimeSeShanbe2 = restTimeSeShanbe2.RestTimeSplit(); + result.RestTimeSeShanbe2Min = restTimeSeShanbe2.RestTimeMinSplit(); + var restTimeCheharShanbe2 = result.RestTimeCheharShanbe2; + result.RestTimeCheharShanbe2 = restTimeCheharShanbe2.RestTimeSplit(); + result.RestTimeCheharShanbe2Min = restTimeCheharShanbe2.RestTimeMinSplit(); + var restTimePanjShanbe2 = result.RestTimePanjShanbe2; + result.RestTimePanjShanbe2 = restTimePanjShanbe2.RestTimeSplit(); + result.RestTimePanjShanbe2Min = restTimePanjShanbe2.RestTimeMinSplit(); + var restTimeJome2 = result.RestTimeJome2; + result.RestTimeJome2 = restTimeJome2.RestTimeSplit(); + result.RestTimeJome2Min = restTimeJome2.RestTimeMinSplit(); + + #endregion + + #region week3 + + var restTimeShanbe3 = result.RestTimeShanbe3; + result.RestTimeShanbe3 = restTimeShanbe3.RestTimeSplit(); + result.RestTimeShanbe3Min = restTimeShanbe3.RestTimeMinSplit(); + var restTimeYekShanbe3 = result.RestTimeYekShanbe3; + result.RestTimeYekShanbe3 = restTimeYekShanbe3.RestTimeSplit(); + result.RestTimeYekShanbe3Min = restTimeYekShanbe3.RestTimeMinSplit(); + var restTimeDoShanbe3 = result.RestTimeDoShanbe3; + result.RestTimeDoShanbe3 = restTimeDoShanbe3.RestTimeSplit(); + result.RestTimeDoShanbe3Min = restTimeDoShanbe3.RestTimeMinSplit(); + var restTimeSeShanbe3 = result.RestTimeSeShanbe3; + result.RestTimeSeShanbe3 = restTimeSeShanbe3.RestTimeSplit(); + result.RestTimeSeShanbe3Min = restTimeSeShanbe3.RestTimeMinSplit(); + var restTimeCheharShanbe3 = result.RestTimeCheharShanbe3; + result.RestTimeCheharShanbe3 = restTimeCheharShanbe3.RestTimeSplit(); + result.RestTimeCheharShanbe3Min = restTimeCheharShanbe3.RestTimeMinSplit(); + var restTimePanjShanbe3 = result.RestTimePanjShanbe3; + result.RestTimePanjShanbe3 = restTimePanjShanbe3.RestTimeSplit(); + result.RestTimePanjShanbe3Min = restTimePanjShanbe3.RestTimeMinSplit(); + var restTimeJome3 = result.RestTimeJome3; + result.RestTimeJome3 = restTimeJome3.RestTimeSplit(); + result.RestTimeJome3Min = restTimeJome3.RestTimeMinSplit(); + + #endregion + + #region week4 + + var restTimeShanbe4 = result.RestTimeShanbe4; + result.RestTimeShanbe4 = restTimeShanbe4.RestTimeSplit(); + result.RestTimeShanbe4Min = restTimeShanbe4.RestTimeMinSplit(); + var restTimeYekShanbe4 = result.RestTimeYekShanbe4; + result.RestTimeYekShanbe4 = restTimeYekShanbe4.RestTimeSplit(); + result.RestTimeYekShanbe4Min = restTimeYekShanbe4.RestTimeMinSplit(); + var restTimeDoShanbe4 = result.RestTimeDoShanbe4; + result.RestTimeDoShanbe4 = restTimeDoShanbe4.RestTimeSplit(); + result.RestTimeDoShanbe4Min = restTimeDoShanbe4.RestTimeMinSplit(); + var restTimeSeShanbe4 = result.RestTimeSeShanbe4; + result.RestTimeSeShanbe4 = restTimeSeShanbe4.RestTimeSplit(); + result.RestTimeSeShanbe4Min = restTimeSeShanbe4.RestTimeMinSplit(); + var restTimeCheharShanbe4 = result.RestTimeCheharShanbe4; + result.RestTimeCheharShanbe4 = restTimeCheharShanbe4.RestTimeSplit(); + result.RestTimeCheharShanbe4Min = restTimeCheharShanbe4.RestTimeMinSplit(); + var restTimePanjShanbe4 = result.RestTimePanjShanbe4; + result.RestTimePanjShanbe4 = restTimePanjShanbe4.RestTimeSplit(); + result.RestTimePanjShanbe4Min = restTimePanjShanbe4.RestTimeMinSplit(); + var restTimeJome4 = result.RestTimeJome4; + result.RestTimeJome4 = restTimeJome4.RestTimeSplit(); + result.RestTimeJome4Min = restTimeJome4.RestTimeMinSplit(); + + #endregion + + #endregion + + workingHoursList.Add(result); + } + else + { + var result = new CreateWorkingHoursTemp + { + WorknigHoursId = workingHours.id, + ShiftWork = workingHours.ShiftWork, + ShiftWorkTemp = "5", + StartComplex = items.FirstOrDefault()?.ComplexStart, + EndComplex = items.FirstOrDefault()?.ComplexEnd, + WeeklyWorkingTime = workingHours.WeeklyWorkingTime + }; + workingHoursList.Add(result); + } + } + } + + + + #endregion + + //دریافت اطلاعات شروع بکار/ترک کار + #region LeftWorks + + var leftWorks = await _context.LeftWorkList + .Where(x => x.WorkshopId == workshopId) + .Where(x => employeeIds.Contains(x.EmployeeId)).AsNoTracking().ToListAsync(); + + #endregion + + //جداسازی شروع و پایان فیش از قراداد با توجه به شروع بکار و ترک کار + #region Separation + + var separation = new List(); + + foreach (var item in contracts) + { + bool hasLeft = false; + var ContractEnd = item.ContractEnd; + var contractStart = item.ContarctStart; + var leftWork = leftWorks.FirstOrDefault(x => x.EmployeeId == item.EmployeeId && item.ContarctStart <= x.LeftWorkDate && item.ContractEnd >= x.StartWorkDate); + if (leftWork == null) + { + separation.Add(new ContractSeparationViewModel() + { + checker = false + }); + continue; + } + + if (leftWork.HasLeft && leftWork.LeftWorkDate < item.ContractEnd && + leftWork.LeftWorkDate >= item.ContarctStart) + { + ContractEnd = leftWork.LeftWorkDate.AddDays(-1); + hasLeft = true; + var start = contractStart.ToFarsi(); + var end = ContractEnd.ToFarsi(); + var ContractPreiodsList = new List(); + var CheckoutMonth = int.Parse(month); + + var syear = Convert.ToInt32(start.Substring(0, 4)); + var smonth = Convert.ToInt32(start.Substring(5, 2)); + var sday = Convert.ToInt32(start.Substring(8, 2)); + + var eyear = Convert.ToInt32(end.Substring(0, 4)); + var emonth = Convert.ToInt32(end.Substring(5, 2)); + var eday = Convert.ToInt32(end.Substring(8, 2)); + + var PersianStartDate = new PersianDateTime(syear, smonth, sday); + var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); + var PersianEndDate = new PersianDateTime(eyear, emonth, eday); + + + + var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; + for (int i = 0; i < totalmonth; i++) + { + + + var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); + if (currentEndDate > PersianEndDate) + { + currentEndDate = PersianEndDate; + } + + var period = new PeriodStartEnd + { + startC = PersianStartDate.ToString("yyyy/MM/dd"), + endC = currentEndDate.ToString("yyyy/MM/dd"), + monthC = currentEndDate.Month + }; + ContractPreiodsList.Add(period); + //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); + + PersianStartDate = PersianStartDate.AddMonths(1); + PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); + + + } + + var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); + if (periodSelect != null) + { + var startDate = periodSelect.startC.ToGeorgianDateTime(); + var endDate = periodSelect.endC.ToGeorgianDateTime(); + + + separation.Add(new ContractSeparationViewModel() + { + StartWorkDate = leftWork.StartWorkDate, + LeftWorkDate = ContractEnd, + HasLeft = hasLeft, + ContarctStart = periodSelect.startC, + ContractEnd = periodSelect.endC, + ContractStartGr = startDate, + ContractEndGr = endDate, + checker = true, + }); + continue; + } + else + { + separation.Add(new ContractSeparationViewModel() + { + checker = false + }); + continue; + } + } + + if (leftWork.HasLeft && leftWork.LeftWorkDate >= item.ContractEnd && + leftWork.LeftWorkDate > item.ContarctStart) + { + var lastWorkDay = leftWork.LeftWorkDate.AddDays(-1); + + if (leftWork.LeftWorkDate == ContractEnd) + { + ContractEnd = lastWorkDay; + hasLeft = true; + } + + if (lastWorkDay == ContractEnd) + { + hasLeft = true; + } + + var start = contractStart.ToFarsi(); + var end = ContractEnd.ToFarsi(); + var ContractPreiodsList = new List(); + var CheckoutMonth = int.Parse(month); + + var syear = Convert.ToInt32(start.Substring(0, 4)); + var smonth = Convert.ToInt32(start.Substring(5, 2)); + var sday = Convert.ToInt32(start.Substring(8, 2)); + + var eyear = Convert.ToInt32(end.Substring(0, 4)); + var emonth = Convert.ToInt32(end.Substring(5, 2)); + var eday = Convert.ToInt32(end.Substring(8, 2)); + + var PersianStartDate = new PersianDateTime(syear, smonth, sday); + var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); + var PersianEndDate = new PersianDateTime(eyear, emonth, eday); + + + + var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; + for (int i = 0; i < totalmonth; i++) + { + + + var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); + if (currentEndDate > PersianEndDate) + { + currentEndDate = PersianEndDate; + } + + var period = new PeriodStartEnd + { + startC = PersianStartDate.ToString("yyyy/MM/dd"), + endC = currentEndDate.ToString("yyyy/MM/dd"), + monthC = currentEndDate.Month + }; + ContractPreiodsList.Add(period); + //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); + + PersianStartDate = PersianStartDate.AddMonths(1); + PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); + + + } + + var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); + if (periodSelect != null) + { + var startDate = periodSelect.startC.ToGeorgianDateTime(); + var endDate = periodSelect.endC.ToGeorgianDateTime(); + + + separation.Add(new ContractSeparationViewModel() + { + StartWorkDate = leftWork.StartWorkDate, + LeftWorkDate = ContractEnd, + HasLeft = hasLeft, + ContarctStart = periodSelect.startC, + ContractEnd = periodSelect.endC, + ContractStartGr = startDate, + ContractEndGr = endDate, + checker = true, + }); + continue; + } + else + { + separation.Add(new ContractSeparationViewModel() + { + checker = false + }); + continue; + } + } + else if(leftWork.HasLeft && contractStart > leftWork.LeftWorkDate) + { + + separation.Add(new ContractSeparationViewModel() + { + checker = false + }); + continue; + } + else if (!leftWork.HasLeft) + { + var start = contractStart.ToFarsi(); + var end = ContractEnd.ToFarsi(); + var ContractPreiodsList = new List(); + var CheckoutMonth = int.Parse(month); + + var syear = Convert.ToInt32(start.Substring(0, 4)); + var smonth = Convert.ToInt32(start.Substring(5, 2)); + var sday = Convert.ToInt32(start.Substring(8, 2)); + + var eyear = Convert.ToInt32(end.Substring(0, 4)); + var emonth = Convert.ToInt32(end.Substring(5, 2)); + var eday = Convert.ToInt32(end.Substring(8, 2)); + + var PersianStartDate = new PersianDateTime(syear, smonth, sday); + var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); + var PersianEndDate = new PersianDateTime(eyear, emonth, eday); + + var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; + for (int i = 0; i < totalmonth; i++) + { + + + var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); + if (currentEndDate > PersianEndDate) + { + currentEndDate = PersianEndDate; + } + + var period = new PeriodStartEnd + { + startC = PersianStartDate.ToString("yyyy/MM/dd"), + endC = currentEndDate.ToString("yyyy/MM/dd"), + monthC = currentEndDate.Month + }; + ContractPreiodsList.Add(period); + //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); + + PersianStartDate = PersianStartDate.AddMonths(1); + PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); + + + } + + var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); + if (periodSelect != null) + { + var startDate = periodSelect.startC.ToGeorgianDateTime(); + var endDate = periodSelect.endC.ToGeorgianDateTime(); + + + + separation.Add(new ContractSeparationViewModel() + { + StartWorkDate = leftWork.StartWorkDate, + HasLeft = hasLeft, + ContarctStart = periodSelect.startC, + ContractEnd = periodSelect.endC, + ContractStartGr = startDate, + ContractEndGr = endDate, + checker = true, + LeftWorkDate = new DateTime(2121, 3, 21), + }); + continue; + + } + else + { + separation.Add(new ContractSeparationViewModel() + { + checker = false + }); + continue; + } + } + else + { + separation.Add(new ContractSeparationViewModel() + { + checker = false + }); + continue; + } + } + + + + #endregion + + //دریافت تنظیمات فنی پرسنل ها + #region EmployeeOptions + + var employeeOptions = await _context.EmployeeComputeOptionsSet.Where(x => x.WorkshopId == workshopId).Select(x => new EmployeeComputeOptionsViewModel + { + Id = x.id, + WorkshopId = x.WorkshopId, + EmployeeId = x.EmployeeId, + ComputeOptions = x.ComputeOptions, + YearsOptions = x.YearsOptions, + BonusesOptions = x.BonusesOptions, + + }).AsNoTracking().ToListAsync(); + + #endregion + + Console.WriteLine("GetContractsAndIncludeDataDataToCreateCheckout : " + watch.Elapsed); + return op.Succcedded(new GetContractAndIncludesDataToCreateDto()); + + } #endregion diff --git a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs index 295d50b7..77706420 100644 --- a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs +++ b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs @@ -108,16 +108,24 @@ public class CheckoutController : AdminBaseController [HttpGet("GetContractsToCreateCheckout")] public async Task>> GetContractsToCreateCheckout(long workshopId, string year, string month, long employeeId) { - + var result =await _checkoutApplication.GetContractToCreateCheckout(workshopId, year, month, employeeId); if (!result.IsSuccedded) return result; - var hasWorkFlow =await _workFlowApplication.HasWorkFlow(workshopId, year, month); + //var hasWorkFlow =await _workFlowApplication.HasWorkFlow(workshopId, year, month); + + //if (hasWorkFlow) + // return new OperationResult>().Failed( + // "این کارگاه به دلیل داشتن کارپوشه مجاز به ایجاد تصفیه حساب نمی باشد"); + + #region testCreate + + var ids = result.Data.Where(x => x.CreateCheckoutStatus == CreateCheckoutStatus.ReadyToCreate).Select(x => x.Id).ToList(); + var test = await _checkoutApplication.CreateCheckoutApi(ids, year, month); + + #endregion - if (hasWorkFlow) - return new OperationResult>().Failed( - "این کارگاه به دلیل داشتن کارپوشه مجاز به ایجاد تصفیه حساب نمی باشد"); return result; } From 1324baa9c70e5b5324490b3ad36b41631f499cfa Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Sat, 24 Jan 2026 14:48:35 +0330 Subject: [PATCH 02/13] GetContractsAndIncludeDataDataToCreateCheckout changes --- .../CheckoutAgg/ICheckoutRepository.cs | 3 +- .../Checkout/ICheckoutApplication.cs | 2 +- .../CheckoutApplication.cs | 6 +-- .../Repository/CheckoutRepository.cs | 45 ++++++++++++++----- .../Admin/Controllers/CheckoutController.cs | 2 +- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index e9a0125a..23a6b262 100644 --- a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs +++ b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs @@ -112,9 +112,10 @@ public interface ICheckoutRepository : IRepository /// /// /// + /// /// Task> GetContractsAndIncludeDataDataToCreateCheckout( - List ids, string month); + List ids, string month, long workshopId); #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs index 2a74d2dd..d10e24e1 100644 --- a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs +++ b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs @@ -113,7 +113,7 @@ public interface ICheckoutApplication /// /// /// - Task CreateCheckoutApi(List ids, string year, string month); + Task CreateCheckoutApi(List ids, string year, string month, long workshopId); #endregion } diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 240b5668..3da6033c 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -789,7 +789,7 @@ public class CheckoutApplication : ICheckoutApplication } - public async Task CreateCheckoutApi(List ids, string year, string month) + public async Task CreateCheckoutApi(List ids, string year, string month, long workshopId) { var op = new OperationResult(); @@ -829,8 +829,8 @@ public class CheckoutApplication : ICheckoutApplication #endregion - var getContcatsData = - _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, month); + var getContcatsData = await + _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, month, workshopId); return op.Succcedded(); } #endregion diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 97ee960a..8d4a491a 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -2762,23 +2762,25 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos return employees; } - public async Task> GetContractsAndIncludeDataDataToCreateCheckout(List ids, string month) + public async Task> GetContractsAndIncludeDataDataToCreateCheckout(List ids, string month, long workshopId) { var op = new OperationResult(); - var watch = new Stopwatch(); - watch.Start(); + var watcher = new Stopwatch(); + watcher.Start(); //دریافت قراداد ها - var contracts =await _context.Contracts.Where(x => ids.Contains(x.id)).AsNoTracking().ToListAsync(); - if (!contracts.Any()) + var getContracts =await _context.Contracts.Include(x=>x.Employee).Where(x => ids.Contains(x.id)).AsNoTracking().ToListAsync(); + if (!getContracts.Any()) return op.Failed("قرادادی یافت نشد"); - var employeeIds = contracts.Select(x => x.EmployeeId).ToList(); - var workshopId = contracts.First().WorkshopIds; + var employeeIds = getContracts.Select(x => x.EmployeeId).ToList(); + //دریافت اطلاعات کارگاه var workshop = await _context.Workshops.FirstAsync(x => x.id == workshopId); - + var GetContractsTime = watcher.Elapsed; + watcher.Reset(); + watcher.Start(); //دریافت اطلاعات پرسنل ها - var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).AsNoTracking().ToListAsync(); + // var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).AsNoTracking().ToListAsync(); //دریافت اطلاعت ساعت کاری #region WorkingHours var getWorkingHours = await _context.WorkingHoursSet.Where(x => ids.Contains(x.ContractId)) @@ -3894,6 +3896,10 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos #endregion + + var workingHoursTime = watcher.Elapsed; + watcher.Reset(); + watcher.Start(); //دریافت اطلاعات شروع بکار/ترک کار #region LeftWorks @@ -3903,12 +3909,18 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos #endregion + var leftWorkTime = watcher.Elapsed; + watcher.Reset(); + watcher.Start(); + //جداسازی شروع و پایان فیش از قراداد با توجه به شروع بکار و ترک کار #region Separation + var timer = new Stopwatch(); + timer.Start(); var separation = new List(); - foreach (var item in contracts) + foreach (var item in getContracts) { bool hasLeft = false; var ContractEnd = item.ContractEnd; @@ -4192,6 +4204,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos #endregion + + var SeparationTime = timer.Elapsed; + + var optionTimer = new Stopwatch(); + optionTimer.Start(); //دریافت تنظیمات فنی پرسنل ها #region EmployeeOptions @@ -4207,8 +4224,12 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos }).AsNoTracking().ToListAsync(); #endregion - - Console.WriteLine("GetContractsAndIncludeDataDataToCreateCheckout : " + watch.Elapsed); + Console.WriteLine("GetContracts - employeeIds - workshop: " + GetContractsTime); + Console.WriteLine("workingHours " + workingHoursTime); + Console.WriteLine("leftWork " + leftWorkTime); + Console.WriteLine("Separation " + SeparationTime); + Console.WriteLine("EmployeeOptions : " + optionTimer.Elapsed); + Console.WriteLine("===================== sum : " + (GetContractsTime + workingHoursTime + leftWorkTime + SeparationTime + optionTimer.Elapsed) + "==================="); return op.Succcedded(new GetContractAndIncludesDataToCreateDto()); } diff --git a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs index 77706420..67968610 100644 --- a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs +++ b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs @@ -122,7 +122,7 @@ public class CheckoutController : AdminBaseController #region testCreate var ids = result.Data.Where(x => x.CreateCheckoutStatus == CreateCheckoutStatus.ReadyToCreate).Select(x => x.Id).ToList(); - var test = await _checkoutApplication.CreateCheckoutApi(ids, year, month); + var test = await _checkoutApplication.CreateCheckoutApi(ids, year, month,workshopId); #endregion From c151e2d3f74494be6ee56eecc3532764858ccde1 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Sun, 25 Jan 2026 19:40:28 +0330 Subject: [PATCH 03/13] some changes --- 0_Framework/0_Framework.csproj | 1 + .../Repository/CheckoutRepository.cs | 35 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/0_Framework/0_Framework.csproj b/0_Framework/0_Framework.csproj index 66522232..a77e5547 100644 --- a/0_Framework/0_Framework.csproj +++ b/0_Framework/0_Framework.csproj @@ -21,6 +21,7 @@ + diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 406fd32d..86a998fd 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -3911,7 +3911,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var leftWorkTime = watcher.Elapsed; watcher.Reset(); - watcher.Start(); + watcher.Stop(); //جداسازی شروع و پایان فیش از قراداد با توجه به شروع بکار و ترک کار #region Separation @@ -3919,8 +3919,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var timer = new Stopwatch(); timer.Start(); var separation = new List(); - - foreach (var item in getContracts) + var seprationData = getContracts.Select(x => new { x.EmployeeId, x.ContarctStart, x.ContractEnd }).ToList(); + foreach (var item in seprationData) { bool hasLeft = false; var ContractEnd = item.ContractEnd; @@ -3932,7 +3932,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { checker = false }); - continue; + } if (leftWork.HasLeft && leftWork.LeftWorkDate < item.ContractEnd && @@ -3958,7 +3958,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var PersianEndDate = new PersianDateTime(eyear, emonth, eday); - var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; for (int i = 0; i < totalmonth; i++) { @@ -3991,7 +3990,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var startDate = periodSelect.startC.ToGeorgianDateTime(); var endDate = periodSelect.endC.ToGeorgianDateTime(); - + separation.Add(new ContractSeparationViewModel() { StartWorkDate = leftWork.StartWorkDate, @@ -4003,7 +4002,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ContractEndGr = endDate, checker = true, }); - continue; + } else { @@ -4011,7 +4010,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { checker = false }); - continue; + } } @@ -4094,7 +4093,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ContractEndGr = endDate, checker = true, }); - continue; + } else { @@ -4102,17 +4101,17 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { checker = false }); - continue; + } } - else if(leftWork.HasLeft && contractStart > leftWork.LeftWorkDate) + else if (leftWork.HasLeft && contractStart > leftWork.LeftWorkDate) { separation.Add(new ContractSeparationViewModel() { checker = false }); - continue; + } else if (!leftWork.HasLeft) { @@ -4178,8 +4177,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos checker = true, LeftWorkDate = new DateTime(2121, 3, 21), }); - continue; - + + } else { @@ -4187,7 +4186,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { checker = false }); - continue; + } } else @@ -4196,7 +4195,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { checker = false }); - continue; + } } @@ -4206,7 +4205,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var SeparationTime = timer.Elapsed; - + timer.Stop(); var optionTimer = new Stopwatch(); optionTimer.Start(); //دریافت تنظیمات فنی پرسنل ها @@ -4597,7 +4596,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var overNightWorkValue = x.NightworkPay > 0 ? x.OverNightWorkValue : "-"; var fridayWorkValue = x.FridayPay > 0 ? x.FridayWorkValue : "-"; var maritalStatus = employees.First(e => e.EmployeeId == x.EmployeeId).MaritalStatus; - var rewardPay = x.RewardPay == null ? "-" : x.RewardPay.ToMoneyCheckZeroNullable(); + var rewardPay = x.RewardPay == 0 ? "-" : x.RewardPay.ToMoney(); var rotatingShiftValue = x.ShiftPay > 0 ? x.RotatingShiftValue : "-"; var totalDeduction = "-"; var totalPayment = "-"; From bef21edf22cbe0856008bf120829ed4351fe70e4 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Mon, 26 Jan 2026 14:44:30 +0330 Subject: [PATCH 04/13] chnage GetContractAndIncluded --- .../GetContractAndIncludesDataToCreateDto.cs | 92 +++++++++++++++++- .../Checkout/ICheckoutApplication.cs | 2 +- .../Contract/ContractSeparationViewModel.cs | 2 + .../CheckoutApplication.cs | 38 ++++---- .../Repository/CheckoutRepository.cs | 96 +++++++++++++++++-- .../Admin/Controllers/CheckoutController.cs | 38 ++++++++ 6 files changed, 236 insertions(+), 32 deletions(-) diff --git a/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs b/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs index 8c916d79..6ee91430 100644 --- a/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs +++ b/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs @@ -1,6 +1,94 @@ -namespace CompanyManagment.App.Contracts.Checkout.Dto; +using CompanyManagment.App.Contracts.Contract; +using CompanyManagment.App.Contracts.EmployeeComputeOptions; +using CompanyManagment.App.Contracts.WorkingHoursTemp; +using System.Collections.Generic; + +namespace CompanyManagment.App.Contracts.Checkout.Dto; public class GetContractAndIncludesDataToCreateDto { - + + + /// + /// آی دی کارگاه + /// + public long WorkshopId { get; set; } + + /// + /// نام کارگاه + /// + public string WorkshopName { get; set; } + + + /// + /// کد بایگانی کارگاه + /// + public string ArchiveCode { get; set; } + + + + public List ContractIncludedData { get; set; } + +} + + +public class ContractIncludedData +{ + /// + /// شماره قرارداد + /// + public string ContractNo { get; set; } + + /// + /// آی دی پرسنل + /// + public long EmployeeId { get; set; } + /// + /// نام کامل پرسنل + /// + public string EmployeeFullName { get; set; } + + /// + /// نام پدر + /// + public string FathersName { get; set; } + + /// + /// کد ملی + /// + public string NationalCode { get; set; } + + /// + /// تاریخ تولد + /// + public string DateOfBirth { get; set; } + + + /// + /// کد پرسنلس + /// + public string PersonnelCode { get; set; } + + + /// + /// وضعیت تاهل + /// + + public string MaritalStatus { get; set; } + + + /// + /// ساعت کاری پرسنل + /// + public CreateWorkingHoursTemp WorkingHours { get; set; } + + /// + /// اطلاعات جداسازی تاریخ فیش + /// + public ContractSeparationViewModel Saparation { get; set; } + + /// + /// تنظیمات فنی پرسنل + /// + public EmployeeComputeOptionsViewModel EmployeeOption { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs index d10e24e1..e513875c 100644 --- a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs +++ b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs @@ -113,7 +113,7 @@ public interface ICheckoutApplication /// /// /// - Task CreateCheckoutApi(List ids, string year, string month, long workshopId); + Task> CreateCheckoutApi(List ids, string year, string month, long workshopId); #endregion } diff --git a/CompanyManagment.App.Contracts/Contract/ContractSeparationViewModel.cs b/CompanyManagment.App.Contracts/Contract/ContractSeparationViewModel.cs index b83f6b32..63175ca5 100644 --- a/CompanyManagment.App.Contracts/Contract/ContractSeparationViewModel.cs +++ b/CompanyManagment.App.Contracts/Contract/ContractSeparationViewModel.cs @@ -19,4 +19,6 @@ public class ContractSeparationViewModel public string ConsumableItems { get; set; } public bool checker { get; set; } public bool HasLeft { get; set; } + + public long EmployeeId { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 54b68506..035aeeba 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -799,7 +799,7 @@ public class CheckoutApplication : ICheckoutApplication } - public async Task CreateCheckoutApi(List ids, string year, string month, long workshopId) + public async Task> CreateCheckoutApi(List ids, string year, string month, long workshopId) { var op = new OperationResult(); @@ -808,27 +808,27 @@ public class CheckoutApplication : ICheckoutApplication #region Validation - if (!string.IsNullOrWhiteSpace(year) && string.IsNullOrWhiteSpace(month)) - return op.Failed("ماه را انتخاب کنید"); - if (string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month)) - return op.Failed("سال را انتخاب کنید"); + //if (!string.IsNullOrWhiteSpace(year) && string.IsNullOrWhiteSpace(month)) + // return op.Failed("ماه را انتخاب کنید"); + //if (string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month)) + // return op.Failed("سال را انتخاب کنید"); - if (string.IsNullOrWhiteSpace(year) && string.IsNullOrWhiteSpace(month)) - { - year = "0"; - month = "0"; + //if (string.IsNullOrWhiteSpace(year) && string.IsNullOrWhiteSpace(month)) + //{ + // year = "0"; + // month = "0"; - var today = DateTime.Now; - var FaToday = today.ToFarsi(); - var convertedYear = FaToday.Substring(0, 4); - var convertedMonth = FaToday.Substring(5, 2); + // var today = DateTime.Now; + // var FaToday = today.ToFarsi(); + // var convertedYear = FaToday.Substring(0, 4); + // var convertedMonth = FaToday.Substring(5, 2); - year = convertedYear; - month = convertedMonth; - } + // year = convertedYear; + // month = convertedMonth; + //} - if (ids.Count == 0) - return op.Failed("هیچ موردی انتخاب نشده اشت"); + //if (ids.Count == 0) + // return op.Failed("هیچ موردی انتخاب نشده اشت"); #endregion @@ -841,7 +841,7 @@ public class CheckoutApplication : ICheckoutApplication var getContcatsData = await _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, month, workshopId); - return op.Succcedded(); + return getContcatsData; } #endregion diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 86a998fd..b9ca4e43 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -2922,6 +2922,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var result = new CreateWorkingHoursTemp { + EmployeeId = getContracts.First(x=>x.id == workingHours.ContractId).EmployeeId, WorknigHoursId = workingHours.id, ShiftWork = "4", ShiftWorkTemp = "1", @@ -3271,6 +3272,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { var result = new CreateWorkingHoursTemp { + EmployeeId = getContracts.First(x => x.id == workingHours.ContractId).EmployeeId, WorknigHoursId = workingHours.id, ShiftWork = workingHours.ShiftWork, ShiftWorkTemp = "4", @@ -3880,6 +3882,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { var result = new CreateWorkingHoursTemp { + EmployeeId = getContracts.First(x => x.id == workingHours.ContractId).EmployeeId, WorknigHoursId = workingHours.id, ShiftWork = workingHours.ShiftWork, ShiftWorkTemp = "5", @@ -3930,7 +3933,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { separation.Add(new ContractSeparationViewModel() { - checker = false + checker = false, + EmployeeId = item.EmployeeId }); } @@ -4001,6 +4005,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ContractStartGr = startDate, ContractEndGr = endDate, checker = true, + EmployeeId = item.EmployeeId }); } @@ -4008,7 +4013,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { separation.Add(new ContractSeparationViewModel() { - checker = false + checker = false, + EmployeeId = item.EmployeeId }); } @@ -4092,6 +4098,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ContractStartGr = startDate, ContractEndGr = endDate, checker = true, + EmployeeId = item.EmployeeId }); } @@ -4099,7 +4106,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { separation.Add(new ContractSeparationViewModel() { - checker = false + checker = false, + EmployeeId = item.EmployeeId }); } @@ -4109,7 +4117,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos separation.Add(new ContractSeparationViewModel() { - checker = false + checker = false, + EmployeeId = item.EmployeeId }); } @@ -4176,6 +4185,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ContractEndGr = endDate, checker = true, LeftWorkDate = new DateTime(2121, 3, 21), + EmployeeId = item.EmployeeId }); @@ -4184,7 +4194,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { separation.Add(new ContractSeparationViewModel() { - checker = false + checker = false, + EmployeeId = item.EmployeeId }); } @@ -4193,7 +4204,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { separation.Add(new ContractSeparationViewModel() { - checker = false + checker = false, + EmployeeId = item.EmployeeId }); } @@ -4219,17 +4231,81 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ComputeOptions = x.ComputeOptions, YearsOptions = x.YearsOptions, BonusesOptions = x.BonusesOptions, - }).AsNoTracking().ToListAsync(); #endregion + + var optionTime = optionTimer.Elapsed; + optionTimer.Stop(); + + + var toListTimer = new Stopwatch(); + toListTimer.Start(); + var incloudedData = getContracts.Select(x => + { + return new ContractIncludedData + { + ContractNo = x.ContractNo, + + + + //اطلاعات هویتی پرسنل + #region EmployeeData + EmployeeId = x.EmployeeId, + EmployeeFullName = x.Employee.FullName, + FathersName = x.Employee.FatherName, + NationalCode = x.Employee.NationalCode, + DateOfBirth = x.Employee.DateOfBirth.ToFarsi(), + PersonnelCode = $"{x.PersonnelCode}", + MaritalStatus = x.Employee.MaritalStatus, + #endregion + + //ساعت کاری پرسنل + #region WorkingHours + WorkingHours = workingHoursList.FirstOrDefault(wh => wh.EmployeeId == x.EmployeeId), + #endregion + + //اطلاعات جداسازی تاریخ فیش از قرارداد + #region Saparation + Saparation = separation.FirstOrDefault(sep => sep.EmployeeId == x.EmployeeId), + #endregion + + //تنظیمات فنی پرسنل + #region EmployeeOption + + EmployeeOption = employeeOptions.FirstOrDefault(option=> option.EmployeeId == x.EmployeeId) + + #endregion + + }; + }).ToList(); + + var finalResult = new GetContractAndIncludesDataToCreateDto() + { + //اطلاعات کارگاه + #region WorkshopData + + WorkshopId = workshop.id, + ArchiveCode = workshop.ArchiveCode, + WorkshopName = workshop.WorkshopName, + + #endregion + + + ContractIncludedData = incloudedData, + }; + + var tolistTime = toListTimer.Elapsed; Console.WriteLine("GetContracts - employeeIds - workshop: " + GetContractsTime); Console.WriteLine("workingHours " + workingHoursTime); Console.WriteLine("leftWork " + leftWorkTime); Console.WriteLine("Separation " + SeparationTime); - Console.WriteLine("EmployeeOptions : " + optionTimer.Elapsed); - Console.WriteLine("===================== sum : " + (GetContractsTime + workingHoursTime + leftWorkTime + SeparationTime + optionTimer.Elapsed) + "==================="); - return op.Succcedded(new GetContractAndIncludesDataToCreateDto()); + Console.WriteLine("EmployeeOptions : " + optionTime); + Console.WriteLine("TolistTime : " + tolistTime); + Console.WriteLine("===================== sum : " + (GetContractsTime + workingHoursTime + leftWorkTime + SeparationTime + optionTime + tolistTime) + "==================="); + + + return op.Succcedded(finalResult); } diff --git a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs index 67968610..a3bc805b 100644 --- a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs +++ b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs @@ -6,6 +6,7 @@ using CompanyManagment.App.Contracts.Workshop; using CompanyManagment.App.Contracts.Workshop.DTOs; using Microsoft.AspNetCore.Mvc; using NuGet.Packaging.Signing; +using NuGet.Protocol; using ServiceHost.BaseControllers; using WorkFlow.Application.Contracts.WorkFlow; @@ -122,6 +123,8 @@ public class CheckoutController : AdminBaseController #region testCreate var ids = result.Data.Where(x => x.CreateCheckoutStatus == CreateCheckoutStatus.ReadyToCreate).Select(x => x.Id).ToList(); + + Console.WriteLine(ids.ToJson()); var test = await _checkoutApplication.CreateCheckoutApi(ids, year, month,workshopId); #endregion @@ -129,6 +132,41 @@ public class CheckoutController : AdminBaseController return result; } + + [HttpPost] + public async Task> CreateCheckout() + { + var ids = new + List() + { + 283652, 290314, 290315, 290316, 290317, 290318, 290319, 290320, 290321, 290322, 290323, 290324, 290325, + 290326, 290327, 290328, 290329, 290330, 290331, 290332, 290333, 290334, 290335, 290336, 290337, 290338, + 290339, 290340, 290341, 290342, 290343, 290344, 290345, 290346, 290347, 290348, 290349, 290350, 290351, + 290352, 290353, 290354, 290355, 290356, 290357, 290358, 290359, 290360, 290361, 290362, 290363, 290364, + 290365, 290366, 290367, 290368, 290369, 290370, 290371, 290372, 290373, 290374, 290375, 290376, 290377, + 290378, 290379, 290380, 290381, 290382, 290383, 290384, 290385, 290386, 290387, 290388, 290389, 290390, + 290391, 290392, 290393, 290394, 290395, 290396, 290397, 290398, 290399, 290400, 290401, 290402, 290403, + 290404, 290405, 290406, 290407, 290408, 290409, 290410, 290411, 290412, 290413, 290414, 290415, 290416, + 290417, 290418, 290419, 290420, 290421, 290422, 290423, 290424, 290425, 290426, 290427, 290428, 290429, + 290430, 290431, 290432, 290433, 290434, 290435, 290436, 290437, 290438, 290439, 290440, 290441, 290442, + 290443, 290444, 290445, 290446, 290447, 290448, 290449, 290450, 290451, 290452, 290453, 290454, 290455, + 290456, 290457, 290458, 290459, 290460, 290461, 290462, 290463, 290464, 290465, 290466, 290467, 290468, + 290469, 290470, 290471, 290472, 290473, 290474, 290475, 290476, 290477, 290478, 290479, 290480, 290481, + 290482, 290483, 290484, 290485, 290486, 290487, 290488, 290489, 290490, 290491, 290492, 290493, 290494, + 290495, 290496, 290497, 290498, 290499, 290500, 290501, 290502, 290503, 290504, 290505, 290506, 290507, + 290508, 290509, 290510, 290511, 290512, 290513, 290514, 290515, 290516, 290517, 290518, 290519, 290520, + 290521, 290522, 290523, 290524, 290525, 290526, 290527, 290528, 290529, 290530, 290531, 290532, 290533, + 290534, 290535, 290536, 290537, 290538, 290539, 290540, 290541, 290542, 290543, 290544, 290545, 290546, + 290547, 290548, 290549, 290550, 290551, 290552, 290553, 290554, 290555, 290556, 290557, 290558, 290559, + 290560, 290561, 290562, 290563, 290564, 290565, 290566, 290567, 290568, 290569, 290570, 290571, 290572, + 290573, 290574, 290575, 290576, 290577, 290578, 290579, 290580, 290581, 290582, 290583, 290584, 290585, + 290586, 290587, 290588 + }; + + + var test = await _checkoutApplication.CreateCheckoutApi(ids, "1404", "10", 499); + return test; + } #endregion } From 26517c20d825468f924f6acec9a5db2c28831a88 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Thu, 29 Jan 2026 13:35:22 +0330 Subject: [PATCH 05/13] some change --- 0_Framework/Application/Tools.cs | 108 ++++++++++++++++++ .../CheckoutAgg/ICheckoutRepository.cs | 3 +- .../CheckoutApplication.cs | 2 +- .../Repository/CheckoutRepository.cs | 25 +++- .../Admin/Controllers/CheckoutController.cs | 15 ++- 5 files changed, 148 insertions(+), 5 deletions(-) diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index 47de9e95..4a7ee562 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -650,7 +650,115 @@ public static class Tools return y2; } + /// + /// تاریخ شمسی میگیرد و پایان ماه را به میلادی برمیگرداند + /// + /// + /// + public static DateTime FindeEndOfMonthReturnGr(this string date) + { + string y2 = string.Empty; + var year = Convert.ToInt32(date.Substring(0, 4)); + var month = Convert.ToInt32(date.Substring(5, 2)); + var YearD = date.Substring(0, 4); + var MonthD = date.Substring(5, 2); + if (month <= 6) + { + y2 = $"{YearD}/{MonthD}/31"; + } + else if (month > 6 && month < 12) + { + y2 = $"{YearD}/{MonthD}/30"; + } + else if (month == 12) + { + switch (year) + { + case 1346: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1350: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1354: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1358: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1362: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1366: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1370: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1375: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1379: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1383: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1387: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1391: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1395: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1399: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1403: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1408: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1412: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1416: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1420: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1424: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1428: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1432: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1436: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1441: + y2 = $"{YearD}/{MonthD}/30"; + break; + case 1445: + y2 = $"{YearD}/{MonthD}/30"; + break; + default: + y2 = $"{YearD}/{MonthD}/29"; + break; + + } + } + + return y2.ToGeorgianDateTime(); + } /// /// تعداد روزهای سال را برمیگرداند /// اگر کبیسهد بود سال 366 روزه برمیگرداند diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index 23a6b262..4b110f84 100644 --- a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs +++ b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs @@ -111,11 +111,12 @@ public interface ICheckoutRepository : IRepository /// دریافت قردادها و جداول وابسته برای ایجاد فیش /// /// + /// /// /// /// Task> GetContractsAndIncludeDataDataToCreateCheckout( - List ids, string month, long workshopId); + List ids, string year, string month, long workshopId); #endregion } \ No newline at end of file diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 035aeeba..11eedd3b 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -840,7 +840,7 @@ public class CheckoutApplication : ICheckoutApplication #endregion var getContcatsData = await - _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, month, workshopId); + _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, year, month, workshopId); return getContcatsData; } #endregion diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index b9ca4e43..0fffff4f 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -2762,8 +2762,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos return employees; } - public async Task> GetContractsAndIncludeDataDataToCreateCheckout(List ids, string month, long workshopId) + public async Task> GetContractsAndIncludeDataDataToCreateCheckout(List ids,string year, string month, long workshopId) { + var checkoutSelectedStartFa = $"{year}/{month}/01"; + var checkoutSelectedStart = checkoutSelectedStartFa.ToGeorgianDateTime(); + var checkoutSelectedEnd = checkoutSelectedStartFa.FindeEndOfMonthReturnGr(); var op = new OperationResult(); var watcher = new Stopwatch(); watcher.Start(); @@ -3923,6 +3926,26 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos timer.Start(); var separation = new List(); var seprationData = getContracts.Select(x => new { x.EmployeeId, x.ContarctStart, x.ContractEnd }).ToList(); + + foreach (var contract in seprationData) + { + var start = new DateTime(); + var end = new DateTime(); + for (var current = contract.ContarctStart; current <= contract.ContractEnd; current=current.AddDays(1)) + { + if (start == new DateTime() && current >= checkoutSelectedStart && current <= checkoutSelectedEnd) + { + start = current; + } + + if (end == new DateTime() && current == checkoutSelectedEnd) + { + end = current; + } + } + } + + foreach (var item in seprationData) { bool hasLeft = false; diff --git a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs index a3bc805b..9be056d6 100644 --- a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs +++ b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs @@ -133,8 +133,13 @@ public class CheckoutController : AdminBaseController } + /// + /// ایجاد فیش حقوقی + /// + /// + /// [HttpPost] - public async Task> CreateCheckout() + public async Task> CreateCheckout([FromBody]TestCreateCheckout command) { var ids = new List() @@ -164,10 +169,16 @@ public class CheckoutController : AdminBaseController }; - var test = await _checkoutApplication.CreateCheckoutApi(ids, "1404", "10", 499); + var test = await _checkoutApplication.CreateCheckoutApi(ids, command.year, command.Month, command.WorkshopId); return test; } #endregion } +public class TestCreateCheckout +{ + public string year { get; set; } + public string Month { get; set; } + public long WorkshopId { get; set; } +} \ No newline at end of file From 6f0a579c338cd6c648e18c12f9487211687da232 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Sat, 31 Jan 2026 15:38:47 +0330 Subject: [PATCH 06/13] chage --- .../Repository/CheckoutRepository.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 0fffff4f..3290fed4 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -3929,8 +3929,18 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos foreach (var contract in seprationData) { + var leftWork = leftWorks.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId && contract.ContarctStart <= x.LeftWorkDate && contract.ContractEnd >= x.StartWorkDate); var start = new DateTime(); var end = new DateTime(); + if (leftWork == null) + { + separation.Add(new ContractSeparationViewModel() + { + checker = false, + EmployeeId = contract.EmployeeId + }); + continue; + } for (var current = contract.ContarctStart; current <= contract.ContractEnd; current=current.AddDays(1)) { if (start == new DateTime() && current >= checkoutSelectedStart && current <= checkoutSelectedEnd) @@ -3942,6 +3952,27 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { end = current; } + + + } + + var leftFirstDayOfNextMonth = end.AddDays(1); + if (leftWork.HasLeft && (leftWork.LeftWorkDate <= == leftFirstDayOfNextMonth) && + leftWork.LeftWorkDate > start) + { + var ContractEnd = leftWork.LeftWorkDate.AddDays(-1); + separation.Add(new ContractSeparationViewModel() + { + StartWorkDate = leftWork.StartWorkDate, + LeftWorkDate = leftWork.LeftWorkDate, + HasLeft = true, + ContarctStart = start.ToFarsi(), + ContractEnd = ContractEnd.ToFarsi(), + ContractStartGr = start, + ContractEndGr = ContractEnd, + checker = true, + EmployeeId = contract.EmployeeId + }); } } From 3f23d1dac07d773dd74d39dbf389438b2117b676 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Sat, 31 Jan 2026 17:08:24 +0330 Subject: [PATCH 07/13] saparation creatcheckout on api mehod changes --- .../Repository/CheckoutRepository.cs | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 3290fed4..1321ab42 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -3929,7 +3929,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos foreach (var contract in seprationData) { - var leftWork = leftWorks.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId && contract.ContarctStart <= x.LeftWorkDate && contract.ContractEnd >= x.StartWorkDate); + var leftWork = leftWorks.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId && contract.ContarctStart < x.LeftWorkDate && contract.ContractEnd >= x.StartWorkDate); var start = new DateTime(); var end = new DateTime(); if (leftWork == null) @@ -3957,14 +3957,14 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } var leftFirstDayOfNextMonth = end.AddDays(1); - if (leftWork.HasLeft && (leftWork.LeftWorkDate <= == leftFirstDayOfNextMonth) && + if (leftWork.HasLeft && leftWork.LeftWorkDate <= leftFirstDayOfNextMonth && leftWork.LeftWorkDate > start) { var ContractEnd = leftWork.LeftWorkDate.AddDays(-1); separation.Add(new ContractSeparationViewModel() { StartWorkDate = leftWork.StartWorkDate, - LeftWorkDate = leftWork.LeftWorkDate, + LeftWorkDate = ContractEnd, HasLeft = true, ContarctStart = start.ToFarsi(), ContractEnd = ContractEnd.ToFarsi(), @@ -3974,6 +3974,36 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos EmployeeId = contract.EmployeeId }); } + else if(leftWork.HasLeft && leftWork.LeftWorkDate > leftFirstDayOfNextMonth) + { + separation.Add(new ContractSeparationViewModel() + { + StartWorkDate = leftWork.StartWorkDate, + LeftWorkDate = leftWork.LeftWorkDate.AddDays(-1), + HasLeft = false, + ContarctStart = start.ToFarsi(), + ContractEnd = end.ToFarsi(), + ContractStartGr = start, + ContractEndGr = end, + checker = true, + EmployeeId = contract.EmployeeId + }); + } + else if(!leftWork.HasLeft) + { + separation.Add(new ContractSeparationViewModel() + { + StartWorkDate = leftWork.StartWorkDate, + LeftWorkDate = new DateTime(2121, 3, 21), + HasLeft = false, + ContarctStart = start.ToFarsi(), + ContractEnd = end.ToFarsi(), + ContractStartGr = start, + ContractEndGr = end, + checker = true, + EmployeeId = contract.EmployeeId + }); + } } From a2c1fd30bf404d9bd49398e2ef0aa55634043601 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Sun, 1 Feb 2026 19:36:09 +0330 Subject: [PATCH 08/13] Mandatory Compute Added to CreateCheckoutApi --- .../IRollCallMandatoryRepository.cs | 2 +- .../IRollCallEmployeeRepository.cs | 3 +- .../GetContractAndIncludesDataToCreateDto.cs | 88 +++- .../Checkout/ICheckoutApplication.cs | 2 +- .../Hubs/CheckoutHub.cs | 18 + .../CheckoutApplication.cs | 143 +++-- .../RollCallEmployeeStatusApplication.cs | 2 +- .../RollCallMandatoryApplication.cs | 2 +- .../Repository/CheckoutRepository.cs | 497 +++++++++--------- .../Repository/RollCallEmployeeRepository.cs | 23 +- .../Repository/RollCallMandatoryRepository.cs | 12 +- .../Repository/YearlySalaryRepository.cs | 2 +- .../Admin/Controllers/CheckoutController.cs | 43 +- .../Pages/Company/Checkouts/Index.cshtml.cs | 1 + ServiceHost/Hubs/CheckoutHub.cs | 18 - 15 files changed, 541 insertions(+), 315 deletions(-) create mode 100644 CompanyManagment.App.Contracts/Hubs/CheckoutHub.cs delete mode 100644 ServiceHost/Hubs/CheckoutHub.cs diff --git a/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs b/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs index f7bec585..d5af76a7 100644 --- a/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs +++ b/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs @@ -16,7 +16,7 @@ namespace Company.Domain.RollCallAgg; public interface IRollCallMandatoryRepository : IRepository { - ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout, bool rotatingShiftCompute, double dailyWageUnAffected, bool totalLeaveCompute); + Task MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout, bool rotatingShiftCompute, double dailyWageUnAffected, bool totalLeaveCompute); /// /// محاسبه ساعات کارکرد پرسنل در صورت داشتن حضور غیاب diff --git a/Company.Domain/RollCallEmployeeAgg/IRollCallEmployeeRepository.cs b/Company.Domain/RollCallEmployeeAgg/IRollCallEmployeeRepository.cs index 3c164b50..537db5c7 100644 --- a/Company.Domain/RollCallEmployeeAgg/IRollCallEmployeeRepository.cs +++ b/Company.Domain/RollCallEmployeeAgg/IRollCallEmployeeRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework.Domain; using CompanyManagment.App.Contracts.RollCallEmployee; @@ -7,7 +8,7 @@ namespace Company.Domain.RollCallEmployeeAgg; public interface IRollCallEmployeeRepository : IRepository { - bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd); + Task HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd); List GetByWorkshopId(long workshopId); EditRollCallEmployee GetDetails(long id); RollCallEmployeeViewModel GetByEmployeeIdAndWorkshopId(long employeeId, long workshopId); diff --git a/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs b/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs index 6ee91430..dd5e7891 100644 --- a/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs +++ b/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs @@ -1,4 +1,5 @@ -using CompanyManagment.App.Contracts.Contract; +using System; +using CompanyManagment.App.Contracts.Contract; using CompanyManagment.App.Contracts.EmployeeComputeOptions; using CompanyManagment.App.Contracts.WorkingHoursTemp; using System.Collections.Generic; @@ -25,6 +26,26 @@ public class GetContractAndIncludesDataToCreateDto /// public string ArchiveCode { get; set; } + /// + /// آیا تنظیمات کارگاه بر رو ایجاد فیش استاتیک است + /// + public bool IsStaticCheckout { get; set; } + + /// + /// آیا کارگاه در تعطیلات رسمی باز است + /// + public bool WorkshopHolidayWorking { get; set; } + + /// + /// محاسبه نوبت کاری در فیش حقوقی + /// + public bool RotatingShiftCompute { get; set; } + + + /// + /// آیا پاداش در فیش حقوقی محاسبه شود + /// + public bool RewardComputeOnCheckout { get; set; } public List ContractIncludedData { get; set; } @@ -85,10 +106,71 @@ public class ContractIncludedData /// /// اطلاعات جداسازی تاریخ فیش /// - public ContractSeparationViewModel Saparation { get; set; } + public ContractSeparationViewModel Separation { get; set; } /// /// تنظیمات فنی پرسنل + /// سنوات /// - public EmployeeComputeOptionsViewModel EmployeeOption { get; set; } + public string YearsOption { get; set; } + + + /// + /// تنظیمات فنی پرسنل + /// عیدی و پاداش + /// + public string BonusesOption { get; set; } + + + + /// + /// تنظیمات فنی پرسنل + /// مزد مرخصی + /// + public string ComputeOption { get; set; } + + + /// + /// ترایخ شروع قراداد + /// شمسی + /// + public string ContractStart { get; set; } + + /// + /// تاریخ پایان قرارداد + /// شمسی + /// + public string ContractEnd { get; set; } + + /// + /// ترایخ شروع قراداد + /// میلادی + /// + public DateTime ContractStartGr { get; set; } + + /// + /// تاریخ پایان قرارداد + /// میلادی + /// + public DateTime ContractEndGr { get; set; } + + /// + /// آی دی قراداد + /// + public long ContractId { get; set; } + + /// + /// مزد روزانه قرداد بدون تاثیر ساعات کار + /// + public double DailySalaryUnAffected { get; set; } + + /// + /// نوع مزد روزانه + /// + public string DailyWageType { get; set; } + + /// + /// اولین شروع بکار پرسنل + /// + public string FirstGetWorkingDay { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs index e513875c..d10e24e1 100644 --- a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs +++ b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs @@ -113,7 +113,7 @@ public interface ICheckoutApplication /// /// /// - Task> CreateCheckoutApi(List ids, string year, string month, long workshopId); + Task CreateCheckoutApi(List ids, string year, string month, long workshopId); #endregion } diff --git a/CompanyManagment.App.Contracts/Hubs/CheckoutHub.cs b/CompanyManagment.App.Contracts/Hubs/CheckoutHub.cs new file mode 100644 index 00000000..8c876cac --- /dev/null +++ b/CompanyManagment.App.Contracts/Hubs/CheckoutHub.cs @@ -0,0 +1,18 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.SignalR; + +namespace CompanyManagment.App.Contracts.Hubs; + +public class CheckoutHub : Hub +{ + + public async Task send(long id) + { + await Groups.AddToGroupAsync(Context.ConnectionId, GetGroupName(id)); + } + + public static string GetGroupName(long id) + { + return $"group-Checkout-{id}"; + } +} \ No newline at end of file diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 11eedd3b..e5681473 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -7,6 +7,7 @@ using Company.Domain.empolyerAgg; using Company.Domain.LeaveAgg; using Company.Domain.LeftWorkAgg; using Company.Domain.RollCallAgg; +using Company.Domain.RollCallEmployeeAgg; using Company.Domain.WorkingHoursTempAgg; using Company.Domain.WorkshopAgg; using Company.Domain.YearlySalaryAgg; @@ -14,6 +15,7 @@ using CompanyManagment.App.Contracts.Checkout; using CompanyManagment.App.Contracts.Checkout.Dto; using CompanyManagment.App.Contracts.Contract; using CompanyManagment.App.Contracts.HolidayItem; +using CompanyManagment.App.Contracts.Hubs; using CompanyManagment.App.Contracts.Leave; using CompanyManagment.App.Contracts.MandantoryHours; using CompanyManagment.App.Contracts.PersonalContractingParty; @@ -23,8 +25,10 @@ using CompanyManagment.App.Contracts.Workshop; using CompanyManagment.EFCore.Migrations; using CompanyManagment.EFCore.Repository; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; @@ -48,12 +52,13 @@ public class CheckoutApplication : ICheckoutApplication private readonly IWorkingHoursTempRepository _workingHoursTempRepository; private readonly IWorkshopRepository _workshopRepository; private readonly IAuthHelper _authHelper; - + private readonly IHubContext _hubContext; + private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; public CheckoutApplication(ICheckoutRepository checkoutRepository, IYearlySalaryRepository yearlySalaryRepository, ILeftWorkRepository leftWorkRepository, - IEmployerRepository employerRepository, IPersonalContractingPartyApp contractingPartyApp, ILeaveApplication leaveApplication, IMandatoryHoursApplication mandatoryHoursApplication, IRollCallMandatoryRepository rollCallMandatoryRepository, IRollCallRepository rollCallRepository, IHolidayItemApplication holidayItemApplication, IWorkingHoursTempRepository workingHoursTempRepository, IWorkshopRepository workshopRepository, IAuthHelper authHelper) + IEmployerRepository employerRepository, IPersonalContractingPartyApp contractingPartyApp, ILeaveApplication leaveApplication, IMandatoryHoursApplication mandatoryHoursApplication, IRollCallMandatoryRepository rollCallMandatoryRepository, IRollCallRepository rollCallRepository, IHolidayItemApplication holidayItemApplication, IWorkingHoursTempRepository workingHoursTempRepository, IWorkshopRepository workshopRepository, IAuthHelper authHelper, IHubContext hubContext, IRollCallEmployeeRepository rollCallEmployeeRepository) { _checkoutRepository = checkoutRepository; _yearlySalaryRepository = yearlySalaryRepository; @@ -68,6 +73,8 @@ public class CheckoutApplication : ICheckoutApplication _workingHoursTempRepository = workingHoursTempRepository; _workshopRepository = workshopRepository; _authHelper = authHelper; + _hubContext = hubContext; + _rollCallEmployeeRepository = rollCallEmployeeRepository; } [SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records", MessageId = "count: 241")] @@ -799,38 +806,15 @@ public class CheckoutApplication : ICheckoutApplication } - public async Task> CreateCheckoutApi(List ids, string year, string month, long workshopId) + public async Task CreateCheckoutApi(List ids, string year, string month, long workshopId) { + var op = new OperationResult(); //آی دی کاربر لاگین شده برای استفاده در signalR - var currentAcc = _authHelper.CurrentAccountId(); + var currntAcc = _authHelper.CurrentAccountId(); - #region Validation - //if (!string.IsNullOrWhiteSpace(year) && string.IsNullOrWhiteSpace(month)) - // return op.Failed("ماه را انتخاب کنید"); - //if (string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month)) - // return op.Failed("سال را انتخاب کنید"); - - //if (string.IsNullOrWhiteSpace(year) && string.IsNullOrWhiteSpace(month)) - //{ - // year = "0"; - // month = "0"; - - // var today = DateTime.Now; - // var FaToday = today.ToFarsi(); - // var convertedYear = FaToday.Substring(0, 4); - // var convertedMonth = FaToday.Substring(5, 2); - - // year = convertedYear; - // month = convertedMonth; - //} - - //if (ids.Count == 0) - // return op.Failed("هیچ موردی انتخاب نشده اشت"); - - #endregion #region GetInsuranceData @@ -839,9 +823,108 @@ public class CheckoutApplication : ICheckoutApplication #endregion - var getContcatsData = await + var getContractsData = await _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, year, month, workshopId); - return getContcatsData; + + if (!getContractsData.IsSuccedded) + { + await _hubContext.Clients.Group(CheckoutHub.GetGroupName(currntAcc)) + .SendAsync("StartProcessingFailed", getContractsData.Message); + return op.Failed(getContractsData.Message); + } + var timer = new Stopwatch(); + timer.Start(); + int i = 0; + foreach (var item in getContractsData.Data.ContractIncludedData) + { + + //آیا کل مرخصی به ساعت کاراضافه شود؟ + bool totalLeaveCompute = false; + //آیا غیبت محاسبه شود؟ + bool abcenseDeduction = false; + switch (item.ComputeOption) + { + case "OnEndOfYear": + var endOfYearCheckout = item.Separation.ContractEnd.Substring(5, 2); + + totalLeaveCompute = true; + abcenseDeduction = item.Separation.HasLeft || endOfYearCheckout == "12"; + break; + case "OnLeftWork": + + totalLeaveCompute = true; + abcenseDeduction = item.Separation.HasLeft; + break; + case "OnEndOfContract": + var startMonth = item.ContractStart.Substring(5, 2); + var endMonth = item.ContractEnd.Substring(5, 2); + + totalLeaveCompute = startMonth != endMonth; + abcenseDeduction = (startMonth != endMonth && item.Separation.HasLeft) || (startMonth != endMonth && item.ContractEndGr == item.Separation.ContractEndGr); + break; + } + + + //دستمزد روزانه بدون تاثیر ساعت کار + #region DailyWageCompute + + var contract = new EditContract() + { + ContractStartGr = item.ContractStartGr, + ContractEndGr = item.ContractEndGr, + DailySalaryUnAffected = item.DailySalaryUnAffected, + DailyWageType = item.DailyWageType, + ContarctStart = item.ContractStart, + ContractEnd = item.ContractEnd, + GetWorkDate = item.FirstGetWorkingDay, + GetWorkDateHide = item.FirstGetWorkingDay, + + }; + + //دستمزد روزانه بدون تاثیر ساعت کار + var dailyWageUnAffected =await _yearlySalaryRepository.GetCheckoutDailyWage(contract, + item.Separation.ContractStartGr, item.Separation.ContractEndGr); + + #endregion + + + + + var hasRollCall =await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, item.Separation.ContractStartGr, item.Separation.ContractEndGr); + if (getContractsData.Data.IsStaticCheckout) + hasRollCall = false; + + //محاسبه موظفی + #region MandatoryCompute + var mandatoryCompute = new ComputingViewModel(); + + item.WorkingHours.ContractStartGr = item.Separation.ContractStartGr; + item.WorkingHours.ContractEndGr = item.Separation.ContractEndGr; + item.WorkingHours.ContarctStart = item.Separation.ContarctStart; + item.WorkingHours.ContractEnd = item.Separation.ContractEnd; + item.WorkingHours.GetWorkDate = contract.GetWorkDate; + item.WorkingHours.GetWorkDateHide = contract.GetWorkDate; + item.WorkingHours.WorkshopId = workshopId; + item.WorkingHours.EmployeeId = item.EmployeeId; + + mandatoryCompute =await _rollCallMandatoryRepository.MandatoryCompute(item.EmployeeId, workshopId, + item.Separation.ContractStartGr, item.Separation.ContractEndGr, item.WorkingHours, getContractsData.Data.WorkshopHolidayWorking, + hasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); + + #endregion + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("================================================================== "); + Console.WriteLine("========================================Counter ================== " + (i+1)); + Console.WriteLine("================================================================== "); + Console.ResetColor(); + i += 1; + } + + + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("after GetData To mandatoryCompute" + timer.Elapsed); + Console.ResetColor(); + return op.Succcedded(); } #endregion diff --git a/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs b/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs index 44acfd3e..596fa3e9 100644 --- a/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs +++ b/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs @@ -90,7 +90,7 @@ namespace CompanyManagment.Application public bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd) { - return _rollCallEmployeeRepository.HasRollCallRecord(employeeId, workshopId, contractStart, contractEnd); + return _rollCallEmployeeRepository.HasRollCallRecord(employeeId, workshopId, contractStart, contractEnd).GetAwaiter().GetResult(); } public List GetActiveByWorkshopIdInDate(long workshopId, DateTime startDateGr, DateTime endDateGr) diff --git a/CompanyManagment.Application/RollCallMandatoryApplication.cs b/CompanyManagment.Application/RollCallMandatoryApplication.cs index dd9bbd39..ea16f367 100644 --- a/CompanyManagment.Application/RollCallMandatoryApplication.cs +++ b/CompanyManagment.Application/RollCallMandatoryApplication.cs @@ -24,7 +24,7 @@ public class RollCallMandatoryApplication : IRollCallMandatoryApplication public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout, bool rotatingShiftCompute, double dailyWageUnAffected, bool totalLeaveCompute) { - return _rollCallMandatoryRepository.MandatoryCompute(employeeId,workshopId, contractStart, contractEnd, command, holidayWorking, isStaticCheckout, rotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); + return _rollCallMandatoryRepository.MandatoryCompute(employeeId,workshopId, contractStart, contractEnd, command, holidayWorking, isStaticCheckout, rotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute).GetAwaiter().GetResult(); } diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 1321ab42..144cb9cd 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -301,7 +301,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos : startSreach; bool hasRollCall = _rollCallEmployeeRepository.HasRollCallRecord(employeeJoin, workshopId, startStatusSearch, - endStatusSearch); + endStatusSearch).GetAwaiter().GetResult(); bool extension = true; bool laterThanEnd = false; @@ -321,7 +321,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { // اگر ترک کار کرده بود // اگر ترک کارش در بازه انتخاب شده بود - if (leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch) + var leftFirstDayOfNextMonth = endSearch.AddDays(1); + if (leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= leftFirstDayOfNextMonth) { //اگر بازه انتخاب شده در تاریخ جاری بود if (startSreach == currentStart && endSearch == currentEnd) @@ -4007,293 +4008,293 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } - foreach (var item in seprationData) - { - bool hasLeft = false; - var ContractEnd = item.ContractEnd; - var contractStart = item.ContarctStart; - var leftWork = leftWorks.FirstOrDefault(x => x.EmployeeId == item.EmployeeId && item.ContarctStart <= x.LeftWorkDate && item.ContractEnd >= x.StartWorkDate); - if (leftWork == null) - { - separation.Add(new ContractSeparationViewModel() - { - checker = false, - EmployeeId = item.EmployeeId - }); + //foreach (var item in seprationData) + //{ + // bool hasLeft = false; + // var ContractEnd = item.ContractEnd; + // var contractStart = item.ContarctStart; + // var leftWork = leftWorks.FirstOrDefault(x => x.EmployeeId == item.EmployeeId && item.ContarctStart <= x.LeftWorkDate && item.ContractEnd >= x.StartWorkDate); + // if (leftWork == null) + // { + // separation.Add(new ContractSeparationViewModel() + // { + // checker = false, + // EmployeeId = item.EmployeeId + // }); - } + // } - if (leftWork.HasLeft && leftWork.LeftWorkDate < item.ContractEnd && - leftWork.LeftWorkDate >= item.ContarctStart) - { - ContractEnd = leftWork.LeftWorkDate.AddDays(-1); - hasLeft = true; - var start = contractStart.ToFarsi(); - var end = ContractEnd.ToFarsi(); - var ContractPreiodsList = new List(); - var CheckoutMonth = int.Parse(month); + // if (leftWork.HasLeft && leftWork.LeftWorkDate < item.ContractEnd && + // leftWork.LeftWorkDate >= item.ContarctStart) + // { + // ContractEnd = leftWork.LeftWorkDate.AddDays(-1); + // hasLeft = true; + // var start = contractStart.ToFarsi(); + // var end = ContractEnd.ToFarsi(); + // var ContractPreiodsList = new List(); + // var CheckoutMonth = int.Parse(month); - var syear = Convert.ToInt32(start.Substring(0, 4)); - var smonth = Convert.ToInt32(start.Substring(5, 2)); - var sday = Convert.ToInt32(start.Substring(8, 2)); + // var syear = Convert.ToInt32(start.Substring(0, 4)); + // var smonth = Convert.ToInt32(start.Substring(5, 2)); + // var sday = Convert.ToInt32(start.Substring(8, 2)); - var eyear = Convert.ToInt32(end.Substring(0, 4)); - var emonth = Convert.ToInt32(end.Substring(5, 2)); - var eday = Convert.ToInt32(end.Substring(8, 2)); + // var eyear = Convert.ToInt32(end.Substring(0, 4)); + // var emonth = Convert.ToInt32(end.Substring(5, 2)); + // var eday = Convert.ToInt32(end.Substring(8, 2)); - var PersianStartDate = new PersianDateTime(syear, smonth, sday); - var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); - var PersianEndDate = new PersianDateTime(eyear, emonth, eday); + // var PersianStartDate = new PersianDateTime(syear, smonth, sday); + // var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); + // var PersianEndDate = new PersianDateTime(eyear, emonth, eday); - var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; - for (int i = 0; i < totalmonth; i++) - { + // var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; + // for (int i = 0; i < totalmonth; i++) + // { - var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); - if (currentEndDate > PersianEndDate) - { - currentEndDate = PersianEndDate; - } + // var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); + // if (currentEndDate > PersianEndDate) + // { + // currentEndDate = PersianEndDate; + // } - var period = new PeriodStartEnd - { - startC = PersianStartDate.ToString("yyyy/MM/dd"), - endC = currentEndDate.ToString("yyyy/MM/dd"), - monthC = currentEndDate.Month - }; - ContractPreiodsList.Add(period); - //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); + // var period = new PeriodStartEnd + // { + // startC = PersianStartDate.ToString("yyyy/MM/dd"), + // endC = currentEndDate.ToString("yyyy/MM/dd"), + // monthC = currentEndDate.Month + // }; + // ContractPreiodsList.Add(period); + // //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); - PersianStartDate = PersianStartDate.AddMonths(1); - PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); + // PersianStartDate = PersianStartDate.AddMonths(1); + // PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); - } + // } - var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); - if (periodSelect != null) - { - var startDate = periodSelect.startC.ToGeorgianDateTime(); - var endDate = periodSelect.endC.ToGeorgianDateTime(); + // var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); + // if (periodSelect != null) + // { + // var startDate = periodSelect.startC.ToGeorgianDateTime(); + // var endDate = periodSelect.endC.ToGeorgianDateTime(); - separation.Add(new ContractSeparationViewModel() - { - StartWorkDate = leftWork.StartWorkDate, - LeftWorkDate = ContractEnd, - HasLeft = hasLeft, - ContarctStart = periodSelect.startC, - ContractEnd = periodSelect.endC, - ContractStartGr = startDate, - ContractEndGr = endDate, - checker = true, - EmployeeId = item.EmployeeId - }); + // separation.Add(new ContractSeparationViewModel() + // { + // StartWorkDate = leftWork.StartWorkDate, + // LeftWorkDate = ContractEnd, + // HasLeft = hasLeft, + // ContarctStart = periodSelect.startC, + // ContractEnd = periodSelect.endC, + // ContractStartGr = startDate, + // ContractEndGr = endDate, + // checker = true, + // EmployeeId = item.EmployeeId + // }); - } - else - { - separation.Add(new ContractSeparationViewModel() - { - checker = false, - EmployeeId = item.EmployeeId - }); + // } + // else + // { + // separation.Add(new ContractSeparationViewModel() + // { + // checker = false, + // EmployeeId = item.EmployeeId + // }); - } - } + // } + // } - if (leftWork.HasLeft && leftWork.LeftWorkDate >= item.ContractEnd && - leftWork.LeftWorkDate > item.ContarctStart) - { - var lastWorkDay = leftWork.LeftWorkDate.AddDays(-1); + // if (leftWork.HasLeft && leftWork.LeftWorkDate >= item.ContractEnd && + // leftWork.LeftWorkDate > item.ContarctStart) + // { + // var lastWorkDay = leftWork.LeftWorkDate.AddDays(-1); - if (leftWork.LeftWorkDate == ContractEnd) - { - ContractEnd = lastWorkDay; - hasLeft = true; - } + // if (leftWork.LeftWorkDate == ContractEnd) + // { + // ContractEnd = lastWorkDay; + // hasLeft = true; + // } - if (lastWorkDay == ContractEnd) - { - hasLeft = true; - } + // if (lastWorkDay == ContractEnd) + // { + // hasLeft = true; + // } - var start = contractStart.ToFarsi(); - var end = ContractEnd.ToFarsi(); - var ContractPreiodsList = new List(); - var CheckoutMonth = int.Parse(month); + // var start = contractStart.ToFarsi(); + // var end = ContractEnd.ToFarsi(); + // var ContractPreiodsList = new List(); + // var CheckoutMonth = int.Parse(month); - var syear = Convert.ToInt32(start.Substring(0, 4)); - var smonth = Convert.ToInt32(start.Substring(5, 2)); - var sday = Convert.ToInt32(start.Substring(8, 2)); + // var syear = Convert.ToInt32(start.Substring(0, 4)); + // var smonth = Convert.ToInt32(start.Substring(5, 2)); + // var sday = Convert.ToInt32(start.Substring(8, 2)); - var eyear = Convert.ToInt32(end.Substring(0, 4)); - var emonth = Convert.ToInt32(end.Substring(5, 2)); - var eday = Convert.ToInt32(end.Substring(8, 2)); + // var eyear = Convert.ToInt32(end.Substring(0, 4)); + // var emonth = Convert.ToInt32(end.Substring(5, 2)); + // var eday = Convert.ToInt32(end.Substring(8, 2)); - var PersianStartDate = new PersianDateTime(syear, smonth, sday); - var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); - var PersianEndDate = new PersianDateTime(eyear, emonth, eday); + // var PersianStartDate = new PersianDateTime(syear, smonth, sday); + // var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); + // var PersianEndDate = new PersianDateTime(eyear, emonth, eday); - var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; - for (int i = 0; i < totalmonth; i++) - { + // var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; + // for (int i = 0; i < totalmonth; i++) + // { - var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); - if (currentEndDate > PersianEndDate) - { - currentEndDate = PersianEndDate; - } + // var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); + // if (currentEndDate > PersianEndDate) + // { + // currentEndDate = PersianEndDate; + // } - var period = new PeriodStartEnd - { - startC = PersianStartDate.ToString("yyyy/MM/dd"), - endC = currentEndDate.ToString("yyyy/MM/dd"), - monthC = currentEndDate.Month - }; - ContractPreiodsList.Add(period); - //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); + // var period = new PeriodStartEnd + // { + // startC = PersianStartDate.ToString("yyyy/MM/dd"), + // endC = currentEndDate.ToString("yyyy/MM/dd"), + // monthC = currentEndDate.Month + // }; + // ContractPreiodsList.Add(period); + // //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); - PersianStartDate = PersianStartDate.AddMonths(1); - PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); + // PersianStartDate = PersianStartDate.AddMonths(1); + // PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); - } + // } - var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); - if (periodSelect != null) - { - var startDate = periodSelect.startC.ToGeorgianDateTime(); - var endDate = periodSelect.endC.ToGeorgianDateTime(); + // var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); + // if (periodSelect != null) + // { + // var startDate = periodSelect.startC.ToGeorgianDateTime(); + // var endDate = periodSelect.endC.ToGeorgianDateTime(); - separation.Add(new ContractSeparationViewModel() - { - StartWorkDate = leftWork.StartWorkDate, - LeftWorkDate = ContractEnd, - HasLeft = hasLeft, - ContarctStart = periodSelect.startC, - ContractEnd = periodSelect.endC, - ContractStartGr = startDate, - ContractEndGr = endDate, - checker = true, - EmployeeId = item.EmployeeId - }); + // separation.Add(new ContractSeparationViewModel() + // { + // StartWorkDate = leftWork.StartWorkDate, + // LeftWorkDate = ContractEnd, + // HasLeft = hasLeft, + // ContarctStart = periodSelect.startC, + // ContractEnd = periodSelect.endC, + // ContractStartGr = startDate, + // ContractEndGr = endDate, + // checker = true, + // EmployeeId = item.EmployeeId + // }); - } - else - { - separation.Add(new ContractSeparationViewModel() - { - checker = false, - EmployeeId = item.EmployeeId - }); + // } + // else + // { + // separation.Add(new ContractSeparationViewModel() + // { + // checker = false, + // EmployeeId = item.EmployeeId + // }); - } - } - else if (leftWork.HasLeft && contractStart > leftWork.LeftWorkDate) - { + // } + // } + // else if (leftWork.HasLeft && contractStart > leftWork.LeftWorkDate) + // { - separation.Add(new ContractSeparationViewModel() - { - checker = false, - EmployeeId = item.EmployeeId - }); + // separation.Add(new ContractSeparationViewModel() + // { + // checker = false, + // EmployeeId = item.EmployeeId + // }); - } - else if (!leftWork.HasLeft) - { - var start = contractStart.ToFarsi(); - var end = ContractEnd.ToFarsi(); - var ContractPreiodsList = new List(); - var CheckoutMonth = int.Parse(month); + // } + // else if (!leftWork.HasLeft) + // { + // var start = contractStart.ToFarsi(); + // var end = ContractEnd.ToFarsi(); + // var ContractPreiodsList = new List(); + // var CheckoutMonth = int.Parse(month); - var syear = Convert.ToInt32(start.Substring(0, 4)); - var smonth = Convert.ToInt32(start.Substring(5, 2)); - var sday = Convert.ToInt32(start.Substring(8, 2)); + // var syear = Convert.ToInt32(start.Substring(0, 4)); + // var smonth = Convert.ToInt32(start.Substring(5, 2)); + // var sday = Convert.ToInt32(start.Substring(8, 2)); - var eyear = Convert.ToInt32(end.Substring(0, 4)); - var emonth = Convert.ToInt32(end.Substring(5, 2)); - var eday = Convert.ToInt32(end.Substring(8, 2)); + // var eyear = Convert.ToInt32(end.Substring(0, 4)); + // var emonth = Convert.ToInt32(end.Substring(5, 2)); + // var eday = Convert.ToInt32(end.Substring(8, 2)); - var PersianStartDate = new PersianDateTime(syear, smonth, sday); - var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); - var PersianEndDate = new PersianDateTime(eyear, emonth, eday); + // var PersianStartDate = new PersianDateTime(syear, smonth, sday); + // var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1); + // var PersianEndDate = new PersianDateTime(eyear, emonth, eday); - var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; - for (int i = 0; i < totalmonth; i++) - { + // var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1; + // for (int i = 0; i < totalmonth; i++) + // { - var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); - if (currentEndDate > PersianEndDate) - { - currentEndDate = PersianEndDate; - } + // var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1); + // if (currentEndDate > PersianEndDate) + // { + // currentEndDate = PersianEndDate; + // } - var period = new PeriodStartEnd - { - startC = PersianStartDate.ToString("yyyy/MM/dd"), - endC = currentEndDate.ToString("yyyy/MM/dd"), - monthC = currentEndDate.Month - }; - ContractPreiodsList.Add(period); - //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); + // var period = new PeriodStartEnd + // { + // startC = PersianStartDate.ToString("yyyy/MM/dd"), + // endC = currentEndDate.ToString("yyyy/MM/dd"), + // monthC = currentEndDate.Month + // }; + // ContractPreiodsList.Add(period); + // //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}"); - PersianStartDate = PersianStartDate.AddMonths(1); - PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); + // PersianStartDate = PersianStartDate.AddMonths(1); + // PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1); - } + // } - var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); - if (periodSelect != null) - { - var startDate = periodSelect.startC.ToGeorgianDateTime(); - var endDate = periodSelect.endC.ToGeorgianDateTime(); + // var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth); + // if (periodSelect != null) + // { + // var startDate = periodSelect.startC.ToGeorgianDateTime(); + // var endDate = periodSelect.endC.ToGeorgianDateTime(); - separation.Add(new ContractSeparationViewModel() - { - StartWorkDate = leftWork.StartWorkDate, - HasLeft = hasLeft, - ContarctStart = periodSelect.startC, - ContractEnd = periodSelect.endC, - ContractStartGr = startDate, - ContractEndGr = endDate, - checker = true, - LeftWorkDate = new DateTime(2121, 3, 21), - EmployeeId = item.EmployeeId - }); + // separation.Add(new ContractSeparationViewModel() + // { + // StartWorkDate = leftWork.StartWorkDate, + // HasLeft = hasLeft, + // ContarctStart = periodSelect.startC, + // ContractEnd = periodSelect.endC, + // ContractStartGr = startDate, + // ContractEndGr = endDate, + // checker = true, + // LeftWorkDate = new DateTime(2121, 3, 21), + // EmployeeId = item.EmployeeId + // }); - } - else - { - separation.Add(new ContractSeparationViewModel() - { - checker = false, - EmployeeId = item.EmployeeId - }); + // } + // else + // { + // separation.Add(new ContractSeparationViewModel() + // { + // checker = false, + // EmployeeId = item.EmployeeId + // }); - } - } - else - { - separation.Add(new ContractSeparationViewModel() - { - checker = false, - EmployeeId = item.EmployeeId - }); + // } + // } + // else + // { + // separation.Add(new ContractSeparationViewModel() + // { + // checker = false, + // EmployeeId = item.EmployeeId + // }); - } - } + // } + //} @@ -4325,14 +4326,21 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var toListTimer = new Stopwatch(); toListTimer.Start(); + var yearsOption = workshop.YearsOptions; + var bonusesOption = workshop.BonusesOptions; + var computeOption = workshop.ComputeOptions; var incloudedData = getContracts.Select(x => { + + var employeeOption = employeeOptions.FirstOrDefault(option => option.EmployeeId == x.EmployeeId); + if(employeeOption != null) + { + yearsOption = employeeOption.YearsOptions; + bonusesOption = employeeOption.BonusesOptions; + computeOption = employeeOption.ComputeOptions; + } return new ContractIncludedData { - ContractNo = x.ContractNo, - - - //اطلاعات هویتی پرسنل #region EmployeeData EmployeeId = x.EmployeeId, @@ -4351,16 +4359,31 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos //اطلاعات جداسازی تاریخ فیش از قرارداد #region Saparation - Saparation = separation.FirstOrDefault(sep => sep.EmployeeId == x.EmployeeId), + Separation = separation.FirstOrDefault(sep => sep.EmployeeId == x.EmployeeId), #endregion //تنظیمات فنی پرسنل #region EmployeeOption - EmployeeOption = employeeOptions.FirstOrDefault(option=> option.EmployeeId == x.EmployeeId) + YearsOption = yearsOption, + BonusesOption = bonusesOption, + ComputeOption = computeOption, #endregion + //اطلاعات قراداد + #region ContractData + + ContractNo = x.ContractNo, + ContractStart = x.ContarctStart.ToFarsi(), + ContractEnd = x.ContractEnd.ToFarsi(), + ContractStartGr = x.ContarctStart, + ContractEndGr = x.ContractEnd, + ContractId = x.id, + DailySalaryUnAffected = x.DailySalaryUnAffected, + DailyWageType = x.DailyWageType, + FirstGetWorkingDay = x.GetWorkDate.ToFarsi(), + #endregion }; }).ToList(); @@ -4372,7 +4395,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos WorkshopId = workshop.id, ArchiveCode = workshop.ArchiveCode, WorkshopName = workshop.WorkshopName, - + IsStaticCheckout = workshop.IsStaticCheckout, #endregion diff --git a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs index b0832169..bbc15222 100644 --- a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using _0_Framework.Application; +using _0_Framework.Application; using _0_Framework.InfraStructure; using Company.Domain.RollCallEmployeeAgg; using Company.Domain.RollCallEmployeeStatusAgg; @@ -13,6 +8,12 @@ using CompanyManagment.App.Contracts.RollCallEmployee; using CompanyManagment.App.Contracts.RollCallEmployeeStatus; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace CompanyManagment.EFCore.Repository; @@ -39,7 +40,7 @@ public class RollCallEmployeeRepository : RepositoryBase } - public bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd) + public async Task HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd) { //موقت // دادمهرگستر 11 * @@ -89,8 +90,8 @@ public class RollCallEmployeeRepository : RepositoryBase //if (rollCallEmployee == null) // return false; - var rollCallEmployee = _context.RollCallEmployees.Include(xs => xs.EmployeesStatus) - .FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId); + var rollCallEmployee =await _context.RollCallEmployees.Include(xs => xs.EmployeesStatus) + .FirstOrDefaultAsync(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId); //اگر تنظیمات حضور غیاب نداشت if (rollCallEmployee == null) return false; @@ -99,8 +100,8 @@ public class RollCallEmployeeRepository : RepositoryBase if (!rollCallEmployee.EmployeesStatus.Any()) return false; - var leftWork = - _context.LeftWorkList.FirstOrDefault(x => + var leftWork = await + _context.LeftWorkList.FirstOrDefaultAsync(x => x.StartWorkDate <= contractEnd.Date && x.LeftWorkDate > contractStart); if (leftWork == null) return false; diff --git a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs index 7b6d8a7e..ee367bc9 100644 --- a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs @@ -65,7 +65,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll #region OfficialChckout - public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, + public async Task MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout, bool rotatingShiftCompute, double dailyWageUnAffected, bool totalLeaveCompute) @@ -86,7 +86,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll int TotalContractDays = (int)(contractEnd - contractStart).TotalDays + 1; int fridays = 0; - int holiday = _context.HolidayItems.Count(x => x.Holidaydate >= contractStart && x.Holidaydate <= contractEnd); + int holiday =await _context.HolidayItems.CountAsync(x => x.Holidaydate >= contractStart && x.Holidaydate <= contractEnd); ; for (var gDate = contractStart; gDate <= contractEnd; gDate = gDate.AddDays(1)) { @@ -117,8 +117,8 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll #region breakTime - BaseCustomizeEntity settings = _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery() - .Include(x => x.CustomizeWorkshopGroupSettings).FirstOrDefault(x => + BaseCustomizeEntity settings =await _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery() + .Include(x => x.CustomizeWorkshopGroupSettings).FirstOrDefaultAsync(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId); //اگر ساعت استراحت پرسنل وجود نداشت صفر است var breakTimeEntity = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime; @@ -196,7 +196,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll } else { - rollCallResult = _context.RollCalls.Where(x => + rollCallResult =await _context.RollCalls.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate.Value.Date >= contractStart.Date && x.StartDate.Value.Date <= contractEnd.Date && x.EndDate != null).Select(x => new RollCallViewModel() @@ -206,7 +206,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll ShiftSpan = (x.EndDate.Value - x.StartDate.Value), CreationDate = x.ShiftDate, BreakTimeSpan = x.BreakTimeSpan - }).ToList(); + }).ToListAsync(); groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.Date).Select(x => { diff --git a/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs b/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs index edef4117..70529b65 100644 --- a/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs +++ b/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs @@ -2789,7 +2789,7 @@ public class YearlySalaryRepository : RepositoryBase, IYearl private (bool hasRollCall, double WorkingTotalHours) GetTotalWorkingHoursIfHasRollCall(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd) { bool hasRollCall = _rollCallEmployeeRepository.HasRollCallRecord(employeeId, workshopId, - contractStart, contractEnd); + contractStart, contractEnd).GetAwaiter().GetResult(); double totalWorkingHours = 0; if (!hasRollCall) return (false, 0); diff --git a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs index 9be056d6..c53f0e30 100644 --- a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs +++ b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs @@ -139,8 +139,9 @@ public class CheckoutController : AdminBaseController /// /// [HttpPost] - public async Task> CreateCheckout([FromBody]TestCreateCheckout command) + public async Task CreateCheckout([FromBody]TestCreateCheckout command) { + var op = new OperationResult>(); var ids = new List() { @@ -165,12 +166,34 @@ public class CheckoutController : AdminBaseController 290547, 290548, 290549, 290550, 290551, 290552, 290553, 290554, 290555, 290556, 290557, 290558, 290559, 290560, 290561, 290562, 290563, 290564, 290565, 290566, 290567, 290568, 290569, 290570, 290571, 290572, 290573, 290574, 290575, 290576, 290577, 290578, 290579, 290580, 290581, 290582, 290583, 290584, 290585, - 290586, 290587, 290588 + 299612, 290587, 290588 }; + // var ids = new List(){ 299612 }; + + if (!string.IsNullOrWhiteSpace(command.year) && string.IsNullOrWhiteSpace(command.Month)) + return BadRequest(); + if (string.IsNullOrWhiteSpace(command.year) && !string.IsNullOrWhiteSpace(command.Month)) + return BadRequest(); + + if (string.IsNullOrWhiteSpace(command.year) && string.IsNullOrWhiteSpace(command.Month)) + { - + + var today = DateTime.Now; + var FaToday = today.ToFarsi(); + var convertedYear = FaToday.Substring(0, 4); + var convertedMonth = FaToday.Substring(5, 2); + + command.year = convertedYear; + command.Month = convertedMonth; + } + + if (ids.Count == 0 || command.WorkshopId == 0) + return BadRequest(); + var test = await _checkoutApplication.CreateCheckoutApi(ids, command.year, command.Month, command.WorkshopId); - return test; + return Ok(); + } #endregion @@ -181,4 +204,16 @@ public class TestCreateCheckout public string year { get; set; } public string Month { get; set; } public long WorkshopId { get; set; } +} + + +public class Testresponse +{ + public string EmployeeName { get; set; } + public string ContractNo { get; set; } + public string Start { get; set; } + public string End { get; set; } + public bool HasLeft { get; set; } + + public string LeftDate { get; set; } } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs index 677ec096..55da8adc 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs @@ -38,6 +38,7 @@ using Company.Domain.InsuranceListAgg; using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.EFCore.Repository; using System.Linq; +using CompanyManagment.App.Contracts.Hubs; namespace ServiceHost.Areas.Admin.Pages.Company.Checkouts; diff --git a/ServiceHost/Hubs/CheckoutHub.cs b/ServiceHost/Hubs/CheckoutHub.cs deleted file mode 100644 index 3d688680..00000000 --- a/ServiceHost/Hubs/CheckoutHub.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.AspNetCore.SignalR; - -namespace ServiceHost.Hubs -{ - public class CheckoutHub : Hub - { - - public async Task send(long id) - { - await Groups.AddToGroupAsync(Context.ConnectionId, GetGroupName(id)); - } - - public static string GetGroupName(long id) - { - return $"group-Checkout-{id}"; - } - } -} From 734fd9ebca3aa03ae13902a1af606ac381206862 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Mon, 2 Feb 2026 16:37:23 +0330 Subject: [PATCH 09/13] change --- 0_Framework/Application/Tools.cs | 27 ++ .../GetContractAndIncludesDataToCreateDto.cs | 34 ++ .../CheckoutApplication.cs | 372 ++++++++++++++++-- .../Repository/CheckoutRepository.cs | 8 +- .../Pages/Company/Checkouts/Index.cshtml.cs | 2 + 5 files changed, 407 insertions(+), 36 deletions(-) diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index 4a7ee562..2708a5aa 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -41,6 +41,33 @@ public static class Tools return Regex.IsMatch(mobileNo, "^((09))(\\d{9})$"); } + /// + /// متد رند کننده مبلغ + /// استفاده شده در بیمه + /// + /// + /// + public static double GetRoundDoubleValue(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; + } + /// /// تاریخ شروع و تعداد ماه را میگیرد و تاریخ پایان قراردا را بر میگرداند /// diff --git a/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs b/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs index dd5e7891..bb2dc6b4 100644 --- a/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs +++ b/CompanyManagment.App.Contracts/Checkout/Dto/GetContractAndIncludesDataToCreateDto.cs @@ -47,6 +47,40 @@ public class GetContractAndIncludesDataToCreateDto /// public bool RewardComputeOnCheckout { get; set; } + /// + /// آیا اضافه کار فیش حقوقی در بیمه محاسبه شود + /// + public bool HasInsuranceCheckoutOverTime { get; set; } + + /// + /// آی دی صنف بیمه کارگاه + /// + public long? InsuranceJobId { get; set; } + + /// + /// آیا کارگاه مشاغل مقطوع است + /// + public bool FixedSalary { get; set; } + + /// + /// جمعیت شهر کارگاه + /// + public string Population { get; set; } + + /// + /// نوع ارسال لیست بیمه + /// + public string TypeOfInsuranceSend { get; set; } + + + /// + /// قرارداد قدیمی است؟ + /// + public bool IsOldContract { get; set; } + + + + public List ContractIncludedData { get; set; } diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index e5681473..afd4bcd3 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -2,10 +2,13 @@ using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects; using Company.Domain.CheckoutAgg; using Company.Domain.CheckoutAgg.ValueObjects; +using Company.Domain.ContractAgg; using Company.Domain.EmployeeAgg; using Company.Domain.empolyerAgg; +using Company.Domain.InsuranceListAgg; using Company.Domain.LeaveAgg; using Company.Domain.LeftWorkAgg; +using Company.Domain.LeftWorkInsuranceAgg; using Company.Domain.RollCallAgg; using Company.Domain.RollCallEmployeeAgg; using Company.Domain.WorkingHoursTempAgg; @@ -16,12 +19,14 @@ using CompanyManagment.App.Contracts.Checkout.Dto; using CompanyManagment.App.Contracts.Contract; using CompanyManagment.App.Contracts.HolidayItem; using CompanyManagment.App.Contracts.Hubs; +using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.App.Contracts.Leave; using CompanyManagment.App.Contracts.MandantoryHours; using CompanyManagment.App.Contracts.PersonalContractingParty; using CompanyManagment.App.Contracts.RollCall; using CompanyManagment.App.Contracts.WorkingHoursTemp; using CompanyManagment.App.Contracts.Workshop; +using CompanyManagment.App.Contracts.YearlySalary; using CompanyManagment.EFCore.Migrations; using CompanyManagment.EFCore.Repository; using Microsoft.AspNetCore.Mvc; @@ -54,11 +59,16 @@ public class CheckoutApplication : ICheckoutApplication private readonly IAuthHelper _authHelper; private readonly IHubContext _hubContext; private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; + private readonly IContractRepository _contractRepository; + private readonly IInsuranceListRepository _insuranceListRepository; + private readonly ILeftWorkInsuranceRepository _leftWorkInsuranceRepository; + private readonly IInsuranceListApplication _insuranceListApplication; + public CheckoutApplication(ICheckoutRepository checkoutRepository, IYearlySalaryRepository yearlySalaryRepository, ILeftWorkRepository leftWorkRepository, - IEmployerRepository employerRepository, IPersonalContractingPartyApp contractingPartyApp, ILeaveApplication leaveApplication, IMandatoryHoursApplication mandatoryHoursApplication, IRollCallMandatoryRepository rollCallMandatoryRepository, IRollCallRepository rollCallRepository, IHolidayItemApplication holidayItemApplication, IWorkingHoursTempRepository workingHoursTempRepository, IWorkshopRepository workshopRepository, IAuthHelper authHelper, IHubContext hubContext, IRollCallEmployeeRepository rollCallEmployeeRepository) + IEmployerRepository employerRepository, IPersonalContractingPartyApp contractingPartyApp, ILeaveApplication leaveApplication, IMandatoryHoursApplication mandatoryHoursApplication, IRollCallMandatoryRepository rollCallMandatoryRepository, IRollCallRepository rollCallRepository, IHolidayItemApplication holidayItemApplication, IWorkingHoursTempRepository workingHoursTempRepository, IWorkshopRepository workshopRepository, IAuthHelper authHelper, IHubContext hubContext, IRollCallEmployeeRepository rollCallEmployeeRepository, IContractRepository contractRepository, IInsuranceListRepository insuranceListRepository, ILeftWorkInsuranceRepository leftWorkInsuranceRepository, IInsuranceListApplication insuranceListApplication) { _checkoutRepository = checkoutRepository; _yearlySalaryRepository = yearlySalaryRepository; @@ -75,6 +85,10 @@ public class CheckoutApplication : ICheckoutApplication _authHelper = authHelper; _hubContext = hubContext; _rollCallEmployeeRepository = rollCallEmployeeRepository; + _contractRepository = contractRepository; + _insuranceListRepository = insuranceListRepository; + _leftWorkInsuranceRepository = leftWorkInsuranceRepository; + _insuranceListApplication = insuranceListApplication; } [SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records", MessageId = "count: 241")] @@ -270,12 +284,12 @@ public class CheckoutApplication : ICheckoutApplication rewardPay = rewards.Sum(x => x.AmountDouble); } - - - var firstDayOfMonth = $"{command.ContractStart.Substring(0, 8)}01".ToGeorgianDateTime(); - var firstDayOfCurrentMonth = new DateTime(syear, smonth, 1, new PersianCalendar()); + + + var firstDayOfMonth = $"{command.ContractStart.Substring(0, 8)}01".ToGeorgianDateTime(); + var firstDayOfCurrentMonth = new DateTime(syear, smonth, 1, new PersianCalendar()); LeaveSearchModel sickLeaveSearch = new LeaveSearchModel() { @@ -391,12 +405,12 @@ public class CheckoutApplication : ICheckoutApplication - var totalClaimsDouble = monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + command.OvertimePay + - command.NightworkPay + familyAllowance + bunos + years + command.LeavePay + command.FridayPay + command.ShiftPay + rewardPay; - var totalClaims = totalClaimsDouble.ToMoney(); - var totalDeductionDouble = insuranceDeduction + command.AbsenceDeduction + command.InstallmentDeduction + command.SalaryAidDeduction; - var totalDeductions = totalDeductionDouble.ToMoney(); - var totalPayment = totalClaimsDouble - totalDeductionDouble; + var totalClaimsDouble = monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + command.OvertimePay + + command.NightworkPay + familyAllowance + bunos + years + command.LeavePay + command.FridayPay + command.ShiftPay + rewardPay; + var totalClaims = totalClaimsDouble.ToMoney(); + var totalDeductionDouble = insuranceDeduction + command.AbsenceDeduction + command.InstallmentDeduction + command.SalaryAidDeduction; + var totalDeductions = totalDeductionDouble.ToMoney(); + var totalPayment = totalClaimsDouble - totalDeductionDouble; if (_checkoutRepository.Exists(x => x.Month == command.Month && x.Year == command.Year && x.ContractNo == command.ContractNo)) @@ -411,13 +425,13 @@ public class CheckoutApplication : ICheckoutApplication } - var checkout = new Checkout(command.EmployeeFullName, command.FathersName, command.NationalCode - , command.DateOfBirth, command.EmployeeId, command.WorkshopName, command.WorkshopId, command.ContractNo, command.ContractStartGr, command.ContractEndGr, month, year, - command.ContractId, command.WorkingHoursId, monthlyWage, bacicYears, consumableItem, housingAllowance - , command.OvertimePay, command.NightworkPay, command.FridayPay, 0, command.ShiftPay, familyAllowance, bunos, years, command.LeavePay, insuranceDeduction, 0, command.InstallmentDeduction, command.SalaryAidDeduction, command.AbsenceDeduction, sumOfWorkingDays, - command.ArchiveCode, command.PersonnelCode, totalClaims, totalDeductions, totalPayment, command.Signature, marriedAllowance, command.LeaveCheckout, command.CreditLeaves, command.AbsencePeriod, command.AverageHoursPerDay, command.HasRollCall, command.OverTimeWorkValue, command.OverNightWorkValue - , command.FridayWorkValue, command.RotatingShiftValue, command.AbsenceValue, command.TotalDayOfLeaveCompute, command.TotalDayOfYearsCompute, command.TotalDayOfBunosesCompute, - loanInstallments, salaryAids,checkoutRollCall,command.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay); + var checkout = new Checkout(command.EmployeeFullName, command.FathersName, command.NationalCode + , command.DateOfBirth, command.EmployeeId, command.WorkshopName, command.WorkshopId, command.ContractNo, command.ContractStartGr, command.ContractEndGr, month, year, + command.ContractId, command.WorkingHoursId, monthlyWage, bacicYears, consumableItem, housingAllowance + , command.OvertimePay, command.NightworkPay, command.FridayPay, 0, command.ShiftPay, familyAllowance, bunos, years, command.LeavePay, insuranceDeduction, 0, command.InstallmentDeduction, command.SalaryAidDeduction, command.AbsenceDeduction, sumOfWorkingDays, + command.ArchiveCode, command.PersonnelCode, totalClaims, totalDeductions, totalPayment, command.Signature, marriedAllowance, command.LeaveCheckout, command.CreditLeaves, command.AbsencePeriod, command.AverageHoursPerDay, command.HasRollCall, command.OverTimeWorkValue, command.OverNightWorkValue + , command.FridayWorkValue, command.RotatingShiftValue, command.AbsenceValue, command.TotalDayOfLeaveCompute, command.TotalDayOfYearsCompute, command.TotalDayOfBunosesCompute, + loanInstallments, salaryAids, checkoutRollCall, command.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay); _checkoutRepository.CreateCkeckout(checkout).GetAwaiter().GetResult(); //_checkoutRepository.SaveChanges(); @@ -781,11 +795,11 @@ public class CheckoutApplication : ICheckoutApplication year = "0"; month = "0"; } - + var result = await GetContractResultToCreateCheckout(workshopId, employeeId, year, month, null, null); - if(result.CreateCheckoutList.Count == 0) + if (result.CreateCheckoutList.Count == 0) return op.Failed("موردی یافت نشد"); var finalResult = result.CreateCheckoutList.Select(x => new ContractsListToCreateCheckoutDto { @@ -808,7 +822,7 @@ public class CheckoutApplication : ICheckoutApplication public async Task CreateCheckoutApi(List ids, string year, string month, long workshopId) { - + var op = new OperationResult(); //آی دی کاربر لاگین شده برای استفاده در signalR @@ -817,21 +831,43 @@ public class CheckoutApplication : ICheckoutApplication + + + var getContractsData = await + _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, year, month, workshopId); + + #region GetInsuranceData - + + + var startMonthFa = $"{year}/{month.PadLeft(2, '0')}/01"; + DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); + DateTime endDateGr = startMonthFa.FindeEndOfMonth().ToGeorgianDateTime(); + int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2)); + + + var insuranceListData = + _insuranceListRepository.EmployeeInsuranceDataBy(startDateGr, getContractsData.Data.WorkshopId); + var yearlysaleries = _yearlySalaryRepository.GetInsuranceItems(startDateGr, endDateGr, year); + + var insuranceEmployeeData = + _leftWorkInsuranceRepository.GetEmployeeInsuranceLeftWorksAndInformation(getContractsData.Data.WorkshopId, startDateGr, + endDateGr); + + #endregion - var getContractsData = await - _checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, year, month, workshopId); if (!getContractsData.IsSuccedded) { - await _hubContext.Clients.Group(CheckoutHub.GetGroupName(currntAcc)) - .SendAsync("StartProcessingFailed", getContractsData.Message); - return op.Failed(getContractsData.Message); + await _hubContext.Clients.Group(CheckoutHub.GetGroupName(currntAcc)) + .SendAsync("StartProcessingFailed", getContractsData.Message); + return op.Failed(getContractsData.Message); } + + var timer = new Stopwatch(); timer.Start(); int i = 0; @@ -882,18 +918,18 @@ public class CheckoutApplication : ICheckoutApplication }; //دستمزد روزانه بدون تاثیر ساعت کار - var dailyWageUnAffected =await _yearlySalaryRepository.GetCheckoutDailyWage(contract, + var dailyWageUnAffected = await _yearlySalaryRepository.GetCheckoutDailyWage(contract, item.Separation.ContractStartGr, item.Separation.ContractEndGr); #endregion - - var hasRollCall =await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, item.Separation.ContractStartGr, item.Separation.ContractEndGr); + + var hasRollCall = await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, item.Separation.ContractStartGr, item.Separation.ContractEndGr); if (getContractsData.Data.IsStaticCheckout) hasRollCall = false; - + //محاسبه موظفی #region MandatoryCompute var mandatoryCompute = new ComputingViewModel(); @@ -906,21 +942,287 @@ public class CheckoutApplication : ICheckoutApplication item.WorkingHours.GetWorkDateHide = contract.GetWorkDate; item.WorkingHours.WorkshopId = workshopId; item.WorkingHours.EmployeeId = item.EmployeeId; - - mandatoryCompute =await _rollCallMandatoryRepository.MandatoryCompute(item.EmployeeId, workshopId, + + mandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(item.EmployeeId, workshopId, item.Separation.ContractStartGr, item.Separation.ContractEndGr, item.WorkingHours, getContractsData.Data.WorkshopHolidayWorking, hasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); #endregion + + + if (contract.EmployeeId == 9659) + mandatoryCompute.SumTime44 = "48 - 24"; + + var officialHoliday = mandatoryCompute.OfficialHoliday; + var Friday = int.Parse(mandatoryCompute.NumberOfFriday); + var fridayStartToEnd = mandatoryCompute.FridayStartToEnd; + + var totalHoursH = mandatoryCompute.TotalHoursesH; + var totalHoursM = mandatoryCompute.TotalHoursesM; + var dayliWage = mandatoryCompute.SalaryCompute.MoneyToDouble(); + var consumableItemDouble = mandatoryCompute.ConsumableItems.MoneyToDouble(); + var housingAllowanceDouble = mandatoryCompute.HousingAllowance.MoneyToDouble(); + var familyAllowanceDouble = mandatoryCompute.FamilyAllowance.MoneyToDouble(); + var marriedAllowanceDouble = mandatoryCompute.MarriedAllowance.MoneyToDouble(); + + //اضافه کاری + var overTimeWorking = _yearlySalaryRepository.GetOverTimeWorking(dayliWage, + mandatoryCompute.OverTimeWorkH, mandatoryCompute.OverTimeWorkM); + //شبکاری + var overNightWorking = _yearlySalaryRepository.GetOverNightWorking(dayliWage, + mandatoryCompute.OverNightWorkH, mandatoryCompute.OverNightWorkM, mandatoryCompute.SumTime44, + officialHoliday, Friday, item.Separation.ContractStartGr, item.Separation.ContractEndGr, totalHoursH, + totalHoursM); + + + //سنوات + var yearsPay = _yearlySalaryRepository.Years(item.Separation.ContractStartGr, item.Separation.LeftWorkDate, + item.Separation.ContractEndGr, + dayliWage, item.YearsOption, item.Separation.HasLeft, item.Separation.StartWorkDate, contract.ContractStartGr, + contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, getContractsData.Data.IsOldContract); + //عیدی + #region BonusesPay + var bunosesPay = _yearlySalaryRepository.Bunoses(item.Separation.ContarctStart, item.Separation.LeftWorkDate, + item.Separation.ContractStartGr, item.Separation.ContractEndGr, + dayliWage, item.BonusesOption, item.Separation.HasLeft, item.Separation.StartWorkDate, + contract.ContractStartGr, + contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, getContractsData.Data.IsOldContract); + //اگر تصفیه حساب پاک شده برای عیدی یا سنوات وجود داشت + if (bunosesPay.NotCompleted || yearsPay.NotCompleted) + { + + List lostCheckoutsDates = new List(); + if ((bunosesPay.NotCompleted && yearsPay.NotCompleted) || (bunosesPay.NotCompleted && !yearsPay.NotCompleted)) + lostCheckoutsDates = bunosesPay.BunosesStatusList; + if (!bunosesPay.NotCompleted && yearsPay.NotCompleted) + lostCheckoutsDates = yearsPay.BunosesStatusList; + + foreach (var found in lostCheckoutsDates) + { + ComputingViewModel foundMandatoryCompute = new ComputingViewModel(); + var foundContract = _contractRepository.GetContractByStartEnd(found.ContractStart, + found.ContractEnd, contract.WorkshopIds, contract.EmployeeId); + + if (foundContract.Id > 0) + { + var foundWorkingHours = _workingHoursTempRepository.GetByContractIdConvertToShiftwork4(foundContract.Id); + foundWorkingHours.ContractStartGr = found.ContractStart; + foundWorkingHours.ContractEndGr = found.ContractEnd; + foundWorkingHours.ContarctStart = found.ContractStart.ToFarsi(); + foundWorkingHours.ContractEnd = found.ContractEnd.ToFarsi(); + foundWorkingHours.GetWorkDate = foundContract.GetWorkDate; + foundWorkingHours.GetWorkDateHide = foundContract.GetWorkDate; + foundWorkingHours.WorkshopId = contract.WorkshopIds; + foundWorkingHours.EmployeeId = contract.EmployeeId; + bool foundHasRollCall = await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, found.ContractStart, found.ContractEnd); + + if (getContractsData.Data.IsStaticCheckout) + foundHasRollCall = false; + + foundMandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(contract.EmployeeId, + contract.WorkshopIds, + found.ContractStart, found.ContractEnd, foundWorkingHours, getContractsData.Data.WorkshopHolidayWorking, foundHasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); + + + + + + var MontlyYearsBunos = + _yearlySalaryRepository.GetMontlyBunosYears(foundMandatoryCompute.weeklyTime, found.ContractStart, found.ContractEnd, + foundMandatoryCompute.SalaryCompute.MoneyToDouble(), foundMandatoryCompute.SumTime44, foundMandatoryCompute.OfficialHoliday, + int.Parse(foundMandatoryCompute.NumberOfFriday), foundMandatoryCompute.TotalHolidayAndNotH, foundMandatoryCompute.TotalHolidayAndNotM, + foundMandatoryCompute.Basic, foundMandatoryCompute.FridayStartToEnd, foundMandatoryCompute.DayliFeeComplete, hasRollCall, getContractsData.Data.WorkshopHolidayWorking, item.WorkingHours.ShiftWork); + double foundMontlySalary = MontlyYearsBunos.MontlyWage + MontlyYearsBunos.BasicYears; + int foundTotaldays = Convert.ToInt32(MontlyYearsBunos.SumOfWorkingDay); + double foundDayliWage = foundMontlySalary / foundTotaldays; + if (bunosesPay.NotCompleted) + { + double foundBonuses = ((foundDayliWage * 60) / 365) * foundTotaldays; + bunosesPay.Bunoses += foundBonuses; + bunosesPay.TotalDayCompute += foundTotaldays; + } + + if (yearsPay.NotCompleted) + { + double foundBonuses = ((foundDayliWage * 30) / 365) * foundTotaldays; + yearsPay.YearsPay += foundBonuses; + yearsPay.TotalDayCompute += foundTotaldays; + } + + } + } + } + + #endregion + + //مزد مرخصی جدید + var leavePayNew = _yearlySalaryRepository.LeavePay(item.Separation.ContarctStart, + item.Separation.LeftWorkDate, item.Separation.ContractStartGr, item.Separation.ContractEndGr, + dayliWage, item.ComputeOption, item.Separation.HasLeft, item.Separation.StartWorkDate, + contract.ContractStartGr, + contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, fridayStartToEnd, + officialHoliday, totalHoursH, totalHoursM, consumableItemDouble, housingAllowanceDouble, + familyAllowanceDouble, marriedAllowanceDouble, getContractsData.Data.IsOldContract); + + + + + #region Insurance + + double insuranceShare = 0; + //اگر پرسنل داری شروع بکار بیمه بود + var insuranceEmployeeDataItem = + insuranceEmployeeData.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId); + + //اگر لیست بیمه برای پرسنل ساخته شده بود + var insuranceListDataWithDetails = + insuranceListData.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId); + if (insuranceListDataWithDetails != null) + { + insuranceShare = insuranceListDataWithDetails.InsuranceShare; + } + else + { + if (insuranceEmployeeDataItem != null && insuranceEmployeeDataItem.StartWorkDateGr <= item.Separation.ContractEndGr) + { + var workingDays = Tools.GetEmployeeInsuranceWorkingDays(insuranceEmployeeDataItem.StartWorkDateGr, item.Separation.LeftWorkDate, startDateGr, endDateGr, insuranceEmployeeDataItem.EmployeeId); + var leftWorkFa = workingDays.hasLeftWorkInMonth ? item.Separation.LeftWorkDate.ToFarsi() : ""; + + //به دست آوردن دستمزد روزانه با توجه به اینکه کارگاه مشاغل مقطوع است یا خیر + + double dailyWage = 0; + if (getContractsData.Data.FixedSalary) + { + var res = _insuranceListApplication.GetDailyWageFixedSalary(year, getContractsData.Data.WorkshopId, insuranceEmployeeDataItem.EmployeeId, startDateGr, + endDateGr, insuranceEmployeeDataItem.JobId, getContractsData.Data.Population, getContractsData.Data.InsuranceJobId); + dailyWage = res ?? 0; + + } + else + { + var res = _insuranceListApplication.ComputeDailyWage(yearlysaleries.DayliWage, insuranceEmployeeDataItem.EmployeeId, getContractsData.Data.WorkshopId, year); + dailyWage = res; + } + + //بدست آوردن پایه سنوات + var baseYears = _insuranceListRepository.GetEmployeeInsuranceBaseYear(insuranceEmployeeDataItem.EmployeeId, getContractsData.Data.WorkshopId, + workingDays.countWorkingDays, startDateGr, endDateGr, workingDays.startWork, workingDays.endWork, workingDays.hasLeftWorkInMonth); + + //جمع مزد روزانه و پایه سنوات + var dailyWagePlusBaseYears = dailyWage + baseYears.baseYear; + + + //دستمزد ماهانه با محاسبه پایه سنوات + var monthlySalary = Tools.GetRoundDoubleValue(dailyWagePlusBaseYears * workingDays.countWorkingDays); + + //حق تاهل + var marriedAllowanceForInsurance = item.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0; + + //محاسبه مزایای ماهانه + var monthlyBenefits = _insuranceListApplication.GetMonthlyBenefits(endOfMonth, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marriedAllowanceForInsurance, workingDays.countWorkingDays, getContractsData.Data.TypeOfInsuranceSend, insuranceEmployeeDataItem.JobId, insuranceEmployeeDataItem.EmployeeId, insuranceEmployeeDataItem.IncludeStatus); + if (getContractsData.Data.HasInsuranceCheckoutOverTime) + { + + monthlyBenefits = Tools.GetRoundDoubleValue(monthlyBenefits += overTimeWorking); + } + + //محاسبه جمع مزایای مشمول و دستمزد ماهانه + var benefitsIncludedContinuous = monthlyBenefits + monthlySalary; + + //محاسبه حق بیمه سهم بیمه شده + insuranceShare = (benefitsIncludedContinuous * 7) / 100; + } + } + + + + #endregion + #region ResultToSave + + var syear = Convert.ToInt32(item.ContractStart.Substring(0, 4)); + + string monthfarsiName = (item.ContractStart.Substring(5, 2)).ToFarsiMonthByNumber(); + + var yearShamsi = item.ContractStart.Substring(0, 4); + + + var dayliWageDouble = mandatoryCompute.SalaryCompute.MoneyToDouble(); + // کمک هزینه اقلام + var consumableItem = mandatoryCompute.ConsumableItems.MoneyToDouble(); + //حق اولاد + var familyAllowance = mandatoryCompute.FamilyAllowance.MoneyToDouble(); + //کمک هزینه مسکن + var housingAllowance = mandatoryCompute.HousingAllowance.MoneyToDouble(); + //حق تاهل + var marriedAllowance = mandatoryCompute.MarriedAllowance.MoneyToDouble(); + + #region Salary + + var totalDays = (item.Separation.ContractEndGr - item.Separation.ContractStartGr).TotalDays + 1; + + //حقوق ماهانه + var monthlyWage = mandatoryCompute.DailySalaryAffected * totalDays; + //پایه سنوات + var bacicYears = mandatoryCompute.BaseYearAffected * totalDays; + #endregion + + + //سنوات + var years = yearsPay.YearsPay; + //عیدی و پاداش + var bunos = bunosesPay.Bunoses; + + //فاطمه احمدژاد === موقت عیدی و پاداش و سنوات حساب نشه + if (item.EmployeeId == 45104 && getContractsData.Data.WorkshopId == 315) + { + years = 0; + + bunos = 0; + } + + //تعداد زروز های فیش + var sumOfWorkingDays = $"{totalDays}"; + + //مبلغ جمعه کاری + double fridayPay = 0; + if (Friday > 0) + { + var fridayPercent = dayliWageDouble * 40 / 100; + //فوق العاده جمعه کاری + fridayPay = fridayPercent * Friday; + } + + + //حق بیمه سهم کارگر + #region InsuranceDeduction + + double insuranceDeduction = 0; + bool hasInsuranceShareTheSameAsList = false; + var inshuranceShareRound = Tools.GetRoundDoubleValue(insuranceShare); + if (inshuranceShareRound == 0) + { + var insuranceOverTime = getContractsData.Data.HasInsuranceCheckoutOverTime ? overTimeWorking : 0; + insuranceDeduction = (monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + insuranceOverTime) * 7 / 100; + } + else + { + insuranceDeduction = inshuranceShareRound; + hasInsuranceShareTheSameAsList = true; + } + + + #endregion + + #endregion Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("================================================================== "); - Console.WriteLine("========================================Counter ================== " + (i+1)); + Console.WriteLine("========================================Counter ================== " + (i + 1)); Console.WriteLine("================================================================== "); Console.ResetColor(); i += 1; } - + Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("after GetData To mandatoryCompute" + timer.Elapsed); Console.ResetColor(); diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 144cb9cd..564d0fd9 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -4396,9 +4396,15 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ArchiveCode = workshop.ArchiveCode, WorkshopName = workshop.WorkshopName, IsStaticCheckout = workshop.IsStaticCheckout, + HasInsuranceCheckoutOverTime = workshop.InsuranceCheckoutOvertime, + FixedSalary = workshop.FixedSalary, + InsuranceJobId = workshop.InsuranceJobId, + Population = workshop.Population, + TypeOfInsuranceSend = workshop.TypeOfInsuranceSend, + #endregion - + ContractIncludedData = incloudedData, }; diff --git a/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs index ecccbe72..732608e0 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs @@ -7854,6 +7854,8 @@ public class IndexModel : PageModel } #endregion + + } From 7d35a65f35301b67431afbf1c2c2a211aad5e8ec Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Tue, 3 Feb 2026 17:00:36 +0330 Subject: [PATCH 10/13] save to db Checkout new Method --- .../CheckoutAgg/ICheckoutRepository.cs | 2 +- .../CheckoutApplication.cs | 290 +++++++++++++++++- .../Repository/CheckoutRepository.cs | 47 ++- 3 files changed, 307 insertions(+), 32 deletions(-) diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index 4b110f84..72753f71 100644 --- a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs +++ b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs @@ -23,7 +23,7 @@ public interface ICheckoutRepository : IRepository string year, string month); EditCheckout GetDetails(long id); - Task CreateCkeckout(Checkout command); + Task CreateCheckout(Checkout command); /// /// لود لیست اولیه جهت ایجاد فیش حقوقی /// diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index afd4bcd3..2a04c722 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -433,7 +433,7 @@ public class CheckoutApplication : ICheckoutApplication , command.FridayWorkValue, command.RotatingShiftValue, command.AbsenceValue, command.TotalDayOfLeaveCompute, command.TotalDayOfYearsCompute, command.TotalDayOfBunosesCompute, loanInstallments, salaryAids, checkoutRollCall, command.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay); - _checkoutRepository.CreateCkeckout(checkout).GetAwaiter().GetResult(); + _checkoutRepository.CreateCheckout(checkout).GetAwaiter().GetResult(); //_checkoutRepository.SaveChanges(); //var employeeFullName = new SqlParameter("@EmployeeFullName", SqlDbType.NVarChar, 50); @@ -828,7 +828,7 @@ public class CheckoutApplication : ICheckoutApplication //آی دی کاربر لاگین شده برای استفاده در signalR var currntAcc = _authHelper.CurrentAccountId(); - + var signalR = _hubContext.Clients.Group(CheckoutHub.GetGroupName(currntAcc)); @@ -862,8 +862,8 @@ public class CheckoutApplication : ICheckoutApplication if (!getContractsData.IsSuccedded) { - await _hubContext.Clients.Group(CheckoutHub.GetGroupName(currntAcc)) - .SendAsync("StartProcessingFailed", getContractsData.Message); + + signalR.SendAsync("StartProcessingFailed", getContractsData.Message); return op.Failed(getContractsData.Message); } @@ -874,29 +874,29 @@ public class CheckoutApplication : ICheckoutApplication foreach (var item in getContractsData.Data.ContractIncludedData) { - //آیا کل مرخصی به ساعت کاراضافه شود؟ + //آیا کل مرخصی به ساعت کاراضافه شود؟ bool totalLeaveCompute = false; //آیا غیبت محاسبه شود؟ - bool abcenseDeduction = false; + bool abcenseDeductionCompute = false; switch (item.ComputeOption) { case "OnEndOfYear": var endOfYearCheckout = item.Separation.ContractEnd.Substring(5, 2); totalLeaveCompute = true; - abcenseDeduction = item.Separation.HasLeft || endOfYearCheckout == "12"; + abcenseDeductionCompute = item.Separation.HasLeft || endOfYearCheckout == "12"; break; case "OnLeftWork": totalLeaveCompute = true; - abcenseDeduction = item.Separation.HasLeft; + abcenseDeductionCompute = item.Separation.HasLeft; break; case "OnEndOfContract": var startMonth = item.ContractStart.Substring(5, 2); var endMonth = item.ContractEnd.Substring(5, 2); totalLeaveCompute = startMonth != endMonth; - abcenseDeduction = (startMonth != endMonth && item.Separation.HasLeft) || (startMonth != endMonth && item.ContractEndGr == item.Separation.ContractEndGr); + abcenseDeductionCompute = (startMonth != endMonth && item.Separation.HasLeft) || (startMonth != endMonth && item.ContractEndGr == item.Separation.ContractEndGr); break; } @@ -966,10 +966,10 @@ public class CheckoutApplication : ICheckoutApplication var marriedAllowanceDouble = mandatoryCompute.MarriedAllowance.MoneyToDouble(); //اضافه کاری - var overTimeWorking = _yearlySalaryRepository.GetOverTimeWorking(dayliWage, + var overTimePay = _yearlySalaryRepository.GetOverTimeWorking(dayliWage, mandatoryCompute.OverTimeWorkH, mandatoryCompute.OverTimeWorkM); //شبکاری - var overNightWorking = _yearlySalaryRepository.GetOverNightWorking(dayliWage, + var overNightPay = _yearlySalaryRepository.GetOverNightWorking(dayliWage, mandatoryCompute.OverNightWorkH, mandatoryCompute.OverNightWorkM, mandatoryCompute.SumTime44, officialHoliday, Friday, item.Separation.ContractStartGr, item.Separation.ContractEndGr, totalHoursH, totalHoursM); @@ -1123,7 +1123,7 @@ public class CheckoutApplication : ICheckoutApplication if (getContractsData.Data.HasInsuranceCheckoutOverTime) { - monthlyBenefits = Tools.GetRoundDoubleValue(monthlyBenefits += overTimeWorking); + monthlyBenefits = Tools.GetRoundDoubleValue(monthlyBenefits += overTimePay); } //محاسبه جمع مزایای مشمول و دستمزد ماهانه @@ -1137,10 +1137,12 @@ public class CheckoutApplication : ICheckoutApplication #endregion + #region ResultToSave var syear = Convert.ToInt32(item.ContractStart.Substring(0, 4)); - + var smonth = Convert.ToInt32(item.ContractStart.Substring(5, 2)); + string monthfarsiName = (item.ContractStart.Substring(5, 2)).ToFarsiMonthByNumber(); var yearShamsi = item.ContractStart.Substring(0, 4); @@ -1201,7 +1203,7 @@ public class CheckoutApplication : ICheckoutApplication var inshuranceShareRound = Tools.GetRoundDoubleValue(insuranceShare); if (inshuranceShareRound == 0) { - var insuranceOverTime = getContractsData.Data.HasInsuranceCheckoutOverTime ? overTimeWorking : 0; + var insuranceOverTime = getContractsData.Data.HasInsuranceCheckoutOverTime ? overTimePay : 0; insuranceDeduction = (monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + insuranceOverTime) * 7 / 100; } else @@ -1213,7 +1215,267 @@ public class CheckoutApplication : ICheckoutApplication #endregion + //مقادیر - روز - تعداد - ساعت + #region Values + + //مدت شب کاری + var overNightWorkValue = + $"{Convert.ToInt32(mandatoryCompute.OverNightWorkH):00}:{Convert.ToInt32(mandatoryCompute.OverNightWorkM):00}"; + //تعداد جمعه کاری + var fridayWorkValue = $"{Friday}"; + //نوع نوبت کاری + var rotatingShiftValue = mandatoryCompute.RotatingShiftValue; + // تعداد سال های سنوات + var totalDayOfYearsCompute = yearsPay.YearsPay > 0 ? $"{yearsPay.TotalDayCompute}" : "0"; + //تعداد روز های عیدی و پاداش + var totalDayOfBunosesCompute = bunosesPay.Bunoses > 0 ? $"{bunosesPay.TotalDayCompute}" : "0"; + //مدت اضافه کارس + var overTimeWorkValue = + $"{Convert.ToInt32(mandatoryCompute.OverTimeWorkH):00}:{Convert.ToInt32(mandatoryCompute.OverTimeWorkM):00}"; + + #endregion + + //کسر اضافه کار از غیبت یا بلعکس + #region OverTimeAndAbsencSubtraction + var absenceDeduction = abcenseDeductionCompute ? leavePayNew.AbsenceDeduction : 0; + + if (overTimePay > 0 && absenceDeduction > 0) + { + if (absenceDeduction >= overTimePay) + { + absenceDeduction -= overTimePay; + overTimePay = 0; + overTimeWorkValue = "00:00"; + } + else + { + overTimePay -= absenceDeduction; + absenceDeduction = 0; + } + + } + #endregion + + //مساعده + #region SalaryAid + + var salaryAids = + _rollCallMandatoryRepository.SalaryAidsForCheckout(contract.EmployeeId, contract.WorkshopIds, startDateGr, endDateGr) + .Select(x => new CheckoutSalaryAid(x.Amount, x.SalaryAidDateTimeGe, x.SalaryAidDateTimeFa, x.CalculationDateTimeGe, x.CalculationDateTimeFa, x.Id)).ToList(); + + var salaryAidDeduction = salaryAids.Sum(x => x.Amount.MoneyToDouble()); + + #endregion + + //اقساط وام + #region LoanInstallment + + var loanInstallments = _rollCallMandatoryRepository.LoanInstallmentForCheckout(contract.EmployeeId, contract.WorkshopIds, + item.Separation.ContractStartGr, item.Separation.HasLeft ? DateTime.MaxValue : item.Separation.ContractEndGr) + .Select(x => + new CheckoutLoanInstallment(x.Amount, x.Month, x.Year, x.IsActive, x.RemainingAmount, x.LoanAmount, x.Id)).ToList(); + + var installmentDeduction = loanInstallments.Sum(x => x.AmountForMonth.MoneyToDouble()); + + #endregion + + //پاداش + #region Reward + + + var rewards = new List(); + double rewardPay = 0; + if (getContractsData.Data.RewardComputeOnCheckout) + { + rewards = _rollCallMandatoryRepository.RewardForCheckout(contract.EmployeeId, contract.WorkshopIds, startDateGr, endDateGr) + .Select(x => new CheckoutReward(x.Amount, x.AmountDouble, x.GrantDateFa, x.GrantDateGr, x.Description, x.Title, x.Id)).ToList(); + + rewardPay = rewards.Sum(x => x.AmountDouble); + } + + #endregion + + //جدول حضورغیاب پرسنل + #region CheckoutRollCall + + //کارکرد واقعی - محاسبات شامل مرخصی افزوده شده + var totalWorkingTimeSpan = mandatoryCompute.TotalWorkingTimeSpan; + //ساعت استراحت + var totalBreakTimeSpan = mandatoryCompute.TotalBreakTimeSpan; + // ساعت حضور - بدون مرخصی افزده شده + var totalPresentTimeSpan = mandatoryCompute.TotalPresentTimeSpan; + //مدت مرخصی استحقاقی + var totalPaidLeave = mandatoryCompute.TotalPaidLeave; + //مدت مرخصی استعلاجی + var totalSickLeave = mandatoryCompute.TotalSickLeave; + + + var firstDayOfMonth = startDateGr; + var firstDayOfCurrentMonth = new DateTime(syear, smonth, 1, new PersianCalendar()); + + LeaveSearchModel sickLeaveSearch = new LeaveSearchModel() + { + EmployeeId = contract.EmployeeId, + WorkshopId = contract.WorkshopIds, + StartLeaveGr = item.Separation.ContractStartGr, + EndLeaveGr = item.Separation.ContractEndGr, + IsAccepted = true, + }; + var leaves = _leaveApplication.search(sickLeaveSearch); + + firstDayOfMonth.AddMonthsFa(1, out var lastDayOfCurrentMonth); + + lastDayOfCurrentMonth = lastDayOfCurrentMonth.AddDays(-1); + + int dateRange = (int)(lastDayOfCurrentMonth - firstDayOfCurrentMonth).TotalDays + 1; + + var holidays = _holidayItemApplication.Search(new HolidayItemSearchModel() + { + HolidayYear = item.Separation.ContractStartGr.ToFarsiYear() + }); + //all the dates from start to end, to be compared with present days to get absent dates + var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => firstDayOfCurrentMonth.AddDays(offset).Date).ToList(); + + var absentRecords = completeDaysList + .ExceptBy(mandatoryCompute.GroupedRollCalls.Select(x => x.CreationDate.Date), y => y.Date) + .Select(x => + { + var leave = leaves.FirstOrDefault(y => + y.EmployeeId == contract.EmployeeId && y.EndLeaveGr.Date >= x.Date && y.StartLeaveGr.Date <= x.Date); + var isHoliday = holidays.Any(y => y.HolidaydateGr == x.Date); + var isFriday = x.Date.DayOfWeek == DayOfWeek.Friday; + var isNormalWorkingDay = isHoliday == false && isFriday == false; + return new CheckoutDailyRollCallViewModel() + { + StartDate1 = null, + EndDate1 = null, + DateTimeGr = x.Date, + DayOfWeek = x.Date.DayOfWeek.ToString(), + RollCallDateFa = x.Date.ToFarsi(), + LeaveType = leave != null ? leave.LeaveType : "", + IsAbsent = leave == null && isNormalWorkingDay + }; + }); + + + var presentDays = mandatoryCompute.GroupedRollCalls.Select(x => + { + + var orderedRollcalls = x.ShiftList.OrderBy(y => y.Start); + + var rollCallTimeSpanPerDay = x.SumOneDaySpan; + TimeSpan breakTimePerDay = x.BreakTime; + + return new CheckoutDailyRollCallViewModel() + { + StartDate1 = orderedRollcalls.FirstOrDefault().Start.ToString("HH:mm"), + EndDate1 = orderedRollcalls.FirstOrDefault().EndWithOutResTime.ToString("HH:mm"), + + StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.Start.ToString("HH:mm") ?? "", + EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndWithOutResTime.ToString("HH:mm") ?? "", + + TotalhourseSpan = rollCallTimeSpanPerDay, + + BreakTimeTimeSpan = breakTimePerDay, + + DayOfWeek = x.CreationDate.DayOfWeek.DayOfWeeKToPersian(), + RollCallDateFa = x.CreationDate.Date.ToFarsi(), + DateTimeGr = x.CreationDate.Date, + IsSliced = x.ShiftList.Count() > 2, + IsAbsent = false + }; + }); + + + presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel + { + StartDate1 = x.StartDate1, + EndDate1 = x.EndDate1, + EndDate2 = x.EndDate2, + StartDate2 = x.StartDate2, + TotalWorkingHours = $"{(int)(x.TotalhourseSpan.TotalHours)}:{x.TotalhourseSpan.Minutes:00}", + BreakTimeString = $"{(int)(x.BreakTimeTimeSpan.TotalHours)}:{x.BreakTimeTimeSpan.Minutes:00}", + TotalhourseSpan = x.TotalhourseSpan, + BreakTimeTimeSpan = x.BreakTimeTimeSpan, + DayOfWeek = x.DayOfWeek, + RollCallDateFa = x.RollCallDateFa, + DateTimeGr = x.DateTimeGr, + IsSliced = x.IsSliced, + IsAbsent = false + }); + + var result = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); + result.ForEach(x => + { + x.IsHoliday = holidays.Any(y => x.DateTimeGr.Date == y.HolidaydateGr.Date); + x.IsFriday = x.DateTimeGr.DayOfWeek == DayOfWeek.Friday; + }); + + var checkoutRollCallDays = result.Select(x => new CheckoutRollCallDay(x.DateTimeGr, + x.StartDate1, x.EndDate1, x.StartDate2, x.EndDate2, + x.BreakTimeTimeSpan, x.IsSliced, x.TotalhourseSpan, x.IsAbsent, x.IsFriday, x.IsHoliday, x.LeaveType)) + .ToList(); + + + double mandatoryHours = _mandatoryHoursApplication.GetMandatoryHoursByYearAndMonth(syear, smonth); + int mandatoryWholeHours = (int)mandatoryHours; + int mandatoryMinutes = (int)((mandatoryHours - mandatoryWholeHours) * 60); + + var totalMandatoryHours = TimeSpan.FromHours(mandatoryWholeHours).Add(TimeSpan.FromMinutes(mandatoryMinutes)); + var checkoutRollCall = new CheckoutRollCall(totalMandatoryHours, totalPresentTimeSpan, totalBreakTimeSpan, + totalWorkingTimeSpan, totalPaidLeave, totalSickLeave, checkoutRollCallDays); + #endregion + + //مقادیر پرداخت نهایی - مطالبات - کسورات + #region TotalPayment + + var shiftPay = contract.WorkshopIds == 552 && hasRollCall ? 0 : mandatoryCompute.ShiftPay; + + + var totalClaimsDouble = monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + overTimePay + + overNightPay + familyAllowance + bunos + years + leavePayNew.LeavPay + fridayPay + shiftPay + rewardPay; + var totalDeductionDouble = insuranceDeduction + absenceDeduction + installmentDeduction + salaryAidDeduction; + + //مطالبات + var totalClaims = totalClaimsDouble.ToMoney(); + //کسورات + var totalDeductions = totalDeductionDouble.ToMoney(); + + //مبلغ قابل پرداخت + var totalPayment = totalClaimsDouble - totalDeductionDouble; + + #endregion + + + #region CreateCheckoutModel + + var checkout = new Checkout(item.EmployeeFullName, item.FathersName, item.NationalCode + , item.DateOfBirth, item.EmployeeId, getContractsData.Data.WorkshopName, getContractsData.Data.WorkshopId, item.ContractNo, item.Separation.ContractStartGr, item.Separation.ContractEndGr, monthfarsiName, yearShamsi, + item.ContractId, item.WorkingHours.WorknigHoursId, monthlyWage, bacicYears, consumableItem, housingAllowance + , overTimePay, overNightPay, fridayPay, 0, shiftPay, familyAllowance, bunos, years, leavePayNew.LeavPay, insuranceDeduction, 0, installmentDeduction, salaryAidDeduction, absenceDeduction, sumOfWorkingDays, + getContractsData.Data.ArchiveCode, item.PersonnelCode, totalClaims, totalDeductions, totalPayment, "0", marriedAllowance, leavePayNew.LeaveCheckout, leavePayNew.CreditLeaves, leavePayNew.AbsencePeriod, leavePayNew.AverageHoursPerDay, hasRollCall, overTimeWorkValue, overNightWorkValue + , fridayWorkValue, rotatingShiftValue, "0", leavePayNew.TotalDayOfLeaveCompute, totalDayOfYearsCompute, totalDayOfBunosesCompute, + loanInstallments, salaryAids, checkoutRollCall, mandatoryCompute.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay); + + #endregion + + + #endregion + + + + + #region SaveToDb + + + var saveToDb = await _checkoutRepository.CreateCheckout(checkout); + + #endregion + + + + Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("================================================================== "); Console.WriteLine("========================================Counter ================== " + (i + 1)); diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 564d0fd9..517b02be 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -518,27 +518,40 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos }; } - public async Task CreateCkeckout(Checkout command) + public async Task CreateCheckout(Checkout command) { - var creationDates = DateTime.Now; - //var result = await _context.Database.ExecuteSqlInterpolatedAsync($"EXEC InsertQuery_Checkout {id},{employeeFullName},{isActiveString},{signature},{fathersName},{nationalCode},{dateOfBirth},{employeeId},{workshopName},{workshopId},{contractNo},{contractStart},{contractEnd},{month},{year},{contractId},{workingHoursId},{monthlySalary},{baseYearsPay},{consumableItems},{housingAllowance},{overtimePay},{nightworkPay},{fridayPay},{missionPay},{shiftPay},{familyAllowance},{bonusesPay},{yearsPay},{leavePay},{insuranceDeduction},{taxDeducation},{installmentDeduction},{salaryAidDeduction},{absenceDeduction},{creationDate},{archiveCode},{personnelCode},{sumOfWorkingDays},{totalClaims},{taxDeducation},{totalPayment}"); - var result = (_context.Database - .SqlQuery( - $"EXEC InsertQuery_CreateChekoute {command.EmployeeFullName},{"true"},{command.Signature},{command.FathersName},{command.NationalCode},{command.DateOfBirth},{command.EmployeeId},{command.WorkshopName},{command.WorkshopId},{command.ContractNo},{command.ContractStart},{command.ContractEnd},{command.Month},{command.Year},{command.ContractId},{command.WorkingHoursId},{command.MonthlySalary},{command.BaseYearsPay},{command.ConsumableItems},{command.HousingAllowance},{command.OvertimePay},{command.NightworkPay},{command.FridayPay},{command.MissionPay},{command.ShiftPay},{command.FamilyAllowance},{command.BonusesPay},{command.YearsPay},{command.LeavePay},{command.InsuranceDeduction},{command.TaxDeducation},{command.InstallmentDeduction},{command.SalaryAidDeduction},{command.AbsenceDeduction},{creationDates},{command.ArchiveCode},{command.PersonnelCode},{command.SumOfWorkingDays},{command.TotalClaims},{command.TotalDeductions},{command.TotalPayment},{0},{command.MarriedAllowance},{command.AbsencePeriod},{command.AverageHoursPerDay},{command.CreditLeaves},{command.LeaveCheckout},{command.HasRollCall},{command.OverTimeWorkValue},{command.OverNightWorkValue},{command.FridayWorkValue},{command.RotatingShiftValue},{command.AbsenceValue}, {command.TotalDayOfLeaveCompute},{command.TotalDayOfYearsCompute},{command.TotalDayOfBunosesCompute}") - .AsEnumerable()) // این قسمت مهمه! - .FirstOrDefault(); + try + { + var creationDates = DateTime.Now; - var entity = await _context.CheckoutSet.FirstOrDefaultAsync(x => x.id == result); + //var result = await _context.Database.ExecuteSqlInterpolatedAsync($"EXEC InsertQuery_Checkout {id},{employeeFullName},{isActiveString},{signature},{fathersName},{nationalCode},{dateOfBirth},{employeeId},{workshopName},{workshopId},{contractNo},{contractStart},{contractEnd},{month},{year},{contractId},{workingHoursId},{monthlySalary},{baseYearsPay},{consumableItems},{housingAllowance},{overtimePay},{nightworkPay},{fridayPay},{missionPay},{shiftPay},{familyAllowance},{bonusesPay},{yearsPay},{leavePay},{insuranceDeduction},{taxDeducation},{installmentDeduction},{salaryAidDeduction},{absenceDeduction},{creationDate},{archiveCode},{personnelCode},{sumOfWorkingDays},{totalClaims},{taxDeducation},{totalPayment}"); + var result = (_context.Database + .SqlQuery( + $"EXEC InsertQuery_CreateChekoute {command.EmployeeFullName},{"true"},{command.Signature},{command.FathersName},{command.NationalCode},{command.DateOfBirth},{command.EmployeeId},{command.WorkshopName},{command.WorkshopId},{command.ContractNo},{command.ContractStart},{command.ContractEnd},{command.Month},{command.Year},{command.ContractId},{command.WorkingHoursId},{command.MonthlySalary},{command.BaseYearsPay},{command.ConsumableItems},{command.HousingAllowance},{command.OvertimePay},{command.NightworkPay},{command.FridayPay},{command.MissionPay},{command.ShiftPay},{command.FamilyAllowance},{command.BonusesPay},{command.YearsPay},{command.LeavePay},{command.InsuranceDeduction},{command.TaxDeducation},{command.InstallmentDeduction},{command.SalaryAidDeduction},{command.AbsenceDeduction},{creationDates},{command.ArchiveCode},{command.PersonnelCode},{command.SumOfWorkingDays},{command.TotalClaims},{command.TotalDeductions},{command.TotalPayment},{0},{command.MarriedAllowance},{command.AbsencePeriod},{command.AverageHoursPerDay},{command.CreditLeaves},{command.LeaveCheckout},{command.HasRollCall},{command.OverTimeWorkValue},{command.OverNightWorkValue},{command.FridayWorkValue},{command.RotatingShiftValue},{command.AbsenceValue}, {command.TotalDayOfLeaveCompute},{command.TotalDayOfYearsCompute},{command.TotalDayOfBunosesCompute}") + .AsEnumerable()) // این قسمت مهمه! + .FirstOrDefault(); - entity.SetSalaryAid(command.SalaryAids, command.SalaryAidDeduction); - entity.SetLoanInstallment(command.LoanInstallments, command.InstallmentDeduction); - entity.SetReward(command.Rewards,command.RewardPay); - entity.SetCheckoutRollCall(command.CheckoutRollCall); - entity.SetEmployeeMandatoryHours(command.EmployeeMandatoryHours); - if (command.HasInsuranceShareTheSameAsList) - entity.SetInsuranceShare(); - await _context.SaveChangesAsync(); + var entity = await _context.CheckoutSet.FirstOrDefaultAsync(x => x.id == result); + + entity.SetSalaryAid(command.SalaryAids, command.SalaryAidDeduction); + entity.SetLoanInstallment(command.LoanInstallments, command.InstallmentDeduction); + entity.SetReward(command.Rewards, command.RewardPay); + entity.SetCheckoutRollCall(command.CheckoutRollCall); + entity.SetEmployeeMandatoryHours(command.EmployeeMandatoryHours); + if (command.HasInsuranceShareTheSameAsList) + entity.SetInsuranceShare(); + await _context.SaveChangesAsync(); + + return true; + } + catch (Exception) + { + + return false; + } + + } From da966e49c3a5be70a1404cd6b813366dd8875cc1 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Tue, 3 Feb 2026 17:16:25 +0330 Subject: [PATCH 11/13] add create signalR --- .../CheckoutApplication.cs | 1097 +++++++++-------- 1 file changed, 553 insertions(+), 544 deletions(-) diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 2a04c722..1c49bd39 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -863,7 +863,7 @@ public class CheckoutApplication : ICheckoutApplication if (!getContractsData.IsSuccedded) { - signalR.SendAsync("StartProcessingFailed", getContractsData.Message); + await signalR.SendAsync("StartProcessingFailed", getContractsData.Message); return op.Failed(getContractsData.Message); } @@ -874,604 +874,613 @@ public class CheckoutApplication : ICheckoutApplication foreach (var item in getContractsData.Data.ContractIncludedData) { - //آیا کل مرخصی به ساعت کاراضافه شود؟ - bool totalLeaveCompute = false; - //آیا غیبت محاسبه شود؟ - bool abcenseDeductionCompute = false; - switch (item.ComputeOption) + try { - case "OnEndOfYear": - var endOfYearCheckout = item.Separation.ContractEnd.Substring(5, 2); - - totalLeaveCompute = true; - abcenseDeductionCompute = item.Separation.HasLeft || endOfYearCheckout == "12"; - break; - case "OnLeftWork": - - totalLeaveCompute = true; - abcenseDeductionCompute = item.Separation.HasLeft; - break; - case "OnEndOfContract": - var startMonth = item.ContractStart.Substring(5, 2); - var endMonth = item.ContractEnd.Substring(5, 2); - - totalLeaveCompute = startMonth != endMonth; - abcenseDeductionCompute = (startMonth != endMonth && item.Separation.HasLeft) || (startMonth != endMonth && item.ContractEndGr == item.Separation.ContractEndGr); - break; - } - - - //دستمزد روزانه بدون تاثیر ساعت کار - #region DailyWageCompute - - var contract = new EditContract() - { - ContractStartGr = item.ContractStartGr, - ContractEndGr = item.ContractEndGr, - DailySalaryUnAffected = item.DailySalaryUnAffected, - DailyWageType = item.DailyWageType, - ContarctStart = item.ContractStart, - ContractEnd = item.ContractEnd, - GetWorkDate = item.FirstGetWorkingDay, - GetWorkDateHide = item.FirstGetWorkingDay, - - }; - - //دستمزد روزانه بدون تاثیر ساعت کار - var dailyWageUnAffected = await _yearlySalaryRepository.GetCheckoutDailyWage(contract, - item.Separation.ContractStartGr, item.Separation.ContractEndGr); - - #endregion - - - - - var hasRollCall = await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, item.Separation.ContractStartGr, item.Separation.ContractEndGr); - if (getContractsData.Data.IsStaticCheckout) - hasRollCall = false; - - //محاسبه موظفی - #region MandatoryCompute - var mandatoryCompute = new ComputingViewModel(); - - item.WorkingHours.ContractStartGr = item.Separation.ContractStartGr; - item.WorkingHours.ContractEndGr = item.Separation.ContractEndGr; - item.WorkingHours.ContarctStart = item.Separation.ContarctStart; - item.WorkingHours.ContractEnd = item.Separation.ContractEnd; - item.WorkingHours.GetWorkDate = contract.GetWorkDate; - item.WorkingHours.GetWorkDateHide = contract.GetWorkDate; - item.WorkingHours.WorkshopId = workshopId; - item.WorkingHours.EmployeeId = item.EmployeeId; - - mandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(item.EmployeeId, workshopId, - item.Separation.ContractStartGr, item.Separation.ContractEndGr, item.WorkingHours, getContractsData.Data.WorkshopHolidayWorking, - hasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); - - #endregion - - - if (contract.EmployeeId == 9659) - mandatoryCompute.SumTime44 = "48 - 24"; - - var officialHoliday = mandatoryCompute.OfficialHoliday; - var Friday = int.Parse(mandatoryCompute.NumberOfFriday); - var fridayStartToEnd = mandatoryCompute.FridayStartToEnd; - - var totalHoursH = mandatoryCompute.TotalHoursesH; - var totalHoursM = mandatoryCompute.TotalHoursesM; - var dayliWage = mandatoryCompute.SalaryCompute.MoneyToDouble(); - var consumableItemDouble = mandatoryCompute.ConsumableItems.MoneyToDouble(); - var housingAllowanceDouble = mandatoryCompute.HousingAllowance.MoneyToDouble(); - var familyAllowanceDouble = mandatoryCompute.FamilyAllowance.MoneyToDouble(); - var marriedAllowanceDouble = mandatoryCompute.MarriedAllowance.MoneyToDouble(); - - //اضافه کاری - var overTimePay = _yearlySalaryRepository.GetOverTimeWorking(dayliWage, - mandatoryCompute.OverTimeWorkH, mandatoryCompute.OverTimeWorkM); - //شبکاری - var overNightPay = _yearlySalaryRepository.GetOverNightWorking(dayliWage, - mandatoryCompute.OverNightWorkH, mandatoryCompute.OverNightWorkM, mandatoryCompute.SumTime44, - officialHoliday, Friday, item.Separation.ContractStartGr, item.Separation.ContractEndGr, totalHoursH, - totalHoursM); - - - //سنوات - var yearsPay = _yearlySalaryRepository.Years(item.Separation.ContractStartGr, item.Separation.LeftWorkDate, - item.Separation.ContractEndGr, - dayliWage, item.YearsOption, item.Separation.HasLeft, item.Separation.StartWorkDate, contract.ContractStartGr, - contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, getContractsData.Data.IsOldContract); - //عیدی - #region BonusesPay - var bunosesPay = _yearlySalaryRepository.Bunoses(item.Separation.ContarctStart, item.Separation.LeftWorkDate, - item.Separation.ContractStartGr, item.Separation.ContractEndGr, - dayliWage, item.BonusesOption, item.Separation.HasLeft, item.Separation.StartWorkDate, - contract.ContractStartGr, - contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, getContractsData.Data.IsOldContract); - //اگر تصفیه حساب پاک شده برای عیدی یا سنوات وجود داشت - if (bunosesPay.NotCompleted || yearsPay.NotCompleted) - { - - List lostCheckoutsDates = new List(); - if ((bunosesPay.NotCompleted && yearsPay.NotCompleted) || (bunosesPay.NotCompleted && !yearsPay.NotCompleted)) - lostCheckoutsDates = bunosesPay.BunosesStatusList; - if (!bunosesPay.NotCompleted && yearsPay.NotCompleted) - lostCheckoutsDates = yearsPay.BunosesStatusList; - - foreach (var found in lostCheckoutsDates) + //آیا کل مرخصی به ساعت کاراضافه شود؟ + bool totalLeaveCompute = false; + //آیا غیبت محاسبه شود؟ + bool abcenseDeductionCompute = false; + switch (item.ComputeOption) { - ComputingViewModel foundMandatoryCompute = new ComputingViewModel(); - var foundContract = _contractRepository.GetContractByStartEnd(found.ContractStart, - found.ContractEnd, contract.WorkshopIds, contract.EmployeeId); + case "OnEndOfYear": + var endOfYearCheckout = item.Separation.ContractEnd.Substring(5, 2); - if (foundContract.Id > 0) - { - var foundWorkingHours = _workingHoursTempRepository.GetByContractIdConvertToShiftwork4(foundContract.Id); - foundWorkingHours.ContractStartGr = found.ContractStart; - foundWorkingHours.ContractEndGr = found.ContractEnd; - foundWorkingHours.ContarctStart = found.ContractStart.ToFarsi(); - foundWorkingHours.ContractEnd = found.ContractEnd.ToFarsi(); - foundWorkingHours.GetWorkDate = foundContract.GetWorkDate; - foundWorkingHours.GetWorkDateHide = foundContract.GetWorkDate; - foundWorkingHours.WorkshopId = contract.WorkshopIds; - foundWorkingHours.EmployeeId = contract.EmployeeId; - bool foundHasRollCall = await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, found.ContractStart, found.ContractEnd); + totalLeaveCompute = true; + abcenseDeductionCompute = item.Separation.HasLeft || endOfYearCheckout == "12"; + break; + case "OnLeftWork": - if (getContractsData.Data.IsStaticCheckout) - foundHasRollCall = false; + totalLeaveCompute = true; + abcenseDeductionCompute = item.Separation.HasLeft; + break; + case "OnEndOfContract": + var startMonth = item.ContractStart.Substring(5, 2); + var endMonth = item.ContractEnd.Substring(5, 2); - foundMandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(contract.EmployeeId, - contract.WorkshopIds, - found.ContractStart, found.ContractEnd, foundWorkingHours, getContractsData.Data.WorkshopHolidayWorking, foundHasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); - - - - - - var MontlyYearsBunos = - _yearlySalaryRepository.GetMontlyBunosYears(foundMandatoryCompute.weeklyTime, found.ContractStart, found.ContractEnd, - foundMandatoryCompute.SalaryCompute.MoneyToDouble(), foundMandatoryCompute.SumTime44, foundMandatoryCompute.OfficialHoliday, - int.Parse(foundMandatoryCompute.NumberOfFriday), foundMandatoryCompute.TotalHolidayAndNotH, foundMandatoryCompute.TotalHolidayAndNotM, - foundMandatoryCompute.Basic, foundMandatoryCompute.FridayStartToEnd, foundMandatoryCompute.DayliFeeComplete, hasRollCall, getContractsData.Data.WorkshopHolidayWorking, item.WorkingHours.ShiftWork); - double foundMontlySalary = MontlyYearsBunos.MontlyWage + MontlyYearsBunos.BasicYears; - int foundTotaldays = Convert.ToInt32(MontlyYearsBunos.SumOfWorkingDay); - double foundDayliWage = foundMontlySalary / foundTotaldays; - if (bunosesPay.NotCompleted) - { - double foundBonuses = ((foundDayliWage * 60) / 365) * foundTotaldays; - bunosesPay.Bunoses += foundBonuses; - bunosesPay.TotalDayCompute += foundTotaldays; - } - - if (yearsPay.NotCompleted) - { - double foundBonuses = ((foundDayliWage * 30) / 365) * foundTotaldays; - yearsPay.YearsPay += foundBonuses; - yearsPay.TotalDayCompute += foundTotaldays; - } - - } + totalLeaveCompute = startMonth != endMonth; + abcenseDeductionCompute = (startMonth != endMonth && item.Separation.HasLeft) || (startMonth != endMonth && item.ContractEndGr == item.Separation.ContractEndGr); + break; } - } - #endregion - //مزد مرخصی جدید - var leavePayNew = _yearlySalaryRepository.LeavePay(item.Separation.ContarctStart, - item.Separation.LeftWorkDate, item.Separation.ContractStartGr, item.Separation.ContractEndGr, - dayliWage, item.ComputeOption, item.Separation.HasLeft, item.Separation.StartWorkDate, + //دستمزد روزانه بدون تاثیر ساعت کار + #region DailyWageCommpute + + var contract = new EditContract() + { + ContractStartGr = item.ContractStartGr, + ContractEndGr = item.ContractEndGr, + DailySalaryUnAffected = item.DailySalaryUnAffected, + DailyWageType = item.DailyWageType, + ContarctStart = item.ContractStart, + ContractEnd = item.ContractEnd, + GetWorkDate = item.FirstGetWorkingDay, + GetWorkDateHide = item.FirstGetWorkingDay, + + }; + + //دستمزد روزانه بدون تاثیر ساعت کار + var dailyWageUnAffected = await _yearlySalaryRepository.GetCheckoutDailyWage(contract, + item.Separation.ContractStartGr, item.Separation.ContractEndGr); + + #endregion + + + + + var hasRollCall = await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, item.Separation.ContractStartGr, item.Separation.ContractEndGr); + if (getContractsData.Data.IsStaticCheckout) + hasRollCall = false; + + //محاسبه موظفی + #region MandatoryCompute + var mandatoryCompute = new ComputingViewModel(); + + item.WorkingHours.ContractStartGr = item.Separation.ContractStartGr; + item.WorkingHours.ContractEndGr = item.Separation.ContractEndGr; + item.WorkingHours.ContarctStart = item.Separation.ContarctStart; + item.WorkingHours.ContractEnd = item.Separation.ContractEnd; + item.WorkingHours.GetWorkDate = contract.GetWorkDate; + item.WorkingHours.GetWorkDateHide = contract.GetWorkDate; + item.WorkingHours.WorkshopId = workshopId; + item.WorkingHours.EmployeeId = item.EmployeeId; + + mandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(item.EmployeeId, workshopId, + item.Separation.ContractStartGr, item.Separation.ContractEndGr, item.WorkingHours, getContractsData.Data.WorkshopHolidayWorking, + hasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); + + #endregion + + + if (contract.EmployeeId == 9659) + mandatoryCompute.SumTime44 = "48 - 24"; + + var officialHoliday = mandatoryCompute.OfficialHoliday; + var Friday = int.Parse(mandatoryCompute.NumberOfFriday); + var fridayStartToEnd = mandatoryCompute.FridayStartToEnd; + + var totalHoursH = mandatoryCompute.TotalHoursesH; + var totalHoursM = mandatoryCompute.TotalHoursesM; + var dayliWage = mandatoryCompute.SalaryCompute.MoneyToDouble(); + var consumableItemDouble = mandatoryCompute.ConsumableItems.MoneyToDouble(); + var housingAllowanceDouble = mandatoryCompute.HousingAllowance.MoneyToDouble(); + var familyAllowanceDouble = mandatoryCompute.FamilyAllowance.MoneyToDouble(); + var marriedAllowanceDouble = mandatoryCompute.MarriedAllowance.MoneyToDouble(); + + //اضافه کاری + var overTimePay = _yearlySalaryRepository.GetOverTimeWorking(dayliWage, + mandatoryCompute.OverTimeWorkH, mandatoryCompute.OverTimeWorkM); + //شبکاری + var overNightPay = _yearlySalaryRepository.GetOverNightWorking(dayliWage, + mandatoryCompute.OverNightWorkH, mandatoryCompute.OverNightWorkM, mandatoryCompute.SumTime44, + officialHoliday, Friday, item.Separation.ContractStartGr, item.Separation.ContractEndGr, totalHoursH, + totalHoursM); + + + //سنوات + var yearsPay = _yearlySalaryRepository.Years(item.Separation.ContractStartGr, item.Separation.LeftWorkDate, + item.Separation.ContractEndGr, + dayliWage, item.YearsOption, item.Separation.HasLeft, item.Separation.StartWorkDate, contract.ContractStartGr, + contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, getContractsData.Data.IsOldContract); + //عیدی + #region BonusesPay + var bunosesPay = _yearlySalaryRepository.Bunoses(item.Separation.ContarctStart, item.Separation.LeftWorkDate, + item.Separation.ContractStartGr, item.Separation.ContractEndGr, + dayliWage, item.BonusesOption, item.Separation.HasLeft, item.Separation.StartWorkDate, contract.ContractStartGr, - contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, fridayStartToEnd, - officialHoliday, totalHoursH, totalHoursM, consumableItemDouble, housingAllowanceDouble, - familyAllowanceDouble, marriedAllowanceDouble, getContractsData.Data.IsOldContract); - - - - - #region Insurance - - double insuranceShare = 0; - //اگر پرسنل داری شروع بکار بیمه بود - var insuranceEmployeeDataItem = - insuranceEmployeeData.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId); - - //اگر لیست بیمه برای پرسنل ساخته شده بود - var insuranceListDataWithDetails = - insuranceListData.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId); - if (insuranceListDataWithDetails != null) - { - insuranceShare = insuranceListDataWithDetails.InsuranceShare; - } - else - { - if (insuranceEmployeeDataItem != null && insuranceEmployeeDataItem.StartWorkDateGr <= item.Separation.ContractEndGr) + contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, getContractsData.Data.IsOldContract); + //اگر تصفیه حساب پاک شده برای عیدی یا سنوات وجود داشت + if (bunosesPay.NotCompleted || yearsPay.NotCompleted) { - var workingDays = Tools.GetEmployeeInsuranceWorkingDays(insuranceEmployeeDataItem.StartWorkDateGr, item.Separation.LeftWorkDate, startDateGr, endDateGr, insuranceEmployeeDataItem.EmployeeId); - var leftWorkFa = workingDays.hasLeftWorkInMonth ? item.Separation.LeftWorkDate.ToFarsi() : ""; - //به دست آوردن دستمزد روزانه با توجه به اینکه کارگاه مشاغل مقطوع است یا خیر + List lostCheckoutsDates = new List(); + if ((bunosesPay.NotCompleted && yearsPay.NotCompleted) || (bunosesPay.NotCompleted && !yearsPay.NotCompleted)) + lostCheckoutsDates = bunosesPay.BunosesStatusList; + if (!bunosesPay.NotCompleted && yearsPay.NotCompleted) + lostCheckoutsDates = yearsPay.BunosesStatusList; - double dailyWage = 0; - if (getContractsData.Data.FixedSalary) + foreach (var found in lostCheckoutsDates) { - var res = _insuranceListApplication.GetDailyWageFixedSalary(year, getContractsData.Data.WorkshopId, insuranceEmployeeDataItem.EmployeeId, startDateGr, - endDateGr, insuranceEmployeeDataItem.JobId, getContractsData.Data.Population, getContractsData.Data.InsuranceJobId); - dailyWage = res ?? 0; + ComputingViewModel foundMandatoryCompute = new ComputingViewModel(); + var foundContract = _contractRepository.GetContractByStartEnd(found.ContractStart, + found.ContractEnd, contract.WorkshopIds, contract.EmployeeId); + if (foundContract.Id > 0) + { + var foundWorkingHours = _workingHoursTempRepository.GetByContractIdConvertToShiftwork4(foundContract.Id); + foundWorkingHours.ContractStartGr = found.ContractStart; + foundWorkingHours.ContractEndGr = found.ContractEnd; + foundWorkingHours.ContarctStart = found.ContractStart.ToFarsi(); + foundWorkingHours.ContractEnd = found.ContractEnd.ToFarsi(); + foundWorkingHours.GetWorkDate = foundContract.GetWorkDate; + foundWorkingHours.GetWorkDateHide = foundContract.GetWorkDate; + foundWorkingHours.WorkshopId = contract.WorkshopIds; + foundWorkingHours.EmployeeId = contract.EmployeeId; + bool foundHasRollCall = await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, found.ContractStart, found.ContractEnd); + + if (getContractsData.Data.IsStaticCheckout) + foundHasRollCall = false; + + foundMandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(contract.EmployeeId, + contract.WorkshopIds, + found.ContractStart, found.ContractEnd, foundWorkingHours, getContractsData.Data.WorkshopHolidayWorking, foundHasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); + + + + + + var MontlyYearsBunos = + _yearlySalaryRepository.GetMontlyBunosYears(foundMandatoryCompute.weeklyTime, found.ContractStart, found.ContractEnd, + foundMandatoryCompute.SalaryCompute.MoneyToDouble(), foundMandatoryCompute.SumTime44, foundMandatoryCompute.OfficialHoliday, + int.Parse(foundMandatoryCompute.NumberOfFriday), foundMandatoryCompute.TotalHolidayAndNotH, foundMandatoryCompute.TotalHolidayAndNotM, + foundMandatoryCompute.Basic, foundMandatoryCompute.FridayStartToEnd, foundMandatoryCompute.DayliFeeComplete, hasRollCall, getContractsData.Data.WorkshopHolidayWorking, item.WorkingHours.ShiftWork); + double foundMontlySalary = MontlyYearsBunos.MontlyWage + MontlyYearsBunos.BasicYears; + int foundTotaldays = Convert.ToInt32(MontlyYearsBunos.SumOfWorkingDay); + double foundDayliWage = foundMontlySalary / foundTotaldays; + if (bunosesPay.NotCompleted) + { + double foundBonuses = ((foundDayliWage * 60) / 365) * foundTotaldays; + bunosesPay.Bunoses += foundBonuses; + bunosesPay.TotalDayCompute += foundTotaldays; + } + + if (yearsPay.NotCompleted) + { + double foundBonuses = ((foundDayliWage * 30) / 365) * foundTotaldays; + yearsPay.YearsPay += foundBonuses; + yearsPay.TotalDayCompute += foundTotaldays; + } + + } } - else - { - var res = _insuranceListApplication.ComputeDailyWage(yearlysaleries.DayliWage, insuranceEmployeeDataItem.EmployeeId, getContractsData.Data.WorkshopId, year); - dailyWage = res; - } - - //بدست آوردن پایه سنوات - var baseYears = _insuranceListRepository.GetEmployeeInsuranceBaseYear(insuranceEmployeeDataItem.EmployeeId, getContractsData.Data.WorkshopId, - workingDays.countWorkingDays, startDateGr, endDateGr, workingDays.startWork, workingDays.endWork, workingDays.hasLeftWorkInMonth); - - //جمع مزد روزانه و پایه سنوات - var dailyWagePlusBaseYears = dailyWage + baseYears.baseYear; - - - //دستمزد ماهانه با محاسبه پایه سنوات - var monthlySalary = Tools.GetRoundDoubleValue(dailyWagePlusBaseYears * workingDays.countWorkingDays); - - //حق تاهل - var marriedAllowanceForInsurance = item.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0; - - //محاسبه مزایای ماهانه - var monthlyBenefits = _insuranceListApplication.GetMonthlyBenefits(endOfMonth, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marriedAllowanceForInsurance, workingDays.countWorkingDays, getContractsData.Data.TypeOfInsuranceSend, insuranceEmployeeDataItem.JobId, insuranceEmployeeDataItem.EmployeeId, insuranceEmployeeDataItem.IncludeStatus); - if (getContractsData.Data.HasInsuranceCheckoutOverTime) - { - - monthlyBenefits = Tools.GetRoundDoubleValue(monthlyBenefits += overTimePay); - } - - //محاسبه جمع مزایای مشمول و دستمزد ماهانه - var benefitsIncludedContinuous = monthlyBenefits + monthlySalary; - - //محاسبه حق بیمه سهم بیمه شده - insuranceShare = (benefitsIncludedContinuous * 7) / 100; } - } + + #endregion + + //مزد مرخصی جدید + var leavePayNew = _yearlySalaryRepository.LeavePay(item.Separation.ContarctStart, + item.Separation.LeftWorkDate, item.Separation.ContractStartGr, item.Separation.ContractEndGr, + dayliWage, item.ComputeOption, item.Separation.HasLeft, item.Separation.StartWorkDate, + contract.ContractStartGr, + contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, fridayStartToEnd, + officialHoliday, totalHoursH, totalHoursM, consumableItemDouble, housingAllowanceDouble, + familyAllowanceDouble, marriedAllowanceDouble, getContractsData.Data.IsOldContract); - #endregion - - #region ResultToSave - var syear = Convert.ToInt32(item.ContractStart.Substring(0, 4)); - var smonth = Convert.ToInt32(item.ContractStart.Substring(5, 2)); + #region Insurance - string monthfarsiName = (item.ContractStart.Substring(5, 2)).ToFarsiMonthByNumber(); - - var yearShamsi = item.ContractStart.Substring(0, 4); + double insuranceShare = 0; + //اگر پرسنل داری شروع بکار بیمه بود + var insuranceEmployeeDataItem = + insuranceEmployeeData.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId); - - var dayliWageDouble = mandatoryCompute.SalaryCompute.MoneyToDouble(); - // کمک هزینه اقلام - var consumableItem = mandatoryCompute.ConsumableItems.MoneyToDouble(); - //حق اولاد - var familyAllowance = mandatoryCompute.FamilyAllowance.MoneyToDouble(); - //کمک هزینه مسکن - var housingAllowance = mandatoryCompute.HousingAllowance.MoneyToDouble(); - //حق تاهل - var marriedAllowance = mandatoryCompute.MarriedAllowance.MoneyToDouble(); - - #region Salary - - var totalDays = (item.Separation.ContractEndGr - item.Separation.ContractStartGr).TotalDays + 1; - - //حقوق ماهانه - var monthlyWage = mandatoryCompute.DailySalaryAffected * totalDays; - //پایه سنوات - var bacicYears = mandatoryCompute.BaseYearAffected * totalDays; - #endregion - - - //سنوات - var years = yearsPay.YearsPay; - //عیدی و پاداش - var bunos = bunosesPay.Bunoses; - - //فاطمه احمدژاد === موقت عیدی و پاداش و سنوات حساب نشه - if (item.EmployeeId == 45104 && getContractsData.Data.WorkshopId == 315) - { - years = 0; - - bunos = 0; - } - - //تعداد زروز های فیش - var sumOfWorkingDays = $"{totalDays}"; - - //مبلغ جمعه کاری - double fridayPay = 0; - if (Friday > 0) - { - var fridayPercent = dayliWageDouble * 40 / 100; - //فوق العاده جمعه کاری - fridayPay = fridayPercent * Friday; - } - - - //حق بیمه سهم کارگر - #region InsuranceDeduction - - double insuranceDeduction = 0; - bool hasInsuranceShareTheSameAsList = false; - var inshuranceShareRound = Tools.GetRoundDoubleValue(insuranceShare); - if (inshuranceShareRound == 0) - { - var insuranceOverTime = getContractsData.Data.HasInsuranceCheckoutOverTime ? overTimePay : 0; - insuranceDeduction = (monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + insuranceOverTime) * 7 / 100; - } - else - { - insuranceDeduction = inshuranceShareRound; - hasInsuranceShareTheSameAsList = true; - } - - - #endregion - - //مقادیر - روز - تعداد - ساعت - #region Values - - //مدت شب کاری - var overNightWorkValue = - $"{Convert.ToInt32(mandatoryCompute.OverNightWorkH):00}:{Convert.ToInt32(mandatoryCompute.OverNightWorkM):00}"; - //تعداد جمعه کاری - var fridayWorkValue = $"{Friday}"; - //نوع نوبت کاری - var rotatingShiftValue = mandatoryCompute.RotatingShiftValue; - // تعداد سال های سنوات - var totalDayOfYearsCompute = yearsPay.YearsPay > 0 ? $"{yearsPay.TotalDayCompute}" : "0"; - //تعداد روز های عیدی و پاداش - var totalDayOfBunosesCompute = bunosesPay.Bunoses > 0 ? $"{bunosesPay.TotalDayCompute}" : "0"; - //مدت اضافه کارس - var overTimeWorkValue = - $"{Convert.ToInt32(mandatoryCompute.OverTimeWorkH):00}:{Convert.ToInt32(mandatoryCompute.OverTimeWorkM):00}"; - - - #endregion - - //کسر اضافه کار از غیبت یا بلعکس - #region OverTimeAndAbsencSubtraction - var absenceDeduction = abcenseDeductionCompute ? leavePayNew.AbsenceDeduction : 0; - - if (overTimePay > 0 && absenceDeduction > 0) - { - if (absenceDeduction >= overTimePay) + //اگر لیست بیمه برای پرسنل ساخته شده بود + var insuranceListDataWithDetails = + insuranceListData.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId); + if (insuranceListDataWithDetails != null) { - absenceDeduction -= overTimePay; - overTimePay = 0; - overTimeWorkValue = "00:00"; + insuranceShare = insuranceListDataWithDetails.InsuranceShare; } else { - overTimePay -= absenceDeduction; - absenceDeduction = 0; + if (insuranceEmployeeDataItem != null && insuranceEmployeeDataItem.StartWorkDateGr <= item.Separation.ContractEndGr) + { + var workingDays = Tools.GetEmployeeInsuranceWorkingDays(insuranceEmployeeDataItem.StartWorkDateGr, item.Separation.LeftWorkDate, startDateGr, endDateGr, insuranceEmployeeDataItem.EmployeeId); + var leftWorkFa = workingDays.hasLeftWorkInMonth ? item.Separation.LeftWorkDate.ToFarsi() : ""; + + //به دست آوردن دستمزد روزانه با توجه به اینکه کارگاه مشاغل مقطوع است یا خیر + + double dailyWage = 0; + if (getContractsData.Data.FixedSalary) + { + var res = _insuranceListApplication.GetDailyWageFixedSalary(year, getContractsData.Data.WorkshopId, insuranceEmployeeDataItem.EmployeeId, startDateGr, + endDateGr, insuranceEmployeeDataItem.JobId, getContractsData.Data.Population, getContractsData.Data.InsuranceJobId); + dailyWage = res ?? 0; + + } + else + { + var res = _insuranceListApplication.ComputeDailyWage(yearlysaleries.DayliWage, insuranceEmployeeDataItem.EmployeeId, getContractsData.Data.WorkshopId, year); + dailyWage = res; + } + + //بدست آوردن پایه سنوات + var baseYears = _insuranceListRepository.GetEmployeeInsuranceBaseYear(insuranceEmployeeDataItem.EmployeeId, getContractsData.Data.WorkshopId, + workingDays.countWorkingDays, startDateGr, endDateGr, workingDays.startWork, workingDays.endWork, workingDays.hasLeftWorkInMonth); + + //جمع مزد روزانه و پایه سنوات + var dailyWagePlusBaseYears = dailyWage + baseYears.baseYear; + + + //دستمزد ماهانه با محاسبه پایه سنوات + var monthlySalary = Tools.GetRoundDoubleValue(dailyWagePlusBaseYears * workingDays.countWorkingDays); + + //حق تاهل + var marriedAllowanceForInsurance = item.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0; + + //محاسبه مزایای ماهانه + var monthlyBenefits = _insuranceListApplication.GetMonthlyBenefits(endOfMonth, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marriedAllowanceForInsurance, workingDays.countWorkingDays, getContractsData.Data.TypeOfInsuranceSend, insuranceEmployeeDataItem.JobId, insuranceEmployeeDataItem.EmployeeId, insuranceEmployeeDataItem.IncludeStatus); + if (getContractsData.Data.HasInsuranceCheckoutOverTime) + { + + monthlyBenefits = Tools.GetRoundDoubleValue(monthlyBenefits += overTimePay); + } + + //محاسبه جمع مزایای مشمول و دستمزد ماهانه + var benefitsIncludedContinuous = monthlyBenefits + monthlySalary; + + //محاسبه حق بیمه سهم بیمه شده + insuranceShare = (benefitsIncludedContinuous * 7) / 100; + } } - } - #endregion - - //مساعده - #region SalaryAid - - var salaryAids = - _rollCallMandatoryRepository.SalaryAidsForCheckout(contract.EmployeeId, contract.WorkshopIds, startDateGr, endDateGr) - .Select(x => new CheckoutSalaryAid(x.Amount, x.SalaryAidDateTimeGe, x.SalaryAidDateTimeFa, x.CalculationDateTimeGe, x.CalculationDateTimeFa, x.Id)).ToList(); - - var salaryAidDeduction = salaryAids.Sum(x => x.Amount.MoneyToDouble()); - - #endregion - - //اقساط وام - #region LoanInstallment - - var loanInstallments = _rollCallMandatoryRepository.LoanInstallmentForCheckout(contract.EmployeeId, contract.WorkshopIds, - item.Separation.ContractStartGr, item.Separation.HasLeft ? DateTime.MaxValue : item.Separation.ContractEndGr) - .Select(x => - new CheckoutLoanInstallment(x.Amount, x.Month, x.Year, x.IsActive, x.RemainingAmount, x.LoanAmount, x.Id)).ToList(); - - var installmentDeduction = loanInstallments.Sum(x => x.AmountForMonth.MoneyToDouble()); - - #endregion - - //پاداش - #region Reward - var rewards = new List(); - double rewardPay = 0; - if (getContractsData.Data.RewardComputeOnCheckout) - { - rewards = _rollCallMandatoryRepository.RewardForCheckout(contract.EmployeeId, contract.WorkshopIds, startDateGr, endDateGr) - .Select(x => new CheckoutReward(x.Amount, x.AmountDouble, x.GrantDateFa, x.GrantDateGr, x.Description, x.Title, x.Id)).ToList(); + #endregion - rewardPay = rewards.Sum(x => x.AmountDouble); - } + #region ResultToSave - #endregion + var syear = Convert.ToInt32(item.ContractStart.Substring(0, 4)); + var smonth = Convert.ToInt32(item.ContractStart.Substring(5, 2)); - //جدول حضورغیاب پرسنل - #region CheckoutRollCall + string monthfarsiName = (item.ContractStart.Substring(5, 2)).ToFarsiMonthByNumber(); - //کارکرد واقعی - محاسبات شامل مرخصی افزوده شده - var totalWorkingTimeSpan = mandatoryCompute.TotalWorkingTimeSpan; - //ساعت استراحت - var totalBreakTimeSpan = mandatoryCompute.TotalBreakTimeSpan; - // ساعت حضور - بدون مرخصی افزده شده - var totalPresentTimeSpan = mandatoryCompute.TotalPresentTimeSpan; - //مدت مرخصی استحقاقی - var totalPaidLeave = mandatoryCompute.TotalPaidLeave; - //مدت مرخصی استعلاجی - var totalSickLeave = mandatoryCompute.TotalSickLeave; + var yearShamsi = item.ContractStart.Substring(0, 4); - var firstDayOfMonth = startDateGr; - var firstDayOfCurrentMonth = new DateTime(syear, smonth, 1, new PersianCalendar()); + var dayliWageDouble = mandatoryCompute.SalaryCompute.MoneyToDouble(); + // کمک هزینه اقلام + var consumableItem = mandatoryCompute.ConsumableItems.MoneyToDouble(); + //حق اولاد + var familyAllowance = mandatoryCompute.FamilyAllowance.MoneyToDouble(); + //کمک هزینه مسکن + var housingAllowance = mandatoryCompute.HousingAllowance.MoneyToDouble(); + //حق تاهل + var marriedAllowance = mandatoryCompute.MarriedAllowance.MoneyToDouble(); - LeaveSearchModel sickLeaveSearch = new LeaveSearchModel() - { - EmployeeId = contract.EmployeeId, - WorkshopId = contract.WorkshopIds, - StartLeaveGr = item.Separation.ContractStartGr, - EndLeaveGr = item.Separation.ContractEndGr, - IsAccepted = true, - }; - var leaves = _leaveApplication.search(sickLeaveSearch); + #region Salary - firstDayOfMonth.AddMonthsFa(1, out var lastDayOfCurrentMonth); + var totalDays = (item.Separation.ContractEndGr - item.Separation.ContractStartGr).TotalDays + 1; - lastDayOfCurrentMonth = lastDayOfCurrentMonth.AddDays(-1); + //حقوق ماهانه + var monthlyWage = mandatoryCompute.DailySalaryAffected * totalDays; + //پایه سنوات + var bacicYears = mandatoryCompute.BaseYearAffected * totalDays; + #endregion - int dateRange = (int)(lastDayOfCurrentMonth - firstDayOfCurrentMonth).TotalDays + 1; - var holidays = _holidayItemApplication.Search(new HolidayItemSearchModel() - { - HolidayYear = item.Separation.ContractStartGr.ToFarsiYear() - }); - //all the dates from start to end, to be compared with present days to get absent dates - var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => firstDayOfCurrentMonth.AddDays(offset).Date).ToList(); + //سنوات + var years = yearsPay.YearsPay; + //عیدی و پاداش + var bunos = bunosesPay.Bunoses; - var absentRecords = completeDaysList - .ExceptBy(mandatoryCompute.GroupedRollCalls.Select(x => x.CreationDate.Date), y => y.Date) - .Select(x => + //فاطمه احمدژاد === موقت عیدی و پاداش و سنوات حساب نشه + if (item.EmployeeId == 45104 && getContractsData.Data.WorkshopId == 315) { - var leave = leaves.FirstOrDefault(y => - y.EmployeeId == contract.EmployeeId && y.EndLeaveGr.Date >= x.Date && y.StartLeaveGr.Date <= x.Date); - var isHoliday = holidays.Any(y => y.HolidaydateGr == x.Date); - var isFriday = x.Date.DayOfWeek == DayOfWeek.Friday; - var isNormalWorkingDay = isHoliday == false && isFriday == false; + years = 0; + + bunos = 0; + } + + //تعداد زروز های فیش + var sumOfWorkingDays = $"{totalDays}"; + + //مبلغ جمعه کاری + double fridayPay = 0; + if (Friday > 0) + { + var fridayPercent = dayliWageDouble * 40 / 100; + //فوق العاده جمعه کاری + fridayPay = fridayPercent * Friday; + } + + + //حق بیمه سهم کارگر + #region InsuranceDeduction + + double insuranceDeduction = 0; + bool hasInsuranceShareTheSameAsList = false; + var inshuranceShareRound = Tools.GetRoundDoubleValue(insuranceShare); + if (inshuranceShareRound == 0) + { + var insuranceOverTime = getContractsData.Data.HasInsuranceCheckoutOverTime ? overTimePay : 0; + insuranceDeduction = (monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + insuranceOverTime) * 7 / 100; + } + else + { + insuranceDeduction = inshuranceShareRound; + hasInsuranceShareTheSameAsList = true; + } + + + #endregion + + //مقادیر - روز - تعداد - ساعت + #region Values + + //مدت شب کاری + var overNightWorkValue = + $"{Convert.ToInt32(mandatoryCompute.OverNightWorkH):00}:{Convert.ToInt32(mandatoryCompute.OverNightWorkM):00}"; + //تعداد جمعه کاری + var fridayWorkValue = $"{Friday}"; + //نوع نوبت کاری + var rotatingShiftValue = mandatoryCompute.RotatingShiftValue; + // تعداد سال های سنوات + var totalDayOfYearsCompute = yearsPay.YearsPay > 0 ? $"{yearsPay.TotalDayCompute}" : "0"; + //تعداد روز های عیدی و پاداش + var totalDayOfBunosesCompute = bunosesPay.Bunoses > 0 ? $"{bunosesPay.TotalDayCompute}" : "0"; + //مدت اضافه کارس + var overTimeWorkValue = + $"{Convert.ToInt32(mandatoryCompute.OverTimeWorkH):00}:{Convert.ToInt32(mandatoryCompute.OverTimeWorkM):00}"; + + + #endregion + + //کسر اضافه کار از غیبت یا بلعکس + #region OverTimeAndAbsencSubtraction + var absenceDeduction = abcenseDeductionCompute ? leavePayNew.AbsenceDeduction : 0; + + if (overTimePay > 0 && absenceDeduction > 0) + { + if (absenceDeduction >= overTimePay) + { + absenceDeduction -= overTimePay; + overTimePay = 0; + overTimeWorkValue = "00:00"; + } + else + { + overTimePay -= absenceDeduction; + absenceDeduction = 0; + } + + } + #endregion + + //مساعده + #region SalaryAid + + var salaryAids = + _rollCallMandatoryRepository.SalaryAidsForCheckout(contract.EmployeeId, contract.WorkshopIds, startDateGr, endDateGr) + .Select(x => new CheckoutSalaryAid(x.Amount, x.SalaryAidDateTimeGe, x.SalaryAidDateTimeFa, x.CalculationDateTimeGe, x.CalculationDateTimeFa, x.Id)).ToList(); + + var salaryAidDeduction = salaryAids.Sum(x => x.Amount.MoneyToDouble()); + + #endregion + + //اقساط وام + #region LoanInstallment + + var loanInstallments = _rollCallMandatoryRepository.LoanInstallmentForCheckout(contract.EmployeeId, contract.WorkshopIds, + item.Separation.ContractStartGr, item.Separation.HasLeft ? DateTime.MaxValue : item.Separation.ContractEndGr) + .Select(x => + new CheckoutLoanInstallment(x.Amount, x.Month, x.Year, x.IsActive, x.RemainingAmount, x.LoanAmount, x.Id)).ToList(); + + var installmentDeduction = loanInstallments.Sum(x => x.AmountForMonth.MoneyToDouble()); + + #endregion + + //پاداش + #region Reward + + + var rewards = new List(); + double rewardPay = 0; + if (getContractsData.Data.RewardComputeOnCheckout) + { + rewards = _rollCallMandatoryRepository.RewardForCheckout(contract.EmployeeId, contract.WorkshopIds, startDateGr, endDateGr) + .Select(x => new CheckoutReward(x.Amount, x.AmountDouble, x.GrantDateFa, x.GrantDateGr, x.Description, x.Title, x.Id)).ToList(); + + rewardPay = rewards.Sum(x => x.AmountDouble); + } + + #endregion + + //جدول حضورغیاب پرسنل + #region CheckoutRollCall + + //کارکرد واقعی - محاسبات شامل مرخصی افزوده شده + var totalWorkingTimeSpan = mandatoryCompute.TotalWorkingTimeSpan; + //ساعت استراحت + var totalBreakTimeSpan = mandatoryCompute.TotalBreakTimeSpan; + // ساعت حضور - بدون مرخصی افزده شده + var totalPresentTimeSpan = mandatoryCompute.TotalPresentTimeSpan; + //مدت مرخصی استحقاقی + var totalPaidLeave = mandatoryCompute.TotalPaidLeave; + //مدت مرخصی استعلاجی + var totalSickLeave = mandatoryCompute.TotalSickLeave; + + + var firstDayOfMonth = startDateGr; + var firstDayOfCurrentMonth = new DateTime(syear, smonth, 1, new PersianCalendar()); + + LeaveSearchModel sickLeaveSearch = new LeaveSearchModel() + { + EmployeeId = contract.EmployeeId, + WorkshopId = contract.WorkshopIds, + StartLeaveGr = item.Separation.ContractStartGr, + EndLeaveGr = item.Separation.ContractEndGr, + IsAccepted = true, + }; + var leaves = _leaveApplication.search(sickLeaveSearch); + + firstDayOfMonth.AddMonthsFa(1, out var lastDayOfCurrentMonth); + + lastDayOfCurrentMonth = lastDayOfCurrentMonth.AddDays(-1); + + int dateRange = (int)(lastDayOfCurrentMonth - firstDayOfCurrentMonth).TotalDays + 1; + + var holidays = _holidayItemApplication.Search(new HolidayItemSearchModel() + { + HolidayYear = item.Separation.ContractStartGr.ToFarsiYear() + }); + //all the dates from start to end, to be compared with present days to get absent dates + var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => firstDayOfCurrentMonth.AddDays(offset).Date).ToList(); + + var absentRecords = completeDaysList + .ExceptBy(mandatoryCompute.GroupedRollCalls.Select(x => x.CreationDate.Date), y => y.Date) + .Select(x => + { + var leave = leaves.FirstOrDefault(y => + y.EmployeeId == contract.EmployeeId && y.EndLeaveGr.Date >= x.Date && y.StartLeaveGr.Date <= x.Date); + var isHoliday = holidays.Any(y => y.HolidaydateGr == x.Date); + var isFriday = x.Date.DayOfWeek == DayOfWeek.Friday; + var isNormalWorkingDay = isHoliday == false && isFriday == false; + return new CheckoutDailyRollCallViewModel() + { + StartDate1 = null, + EndDate1 = null, + DateTimeGr = x.Date, + DayOfWeek = x.Date.DayOfWeek.ToString(), + RollCallDateFa = x.Date.ToFarsi(), + LeaveType = leave != null ? leave.LeaveType : "", + IsAbsent = leave == null && isNormalWorkingDay + }; + }); + + + var presentDays = mandatoryCompute.GroupedRollCalls.Select(x => + { + + var orderedRollcalls = x.ShiftList.OrderBy(y => y.Start); + + var rollCallTimeSpanPerDay = x.SumOneDaySpan; + TimeSpan breakTimePerDay = x.BreakTime; + return new CheckoutDailyRollCallViewModel() { - StartDate1 = null, - EndDate1 = null, - DateTimeGr = x.Date, - DayOfWeek = x.Date.DayOfWeek.ToString(), - RollCallDateFa = x.Date.ToFarsi(), - LeaveType = leave != null ? leave.LeaveType : "", - IsAbsent = leave == null && isNormalWorkingDay + StartDate1 = orderedRollcalls.FirstOrDefault().Start.ToString("HH:mm"), + EndDate1 = orderedRollcalls.FirstOrDefault().EndWithOutResTime.ToString("HH:mm"), + + StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.Start.ToString("HH:mm") ?? "", + EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndWithOutResTime.ToString("HH:mm") ?? "", + + TotalhourseSpan = rollCallTimeSpanPerDay, + + BreakTimeTimeSpan = breakTimePerDay, + + DayOfWeek = x.CreationDate.DayOfWeek.DayOfWeeKToPersian(), + RollCallDateFa = x.CreationDate.Date.ToFarsi(), + DateTimeGr = x.CreationDate.Date, + IsSliced = x.ShiftList.Count() > 2, + IsAbsent = false }; }); - var presentDays = mandatoryCompute.GroupedRollCalls.Select(x => - { - - var orderedRollcalls = x.ShiftList.OrderBy(y => y.Start); - - var rollCallTimeSpanPerDay = x.SumOneDaySpan; - TimeSpan breakTimePerDay = x.BreakTime; - - return new CheckoutDailyRollCallViewModel() + presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel { - StartDate1 = orderedRollcalls.FirstOrDefault().Start.ToString("HH:mm"), - EndDate1 = orderedRollcalls.FirstOrDefault().EndWithOutResTime.ToString("HH:mm"), - - StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.Start.ToString("HH:mm") ?? "", - EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndWithOutResTime.ToString("HH:mm") ?? "", - - TotalhourseSpan = rollCallTimeSpanPerDay, - - BreakTimeTimeSpan = breakTimePerDay, - - DayOfWeek = x.CreationDate.DayOfWeek.DayOfWeeKToPersian(), - RollCallDateFa = x.CreationDate.Date.ToFarsi(), - DateTimeGr = x.CreationDate.Date, - IsSliced = x.ShiftList.Count() > 2, + StartDate1 = x.StartDate1, + EndDate1 = x.EndDate1, + EndDate2 = x.EndDate2, + StartDate2 = x.StartDate2, + TotalWorkingHours = $"{(int)(x.TotalhourseSpan.TotalHours)}:{x.TotalhourseSpan.Minutes:00}", + BreakTimeString = $"{(int)(x.BreakTimeTimeSpan.TotalHours)}:{x.BreakTimeTimeSpan.Minutes:00}", + TotalhourseSpan = x.TotalhourseSpan, + BreakTimeTimeSpan = x.BreakTimeTimeSpan, + DayOfWeek = x.DayOfWeek, + RollCallDateFa = x.RollCallDateFa, + DateTimeGr = x.DateTimeGr, + IsSliced = x.IsSliced, IsAbsent = false - }; - }); + }); + + var result = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); + result.ForEach(x => + { + x.IsHoliday = holidays.Any(y => x.DateTimeGr.Date == y.HolidaydateGr.Date); + x.IsFriday = x.DateTimeGr.DayOfWeek == DayOfWeek.Friday; + }); + + var checkoutRollCallDays = result.Select(x => new CheckoutRollCallDay(x.DateTimeGr, + x.StartDate1, x.EndDate1, x.StartDate2, x.EndDate2, + x.BreakTimeTimeSpan, x.IsSliced, x.TotalhourseSpan, x.IsAbsent, x.IsFriday, x.IsHoliday, x.LeaveType)) + .ToList(); - presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel + double mandatoryHours = _mandatoryHoursApplication.GetMandatoryHoursByYearAndMonth(syear, smonth); + int mandatoryWholeHours = (int)mandatoryHours; + int mandatoryMinutes = (int)((mandatoryHours - mandatoryWholeHours) * 60); + + var totalMandatoryHours = TimeSpan.FromHours(mandatoryWholeHours).Add(TimeSpan.FromMinutes(mandatoryMinutes)); + var checkoutRollCall = new CheckoutRollCall(totalMandatoryHours, totalPresentTimeSpan, totalBreakTimeSpan, + totalWorkingTimeSpan, totalPaidLeave, totalSickLeave, checkoutRollCallDays); + #endregion + + //مقادیر پرداخت نهایی - مطالبات - کسورات + #region TotalPayment + + var shiftPay = contract.WorkshopIds == 552 && hasRollCall ? 0 : mandatoryCompute.ShiftPay; + + + var totalClaimsDouble = monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + overTimePay + + overNightPay + familyAllowance + bunos + years + leavePayNew.LeavPay + fridayPay + shiftPay + rewardPay; + var totalDeductionDouble = insuranceDeduction + absenceDeduction + installmentDeduction + salaryAidDeduction; + + //مطالبات + var totalClaims = totalClaimsDouble.ToMoney(); + //کسورات + var totalDeductions = totalDeductionDouble.ToMoney(); + + //مبلغ قابل پرداخت + var totalPayment = totalClaimsDouble - totalDeductionDouble; + + #endregion + + + #region CreateCheckoutModel + + var checkout = new Checkout(item.EmployeeFullName, item.FathersName, item.NationalCode + , item.DateOfBirth, item.EmployeeId, getContractsData.Data.WorkshopName, getContractsData.Data.WorkshopId, item.ContractNo, item.Separation.ContractStartGr, item.Separation.ContractEndGr, monthfarsiName, yearShamsi, + item.ContractId, item.WorkingHours.WorknigHoursId, monthlyWage, bacicYears, consumableItem, housingAllowance + , overTimePay, overNightPay, fridayPay, 0, shiftPay, familyAllowance, bunos, years, leavePayNew.LeavPay, insuranceDeduction, 0, installmentDeduction, salaryAidDeduction, absenceDeduction, sumOfWorkingDays, + getContractsData.Data.ArchiveCode, item.PersonnelCode, totalClaims, totalDeductions, totalPayment, "0", marriedAllowance, leavePayNew.LeaveCheckout, leavePayNew.CreditLeaves, leavePayNew.AbsencePeriod, leavePayNew.AverageHoursPerDay, hasRollCall, overTimeWorkValue, overNightWorkValue + , fridayWorkValue, rotatingShiftValue, "0", leavePayNew.TotalDayOfLeaveCompute, totalDayOfYearsCompute, totalDayOfBunosesCompute, + loanInstallments, salaryAids, checkoutRollCall, mandatoryCompute.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay); + + #endregion + + + #endregion + + + + + #region SaveToDb + + + var saveToDb = await _checkoutRepository.CreateCheckout(checkout); + if(!saveToDb) + await signalR.SendAsync() + #endregion + } + catch (Exception) { - StartDate1 = x.StartDate1, - EndDate1 = x.EndDate1, - EndDate2 = x.EndDate2, - StartDate2 = x.StartDate2, - TotalWorkingHours = $"{(int)(x.TotalhourseSpan.TotalHours)}:{x.TotalhourseSpan.Minutes:00}", - BreakTimeString = $"{(int)(x.BreakTimeTimeSpan.TotalHours)}:{x.BreakTimeTimeSpan.Minutes:00}", - TotalhourseSpan = x.TotalhourseSpan, - BreakTimeTimeSpan = x.BreakTimeTimeSpan, - DayOfWeek = x.DayOfWeek, - RollCallDateFa = x.RollCallDateFa, - DateTimeGr = x.DateTimeGr, - IsSliced = x.IsSliced, - IsAbsent = false - }); - var result = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); - result.ForEach(x => - { - x.IsHoliday = holidays.Any(y => x.DateTimeGr.Date == y.HolidaydateGr.Date); - x.IsFriday = x.DateTimeGr.DayOfWeek == DayOfWeek.Friday; - }); - - var checkoutRollCallDays = result.Select(x => new CheckoutRollCallDay(x.DateTimeGr, - x.StartDate1, x.EndDate1, x.StartDate2, x.EndDate2, - x.BreakTimeTimeSpan, x.IsSliced, x.TotalhourseSpan, x.IsAbsent, x.IsFriday, x.IsHoliday, x.LeaveType)) - .ToList(); - - - double mandatoryHours = _mandatoryHoursApplication.GetMandatoryHoursByYearAndMonth(syear, smonth); - int mandatoryWholeHours = (int)mandatoryHours; - int mandatoryMinutes = (int)((mandatoryHours - mandatoryWholeHours) * 60); - - var totalMandatoryHours = TimeSpan.FromHours(mandatoryWholeHours).Add(TimeSpan.FromMinutes(mandatoryMinutes)); - var checkoutRollCall = new CheckoutRollCall(totalMandatoryHours, totalPresentTimeSpan, totalBreakTimeSpan, - totalWorkingTimeSpan, totalPaidLeave, totalSickLeave, checkoutRollCallDays); - #endregion - - //مقادیر پرداخت نهایی - مطالبات - کسورات - #region TotalPayment - - var shiftPay = contract.WorkshopIds == 552 && hasRollCall ? 0 : mandatoryCompute.ShiftPay; - - - var totalClaimsDouble = monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + overTimePay + - overNightPay + familyAllowance + bunos + years + leavePayNew.LeavPay + fridayPay + shiftPay + rewardPay; - var totalDeductionDouble = insuranceDeduction + absenceDeduction + installmentDeduction + salaryAidDeduction; - - //مطالبات - var totalClaims = totalClaimsDouble.ToMoney(); - //کسورات - var totalDeductions = totalDeductionDouble.ToMoney(); - - //مبلغ قابل پرداخت - var totalPayment = totalClaimsDouble - totalDeductionDouble; - - #endregion - - - #region CreateCheckoutModel - - var checkout = new Checkout(item.EmployeeFullName, item.FathersName, item.NationalCode - , item.DateOfBirth, item.EmployeeId, getContractsData.Data.WorkshopName, getContractsData.Data.WorkshopId, item.ContractNo, item.Separation.ContractStartGr, item.Separation.ContractEndGr, monthfarsiName, yearShamsi, - item.ContractId, item.WorkingHours.WorknigHoursId, monthlyWage, bacicYears, consumableItem, housingAllowance - , overTimePay, overNightPay, fridayPay, 0, shiftPay, familyAllowance, bunos, years, leavePayNew.LeavPay, insuranceDeduction, 0, installmentDeduction, salaryAidDeduction, absenceDeduction, sumOfWorkingDays, - getContractsData.Data.ArchiveCode, item.PersonnelCode, totalClaims, totalDeductions, totalPayment, "0", marriedAllowance, leavePayNew.LeaveCheckout, leavePayNew.CreditLeaves, leavePayNew.AbsencePeriod, leavePayNew.AverageHoursPerDay, hasRollCall, overTimeWorkValue, overNightWorkValue - , fridayWorkValue, rotatingShiftValue, "0", leavePayNew.TotalDayOfLeaveCompute, totalDayOfYearsCompute, totalDayOfBunosesCompute, - loanInstallments, salaryAids, checkoutRollCall, mandatoryCompute.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay); - - #endregion - - - #endregion - - - - - #region SaveToDb - - - var saveToDb = await _checkoutRepository.CreateCheckout(checkout); - - #endregion + throw; + } From 2c305e1d7a4f577ac0f94b40404218a9678919d9 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Tue, 3 Feb 2026 17:47:08 +0330 Subject: [PATCH 12/13] change --- .../CheckoutApplication.cs | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 1c49bd39..7c995ee9 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -19,6 +19,7 @@ using CompanyManagment.App.Contracts.Checkout.Dto; using CompanyManagment.App.Contracts.Contract; using CompanyManagment.App.Contracts.HolidayItem; using CompanyManagment.App.Contracts.Hubs; +using CompanyManagment.App.Contracts.InstitutionContract; using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.App.Contracts.Leave; using CompanyManagment.App.Contracts.MandantoryHours; @@ -870,7 +871,12 @@ public class CheckoutApplication : ICheckoutApplication var timer = new Stopwatch(); timer.Start(); - int i = 0; + + int successProcess = 1; + int countList = getContractsData.Data.ContractIncludedData.Count; + List failedCreateList = []; + int createSuccessCount = 0; + int createFailedCount = 0; foreach (var item in getContractsData.Data.ContractIncludedData) { @@ -1472,25 +1478,36 @@ public class CheckoutApplication : ICheckoutApplication var saveToDb = await _checkoutRepository.CreateCheckout(checkout); - if(!saveToDb) - await signalR.SendAsync() + if (!saveToDb) + { + createFailedCount += 1; + failedCreateList.Add(item.EmployeeFullName); + } + else + { + createSuccessCount += 1; + } #endregion } catch (Exception) { + createFailedCount += 1; + failedCreateList.Add(item.EmployeeFullName); - throw; } + var percent = (successProcess / (double)countList) * 100; + await signalR.SendAsync("showStatus", countList, createFailedCount, createSuccessCount, (int)percent, failedCreateList); + successProcess += 1; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("================================================================== "); - Console.WriteLine("========================================Counter ================== " + (i + 1)); + Console.WriteLine("======================================== Counter " + successProcess + " ================== "); Console.WriteLine("================================================================== "); Console.ResetColor(); - i += 1; + } From ec8dfe4799efdb676bb8d9946930332e90cd3ca7 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Thu, 5 Feb 2026 14:18:11 +0330 Subject: [PATCH 13/13] change create checkout api --- .../CheckoutApplication.cs | 16 +++- .../Repository/CheckoutRepository.cs | 3 +- .../Admin/Controllers/CheckoutController.cs | 94 ++++++++----------- 3 files changed, 53 insertions(+), 60 deletions(-) diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 7c995ee9..25294eec 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -874,7 +874,7 @@ public class CheckoutApplication : ICheckoutApplication int successProcess = 1; int countList = getContractsData.Data.ContractIncludedData.Count; - List failedCreateList = []; + List createFailedList = []; int createSuccessCount = 0; int createFailedCount = 0; foreach (var item in getContractsData.Data.ContractIncludedData) @@ -938,6 +938,7 @@ public class CheckoutApplication : ICheckoutApplication if (getContractsData.Data.IsStaticCheckout) hasRollCall = false; + var isStaticCheckout = hasRollCall == false; //محاسبه موظفی #region MandatoryCompute var mandatoryCompute = new ComputingViewModel(); @@ -953,7 +954,7 @@ public class CheckoutApplication : ICheckoutApplication mandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(item.EmployeeId, workshopId, item.Separation.ContractStartGr, item.Separation.ContractEndGr, item.WorkingHours, getContractsData.Data.WorkshopHolidayWorking, - hasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); + isStaticCheckout, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute); #endregion @@ -1481,7 +1482,7 @@ public class CheckoutApplication : ICheckoutApplication if (!saveToDb) { createFailedCount += 1; - failedCreateList.Add(item.EmployeeFullName); + createFailedList.Add(item.EmployeeFullName); } else { @@ -1492,13 +1493,18 @@ public class CheckoutApplication : ICheckoutApplication catch (Exception) { createFailedCount += 1; - failedCreateList.Add(item.EmployeeFullName); + createFailedList.Add(item.EmployeeFullName); } var percent = (successProcess / (double)countList) * 100; - await signalR.SendAsync("showStatus", countList, createFailedCount, createSuccessCount, (int)percent, failedCreateList); + // await signalR.SendAsync("showStatus", countList, createFailedCount, createSuccessCount, (int)percent, createFailedList); + await signalR.SendAsync("all", countList); + await signalR.SendAsync("failed", createFailedCount); + await signalR.SendAsync("Success", createSuccessCount); + await signalR.SendAsync("percent", (int)percent); + await signalR.SendAsync("failedList", createFailedList); successProcess += 1; diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 517b02be..e8d59c8f 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -2784,8 +2784,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var op = new OperationResult(); var watcher = new Stopwatch(); watcher.Start(); + var test = _context.Contracts.FirstOrDefault(x => x.id == 290499); //دریافت قراداد ها - var getContracts =await _context.Contracts.Include(x=>x.Employee).Where(x => ids.Contains(x.id)).AsNoTracking().ToListAsync(); + var getContracts =await _context.Contracts.Where(x => ids.Contains(x.id)).Include(e=>e.Employee).AsNoTracking().ToListAsync(); if (!getContracts.Any()) return op.Failed("قرادادی یافت نشد"); diff --git a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs index c53f0e30..f572d293 100644 --- a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs +++ b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs @@ -120,14 +120,6 @@ public class CheckoutController : AdminBaseController // return new OperationResult>().Failed( // "این کارگاه به دلیل داشتن کارپوشه مجاز به ایجاد تصفیه حساب نمی باشد"); - #region testCreate - - var ids = result.Data.Where(x => x.CreateCheckoutStatus == CreateCheckoutStatus.ReadyToCreate).Select(x => x.Id).ToList(); - - Console.WriteLine(ids.ToJson()); - var test = await _checkoutApplication.CreateCheckoutApi(ids, year, month,workshopId); - - #endregion return result; @@ -139,41 +131,41 @@ public class CheckoutController : AdminBaseController /// /// [HttpPost] - public async Task CreateCheckout([FromBody]TestCreateCheckout command) + public async Task> CreateCheckout([FromBody] CreateCheckoutDto command) { - var op = new OperationResult>(); - var ids = new - List() - { - 283652, 290314, 290315, 290316, 290317, 290318, 290319, 290320, 290321, 290322, 290323, 290324, 290325, - 290326, 290327, 290328, 290329, 290330, 290331, 290332, 290333, 290334, 290335, 290336, 290337, 290338, - 290339, 290340, 290341, 290342, 290343, 290344, 290345, 290346, 290347, 290348, 290349, 290350, 290351, - 290352, 290353, 290354, 290355, 290356, 290357, 290358, 290359, 290360, 290361, 290362, 290363, 290364, - 290365, 290366, 290367, 290368, 290369, 290370, 290371, 290372, 290373, 290374, 290375, 290376, 290377, - 290378, 290379, 290380, 290381, 290382, 290383, 290384, 290385, 290386, 290387, 290388, 290389, 290390, - 290391, 290392, 290393, 290394, 290395, 290396, 290397, 290398, 290399, 290400, 290401, 290402, 290403, - 290404, 290405, 290406, 290407, 290408, 290409, 290410, 290411, 290412, 290413, 290414, 290415, 290416, - 290417, 290418, 290419, 290420, 290421, 290422, 290423, 290424, 290425, 290426, 290427, 290428, 290429, - 290430, 290431, 290432, 290433, 290434, 290435, 290436, 290437, 290438, 290439, 290440, 290441, 290442, - 290443, 290444, 290445, 290446, 290447, 290448, 290449, 290450, 290451, 290452, 290453, 290454, 290455, - 290456, 290457, 290458, 290459, 290460, 290461, 290462, 290463, 290464, 290465, 290466, 290467, 290468, - 290469, 290470, 290471, 290472, 290473, 290474, 290475, 290476, 290477, 290478, 290479, 290480, 290481, - 290482, 290483, 290484, 290485, 290486, 290487, 290488, 290489, 290490, 290491, 290492, 290493, 290494, - 290495, 290496, 290497, 290498, 290499, 290500, 290501, 290502, 290503, 290504, 290505, 290506, 290507, - 290508, 290509, 290510, 290511, 290512, 290513, 290514, 290515, 290516, 290517, 290518, 290519, 290520, - 290521, 290522, 290523, 290524, 290525, 290526, 290527, 290528, 290529, 290530, 290531, 290532, 290533, - 290534, 290535, 290536, 290537, 290538, 290539, 290540, 290541, 290542, 290543, 290544, 290545, 290546, - 290547, 290548, 290549, 290550, 290551, 290552, 290553, 290554, 290555, 290556, 290557, 290558, 290559, - 290560, 290561, 290562, 290563, 290564, 290565, 290566, 290567, 290568, 290569, 290570, 290571, 290572, - 290573, 290574, 290575, 290576, 290577, 290578, 290579, 290580, 290581, 290582, 290583, 290584, 290585, - 299612, 290587, 290588 - }; - // var ids = new List(){ 299612 }; + var op = new OperationResult(); + //var ids = new + // List() + // { + // 283652, 290314, 290315, 290316, 290317, 290318, 290319, 290320, 290321, 290322, 290323, 290324, 290325, + // 290326, 290327, 290328, 290329, 290330, 290331, 290332, 290333, 290334, 290335, 290336, 290337, 290338, + // 290339, 290340, 290341, 290342, 290343, 290344, 290345, 290346, 290347, 290348, 290349, 290350, 290351, + // 290352, 290353, 290354, 290355, 290356, 290357, 290358, 290359, 290360, 290361, 290362, 290363, 290364, + // 290365, 290366, 290367, 290368, 290369, 290370, 290371, 290372, 290373, 290374, 290375, 290376, 290377, + // 290378, 290379, 290380, 290381, 290382, 290383, 290384, 290385, 290386, 290387, 290388, 290389, 290390, + // 290391, 290392, 290393, 290394, 290395, 290396, 290397, 290398, 290399, 290400, 290401, 290402, 290403, + // 290404, 290405, 290406, 290407, 290408, 290409, 290410, 290411, 290412, 290413, 290414, 290415, 290416, + // 290417, 290418, 290419, 290420, 290421, 290422, 290423, 290424, 290425, 290426, 290427, 290428, 290429, + // 290430, 290431, 290432, 290433, 290434, 290435, 290436, 290437, 290438, 290439, 290440, 290441, 290442, + // 290443, 290444, 290445, 290446, 290447, 290448, 290449, 290450, 290451, 290452, 290453, 290454, 290455, + // 290456, 290457, 290458, 290459, 290460, 290461, 290462, 290463, 290464, 290465, 290466, 290467, 290468, + // 290469, 290470, 290471, 290472, 290473, 290474, 290475, 290476, 290477, 290478, 290479, 290480, 290481, + // 290482, 290483, 290484, 290485, 290486, 290487, 290488, 290489, 290490, 290491, 290492, 290493, 290494, + // 290495, 290496, 290497, 290498, 290499, 290500, 290501, 290502, 290503, 290504, 290505, 290506, 290507, + // 290508, 290509, 290510, 290511, 290512, 290513, 290514, 290515, 290516, 290517, 290518, 290519, 290520, + // 290521, 290522, 290523, 290524, 290525, 290526, 290527, 290528, 290529, 290530, 290531, 290532, 290533, + // 290534, 290535, 290536, 290537, 290538, 290539, 290540, 290541, 290542, 290543, 290544, 290545, 290546, + // 290547, 290548, 290549, 290550, 290551, 290552, 290553, 290554, 290555, 290556, 290557, 290558, 290559, + // 290560, 290561, 290562, 290563, 290564, 290565, 290566, 290567, 290568, 290569, 290570, 290571, 290572, + // 290573, 290574, 290575, 290576, 290577, 290578, 290579, 290580, 290581, 290582, 290583, 290584, 290585, + // 299612, 290587, 290588 + // }; + //command.Ids = new List(){ 290449 }; if (!string.IsNullOrWhiteSpace(command.year) && string.IsNullOrWhiteSpace(command.Month)) - return BadRequest(); + return op.Failed("ماه را انتخاب کنید"); if (string.IsNullOrWhiteSpace(command.year) && !string.IsNullOrWhiteSpace(command.Month)) - return BadRequest(); + return op.Failed("سال را انتخاب کنید"); if (string.IsNullOrWhiteSpace(command.year) && string.IsNullOrWhiteSpace(command.Month)) { @@ -188,32 +180,26 @@ public class CheckoutController : AdminBaseController command.Month = convertedMonth; } - if (ids.Count == 0 || command.WorkshopId == 0) - return BadRequest(); + if (command.WorkshopId == 0) + return op.Failed("کارگاه انتخاب نشده است"); + if (command.Ids.Count == 0) + return op.Failed("هیچ موردی انتخاب نشده است"); - var test = await _checkoutApplication.CreateCheckoutApi(ids, command.year, command.Month, command.WorkshopId); - return Ok(); + + var result = await _checkoutApplication.CreateCheckoutApi(command.Ids, command.year, command.Month, command.WorkshopId); + return result; } #endregion } -public class TestCreateCheckout +public class CreateCheckoutDto { + public List Ids { get; set; } public string year { get; set; } public string Month { get; set; } public long WorkshopId { get; set; } } -public class Testresponse -{ - public string EmployeeName { get; set; } - public string ContractNo { get; set; } - public string Start { get; set; } - public string End { get; set; } - public bool HasLeft { get; set; } - - public string LeftDate { get; set; } -} \ No newline at end of file