Send Warning and leagal action Message
This commit is contained in:
@@ -6285,58 +6285,6 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
|
||||
|
||||
#region LegalActionSms
|
||||
|
||||
|
||||
public async Task SendLegalActionSmsTask()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
|
||||
// تبدیل تاریخ میلادی به شمسی
|
||||
var persianNow = now.ToFarsi();
|
||||
var persianEndOfMonth = int.Parse(persianNow.FindeEndOfMonth().Substring(8, 2));
|
||||
var dayOfMonth = int.Parse(persianNow.Substring(8, 2));
|
||||
var hour = now.Hour;
|
||||
var minute = now.Minute;
|
||||
var checkAnyToExecute = false;
|
||||
|
||||
//اگر آخرین روز ماه باشد
|
||||
//اگر روز مثلا عدد روز 31 بود ولی آخرین روز ماه 30 بود
|
||||
if (dayOfMonth == persianEndOfMonth)
|
||||
{
|
||||
checkAnyToExecute = await _context.SmsSettings
|
||||
.AnyAsync(x =>
|
||||
x.DayOfMonth >= dayOfMonth &&
|
||||
x.TimeOfDay.Hours == hour &&
|
||||
x.TimeOfDay.Minutes == minute &&
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.LegalAction &&
|
||||
x.IsActive
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkAnyToExecute = await _context.SmsSettings
|
||||
.AnyAsync(x =>
|
||||
x.DayOfMonth == dayOfMonth &&
|
||||
x.TimeOfDay.Hours == hour &&
|
||||
x.TimeOfDay.Minutes == minute &&
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.LegalAction &&
|
||||
x.IsActive
|
||||
);
|
||||
}
|
||||
|
||||
if (checkAnyToExecute)
|
||||
{
|
||||
//اجرای تسک
|
||||
_logger.LogInformation("اجرای تسک ارسال پیامک اقدام قضائی SendLegalActionSms" +
|
||||
persianNow + " - " + hour + ":" + minute);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CustomViewModels
|
||||
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
using _0_Framework.Application.Enums;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Application.Enums;
|
||||
using _0_Framework.Application.Sms;
|
||||
using _0_Framework.InfraStructure;
|
||||
using Company.Domain.InstitutionContractAgg;
|
||||
using Company.Domain.SmsResultAgg;
|
||||
using CompanyManagment.App.Contracts.Hubs;
|
||||
using CompanyManagment.App.Contracts.InstitutionContract;
|
||||
using CompanyManagment.App.Contracts.InstitutionContractContactinfo;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PersianTools.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Application.Sms;
|
||||
using CompanyManagment.App.Contracts.InstitutionContractContactinfo;
|
||||
using PersianTools.Core;
|
||||
|
||||
namespace CompanyManagment.EFCore.Repository;
|
||||
|
||||
@@ -21,15 +25,18 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
private readonly CompanyContext _context;
|
||||
private readonly ILogger<InstitutionContractSmsServiceRepository> _logger;
|
||||
private readonly ISmsService _smsService;
|
||||
public InstitutionContractSmsServiceRepository(CompanyContext context, ISmsService smsService) : base(context)
|
||||
private readonly ISmsResultRepository _smsResultRepository;
|
||||
public InstitutionContractSmsServiceRepository(CompanyContext context, ISmsService smsService, ILogger<InstitutionContractSmsServiceRepository> logger, ISmsResultRepository smsResultRepository) : base(context)
|
||||
{
|
||||
_context = context;
|
||||
_smsService = smsService;
|
||||
_logger = logger;
|
||||
_smsResultRepository = smsResultRepository;
|
||||
}
|
||||
|
||||
#region WarningSms
|
||||
#region WarninSmsAndLegalActionSms
|
||||
|
||||
public async Task SendWarningSmsTask()
|
||||
public async Task SendWarningOrLegalActionSmsTask(TypeOfSmsSetting typeOfSmsSetting)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
@@ -51,7 +58,7 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
x.DayOfMonth >= dayOfMonth &&
|
||||
x.TimeOfDay.Hours == hour &&
|
||||
x.TimeOfDay.Minutes == minute &&
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.Warning &&
|
||||
x.TypeOfSmsSetting == typeOfSmsSetting &&
|
||||
x.IsActive
|
||||
);
|
||||
}
|
||||
@@ -62,7 +69,7 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
x.DayOfMonth == dayOfMonth &&
|
||||
x.TimeOfDay.Hours == hour &&
|
||||
x.TimeOfDay.Minutes == minute &&
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.Warning &&
|
||||
x.TypeOfSmsSetting == typeOfSmsSetting &&
|
||||
x.IsActive
|
||||
);
|
||||
}
|
||||
@@ -71,14 +78,12 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
if (checkAnyToExecute)
|
||||
{
|
||||
|
||||
var getSmsData =await GetWarningOrLegalActionSmsListData(TypeOfSmsSetting.Warning);
|
||||
var getSmsData =await GetWarningOrLegalActionSmsListData(typeOfSmsSetting);
|
||||
await SendWarningOrLegalActionSms(getSmsData, typeOfSmsSetting);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
/// <summary>
|
||||
///دریافت لیست پیامک قراداد های آبی بدهکار
|
||||
/// </summary>
|
||||
@@ -141,237 +146,253 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
var endOfContractNextMonthStart = new PersianDateTime(year, month, 1).AddMonths(1);
|
||||
var endOfContractNextMonthEnd = (($"{endOfContractNextMonthStart}").FindeEndOfMonth()).ToGeorgianDateTime();
|
||||
var now = DateTime.Now;
|
||||
bool executeCondition = false;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(contractingParty.LName) && !hasLegalActionSentSms && now.Date <= endOfContractNextMonthEnd.Date)
|
||||
switch (typeOfSmsSetting)
|
||||
{
|
||||
//Thread.Sleep(500);
|
||||
var partyName = contractingParty.LName;
|
||||
case TypeOfSmsSetting.Warning:
|
||||
executeCondition = !hasLegalActionSentSms && now.Date <= endOfContractNextMonthEnd.Date;
|
||||
|
||||
break;
|
||||
case TypeOfSmsSetting.LegalAction:
|
||||
executeCondition = !hasLegalActionSentSms && now.Date > endOfContractNextMonthEnd.Date;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(contractingParty.LName) && executeCondition)
|
||||
{
|
||||
//Thread.Sleep(500);x.IsLegal == "حقیقی" ? $"{x.FName.Trim()} {x.LName.Trim()}" : $"{x.LName.Trim()}"
|
||||
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 hasFinancialStatement =
|
||||
financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId);
|
||||
|
||||
var hasPhonNumber = phoneNumberList.Any(x => x.InstitutionContractId == item.Id);
|
||||
|
||||
//var id = $"{item.ContractingPartyId}";
|
||||
var aprove = $"{transactions.id}";
|
||||
var balance = debtor - creditor;
|
||||
|
||||
if (balance > 0) // اگر بدهکار بود
|
||||
if (hasFinancialStatement && hasPhonNumber)
|
||||
{
|
||||
var phoneNumbers = phoneNumberList.Where(x => x.InstitutionContractId == item.Id)
|
||||
.Select(x => new CreateContactInfo
|
||||
{
|
||||
PhoneType = x.PhoneType,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
|
||||
if (isLegal)
|
||||
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;
|
||||
|
||||
if (balance > 0) // اگر بدهکار بود
|
||||
{
|
||||
|
||||
if (isLegal)
|
||||
{
|
||||
if (item.OfficialCompany == "Official") // حقوقی بدهکار رسمی
|
||||
{
|
||||
if (item.OfficialCompany == "Official") // حقوقی بدهکار رسمی
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
|
||||
//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);
|
||||
//}
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
|
||||
//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);
|
||||
//}
|
||||
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 608443 : 0,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBill",
|
||||
Code1 = "",
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 608443 : 0,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBill",
|
||||
Code1 = "",
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (item.OfficialCompany == "NotOfficial") // حقوقی بدهکار غیر رسمی
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
|
||||
//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);
|
||||
//}
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 351691 : 0,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBill",
|
||||
Code1 = "",
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
else if (item.OfficialCompany == "NotOfficial") // حقوقی بدهکار غیر رسمی
|
||||
{
|
||||
if (item.OfficialCompany == "Official") // حقیقی بدهکار رسمی
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
//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);
|
||||
//}
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 351691 : 0,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBill",
|
||||
Code1 = "",
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
|
||||
//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);
|
||||
//}
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 190430 : 0,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBill",
|
||||
Code1 = "",
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.OfficialCompany == "Official") // حقیقی بدهکار رسمی
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
|
||||
//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);
|
||||
//}
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 190430 : 0,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBill",
|
||||
Code1 = "",
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (item.OfficialCompany == "NotOfficial") // حقیقی بدهکار غیر رسمی
|
||||
|
||||
|
||||
}
|
||||
else if (item.OfficialCompany == "NotOfficial") // حقیقی بدهکار غیر رسمی
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
//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);
|
||||
//}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
//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);
|
||||
//}
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 412829 : 0,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBill",
|
||||
Code1 = "",
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 412829 : 0,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBill",
|
||||
Code1 = "",
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -397,7 +418,20 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
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)
|
||||
|
||||
bool executeCondition = false;
|
||||
|
||||
switch (typeOfSmsSetting)
|
||||
{
|
||||
case TypeOfSmsSetting.Warning:
|
||||
executeCondition = !hasLegalActionSentSms && now.Date <= endOfContractNextMonthEnd.Date;
|
||||
|
||||
break;
|
||||
case TypeOfSmsSetting.LegalAction:
|
||||
executeCondition = !hasLegalActionSentSms && now.Date > endOfContractNextMonthEnd.Date;
|
||||
break;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(contractingParty.LName) && executeCondition)
|
||||
{
|
||||
var partyName = contractingParty.IsLegal == "حقیقی"
|
||||
? $"{contractingParty.FName} {contractingParty.LName}"
|
||||
@@ -411,68 +445,68 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
//var isBlock = contractingParty.IsBlock == "true" ? true : false;
|
||||
//var isActive = contractingParty.IsActiveString == "true" ? true : false;
|
||||
|
||||
|
||||
var hasFinancialStatement =
|
||||
financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId);
|
||||
|
||||
var hasFinancialStatement =
|
||||
financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId);
|
||||
|
||||
|
||||
var hasPhonNumber = phoneNumberList.Any(x => x.InstitutionContractId == item.Id);
|
||||
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) // اگر بدهکار بود
|
||||
if (hasFinancialStatement && hasPhonNumber)
|
||||
{
|
||||
var phoneNumbers = phoneNumberList.Where(x => x.InstitutionContractId == item.Id)
|
||||
.Select(x => new CreateContactInfo
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
PhoneType = x.PhoneType,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
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()
|
||||
{
|
||||
string publicId = transactions.PublicIdStr;
|
||||
string code1 = publicId.Substring(0, 25);
|
||||
string code2 = publicId.Substring(25);
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = typeOfSmsSetting == TypeOfSmsSetting.Warning ? 530657 : 665145,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBillNew",
|
||||
Code1 = code1,
|
||||
Code2 = code2,
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -484,6 +518,94 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
}
|
||||
return smsList;
|
||||
}
|
||||
|
||||
|
||||
public async Task SendWarningOrLegalActionSms(List<SmsListData> smsListData, TypeOfSmsSetting typeOfSmsSetting)
|
||||
{
|
||||
//ارسال پیامک با اساس لیست
|
||||
|
||||
var typeOfSms = "";
|
||||
|
||||
switch (typeOfSmsSetting)
|
||||
{
|
||||
case TypeOfSmsSetting.Warning:
|
||||
typeOfSms = "هشدار";
|
||||
break;
|
||||
case TypeOfSmsSetting.LegalAction:
|
||||
typeOfSms = "اقدام قضایی";
|
||||
break;
|
||||
}
|
||||
#region SendSMSFromList
|
||||
|
||||
if (smsListData.Any() && !string.IsNullOrWhiteSpace(typeOfSms))
|
||||
{
|
||||
|
||||
|
||||
// int successProcess = 1;
|
||||
//int countList = smsListData.Count;
|
||||
|
||||
|
||||
foreach (var item in smsListData.Take(1))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (item.TypeOfSmsMethod == "MonthlyBill")
|
||||
{
|
||||
var res = await _smsService.MonthlyBill("09114221321", item.TemplateId, item.PartyName,
|
||||
item.Amount,
|
||||
$"{item.ContractingPartyId}", item.AproveId);
|
||||
|
||||
if (res.isSucceded)
|
||||
{
|
||||
var createSmsResult = new Company.Domain.SmsResultAgg.SmsResult(res.messaeId,
|
||||
res.message, typeOfSms, item.PartyName, item.PhoneNumber,
|
||||
item.ContractingPartyId, item.InstitutionContractId);
|
||||
|
||||
await _smsResultRepository.CreateAsync(createSmsResult);
|
||||
await _smsResultRepository.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var res = await _smsService.MonthlyBillNew(item.PhoneNumber, item.TemplateId, item.PartyName,
|
||||
item.Amount, item.Code1, item.Code2);
|
||||
if (res.isSucceded)
|
||||
{
|
||||
var createSmsResult = new Company.Domain.SmsResultAgg.SmsResult(res.messaeId,
|
||||
res.message, typeOfSms, item.PartyName, item.PhoneNumber,
|
||||
item.ContractingPartyId, item.InstitutionContractId);
|
||||
|
||||
await _smsResultRepository.CreateAsync(createSmsResult);
|
||||
await _smsResultRepository.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(600);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string name = item.PartyName.Length > 18 ? item.PartyName.Substring(0, 18) : item.PartyName;
|
||||
string errMess = $"{name}-خطا";
|
||||
_logger.LogError(errMess);
|
||||
await _smsService.Alarm("09114221321", errMess);
|
||||
}
|
||||
|
||||
//var percent = (successProcess / (double)countList) * 100;
|
||||
//await _hubContext.Clients.Group(SendSmsHub.GetGroupName(7))
|
||||
//.SendAsync("showStatus", (int)percent);
|
||||
|
||||
// successProcess += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user