From 63a3027a17824dbca52985c174c9c77f97cadb07 Mon Sep 17 00:00:00 2001 From: mahan Date: Sun, 18 Jan 2026 12:51:58 +0330 Subject: [PATCH] add client checkout list controller --- .../CheckoutAgg/ICheckoutRepository.cs | 2 + .../Checkout/ICheckoutApplication.cs | 36 + .../CheckoutApplication.cs | 5 + .../Repository/CheckoutRepository.cs | 884 ++++++++++-------- .../Client/Controllers/CheckoutController.cs | 25 + 5 files changed, 539 insertions(+), 413 deletions(-) create mode 100644 ServiceHost/Areas/Client/Controllers/CheckoutController.cs diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index 5294bbaa..b14ba1cd 100644 --- a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs +++ b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs @@ -80,4 +80,6 @@ public interface ICheckoutRepository : IRepository #endregion Task GetByWorkshopIdEmployeeIdInDate(long workshopId, long employeeId, DateTime inDate); + Task> GetListForClient(long workshopId, + CheckoutListClientSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs index 74f5cccb..93ddb0cc 100644 --- a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs +++ b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs @@ -62,4 +62,40 @@ public interface ICheckoutApplication long workshopId, DateTime start, DateTime end); #endregion + + Task> GetListForClient(long workshopId, + CheckoutListClientSearchModel searchModel); +} + +public class CheckoutListClientSearchModel:PaginationRequest +{ + public long? EmployeeId { get; set; } + public string Year { get; set; } + public string Month { get; set; } + public string StartDate { get; set; } + public string EndDate { get; set; } + public CheckoutClientListOrderType? OrderType { get; set; } +} + +public class CheckoutListClientDto +{ + public long Id { get; set; } + public string Year { get; set; } + public string Month { get; set; } + public string EmployeeName { get; set; } + public string ContractNo { get; set; } + public string ContractStart { get; set; } + public string ContractEnd { get; set; } + public bool Signature { get; set; } +} + +public enum CheckoutClientListOrderType +{ + ByCheckoutCreationDate, + BySignedCheckout, + ByUnSignedCheckout, + ByPersonnelCode, + ByPersonnelCodeDescending, + ByCheckoutStartDate, + ByCheckoutStartDateDescending } \ No newline at end of file diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 8768f70e..11ce1fa9 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -706,5 +706,10 @@ public class CheckoutApplication : ICheckoutApplication return _checkoutRepository.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, start, end); } + public async Task> GetListForClient(long workshopId,CheckoutListClientSearchModel searchModel) + { + return await _checkoutRepository.GetListForClient(workshopId, searchModel); + } + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index a78ff18e..d2fdc947 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Reflection.Metadata.Ecma335; using System.Threading.Tasks; using _0_Framework.Application; +using _0_Framework.Exceptions; using _0_Framework.InfraStructure; using Company.Domain.CheckoutAgg; using Company.Domain.LeftWorkAgg; @@ -50,9 +51,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; @@ -71,10 +74,11 @@ 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); - + var res = _context.CheckoutSet.FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeId && x.Year == year && x.Month == farisMonthName && x.IsActiveString == "true"); @@ -83,61 +87,61 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var checkLeftDate = ($"{year}/{month}/01").ToGeorgianDateTime(); var hasLeftwork = _context.LeftWorkList.Any(x => x.EmployeeId == employeId && x.WorkshopId == workshopId && x.LeftWorkDate == checkLeftDate); - if(hasLeftwork) + if (hasLeftwork) return (true, 0, 0, 0, 0, 0, 0); return (false, 0, 0, 0, 0, 0, 0); } - - 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); } @@ -152,7 +156,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; @@ -165,7 +170,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } else { - if (month == "0" && year == "0") { DateTime now = DateTime.Now; @@ -195,8 +199,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos startSreach = startStr.ToGeorgianDateTime(); endSearch = (startStr.FindeEndOfMonth()).ToGeorgianDateTime(); } - } + var timer = new Stopwatch(); timer.Start(); @@ -211,7 +215,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 }) @@ -221,16 +227,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( @@ -249,12 +254,12 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var now = DateTime.Now; 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, @@ -273,9 +278,10 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos EmployeeHasCreateCheckout = true }; } + var employeeJoin = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork .contractWorkshopEmployee.employee.id; - + var leftWork = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork .leftwork; @@ -283,11 +289,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; @@ -300,11 +308,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) @@ -322,7 +330,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ? leftWork.StartWorkDate.ToFarsi() : startSreach.ToFarsi(); contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi(); - } else { @@ -334,7 +341,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ? leftWork.StartWorkDate.ToFarsi() : startSreach.ToFarsi(); contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi(); - } } else if (endSearch < currentStart) @@ -357,7 +363,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos : startSreach.ToFarsi(); contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi(); } - } else if (leftWork.HasLeft && leftWork.LeftWorkDate <= startSreach) { @@ -365,7 +370,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos extension = false; description = "به دلیل ترک کار پیش از تاریخ انتخاب شده مجاز به ایجاد فیش نمی باشید"; leftWorkDate = leftWork.LeftWorkDate.ToFarsi(); - } else if (!leftWork.HasLeft && startSreach == currentStart) { @@ -376,13 +380,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; @@ -397,12 +397,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 @@ -468,13 +467,11 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos contractEnd = endSearch.ToFarsi(); } } - } #endregion - return new CreateCheckoutListViewModel { Id = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork @@ -498,15 +495,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() @@ -517,14 +513,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); @@ -533,10 +528,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos entity.SetLoanInstallment(command.LoanInstallments, command.InstallmentDeduction); entity.SetCheckoutRollCall(command.CheckoutRollCall); entity.SetEmployeeMandatoryHours(command.EmployeeMandatoryHours); - if(command.HasInsuranceShareTheSameAsList) + if (command.HasInsuranceShareTheSameAsList) entity.SetInsuranceShare(); await _context.SaveChangesAsync(); - } @@ -678,9 +672,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) && @@ -799,7 +790,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) && @@ -813,17 +803,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) @@ -865,7 +850,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos ContractNo = x.ContractNo, ContractId = x.ContractId, HasRollCall = x.HasRollCall - }); if (searchModel.EmployeeId != 0 && searchModel.WorkshopId != 0) @@ -884,11 +868,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) @@ -898,78 +883,79 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos foreach (var item in checkouts) { var ch = new CheckoutViewModel() + { + Id = item.id, + WorkshopId = item.WorkshopId, + ContractId = item.ContractId, + EmployeeId = item.EmployeeId, + EmployeeFullName = item.EmployeeFullName, + FathersName = item.FathersName, + NationalCode = item.NationalCode, + DateOfBirth = item.DateOfBirth, + WorkshopName = item.WorkshopName, + Month = item.Month, + Year = item.Year, + PersonnelCode = item.PersonnelCode, + PersonnelCodeInt = Convert.ToInt32(item.PersonnelCode), + ContractNo = item.ContractNo, + MonthlySalary = item.MonthlySalary.ToMoney(), + BaseYearsPay = item.BaseYearsPay.ToMoney(), + ConsumableItems = item.ConsumableItems.ToMoney(), + HousingAllowance = item.HousingAllowance.ToMoney(), + OvertimePay = item.OvertimePay.ToMoney(), + NightworkPay = item.NightworkPay.ToMoney(), + FridayPay = item.FridayPay.ToMoney(), + MissionPay = item.MissionPay.ToMoney(), + ShiftPay = item.ShiftPay.ToMoney(), + FamilyAllowance = item.FamilyAllowance.ToMoney(), + BonusesPay = item.BonusesPay.ToMoney(), + YearsPay = item.YearsPay.ToMoney(), + LeavePay = item.LeavePay.ToMoney(), + InsuranceDeduction = item.InsuranceDeduction.ToMoney(), + TaxDeducation = item.TaxDeducation.ToMoney(), + InstallmentDeduction = item.InstallmentDeduction.ToMoney(), + SalaryAidDeduction = item.SalaryAidDeduction.ToMoney(), + AbsenceDeduction = item.AbsenceDeduction.ToMoney(), + TotalClaims = item.TotalClaims, + TotalDeductions = item.TotalDeductions, + TotalPayment = item.TotalPayment.ToMoney(), + RewardPay = item.RewardPay.ToMoneyNullable(), + ContractStartGr = item.ContractStart, + ContractEndGr = item.ContractEnd, + IsLeft = false, + LeftWorkDate = "", + LastDayOfWork = "", + MarriedAllowance = item.MarriedAllowance.ToMoney(), + HasRollCall = item.HasRollCall, + SumOfWorkingDays = "-", + OverTimeWorkValue = item.OverTimeWorkValue, + OverNightWorkValue = item.OverNightWorkValue, + FridayWorkValue = item.FridayWorkValue, + RotatingShiftValue = item.RotatingShiftValue, + AbsenceValue = item.AbsenceValue, + MaritalStatus = "", + TotalDayOfLeaveCompute = "-", + TotalDayOfYearsCompute = "-", + TotalDayOfBunosesCompute = "-", + InstallmentViewModels = item.LoanInstallments.Select(i => new LoanInstallmentViewModel() { - Id = item.id, - WorkshopId = item.WorkshopId, - ContractId = item.ContractId, - EmployeeId = item.EmployeeId, - EmployeeFullName = item.EmployeeFullName, - FathersName = item.FathersName, - NationalCode = item.NationalCode, - DateOfBirth = item.DateOfBirth, - WorkshopName = item.WorkshopName, - Month = item.Month, - Year = item.Year, - PersonnelCode = item.PersonnelCode, - PersonnelCodeInt = Convert.ToInt32(item.PersonnelCode), - ContractNo = item.ContractNo, - MonthlySalary = item.MonthlySalary.ToMoney(), - BaseYearsPay = item.BaseYearsPay.ToMoney(), - ConsumableItems = item.ConsumableItems.ToMoney(), - HousingAllowance = item.HousingAllowance.ToMoney(), - OvertimePay = item.OvertimePay.ToMoney(), - NightworkPay = item.NightworkPay.ToMoney(), - FridayPay = item.FridayPay.ToMoney(), - MissionPay = item.MissionPay.ToMoney(), - ShiftPay = item.ShiftPay.ToMoney(), - FamilyAllowance = item.FamilyAllowance.ToMoney(), - BonusesPay = item.BonusesPay.ToMoney(), - YearsPay = item.YearsPay.ToMoney(), - LeavePay = item.LeavePay.ToMoney(), - InsuranceDeduction = item.InsuranceDeduction.ToMoney(), - TaxDeducation = item.TaxDeducation.ToMoney(), - InstallmentDeduction = item.InstallmentDeduction.ToMoney(), - SalaryAidDeduction = item.SalaryAidDeduction.ToMoney(), - AbsenceDeduction = item.AbsenceDeduction.ToMoney(), - TotalClaims = item.TotalClaims, - TotalDeductions = item.TotalDeductions, - TotalPayment = item.TotalPayment.ToMoney(), - RewardPay = item.RewardPay.ToMoneyNullable(), - ContractStartGr = item.ContractStart, - ContractEndGr = item.ContractEnd, - IsLeft = false, - LeftWorkDate = "", - LastDayOfWork = "", - MarriedAllowance = item.MarriedAllowance.ToMoney(), - HasRollCall = item.HasRollCall, - SumOfWorkingDays = "-", - OverTimeWorkValue = item.OverTimeWorkValue, - OverNightWorkValue = item.OverNightWorkValue, - FridayWorkValue = item.FridayWorkValue, - RotatingShiftValue = item.RotatingShiftValue, - AbsenceValue = item.AbsenceValue, - MaritalStatus = "", - TotalDayOfLeaveCompute = "-", - TotalDayOfYearsCompute = "-", - TotalDayOfBunosesCompute = "-", - InstallmentViewModels = item.LoanInstallments.Select(i => new LoanInstallmentViewModel() - { - Amount = i.AmountForMonth, - AmountDouble = i.AmountForMonth.MoneyToDouble(), - Year = i.Year, - Month = i.Month, - IsActive = i.IsActive, - RemainingAmount = i.LoanRemaining, - LoanAmount = i.LoanAmount - }).ToList(), - SalaryAidViewModels = item.SalaryAids.Select(s => new SalaryAidViewModel() - { - Amount = s.Amount, - AmountDouble = s.Amount.MoneyToDouble(), - SalaryAidDateTimeFa = s.SalaryAidDateTimeFa, - SalaryAidDateTimeGe = s.SalaryAidDateTime - }).ToList(), - CheckoutRollCall = item.CheckoutRollCall != null ? new CheckoutRollCallViewModel() + Amount = i.AmountForMonth, + AmountDouble = i.AmountForMonth.MoneyToDouble(), + Year = i.Year, + Month = i.Month, + IsActive = i.IsActive, + RemainingAmount = i.LoanRemaining, + LoanAmount = i.LoanAmount + }).ToList(), + SalaryAidViewModels = item.SalaryAids.Select(s => new SalaryAidViewModel() + { + Amount = s.Amount, + AmountDouble = s.Amount.MoneyToDouble(), + SalaryAidDateTimeFa = s.SalaryAidDateTimeFa, + SalaryAidDateTimeGe = s.SalaryAidDateTime + }).ToList(), + CheckoutRollCall = item.CheckoutRollCall != null + ? new CheckoutRollCallViewModel() { TotalPresentTimeSpan = item.CheckoutRollCall.TotalPresentTimeSpan, TotalBreakTimeSpan = item.CheckoutRollCall.TotalBreakTimeSpan, @@ -977,29 +963,31 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos 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,"-") - }; + 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, "-") + }; var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId); ch.WorkshopName = workshopName.WorkshopName; ch.TotalPaymentHide = workshopName.TotalPaymentHide; @@ -1122,9 +1110,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 @@ -1142,7 +1129,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 { @@ -1163,13 +1152,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; @@ -1178,9 +1166,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); } @@ -1191,6 +1181,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos printNumer += 1; rec.PrintCounter = printNumer; } + return query; } @@ -1216,7 +1207,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) { @@ -1245,7 +1235,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) @@ -1370,7 +1361,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); @@ -1390,6 +1380,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); @@ -1484,7 +1475,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 => { @@ -1497,20 +1489,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; @@ -1519,15 +1510,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)); @@ -1536,8 +1530,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()); @@ -1557,50 +1551,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(); @@ -1614,7 +1612,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos secondRCEndDate = secondRollCall.ShiftEndWithoutRest ?? secondRollCall.EndDate; - return new CheckoutDailyRollCallViewModel() { StartDate1 = firstRollCall?.StartDate?.ToString("HH:mm") ?? "", @@ -1686,12 +1683,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); @@ -1699,7 +1699,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { return new List(); } + #endregion + var query = _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList) .AsSplitQuery().Select(x => new CheckoutViewModel() { @@ -1741,9 +1743,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos { WarningMessage = wm.WarningMessage, TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, - }).ToList() - }).Where(x => x.WorkshopId == searchModel.WorkshopId); if (searchModel.EmployeeId > 0) { @@ -1752,7 +1752,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(); @@ -1857,16 +1857,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) @@ -1897,8 +1901,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos break; default: return query.OrderByDescending(x => x.Id).Skip(searchModel.PageIndex).Take(30).ToList(); } - - } #endregion @@ -1928,12 +1930,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) { @@ -1951,6 +1951,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos notRemoveList.Add(item); } } + return notRemoveList; } @@ -2010,7 +2011,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, @@ -2033,7 +2035,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) @@ -2050,15 +2053,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)) @@ -2066,7 +2072,6 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos hasEmployeeOrWorkshpSearch = true; checkouts = checkouts.Where(x => x.ch.ContractNo == searchModel.ContractNo); } - //if (searchModel.IsActiveString == null) @@ -2100,7 +2105,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) && @@ -2220,7 +2224,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) && @@ -2240,22 +2243,20 @@ 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(), @@ -2281,64 +2282,57 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos 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) + 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)) { @@ -2348,7 +2342,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) @@ -2356,7 +2351,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) @@ -2366,99 +2361,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; @@ -2476,11 +2461,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 = ; @@ -2503,13 +2485,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); @@ -2518,11 +2496,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; @@ -2566,7 +2546,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) && @@ -2686,7 +2665,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) && @@ -2701,16 +2679,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(); @@ -2721,22 +2701,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, @@ -2751,5 +2726,88 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos x.ContractEnd >= inDate); } + public async Task> GetListForClient(long workshopId, + CheckoutListClientSearchModel searchModel) + { + var query = _context.CheckoutSet.Where(x => x.WorkshopId == workshopId); + if (searchModel.EmployeeId is > 0) + { + query = query.Where(x => x.EmployeeId == searchModel.EmployeeId); + } + + if (!string.IsNullOrWhiteSpace(searchModel.StartDate) && !string.IsNullOrWhiteSpace(searchModel.EndDate)) + { + if (!searchModel.StartDate.TryToGeorgianDateTime(out var startDateGr)) + throw new BadRequestException("تاریخ شروع جستجو نامعتبر است"); + + if (!searchModel.EndDate.TryToGeorgianDateTime(out var endDateGr)) + { + throw new BadRequestException("تاریخ پایان جستجو نامعتبر است"); + } + + query = query.Where(x => x.ContractStart <= endDateGr && x.ContractEnd >= startDateGr); + } + + if (!string.IsNullOrWhiteSpace(searchModel.Year)) + { + query = query.Where(x => x.Year == searchModel.Year); + } + + if (!string.IsNullOrWhiteSpace(searchModel.Month)) + { + var searchedMonth = Convert.ToInt32(searchModel.Month).ToFarsiMonthByIntNumber(); + + query = query.Where(x => x.Month == searchedMonth); + } + + query = searchModel.OrderType switch + { + CheckoutClientListOrderType.ByCheckoutCreationDate => + query.OrderBy(x => x.CreationDate), + + CheckoutClientListOrderType.ByCheckoutStartDate => + query.OrderBy(x => x.ContractStart), + + CheckoutClientListOrderType.ByCheckoutStartDateDescending => + query.OrderByDescending(x => x.ContractStart), + + CheckoutClientListOrderType.ByPersonnelCode => + query.OrderBy(x => x.PersonnelCode), + + CheckoutClientListOrderType.ByPersonnelCodeDescending => + query.OrderByDescending(x => x.PersonnelCode), + + CheckoutClientListOrderType.BySignedCheckout => + query.OrderByDescending(x => x.Signature == "1"), + + CheckoutClientListOrderType.ByUnSignedCheckout => + query.OrderBy(x => x.Signature == "1"), + + _ => query.OrderByDescending(x => x.id) + }; + + var list =await query.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); + + var resList = list.Select(x => new CheckoutListClientDto() + { + Id = x.id, + ContractStart = x.ContractStart.ToFarsi(), + ContractEnd = x.ContractEnd.ToFarsi(), + Year = x.Year, + Month = x.Month, + ContractNo = x.ContractNo, + EmployeeName = x.EmployeeFullName, + Signature = x.Signature == "1" + }).ToList(); + + var res = new PagedResult + { + TotalCount = await query.CountAsync(), + List = resList + }; + + return res; + } + #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/CheckoutController.cs b/ServiceHost/Areas/Client/Controllers/CheckoutController.cs new file mode 100644 index 00000000..af770205 --- /dev/null +++ b/ServiceHost/Areas/Client/Controllers/CheckoutController.cs @@ -0,0 +1,25 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.Checkout; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Client.Controllers; + +public class CheckoutController:ClientBaseController +{ + private readonly ICheckoutApplication _checkoutApplication; + private readonly long _workshopId; + + public CheckoutController(ICheckoutApplication checkoutApplication,IAuthHelper authHelper) + { + _checkoutApplication = checkoutApplication; + _workshopId = authHelper.GetWorkshopId(); + } + + [HttpGet] + public async Task>> GetList(CheckoutListClientSearchModel searchModel) + { + var res =await _checkoutApplication.GetListForClient(_workshopId, searchModel); + return res; + } +} \ No newline at end of file