From 5202779d9f04a7c8a79167a12567356748e2b0e6 Mon Sep 17 00:00:00 2001 From: SamSys Date: Thu, 8 Jan 2026 12:18:01 +0330 Subject: [PATCH] changes --- ...InstitutionContractSmsServiceRepository.cs | 120 ++++++++++++++++-- ServiceHost/Program.cs | 17 +-- 2 files changed, 109 insertions(+), 28 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractSmsServiceRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractSmsServiceRepository.cs index d8a5da00..3661fbf1 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractSmsServiceRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractSmsServiceRepository.cs @@ -104,7 +104,6 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase x.IsActiveString == "blue" && x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First()).ToListAsync(); - var institutionContractsIds = institutionContracts.Select(x => x.Id).ToList(); // قرارداد هایی که بطور یکجا پرداخت شده اند var paidInFull = institutionContracts.Where(x => @@ -126,7 +125,7 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase x.TypeOfSms == "اقدام قضایی").AsNoTracking().ToListAsync(); - var warningSentSms = await _context.SmsResults.Where(x => x.TypeOfSms.Contains("هشدار")).AsNoTracking().ToListAsync(); + var oldInstitutionContract = institutionContracts.Where(x => x.IsInstallment == false).ToList(); var electronicInstitutionContract = institutionContracts.Where(x => x.IsInstallment == true).ToList(); @@ -151,10 +150,10 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase 25) partyName = $"{partyName.Substring(0, 25)}"; var isLegal = contractingParty.IsLegal == "حقوقی" ? true : false; - var isBlock = contractingParty.IsBlock == "true" ? true : false; - var isActive = contractingParty.IsActiveString == "true" ? true : false; - if (!string.IsNullOrWhiteSpace(contractingParty.IsActiveString)) - { + //var isBlock = contractingParty.IsBlock == "true" ? true : false; + //var isActive = contractingParty.IsActiveString == "true" ? true : false; + + var hasFinancialStatement = financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId); @@ -180,7 +179,7 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase x.Creditor); - var id = $"{item.ContractingPartyId}"; + //var id = $"{item.ContractingPartyId}"; var aprove = $"{transactions.id}"; var balance = debtor - creditor; @@ -220,7 +219,7 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase x.id == item.ContractingPartyId); + bool hasLegalActionSentSms = legalActionSentSms.Any(x => x.InstitutionContractId == item.Id); + int year = Convert.ToInt32(item.ContractEndFa.Substring(0, 4)); + int month = Convert.ToInt32(item.ContractEndFa.Substring(5, 2)); + var endOfContractNextMonthStart = new PersianDateTime(year, month, 1).AddMonths(1); + var endOfContractNextMonthEnd = (($"{endOfContractNextMonthStart}").FindeEndOfMonth()).ToGeorgianDateTime(); + var now = DateTime.Now; + if (!string.IsNullOrWhiteSpace(contractingParty.LName) && !hasLegalActionSentSms && now.Date <= endOfContractNextMonthEnd.Date) + { + var partyName = contractingParty.IsLegal == "حقیقی" + ? $"{contractingParty.FName} {contractingParty.LName}" + : $"{contractingParty.LName}"; + if (!string.IsNullOrWhiteSpace(contractingParty.SureName)) + partyName = $"{partyName} ({contractingParty.SureName})"; + + if (partyName.Length > 25) partyName = $"{partyName.Substring(0, 25)}"; + + //var isLegal = contractingParty.IsLegal == "حقوقی" ? true : false; + //var isBlock = contractingParty.IsBlock == "true" ? true : false; + //var isActive = contractingParty.IsActiveString == "true" ? true : false; + + + var hasFinancialStatement = + financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId); + + + var hasPhonNumber = phoneNumberList.Any(x => x.InstitutionContractId == item.Id); + + if (hasFinancialStatement && hasPhonNumber) + { + var phoneNumbers = phoneNumberList.Where(x => x.InstitutionContractId == item.Id) + .Select(x => new CreateContactInfo + { + PhoneType = x.PhoneType, + PhoneNumber = x.PhoneNumber, + + InstitutionContractId = x.InstitutionContractId, + SendSms = x.SendSms + }).Where(x => x.PhoneNumber.Length == 11).ToList(); + + 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}"; + var balance = debtor - creditor; + int templateId = 0; + //انتخاب قالب پیامک بر اساس حقیق/حقوقی + + + if (balance > 0) // اگر بدهکار بود + { + var balanceToMoney = balance.ToMoney(); + + foreach (var number in phoneNumbers) + { + string publicId = transactions.PublicIdStr; + string code1 = publicId.Substring(0, 25); + string code2 = publicId.Substring(25); + + + smsList.Add(new SmsListData() + { + PhoneNumber = number.PhoneNumber, + TemplateId = 530657, + PartyName = partyName, + Amount = balanceToMoney, + ContractingPartyId = contractingParty.id, + AproveId = aprove, + TypeOfSmsMethod = "MonthlyBillNew", + Code1 = code1, + Code2 = code2, + InstitutionContractId = item.Id + }); + + } + } + } + + } + + } + catch (Exception e) + { + _logger.LogError($"ContractingPartyId : {item.ContractingPartyId} - ContractingPartyName : {item.ContractingPartyName} - InstitutionContractId : {item.Id} خطای دریافت لیست بدهکاران "); + throw; + } + } return smsList; } } diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index ee563bb8..4f707f61 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -381,22 +381,7 @@ builder.Services.AddParbad().ConfigureGateways(gateways => // فقط Serilog برای File استفاده می‌شه، کنسول از لاگر پیش‌فرض ASP.NET استفاده می‌کنه -builder.Host.UseSerilog((context, services, configuration) => -{ - var logConfig = configuration - .ReadFrom.Configuration(context.Configuration) - .ReadFrom.Services(services) - .Enrich.FromLogContext(); - - - logConfig.WriteTo.File( - path: Path.Combine(logDirectory, "gozareshgir_log.txt"), - rollingInterval: RollingInterval.Day, - retainedFileCountLimit: 30, - shared: true, - outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}" - ); -}, writeToProviders: true); // این باعث میشه کنسول پیش‌فرض هم کار کنه +builder.Host.UseSerilog(); // این باعث میشه کنسول پیش‌فرض هم کار کنه Log.Information("SERILOG STARTED SUCCESSFULLY");