From 60252ab03211efc7b67c872c35bd61ce6ebf3378 Mon Sep 17 00:00:00 2001 From: SamSys Date: Sat, 19 Jul 2025 18:43:05 +0400 Subject: [PATCH] Insurance bug fix - CreateTransction for rolllCall --- .../IInstitutionContractRepository.cs | 10 ++ .../IInstitutionContractApplication.cs | 8 + .../InstitutionContractApplication.cs | 8 + .../InsuranceListApplication.cs | 5 +- .../InstitutionContractRepository.cs | 145 ++++++++++++++++++ 5 files changed, 174 insertions(+), 2 deletions(-) diff --git a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs index c46dea77..9aa53393 100644 --- a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs +++ b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs @@ -33,4 +33,14 @@ public interface IInstitutionContractRepository : IRepository workshopViewModels); InstitutionContract InstitutionContractByEmployerId(long employerId); + + + /// + /// ایجاد سند مالی حضور غیاب + /// + /// + /// + /// + /// + void RollcallServiceCreateTransaction(); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs index 342ad846..57ac69f0 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs @@ -15,6 +15,14 @@ public interface IInstitutionContractApplication List Search(InstitutionContractSearchModel searchModel); List NewSearch(InstitutionContractSearchModel searchModel); + + /// + /// دریافت اطلاعات قزداد های مالی فعال + ///دارای کارگاه + /// جهت ست کردن سرویس ها از طریق اکسل + /// + /// + List GetInstitutionContractToSetServicesExcelImport(); List PrintAll(List id); InstitutionContractViewModel PrintOne(long id); OperationResult Active(long id); diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index b228581a..fd87513b 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -579,6 +579,14 @@ public class InstitutionContractApplication : IInstitutionContractApplication return _institutionContractRepository.NewSearch(searchModel); } + + public List GetInstitutionContractToSetServicesExcelImport() + { + var result = _institutionContractRepository.NewSearch(new InstitutionContractSearchModel()); + + return result.Where(x => x.IsActiveString == "true" && x.IsContractingPartyBlock !="true" && x.WorkshopCount != "0" && x.ContractStartGr <= DateTime.Now && x.ContractEndGr >= DateTime.Now).ToList(); + } + public string ExpCheckColor(DateTime now, DateTime ContractEndGr, DateTime endThisMontGr, string ContractAmount, string isActiveString) { string result = ""; diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index 251be235..08f07cf2 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -537,8 +537,9 @@ public class InsuranceListApplication : IInsuranceListApplication var employeeListData = employeeInsurancDataPreviusList .FirstOrDefault(e => e.EmployeeId == employee.EmployeeId); //مزیای عیر مشمول لیست قبل - var benefitsIncludedNonContinuous = - employeeListData != null ? employeeListData.BenefitsIncludedNonContinuous : 0; + //var benefitsIncludedNonContinuous = + // employeeListData != null ? employeeListData.BenefitsIncludedNonContinuous : 0; + double benefitsIncludedNonContinuous = 0; if (workshop.InsuranceCheckoutFamilyAllowance && employeeHasCheckout && !isManager) { diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index 7bce4b2f..e2fc888c 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -13,6 +13,7 @@ using CompanyManagment.App.Contracts.Employer; using CompanyManagment.App.Contracts.InstitutionContract; using CompanyManagment.App.Contracts.Workshop; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using PersianTools.Core; @@ -759,6 +760,150 @@ public class InstitutionContractRepository : RepositoryBase + /// ایجاد سند مالی حضور غیاب + /// + /// + /// + /// + /// + + #region RollcallServicCreateTransaction + + public void RollcallServiceCreateTransaction() + { + DateTime now = DateTime.Now; + var nowFa = now.ToFarsi(); + var endOfMonth = nowFa.FindeEndOfMonth(); + + DateTime endOfMonthGr = endOfMonth.ToGeorgianDateTime(); + + + #region FindeNextMonth 1th + var year = Convert.ToInt32(endOfMonth.Substring(0, 4)); + var month = Convert.ToInt32(endOfMonth.Substring(5, 2)); + var nextM = new PersianDateTime(year, month, 1).AddMonths(1); + var nextMonthGr = ($"{nextM}").ToGeorgianDateTime(); + var endOfCurrentMonth = (($"{endOfMonth.Substring(0, 8)}/01").FindeEndOfMonth()).ToGeorgianDateTime(); + #endregion + #region GetAvtiveContracts + var institutionContracts = _context.InstitutionContractSet.Where(x => x.IsActiveString == "true").Select(x => new InstitutionContractViewModel + { + Id = x.id, + ContractingPartyId = x.ContractingPartyId, + ContractingPartyName = x.ContractingPartyName, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + IsActiveString = x.IsActiveString, + SearchAmount = x.ContractAmount, + TypeOfContract = x.TypeOfContract + }).Where(x => + x.ContractStartGr < endOfMonthGr && x.ContractEndGr >= endOfMonthGr && x.SearchAmount > 0) + .ToList(); + #endregion + + #region GetFutureContracts + + List futureContracts = _context.InstitutionContractSet + .Where(x => x.IsActiveString == "true" && + x.ContractStartGr == nextMonthGr && x.ContractAmount > 0) + .Select(x => new InstitutionContractViewModel + { + Id = x.id, + ContractingPartyId = x.ContractingPartyId, + ContractingPartyName = x.ContractingPartyName, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + IsActiveString = x.IsActiveString, + TypeOfContract = x.TypeOfContract, + ExtensionNo = x.ExtensionNo, + }).ToList(); + + #endregion + + #region GetDectivedContractOnCurrentMonth + + if (futureContracts.Any()) + { + List futureContractIds = futureContracts.Select(x => x.ContractingPartyId).ToList(); + List deatcivedContract = _context.InstitutionContractSet + .Where(x => x.IsActiveString == "false" && futureContractIds.Contains(x.ContractingPartyId) && + x.ContractEndGr == endOfCurrentMonth && x.ContractAmount > 0) + .Select(x => new InstitutionContractViewModel + { + Id = x.id, + ContractingPartyId = x.ContractingPartyId, + ContractingPartyName = x.ContractingPartyName, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + IsActiveString = x.IsActiveString, + SearchAmount = x.ContractAmount, + TypeOfContract = x.TypeOfContract + }).ToList(); + + if (deatcivedContract.Any()) + institutionContracts.AddRange(deatcivedContract); + } + + List exceptionContractingPartyIds = [30520, 30739]; + institutionContracts = institutionContracts + .Where(x => !exceptionContractingPartyIds.Contains(x.ContractingPartyId)).ToList(); + int counter = 0; + var rollcallServiceList = + _context.RollCallServices.Where(x => x.IsActiveString == "true").ToList(); + var activeStatusDate = new DateTime(2121, 03, 21); + + foreach (var item in institutionContracts) + { + + //var isblock = contractingParty.IsBlock == "true" ? true : false; + + var employers = _context.Employers.Where(x => x.ContractingPartyId == item.ContractingPartyId).Select(x => x.id); + var workshops = _context.WorkshopEmployers.Where(x => employers.Contains(x.EmployerId)).Select(x => x.WorkshopId).Distinct().ToList(); + + + var srvices = + rollcallServiceList.Where(x => workshops.Contains(x.WorkshopId)).ToList(); + if (rollcallServiceList.Count > 0) + { + foreach (var rollCallService in srvices) + { + var spaning = (int)(endOfMonthGr - rollCallService.StartService).TotalDays + 1; + int monthCounter = spaning > 31 ? 2 : 1; + + + + var employees = + _context.RollCallEmployees.Where(x => x.WorkshopId == rollCallService.WorkshopId).Select(x=>x.id); + + var employeeCount = _context.RollCallEmployeesStatus.Where(x => employees.Contains(x.RollCallEmployeeId)) + .Count(x => x.EndDate.Date == activeStatusDate.Date); + + if (employeeCount > 0) + { + counter++; + Console.WriteLine(" number : " + counter + " - " + rollCallService.StartService.ToFarsi() + " WorkshopId : " + rollCallService.WorkshopId + " monthCount : " + monthCounter + " employeeCount : " + employeeCount); + } + + } + } + + } + + #endregion + } + + #endregion + + #region CustomViewModels