diff --git a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Jobs/JobSchedulerRegistrator.cs b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Jobs/JobSchedulerRegistrator.cs
index 7eaab611..f368cb3e 100644
--- a/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Jobs/JobSchedulerRegistrator.cs
+++ b/BackgroundInstitutionContract/BackgroundInstitutionContract.Task/Jobs/JobSchedulerRegistrator.cs
@@ -58,17 +58,17 @@ public class JobSchedulerRegistrator
"*/1 * * * *" // هر 1 دقیقه یکبار چک کن
);
- RecurringJob.AddOrUpdate(
- "InstitutionContract.SendWarningSms",
- () => SendWarningSms(),
- "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
- );
+ //RecurringJob.AddOrUpdate(
+ // "InstitutionContract.SendWarningSms",
+ // () => SendWarningSms(),
+ // "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
+ //);
- RecurringJob.AddOrUpdate(
- "InstitutionContract.SendLegalActionSms",
- () => SendLegalActionSms(),
- "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
- );
+ //RecurringJob.AddOrUpdate(
+ // "InstitutionContract.SendLegalActionSms",
+ // () => SendLegalActionSms(),
+ // "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
+ //);
}
diff --git a/CompanyManagment.App.Contracts/InstitutionContract/SmsListData.cs b/CompanyManagment.App.Contracts/InstitutionContract/SmsListData.cs
index 538c7906..e81a8ecf 100644
--- a/CompanyManagment.App.Contracts/InstitutionContract/SmsListData.cs
+++ b/CompanyManagment.App.Contracts/InstitutionContract/SmsListData.cs
@@ -109,4 +109,14 @@ public class BlockSmsListData
/// پابلیک آی دی بخش دو
///
public string Code2 { get; set; }
+}
+
+
+///
+/// لیست قراداد های آبی
+/// جهت ارسال هشدار یا اقدام قضائی
+///
+public class BlueWarningSmsData
+{
+
}
\ No newline at end of file
diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs
index 75a73c55..d240d0e7 100644
--- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs
+++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs
@@ -3561,7 +3561,7 @@ public class InstitutionContractRepository : RepositoryBase SendReminderSmsForBackgroundTask()
{
var now = DateTime.Now;
- _logger.LogInformation("================>> SendReminderSmsForBackgroundTask job run");
+
// تبدیل تاریخ میلادی به شمسی
var persianNow = now.ToFarsi();
@@ -6333,6 +6333,269 @@ public class InstitutionContractRepository : RepositoryBase
+ ///دریافت لیست پیامک قرادا های آبی بدهکار
+ ///
+ ///
+ public async Task> GetBlueSmsListData()
+ {
+
+ var institutionContracts = await _context.InstitutionContractSet.AsQueryable().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,
+ IsInstallment = x.IsInstallment,
+ VerificationStatus = x.VerificationStatus,
+ SigningType = x.SigningType,
+ }).Where(x => x.IsActiveString == "blue" &&
+ x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First()).ToListAsync();
+
+ // قرارداد هایی که بطور یکجا پرداخت شده اند
+ var paidInFull = institutionContracts.Where(x =>
+ x.SigningType != InstitutionContractSigningType.Legacy && x.IsInstallment == false && x.SigningType != null).ToList();
+
+ //حذف قراداد هایی که یکجا پرداخت شده اند از لیست ایجاد سند ماهانه
+ institutionContracts = institutionContracts.Except(paidInFull).ToList();
+
+ var contractingPartyList = await _context.PersonalContractingParties
+ .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();
+
+ var phoneNumberList = await _context.InstitutionContractContactInfos
+ .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();
+ var legalActionSentSms =await _context.SmsResults
+ .Where(x => x.TypeOfSms == "اقدام قضایی").ToListAsync();
+ var warningSentSms = await _context.SmsResults.Where(x => x.TypeOfSms.Contains("هشدار")).ToListAsync();
+
+ var oldInstitutionContract = institutionContracts.Where(x => x.IsInstallment == false).ToList();
+ var electronicInstitutionContract = institutionContracts.Where(x => x.IsInstallment == true).ToList();
+
+ foreach (var item in oldInstitutionContract)
+ {
+ try
+ {
+ var contractingParty = GetDetails(item.ContractingPartyId);
+ bool hasLegalActionSentSms = legalActionSentSms.Any(x => x.InstitutionContractId == item.Id);
+
+ if (!string.IsNullOrWhiteSpace(contractingParty.LName) && !hasLegalActionSentSms)
+ {
+ //Thread.Sleep(500);
+ var partyName = contractingParty.LName;
+
+ 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;
+ if (!string.IsNullOrWhiteSpace(contractingParty.IsActiveString))
+ {
+ 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.FinancialTransactionViewModels.Sum(x => x.Deptor);
+ var creditor = transactions.FinancialTransactionViewModels.Sum(x => x.Creditor);
+
+
+ var id = $"{item.ContractingPartyId}";
+ var aprove = $"{transactions.Id}";
+ var balance = debtor - creditor;
+
+ if (balance > 0) // اگر بدهکار بود
+ {
+
+ if (isLegal)
+ {
+ if (item.OfficialCompany == "Official") // حقوقی بدهکار رسمی
+ {
+ var balanceToMoney = balance.ToMoney();
+
+ foreach (var number in phoneNumbers)
+ {
+
+ var isLastAlarmSend = _context.SmsResults.Any(x => (
+ x.ContractingPatyId == contractingParty.Id &&
+ x.Mobile == number.PhoneNumber) && (x.TypeOfSms == "اقدام قضایی" || x.TypeOfSms == "هشدار دوم"));
+
+ if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
+ number.PhoneNumber.Length == 11 && !isSend && !isLastAlarmSend)
+ {
+
+ var smsResult = _smsService.MonthlyBill(number.PhoneNumber, 608443,
+ partyName,
+ balanceToMoney, id, aprove);
+ Thread.Sleep(1000);
+ if (smsResult.IsSuccedded)
+ {
+ var createSmsResult = new SmsResult(smsResult.MessageId,
+ smsResult.Message, typeOfSms, partyName, number.PhoneNumber,
+ item.ContractingPartyId, item.Id);
+ _smsResultRepository.Create(createSmsResult);
+ _smsResultRepository.SaveChanges();
+ Thread.Sleep(1000);
+ }
+
+ }
+ }
+
+
+
+ }
+ else if (item.OfficialCompany == "NotOfficial") // حقوقی بدهکار غیر رسمی
+ {
+ var balanceToMoney = balance.ToMoney();
+ foreach (var number in phoneNumbers)
+ {
+ var isSend = _context.SmsResults.Any(x =>
+ x.ContractingPatyId == contractingParty.Id &&
+ x.Mobile == number.PhoneNumber && x.TypeOfSms == typeOfSms);
+ var isLastAlarmSend = _context.SmsResults.Any(x => (
+ x.ContractingPatyId == contractingParty.Id &&
+ x.Mobile == number.PhoneNumber) && (x.TypeOfSms == "اقدام قضایی" || x.TypeOfSms == "هشدار دوم"));
+ if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
+ number.PhoneNumber.Length == 11 && !isSend && !isLastAlarmSend)
+ {
+
+ var smsResult = _smsService.MonthlyBill(number.PhoneNumber, 351691,
+ partyName,
+ balanceToMoney, id, aprove);
+ Thread.Sleep(1000);
+ if (smsResult.IsSuccedded)
+ {
+ var createSmsResult = new SmsResult(smsResult.MessageId,
+ smsResult.Message, typeOfSms, partyName, number.PhoneNumber,
+ item.ContractingPartyId, item.Id);
+ _smsResultRepository.Create(createSmsResult);
+ _smsResultRepository.SaveChanges();
+ Thread.Sleep(1000);
+ }
+
+
+
+ }
+ }
+
+
+ }
+ }
+ else
+ {
+ if (item.OfficialCompany == "Official") // حقیقی بدهکار رسمی
+ {
+ var balanceToMoney = balance.ToMoney();
+
+ foreach (var number in phoneNumbers)
+ {
+ var isSend = _context.SmsResults.Any(x =>
+ x.ContractingPatyId == contractingParty.Id &&
+ x.Mobile == number.PhoneNumber && x.TypeOfSms == typeOfSms);
+ var isLastAlarmSend = _context.SmsResults.Any(x => (
+ x.ContractingPatyId == contractingParty.Id &&
+ x.Mobile == number.PhoneNumber) && (x.TypeOfSms == "اقدام قضایی" || x.TypeOfSms == "هشدار دوم"));
+ if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
+ number.PhoneNumber.Length == 11 && !isSend && !isLastAlarmSend)
+ {
+
+ var smsResult = _smsService.MonthlyBill(number.PhoneNumber, 190430,
+ partyName,
+ balanceToMoney, id, aprove);
+ Thread.Sleep(1000);
+ if (smsResult.IsSuccedded)
+ {
+ var createSmsResult = new SmsResult(smsResult.MessageId,
+ smsResult.Message, typeOfSms, partyName, number.PhoneNumber,
+ item.ContractingPartyId, item.Id);
+ _smsResultRepository.Create(createSmsResult);
+ _smsResultRepository.SaveChanges();
+ Thread.Sleep(1000);
+ }
+ }
+ }
+
+
+ }
+ else if (item.OfficialCompany == "NotOfficial") // حقیقی بدهکار غیر رسمی
+ {
+ var balanceToMoney = balance.ToMoney();
+
+ foreach (var number in phoneNumbers)
+ {
+ var isSend = _context.SmsResults.Any(x =>
+ x.ContractingPatyId == contractingParty.Id &&
+ x.Mobile == number.PhoneNumber && x.TypeOfSms == typeOfSms);
+ var isLastAlarmSend = _context.SmsResults.Any(x => (
+ x.ContractingPatyId == contractingParty.Id &&
+ x.Mobile == number.PhoneNumber) && (x.TypeOfSms == "اقدام قضایی" || x.TypeOfSms == "هشدار دوم"));
+ if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
+ number.PhoneNumber.Length == 11 && !isSend && !isLastAlarmSend)
+ {
+ var smsResult = _smsService.MonthlyBill(number.PhoneNumber, 412829,
+ partyName,
+ balanceToMoney, id, aprove);
+ Thread.Sleep(1000);
+ if (smsResult.IsSuccedded)
+ {
+ var createSmsResult = new SmsResult(smsResult.MessageId,
+ smsResult.Message, typeOfSms, partyName, number.PhoneNumber,
+ item.ContractingPartyId, item.Id);
+ _smsResultRepository.Create(createSmsResult);
+ _smsResultRepository.SaveChanges();
+ Thread.Sleep(1000);
+ }
+
+
+ }
+ }
+
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+
+
+ string name = item.ContractingPartyName.Length > 18 ? item.ContractingPartyName.Substring(0, 18) : item.ContractingPartyName;
+ string errMess = $"{name}-خطا";
+ _smsService.Alarm("09114221321", errMess);
+ _logger.LogError(e, "BlueWarningSms");
+ }
+ }
+ }
#endregion