diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index ef602951..5a852773 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -52,81 +52,81 @@ public static class Tools /// /// /// - public static (int countWorkingDays,DateTime startWork,DateTime endWork,bool hasStartWorkInMonth,bool hasLeftWorkInMonth) GetEmployeeInsuranceWorkingDays(DateTime startWork,DateTime? leftWork,DateTime startDate, - DateTime endDate,long employeeId) + public static (int countWorkingDays, DateTime startWork, DateTime endWork, bool hasStartWorkInMonth, bool hasLeftWorkInMonth) GetEmployeeInsuranceWorkingDays(DateTime startWork, DateTime? leftWork, DateTime startDate, + DateTime endDate, long employeeId) { - DateTime start = startDate; + DateTime start = startDate; DateTime end = endDate; bool startWorkInMonth = false; bool endWorkInMonth = false; - + //اگر شروع بکار پرسنل در ماه مشخص شده لیست بیمه بود if (startWork >= startDate) { - start = startWork; - startWorkInMonth = true; + start = startWork; + startWorkInMonth = true; } - if(leftWork == null) + if (leftWork == null) leftWork = DateTime.MinValue; //اگر ترک کار پرسنل در ماه مشخص شده لیست بیمه بود if (leftWork != DateTime.MinValue && leftWork.Value < endDate) { - end = leftWork.Value; + end = leftWork.Value; endWorkInMonth = true; } - int countDays = (int)(end - start).TotalDays +1; + int countDays = (int)(end - start).TotalDays + 1; //روزهای کارکرد پرسنل با آی دی های زیر دستی تعریف شد switch (employeeId) { - //case 3812://ثابت- کسری حاجی پور - // countWorkingDays = 15; - // break; - case 40463://ثابت - countDays = 10; - break; - case 40469://ثابت - countDays = 7; - break; - //case 9950://ثابت - // countDays = 15; - //break; - case 9640://ثابت - countDays = 15; - break; - case 40998://ثابت - countDays = 15; - break; - case 6219://ثابت - countDays = 15; - break; - //case 7897://ثابت - // countWorkingDays = 15; + //case 3812://ثابت- کسری حاجی پور + // countWorkingDays = 15; + // break; + case 40463://ثابت + countDays = 10; + break; + case 40469://ثابت + countDays = 7; + break; + //case 9950://ثابت + // countDays = 15; + //break; + case 9640://ثابت + countDays = 15; + break; + case 40998://ثابت + countDays = 15; + break; + case 6219://ثابت + countDays = 15; + break; + //case 7897://ثابت + // countWorkingDays = 15; } - return (countDays,start,end,startWorkInMonth,endWorkInMonth); + return (countDays, start, end, startWorkInMonth, endWorkInMonth); } - /// - /// محاسبه سن - /// - /// - /// - /// - public static (int yearCount, int monthCount, int dayCount) GetAge(DateTime startDate, DateTime endDate) + /// + /// محاسبه سن + /// + /// + /// + /// + public static (int yearCount, int monthCount, int dayCount) GetAge(DateTime startDate, DateTime endDate) { - + var startFa = startDate.ToFarsi(); int startYear = Convert.ToInt32(startFa.Substring(0, 4)); int startMonth = Convert.ToInt32(startFa.Substring(5, 2)); int startDay = Convert.ToInt32(startFa.Substring(8, 2)); var start = new PersianDateTime(startYear, startMonth, startDay); - + var endFa = endDate.ToFarsi(); int endYear = Convert.ToInt32(endFa.Substring(0, 4)); int endMonth = Convert.ToInt32(endFa.Substring(5, 2)); @@ -141,7 +141,7 @@ public static class Tools if (firstYearCounter > end) { start = start.AddYears(-1); - + var endMonthCounter = new PersianDateTime(end.Year, end.Month, start.Day); for (var monthCounter = start; monthCounter <= end; monthCounter = monthCounter.AddMonths(1)) @@ -193,7 +193,7 @@ public static class Tools if (yearCouner.Year == end.Year) { - var endMonthCounter = new PersianDateTime(end.Year, end.Month, (yearCouner.Day > end.Day ? end.Day : yearCouner.Day)); + var endMonthCounter = new PersianDateTime(end.Year, end.Month, (yearCouner.Day > end.Day ? end.Day : yearCouner.Day)); if (yearCouner.Day <= end.Day) { @@ -244,7 +244,7 @@ public static class Tools Console.ResetColor(); Console.WriteLine($"old: [{years} year] ، [{months} month] ، [{days} day]"); - return (years,months,days); + return (years, months, days); } public static string ToFarsi(this DateTime? date) @@ -397,9 +397,9 @@ public static class Tools public static DateTime ToGeorgianDateTime(this string persianDate) { - persianDate = persianDate.ToEnglishNumber(); try { + persianDate = persianDate.ToEnglishNumber(); var year = Convert.ToInt32(persianDate.Substring(0, 4)); var month = Convert.ToInt32(persianDate.Substring(5, 2)); var day = Convert.ToInt32(persianDate.Substring(8, 2)); @@ -1267,16 +1267,16 @@ public static class Tools var part5 = parts[5].Substring(0, 2); - try + try { PersianCalendar pc = new PersianCalendar(); - dateTime = pc.ToDateTime(int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]), int.Parse(parts[4]), int.Parse(part5), 0, 0, 0); - + dateTime = pc.ToDateTime(int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]), int.Parse(parts[4]), int.Parse(part5), 0, 0, 0); + } catch (Exception e) { - + } } @@ -1384,8 +1384,8 @@ public static class Tools } public static DateTime FindFirstDayOfMonthGr(this DateTime date) { - var pc = new PersianCalendar(); - return ($"{pc.GetYear(date)}/{pc.GetMonth(date):00}/01").ToGeorgianDateTime(); + var pc = new PersianCalendar(); + return ($"{pc.GetYear(date)}/{pc.GetMonth(date):00}/01").ToGeorgianDateTime(); } #region Mahan @@ -1588,19 +1588,19 @@ public static class Tools public static TimeOnly CalculateOffset(ICollection shiftDetailsRegularShifts) { - if (!shiftDetailsRegularShifts.Any()) - { - return TimeOnly.MinValue; - } - var date = new DateOnly(); - var firstStartShift = new DateTime(date, shiftDetailsRegularShifts.MinBy(x => x.Placement).StartTime); - var lastEndShift = new DateTime(date, shiftDetailsRegularShifts.MaxBy(x => x.Placement).EndTime); - if (lastEndShift > firstStartShift) - firstStartShift = firstStartShift.AddDays(1); - var offSet = (firstStartShift - lastEndShift).Divide(2); - return TimeOnly.FromDateTime(lastEndShift.Add(offSet)); + if (!shiftDetailsRegularShifts.Any()) + { + return TimeOnly.MinValue; + } + var date = new DateOnly(); + var firstStartShift = new DateTime(date, shiftDetailsRegularShifts.MinBy(x => x.Placement).StartTime); + var lastEndShift = new DateTime(date, shiftDetailsRegularShifts.MaxBy(x => x.Placement).EndTime); + if (lastEndShift > firstStartShift) + firstStartShift = firstStartShift.AddDays(1); + var offSet = (firstStartShift - lastEndShift).Divide(2); + return TimeOnly.FromDateTime(lastEndShift.Add(offSet)); } - public static DateTime GetNextDayOfWeek(this DateTime date, DayOfWeek dayOfWeek) + public static DateTime GetNextDayOfWeek(this DateTime date, DayOfWeek dayOfWeek) { int numberOfNextDayOfWeek = ((int)dayOfWeek - (int)date.DayOfWeek + 7) % 7; return date.AddDays(numberOfNextDayOfWeek == 0 ? 7 : numberOfNextDayOfWeek); @@ -1772,75 +1772,75 @@ public static class Tools public static string ToFarsiHoursAndMinutes(int hours, int minutes, string emptyValue = "") { - string message = emptyValue; - if (hours > 0 && minutes > 0) - { + string message = emptyValue; + if (hours > 0 && minutes > 0) + { - message = hours + " " + "ساعت و" + " " + minutes + " " + "دقیقه"; - } - else if (hours > 0 && minutes == 0) - { + message = hours + " " + "ساعت و" + " " + minutes + " " + "دقیقه"; + } + else if (hours > 0 && minutes == 0) + { - message = hours + " " + "ساعت "; - } - else if (hours == 0 && minutes > 0) - { + message = hours + " " + "ساعت "; + } + else if (hours == 0 && minutes > 0) + { - message = minutes + " " + "دقیقه"; - } + message = minutes + " " + "دقیقه"; + } - return message; + return message; } - public static string ToFarsiHoursAndMinutes(this TimeSpan timeSpan, string emptyValue = "") + public static string ToFarsiHoursAndMinutes(this TimeSpan timeSpan, string emptyValue = "") { - var hours = (int)timeSpan.TotalHours; - var minutes = timeSpan.Minutes; - string message = emptyValue; - if (hours > 0 && minutes > 0) - { + var hours = (int)timeSpan.TotalHours; + var minutes = timeSpan.Minutes; + string message = emptyValue; + if (hours > 0 && minutes > 0) + { - message = hours + " " + "ساعت و" + " " + minutes + " " + "دقیقه"; - } - else if (hours > 0 && minutes == 0) - { + message = hours + " " + "ساعت و" + " " + minutes + " " + "دقیقه"; + } + else if (hours > 0 && minutes == 0) + { - message = hours + " " + "ساعت "; - } - else if (hours == 0 && minutes > 0) - { + message = hours + " " + "ساعت "; + } + else if (hours == 0 && minutes > 0) + { - message = minutes + " " + "دقیقه"; - } + message = minutes + " " + "دقیقه"; + } - return message; + return message; } - public static string ToFarsiDaysAndHoursAndMinutes(this TimeSpan timeSpan, string emptyValue = "") - { - var hours = (int)timeSpan.TotalHours; - var minutes = timeSpan.Minutes; - var days = hours / 24; - hours = hours % 24; - string message = ""; + public static string ToFarsiDaysAndHoursAndMinutes(this TimeSpan timeSpan, string emptyValue = "") + { + var hours = (int)timeSpan.TotalHours; + var minutes = timeSpan.Minutes; + var days = hours / 24; + hours = hours % 24; + string message = ""; - if (days > 0) - message += days + " " + "روز"; - if (hours > 0) - if (message == "") - message += hours + " " + "ساعت"; - else - message += " و " + hours + " " + "ساعت"; - if (minutes > 0) - if (message == "") - message += minutes + " " + "دقیقه"; - else - message += " و " + minutes + " " + "دقیقه"; + if (days > 0) + message += days + " " + "روز"; + if (hours > 0) + if (message == "") + message += hours + " " + "ساعت"; + else + message += " و " + hours + " " + "ساعت"; + if (minutes > 0) + if (message == "") + message += minutes + " " + "دقیقه"; + else + message += " و " + minutes + " " + "دقیقه"; - if (message == "") - message = emptyValue; - return message; - } + if (message == "") + message = emptyValue; + return message; + } - public static bool ArePropertiesEqual(this T obj1, T obj2) + public static bool ArePropertiesEqual(this T obj1, T obj2) { // If either object is null, they can't be equal if (obj1 == null || obj2 == null) diff --git a/Company.Domain/FileAlert/IFileAlertRepository.cs b/Company.Domain/FileAlert/IFileAlertRepository.cs index af277e1a..589519b7 100644 --- a/Company.Domain/FileAlert/IFileAlertRepository.cs +++ b/Company.Domain/FileAlert/IFileAlertRepository.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework_b.Domain; using CompanyManagment.App.Contracts.FileAlert; @@ -10,4 +11,5 @@ public interface IFileAlertRepository : IRepository FileAlertViewModel GetDetails(long id); void Remove(long id); List Search(FileAlertSearchModel searchModel); + Task> GetFileAlerts(); } \ No newline at end of file diff --git a/CompanyManagment.Application/FileAlertApplication.cs b/CompanyManagment.Application/FileAlertApplication.cs index 0e3c2e5d..55683dc8 100644 --- a/CompanyManagment.Application/FileAlertApplication.cs +++ b/CompanyManagment.Application/FileAlertApplication.cs @@ -81,15 +81,17 @@ public class FileAlertApplication : IFileAlertApplication var fileStates = _fileStateApplication.Search(new FileStateSearchModel()); var fileAlertsVM = new List(); +#if DEBUG + files = files.Take(5).ToList(); +#endif foreach (var item in files) { var file = _fileApplication.GetFileDetails(item); - Console.WriteLine(file.Id); file.State = _fileStateApplication.GetFileState(file); if (file.State == 0) continue; - + // file.StateDate = _fileStateApplication.GetFileStateDate(file); var today = DateTime.Now.Date; diff --git a/CompanyManagment.EFCore/Repository/FileAlertRepository.cs b/CompanyManagment.EFCore/Repository/FileAlertRepository.cs index 826ef420..fc9e2655 100644 --- a/CompanyManagment.EFCore/Repository/FileAlertRepository.cs +++ b/CompanyManagment.EFCore/Repository/FileAlertRepository.cs @@ -1,8 +1,15 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; +using _0_Framework.Application; using _0_Framework_b.InfraStructure; +using Company.Domain.File1; using Company.Domain.FileAlert; +using CompanyManagment.App.Contracts.File1; using CompanyManagment.App.Contracts.FileAlert; +using CompanyManagment.App.Contracts.FileState; +using Microsoft.EntityFrameworkCore; namespace CompanyManagment.EFCore.Repository; @@ -44,16 +51,149 @@ public class FileAlertRepository : RepositoryBase, IFileAlertRe }); //TODO if - if(searchModel.FileState_Id != 0) + if (searchModel.FileState_Id != 0) { query = query.Where(x => x.FileState_Id == searchModel.FileState_Id); } - - if(searchModel.File_Id != 0) + + if (searchModel.File_Id != 0) { query = query.Where(x => x.File_Id == searchModel.File_Id); } return query.OrderByDescending(x => x.Id).ToList(); } + + public async Task> GetFileAlerts() + { + var today = DateTime.Today; + + var fileStates = _context.FileStates.Include(x => x.FileTiming).Select(x => new + { + Id = x.id, + x.FileTiming_Id, + x.State, + x.Title, + x.FileTiming.Deadline + }); + var files = await _context.Files.Where(x => x.Status == FileEnums.ACTIVE) + .Include(x => x.BoardsList).ThenInclude(x => x.ProceedingSessionsList) + .Include(x => x.PetitionsList) + .Where(file => + file.FileClass == null + || file.HasMandate != 2 + || (file.BoardsList.Any(a => a.BoardType_Id == 1 && a.DisputeResolutionPetitionDate == new DateTime())) + || (file.BoardsList.Any(a => + a.BoardType_Id == 1 && a.DisputeResolutionPetitionDate != new DateTime() && + a.ProceedingSessionsList.Count == 0)) + || (file.BoardsList.Any(a => a.BoardType_Id == 1 && a.ProceedingSessionsList.Count != 0) && + (file.PetitionsList.Any(x => x.BoardType_Id == 1) == false)) + || (file.PetitionsList.Any(x => x.BoardType_Id == 1) && file.BoardsList.Any(a => + a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate == new DateTime())) + || (file.BoardsList.Any(a => + a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate != new DateTime() && + a.ProceedingSessionsList.Count == 0)) + || (file.PetitionsList.Any(x => x.BoardType_Id == 2) == false) + ).ToListAsync(); + + var fileWithState = files.Select(x => + { + var state = GetFileState(x); + return new + { + File = x, + State = state, + StateDate = GetFileStateDate(x, state) + }; + }).Where(x => x.StateDate > today); + + + var res = fileWithState.Select(x => + { + var file = x.File; + if (x.File.FileAlertsList.Any() == false) + { + var dueDate = x.StateDate + TimeSpan.FromDays(fileStates.FirstOrDefault(f => f.State == x.State)?.Deadline ?? 0); + var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate); + } + + }); + + } + public int GetFileState(File1 file) + { + //if (file.FileClass == null || (file.FileClass != null && file.DiagnosisBoard.DisputeResolutionPetitionDate == null)) + if (file.FileClass == null) + return FileStateEnums.FILE_CLASS_NOT_REGISTERED; + + //if (file.HasMandate != 2 || (file.HasMandate == 2 && file.DiagnosisBoard.DisputeResolutionPetitionDate == null)) + if (file.HasMandate != 2) + return FileStateEnums.MANDATE_NOT_REGISTERED; + + if ((file.BoardsList.Any(a => a.BoardType_Id == 1 && a.DisputeResolutionPetitionDate == new DateTime()))) + return FileStateEnums.NO_PETITION_DATE_ISSUED; + + if ((file.BoardsList.Any(a => + a.BoardType_Id == 1 && a.DisputeResolutionPetitionDate != new DateTime() && + a.ProceedingSessionsList.Count == 0))) + return FileStateEnums.NO_DIAGNOSIS_INVITATION_ISSUED; + + if ((file.BoardsList.Any(a => a.BoardType_Id == 1 && a.ProceedingSessionsList.Count != 0) && + (file.PetitionsList.Any(x => x.BoardType_Id == 1) == false))) + return FileStateEnums.NO_DIAGNOSIS_PETITION_ISSUED; + + if ((file.PetitionsList.Any(x => x.BoardType_Id == 1) && file.BoardsList.Any(a => + a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate == new DateTime()))) + return FileStateEnums.PROTEST_NOT_REGISTERED; + + if ((file.BoardsList.Any(a => + a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate != new DateTime() && + a.ProceedingSessionsList.Count == 0))) + return FileStateEnums.NO_DISPUTE_INVITATION_ISSUED; + + if ((file.PetitionsList.Any(x => x.BoardType_Id == 2) == false)) + return FileStateEnums.NO_DISPUTE_PETITION_ISSUED; + + return 0; + } + public DateTime? GetFileStateDate(File1 file, int state) + { + var diagnosisBoard = file.BoardsList.FirstOrDefault(x => x.BoardType_Id == 1); + var diagnosisPetition = file.PetitionsList.FirstOrDefault(x => x.BoardType_Id == 1); + var disputeResolutionBoard = file.BoardsList.FirstOrDefault(x => x.BoardType_Id == 2); + switch (state) + { + case FileStateEnums.FILE_CLASS_NOT_REGISTERED: + return file.ClientVisitDate; + + case FileStateEnums.MANDATE_NOT_REGISTERED: + return file.ClientVisitDate; + + case FileStateEnums.NO_PETITION_DATE_ISSUED: + return file.ClientVisitDate; + + case FileStateEnums.NO_DIAGNOSIS_INVITATION_ISSUED: + return diagnosisBoard?.DisputeResolutionPetitionDate; + + case FileStateEnums.NO_DIAGNOSIS_PETITION_ISSUED: + var lastDiagnosisPs = file.BoardsList.First(x => x.BoardType_Id == 1).ProceedingSessionsList.Last(); + + return lastDiagnosisPs.Date; + + case FileStateEnums.PROTEST_NOT_REGISTERED: + return diagnosisPetition? + .NotificationPetitionDate; + + case FileStateEnums.NO_DISPUTE_INVITATION_ISSUED: + return disputeResolutionBoard?.DisputeResolutionPetitionDate; + + case FileStateEnums.NO_DISPUTE_PETITION_ISSUED: + var lastDisputeResolutionPs = file.BoardsList.First(x => x.BoardType_Id == 2).ProceedingSessionsList.Last(); + return lastDisputeResolutionPs.Date; + + default: + return null; + } + } + } \ No newline at end of file