From be282fa548cc37c12ce7ecd6f4686828b82b44a5 Mon Sep 17 00:00:00 2001 From: MahanCh Date: Thu, 31 Jul 2025 12:22:01 +0330 Subject: [PATCH] change get list in InstitutionContractApplication.cs --- .../IInstitutionContractRepository.cs | 3 + .../IInstitutionContractApplication.cs | 18 +- .../InstitutionContractApplication.cs | 4 +- .../InstitutionContractRepository.cs | 492 +++++++++--------- .../institutionContractController.cs | 2 +- 5 files changed, 279 insertions(+), 240 deletions(-) diff --git a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs index 9aa53393..16433c35 100644 --- a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs +++ b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using _0_Framework.Application; using _0_Framework.Domain; using CompanyManagment.App.Contracts.InstitutionContract; using CompanyManagment.App.Contracts.Workshop; @@ -43,4 +44,6 @@ public interface IInstitutionContractRepository : IRepository /// void RollcallServiceCreateTransaction(); + + Task GetList(InstitutionContractListSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs index f5a8ac1d..fecb851a 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs @@ -51,7 +51,7 @@ public interface IInstitutionContractApplication /// /// /// - Task>> GetList + Task GetList (InstitutionContractListSearchModel searchModel); #endregion @@ -109,6 +109,22 @@ public class InstitutionContractListSearchModel /// لیست قرارداد های موسسه /// public class GetInstitutionContractListViewModel +{ + /// + /// بدهی کل + /// + public double TotalDebt { get; set; } + + /// + /// مبلغ قرارداد ها + /// + public double TotalAmount { get; set; } + + public List Items { get; set; } + +} + +public class GetInstitutionContractListItemsViewModel { /// /// آیدی diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index cb4db42a..f78eee5e 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -869,9 +869,9 @@ public class InstitutionContractApplication : IInstitutionContractApplication return _institutionContractRepository.GetcontractAmount(countPerson); } - public Task>> GetList(InstitutionContractListSearchModel searchModel) + public async Task GetList(InstitutionContractListSearchModel searchModel) { - throw new NotImplementedException(); + return await _institutionContractRepository.GetList(searchModel); } } diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index 64653737..6abed8c8 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -27,7 +27,9 @@ public class InstitutionContractRepository : RepositoryBase new EditInstitutionContract() - { - Id = x.id, - ContractNo = x.ContractNo, - ContractStartGr = x.ContractStartGr, - ContractStartFa = x.ContractStartFa, - ContractEndGr = x.ContractEndGr, - ContractEndFa = x.ContractEndFa, - RepresentativeName = x.RepresentativeName, - ContractingPartyName = x.ContractingPartyName, - RepresentativeId = x.RepresentativeId, - ContractingPartyId = x.ContractingPartyId, - ContractDateFa = x.ContractDateFa, - State = x.State, - City = x.City, - Address = x.Address, - Description = x.Description, - WorkshopManualCount = x.WorkshopManualCount, - EmployeeManualCount = x.EmployeeManualCount, - ContractAmountString = x.ContractAmount.ToMoney(), - ContractAmount = x.ContractAmount, - DailyCompenseationString = x.DailyCompenseation.ToMoney(), - ObligationString = x.Obligation.ToMoney(), - TotalAmountString = x.TotalAmount.ToMoney(), - ExtensionNo = x.ExtensionNo, - OfficialCompany = x.OfficialCompany, - TypeOfContract = x.TypeOfContract, - Signature = x.Signature, - HasValueAddedTax = x.HasValueAddedTax, - ValueAddedTax = x.ValueAddedTax, - - }) + { + Id = x.id, + ContractNo = x.ContractNo, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + RepresentativeName = x.RepresentativeName, + ContractingPartyName = x.ContractingPartyName, + RepresentativeId = x.RepresentativeId, + ContractingPartyId = x.ContractingPartyId, + ContractDateFa = x.ContractDateFa, + State = x.State, + City = x.City, + Address = x.Address, + Description = x.Description, + WorkshopManualCount = x.WorkshopManualCount, + EmployeeManualCount = x.EmployeeManualCount, + ContractAmountString = x.ContractAmount.ToMoney(), + ContractAmount = x.ContractAmount, + DailyCompenseationString = x.DailyCompenseation.ToMoney(), + ObligationString = x.Obligation.ToMoney(), + TotalAmountString = x.TotalAmount.ToMoney(), + ExtensionNo = x.ExtensionNo, + OfficialCompany = x.OfficialCompany, + TypeOfContract = x.TypeOfContract, + Signature = x.Signature, + HasValueAddedTax = x.HasValueAddedTax, + ValueAddedTax = x.ValueAddedTax, + }) .FirstOrDefault(x => x.Id == id); } public EditInstitutionContract GetFirstContract(long contractingPartyId, string typeOfContract) { return _context.InstitutionContractSet.Select(x => new EditInstitutionContract() - { - Id = x.id, - ContractNo = x.ContractNo, - ContractStartGr = x.ContractStartGr, - ContractStartFa = x.ContractStartFa, - ContractEndGr = x.ContractEndGr, - ContractEndFa = x.ContractEndFa, - RepresentativeName = x.RepresentativeName, - ContractingPartyName = x.ContractingPartyName, - RepresentativeId = x.RepresentativeId, - ContractingPartyId = x.ContractingPartyId, - ContractDateFa = x.ContractDateFa, - State = x.State, - City = x.City, - Address = x.Address, - Description = x.Description, - WorkshopManualCount = x.WorkshopManualCount, - EmployeeManualCount = x.EmployeeManualCount, - ContractAmountString = x.ContractAmount.ToMoney(), - DailyCompenseationString = x.DailyCompenseation.ToMoney(), - ObligationString = x.Obligation.ToMoney(), - TotalAmountString = x.TotalAmount.ToMoney(), - ExtensionNo = x.ExtensionNo, - OfficialCompany = x.OfficialCompany, - TypeOfContract = x.TypeOfContract, - Signature = x.Signature - - }) - .Where(x => x.ContractingPartyId == contractingPartyId && x.TypeOfContract == typeOfContract).OrderBy(x => x.ExtensionNo).FirstOrDefault(); + { + Id = x.id, + ContractNo = x.ContractNo, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + RepresentativeName = x.RepresentativeName, + ContractingPartyName = x.ContractingPartyName, + RepresentativeId = x.RepresentativeId, + ContractingPartyId = x.ContractingPartyId, + ContractDateFa = x.ContractDateFa, + State = x.State, + City = x.City, + Address = x.Address, + Description = x.Description, + WorkshopManualCount = x.WorkshopManualCount, + EmployeeManualCount = x.EmployeeManualCount, + ContractAmountString = x.ContractAmount.ToMoney(), + DailyCompenseationString = x.DailyCompenseation.ToMoney(), + ObligationString = x.Obligation.ToMoney(), + TotalAmountString = x.TotalAmount.ToMoney(), + ExtensionNo = x.ExtensionNo, + OfficialCompany = x.OfficialCompany, + TypeOfContract = x.TypeOfContract, + Signature = x.Signature + }) + .Where(x => x.ContractingPartyId == contractingPartyId && x.TypeOfContract == typeOfContract) + .OrderBy(x => x.ExtensionNo).FirstOrDefault(); } public List InstitutionContractsWithoutAccount() { var now = DateTime.Now; - var contractHasClientAccountList = _context.InstitutionContractSet.AsSplitQuery().Where(x => x.IsActiveString == "true" && x.ContractStartGr <= now && x.ContractEndGr >= now) + var contractHasClientAccountList = _context.InstitutionContractSet.AsSplitQuery().Where(x => + x.IsActiveString == "true" && x.ContractStartGr <= now && x.ContractEndGr >= now) .Join(_context.ContractingPartyAccounts, contract => contract.ContractingPartyId, acc => acc.PersonalContractingPartyId, - ((contract, account) => new {contract, account})).Select(x=>x.contract); + ((contract, account) => new { contract, account })).Select(x => x.contract); var allActiveContracts = _context.InstitutionContractSet.Where(x => x.IsActiveString == "true" && x.ContractStartGr <= now && x.ContractEndGr >= now); @@ -137,21 +139,21 @@ public class InstitutionContractRepository : RepositoryBase ContractWithoutValidContactInfo() { var now = DateTime.Now; - var contractHasContactInfo = _context.InstitutionContractSet.AsSplitQuery().Where(x => x.IsActiveString == "true" && x.ContractStartGr <= now && x.ContractEndGr >= now) + var contractHasContactInfo = _context.InstitutionContractSet.AsSplitQuery().Where(x => + x.IsActiveString == "true" && x.ContractStartGr <= now && x.ContractEndGr >= now) .Join(_context.InstitutionContractContactInfos, contract => contract.id, contactInfo => contactInfo.InstitutionContractId, ((contract, contactInfo) => new { contract, contactInfo })) - .Where(x => x.contactInfo.SendSms && x.contactInfo.Position == "طرف قرارداد" && x.contactInfo.PhoneType == "شماره همراه") + .Where(x => x.contactInfo.SendSms && x.contactInfo.Position == "طرف قرارداد" && + x.contactInfo.PhoneType == "شماره همراه") .Select(x => x.contract); var allvalidCcntactInfoContracts = _context.InstitutionContractSet.Where(x => @@ -177,9 +179,9 @@ public class InstitutionContractRepository : RepositoryBase Search(InstitutionContractSearchModel searchModel) { //var stored = _context.InstitutionContractSet.FromSqlInterpolated($"SelectQuery_InstitutionContract").AsNoTracking() @@ -204,8 +206,6 @@ public class InstitutionContractRepository : RepositoryBase x.SearchAmount >= start && x.SearchAmount <= end); } + if (!string.IsNullOrWhiteSpace(searchModel.StartAmount) && string.IsNullOrWhiteSpace(searchModel.EndAmount)) { @@ -232,6 +233,7 @@ public class InstitutionContractRepository : RepositoryBase x.SearchAmount >= start); } + if (string.IsNullOrWhiteSpace(searchModel.StartAmount) && !string.IsNullOrWhiteSpace(searchModel.EndAmount)) { @@ -241,7 +243,6 @@ public class InstitutionContractRepository : RepositoryBase= start); query = query.Where(x => x.SearchAmount <= end); - } if (searchModel.IsActiveString == null) @@ -255,7 +256,8 @@ public class InstitutionContractRepository : RepositoryBase x.IsActiveString == "false" || x.IsActiveString == "true" || x.IsActiveString == "blue"); + query = query.Where(x => + x.IsActiveString == "false" || x.IsActiveString == "true" || x.IsActiveString == "blue"); } if (searchModel.OfficialCompany == "Official") @@ -307,58 +309,64 @@ public class InstitutionContractRepository : RepositoryBase new InstitutionContractViewModel() - { - Id = x.id, - ContractNo = x.ContractNo, - ContractStartGr = x.ContractStartGr, - ContractStartFa = x.ContractStartFa, - ContractEndGr = x.ContractEndGr, - ContractEndFa = x.ContractEndFa, - RepresentativeId = x.RepresentativeId, - RepresentativeName = x.RepresentativeName, - ContractingPartyName = x.ContractingPartyName, - ContractingPartyId = x.ContractingPartyId, - ContractAmount = x.ContractAmount.ToMoney(), - TotalAmount = x.TotalAmount.ToMoney(), - SearchAmount = x.ContractAmount, - IsActiveString = x.IsActiveString, - OfficialCompany = x.OfficialCompany, - TypeOfContract = x.TypeOfContract, - Signature = x.Signature, - - WorkshopCount = "", - //WorkshopViewModels = _context.Workshops.Include(w=>w.WorkshopEmployers).Include(w => w.LeftWorks).Include(w => w.LeftWorkInsurances).Select(w => new WorkshopViewModel() - //{ - // Id = w.id, - // WorkshopName = w.WorkshopName, - // WorkshopFullName = w.WorkshopFullName, - // ArchiveCode = w.ArchiveCode, - // ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(), - // LeftWorkIds = w.LeftWorks.Where(l => l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now).Select(l => l.EmployeeId).ToList(), - // InsuranceLeftWorkIds = w.LeftWorkInsurances.Where(l => (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now) || (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate == null)).Select(l => l.EmployeeId).ToList(), - //}).Where(w=>w.ContractingPartId == x.ContractingPartyId).ToList(), - WorkshopIds = _context.Workshops - .Include(w => w.WorkshopEmployers).Select(w => new WorkshopViewModel() { - Id = w.id, - ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(), + Id = x.id, + ContractNo = x.ContractNo, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + RepresentativeId = x.RepresentativeId, + RepresentativeName = x.RepresentativeName, + ContractingPartyName = x.ContractingPartyName, + ContractingPartyId = x.ContractingPartyId, + ContractAmount = x.ContractAmount.ToMoney(), + TotalAmount = x.TotalAmount.ToMoney(), + SearchAmount = x.ContractAmount, + IsActiveString = x.IsActiveString, + OfficialCompany = x.OfficialCompany, + TypeOfContract = x.TypeOfContract, + Signature = x.Signature, - }).Where(c => c.ContractingPartId == x.ContractingPartyId).Select(w => w.Id).ToList(), - EmployerViewModels = _context.Employers.Where(e => e.ContractingPartyId == x.ContractingPartyId).Select(e => - new EmployerViewModel() - { - Id = e.id, - FullName = e.FName + " " + e.LName, + WorkshopCount = "", + //WorkshopViewModels = _context.Workshops.Include(w=>w.WorkshopEmployers).Include(w => w.LeftWorks).Include(w => w.LeftWorkInsurances).Select(w => new WorkshopViewModel() + //{ + // Id = w.id, + // WorkshopName = w.WorkshopName, + // WorkshopFullName = w.WorkshopFullName, + // ArchiveCode = w.ArchiveCode, + // ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(), + // LeftWorkIds = w.LeftWorks.Where(l => l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now).Select(l => l.EmployeeId).ToList(), + // InsuranceLeftWorkIds = w.LeftWorkInsurances.Where(l => (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now) || (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate == null)).Select(l => l.EmployeeId).ToList(), + //}).Where(w=>w.ContractingPartId == x.ContractingPartyId).ToList(), + WorkshopIds = _context.Workshops + .Include(w => w.WorkshopEmployers).Select(w => new WorkshopViewModel() + { + Id = w.id, + ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId) + .FirstOrDefault(), + }).Where(c => c.ContractingPartId == x.ContractingPartyId).Select(w => w.Id).ToList(), + EmployerViewModels = _context.Employers.Where(e => e.ContractingPartyId == x.ContractingPartyId) + .Select(e => + new EmployerViewModel() + { + Id = e.id, + FullName = e.FName + " " + e.LName, + }).GroupBy(e => e.Id).Select(e => e.First()).ToList(), + EmployerIds = _context.Employers.AsSplitQuery().Where(e => e.ContractingPartyId == x.ContractingPartyId) + .Select(e => e.id).ToList(), + EmployerNo = "", + EmployerName = "", - }).GroupBy(e => e.Id).Select(e => e.First()).ToList(), - EmployerIds = _context.Employers.AsSplitQuery().Where(e => e.ContractingPartyId == x.ContractingPartyId).Select(e => e.id).ToList(), - EmployerNo = "", - EmployerName = "", - - IsContractingPartyBlock = _context.PersonalContractingParties.AsSplitQuery().Any(p => p.id == x.ContractingPartyId && p.IsBlock == "true") ? "true" : "false", - BlockTimes = _context.PersonalContractingParties.AsSplitQuery().Any(p => p.id == x.ContractingPartyId) ? _context.PersonalContractingParties.FirstOrDefault(p => p.id == x.ContractingPartyId).BlockTimes : 0, - - }); + IsContractingPartyBlock = + _context.PersonalContractingParties.AsSplitQuery() + .Any(p => p.id == x.ContractingPartyId && p.IsBlock == "true") + ? "true" + : "false", + BlockTimes = _context.PersonalContractingParties.AsSplitQuery().Any(p => p.id == x.ContractingPartyId) + ? _context.PersonalContractingParties.FirstOrDefault(p => p.id == x.ContractingPartyId).BlockTimes + : 0, + }); if (searchModel.Id != 0) query = query.Where(x => x.Id == searchModel.Id); @@ -376,6 +384,7 @@ public class InstitutionContractRepository : RepositoryBase x.SearchAmount >= start && x.SearchAmount <= end); } + if (!string.IsNullOrWhiteSpace(searchModel.StartAmount) && string.IsNullOrWhiteSpace(searchModel.EndAmount)) { @@ -384,6 +393,7 @@ public class InstitutionContractRepository : RepositoryBase x.SearchAmount >= start); } + if (string.IsNullOrWhiteSpace(searchModel.StartAmount) && !string.IsNullOrWhiteSpace(searchModel.EndAmount)) { @@ -393,7 +403,6 @@ public class InstitutionContractRepository : RepositoryBase= start); query = query.Where(x => x.SearchAmount <= end); - } @@ -408,7 +417,8 @@ public class InstitutionContractRepository : RepositoryBase x.IsActiveString == "false" || x.IsActiveString == "true" || x.IsActiveString == "blue"); + query = query.Where(x => + x.IsActiveString == "false" || x.IsActiveString == "true" || x.IsActiveString == "blue"); } if (searchModel.OfficialCompany == "Official") @@ -438,6 +448,7 @@ public class InstitutionContractRepository : RepositoryBase x.EmployerIds.Count > 0 && x.EmployerIds.Any(e => e == searchModel.EmployerId)); } + if (searchModel.Signature == "2") { query = query.Where(x => x.Signature == "0" || x.Signature == "1"); @@ -490,66 +501,67 @@ public class InstitutionContractRepository : RepositoryBase w.LeftWorkIds.Count)) + (x.WorkshopViewModels.Sum(w => w.InsuranceLeftWorkIds.Count(c => !w.LeftWorkIds.Contains(c))))).ToString(), // ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0, - WorkshopViewModels = _context.Workshops.AsSplitQuery().Where(w => x.WorkshopIds.Contains(w.id)).Include(w => w.LeftWorks).Include(w => w.LeftWorkInsurances).Select(w => new WorkshopViewModel() - { - Id = w.id, - WorkshopName = w.WorkshopName, - WorkshopFullName = w.WorkshopFullName, - ArchiveCode = w.ArchiveCode, - ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(), - LeftWorkIds = w.LeftWorks.Where(l => l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now).Select(l => l.EmployeeId).ToList(), - InsuranceLeftWorkIds = w.LeftWorkInsurances.Where(l => (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now) || (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate == null)).Select(l => l.EmployeeId).ToList(), - }).ToList(), - + WorkshopViewModels = _context.Workshops.AsSplitQuery().Where(w => x.WorkshopIds.Contains(w.id)) + .Include(w => w.LeftWorks).Include(w => w.LeftWorkInsurances).Select(w => new WorkshopViewModel() + { + Id = w.id, + WorkshopName = w.WorkshopName, + WorkshopFullName = w.WorkshopFullName, + ArchiveCode = w.ArchiveCode, + ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(), + LeftWorkIds = w.LeftWorks + .Where(l => l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now) + .Select(l => l.EmployeeId).ToList(), + InsuranceLeftWorkIds = w.LeftWorkInsurances + .Where(l => (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now) || + (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate == null)) + .Select(l => l.EmployeeId).ToList(), + }).ToList(), }).ToList(); listQuery = listQuery.Select(x => new InstitutionContractViewModel() - { - Id = x.Id, - ContractNo = x.ContractNo, - ContractStartGr = x.ContractStartGr, - ContractStartFa = x.ContractStartFa, - ContractEndGr = x.ContractEndGr, - ContractEndFa = x.ContractEndFa, - RepresentativeId = x.RepresentativeId, - RepresentativeName = x.RepresentativeName, - ContractingPartyName = x.ContractingPartyName, - ContractingPartyId = x.ContractingPartyId, - ContractAmount = x.ContractAmount, - TotalAmount = x.TotalAmount, - SearchAmount = x.SearchAmount, - IsActiveString = x.IsActiveString, - OfficialCompany = x.OfficialCompany, - TypeOfContract = x.TypeOfContract, - Signature = x.Signature, - ExpireColor = x.ExpireColor, - IsExpier = x.IsExpier, - BalanceDouble = x.BalanceDouble, - BalanceStr = x.BalanceStr, - EmployerViewModels = x.EmployerViewModels, - EmployerNo = x.EmployerNo, - EmployerName = x.EmployerViewModels.Select(n => n.FullName).FirstOrDefault(), - WorkshopViewModels = x.WorkshopViewModels, - WorkshopCount = x.WorkshopCount, - IsContractingPartyBlock = x.IsContractingPartyBlock, - BlockTimes = x.BlockTimes, - EmployeeCount = + { + Id = x.Id, + ContractNo = x.ContractNo, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + RepresentativeId = x.RepresentativeId, + RepresentativeName = x.RepresentativeName, + ContractingPartyName = x.ContractingPartyName, + ContractingPartyId = x.ContractingPartyId, + ContractAmount = x.ContractAmount, + TotalAmount = x.TotalAmount, + SearchAmount = x.SearchAmount, + IsActiveString = x.IsActiveString, + OfficialCompany = x.OfficialCompany, + TypeOfContract = x.TypeOfContract, + Signature = x.Signature, + ExpireColor = x.ExpireColor, + IsExpier = x.IsExpier, + BalanceDouble = x.BalanceDouble, + BalanceStr = x.BalanceStr, + EmployerViewModels = x.EmployerViewModels, + EmployerNo = x.EmployerNo, + EmployerName = x.EmployerViewModels.Select(n => n.FullName).FirstOrDefault(), + WorkshopViewModels = x.WorkshopViewModels, + WorkshopCount = x.WorkshopCount, + IsContractingPartyBlock = x.IsContractingPartyBlock, + BlockTimes = x.BlockTimes, + EmployeeCount = ((x.WorkshopViewModels.Sum(w => w.LeftWorkIds.Count)) + (x.WorkshopViewModels.Sum(w => w.InsuranceLeftWorkIds.Count(c => !w.LeftWorkIds.Contains(c))))).ToString(), - ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0, - - - }).OrderBy(x => x.WorkshopCount != "0" && string.IsNullOrWhiteSpace(x.ExpireColor)) + ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0, + }).OrderBy(x => x.WorkshopCount != "0" && string.IsNullOrWhiteSpace(x.ExpireColor)) .ThenBy(x => x.WorkshopCount == "0" && string.IsNullOrWhiteSpace(x.ExpireColor)) .ThenBy(x => x.IsExpier == "true") .ThenBy(x => x.ExpireColor == "purple") .ThenBy(x => x.ExpireColor == "black").ToList(); Console.WriteLine("test >>> " + timer.Elapsed); return listQuery; - } - public List PrintAll(List id) { throw new NotImplementedException(); @@ -581,9 +593,6 @@ public class InstitutionContractRepository : RepositoryBasei.YearlySalaryItemsList).FirstOrDefault(x => + var dailyWageYearlySalery = _context.YearlySalaries.Include(i => i.YearlySalaryItemsList).FirstOrDefault(x => x.StartDate.Date <= DateTime.Now.Date && x.EndDate >= DateTime.Now.Date); double res = 0; if (countPerson > 0 && dailyWageYearlySalery != null) @@ -641,8 +649,9 @@ public class InstitutionContractRepository : RepositoryBase x.id == employerId)!.ContractingPartyId; if (_context.PersonalContractingParties.Any(x => x.id == contractingPryId && x.IsBlock == "true")) return new(); var contracts = _context.InstitutionContractSet.Where(x => x.ContractingPartyId == contractingPryId).ToList(); var contract = contracts.FirstOrDefault(x => x.IsActiveString != "false" && - x.ContractStartGr.Date <= DateTime.Now.Date && x.ContractEndGr >= DateTime.Now.Date); + x.ContractStartGr.Date <= DateTime.Now.Date && + x.ContractEndGr >= DateTime.Now.Date); if (contract != null) { return contract; } - else + else { var future = contracts.FirstOrDefault(x => x.IsActiveString != "false" && - x.ContractStartGr.Date >= DateTime.Now.Date && x.ContractEndGr >= DateTime.Now.Date); + x.ContractStartGr.Date >= DateTime.Now.Date && + x.ContractEndGr >= DateTime.Now.Date); if (future != null) return future; return new(); } - - } @@ -783,30 +789,36 @@ public class InstitutionContractRepository : RepositoryBase 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) + + 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 @@ -866,18 +878,18 @@ public class InstitutionContractRepository : RepositoryBase 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 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; @@ -891,41 +903,45 @@ public class InstitutionContractRepository : RepositoryBase x.id == rollCallService.WorkshopId); - + string description = ""; if (rollCallService.StartService <= prevMonthStart) { var monthPrev = prevMonthEnd.ToFarsi().Substring(5, 2); var yearPrev = prevMonthEnd.ToFarsi().Substring(0, 4); var prevMonthName = monthPrev.ToFarsiMonthByNumber(); - description = $"{prevMonthName} و {currentMonthName} {yearCurrent} - {workshop.WorkshopFullName}"; + description = + $"{prevMonthName} و {currentMonthName} {yearCurrent} - {workshop.WorkshopFullName}"; monthCounter = 2; - }else if (rollCallService.StartService <= currentMonthStart && - rollCallService.StartService > prevMonthStart) + } + else if (rollCallService.StartService <= currentMonthStart && + rollCallService.StartService > prevMonthStart) { monthCounter = 1; - + description = $"{currentMonthName} {yearCurrent} - {workshop.WorkshopFullName}"; } - - + var employees = - _context.RollCallEmployees.Where(x => x.WorkshopId == rollCallService.WorkshopId).Select(x=>x.id); + _context.RollCallEmployees.Where(x => x.WorkshopId == rollCallService.WorkshopId) + .Select(x => x.id); - var employeeCount = _context.RollCallEmployeesStatus.Where(x => employees.Contains(x.RollCallEmployeeId)) + var employeeCount = _context.RollCallEmployeesStatus + .Where(x => employees.Contains(x.RollCallEmployeeId)) .Count(x => x.EndDate.Date == activeStatusDate.Date); - + if (employeeCount > 0 && monthCounter > 0) { - counter++; - var dailyWageYearlySalery = _context.YearlySalaries.Include(i => i.YearlySalaryItemsList).FirstOrDefault(x => - x.StartDate.Date <= DateTime.Now.Date && x.EndDate >= DateTime.Now.Date); + var dailyWageYearlySalery = _context.YearlySalaries.Include(i => i.YearlySalaryItemsList) + .FirstOrDefault(x => + x.StartDate.Date <= DateTime.Now.Date && x.EndDate >= DateTime.Now.Date); - var dailyWage = dailyWageYearlySalery.YearlySalaryItemsList.Where(x => x.ItemName == "مزد روزانه") + var dailyWage = dailyWageYearlySalery.YearlySalaryItemsList + .Where(x => x.ItemName == "مزد روزانه") .Select(x => x.ItemValue).FirstOrDefault(); var planPercentage = _context.PlanPercentages.FirstOrDefault(); @@ -934,8 +950,9 @@ public class InstitutionContractRepository : RepositoryBase x.CountPerson == countPersonnel); - var amountForOneMonth =(((dailyWage * planPercentage.RollCallPercent) / 100) * planByCountPerson.CountPerson * - planByCountPerson.IncreasePercentage); + var amountForOneMonth = (((dailyWage * planPercentage.RollCallPercent) / 100) * + planByCountPerson.CountPerson * + planByCountPerson.IncreasePercentage); var amountWithoutTax = amountForOneMonth * monthCounter; @@ -944,7 +961,9 @@ public class InstitutionContractRepository : RepositoryBase @@ -962,31 +981,32 @@ public class InstitutionContractRepository : RepositoryBase GetList(InstitutionContractListSearchModel searchModel) + { + throw new NotImplementedException(); + } + #endregion #region CustomViewModels - - public class WorkshopsAndEmployeeViewModel { public List WorkshopViewModels { get; set; } diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index a8904df8..85cae08f 100644 --- a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs +++ b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs @@ -21,7 +21,7 @@ public class institutionContractController : Controller /// /// [HttpGet] - public async Task>>> GetList(InstitutionContractListSearchModel searchModel) + public async Task> GetList(InstitutionContractListSearchModel searchModel) { return await _institutionContractApplication.GetList(searchModel); }