diff --git a/Company.Domain/ContarctingPartyAgg/PersonalContractingParty.cs b/Company.Domain/ContarctingPartyAgg/PersonalContractingParty.cs index d5735e60..29de6fb9 100644 --- a/Company.Domain/ContarctingPartyAgg/PersonalContractingParty.cs +++ b/Company.Domain/ContarctingPartyAgg/PersonalContractingParty.cs @@ -290,4 +290,13 @@ public class PersonalContractingParty : EntityBase this.Gender = gender; this.IsAuthenticated = true; } + + public void EditLegalPartyFromInstitution(string legalPosition, string companyName, + string registerId,string nationalId) + { + LegalPosition = legalPosition; + LName = companyName; + RegisterId = registerId; + NationalId = nationalId; + } } \ No newline at end of file diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index 2ced77de..ffbcb7d9 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -981,6 +981,12 @@ public class InstitutionContractApplication : IInstitutionContractApplication existingContractingParty.UnAuthenticateLegalEdit(legalCommand.FName,legalCommand.LName,legalCommand.FatherName,legalCommand.IdNumber,existingContractingParty.IdNumberSeri,existingContractingParty.IdNumberSerial, legalCommand.BirthDateFa,legalCommand.Gender,legalCommand.PhoneNumber); } + + if (existingContractingParty != null) + { + existingContractingParty.EditLegalPartyFromInstitution(command.LegalParty.Position,command.LegalParty.CompanyName, + command.LegalParty.RegisterId,command.LegalParty.NationalId); + } } else if (command.ContractingPartyLegalType == LegalType.Real) { diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index a06762f6..ffaa4102 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -80,7 +80,9 @@ public class InstitutionContractRepository : RepositoryBase hubContext) : base(context) + IPlanPercentageRepository planPercentageRepository, ISmsService smsService, + ISmsResultRepository smsResultRepository, IFinancialTransactionRepository financialTransactionRepository, + IFinancialStatmentRepository financialStatmentRepository, IHubContext hubContext) : base(context) { _context = context; _employerRepository = employerRepository; @@ -100,69 +102,69 @@ 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 - }) + { + 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(); } @@ -580,40 +582,40 @@ 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, - 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") @@ -1101,7 +1103,10 @@ public class InstitutionContractRepository : RepositoryBase= now && x.contract.ContractEndGr <= endThisMontGr && !_context.InstitutionContractSet.Any(i=>i.ContractingPartyId == x.contract.ContractingPartyId && x.contract.ExtensionNo+1 <= i.ExtensionNo && i.IsActiveString == "true")) + : (x.contract.ContractEndGr >= now && x.contract.ContractEndGr <= endThisMontGr && + !_context.InstitutionContractSet.Any(i => + i.ContractingPartyId == x.contract.ContractingPartyId && + x.contract.ExtensionNo + 1 <= i.ExtensionNo && i.IsActiveString == "true")) ? (int)InstitutionContractListStatus.PendingForRenewal : x.contractingParty.IsBlock == "true" ? (int)InstitutionContractListStatus.Block @@ -1726,9 +1731,9 @@ public class InstitutionContractRepository : RepositoryBase x.WorkshopGroup) - .ThenInclude(x=> x.InitialWorkshops) - .Include(x=>x.WorkshopGroup) - .ThenInclude(x=>x.CurrentWorkshops) + .ThenInclude(x => x.InitialWorkshops) + .Include(x => x.WorkshopGroup) + .ThenInclude(x => x.CurrentWorkshops) .FirstOrDefaultAsync(x => x.id == institutionContractId); } @@ -1865,8 +1870,8 @@ public class InstitutionContractRepository : RepositoryBase GetByPublicIdAsync(Guid id) { return await _context.InstitutionContractSet - .Include(x=>x.ContactInfoList) - .Include(x=>x.Installments) + .Include(x => x.ContactInfoList) + .Include(x => x.Installments) .FirstOrDefaultAsync(x => x.PublicId == id); } @@ -1881,7 +1886,7 @@ public class InstitutionContractRepository : RepositoryBase baseAmount) throw new BadRequestException("مقدار تخفیف نمی‌تواند بیشتر از مبلغ کل باشد"); @@ -1933,7 +1938,7 @@ public class InstitutionContractRepository : RepositoryBase x.NationalId == legalCommand.NationalId); if (!request.LegalParty.IsAuth) { - var legalCommand = request.LegalParty; - var personalContractingParty = _context.PersonalContractingParties - .FirstOrDefault(x=>x.NationalId == legalCommand.NationalId); - if (personalContractingParty is {IsAuthenticated:false}) + if (realPersonalContractingParty is { IsAuthenticated: false }) { - personalContractingParty.UnAuthenticateLegalEdit(legalCommand.FName, legalCommand.LName, - legalCommand.FatherName, legalCommand.IdNumber, personalContractingParty.IdNumberSeri, - personalContractingParty.IdNumberSerial, legalCommand.BirthDateFa, legalCommand.Gender, + realPersonalContractingParty.UnAuthenticateLegalEdit(legalCommand.FName, legalCommand.LName, + legalCommand.FatherName, legalCommand.IdNumber, realPersonalContractingParty.IdNumberSeri, + realPersonalContractingParty.IdNumberSerial, legalCommand.BirthDateFa, legalCommand.Gender, legalCommand.PhoneNumber); } } + realPersonalContractingParty?.EditLegalPartyFromInstitution(legalCommand.Position, legalCommand.CompanyName, + legalCommand.RegisterId, legalCommand.NationalId); break; case LegalType.Real: if (!request.RealParty.IsAuth) @@ -2092,7 +2099,7 @@ public class InstitutionContractRepository : RepositoryBase x.Nationalcode == realCommand.NationalCode); - if (personalContractingParty is {IsAuthenticated:false}) + if (personalContractingParty is { IsAuthenticated: false }) { personalContractingParty.UnAuthenticateRealEdit(realCommand.FName, realCommand.LName, realCommand.FatherName, realCommand.IdNumber, personalContractingParty.IdNumberSeri, @@ -2100,19 +2107,20 @@ public class InstitutionContractRepository : RepositoryBase x.Id == request.TempId) .FirstOrDefaultAsync(); if (extenstionTemp == null) { throw new BadRequestException("دیتای درخواست شده نامعتبر است"); } - + var prevInstitutionContracts = await _context.InstitutionContractSet .Include(x => x.WorkshopGroup) .ThenInclude(institutionContractWorkshopGroup => institutionContractWorkshopGroup.CurrentWorkshops) @@ -2280,9 +2288,9 @@ public class InstitutionContractRepository : RepositoryBase SetDiscountForExtension(InstitutionContractSetDiscountForExtensionRequest request) + public async Task SetDiscountForExtension( + InstitutionContractSetDiscountForExtensionRequest request) { - if (request.DiscountPercentage <= 0) throw new BadRequestException("مقدار تخفیف نمی‌تواند برابر یا کمتر از صفر باشد"); var institutionTemp = await _institutionExtensionTemp.Find(x => x.Id == request.TempId) @@ -2294,14 +2302,15 @@ public class InstitutionContractRepository : RepositoryBase0) + if (institutionTemp.MonthlyPayment.DiscountPercetage > 0) throw new BadRequestException("تخفیف قبلا برای این قرارداد اعمال شده است"); } else { - if(institutionTemp.OneTimePayment.DiscountPercetage>0) + if (institutionTemp.OneTimePayment.DiscountPercetage > 0) throw new BadRequestException("تخفیف قبلا برای این قرارداد اعمال شده است"); } + var selectedPlan = institutionTemp.Duration switch { InstitutionContractDuration.OneMonth => institutionTemp.OneMonth, @@ -2317,10 +2326,9 @@ public class InstitutionContractRepository : RepositoryBase x.Id == institutionTemp.Id, institutionTemp); @@ -2429,7 +2437,8 @@ public class InstitutionContractRepository : RepositoryBasex.Id == institutionTemp.Id, + + await _institutionExtensionTemp.ReplaceOneAsync(x => x.Id == institutionTemp.Id, institutionTemp); - } else { @@ -2484,8 +2492,9 @@ public class InstitutionContractRepository : RepositoryBasex.Id == institutionTemp.Id, + + await _institutionExtensionTemp.ReplaceOneAsync(x => x.Id == institutionTemp.Id, institutionTemp); } @@ -2535,16 +2545,16 @@ public class InstitutionContractRepository : RepositoryBase ExtensionComplete(InstitutionContractExtensionCompleteRequest request) { var institutionContractTemp = await _institutionExtensionTemp.Find(x => x.Id == request.TemporaryId) .FirstOrDefaultAsync(); - + if (institutionContractTemp == null) throw new BadRequestException("اطلاعات وارد شده نامعتبر است"); + var selectedDuration = institutionContractTemp.Duration switch { InstitutionContractDuration.OneMonth => institutionContractTemp.OneMonth, @@ -2655,6 +2665,7 @@ public class InstitutionContractRepository : RepositoryBase @@ -2739,7 +2750,6 @@ public class InstitutionContractRepository : RepositoryBase x.Id == amendmentTemp.Id, amendmentTemp); - } + public async Task> GetInstitutionContractSelectList(string search, string selected) { - var contractingParties = _context.PersonalContractingParties.Select(x => new InstitutionContractSelectListViewModel() - { - Id = x.id, - Text = x.IsLegal == "حقیقی" ? x.SureName == null - ? x.FName + " " + x.LName - : x.FName + " " + x.LName + " " + x.SureName - : x.SureName == null ? x.LName - : x.LName + " " + x.SureName - }); + var contractingParties = _context.PersonalContractingParties.Select(x => + new InstitutionContractSelectListViewModel() + { + Id = x.id, + Text = x.IsLegal == "حقیقی" ? x.SureName == null + ? x.FName + " " + x.LName + : x.FName + " " + x.LName + " " + x.SureName + : x.SureName == null ? x.LName + : x.LName + " " + x.SureName + }); var workshops = _context.Workshops.Select(x => new InstitutionContractSelectListViewModel() { @@ -3067,6 +3077,7 @@ public class InstitutionContractRepository : RepositoryBase x.Text == selected); } + if (!string.IsNullOrWhiteSpace(search)) { res = res.Where(x => x.Text.Contains(search)); @@ -3078,7 +3089,6 @@ public class InstitutionContractRepository : RepositoryBase x.Id).ToList(); - } public async Task> PrintAllAsync(List ids) @@ -3211,7 +3221,8 @@ public class InstitutionContractRepository : RepositoryBase /// دریافت لیست - ارسال پیامک /// فراخوانی از سمت بک گراند سرویس @@ -3374,11 +3382,9 @@ public class InstitutionContractRepository : RepositoryBase public async Task SendReminderSmsForBackgroundTask() { - var now = DateTime.Now; - // تبدیل تاریخ میلادی به شمسی var persianNow = now.ToFarsi(); var persianEndOfMonth = int.Parse(persianNow.FindeEndOfMonth().Substring(8, 2)); @@ -3413,8 +3419,6 @@ public class InstitutionContractRepository : RepositoryBase /// ارسال پیامک صورت حساب ماهانه /// @@ -3457,6 +3462,7 @@ public class InstitutionContractRepository : RepositoryBase /// پیامک بلاک /// @@ -3466,7 +3472,6 @@ public class InstitutionContractRepository : RepositoryBase> GetBlockListData(DateTime checkDate) { var smsList = new List(); - var institutionContracts =await _context.InstitutionContractSet.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, - ContractAmountDouble = x.ContractAmount, - OfficialCompany = x.OfficialCompany - }).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate && - x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First()).ToListAsync(); + var institutionContracts = await _context.InstitutionContractSet.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, + ContractAmountDouble = x.ContractAmount, + OfficialCompany = x.OfficialCompany + }).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate && + x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First()) + .ToListAsync(); var contractingPartyList = await _context.PersonalContractingParties @@ -3548,8 +3550,7 @@ public class InstitutionContractRepository : RepositoryBase institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.ContractingPartyId)) - .Include(x => x.FinancialTransactionList).Where( - x => x.FinancialTransactionList.Count > 0).ToListAsync(); + .Include(x => x.FinancialTransactionList).Where(x => x.FinancialTransactionList.Count > 0).ToListAsync(); var phoneNumberList = await _context.InstitutionContractContactInfos .Where(x => institutionContracts.Select(ins => ins.Id).Contains(x.InstitutionContractId)) @@ -3563,8 +3564,9 @@ public class InstitutionContractRepository : RepositoryBase x.id == item.ContractingPartyId); if (contractingParty != null && contractingParty.IsBlock == "true") { - - var partyName = contractingParty.IsLegal == "حقیقی" ? $"{contractingParty.FName} {contractingParty.LName}" : $"{contractingParty.LName}"; + var partyName = contractingParty.IsLegal == "حقیقی" + ? $"{contractingParty.FName} {contractingParty.LName}" + : $"{contractingParty.LName}"; if (!string.IsNullOrWhiteSpace(contractingParty.SureName)) partyName = $"{partyName} ({contractingParty.SureName})"; @@ -3573,21 +3575,21 @@ public class InstitutionContractRepository : RepositoryBase x.ContractingPartyId == item.ContractingPartyId & x.FinancialTransactionList.Count > 0); + financialStatmentList.Any(x => + x.ContractingPartyId == item.ContractingPartyId & x.FinancialTransactionList.Count > 0); var hasPhonNumber = phoneNumberList.Any(x => x.InstitutionContractId == item.Id); - if (hasFinancialStatment && hasPhonNumber) { - - var transactions = financialStatmentList.FirstOrDefault(x => x.ContractingPartyId == item.ContractingPartyId); + var transactions = + financialStatmentList.FirstOrDefault(x => x.ContractingPartyId == item.ContractingPartyId); var debtor = transactions.FinancialTransactionList.Sum(x => x.Deptor); var creditor = transactions.FinancialTransactionList.Sum(x => x.Creditor); - + var id = $"{item.ContractingPartyId}"; var aprove = $"{transactions.id}"; @@ -3631,21 +3633,26 @@ public class InstitutionContractRepository : RepositoryBase 18 ? item.ContractingPartyName.Substring(0, 18) : item.ContractingPartyName; + string name = item.ContractingPartyName.Length > 18 + ? item.ContractingPartyName.Substring(0, 18) + : item.ContractingPartyName; string errMess = $"{name}-خطا"; await _smsService.Alarm("09114221321", errMess); - } } @@ -3656,7 +3663,6 @@ public class InstitutionContractRepository : RepositoryBase ///دریافت لیست بدهکارن /// جهت ارسال پیامک @@ -3664,7 +3670,6 @@ public class InstitutionContractRepository : RepositoryBase public async Task> GetSmsListData(DateTime checkDate, TypeOfSmsSetting typeOfSmsSetting) { - var watch = new Stopwatch(); var smsList = new List(); var currentMonthStart = ($"{(checkDate.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime(); @@ -3673,37 +3678,39 @@ public class InstitutionContractRepository : RepositoryBase x.StartService.Date <= previusMonthStart.Date && x.EndService.Date >= previusMonthEnd.Date).ToList(); - var institutionContracts = await _context.InstitutionContractSet.AsSplitQuery().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, - ContractAmountDouble = x.ContractAmount, - OfficialCompany = x.OfficialCompany - }).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate && - x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First()).ToListAsync(); + var institutionContracts = await _context.InstitutionContractSet.AsSplitQuery().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, + ContractAmountDouble = x.ContractAmount, + OfficialCompany = x.OfficialCompany + }).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate && + x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First()) + .ToListAsync(); var contractingPartyList = await _context.PersonalContractingParties - .Where(x=> institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.id)).ToListAsync(); - + .Where(x => institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.id)).ToListAsync(); + var financialStatmentList = await _context.FinancialStatments.AsSplitQuery() - .Where(x=> institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.ContractingPartyId)) - .Include(x => x.FinancialTransactionList).Where( - x => x.FinancialTransactionList.Count > 0).ToListAsync(); + .Where(x => institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.ContractingPartyId)) + .Include(x => x.FinancialTransactionList).Where(x => x.FinancialTransactionList.Count > 0).ToListAsync(); var phoneNumberList = await _context.InstitutionContractContactInfos - .Where(x=> institutionContracts.Select(ins=>ins.Id).Contains(x.InstitutionContractId)) + .Where(x => institutionContracts.Select(ins => ins.Id).Contains(x.InstitutionContractId)) .Where(x => x.SendSms && x.PhoneType == "شماره همراه" && !string.IsNullOrWhiteSpace(x.PhoneNumber) && - x.PhoneNumber.Length == 11).ToListAsync(); + x.PhoneNumber.Length == 11).ToListAsync(); Console.WriteLine("database query: " + watch.Elapsed); watch.Stop(); @@ -3717,7 +3724,9 @@ public class InstitutionContractRepository : RepositoryBase x.InstitutionContractId == item.Id) .Select(x => new CreateContactInfo { @@ -3748,7 +3756,8 @@ public class InstitutionContractRepository : RepositoryBase x.PhoneNumber.Length == 11).ToList(); - var transactions = financialStatmentList.FirstOrDefault(x=>x.ContractingPartyId == item.ContractingPartyId); + var transactions = financialStatmentList.FirstOrDefault(x => + x.ContractingPartyId == item.ContractingPartyId); var debtor = transactions.FinancialTransactionList.Sum(x => x.Deptor); var creditor = transactions.FinancialTransactionList.Sum(x => x.Creditor); @@ -3799,7 +3808,6 @@ public class InstitutionContractRepository : RepositoryBase 18 ? item.ContractingPartyName.Substring(0, 18) : item.ContractingPartyName; + string name = item.ContractingPartyName.Length > 18 + ? item.ContractingPartyName.Substring(0, 18) + : item.ContractingPartyName; string errMess = $"{name}-خطا"; // _smsService.Alarm("09114221321", errMess); - } } @@ -3998,7 +4042,6 @@ public class InstitutionContractRepository : RepositoryBase smsListData, string typeOfSms, @@ -4006,7 +4049,6 @@ public class InstitutionContractRepository : RepositoryBase 18 ? item.PartyName.Substring(0, 18) : item.PartyName; string errMess = $"{name}-خطا"; await _smsService.Alarm("09114221321", errMess); - } + Thread.Sleep(600); var percent = (successProcess / (double)countList) * 100; await _hubContext.Clients.Group(SendSmsHub.GetGroupName(10)) @@ -4053,21 +4095,20 @@ public class InstitutionContractRepository : RepositoryBase /// - public async Task SendReminderSmsToContractingParties(List smsListData, string typeOfSms, string sendMessStart, string sendMessEnd) + public async Task SendReminderSmsToContractingParties(List smsListData, string typeOfSms, + string sendMessStart, string sendMessEnd) { //ارسال پیامک با اساس لیست - #region SendSMSFromList - + #region SendSMSFromList if (smsListData.Any()) { - //await _smsService.Alarm("09114221321", sendMessStart); //Thread.Sleep(1000); //await _smsService.Alarm("09111485044", sendMessStart); //Thread.Sleep(1000); - + int successProcess = 1; int countList = smsListData.Count; @@ -4078,7 +4119,8 @@ public class InstitutionContractRepository : RepositoryBase 18 ? item.PartyName.Substring(0, 18) : item.PartyName; string errMess = $"{name}-خطا"; await _smsService.Alarm("09114221321", errMess); - } - var percent =(successProcess / (double)countList) * 100; + + var percent = (successProcess / (double)countList) * 100; await _hubContext.Clients.Group(SendSmsHub.GetGroupName(7)) .SendAsync("showStatus", (int)percent); successProcess += 1; - - - - } @@ -4132,7 +4170,6 @@ public class InstitutionContractRepository : RepositoryBase new FinancialTransactionViewModel - { - Id = t.id, - TdateFa = t.TdateFa, - TdateGr = t.TdateGr, - Description = t.TypeOfTransaction == "debt" - ? "ایجاد درآمد" + " " + t.DescriptionOption + " " + t.Description - : "دریافت درآمد" + " " + t.DescriptionOption + " " + t.Description, - Deptor = t.Deptor, - DeptorString = t.Deptor != 0 ? t.Deptor.ToMoney() : "", - Creditor = t.Creditor, - CreditorString = t.Creditor != 0 ? t.Creditor.ToMoney() : "", - Balance = t.Balance, - MessageText = t.MessageText, - SentSms = t.SentSms, - SentSmsDateFa = t.SentSmsDateFa, - FinancialStatementId = t.FinancialStatementId, - TypeOfTransaction = t.TypeOfTransaction, - DescriptionOption = t.DescriptionOption - }).OrderBy(t => t.TdateGr).ToList() + FinancialTransactionViewModels = x.FinancialTransactionList.Select(t => + new FinancialTransactionViewModel + { + Id = t.id, + TdateFa = t.TdateFa, + TdateGr = t.TdateGr, + Description = t.TypeOfTransaction == "debt" + ? "ایجاد درآمد" + " " + t.DescriptionOption + " " + t.Description + : "دریافت درآمد" + " " + t.DescriptionOption + " " + t.Description, + Deptor = t.Deptor, + DeptorString = t.Deptor != 0 ? t.Deptor.ToMoney() : "", + Creditor = t.Creditor, + CreditorString = t.Creditor != 0 ? t.Creditor.ToMoney() : "", + Balance = t.Balance, + MessageText = t.MessageText, + SentSms = t.SentSms, + SentSmsDateFa = t.SentSmsDateFa, + FinancialStatementId = t.FinancialStatementId, + TypeOfTransaction = t.TypeOfTransaction, + DescriptionOption = t.DescriptionOption + }).OrderBy(t => t.TdateGr).ToList() }) .FirstOrDefaultAsync(x => x.ContractingPartyId == contractingPartyId); - - } #endregion @@ -4189,18 +4225,20 @@ public class InstitutionContractRepository : RepositoryBase /// - public async Task CreateTransactionForInstitutionContracts(DateTime endOfMonthGr, string endOfMonthFa, string description) + public async Task CreateTransactionForInstitutionContracts(DateTime endOfMonthGr, string endOfMonthFa, + string description) { - #region FindeNextMonth 1th var firstDayOfMonthGr = ($"{endOfMonthFa.Substring(0, 8)}01").ToGeorgianDateTime(); var nextMonthGr = endOfMonthGr.AddDays(1); var endOfCurrentMonth = (($"{endOfMonthFa.Substring(0, 8)}/01").FindeEndOfMonth()).ToGeorgianDateTime(); + #endregion #region GetAvtiveContracts + var institutionContracts = await _context.InstitutionContractSet.Where(x => x.IsActiveString == "true") .Include(x => x.Installments) .Select(x => new InstitutionContractViewModel @@ -4217,11 +4255,14 @@ public class InstitutionContractRepository : RepositoryBase new InstitutionContractInstallmentViewModel { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }).OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(), - + InstallmentList = x.Installments + .Select(ins => new InstitutionContractInstallmentViewModel + { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }) + .OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(), }).Where(x => x.ContractStartGr < endOfMonthGr && x.ContractEndGr >= endOfMonthGr && x.ContractAmountDouble > 0) .ToListAsync(); + #endregion #region GetFutureContracts @@ -4233,7 +4274,6 @@ public class InstitutionContractRepository : RepositoryBase new InstitutionContractInstallmentViewModel { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }).OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(), + InstallmentList = x.Installments + .Select(ins => new InstitutionContractInstallmentViewModel + { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }) + .OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(), }).ToListAsync(); if (deatcivedContract.Any()) institutionContracts.AddRange(deatcivedContract); - - - } @@ -4275,19 +4315,19 @@ public class InstitutionContractRepository : RepositoryBase x.IsActiveString == "true").ToListAsync(); var activeStatusDate = new DateTime(2121, 03, 21); + #endregion + int count = 0; int serviceCounter = 0; foreach (var item in institutionContracts) { var jobRelation = "بابت قرارداد مابین (روابط کار)"; var taxAndFinancial = "بابت قرارداد مابین (حسابداری و مالیات)"; - + var contractingParty = await _context.PersonalContractingParties.FirstOrDefaultAsync(x => x.id == item.ContractingPartyId); - - string partyName = item.ContractingPartyName; if (partyName.Length > 18) partyName = $"{partyName.Substring(0, 18)}"; @@ -4298,8 +4338,9 @@ public class InstitutionContractRepository : RepositoryBase x.ContractingPartyId == item.ContractingPartyId); + var hasFinancialStatment = + await _context.FinancialStatments.AnyAsync(x => + x.ContractingPartyId == item.ContractingPartyId); var computeOption = item.TypeOfContract == "JobRelation" ? jobRelation : taxAndFinancial; if (hasFinancialStatment) @@ -4308,49 +4349,40 @@ public class InstitutionContractRepository : RepositoryBase x.ContractingPartyId == item.ContractingPartyId); var financialStatmentId = financialStatmentData.id; - + var alreadyCreated = await _context.FinancialTransactions.AnyAsync(x => x.DescriptionOption == computeOption && x.TypeOfTransaction == "debt" && x.TdateGr.Date == endOfMonthGr.Date && x.FinancialStatementId == financialStatmentId); if (!alreadyCreated) { - - - - - if (item.IsInstallment && item.VerificationStatus == InstitutionContractVerificationStatus.Verified) - { - var instalment = item.InstallmentList - .FirstOrDefault(x => - x.InstallmentDateGr >= firstDayOfMonthGr && - x.InstallmentDateGr <= endOfMonthGr); - if (instalment != null) - { - var transaction = new FinancialTransaction(financialStatmentId, endOfMonthGr, - endOfMonthFa, - description, - "debt", computeOption, instalment.AmountDouble, 0, 0, isblock); - await _financialTransactionRepository.CreateAsync(transaction); - await _financialTransactionRepository.SaveChangesAsync(); - } - - } - else + if (item.IsInstallment && + item.VerificationStatus == InstitutionContractVerificationStatus.Verified) + { + var instalment = item.InstallmentList + .FirstOrDefault(x => + x.InstallmentDateGr >= firstDayOfMonthGr && + x.InstallmentDateGr <= endOfMonthGr); + if (instalment != null) { var transaction = new FinancialTransaction(financialStatmentId, endOfMonthGr, endOfMonthFa, description, - "debt", computeOption, item.ContractAmountDouble, 0, 0, isblock); + "debt", computeOption, instalment.AmountDouble, 0, 0, isblock); await _financialTransactionRepository.CreateAsync(transaction); await _financialTransactionRepository.SaveChangesAsync(); } - - + } + else + { + var transaction = new FinancialTransaction(financialStatmentId, endOfMonthGr, + endOfMonthFa, + description, + "debt", computeOption, item.ContractAmountDouble, 0, 0, isblock); + await _financialTransactionRepository.CreateAsync(transaction); + await _financialTransactionRepository.SaveChangesAsync(); + } } - - - } else { @@ -4359,7 +4391,8 @@ public class InstitutionContractRepository : RepositoryBase @@ -4372,9 +4405,7 @@ public class InstitutionContractRepository : RepositoryBase x.ContractingPartyId == item.ContractingPartyId) - .Select(x => x.id).ToListAsync(); - var workshops = await _context.WorkshopEmployers.Where(x => employers.Contains(x.EmployerId)) + var employers = await _context.Employers + .Where(x => x.ContractingPartyId == item.ContractingPartyId) + .Select(x => x.id).ToListAsync(); + var workshops = await _context.WorkshopEmployers + .Where(x => employers.Contains(x.EmployerId)) .Select(x => x.WorkshopId).Distinct().ToListAsync(); var services = @@ -4419,7 +4449,9 @@ public class InstitutionContractRepository : RepositoryBase x.id == rollCallService.WorkshopId); + var workshop = + await _context.Workshops.FirstOrDefaultAsync(x => + x.id == rollCallService.WorkshopId); string rollCallTransactionDescription = ""; //if (rollCallService.StartService <= prevMonthStart) @@ -4443,11 +4475,13 @@ public class InstitutionContractRepository : RepositoryBase x.WorkshopId == rollCallService.WorkshopId) + _context.RollCallEmployees + .Where(x => x.WorkshopId == rollCallService.WorkshopId) .Select(x => x.id).ToListAsync(); var employeeCount = await _context.RollCallEmployeesStatus @@ -4456,12 +4490,11 @@ public class InstitutionContractRepository : RepositoryBase 0 && monthCounter > 0) { - - - - var dailyWageYearlySalery = await _context.YearlySalaries.Include(i => i.YearlySalaryItemsList) + var dailyWageYearlySalery = await _context.YearlySalaries + .Include(i => i.YearlySalaryItemsList) .FirstOrDefaultAsync(x => - x.StartDate.Date <= DateTime.Now.Date && x.EndDate >= DateTime.Now.Date); + x.StartDate.Date <= DateTime.Now.Date && + x.EndDate >= DateTime.Now.Date); var dailyWage = dailyWageYearlySalery.YearlySalaryItemsList .Where(x => x.ItemName == "مزد روزانه") @@ -4488,8 +4521,6 @@ public class InstitutionContractRepository : RepositoryBase x.ContractingPartyId == item.ContractingPartyId); @@ -4500,32 +4531,35 @@ public class InstitutionContractRepository : RepositoryBase x.FinancialStatementId == financialStatementId && - x.Description == rollCallTransactionDescription && - x.DescriptionOption == "بابت سرویس حضور غیاب" && + x.Description == rollCallTransactionDescription && + x.DescriptionOption == "بابت سرویس حضور غیاب" && x.TypeOfTransaction == "debt" && x.TdateFa == endOfMonthFa); if (!alreadyCreated) { serviceCounter++; - Console.WriteLine(serviceCounter + " - " + rollCallService.StartService.ToFarsi() + " - " + + Console.WriteLine(serviceCounter + " - " + + rollCallService.StartService.ToFarsi() + " - " + rollCallService.WorkshopId + " - " + employeeCount + $" - {totalAmonut} - round {result}"); await _context.FinancialTransactions.AddAsync(transaction); await _context.SaveChangesAsync(); } - + //Console.WriteLine(" number : " + counter + " - " + rollCallService.StartService.ToFarsi() + " - WorkshopId : " + rollCallService.WorkshopId + " - monthCount : " + monthCounter + " - employeeCount : " + employeeCount + $" - Amount : {amountWithoutTax.ToMoney()}" + $" - ten : {tenPercent.ToMoney()} total : {totalAmonut.ToMoney()}"); } @@ -4534,8 +4568,6 @@ public class InstitutionContractRepository : RepositoryBase 18 ? partyName.Substring(0, 18) : partyName; string errMess = $"{name}-خطا"; await _smsService.Alarm("09114221321", errMess); - } count += 1; Console.WriteLine(count); - } } #endregion #endregion - } public async Task GetIdByInstallmentId(long installmentId) { - return await _context.InstitutionContractSet.Include(x=>x.Installments) - .Where(x=>x.Installments.Any(i=>i.Id==installmentId)) - .Select(x=>x.id).FirstOrDefaultAsync(); + return await _context.InstitutionContractSet.Include(x => x.Installments) + .Where(x => x.Installments.Any(i => i.Id == installmentId)) + .Select(x => x.id).FirstOrDefaultAsync(); } #endregion - - #region CustomViewModels public class WorkshopsAndEmployeeViewModel @@ -4587,8 +4612,5 @@ public class InstitutionContractRepository : RepositoryBase