diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index 5a852773..4c8f4408 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -1680,6 +1680,10 @@ public static class Tools } + + + + #endregion #region Pooya @@ -1899,15 +1903,18 @@ public static class Tools public static int GetWorkingDaysDifference(DateTime? fromDate, DateTime? toDate) { - //var workingDays = PersianDateExtensions.GetWorkingDays(new PersianDateTime(fromDate.ToFarsi()), new PersianDateTime(toDate.ToFarsi()), true); var workingDays = PersianDateExtensions.GetWorkingDays((DateTime)fromDate, (DateTime)toDate, true); + if (fromDate > toDate) workingDays *= -1; + return workingDays; } + + #endregion } \ No newline at end of file diff --git a/Company.Domain/FileAlert/IFileAlertRepository.cs b/Company.Domain/FileAlert/IFileAlertRepository.cs index 589519b7..3417f78c 100644 --- a/Company.Domain/FileAlert/IFileAlertRepository.cs +++ b/Company.Domain/FileAlert/IFileAlertRepository.cs @@ -11,5 +11,5 @@ public interface IFileAlertRepository : IRepository FileAlertViewModel GetDetails(long id); void Remove(long id); List Search(FileAlertSearchModel searchModel); - Task> GetFileAlerts(); + Task> GetFileAlerts(FileAlertSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/FileAlert/IFileAlertApplication.cs b/CompanyManagment.App.Contracts/FileAlert/IFileAlertApplication.cs index ad29384a..8c8d78df 100644 --- a/CompanyManagment.App.Contracts/FileAlert/IFileAlertApplication.cs +++ b/CompanyManagment.App.Contracts/FileAlert/IFileAlertApplication.cs @@ -14,5 +14,5 @@ public interface IFileAlertApplication List Search(FileAlertSearchModel searchModel); List GetFilesAlerts(List files); int getMaximumAdditionalDeadlineTimes(int additionalDeadline); - Task> GetFileAlerts(); + Task> GetFileAlerts(FileAlertSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.Application/FileAlertApplication.cs b/CompanyManagment.Application/FileAlertApplication.cs index 8e40c771..7994b6a1 100644 --- a/CompanyManagment.Application/FileAlertApplication.cs +++ b/CompanyManagment.Application/FileAlertApplication.cs @@ -179,8 +179,8 @@ public class FileAlertApplication : IFileAlertApplication return 0; } - public async Task> GetFileAlerts() + public async Task> GetFileAlerts(FileAlertSearchModel searchModel) { - return await _fileAlertRepository.GetFileAlerts(); + return await _fileAlertRepository.GetFileAlerts(searchModel); } } \ No newline at end of file diff --git a/CompanyManagment.Application/PetitionApplication.cs b/CompanyManagment.Application/PetitionApplication.cs index 0781ace3..bb79acfc 100644 --- a/CompanyManagment.Application/PetitionApplication.cs +++ b/CompanyManagment.Application/PetitionApplication.cs @@ -21,13 +21,42 @@ public class PetitionApplication : IPetitionApplication var petitionIssuanceDate = new DateTime?(); var notificationPetitionDate = new DateTime?(); + if (!string.IsNullOrWhiteSpace(command.PetitionNo) || + !string.IsNullOrWhiteSpace(command.NotificationPetitionDate) || + !string.IsNullOrWhiteSpace(command.PetitionIssuanceDate) || + !string.IsNullOrWhiteSpace(command.TotalPenalty)) + { + if (string.IsNullOrWhiteSpace(command.PetitionNo)) + { + return operation.Failed("لطفا شماره دادنامه خودرا وارد کنید"); + } + + if (string.IsNullOrWhiteSpace(command.NotificationPetitionDate)) + { + return operation.Failed("لطفا تاریخ ابلاغ دادنامه را وارد کنید"); + } + + if (string.IsNullOrWhiteSpace(command.PetitionIssuanceDate)) + { + return operation.Failed("لطفا تاریخ صدور دادنامه را وارد کنید"); + } + + if (string.IsNullOrWhiteSpace(command.TotalPenalty)) + { + return operation.Failed("لطفا جمع نهایی دادنامه را وارد کنید"); + } + } + + if (command.PetitionIssuanceDate != null) petitionIssuanceDate = command.PetitionIssuanceDate.ToGeorgianDateTime(); - + if (command.NotificationPetitionDate != null) notificationPetitionDate = command.NotificationPetitionDate.ToGeorgianDateTime(); + + //TODO if //if(_BoardRepository.Exists(x=>x.Branch == command.Branch)) // operation.Failed("fail message") @@ -37,7 +66,7 @@ public class PetitionApplication : IPetitionApplication _petitionRepository.Create(petition); _petitionRepository.SaveChanges(); - + return operation.Succcedded(petition.id); } @@ -49,6 +78,33 @@ public class PetitionApplication : IPetitionApplication var petitionIssuanceDate = new DateTime?(); var notificationPetitionDate = new DateTime?(); + + if (!string.IsNullOrWhiteSpace(command.PetitionNo) || + !string.IsNullOrWhiteSpace(command.NotificationPetitionDate) || + !string.IsNullOrWhiteSpace(command.PetitionIssuanceDate) || + !string.IsNullOrWhiteSpace(command.TotalPenalty)) + { + if (string.IsNullOrWhiteSpace(command.PetitionNo)) + { + return operation.Failed("لطفا شماره دادنامه خودرا وارد کنید"); + } + + if (string.IsNullOrWhiteSpace(command.NotificationPetitionDate)) + { + return operation.Failed("لطفا تاریخ ابلاغ دادنامه را وارد کنید"); + } + + if (string.IsNullOrWhiteSpace(command.PetitionIssuanceDate)) + { + return operation.Failed("لطفا تاریخ صدور دادنامه را وارد کنید"); + } + + if (string.IsNullOrWhiteSpace(command.TotalPenalty)) + { + return operation.Failed("لطفا جمع نهایی دادنامه را وارد کنید"); + } + } + if (command.PetitionIssuanceDate != null) petitionIssuanceDate = command.PetitionIssuanceDate.ToGeorgianDateTime(); @@ -71,7 +127,7 @@ public class PetitionApplication : IPetitionApplication { return _petitionRepository.GetDetails(id); } - + public EditPetition GetDetails(long fileId, int boardTypeId) { return _petitionRepository.GetDetails(fileId, boardTypeId); diff --git a/CompanyManagment.EFCore/Repository/FileAlertRepository.cs b/CompanyManagment.EFCore/Repository/FileAlertRepository.cs index e77bc5ce..0f12c43c 100644 --- a/CompanyManagment.EFCore/Repository/FileAlertRepository.cs +++ b/CompanyManagment.EFCore/Repository/FileAlertRepository.cs @@ -65,21 +65,14 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe } #region Mahan - public async Task> GetFileAlerts() + public async Task> GetFileAlerts(FileAlertSearchModel searchModel) { var today = DateTime.Today; var fileAlertsVM = new List(); - var fileStates = await _context.FileStates.Include(x => x.FileTiming).Select(x => new - { - Id = x.id, - x.FileTiming_Id, - x.State, - x.Title, - x.FileTiming.Deadline - }).ToListAsync(); + - var files = await _context.Files.Where(x => x.Status == FileEnums.ACTIVE) + var filesQuery = _context.Files.Where(x => x.Status == FileEnums.ACTIVE) .Include(x => x.BoardsList).ThenInclude(x => x.ProceedingSessionsList) .Include(x => x.PetitionsList) .Where(file => @@ -97,14 +90,29 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate != new DateTime() && a.ProceedingSessionsList.Count == 0)) || (file.PetitionsList.Any(x => x.BoardType_Id == 2) == false) - ).ToListAsync(); + ); + if (!string.IsNullOrWhiteSpace(searchModel.ArchiveNo)) + { + var archiveNo = Convert.ToInt64(searchModel.ArchiveNo); + filesQuery = filesQuery.Where(x => x.ArchiveNo == archiveNo); + } + + if (!string.IsNullOrWhiteSpace(searchModel.FileClass)) + { + filesQuery = filesQuery.Where(x => x.FileClass == searchModel.FileClass); + } + + if (searchModel.UserId > 0) + { + filesQuery = filesQuery.Where(x => + (x.Client == 1 && x.Reqester == searchModel.UserId) || + (x.Client == 2 && x.Summoned == searchModel.UserId)); + } + + var files = await filesQuery.ToListAsync(); var fileWithState = files.Select(x => { - if (x.id == 74) - { - - } var state = GetFileState(x); return new { @@ -112,15 +120,43 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe State = state, StateDate = GetFileStateDate(x, state) }; - }).Where(x => x.StateDate > today).ToList(); + }).ToList(); + if (searchModel.FileState_Id>0) + { + fileWithState =fileWithState.Where(x => x.State == searchModel.FileState_Id).ToList(); + } + fileWithState = fileWithState.Where(x => x.StateDate < today).ToList(); + + var requesterIds = fileWithState.Select(x => x.File.Reqester); + var summonedIds = fileWithState.Select(x => x.File.Summoned); + + var requesterEmployees = await _context.Employees.Where(x => requesterIds.Contains(x.id)).ToListAsync(); + var summonedEmployers = await _context.Employers.Where(x => summonedIds.Contains(x.id)).ToListAsync(); + + var fileStates = await _context.FileStates.Include(x => x.FileTiming).Select(x => new + { + Id = x.id, + x.FileTiming_Id, + x.State, + x.Title, + x.FileTiming.Deadline + }).ToListAsync(); foreach (var file in fileWithState) { - if (file.File.FileAlertsList.Count == 0) + var clientFullName = file.File.Client == 1 + ? requesterEmployees.FirstOrDefault(x => x.id == file.File.Reqester)?.FullName + : summonedEmployers.FirstOrDefault(x => x.id == file.File.Summoned)?.FullName ?? "-"; + + var oppositePersonFullName = file.File.Client == 2 + ? requesterEmployees.FirstOrDefault(x => x.id == file.File.Reqester)?.FullName + : summonedEmployers.FirstOrDefault(x => x.id == file.File.Summoned)?.FullName ?? "-"; + + if (file.File.FileAlertsList == null || file.File.FileAlertsList.Count == 0) { - var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline); - var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate); + var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.FirstOrDefault(x => x.State == file.State).Deadline); + var workingDaysDifference = GetDaysWorkingDays(today, dueDate.Value); if (workingDaysDifference <= 1) { @@ -142,7 +178,14 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe Id = fileAlertEntity.id, FileState_Id = fileAlertEntity.FileState_Id, File_Id = fileAlertEntity.File_Id, - IsExpired = false + IsExpired = false, + File = new CreateFile() + { + FileClass = file.File.FileClass, + ArchiveNo = file.File.ArchiveNo, + ClientFullName = clientFullName, + OppositePersonFullName = oppositePersonFullName, + } }; if (workingDaysDifference < 0) fileAlert.IsExpired = true; @@ -153,8 +196,8 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe else if (file.File.FileAlertsList.Count == 1) { - var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline); - var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate); + var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.FirstOrDefault(x => x.State == file.State).Deadline); + var workingDaysDifference = GetDaysWorkingDays(today, dueDate.Value); if (workingDaysDifference <= 1) { @@ -174,7 +217,14 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe Id = fileAlertEntity.id, FileState_Id = fileAlertEntity.FileState_Id, File_Id = fileAlertEntity.File_Id, - IsExpired = false + IsExpired = false, + File = new CreateFile() + { + FileClass = file.File.FileClass, + ArchiveNo = file.File.ArchiveNo, + ClientFullName = clientFullName, + OppositePersonFullName = oppositePersonFullName, + } }; if (workingDaysDifference < 0) fileAlert.IsExpired = true; @@ -186,8 +236,8 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe else { var totalAdditionalDeadline = file.File.FileAlertsList.Sum(x => x.AdditionalDeadline); - var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline) + TimeSpan.FromDays(totalAdditionalDeadline); - var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate); + var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.FirstOrDefault(x => x.State == file.State).Deadline) + TimeSpan.FromDays(totalAdditionalDeadline); + var workingDaysDifference = GetDaysWorkingDays(today, dueDate.Value); ; if (workingDaysDifference <= 1) { @@ -208,7 +258,14 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe Id = fileAlertEntity.id, FileState_Id = fileAlertEntity.FileState_Id, File_Id = fileAlertEntity.File_Id, - IsExpired = false + IsExpired = false, + File = new CreateFile() + { + FileClass = file.File.FileClass, + ArchiveNo = file.File.ArchiveNo, + ClientFullName = clientFullName, + OppositePersonFullName = oppositePersonFullName, + } }; if (workingDaysDifference < 0) fileAlert.IsExpired = true; @@ -218,7 +275,6 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe } } - return fileAlertsVM; } public int GetFileState(File1 file) @@ -297,6 +353,30 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe return null; } } - #endregion + #endregion + public int GetDaysWorkingDays(DateTime startDate, DateTime endDate) + { + int sign = startDate <= endDate ? 1 : -1; + + DateTime from = startDate <= endDate ? startDate : endDate; + DateTime to = startDate <= endDate ? endDate : startDate; + + int totalDays = (to - from).Days + 1; + int fullWeeks = totalDays / 7; + int remainingDays = totalDays % 7; + + int fridays = fullWeeks; + + for (int i = 0; i < remainingDays; i++) + { + var currentDay = from.AddDays(i); + if (currentDay.DayOfWeek == DayOfWeek.Friday) + fridays++; + } + + var holidays = _context.HolidayItems.Count(x => x.Holidaydate >= from && x.Holidaydate <= to); + + return (totalDays - fridays - holidays) * sign; + } } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Pages/Company/FilePage/Alerts.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/FilePage/Alerts.cshtml.cs index 4a6bcbd6..37b83a8e 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/FilePage/Alerts.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/FilePage/Alerts.cshtml.cs @@ -35,11 +35,10 @@ public class AlertsModel : PageModel var files = _fileApplication.Search(new FileSearchModel { ArchiveNo = searchModel.ArchiveNo, FileClass = searchModel.FileClass, Status = FileEnums.ACTIVE }); - viewModels = _fileAlertApplication.GetFilesAlerts(files.Where(x=>x.Id == 74).ToList()); - viewModels =await _fileAlertApplication.GetFileAlerts(); + viewModels =await _fileAlertApplication.GetFileAlerts(searchModel); - if (searchModel.FileState_Id != 0) - viewModels = viewModels.Where(x => x.FileState_Id == searchModel.FileState_Id).ToList(); + //if (searchModel.FileState_Id != 0) + // viewModels = viewModels.Where(x => x.FileState_Id == searchModel.FileState_Id).ToList(); var filesId = viewModels.Select(y => y.File_Id).ToList(); @@ -76,7 +75,7 @@ public class AlertsModel : PageModel .Select(x => new Users { Id = x.Id, FullName = x.FullName }).ToList()); this.searchModel.FileStatesList = _fileStateApplication.Search(new FileStateSearchModel()).OrderBy(x => x.Id).ToList(); - } + } } public JsonResult OnPostSetAdditionalDeadline(EditFileAlert fileAlert)