From 5a1ec104a1cbf50d3de2a353f533624f5e83ffaf Mon Sep 17 00:00:00 2001 From: mahan Date: Tue, 20 Jan 2026 19:44:40 +0330 Subject: [PATCH] add salary aid and loan for checkout print --- .../Checkout/Dto/CheckoutPrintDto.cs | 6 +- .../Checkout/ICheckoutApplication.cs | 12 + .../CheckoutDailyRollCallViewModel.cs | 38 + .../Repository/CheckoutRepository.cs | 1021 +++++++++-------- 4 files changed, 613 insertions(+), 464 deletions(-) diff --git a/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutPrintDto.cs b/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutPrintDto.cs index 201d2679..60b72897 100644 --- a/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutPrintDto.cs +++ b/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutPrintDto.cs @@ -116,7 +116,7 @@ public class CheckoutPrintDto /// /// لیست حضورغیاب /// - public List MonthlyRollCall { get; set; } + public List MonthlyRollCall { get; set; } /// /// دیتای جدول حضورغیاب @@ -128,8 +128,8 @@ public class CheckoutPrintDto //اقساط - مساعده #region SalaryAidAndInstallmentData - public List InstallmentViewModels { get; set; } - public List SalaryAidViewModels { get; set; } + public List Installments { get; set; } + public List SalaryAids { get; set; } #endregion } diff --git a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs index a3e75d18..abbc3238 100644 --- a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs +++ b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs @@ -89,4 +89,16 @@ public interface ICheckoutApplication /// Task> CheckoutPrint(List ids); #endregion +} + +public class CheckoutPrintInstallmentDto +{ + public string RemainingAmount { get; set; } + public string LoanAmount { get; set; } + public string Amount { get; set; } +} +public class CheckoutPrintSalaryAidDto +{ + public string Amount { get; set; } + public string SalaryAidDateTimeFa { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/RollCall/CheckoutDailyRollCallViewModel.cs b/CompanyManagment.App.Contracts/RollCall/CheckoutDailyRollCallViewModel.cs index 9c938ee9..94b2e283 100644 --- a/CompanyManagment.App.Contracts/RollCall/CheckoutDailyRollCallViewModel.cs +++ b/CompanyManagment.App.Contracts/RollCall/CheckoutDailyRollCallViewModel.cs @@ -45,4 +45,42 @@ namespace CompanyManagment.App.Contracts.RollCall } #endregion + public class CheckoutPrintRollCallDto + { + + public string RollCallDateFa { get; set; } + public string StartDate1 { get; set; } + public string EndDate1 { get; set; } + + public string StartDate2 { get; set; } + public string EndDate2 { get; set; } + + //منقطع بودن شیفت کاری + public bool IsSliced { get; set; } + + public string TotalWorkingHours { get; set; } + + public string DayOfWeek { get; set; } + + public string BreakTimeString { get; set; } + + /// + /// اگر مرخصی نداشته باشد خالی خواهد بود، اگر داشته باشد نوع مرخصی جانشانی می شود + /// + public string LeaveType { get; set; } + + public bool IsAbsent { get; set; } + public bool IsFriday { get; set; } + public bool IsHoliday { get; set; } + public bool IsBirthDay { get; set; } + + + public string EnterDifferencesMinutes1 { get; set; } + public string ExitDifferencesMinutes1 { get; set; } + + public string EnterDifferencesMinutes2 { get; set; } + public string ExitDifferencesMinutes2 { get; set; } + + } + } diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 51f6b8c7..cfd2078e 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -54,9 +54,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos private readonly IRollCallMandatoryRepository _rollCallMandatoryRepository; private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; - public CheckoutRepository(IAuthHelper authHelper, CompanyContext context, IConfiguration configuration, ILeftWorkRepository leftWorkRepository, IWorkingHoursTempApplication workingHoursTempApplication, IRollCallRepository rollCallRepository, IRollCallMandatoryRepository rollCallMandatoryRepository, IRollCallEmployeeRepository rollCallEmployeeRepository) : base(context) + public CheckoutRepository(IAuthHelper authHelper, CompanyContext context, IConfiguration configuration, + ILeftWorkRepository leftWorkRepository, IWorkingHoursTempApplication workingHoursTempApplication, + IRollCallRepository rollCallRepository, IRollCallMandatoryRepository rollCallMandatoryRepository, + IRollCallEmployeeRepository rollCallEmployeeRepository) : base(context) { - _authHelper = authHelper; _context = context; _configuration = configuration; @@ -75,7 +77,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos /// /// /// - public (bool hasChekout, double FamilyAlloance, double OverTimePay, double RotatingShift, double Nightwork, double Fridaywork, double YraesPay) HasCheckout(long workshopId, long employeId, string year, string month) + public (bool hasChekout, double FamilyAlloance, double OverTimePay, double RotatingShift, double Nightwork, double + Fridaywork, double YraesPay) HasCheckout(long workshopId, long employeId, string year, string month) { var farisMonthName = Tools.ToFarsiMonthByNumber(month); @@ -94,54 +97,54 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } - return (true, res.FamilyAllowance, res.OvertimePay, res.ShiftPay, res.NightworkPay, res.FridayPay, res.YearsPay); + return (true, res.FamilyAllowance, res.OvertimePay, res.ShiftPay, res.NightworkPay, res.FridayPay, + res.YearsPay); } public EditCheckout GetDetails(long id) { return _context.CheckoutSet.Select(x => new EditCheckout() - { - Id = x.id, - EmployeeFullName = x.EmployeeFullName, - FathersName = x.FathersName, - NationalCode = x.NationalCode, - DateOfBirth = x.DateOfBirth, - WorkshopName = x.WorkshopName, - Month = x.Month, - Year = x.Year, - ContractNo = x.ContractNo, - MonthlySalary = x.MonthlySalary, - BaseYearsPay = x.BaseYearsPay, - ConsumableItems = x.ConsumableItems.ToMoney(), - HousingAllowance = x.HousingAllowance.ToMoney(), - OvertimePay = x.OvertimePay, - NightworkPay = x.NightworkPay, - FridayPay = x.FridayPay, - MissionPay = x.MissionPay, - ShiftPay = x.ShiftPay, - FamilyAllowance = x.FamilyAllowance.ToMoney(), - BonusesPay = x.BonusesPay, - YearsPay = x.YearsPay, - LeavePay = x.LeavePay, - InsuranceDeduction = x.InsuranceDeduction, - TaxDeducation = x.TaxDeducation, - InstallmentDeduction = x.InstallmentDeduction, - SalaryAidDeduction = x.SalaryAidDeduction, - AbsenceDeduction = x.AbsenceDeduction, - TotalClaims = x.TotalClaims, - TotalDeductions = x.TotalDeductions, - TotalPayment = x.TotalPayment, - RewardPay = x.RewardPay, - HasRollCall = x.HasRollCall, - EmployeeId = x.EmployeeId, - WorkshopId = x.WorkshopId, - ContractId = x.ContractId, - ContractStartGr = x.ContractStart, - ContractEndGr = x.ContractEnd, - ContractStart = x.ContractStart.ToFarsi(), - ContractEnd = x.ContractEnd.ToFarsi() - - }) + { + Id = x.id, + EmployeeFullName = x.EmployeeFullName, + FathersName = x.FathersName, + NationalCode = x.NationalCode, + DateOfBirth = x.DateOfBirth, + WorkshopName = x.WorkshopName, + Month = x.Month, + Year = x.Year, + ContractNo = x.ContractNo, + MonthlySalary = x.MonthlySalary, + BaseYearsPay = x.BaseYearsPay, + ConsumableItems = x.ConsumableItems.ToMoney(), + HousingAllowance = x.HousingAllowance.ToMoney(), + OvertimePay = x.OvertimePay, + NightworkPay = x.NightworkPay, + FridayPay = x.FridayPay, + MissionPay = x.MissionPay, + ShiftPay = x.ShiftPay, + FamilyAllowance = x.FamilyAllowance.ToMoney(), + BonusesPay = x.BonusesPay, + YearsPay = x.YearsPay, + LeavePay = x.LeavePay, + InsuranceDeduction = x.InsuranceDeduction, + TaxDeducation = x.TaxDeducation, + InstallmentDeduction = x.InstallmentDeduction, + SalaryAidDeduction = x.SalaryAidDeduction, + AbsenceDeduction = x.AbsenceDeduction, + TotalClaims = x.TotalClaims, + TotalDeductions = x.TotalDeductions, + TotalPayment = x.TotalPayment, + RewardPay = x.RewardPay, + HasRollCall = x.HasRollCall, + EmployeeId = x.EmployeeId, + WorkshopId = x.WorkshopId, + ContractId = x.ContractId, + ContractStartGr = x.ContractStart, + ContractEndGr = x.ContractEnd, + ContractStart = x.ContractStart.ToFarsi(), + ContractEnd = x.ContractEnd.ToFarsi() + }) .FirstOrDefault(x => x.Id == id); } @@ -156,7 +159,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos /// /// /// - public async Task GetContractResultToCreateCheckout(long workshopId, long employeeId, string year, string month, string contractStart, + public async Task GetContractResultToCreateCheckout(long workshopId, long employeeId, + string year, string month, string contractStart, string contractEnd) { DateTime startSreach; @@ -169,7 +173,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } else { - if (month == "0" && year == "0") { DateTime now = DateTime.Now; @@ -199,8 +202,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos startSreach = startStr.ToGeorgianDateTime(); endSearch = (startStr.FindeEndOfMonth()).ToGeorgianDateTime(); } - } + var timer = new Stopwatch(); timer.Start(); @@ -215,7 +218,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos contractWorkshop => contractWorkshop.contract.EmployeeId, employee => employee.id, (contractWorkshop, employee) => new { contractWorkshop, employee }) - .Join(_context.LeftWorkList.AsSplitQuery().Where(l => l.WorkshopId == workshopId && l.StartWorkDate < endSearch && l.LeftWorkDate > startSreach), + .Join( + _context.LeftWorkList.AsSplitQuery().Where(l => + l.WorkshopId == workshopId && l.StartWorkDate < endSearch && l.LeftWorkDate > startSreach), contractWorkshopEmployee => contractWorkshopEmployee.contractWorkshop.contract.EmployeeId, leftwork => leftwork.EmployeeId, (contractWorkshopEmployee, leftwork) => new { contractWorkshopEmployee, leftwork }) @@ -225,16 +230,15 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos personnelCode => personnelCode.EmployeeId, (contractWorkshopEmployeeleftWork, personnelCode) => new { contractWorkshopEmployeeleftWork, personnelCode }) - .GroupJoin(_context.CheckoutSet.AsSplitQuery(), contractWorkshopEmployeeleftWorkPersonnelCode => contractWorkshopEmployeeleftWorkPersonnelCode .contractWorkshopEmployeeleftWork.contractWorkshopEmployee.contractWorkshop.contract.id, checkout => checkout.ContractId, (contractWorkshopEmployeeleftWorkPersonnelCode, checkout) => new { contractWorkshopEmployeeleftWorkPersonnelCode, checkout }) - .GroupJoin(_context.EmployeeComputeOptionsSet.Where(o => o.WorkshopId == workshopId), - x => x.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork.leftwork.EmployeeId, + x => x.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork.leftwork + .EmployeeId, option => option.EmployeeId, (x, options) => new { x.checkout, x.contractWorkshopEmployeeleftWorkPersonnelCode, options }) .SelectMany( @@ -254,11 +258,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos DateTime currentStart = ($"{DateTime.Now.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime(); DateTime currentEnd = ($"{DateTime.Now.ToFarsi().FindeEndOfMonth()}").ToGeorgianDateTime(); - var chekoutCreated = result.checkout.FirstOrDefault(x => x.ContractStart < endSearch && x.ContractEnd > startSreach && x.IsActiveString == "true"); + var chekoutCreated = result.checkout.FirstOrDefault(x => + x.ContractStart < endSearch && x.ContractEnd > startSreach && x.IsActiveString == "true"); if (chekoutCreated != null) { - return new CreateCheckoutListViewModel { Id = chekoutCreated.ContractId, @@ -277,6 +281,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos EmployeeHasCreateCheckout = true }; } + var employeeJoin = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork .contractWorkshopEmployee.employee.id; @@ -287,11 +292,13 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var startStatusSearch = leftWork.StartWorkDate > startSreach && leftWork.StartWorkDate <= endSearch ? leftWork.StartWorkDate : startSreach; - var endStatusSearch = leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch + var endStatusSearch = leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && + leftWork.LeftWorkDate <= endSearch ? leftWork.LeftWorkDate.AddDays(-1) : startSreach; bool hasRollCall = - _rollCallEmployeeRepository.HasRollCallRecord(employeeJoin, workshopId, startStatusSearch, endStatusSearch); + _rollCallEmployeeRepository.HasRollCallRecord(employeeJoin, workshopId, startStatusSearch, + endStatusSearch); bool extension = true; bool laterThanEnd = false; @@ -304,11 +311,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos .contractWorkshopEmployee.contractWorkshop.contract.ContarctStart; var contractEndGr = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork .contractWorkshopEmployee.contractWorkshop.contract.ContractEnd; + #region HasRollCall if (hasRollCall) { - // اگر ترک کار کرده بود // اگر ترک کارش در بازه انتخاب شده بود if (leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch) @@ -326,7 +333,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ? leftWork.StartWorkDate.ToFarsi() : startSreach.ToFarsi(); contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi(); - } else { @@ -338,7 +344,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ? leftWork.StartWorkDate.ToFarsi() : startSreach.ToFarsi(); contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi(); - } } else if (endSearch < currentStart) @@ -361,7 +366,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos : startSreach.ToFarsi(); contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi(); } - } else if (leftWork.HasLeft && leftWork.LeftWorkDate <= startSreach) { @@ -369,7 +373,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos extension = false; description = "به دلیل ترک کار پیش از تاریخ انتخاب شده مجاز به ایجاد فیش نمی باشید"; leftWorkDate = leftWork.LeftWorkDate.ToFarsi(); - } else if (!leftWork.HasLeft && startSreach == currentStart) { @@ -380,13 +383,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ? leftWork.StartWorkDate.ToFarsi() : startSreach.ToFarsi(); contractEnd = endSearch.ToFarsi(); - } else if (!leftWork.HasLeft && startSreach < currentStart) { - - - if (contractStartGr <= startSreach && contractStartGr > endSearch) { laterThanEnd = true; @@ -401,12 +400,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos contractStart = leftWork.StartWorkDate > startSreach ? leftWork.StartWorkDate.ToFarsi() : startSreach.ToFarsi(); - contractEnd = (leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch) ? leftWork.LeftWorkDate.AddDays(-1).ToFarsi() : endSearch.ToFarsi(); - + contractEnd = (leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch) + ? leftWork.LeftWorkDate.AddDays(-1).ToFarsi() + : endSearch.ToFarsi(); } - } - } #endregion @@ -472,13 +470,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos contractEnd = endSearch.ToFarsi(); } } - } #endregion - return new CreateCheckoutListViewModel { Id = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork @@ -502,15 +498,14 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ContractStart = contractStart, ContractEnd = contractEnd, LeftWorkDate = leftWorkDate, - EmployeeHasCreateCheckout = result.option != null ? result.option.CreateCheckout : result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork.contractWorkshopEmployee.contractWorkshop.workshop.CreateCheckout - + EmployeeHasCreateCheckout = result.option != null + ? result.option.CreateCheckout + : result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork + .contractWorkshopEmployee.contractWorkshop.workshop.CreateCheckout }; - }).Where(x => x.EmployeeHasCreateCheckout).OrderByDescending(x => x.Extension).ToList(); - - Console.WriteLine("process : " + timer.Elapsed); return new CreateCheckoutListViewModel() @@ -521,14 +516,13 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos public async Task CreateCkeckout(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())// این قسمت مهمه! + .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(); var entity = await _context.CheckoutSet.FirstOrDefaultAsync(x => x.id == result); @@ -540,7 +534,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos if (command.HasInsuranceShareTheSameAsList) entity.SetInsuranceShare(); await _context.SaveChangesAsync(); - } @@ -682,9 +675,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos query = query.Where(x => x.ContractStartGr >= startyearGr && x.ContractEndGr <= endYearGr).ToList(); if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) return query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt).ToList(); - - - } else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) && string.IsNullOrWhiteSpace(searchModel.ContractStart) && @@ -803,7 +793,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos endDate >= x.ContractEndGr && startDate < x.ContractEndGr).ToList(); if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) return query.OrderBy(x => x.PersonnelCodeInt).ToList(); - } else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) && !string.IsNullOrWhiteSpace(searchModel.ContractEnd) && @@ -817,17 +806,12 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) return query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt).ToList(); - } return query.OrderByDescending(x => x.Id) .ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).Take(100).ToList(); - - - - //foreach(var items in query) //{ // var employeId = _context.WorkshopEmployers?.Where(x => x.WorkshopId == items.WorkshopId) @@ -869,7 +853,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ContractNo = x.ContractNo, ContractId = x.ContractId, HasRollCall = x.HasRollCall - }); if (searchModel.EmployeeId != 0 && searchModel.WorkshopId != 0) @@ -888,11 +871,12 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { var start = searchModel.ContractStart.ToGeorgianDateTime(); var end = searchModel.ContractEnd.ToGeorgianDateTime(); - query = query.Where(x => x.ContractStartGr == start && x.ContractEndGr == end && x.EmployeeId == searchModel.EmployeeId && x.WorkshopId == searchModel.WorkshopId); + query = query.Where(x => + x.ContractStartGr == start && x.ContractEndGr == end && x.EmployeeId == searchModel.EmployeeId && + x.WorkshopId == searchModel.WorkshopId); } return query.OrderBy(x => x.ContractStartGr).ToList(); - } public List PrintAll(List id) @@ -971,38 +955,41 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos Amount = s.Amount, AmountDouble = s.Amount.MoneyToDouble(), SalaryAidDateTimeFa = s.SalaryAidDateTimeFa, - SalaryAidDateTimeGe = s.SalaryAidDateTime + SalaryAidDateTimeGe = s.SalaryAidDateTime, }).ToList(), - CheckoutRollCall = item.CheckoutRollCall != null ? new CheckoutRollCallViewModel() - { - TotalPresentTimeSpan = item.CheckoutRollCall.TotalPresentTimeSpan, - TotalBreakTimeSpan = item.CheckoutRollCall.TotalBreakTimeSpan, - TotalWorkingTimeSpan = item.CheckoutRollCall.TotalWorkingTimeSpan, - TotalPaidLeaveTmeSpan = item.CheckoutRollCall.TotalPaidLeaveTmeSpan, - TotalMandatoryTimeSpan = item.CheckoutRollCall.TotalMandatoryTimeSpan, - TotalSickLeaveTimeSpan = item.CheckoutRollCall.TotalSickLeaveTimeSpan, - RollCallDaysCollection = item.CheckoutRollCall.RollCallDaysCollection.Select(d => new CheckoutRollCallDayViewModel() + CheckoutRollCall = item.CheckoutRollCall != null + ? new CheckoutRollCallViewModel() { - WorkingTimeSpan = d.WorkingTimeSpan, - BreakTimeSpan = d.BreakTimeSpan, - IsSliced = d.IsSliced, - IsAbsent = d.IsAbsent, - IsFriday = d.IsFriday, - IsHoliday = d.IsHoliday, - LeaveType = d.LeaveType, - CheckoutId = d.CheckoutId, - Date = d.Date, - FirstEndDate = d.FirstEndDate, - FirstStartDate = d.FirstStartDate, - Id = d.Id, - SecondEndDate = d.SecondEndDate, - SecondStartDate = d.SecondStartDate, - }).ToList(), - - } : null, + TotalPresentTimeSpan = item.CheckoutRollCall.TotalPresentTimeSpan, + TotalBreakTimeSpan = item.CheckoutRollCall.TotalBreakTimeSpan, + TotalWorkingTimeSpan = item.CheckoutRollCall.TotalWorkingTimeSpan, + TotalPaidLeaveTmeSpan = item.CheckoutRollCall.TotalPaidLeaveTmeSpan, + TotalMandatoryTimeSpan = item.CheckoutRollCall.TotalMandatoryTimeSpan, + TotalSickLeaveTimeSpan = item.CheckoutRollCall.TotalSickLeaveTimeSpan, + RollCallDaysCollection = item.CheckoutRollCall.RollCallDaysCollection.Select(d => + new CheckoutRollCallDayViewModel() + { + WorkingTimeSpan = d.WorkingTimeSpan, + BreakTimeSpan = d.BreakTimeSpan, + IsSliced = d.IsSliced, + IsAbsent = d.IsAbsent, + IsFriday = d.IsFriday, + IsHoliday = d.IsHoliday, + LeaveType = d.LeaveType, + CheckoutId = d.CheckoutId, + Date = d.Date, + FirstEndDate = d.FirstEndDate, + FirstStartDate = d.FirstStartDate, + Id = d.Id, + SecondEndDate = d.SecondEndDate, + SecondStartDate = d.SecondStartDate, + }).ToList(), + } + : null, HasAmountConflict = item.HasAmountConflict, EmployeeMandatoryHoursTimeSpan = item.EmployeeMandatoryHours, - EmployeeMandatoryHoursStr = Tools.ToFarsiHoursAndMinutes(Convert.ToInt32(item.EmployeeMandatoryHours.TotalHours), item.EmployeeMandatoryHours.Minutes, "-") + EmployeeMandatoryHoursStr = Tools.ToFarsiHoursAndMinutes( + Convert.ToInt32(item.EmployeeMandatoryHours.TotalHours), item.EmployeeMandatoryHours.Minutes, "-") }; var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId); ch.WorkshopName = workshopName.WorkshopName; @@ -1126,9 +1113,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var totalPaidLeaveTimeSpans = hourlyPaidLeaveTimeSpans.Concat(dailyPaidLeaveTimeSpans); ch.TotalHourlyLeave = new TimeSpan(hourlyPaidLeaveTimeSpans.Sum(x => x.Ticks)); - ch.TotalPaidLeave = new TimeSpan(totalPaidLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-"); - - + ch.TotalPaidLeave = + new TimeSpan(totalPaidLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-"); #endregion @@ -1146,7 +1132,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ch.TotalBreakTimeStr = ch.CheckoutRollCall.TotalBreakTimeSpan.ToFarsiHoursAndMinutes("-"); ch.TotalPresentTimeStr = ch.CheckoutRollCall.TotalPresentTimeSpan.ToFarsiHoursAndMinutes("-"); ch.TotalMandatoryTimeStr = ch.CheckoutRollCall.TotalMandatoryTimeSpan.ToFarsiHoursAndMinutes("-"); - ch.TotalPaidLeave = Tools.ToFarsiHoursAndMinutes(Convert.ToInt32(ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.TotalHours), ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.Minutes, "-"); + ch.TotalPaidLeave = Tools.ToFarsiHoursAndMinutes( + Convert.ToInt32(ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.TotalHours), + ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.Minutes, "-"); ch.MonthlyRollCall = ch.CheckoutRollCall.RollCallDaysCollection .Select(x => new CheckoutDailyRollCallViewModel { @@ -1167,13 +1155,12 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos BreakTimeString = $"{(int)(x.BreakTimeSpan.TotalHours)}:{x.BreakTimeSpan.Minutes:00}", RollCallDateFa = x.Date.ToFarsi() }).ToList(); - } else { - if (ch.HasRollCall) - ch.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(ch.EmployeeId, ch.WorkshopId, ch.ContractStartGr, ch.ContractEndGr); + ch.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(ch.EmployeeId, ch.WorkshopId, + ch.ContractStartGr, ch.ContractEndGr); else { ch.CreateWorkingHoursTemp.ContractStartGr = ch.ContractStartGr; @@ -1182,9 +1169,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ch.CreateWorkingHoursTemp.ContractEnd = ch.ContractEndGr.ToFarsi(); ch.CreateWorkingHoursTemp.EmployeeId = ch.EmployeeId; ch.CreateWorkingHoursTemp.WorkshopId = ch.WorkshopId; - ch.MonthlyRollCall = ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking); + ch.MonthlyRollCall = + ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking); } } + query.Add(ch); } @@ -1195,6 +1184,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos printNumer += 1; rec.PrintCounter = printNumer; } + return query; } @@ -1220,7 +1210,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos Id = x.id, EmployerFullName = x.FName + " " + x.LName, IsLegal = x.IsLegal, - }).Where(x => emp.Contains(x.Id)).ToList(); if (employerlist.Count > 0) { @@ -1249,7 +1238,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos //} - var leaveList = _context.LeaveList.Where(x => x.WorkshopId == ch.WorkshopId && x.EmployeeId == ch.EmployeeId && x.LeaveType == "استحقاقی"); + var leaveList = _context.LeaveList.Where(x => + x.WorkshopId == ch.WorkshopId && x.EmployeeId == ch.EmployeeId && x.LeaveType == "استحقاقی"); var leaveViewModel = new List(); foreach (var list in leaveList) @@ -1374,7 +1364,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos SalaryAidDateTimeFa = s.SalaryAidDateTimeFa, SalaryAidDateTimeGe = s.SalaryAidDateTime }).ToList(), - }).SingleOrDefault(x => x.Id == id); var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId); @@ -1394,6 +1383,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos }; employers.Add(employer); } + ch.MaritalStatus = _context.Employees.Find(ch.EmployeeId)?.MaritalStatus; ch.EmployerList = employers; var workingHours = _workingHoursTempApplication.GetByContractIdConvertToShiftwork4(ch.ContractId); @@ -1488,7 +1478,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ch.TotalSickLeave = new TimeSpan(sickLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-"); - var hourlyPaidLeaveTimeSpans = hourlyPaidLeave.Select(x => TimeOnly.Parse(x.LeaveHourses).ToTimeSpan()).ToList(); + var hourlyPaidLeaveTimeSpans = + hourlyPaidLeave.Select(x => TimeOnly.Parse(x.LeaveHourses).ToTimeSpan()).ToList(); var dailyPaidLeaveTimeSpans = dailyPaidLeave.Select(x => { @@ -1501,20 +1492,19 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ch.TotalHourlyLeave = new TimeSpan(hourlyPaidLeaveTimeSpans.Sum(x => x.Ticks)); ch.TotalPaidLeave = new TimeSpan(totalPaidLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-"); - - #endregion - if (ch.TotalPaymentHide == false) { ch.TotalClaims = ""; ch.TotalDeductions = ""; ch.TotalPayment = ""; } + if (ch.HasRollCall) - ch.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(ch.EmployeeId, ch.WorkshopId, ch.ContractStartGr, ch.ContractEndGr); + ch.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(ch.EmployeeId, ch.WorkshopId, + ch.ContractStartGr, ch.ContractEndGr); else { ch.CreateWorkingHoursTemp.ContractStartGr = ch.ContractStartGr; @@ -1523,15 +1513,18 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ch.CreateWorkingHoursTemp.ContractEnd = ch.ContractEndGr.ToFarsi(); ch.CreateWorkingHoursTemp.EmployeeId = ch.EmployeeId; ch.CreateWorkingHoursTemp.WorkshopId = ch.WorkshopId; - ch.MonthlyRollCall = ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking); + ch.MonthlyRollCall = + ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking); } + return ch; } - private List ConvertStaticToRollCall(CreateWorkingHoursTemp workingHours, bool workshopHolidayWorking) + private List ConvertStaticToRollCall(CreateWorkingHoursTemp workingHours, + bool workshopHolidayWorking) { var rollCalls = _rollCallMandatoryRepository.ConvertStaticHoursToRollCall(workingHours, - workshopHolidayWorking); + workshopHolidayWorking); var workshopId = workingHours.WorkshopId; var employeeId = workingHours.EmployeeId; var year = Convert.ToInt32(workingHours.ContarctStart.Substring(0, 4)); @@ -1540,8 +1533,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var endMonthDay = workingHours.ContractEndGr; var leaves = _context.LeaveList.Where(x => - x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.EndLeave.Date >= startMonthDay.Date && - x.StartLeave.Date <= endMonthDay.Date).ToList(); + x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.EndLeave.Date >= startMonthDay.Date && + x.StartLeave.Date <= endMonthDay.Date).ToList(); var firstDayOfCurrentMonth = new DateTime(year, month, 1, new PersianCalendar()); @@ -1561,50 +1554,54 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos int dateRange = (int)(lastDayOfCurrentMonth - firstDayOfCurrentMonth).TotalDays + 1; - var holidays = _context.HolidayItems.Where(x => x.HolidayYear.Contains(year.ToString())).Select(x => new HolidayItemViewModel - { - Id = x.id, - Holidaydate = x.Holidaydate.ToFarsi(), - HolidayId = x.HolidayId, - HolidayYear = x.HolidayYear, - HolidaydateGr = x.Holidaydate - }).ToList(); + var holidays = _context.HolidayItems.Where(x => x.HolidayYear.Contains(year.ToString())).Select(x => + new HolidayItemViewModel + { + Id = x.id, + Holidaydate = x.Holidaydate.ToFarsi(), + HolidayId = x.HolidayId, + HolidayYear = x.HolidayYear, + HolidaydateGr = x.Holidaydate + }).ToList(); if (workshopHolidayWorking) holidays = []; //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 => startMonthDay.AddDays(offset).Date).ToList(); + var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => startMonthDay.AddDays(offset).Date) + .ToList(); var absentRecords = completeDaysList - .ExceptBy(rollCalls.Select(x => x.ShiftDate.Date), y => y.Date) - .Select(x => - { - var leave = leaves.FirstOrDefault(y => - y.EmployeeId == employeeId && y.EndLeave.Date >= x.Date && y.StartLeave.Date <= x.Date); - var isHoliday = false; - var isFriday = x.Date.DayOfWeek == DayOfWeek.Friday; - var isNormalWorkingDay = isHoliday == false && isFriday == false; - return new CheckoutDailyRollCallViewModel() + .ExceptBy(rollCalls.Select(x => x.ShiftDate.Date), y => y.Date) + .Select(x => { - StartDate1 = null, - EndDate1 = null, - DateTimeGr = x.Date, - DayOfWeek = x.Date.DayOfWeek.DayOfWeeKToPersian(), - RollCallDateFa = x.Date.ToFarsi(), - LeaveType = leave != null ? leave.LeaveType : "", - IsAbsent = leave == null && isNormalWorkingDay - }; - }); + var leave = leaves.FirstOrDefault(y => + y.EmployeeId == employeeId && y.EndLeave.Date >= x.Date && y.StartLeave.Date <= x.Date); + var isHoliday = false; + 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.DayOfWeeKToPersian(), + RollCallDateFa = x.Date.ToFarsi(), + LeaveType = leave != null ? leave.LeaveType : "", + IsAbsent = leave == null && isNormalWorkingDay + }; + }); var presentDays = rollCalls.GroupBy(x => x.ShiftDate.Date).Select(x => { - var orderedRollcalls = x.OrderBy(y => y.ShiftDate).ToList(); var rollCallTimeSpanPerDay = - new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => y.ShiftEndWithoutRest == null ? (y.EndDate - y.StartDate).Value!.Ticks : (y.ShiftEndWithoutRest - y.StartDate)!.Value.Ticks)); + new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => + y.ShiftEndWithoutRest == null + ? (y.EndDate - y.StartDate).Value!.Ticks + : (y.ShiftEndWithoutRest - y.StartDate)!.Value.Ticks)); var breakTimePerDay = new TimeSpan(x.Sum(r => r.BreakTimeSpan.Ticks)); var firstRollCall = orderedRollcalls.FirstOrDefault(); @@ -1618,7 +1615,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos secondRCEndDate = secondRollCall.ShiftEndWithoutRest ?? secondRollCall.EndDate; - return new CheckoutDailyRollCallViewModel() { StartDate1 = firstRollCall?.StartDate?.ToString("HH:mm") ?? "", @@ -1690,12 +1686,15 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { return new List(); } + var employers = - _context.Employers.Where(x => x.ContractingPartyId == contracingPartyAcc.PersonalContractingPartyId).Select(x => x.id).ToList(); + _context.Employers.Where(x => x.ContractingPartyId == contracingPartyAcc.PersonalContractingPartyId) + .Select(x => x.id).ToList(); if (employers.Count < 1) { return new List(); } + var workshopIds = _context.WorkshopEmployers.Where(x => employers.Contains(x.EmployerId)) .Select(x => x.WorkshopId).ToList(); var checkValid = workshopIds.Any(x => x == searchModel.WorkshopId); @@ -1703,7 +1702,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { return new List(); } + #endregion + var query = _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList) .AsSplitQuery().Select(x => new CheckoutViewModel() { @@ -1745,9 +1746,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { WarningMessage = wm.WarningMessage, TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, - }).ToList() - }).Where(x => x.WorkshopId == searchModel.WorkshopId); if (searchModel.EmployeeId > 0) { @@ -1756,7 +1755,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) && - !string.IsNullOrWhiteSpace(searchModel.ContractEnd)) + !string.IsNullOrWhiteSpace(searchModel.ContractEnd)) { var start = searchModel.ContractStart.ToGeorgianDateTime(); var endd = searchModel.ContractEnd.ToGeorgianDateTime(); @@ -1861,16 +1860,20 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos default: y2 = $"{searchModel.Year}/{searchModel.Month}/29"; break; - } } var start = y.ToGeorgianDateTime(); var end = y2.ToGeorgianDateTime(); - query = query.Where(x => x.ContractStartGr >= start && x.ContractStartGr < end && x.ContractEndGr > start && x.ContractEndGr <= end || - x.ContractStartGr <= start && x.ContractEndGr >= end || start <= x.ContractStartGr && end > x.ContractStartGr || end >= x.ContractEndGr && start < x.ContractEndGr); + query = query.Where(x => + x.ContractStartGr >= start && x.ContractStartGr < end && x.ContractEndGr > start && + x.ContractEndGr <= end || + x.ContractStartGr <= start && x.ContractEndGr >= end || + start <= x.ContractStartGr && end > x.ContractStartGr || + end >= x.ContractEndGr && start < x.ContractEndGr); } + if (searchModel.SearchAll) return query.OrderByDescending(x => x.Id).ToList(); switch (searchModel.Sorting) @@ -1901,8 +1904,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos break; default: return query.OrderByDescending(x => x.Id).Skip(searchModel.PageIndex).Take(30).ToList(); } - - } #endregion @@ -1932,12 +1933,10 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos try { - var checkout = _context.CheckoutSet.Where(x => x.id == id)?.FirstOrDefault(); _context.CheckoutSet.Remove(checkout); _context.SaveChanges(); return op.Succcedded(-1, "حذف با موفقیت انجام شد."); - } catch (Exception) { @@ -1955,6 +1954,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos notRemoveList.Add(item); } } + return notRemoveList; } @@ -2014,7 +2014,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos // ); var checkouts = - _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList).Where(x => workshopAcounts.Contains(x.WorkshopId)) + _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList) + .Where(x => workshopAcounts.Contains(x.WorkshopId)) .Join(_context.Workshops.AsSplitQuery(), ch => ch.WorkshopId, workshop => workshop.id, @@ -2037,7 +2038,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { res.ch, res.workshop, - option = _context.EmployeeComputeOptionsSet.FirstOrDefault(x => x.WorkshopId == res.ch.WorkshopId && x.EmployeeId == res.ch.EmployeeId), + option = _context.EmployeeComputeOptionsSet.FirstOrDefault(x => + x.WorkshopId == res.ch.WorkshopId && x.EmployeeId == res.ch.EmployeeId), res.workshopEmployer, contractingParty = _context.PersonalContractingParties .Include(p => p.Employers) @@ -2054,15 +2056,18 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos hasEmployeeOrWorkshpSearch = true; checkouts = checkouts.Where(x => x.ch.WorkshopId == searchModel.WorkshopId); } + if (searchModel.EmployeeId != 0) { hasEmployeeOrWorkshpSearch = true; checkouts = checkouts.Where(x => x.ch.EmployeeId == searchModel.EmployeeId); } + if (searchModel.EmployerId != 0) { hasEmployeeOrWorkshpSearch = true; - checkouts = checkouts.Where(x => x.contractingParty.Employers.Select(c => c.id).Contains(searchModel.EmployerId)); + checkouts = checkouts.Where(x => + x.contractingParty.Employers.Select(c => c.id).Contains(searchModel.EmployerId)); } if (!string.IsNullOrWhiteSpace(searchModel.ContractNo)) @@ -2072,7 +2077,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } - //if (searchModel.IsActiveString == null) //{ // checkouts = checkouts.Where(x => x.ch.IsActiveString == "true"); @@ -2104,7 +2108,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos checkouts = checkouts.Where(x => x.ch.ContractStart >= startyearGr && x.ch.ContractEnd <= endYearGr); if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) checkouts = checkouts.OrderByDescending(x => x.ch.ContractEnd); - } else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) && string.IsNullOrWhiteSpace(searchModel.ContractStart) && @@ -2224,7 +2227,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos endDate >= x.ch.ContractEnd && startDate < x.ch.ContractEnd); //if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) // checkouts = checkouts.OrderBy(x => x.ch.PersonnelCodeInt); - } else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) && !string.IsNullOrWhiteSpace(searchModel.ContractEnd) && @@ -2244,105 +2246,96 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos if (!string.IsNullOrEmpty(searchModel.EmployeeName)) { hasSearch = true; - var employeeList = _context.Employees.Where(x => (!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchModel.EmployeeName)) || - (!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchModel.EmployeeName))).Select(x => x.id).ToList(); + var employeeList = _context.Employees.Where(x => + (!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchModel.EmployeeName)) || + (!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchModel.EmployeeName))).Select(x => x.id) + .ToList(); checkouts = checkouts.Where(x => employeeList.Contains(x.ch.EmployeeId)); } - - #endregion if (!hasSearch && !hasEmployeeOrWorkshpSearch) { - return checkouts.Select(x => new CheckoutViewModel() - { - - Id = x.ch.id, - EmployeeFullName = x.ch.EmployeeFullName, - ContractStart = x.ch.ContractStart.ToFarsi(), - ContractEnd = x.ch.ContractEnd.ToFarsi(), - ContractStartGr = x.ch.ContractStart, - ContractEndGr = x.ch.ContractEnd, - PersonnelCode = x.ch.PersonnelCode, - PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), - ArchiveCode = x.workshop.ArchiveCode, - SumOfWorkingDays = x.ch.SumOfWorkingDays, - WorkshopName = x.workshop.WorkshopName, - Month = x.ch.Month, - Year = x.ch.Year, - ContractNo = x.ch.ContractNo, - ContractId = x.ch.ContractId, - WorkshopId = x.ch.WorkshopId, - EmployeeId = x.ch.EmployeeId, - EmployerId = x.workshopEmployer.EmployerId, - IsActiveString = x.ch.IsActiveString, - Signature = x.ch.Signature, - CreationDate = x.ch.CreationDate, - EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", - IsBlockCantracingParty = x.contractingParty.IsBlock, - HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, - IsUpdateNeeded = x.ch.IsUpdateNeeded, - CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel { - WarningMessage = wm.WarningMessage, - TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, - - }).ToList() - - - }).OrderByDescending(x => x.Id).Take(3000).ToList().DistinctBy(x => x.Id) + Id = x.ch.id, + EmployeeFullName = x.ch.EmployeeFullName, + ContractStart = x.ch.ContractStart.ToFarsi(), + ContractEnd = x.ch.ContractEnd.ToFarsi(), + ContractStartGr = x.ch.ContractStart, + ContractEndGr = x.ch.ContractEnd, + PersonnelCode = x.ch.PersonnelCode, + PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), + ArchiveCode = x.workshop.ArchiveCode, + SumOfWorkingDays = x.ch.SumOfWorkingDays, + WorkshopName = x.workshop.WorkshopName, + Month = x.ch.Month, + Year = x.ch.Year, + ContractNo = x.ch.ContractNo, + ContractId = x.ch.ContractId, + WorkshopId = x.ch.WorkshopId, + EmployeeId = x.ch.EmployeeId, + EmployerId = x.workshopEmployer.EmployerId, + IsActiveString = x.ch.IsActiveString, + Signature = x.ch.Signature, + CreationDate = x.ch.CreationDate, + EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", + IsBlockCantracingParty = x.contractingParty.IsBlock, + HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, + IsUpdateNeeded = x.ch.IsUpdateNeeded, + CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => + new CheckoutWarningMessageModel + { + WarningMessage = wm.WarningMessage, + TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, + }).ToList() + }).OrderByDescending(x => x.Id).Take(3000).ToList().DistinctBy(x => x.Id) .OrderByDescending(x => x.Id).ThenByDescending(x => x.Year) .ThenBy(x => x.PersonnelCodeInt) .Take(50).ToList(); - } else if (hasSearch && !hasEmployeeOrWorkshpSearch) { - var result = checkouts.Select(x => new CheckoutViewModel() - { - - Id = x.ch.id, - EmployeeFullName = x.ch.EmployeeFullName, - ContractStart = x.ch.ContractStart.ToFarsi(), - ContractEnd = x.ch.ContractEnd.ToFarsi(), - ContractStartGr = x.ch.ContractStart, - ContractEndGr = x.ch.ContractEnd, - PersonnelCode = x.ch.PersonnelCode, - PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), - ArchiveCode = x.workshop.ArchiveCode, - SumOfWorkingDays = x.ch.SumOfWorkingDays, - WorkshopName = x.workshop.WorkshopName, - Month = x.ch.Month, - Year = x.ch.Year, - ContractNo = x.ch.ContractNo, - ContractId = x.ch.ContractId, - WorkshopId = x.ch.WorkshopId, - EmployeeId = x.ch.EmployeeId, - EmployerId = x.workshopEmployer.EmployerId, - IsActiveString = x.ch.IsActiveString, - Signature = x.ch.Signature, - CreationDate = x.ch.CreationDate, - EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", - IsBlockCantracingParty = x.contractingParty.IsBlock, - HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, - IsUpdateNeeded = x.ch.IsUpdateNeeded, - CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel { - WarningMessage = wm.WarningMessage, - TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, - - }).ToList() - - }).OrderByDescending(x => x.Id) - .GroupBy(x => x.Id) + Id = x.ch.id, + EmployeeFullName = x.ch.EmployeeFullName, + ContractStart = x.ch.ContractStart.ToFarsi(), + ContractEnd = x.ch.ContractEnd.ToFarsi(), + ContractStartGr = x.ch.ContractStart, + ContractEndGr = x.ch.ContractEnd, + PersonnelCode = x.ch.PersonnelCode, + PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), + ArchiveCode = x.workshop.ArchiveCode, + SumOfWorkingDays = x.ch.SumOfWorkingDays, + WorkshopName = x.workshop.WorkshopName, + Month = x.ch.Month, + Year = x.ch.Year, + ContractNo = x.ch.ContractNo, + ContractId = x.ch.ContractId, + WorkshopId = x.ch.WorkshopId, + EmployeeId = x.ch.EmployeeId, + EmployerId = x.workshopEmployer.EmployerId, + IsActiveString = x.ch.IsActiveString, + Signature = x.ch.Signature, + CreationDate = x.ch.CreationDate, + EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", + IsBlockCantracingParty = x.contractingParty.IsBlock, + HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, + IsUpdateNeeded = x.ch.IsUpdateNeeded, + CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => + new CheckoutWarningMessageModel + { + WarningMessage = wm.WarningMessage, + TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, + }).ToList() + }).OrderByDescending(x => x.Id) + .GroupBy(x => x.Id) .Select(x => x.First()); - if ((string.IsNullOrWhiteSpace(searchModel.ContractStart) || string.IsNullOrWhiteSpace(searchModel.ContractEnd)) && string.IsNullOrWhiteSpace(searchModel.Month)) { @@ -2352,7 +2345,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos .OrderByDescending(x => x.ContractStartGr).ToList(); } else if ((string.IsNullOrWhiteSpace(searchModel.ContractStart) || - string.IsNullOrWhiteSpace(searchModel.ContractEnd)) && !string.IsNullOrWhiteSpace(searchModel.Month) && !string.IsNullOrWhiteSpace(searchModel.Year)) + string.IsNullOrWhiteSpace(searchModel.ContractEnd)) && + !string.IsNullOrWhiteSpace(searchModel.Month) && !string.IsNullOrWhiteSpace(searchModel.Year)) { //اگر فقط سال و ماه رو سرچ کرد return result.Take(300) @@ -2360,7 +2354,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos .OrderByDescending(x => x.ContractStartGr).ToList(); } else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) && - !string.IsNullOrWhiteSpace(searchModel.ContractEnd)) + !string.IsNullOrWhiteSpace(searchModel.ContractEnd)) { //اگر فقط سال و ماه رو سرچ کرد return result.Take(300) @@ -2370,99 +2364,89 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos return result.ToList().OrderByDescending(x => x.Id) .ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).ToList(); - } else if (hasEmployeeOrWorkshpSearch && !hasSearch) { - return checkouts.Select(x => new CheckoutViewModel() - { - - Id = x.ch.id, - EmployeeFullName = x.ch.EmployeeFullName, - ContractStart = x.ch.ContractStart.ToFarsi(), - ContractEnd = x.ch.ContractEnd.ToFarsi(), - ContractStartGr = x.ch.ContractStart, - ContractEndGr = x.ch.ContractEnd, - PersonnelCode = x.ch.PersonnelCode, - PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), - ArchiveCode = x.workshop.ArchiveCode, - SumOfWorkingDays = x.ch.SumOfWorkingDays, - WorkshopName = x.workshop.WorkshopName, - Month = x.ch.Month, - Year = x.ch.Year, - ContractNo = x.ch.ContractNo, - ContractId = x.ch.ContractId, - WorkshopId = x.ch.WorkshopId, - EmployeeId = x.ch.EmployeeId, - EmployerId = x.workshopEmployer.EmployerId, - IsActiveString = x.ch.IsActiveString, - Signature = x.ch.Signature, - CreationDate = x.ch.CreationDate, - EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", - IsBlockCantracingParty = x.contractingParty.IsBlock, - HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, - IsUpdateNeeded = x.ch.IsUpdateNeeded, - CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel { - WarningMessage = wm.WarningMessage, - TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, - - }).ToList() - - }).GroupBy(x => x.Id).Select(x => x.First()).ToList() + Id = x.ch.id, + EmployeeFullName = x.ch.EmployeeFullName, + ContractStart = x.ch.ContractStart.ToFarsi(), + ContractEnd = x.ch.ContractEnd.ToFarsi(), + ContractStartGr = x.ch.ContractStart, + ContractEndGr = x.ch.ContractEnd, + PersonnelCode = x.ch.PersonnelCode, + PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), + ArchiveCode = x.workshop.ArchiveCode, + SumOfWorkingDays = x.ch.SumOfWorkingDays, + WorkshopName = x.workshop.WorkshopName, + Month = x.ch.Month, + Year = x.ch.Year, + ContractNo = x.ch.ContractNo, + ContractId = x.ch.ContractId, + WorkshopId = x.ch.WorkshopId, + EmployeeId = x.ch.EmployeeId, + EmployerId = x.workshopEmployer.EmployerId, + IsActiveString = x.ch.IsActiveString, + Signature = x.ch.Signature, + CreationDate = x.ch.CreationDate, + EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", + IsBlockCantracingParty = x.contractingParty.IsBlock, + HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, + IsUpdateNeeded = x.ch.IsUpdateNeeded, + CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => + new CheckoutWarningMessageModel + { + WarningMessage = wm.WarningMessage, + TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, + }).ToList() + }).GroupBy(x => x.Id).Select(x => x.First()).ToList() .OrderByDescending(x => x.ContractStartGr).ToList(); } else { return checkouts.Select(x => new CheckoutViewModel() - { - - Id = x.ch.id, - EmployeeFullName = x.ch.EmployeeFullName, - ContractStart = x.ch.ContractStart.ToFarsi(), - ContractEnd = x.ch.ContractEnd.ToFarsi(), - ContractStartGr = x.ch.ContractStart, - ContractEndGr = x.ch.ContractEnd, - PersonnelCode = x.ch.PersonnelCode, - PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), - ArchiveCode = x.workshop.ArchiveCode, - SumOfWorkingDays = x.ch.SumOfWorkingDays, - WorkshopName = x.workshop.WorkshopName, - Month = x.ch.Month, - Year = x.ch.Year, - ContractNo = x.ch.ContractNo, - ContractId = x.ch.ContractId, - WorkshopId = x.ch.WorkshopId, - EmployeeId = x.ch.EmployeeId, - EmployerId = x.workshopEmployer.EmployerId, - IsActiveString = x.ch.IsActiveString, - Signature = x.ch.Signature, - CreationDate = x.ch.CreationDate, - EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", - IsBlockCantracingParty = x.contractingParty.IsBlock, - HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, - IsUpdateNeeded = x.ch.IsUpdateNeeded, - CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel { - WarningMessage = wm.WarningMessage, - TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, - - }).ToList() - - }).GroupBy(x => x.Id) + Id = x.ch.id, + EmployeeFullName = x.ch.EmployeeFullName, + ContractStart = x.ch.ContractStart.ToFarsi(), + ContractEnd = x.ch.ContractEnd.ToFarsi(), + ContractStartGr = x.ch.ContractStart, + ContractEndGr = x.ch.ContractEnd, + PersonnelCode = x.ch.PersonnelCode, + PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), + ArchiveCode = x.workshop.ArchiveCode, + SumOfWorkingDays = x.ch.SumOfWorkingDays, + WorkshopName = x.workshop.WorkshopName, + Month = x.ch.Month, + Year = x.ch.Year, + ContractNo = x.ch.ContractNo, + ContractId = x.ch.ContractId, + WorkshopId = x.ch.WorkshopId, + EmployeeId = x.ch.EmployeeId, + EmployerId = x.workshopEmployer.EmployerId, + IsActiveString = x.ch.IsActiveString, + Signature = x.ch.Signature, + CreationDate = x.ch.CreationDate, + EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", + IsBlockCantracingParty = x.contractingParty.IsBlock, + HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, + IsUpdateNeeded = x.ch.IsUpdateNeeded, + CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => + new CheckoutWarningMessageModel + { + WarningMessage = wm.WarningMessage, + TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, + }).ToList() + }).GroupBy(x => x.Id) .Select(x => x.First()).ToList() .OrderByDescending(x => x.Id) .ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).ToList(); - - } - } + public async Task> SearchForMainCheckout(CheckoutSearchModel searchModel) { - - bool hasSearch = false; bool hasEmployeeOrWorkshpSearch = false; //List query = null; @@ -2480,11 +2464,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos .Select(x => x.WorkshopId).ToList(); - - var query = _context.CheckoutSet.Select(x => new CheckoutViewModel() { - Id = x.id, EmployeeFullName = x.EmployeeFullName, //var start = ; @@ -2507,13 +2488,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos IsActiveString = x.IsActiveString, Signature = x.Signature, CreationDate = x.CreationDate, - - }); - - if (!string.IsNullOrWhiteSpace(searchModel.ContractNo) && searchModel.ContractId != 0) query = query.Where(x => x.ContractNo == searchModel.ContractNo && x.ContractId == searchModel.ContractId); @@ -2522,11 +2499,13 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos hasEmployeeOrWorkshpSearch = true; query = query.Where(x => x.WorkshopId == searchModel.WorkshopId); } + if (searchModel.EmployeeId != 0) { hasEmployeeOrWorkshpSearch = true; query = query.Where(x => x.EmployeeId == searchModel.EmployeeId); } + if (searchModel.EmployerId != 0) { hasEmployeeOrWorkshpSearch = true; @@ -2570,7 +2549,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos query = query.Where(x => x.ContractStartGr >= startyearGr && x.ContractEndGr <= endYearGr); if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) query = query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt); - } else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) && string.IsNullOrWhiteSpace(searchModel.ContractStart) && @@ -2690,7 +2668,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos endDate >= x.ContractEndGr && startDate < x.ContractEndGr); if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) query = query.OrderBy(x => x.PersonnelCodeInt); - } else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) && !string.IsNullOrWhiteSpace(searchModel.ContractEnd) && @@ -2705,16 +2682,18 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) query = query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt); - } if (!string.IsNullOrEmpty(searchModel.EmployeeName)) { hasSearch = true; - var employeeList = _context.Employees.Where(x => (!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchModel.EmployeeName)) || - (!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchModel.EmployeeName))).Select(x => x.id).ToList(); + var employeeList = _context.Employees.Where(x => + (!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchModel.EmployeeName)) || + (!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchModel.EmployeeName))).Select(x => x.id) + .ToList(); query = query.Where(x => employeeList.Contains(x.EmployeeId)); } + if (hasSearch) return query.OrderByDescending(x => x.Id) .ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).ToList(); @@ -2725,22 +2704,17 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos .ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).Take(50).ToList(); // Console.WriteLine("return" + watch.Elapsed); - - - } #endregion #region Pooya - - public List<(long EmployeeId, DateTime CheckoutStart, DateTime CheckoutEnd)> GetLastCheckoutsByWorkshopIdForWorkFlow(long workshopId, DateTime start, DateTime end) + public List<(long EmployeeId, DateTime CheckoutStart, DateTime CheckoutEnd)> + GetLastCheckoutsByWorkshopIdForWorkFlow(long workshopId, DateTime start, DateTime end) { - - - - return _context.CheckoutSet.AsSplitQuery().Where(x => x.ContractEnd.Date >= start && x.ContractStart.Date <= end && x.WorkshopId == workshopId).Select(x => new + return _context.CheckoutSet.AsSplitQuery().Where(x => + x.ContractEnd.Date >= start && x.ContractStart.Date <= end && x.WorkshopId == workshopId).Select(x => new { EmployeeId = x.EmployeeId, CheckoutEnd = x.ContractEnd, @@ -2758,8 +2732,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos #endregion - - #region ForApi public async Task> GetList(CheckoutSearchModelDto searchModel) @@ -2769,40 +2741,37 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos .Select(x => x.WorkshopId); - var watch = new Stopwatch(); watch.Start(); var checkouts = - ( - from workshop in _context.Workshops.Where(x => workshopAccounts.Contains(x.id)) - join x in _context.CheckoutSet - on workshop.id equals x.WorkshopId - select new - { - Id = x.id, - EmployeeFullName = x.EmployeeFullName, - EmployeeId = x.EmployeeId, - ContractStart = x.ContractStart, - ContractEnd = x.ContractEnd, - PersonnelCode = x.PersonnelCode, - SumOfWorkingDays = x.SumOfWorkingDays, - Month = x.Month, - Year = x.Year, - ContractNo = x.ContractNo, - IsActiveString = x.IsActiveString, - Signature = x.Signature, - IsUpdateNeeded = x.IsUpdateNeeded, - WorkshopId = x.WorkshopId, - ArchiveCode = workshop.ArchiveCode, - WorkshopName = workshop.WorkshopFullName, - WorkshopSignCheckout = workshop.SignCheckout, - - } - - ).OrderByDescending(x => x.Id) - .ThenByDescending(x => x.Year) - .ThenByDescending(x => x.ContractStart) - .ThenBy(x => x.PersonnelCode).AsNoTracking(); + ( + from workshop in _context.Workshops.Where(x => workshopAccounts.Contains(x.id)) + join x in _context.CheckoutSet + on workshop.id equals x.WorkshopId + select new + { + Id = x.id, + EmployeeFullName = x.EmployeeFullName, + EmployeeId = x.EmployeeId, + ContractStart = x.ContractStart, + ContractEnd = x.ContractEnd, + PersonnelCode = x.PersonnelCode, + SumOfWorkingDays = x.SumOfWorkingDays, + Month = x.Month, + Year = x.Year, + ContractNo = x.ContractNo, + IsActiveString = x.IsActiveString, + Signature = x.Signature, + IsUpdateNeeded = x.IsUpdateNeeded, + WorkshopId = x.WorkshopId, + ArchiveCode = workshop.ArchiveCode, + WorkshopName = workshop.WorkshopFullName, + WorkshopSignCheckout = workshop.SignCheckout, + } + ).OrderByDescending(x => x.Id) + .ThenByDescending(x => x.Year) + .ThenByDescending(x => x.ContractStart) + .ThenBy(x => x.PersonnelCode).AsNoTracking(); Console.WriteLine("getList======================= : " + watch.Elapsed); @@ -2817,10 +2786,12 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos .OrderByDescending(x => x.ContractStart) .ThenBy(x => x.PersonnelCode); } + if (!string.IsNullOrWhiteSpace(searchModel.EmployeeFullName)) { checkouts = checkouts.Where(x => x.EmployeeFullName.Contains(searchModel.EmployeeFullName)); } + if (searchModel.EmployerId != 0) { var workshopIds = _context.WorkshopEmployers.Where(e => e.EmployerId == searchModel.EmployerId) @@ -2830,16 +2801,12 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } - - - //سرچ سال if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month) && (string.IsNullOrWhiteSpace(searchModel.ContractStart) || string.IsNullOrWhiteSpace(searchModel.ContractEnd))) { - var startYear = searchModel.Year + "/01/01"; var startyearGr = startYear.ToGeorgianDateTime(); var endYear = $"{searchModel.Year}/12/01".FindeEndOfMonth(); @@ -2847,15 +2814,14 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos checkouts = checkouts.Where(x => x.ContractStart >= startyearGr && x.ContractEnd <= endYearGr); - if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || searchModel.EmployerId > 0) + if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || + searchModel.EmployerId > 0) checkouts = checkouts.OrderByDescending(x => x.ContractEnd); - } else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) && string.IsNullOrWhiteSpace(searchModel.ContractStart) && string.IsNullOrWhiteSpace(searchModel.ContractEnd)) { - //سرچ سال و ماه string y1 = $"{searchModel.Year}/{searchModel.Month}/01"; var startDate = y1.ToGeorgianDateTime(); @@ -2969,31 +2935,30 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos endDate >= x.ContractEnd && startDate < x.ContractEnd); //if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) // checkouts = checkouts.OrderBy(x => x.PersonnelCodeInt); - } else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) && !string.IsNullOrWhiteSpace(searchModel.ContractEnd) && string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month)) { - //سرچ تاریخ var start = searchModel.ContractStart.ToGeorgianDateTime(); var endd = searchModel.ContractEnd.ToGeorgianDateTime(); checkouts = checkouts.Where(x => x.ContractStart >= start && x.ContractStart <= endd); - if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || searchModel.EmployerId > 0) + if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || + searchModel.EmployerId > 0) checkouts = checkouts.OrderByDescending(x => x.ContractEnd).ThenBy(x => x.PersonnelCode); } - #endregion watch.Reset(); watch.Start(); - var checkoutQueryFilter = await checkouts.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); + var checkoutQueryFilter = + await checkouts.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); Console.WriteLine("pagination===================== : " + watch.Elapsed); var employers = await @@ -3019,7 +2984,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { var warningMessage = warningMessages.Where(wm => wm.CheckoutId == x.Id); var empl = employers.First(em => em.WorkshopId == x.WorkshopId); - var isBlock = contractnigParties.Any(cp => cp.id == empl.Employer.ContractingPartyId && cp.IsBlock == "true"); + var isBlock = + contractnigParties.Any(cp => cp.id == empl.Employer.ContractingPartyId && cp.IsBlock == "true"); var option = options.FirstOrDefault(o => o.WorkshopId == x.WorkshopId && o.EmployeeId == x.EmployeeId); return new CheckoutDto { @@ -3044,13 +3010,10 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { WarningMessage = wm.WarningMessage, TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, - }).ToList() }; - - }) - .ToList(); + .ToList(); var count = await checkouts.CountAsync(); Console.WriteLine("FinalList================================ : " + watch.Elapsed); return new PagedResult() @@ -3061,7 +3024,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } - public async Task> CheckoutPrint(List ids) { if (ids.Count == 0) @@ -3082,12 +3044,13 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos EmployerFullName = x.Employer.FullName }).ToListAsync(); - var employees = (from x in _context.Employees.Where(x => getCheckouts.Select(ch => ch.EmployeeId).Contains(x.id)) - select new - { - EmployeeId = x.id, - MaritalStatus = x.MaritalStatus - } + var employees = + (from x in _context.Employees.Where(x => getCheckouts.Select(ch => ch.EmployeeId).Contains(x.id)) + select new + { + EmployeeId = x.id, + MaritalStatus = x.MaritalStatus + } ).AsNoTracking(); var workshop = await _context.Workshops.AsNoTracking().FirstAsync(x => x.id == getCheckouts.First().WorkshopId); var showSumOfPayments = workshop.TotalPaymentHide; @@ -3099,7 +3062,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var result = getCheckouts.Select(x => { var leftCheck = leftWorks - .FirstOrDefault(l => l.EmployeeId == x.EmployeeId && x.ContractStart >= l.StartWorkDate && x.ContractStart <= l.LeftWorkDate && l.HasLeft); + .FirstOrDefault(l => + l.EmployeeId == x.EmployeeId && x.ContractStart >= l.StartWorkDate && + x.ContractStart <= l.LeftWorkDate && l.HasLeft); bool hasLeft = false; var leftWorkDate = ""; var lastDayOfWork = ""; @@ -3112,8 +3077,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos leftWorkDate = leftCheck.LeftWorkDate.ToFarsi(); lastDayOfWork = x.ContractEnd.ToFarsi(); } - } + var overTimeWorkValue = x.OvertimePay > 0 ? x.OverTimeWorkValue : "-"; var overNightWorkValue = x.NightworkPay > 0 ? x.OverNightWorkValue : "-"; var fridayWorkValue = x.FridayPay > 0 ? x.FridayWorkValue : "-"; @@ -3130,6 +3095,59 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos totalClaims = x.TotalClaims; } + List rollcalls = []; + TimeSpan TotalPresentTimeSpan; + TimeSpan TotalBreakTimeSpan; + TimeSpan TotalWorkingTimeSpan; + TimeSpan TotalPaidLeaveTmeSpan; + TimeSpan TotalMandatoryTimeSpan; + TimeSpan TotalSickLeaveTimeSpan; + if (x.CheckoutRollCall != null) + { + TotalMandatoryTimeSpan = x.CheckoutRollCall.TotalPresentTimeSpan; + TotalBreakTimeSpan = x.CheckoutRollCall.TotalBreakTimeSpan; + TotalWorkingTimeSpan = x.CheckoutRollCall.TotalWorkingTimeSpan; + TotalPaidLeaveTmeSpan = x.CheckoutRollCall.TotalPaidLeaveTmeSpan; + TotalMandatoryTimeSpan = x.CheckoutRollCall.TotalMandatoryTimeSpan; + TotalSickLeaveTimeSpan = x.CheckoutRollCall.TotalSickLeaveTimeSpan; + rollcalls = x.CheckoutRollCall.RollCallDaysCollection.Select(r => new CheckoutPrintRollCallDto() + { + DayOfWeek = r.Date.DayOfWeek.DayOfWeeKToPersian(), + StartDate1 = r.FirstStartDate, + EndDate1 = r.FirstEndDate, + StartDate2 = r.SecondStartDate, + EndDate2 = r.SecondEndDate, + IsSliced = r.IsSliced, + LeaveType = r.LeaveType, + IsAbsent = r.IsAbsent, + IsFriday = r.IsFriday, + IsHoliday = r.IsHoliday, + TotalWorkingHours = $"{(int)(r.WorkingTimeSpan.TotalHours)}:{r.WorkingTimeSpan.Minutes:00}", + BreakTimeString = $"{(int)(r.BreakTimeSpan.TotalHours)}:{r.BreakTimeSpan.Minutes:00}", + RollCallDateFa = r.Date.ToFarsi() + + }).ToList(); + } + else + { + + if (x.HasRollCall) + x.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(x.EmployeeId, x.WorkshopId, + x.ContractStartGr, x.ContractEndGr); + else + { + x.CreateWorkingHoursTemp.ContractStartGr = x.ContractStartGr; + x.CreateWorkingHoursTemp.ContractEndGr = x.ContractEndGr; + x.CreateWorkingHoursTemp.ContarctStart = x.ContractStartGr.ToFarsi(); + x.CreateWorkingHoursTemp.ContractEnd = x.ContractEndGr.ToFarsi(); + x.CreateWorkingHoursTemp.EmployeeId = x.EmployeeId; + x.CreateWorkingHoursTemp.WorkshopId = x.WorkshopId; + x.MonthlyRollCall = + ConvertStaticToRollCall(x.CreateWorkingHoursTemp, + workshopName.WorkshopHolidayWorking); + } + } + return new CheckoutPrintDto() { Id = x.id, @@ -3137,6 +3155,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos // هدر فیش // اطلاعات هویتی // اطلاعات کارگاه + #region Header EmployeeFullName = x.EmployeeFullName, @@ -3152,6 +3171,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos HasLeft = hasLeft, LastDayOfWork = lastDayOfWork, LeftWorkDate = leftWorkDate, + #endregion //جدول مطالبات و کسورات @@ -3159,82 +3179,161 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos #region PaymentAndDeductionTable //مطالبات - PaymentList = new List - { + PaymentList = + [ new PaymentAndDeductionList() - {RowNumber = 1, Title = "حقوق و مزد", Value = $"{x.SumOfWorkingDays}", Amount = x.MonthlySalary.ToMoneyCheckZero(),}, + { + RowNumber = 1, Title = "حقوق و مزد", Value = $"{x.SumOfWorkingDays}", + Amount = x.MonthlySalary.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 2, Title = "پایه سنوات", Value = "-", Amount = x.BaseYearsPay.ToMoneyCheckZero(),}, + { + RowNumber = 2, Title = "پایه سنوات", Value = "-", Amount = x.BaseYearsPay.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 3, Title = "کمک هزینه اقلام مصرفی خانوار", Value = "-", Amount = x.ConsumableItems.ToMoneyCheckZero(),}, + { + RowNumber = 3, Title = "کمک هزینه اقلام مصرفی خانوار", Value = "-", + Amount = x.ConsumableItems.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 4, Title = "کمک هزینه مسکن", Value = "-", Amount = x.HousingAllowance.ToMoneyCheckZero(),}, + { + RowNumber = 4, Title = "کمک هزینه مسکن", Value = "-", + Amount = x.HousingAllowance.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 5, Title = "فوق العاده اضافه کاری", Value = overTimeWorkValue, Amount = x.OvertimePay.ToMoneyCheckZero(),}, + { + RowNumber = 5, Title = "فوق العاده اضافه کاری", Value = overTimeWorkValue, + Amount = x.OvertimePay.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 6, Title = "فوق العاده شب کاری", Value = overNightWorkValue, Amount = x.NightworkPay.ToMoneyCheckZero(),}, + { + RowNumber = 6, Title = "فوق العاده شب کاری", Value = overNightWorkValue, + Amount = x.NightworkPay.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 7, Title = "فوق العاده جمعه کاری", Value = fridayWorkValue, Amount = x.FridayPay.ToMoneyCheckZero(),}, + { + RowNumber = 7, Title = "فوق العاده جمعه کاری", Value = fridayWorkValue, + Amount = x.FridayPay.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 8, Title = "فوق العاده ماموریت", Value = "-", Amount = "-",}, + { RowNumber = 8, Title = "فوق العاده ماموریت", Value = "-", Amount = "-", }, + new PaymentAndDeductionList() - {RowNumber = 9, Title = "فوق العاده نوبت کاری", Value = rotatingShiftValue, Amount = x.ShiftPay.ToMoneyCheckZero(),}, + { + RowNumber = 9, Title = "فوق العاده نوبت کاری", Value = rotatingShiftValue, + Amount = x.ShiftPay.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 10, Title = "کمک هزینه عائله مندی", Value = "-", Amount = x.FamilyAllowance.ToMoneyCheckZero(),}, + { + RowNumber = 10, Title = "کمک هزینه عائله مندی", Value = "-", + Amount = x.FamilyAllowance.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 11, Title = "حق تاهل", Value = maritalStatus, Amount = x.MarriedAllowance.ToMoneyCheckZero(),}, + { + RowNumber = 11, Title = "حق تاهل", Value = maritalStatus, + Amount = x.MarriedAllowance.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 12, Title = "پاداش", Value = "-", Amount = rewardPay,}, + { RowNumber = 12, Title = "پاداش", Value = "-", Amount = rewardPay, }, + new PaymentAndDeductionList() - {RowNumber = 13, Title = "عیدی و پاداش", Value = "-", Amount = x.BonusesPay.ToMoneyCheckZero(),}, + { + RowNumber = 13, Title = "عیدی و پاداش", Value = "-", + Amount = x.BonusesPay.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 14, Title = "سنوات", Value = "-", Amount = x.YearsPay.ToMoneyCheckZero(),}, + { + RowNumber = 14, Title = "سنوات", Value = "-", + Amount = x.YearsPay.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() - {RowNumber = 15, Title = "مزد مرخصی", Value = "-", Amount = x.LeavePay.ToMoneyCheckZero(),}, - }, + { + RowNumber = 15, Title = "مزد مرخصی", Value = "-", + Amount = x.LeavePay.ToMoneyCheckZero(), + } + ], //کسورات - DeductionList = new List - { + DeductionList = + [ new PaymentAndDeductionList() - {RowNumber = 1, Title = "حق بیمه سهم کارگر", Value = "-", Amount = x.InsuranceDeduction.ToMoneyCheckZero(),}, - new PaymentAndDeductionList() - {RowNumber = 2, Title = "مالیات بر حقوق", Value = "-", Amount = x.TaxDeducation.ToMoneyCheckZero(),}, - new PaymentAndDeductionList() - {RowNumber = 3, Title = "قسط تسهیلات", Value = "-", Amount = x.InstallmentDeduction.ToMoneyCheckZero(),}, - new PaymentAndDeductionList() - {RowNumber = 4, Title = "مساعده", Value = "-", Amount = x.SalaryAidDeduction.ToMoneyCheckZero(),}, - new PaymentAndDeductionList() - {RowNumber = 5, Title = "غیبت", Value = "-", Amount = "-",}, - }, + { + RowNumber = 1, Title = "حق بیمه سهم کارگر", Value = "-", + Amount = x.InsuranceDeduction.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() + { + RowNumber = 2, Title = "مالیات بر حقوق", Value = "-", + Amount = x.TaxDeducation.ToMoneyCheckZero(), + }, + new PaymentAndDeductionList() + { + RowNumber = 3, Title = "قسط تسهیلات", Value = "-", + Amount = x.InstallmentDeduction.ToMoneyCheckZero(), + }, + + new PaymentAndDeductionList() + { + RowNumber = 4, Title = "مساعده", Value = "-", Amount = x.SalaryAidDeduction.ToMoneyCheckZero(), + }, + + new PaymentAndDeductionList() + { RowNumber = 5, Title = "غیبت", Value = "-", Amount = "-", } + ], + TotalPayment = totalPayment, TotalDeductions = totalDeduction, TotalClaims = totalClaims, + #endregion //لیست ورود و خروج پرسنل //اطلاعات ساعات کار و موظقی + #region RollCallData - - + MonthlyRollCall =rollcalls, #endregion //اقساط - مساعده - #region SalaryAidAndInstallmentData + #region SalaryAidAndInstallmentData + SalaryAids= x.SalaryAids.Select(s=> new CheckoutPrintSalaryAidDto() + { + Amount = s.Amount, + SalaryAidDateTimeFa = s.SalaryAidDateTimeFa, + }).ToList(), + + Installments = x.LoanInstallments.Select(i=>new CheckoutPrintInstallmentDto() + { + Amount = i.AmountForMonth, + RemainingAmount = i.LoanRemaining, + LoanAmount = i.LoanAmount + }).ToList(), + + #endregion }; - - - }).ToList(); Console.WriteLine("print : " + watch.Elapsed); return result; } + #endregion } \ No newline at end of file