diff --git a/Company.Domain/LeftWorkAgg/ILeftWorkRepository.cs b/Company.Domain/LeftWorkAgg/ILeftWorkRepository.cs index 4a1f37eb..1c2aefbd 100644 --- a/Company.Domain/LeftWorkAgg/ILeftWorkRepository.cs +++ b/Company.Domain/LeftWorkAgg/ILeftWorkRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.Domain; using CompanyManagment.App.Contracts.LeftWork; @@ -39,5 +40,7 @@ public interface ILeftWorkRepository : IRepository bool IsEmployeeWorkingInDates(long employeeId, long workshopId, List<(DateTime, DateTime)> dates); List GetByWorkshopIdInDates(long workshopId, DateTime startDateGr, DateTime endDateGr); LeftWorkViewModel GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime start, DateTime end); - #endregion + #endregion + + Task GetLastLeftWork(long employeeId, long workshopId); } \ No newline at end of file diff --git a/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs b/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs index 236ded26..c77e8133 100644 --- a/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs +++ b/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Linq; using Company.Domain.RollCallServiceAgg; +using System.Globalization; namespace CompanyManagment.Application @@ -35,7 +36,7 @@ namespace CompanyManagment.Application return op.Failed("کارمند مجاز نیست"); if (!_leftWorkRepository.Exists(x => x.EmployeeId == rollCallEmployee.EmployeeId && x.WorkshopId == rollCallEmployee.WorkshopId && - x.LeftWorkDate.Date > DateTime.Now.Date && x.StartWorkDate.Date <= DateTime.Now.Date)) + (x.LeftWorkDate.Date > DateTime.Now.Date && x.StartWorkDate.Date <= DateTime.Now.Date) || x.StartWorkDate >= DateTime.Today)) return op.Failed("کارمند در کارگاه شروع به کار نکرده است"); if (_employeeRollCallStatusRepository.Exists(y => @@ -50,7 +51,21 @@ namespace CompanyManagment.Application } else { - RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, DateTime.Now.Date); + var pc = new PersianCalendar(); + var startStatus = DateTime.Today; + LeftWork leftWork = + _leftWorkRepository.GetLastLeftWork(rollCallEmployee.EmployeeId, rollCallEmployee.WorkshopId).GetAwaiter().GetResult(); + + if (leftWork.StartWorkDate > DateTime.Today) + startStatus = leftWork.StartWorkDate; + + //else if(pc.GetMonth(DateTime.Today) == pc.GetMonth(leftWork.StartWorkDate)) + //{ + // startStatus = new DateTime(pc.GetYear(leftWork.StartWorkDate), pc.GetMonth(leftWork.StartWorkDate), + // 1, pc); + //} + + RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, startStatus); _employeeRollCallStatusRepository.Create(newRecord); } diff --git a/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs b/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs index e6cb02a0..3d0b9a41 100644 --- a/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.InfraStructure; using Company.Domain.LeftWorkAgg; @@ -675,4 +676,10 @@ public class LeftWorkRepository : RepositoryBase, ILeftWorkRepos } #endregion + public async Task GetLastLeftWork(long employeeId, long workshopId) + { + var leftWork = await _context.LeftWorkList.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId) + .OrderByDescending(x => x.StartWorkDate).FirstOrDefaultAsync(); + return leftWork; + } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs index c91cc4c8..32f97f66 100644 --- a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs @@ -95,15 +95,15 @@ public class RollCallEmployeeRepository : RepositoryBase var rawQuery = employeeQuery.Include(x => x.LeftWorks).Include(x => x.LeftWorkInsurances) .Where(x => x.LeftWorks.Any(y => - y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow && - y.LeftWorkDate > dateNow) || + (y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow && + y.LeftWorkDate > dateNow) || y.StartWorkDate > dateNow) || x.LeftWorkInsurances.Any(y => y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow && (y.LeftWorkDate > dateNow || y.LeftWorkDate == null))).OrderByDescending(x => x.id) .Select(x => new { Id = x.id, - FullName =x.FName +" "+x.LName, + FullName = x.FName + " " + x.LName, x.NationalCode, }).AsSplitQuery();