reminderSms Change to electronicInstitutionContract
This commit is contained in:
@@ -35,6 +35,8 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Company.Domain.FinancialInvoiceAgg;
|
||||
using CompanyManagment.App.Contracts.FinancialInvoice;
|
||||
using ContractingPartyAccount = Company.Domain.ContractingPartyAccountAgg.ContractingPartyAccount;
|
||||
using FinancialStatment = Company.Domain.FinancialStatmentAgg.FinancialStatment;
|
||||
using String = System.String;
|
||||
@@ -3828,7 +3830,9 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
#region GetSmsListData
|
||||
|
||||
//var rollcallServiceList = _context.RollCallServices.Where(x => x.StartService.Date <= previusMonthStart.Date && x.EndService.Date >= previusMonthEnd.Date).ToList();
|
||||
var institutionContracts = await _context.InstitutionContractSet.AsSplitQuery().Select(x =>
|
||||
var institutionContracts = await _context.InstitutionContractSet.AsSplitQuery()
|
||||
.Include(x => x.Installments)
|
||||
.Select(x =>
|
||||
new InstitutionContractViewModel
|
||||
{
|
||||
Id = x.id,
|
||||
@@ -3840,11 +3844,24 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
ContractEndFa = x.ContractEndFa,
|
||||
IsActiveString = x.IsActiveString,
|
||||
ContractAmountDouble = x.ContractAmount,
|
||||
OfficialCompany = x.OfficialCompany
|
||||
OfficialCompany = x.OfficialCompany,
|
||||
IsInstallment = x.IsInstallment,
|
||||
VerificationStatus = x.VerificationStatus,
|
||||
SigningType = x.SigningType,
|
||||
InstallmentList = x.Installments
|
||||
.Select(ins => new InstitutionContractInstallmentViewModel
|
||||
{ AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr })
|
||||
.OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(),
|
||||
}).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate &&
|
||||
x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First())
|
||||
x.ContractAmountDouble > 0 && x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify)
|
||||
.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();
|
||||
@@ -3861,7 +3878,15 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
Console.WriteLine("database query: " + watch.Elapsed);
|
||||
watch.Stop();
|
||||
watch.Start();
|
||||
foreach (var item in institutionContracts)
|
||||
|
||||
//var a = new FinancialInvoice(balance, item.ContractingPartyId, "");
|
||||
//var b = new FinancialInvoiceItem("", balance, a.id, FinancialInvoiceItemType.PreviousDebt,
|
||||
// 0);
|
||||
//a.AddItem(b);
|
||||
//_context.Add(a);
|
||||
var oldInstitutionContract = institutionContracts.Where(x => x.IsInstallment == false).ToList();
|
||||
var electronicInstitutionContract = institutionContracts.Where(x => x.IsInstallment == true).ToList();
|
||||
foreach (var item in oldInstitutionContract)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -3913,6 +3938,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
var aprove = $"{transactions.id}";
|
||||
var balance = debtor - creditor;
|
||||
|
||||
|
||||
|
||||
if (balance > 0) // اگر بدهکار بود
|
||||
{
|
||||
//var employers = _context.Employers.Where(x => x.ContractingPartyId == item.ContractingPartyId)
|
||||
@@ -3954,37 +3981,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
int messageId = 0;
|
||||
string message = "";
|
||||
bool isSuccessSend = false;
|
||||
if (hasRollCallService)
|
||||
{
|
||||
string publicId = transactions.PublicIdStr;
|
||||
string code1 = publicId.Substring(0, 25);
|
||||
string code2 = publicId.Substring(25);
|
||||
var templateId = 789638;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 983035;
|
||||
}
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = templateId,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBillNew",
|
||||
Code1 = code1,
|
||||
Code2 = code2,
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var templateId = 161233;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
@@ -4005,7 +4002,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4017,37 +4014,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
int messageId = 0;
|
||||
string message = "";
|
||||
bool isSuccessSend = false;
|
||||
if (hasRollCallService)
|
||||
{
|
||||
string publicId = transactions.PublicIdStr;
|
||||
string code1 = publicId.Substring(0, 25);
|
||||
string code2 = publicId.Substring(25);
|
||||
var templateId = 789638;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 983035;
|
||||
}
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = templateId,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBillNew",
|
||||
Code1 = code1,
|
||||
Code2 = code2,
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var templateId = 347415;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
@@ -4068,7 +4035,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4084,37 +4051,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
int messageId = 0;
|
||||
string message = "";
|
||||
bool isSuccessSend = false;
|
||||
if (hasRollCallService)
|
||||
{
|
||||
string publicId = transactions.PublicIdStr;
|
||||
string code1 = publicId.Substring(0, 25);
|
||||
string code2 = publicId.Substring(25);
|
||||
var templateId = 768277;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 479624;
|
||||
}
|
||||
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = templateId,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBillNew",
|
||||
Code1 = code1,
|
||||
Code2 = code2,
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var templateId = 998180;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
@@ -4135,7 +4072,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4148,39 +4085,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11)
|
||||
{
|
||||
int messageId = 0;
|
||||
string message = "";
|
||||
bool isSuccessSend = false;
|
||||
|
||||
|
||||
|
||||
if (hasRollCallService)
|
||||
{
|
||||
var templateId = 768277;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 479624;
|
||||
}
|
||||
|
||||
string publicId = transactions.PublicIdStr;
|
||||
string code1 = publicId.Substring(0, 25);
|
||||
string code2 = publicId.Substring(25);
|
||||
smsList.Add(new SmsListData()
|
||||
{
|
||||
PhoneNumber = number.PhoneNumber,
|
||||
TemplateId = templateId,
|
||||
PartyName = partyName,
|
||||
Amount = balanceToMoney,
|
||||
ContractingPartyId = contractingParty.id,
|
||||
AproveId = aprove,
|
||||
TypeOfSmsMethod = "MonthlyBillNew",
|
||||
Code1 = code1,
|
||||
Code2 = code2,
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var templateId = 810539;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
@@ -4201,7 +4107,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
Code2 = "",
|
||||
InstitutionContractId = item.Id
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4224,6 +4130,116 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in electronicInstitutionContract)
|
||||
{
|
||||
try
|
||||
{
|
||||
var contractingParty = contractingPartyList.FirstOrDefault(x => x.id == item.ContractingPartyId);
|
||||
if (!string.IsNullOrWhiteSpace(contractingParty.LName))
|
||||
{
|
||||
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;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(contractingParty.IsActiveString) && isActive)
|
||||
{
|
||||
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 (isLegal)
|
||||
{
|
||||
templateId = 789638;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 983035;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
templateId = 768277;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 479624;
|
||||
}
|
||||
}
|
||||
|
||||
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 = templateId,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
Console.WriteLine("SmsListData: " + watch.Elapsed);
|
||||
|
||||
Reference in New Issue
Block a user