From 0ac4389ec542f70c1c1c73b74ceb8e25dd4b9d4a Mon Sep 17 00:00:00 2001 From: SamSys Date: Fri, 10 Jan 2025 04:34:42 +0330 Subject: [PATCH] add new metod to tools for family allowance --- 0_Framework/Application/Tools.cs | 136 ++++++++++++++++++ .../Ticket/CreateTicket.cs | 1 + .../TicketApplication.cs | 2 +- .../Repository/TicketRepository.cs | 128 +++++++++-------- .../Repository/YearlySalaryRepository.cs | 11 +- .../Pages/Company/Ticket/Index.cshtml.cs | 18 +-- 6 files changed, 223 insertions(+), 73 deletions(-) diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index 4e8636fa..b7afff46 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -32,6 +32,142 @@ public static class Tools public static string[] DayNames = { "شنبه", "یکشنبه", "دو شنبه", "سه شنبه", "چهار شنبه", "پنج شنبه", "جمعه" }; public static string[] DayNamesG = { "یکشنبه", "دو شنبه", "سه شنبه", "چهار شنبه", "پنج شنبه", "جمعه", "شنبه" }; + public static (int yearCount, int monthCount, int dayCount) GetOld(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)); + int endDay = Convert.ToInt32(endFa.Substring(8, 2)); + var end = new PersianDateTime(endYear, endMonth, endDay); + int months = 0; + int days = 0; + int years = 0; + + var firstYearCounter = start.AddYears(1); + + if (firstYearCounter > end) + { + start = start.AddYears(-1); + //if (start > end) + //{ + // start = start.AddMonths(-1); + //} + + var endMonthCounter = new PersianDateTime(end.Year, end.Month, start.Day); + + for (var monthCounter = start; monthCounter <= end; monthCounter = monthCounter.AddMonths(1)) + { + if (monthCounter <= end) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("month : " + monthCounter); + months++; + } + + if (monthCounter.Month == end.Month) + { + var firstDayCounter = monthCounter.AddDays(1); + for (var dayCounter = firstDayCounter; dayCounter <= end; dayCounter = dayCounter.AddDays(1)) + { + if (dayCounter <= end) + { + days++; + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("day : " + dayCounter); + + } + + } + months = months > 0 ? months - 1 : 0; + break; + } + + + + } + + + } + else + { + for (var yearCouner = firstYearCounter; yearCouner <= end; yearCouner = yearCouner.AddYears(1)) + { + + if (yearCouner.Year <= end.Year) + { + years++; + Console.ForegroundColor = ConsoleColor.DarkMagenta; + Console.WriteLine("year : " + yearCouner); + } + + + if (yearCouner.Year == end.Year) + { + + + var endMonthCounter = new PersianDateTime(end.Year, end.Month, yearCouner.Day); + + if (yearCouner.Day <= end.Day) + { + endMonthCounter = end; + + } + for (var monthCounter = yearCouner; monthCounter <= endMonthCounter; monthCounter = monthCounter.AddMonths(1)) + { + if (monthCounter < end) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("month : " + monthCounter); + months++; + } + + if (monthCounter.Month == end.Month) + { + var firstDayCounter = monthCounter.AddDays(1); + if (yearCouner.Day > end.Day) + { + + firstDayCounter = firstDayCounter.AddMonths(-1); + } + for (var dayCounter = firstDayCounter; dayCounter <= end; dayCounter = dayCounter.AddDays(1)) + { + if (dayCounter <= end) + { + days++; + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("day : " + dayCounter); + + } + + } + + months = months > 0 ? months - 1 : 0; + break; + } + + + } + + + } + + + } + } + + + Console.ResetColor(); + Console.WriteLine($"old: [{years} year] ، [{months} month] ، [{days} day]"); + return (years,months,days); + } public static string ToFarsi(this DateTime? date) { diff --git a/AccountManagement.Application.Contracts/Ticket/CreateTicket.cs b/AccountManagement.Application.Contracts/Ticket/CreateTicket.cs index ce17caec..e9d97f61 100644 --- a/AccountManagement.Application.Contracts/Ticket/CreateTicket.cs +++ b/AccountManagement.Application.Contracts/Ticket/CreateTicket.cs @@ -9,6 +9,7 @@ public class CreateTicket public string Title { get; set; } public string Description { get; set; } public long SenderId { get; set; } + public long SubAccountId { get; set; } public string ContractingPartyName { get; set; } public string TicketType { get; set; } public List UploadedMediaIds { get; set; } diff --git a/AccountManagement.Application/TicketApplication.cs b/AccountManagement.Application/TicketApplication.cs index 79a2b83d..95c88b1f 100644 --- a/AccountManagement.Application/TicketApplication.cs +++ b/AccountManagement.Application/TicketApplication.cs @@ -68,7 +68,7 @@ public class TicketApplication : ITicketApplication var ticketNumber = (_ticketRepository.GetLastTicketNumber() + 1).ToString("D5"); var ticket = new Ticket(command.Title, command.Description, command.SenderId, command.ContractingPartyName, - command.TicketType, command.WorkshopId, ticketNumber); + command.TicketType, command.WorkshopId, ticketNumber, command.SubAccountId); _ticketRepository.Create(ticket); _ticketRepository.SaveChanges(); diff --git a/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs index 62a209ad..05361e2d 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs @@ -112,82 +112,86 @@ public class TicketRepository : RepositoryBase, ITicketRepository return query.Skip(searchModel.PageIndex).Take(30).ToList(); } - public List GetTicketsForClients(TicketSearchModel searchModel) - { + public List GetTicketsForClients(TicketSearchModel searchModel) + { - var accountId = _authHelper.CurrentAccountId(); + var accountInfo = _authHelper.CurrentAccountInfo(); - var workshopSlug = _authHelper.GetWorkshopSlug(); - var workshopId = _passwordHasher.SlugDecrypt(workshopSlug); - IQueryable query; - if (workshopId > 0) - { - query = _accountContext.Tickets.Where(x => x.SenderId == accountId && x.WorkshopId == workshopId); - } - else - { - query = _accountContext.Tickets.Where(x => x.SenderId == accountId); - } - if (!string.IsNullOrWhiteSpace(searchModel.ContractingPartyName)) - { - query = query.Where(x => x.ContractingPartyName.Contains(searchModel.ContractingPartyName)); - } + var workshopSlug = _authHelper.GetWorkshopSlug(); + var workshopId = _passwordHasher.SlugDecrypt(workshopSlug); + IQueryable query; + if (workshopId > 0) + { + query = _accountContext.Tickets.Where(x => x.SenderId == accountInfo.Id && x.WorkshopId == workshopId); + } + else + { + query = _accountContext.Tickets.Where(x => x.SenderId == accountInfo.Id); + } - if (!string.IsNullOrWhiteSpace(searchModel.Status)) - { - query = query.Where(x => x.Status == searchModel.Status); - } + if (accountInfo.SubAccountId > 0) + { + query = query.Where(x => x.SubAccountSenderId == accountInfo.SubAccountId); + } + if (!string.IsNullOrWhiteSpace(searchModel.ContractingPartyName)) + { + query = query.Where(x => x.ContractingPartyName.Contains(searchModel.ContractingPartyName)); + } - if (!(string.IsNullOrWhiteSpace(searchModel.StartDate) && string.IsNullOrWhiteSpace(searchModel.EndDate))) - { - if (string.IsNullOrWhiteSpace(searchModel.OneDay)) - { - var startDate = searchModel.StartDate.ToGeorgianDateTime(); - var endDate = searchModel.EndDate.ToGeorgianDateTime(); - query = query.Where(x => startDate < x.CreationDate && endDate > x.CreationDate); - } + if (!string.IsNullOrWhiteSpace(searchModel.Status)) + { + query = query.Where(x => x.Status == searchModel.Status); + } - } + if (!(string.IsNullOrWhiteSpace(searchModel.StartDate) && string.IsNullOrWhiteSpace(searchModel.EndDate))) + { + if (string.IsNullOrWhiteSpace(searchModel.OneDay)) + { + var startDate = searchModel.StartDate.ToGeorgianDateTime(); + var endDate = searchModel.EndDate.ToGeorgianDateTime(); + query = query.Where(x => startDate < x.CreationDate && endDate > x.CreationDate); + } - if (!string.IsNullOrWhiteSpace(searchModel.GeneralSearch)) - { - query = query.Where(x => x.Title.Contains(searchModel.GeneralSearch)); - } + } - if (!string.IsNullOrWhiteSpace(searchModel.Status)) - { - query = query.Where(x => x.Status == searchModel.Status); - } + if (!string.IsNullOrWhiteSpace(searchModel.GeneralSearch)) + { + query = query.Where(x => x.Title.Contains(searchModel.GeneralSearch)); + } - if (!string.IsNullOrWhiteSpace(searchModel.OneDay)) - { - var day = searchModel.OneDay.ToGeorgianDateTime(); - query = query.Where(x => x.CreationDate.Date == day.Date); - } + if (!string.IsNullOrWhiteSpace(searchModel.Status)) + { + query = query.Where(x => x.Status == searchModel.Status); + } + + if (!string.IsNullOrWhiteSpace(searchModel.OneDay)) + { + var day = searchModel.OneDay.ToGeorgianDateTime(); + query = query.Where(x => x.CreationDate.Date == day.Date); + } - var res = query.OrderBy(x => x.Status.Trim() == "بسته شده").ThenByDescending(x => x.CreationDate).Select(x => new TicketViewModel() - { - Description = x.Description, - SenderId = x.SenderId, - ContractingPartyName = x.ContractingPartyName, - Id = x.id, - Title = x.Title, - TicketType = x.TicketType, - Status = x.Status, - CreationDateTimeGr = x.CreationDate, - CreationDateTime = x.CreationDate.ToFarsi(), - TicketNumber = $"TKC_{x.TicketNumber}", - WorkshopName = _workshopRepository.Get(x.WorkshopId).WorkshopFullName + var res = query.OrderBy(x => x.Status.Trim() == "بسته شده").ThenByDescending(x => x.CreationDate).Select(x => new TicketViewModel() + { + Description = x.Description, + SenderId = x.SenderId, + ContractingPartyName = x.ContractingPartyName, + Id = x.id, + Title = x.Title, + TicketType = x.TicketType, + Status = x.Status, + CreationDateTimeGr = x.CreationDate, + CreationDateTime = x.CreationDate.ToFarsi(), + TicketNumber = $"TKC_{x.TicketNumber}", + WorkshopName = _workshopRepository.Get(x.WorkshopId).WorkshopFullName - }); + }); - return res.Skip(searchModel.PageIndex).Take(30).ToList(); - } + return res.Skip(searchModel.PageIndex).Take(30).ToList(); + } - - public void CreateAdminResponse(AdminResponse command) + public void CreateAdminResponse(AdminResponse command) { _accountContext.Add(command); } diff --git a/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs b/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs index 1124b47b..d19cffc3 100644 --- a/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs +++ b/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs @@ -942,11 +942,18 @@ public class YearlySalaryRepository : RepositoryBase, IYearl if (item.DateOfBirth < EndCantract) { Age = (EndCantract - item.DateOfBirth); - var ageUp18 = (zeroTime + Age).Year - 1; var res = ageUp18; - if (ageUp18 <= 18 && insurancHistoey >= 720) + var ageUp18 = (zeroTime + Age).Year - 1; + + var checkOld = Tools.GetOld(item.DateOfBirth, EndCantract); + + if (checkOld.yearCount < 18 && insurancHistoey >= 720) { childeNumber += 1; } + else if (checkOld.yearCount > 18 && checkOld.monthCount == 0) + { + + } } } diff --git a/ServiceHost/Areas/Client/Pages/Company/Ticket/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/Ticket/Index.cshtml.cs index 462dcba0..acb0e41c 100644 --- a/ServiceHost/Areas/Client/Pages/Company/Ticket/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/Ticket/Index.cshtml.cs @@ -98,18 +98,20 @@ namespace ServiceHost.Areas.Client.Pages.Company.Ticket public IActionResult OnPostSaveTicket(CreateTicket command) { + var accountInfo = _authHelper.CurrentAccountInfo(); command.SenderId = _authHelper.CurrentAccountId(); - command.ContractingPartyName = _authHelper.CurrentAccountInfo().Fullname; + command.ContractingPartyName = accountInfo.Fullname; command.WorkshopId = _passwordHasher.SlugDecrypt(User.FindFirstValue("WorkshopSlug")); command.Description = command.Description?.Replace("\n", "
"); - + command.SubAccountId = accountInfo.SubAccountId; - var result = _ticketApplication.CreateTicket(command); - return new JsonResult(new - { - isSuccedd = result.IsSuccedded, - message = result.Message - }); + + var result = _ticketApplication.CreateTicket(command); + return new JsonResult(new + { + isSuccedd = result.IsSuccedded, + message = result.Message + }); } public IActionResult OnPostUploadFile(IFormFile media)