MontlySms and blockSms Background Task Completed
This commit is contained in:
11143
CompanyManagment.EFCore/Migrations/20251116133447_addIsActiveToSmsSeting.Designer.cs
generated
Normal file
11143
CompanyManagment.EFCore/Migrations/20251116133447_addIsActiveToSmsSeting.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CompanyManagment.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class addIsActiveToSmsSeting : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsActive",
|
||||
table: "SmsSettings",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsActive",
|
||||
table: "SmsSettings");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5648,6 +5648,9 @@ namespace CompanyManagment.EFCore.Migrations
|
||||
b.Property<int>("DayOfMonth")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<TimeSpan>("TimeOfDay")
|
||||
.HasColumnType("time(0)");
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -833,7 +834,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
#region RollcallServicCreateTransaction
|
||||
|
||||
public void RollcallServiceCreateTransaction()
|
||||
public async Task RollCallServiceCreateTransaction()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
var nowFa = now.ToFarsi();
|
||||
@@ -2954,8 +2955,17 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
#endregion
|
||||
|
||||
#region DebtReminderSms
|
||||
|
||||
|
||||
|
||||
|
||||
#region DebtReminderSms
|
||||
|
||||
/// <summary>
|
||||
/// دریافت لیست - ارسال پیامک
|
||||
/// فراخوانی از سمت بک گراند سرویس
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SendReminderSmsForBackgroundTask()
|
||||
{
|
||||
|
||||
@@ -2980,7 +2990,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
x.DayOfMonth >= dayOfMonth &&
|
||||
x.TimeOfDay.Hours == hour &&
|
||||
x.TimeOfDay.Minutes == minute &&
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractDebtReminder
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractDebtReminder &&
|
||||
x.IsActive
|
||||
);
|
||||
}
|
||||
else
|
||||
@@ -2990,7 +3001,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
x.DayOfMonth == dayOfMonth &&
|
||||
x.TimeOfDay.Hours == hour &&
|
||||
x.TimeOfDay.Minutes == minute &&
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractDebtReminder
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractDebtReminder &&
|
||||
x.IsActive
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3002,10 +3014,12 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
//اجرای تسک
|
||||
|
||||
//دریافت لیست بدهکاران
|
||||
var smsListData = await GetSmsListData(now);
|
||||
|
||||
var smsListData = await GetSmsListData(now, TypeOfSmsSetting.InstitutionContractDebtReminder);
|
||||
string typeOfSms = "یادآور بدهی ماهانه";
|
||||
string sendMessStart = "شروع پیامک یادآور";
|
||||
string sendMessEnd = "پایان پیامک یادآور";
|
||||
//ارسال پیامک
|
||||
await SendReminderSmsToContractingParties(smsListData);
|
||||
await SendReminderSmsToContractingParties(smsListData, typeOfSms, sendMessStart, sendMessEnd);
|
||||
|
||||
|
||||
Console.WriteLine("executed at : " + persianNow + " - " + hour + ":" + minute);
|
||||
@@ -3016,7 +3030,222 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<SmsListData>> GetSmsListData(DateTime checkDate)
|
||||
#region MonthlySms
|
||||
/// <summary>
|
||||
/// ارسال پیامک صورت حساب ماهانه
|
||||
/// </summary>
|
||||
/// <param name="now"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SendMonthlySms(DateTime now)
|
||||
{
|
||||
//دریافت لیست بدهکاران
|
||||
var smsListData = await GetSmsListData(now, TypeOfSmsSetting.MonthlyInstitutionContract);
|
||||
|
||||
string typeOfSms = "صورت حساب ماهانه";
|
||||
string sendMessStart = "شروع پیامک ماهانه";
|
||||
string sendMessEnd = "پایان پیامک ماهانه";
|
||||
//ارسال پیامک
|
||||
await SendReminderSmsToContractingParties(smsListData, typeOfSms, sendMessStart, sendMessEnd);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BlockSms
|
||||
/// <summary>
|
||||
/// پیامک بلاک
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task SendBlockSmsForBackgroundTask()
|
||||
{
|
||||
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.BlockContractingParty &&
|
||||
x.IsActive
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkAnyToExecute = await _context.SmsSettings
|
||||
.AnyAsync(x =>
|
||||
x.DayOfMonth == dayOfMonth &&
|
||||
x.TimeOfDay.Hours == hour &&
|
||||
x.TimeOfDay.Minutes == minute &&
|
||||
x.TypeOfSmsSetting == TypeOfSmsSetting.BlockContractingParty &&
|
||||
x.IsActive
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (checkAnyToExecute)
|
||||
{
|
||||
//اجرای تسک
|
||||
|
||||
//دریافت لیست بدهکاران
|
||||
var smsListData = await GetBlockListData(now);
|
||||
string typeOfSms = "اعلام مسدودی طرف حساب";
|
||||
string sendMessStart = "شروع پیامک مسدودی";
|
||||
string sendMessEnd = "پایان پیامک مسدودی";
|
||||
//ارسال پیامک
|
||||
|
||||
await SendBlockSmsToContractingParties(smsListData, typeOfSms, sendMessStart, sendMessEnd);
|
||||
|
||||
Console.WriteLine("executed at : " + persianNow + " - " + hour + ":" + minute);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<List<BlockSmsListData>> GetBlockListData(DateTime checkDate)
|
||||
{
|
||||
var smsList = new List<BlockSmsListData>();
|
||||
|
||||
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();
|
||||
|
||||
|
||||
foreach (var item in institutionContracts)
|
||||
{
|
||||
try
|
||||
{
|
||||
var contractingParty = await _context.PersonalContractingParties.FirstOrDefaultAsync(x => x.id == item.ContractingPartyId);
|
||||
if (contractingParty != null && contractingParty.IsBlock == "true")
|
||||
{
|
||||
|
||||
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 hasFinancialStatment =await _context.FinancialStatments.Include(x => x.FinancialTransactionList).AnyAsync(
|
||||
x => x.ContractingPartyId == item.ContractingPartyId && x.FinancialTransactionList.Count > 0);
|
||||
|
||||
var hasPhonNumber =await _context.InstitutionContractContactInfos
|
||||
.AnyAsync(x => x.InstitutionContractId == item.Id && x.SendSms && x.PhoneType == "شماره همراه" &&
|
||||
x.PhoneNumber.Length == 11);
|
||||
|
||||
|
||||
|
||||
if (hasFinancialStatment && hasPhonNumber)
|
||||
{
|
||||
|
||||
var transactions = GetFinancialByContractingPartyId(contractingParty.id).GetAwaiter().GetResult();
|
||||
|
||||
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)
|
||||
{
|
||||
var jobRelation = "بابت قرارداد مابین (روابط کار)";
|
||||
var taxAndFinancial = "بابت قرارداد مابین (حسابداری و مالیات)";
|
||||
|
||||
|
||||
var jobRelationContract = transactions.FinancialTransactionViewModels
|
||||
.OrderByDescending(x => x.TdateGr).FirstOrDefault(x =>
|
||||
x.TypeOfTransaction == "debt" && x.DescriptionOption == jobRelation);
|
||||
var taxAndFinancialContract = transactions.FinancialTransactionViewModels
|
||||
.OrderByDescending(x => x.TdateGr).FirstOrDefault(x =>
|
||||
x.TypeOfTransaction == "debt" && x.DescriptionOption == taxAndFinancial);
|
||||
|
||||
var jobRelationContractAmounts =
|
||||
jobRelationContract != null ? jobRelationContract.Deptor : 0;
|
||||
var taxAndFinancialContractAmounts =
|
||||
taxAndFinancialContract != null ? taxAndFinancialContract.Deptor : 0;
|
||||
|
||||
var sumOfAmounts = jobRelationContractAmounts * 2 + taxAndFinancialContractAmounts * 2;
|
||||
if (balance >= sumOfAmounts)
|
||||
{
|
||||
var phoneNumbers = new List<CreateContactInfo>();
|
||||
phoneNumbers = await _context.InstitutionContractContactInfos.Where(n =>
|
||||
n.InstitutionContractId == item.Id && n.SendSms && n.PhoneType == "شماره همراه" &&
|
||||
!string.IsNullOrWhiteSpace(n.PhoneNumber))
|
||||
.Select(x => new CreateContactInfo
|
||||
{
|
||||
PhoneType = x.PhoneType,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
|
||||
InstitutionContractId = x.InstitutionContractId,
|
||||
SendSms = x.SendSms
|
||||
}).Where(x => x.PhoneNumber.Length == 11).ToListAsync();
|
||||
|
||||
var accountType = item.OfficialCompany == "Official" ? "ol" : "nol";
|
||||
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
var amount = balanceToMoney + " " + "ریال" + " ";
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
smsList.Add(new BlockSmsListData() { PhoneNumber = number.PhoneNumber, PartyName = partyName,AccountType = accountType, Amount = amount, ContractingPartyId = contractingParty.id, InstitutionContractId = item.Id, AproveId = aprove});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string name = item.ContractingPartyName.Length > 18 ? item.ContractingPartyName.Substring(0, 18) : item.ContractingPartyName;
|
||||
string errMess = $"{name}-خطا";
|
||||
await _smsService.Alarm("09114221321", errMess);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return smsList;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///دریافت لیست بدهکارن
|
||||
/// جهت ارسال پیامک
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SmsListData>> GetSmsListData(DateTime checkDate, TypeOfSmsSetting typeOfSmsSetting)
|
||||
{
|
||||
|
||||
|
||||
@@ -3055,7 +3284,9 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
if (!string.IsNullOrWhiteSpace(contractingParty.LName))
|
||||
{
|
||||
//Thread.Sleep(500);
|
||||
var partyName = 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)}";
|
||||
|
||||
@@ -3147,15 +3378,26 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
string publicId = transactions.PublicId;
|
||||
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 = 789638, 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 = 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)
|
||||
{
|
||||
templateId = 394006;
|
||||
}
|
||||
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = 161233, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = templateId, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
|
||||
}
|
||||
|
||||
@@ -3182,14 +3424,26 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
string publicId = transactions.PublicId;
|
||||
string code1 = publicId.Substring(0, 25);
|
||||
string code2 = publicId.Substring(25);
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = 789638, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBillNew", Code1 = code1, Code2 = code2, InstitutionContractId = item.Id });
|
||||
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
|
||||
{
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = 347415, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
var templateId = 347415;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 679068;
|
||||
}
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = templateId, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
|
||||
}
|
||||
|
||||
@@ -3219,14 +3473,25 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
string publicId = transactions.PublicId;
|
||||
string code1 = publicId.Substring(0, 25);
|
||||
string code2 = publicId.Substring(25);
|
||||
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = 768277, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBillNew", Code1 = code1, Code2 = code2, InstitutionContractId = item.Id });
|
||||
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
|
||||
{
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = 998180, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
var templateId = 998180;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 646040;
|
||||
}
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = templateId, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3247,18 +3512,32 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
int messageId = 0;
|
||||
string message = "";
|
||||
bool isSuccessSend = false;
|
||||
|
||||
|
||||
if (hasRollCallService)
|
||||
{
|
||||
var templateId = 768277;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 479624;
|
||||
}
|
||||
string publicId = transactions.PublicId;
|
||||
string code1 = publicId.Substring(0, 25);
|
||||
string code2 = publicId.Substring(25);
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = 768277, 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 = templateId, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBillNew", Code1 = code1, Code2 = code2, InstitutionContractId = item.Id });
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = 810539, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
var templateId = 810539;
|
||||
if (typeOfSmsSetting ==
|
||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||
{
|
||||
templateId = 566537;
|
||||
}
|
||||
smsList.Add(new SmsListData() { PhoneNumber = number.PhoneNumber, TemplateId = templateId, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3292,17 +3571,61 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
}
|
||||
|
||||
public async Task SendReminderSmsToContractingParties(List<SmsListData> smsListData)
|
||||
public async Task SendBlockSmsToContractingParties(List<BlockSmsListData> smsListData, string typeOfSms,
|
||||
string sendMessStart, string sendMessEnd)
|
||||
{
|
||||
if (smsListData.Any())
|
||||
{
|
||||
|
||||
await _smsService.Alarm("09114221321", sendMessStart);
|
||||
Thread.Sleep(1000);
|
||||
await _smsService.Alarm("09111485044", sendMessStart);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
foreach (var item in smsListData)
|
||||
{
|
||||
try
|
||||
{
|
||||
var smsResult =await _smsService.BlockMessage(item.PhoneNumber, item.PartyName,
|
||||
item.Amount, item.AccountType, $"{item.ContractingPartyId}", item.AproveId);
|
||||
Thread.Sleep(1000);
|
||||
var createSmsResult = new Company.Domain.SmsResultAgg.SmsResult(smsResult.messaeId, smsResult.message, typeOfSms,
|
||||
item.PartyName, item.PhoneNumber, item.ContractingPartyId, item.InstitutionContractId);
|
||||
await _smsResultRepository.CreateAsync(createSmsResult);
|
||||
await _smsResultRepository.SaveChangesAsync();
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string name = item.PartyName.Length > 18 ? item.PartyName.Substring(0, 18) : item.PartyName;
|
||||
string errMess = $"{name}-خطا";
|
||||
await _smsService.Alarm("09114221321", errMess);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
await _smsService.Alarm("09114221321", sendMessEnd);
|
||||
Thread.Sleep(1000);
|
||||
await _smsService.Alarm("09111485044", sendMessEnd);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ارسال پیامک های یاد آور بدهی
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task SendReminderSmsToContractingParties(List<SmsListData> smsListData, string typeOfSms, string sendMessStart, string sendMessEnd)
|
||||
{
|
||||
//ارسال پیامک با اساس لیست
|
||||
#region SendSMSFromList
|
||||
|
||||
var typeOfSms = "یادآور بدهی ماهانه";
|
||||
|
||||
|
||||
if (smsListData.Any())
|
||||
{
|
||||
var sendMessStart = "شروع پیامک یادآور";
|
||||
var sendMessEnd = " پایان پیامک یادآور";
|
||||
|
||||
await _smsService.Alarm("09114221321", sendMessStart);
|
||||
Thread.Sleep(1000);
|
||||
await _smsService.Alarm("09111485044", sendMessStart);
|
||||
@@ -3414,10 +3737,10 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
#region CreateMontlyTransaction
|
||||
|
||||
/// <summary>
|
||||
/// ایجاد سند مالی برای قرارداد های قدیمی بدون قسط
|
||||
/// ایجاد سند مالی برای قرارداد ها
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CreateTransactionOldInstitutionContracts(DateTime endOfMonthGr, string endOfMonthFa, string description)
|
||||
public async Task CreateTransactionForInstitutionContracts(DateTime endOfMonthGr, string endOfMonthFa, string description)
|
||||
{
|
||||
|
||||
#region FindeNextMonth 1th
|
||||
@@ -3444,7 +3767,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
ContractAmountDouble = x.ContractAmount,
|
||||
TypeOfContract = x.TypeOfContract,
|
||||
IsInstallment = x.IsInstallment,
|
||||
PublicId = x.PublicId.ToString(),
|
||||
VerificationStatus = x.VerificationStatus,
|
||||
InstallmentList = x.Installments.Select(ins => new InstitutionContractInstallmentViewModel { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }).OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(),
|
||||
|
||||
}).Where(x =>
|
||||
@@ -3486,7 +3809,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
ContractAmountDouble = x.ContractAmount,
|
||||
TypeOfContract = x.TypeOfContract,
|
||||
IsInstallment = x.IsInstallment,
|
||||
PublicId = x.PublicId.ToString(),
|
||||
VerificationStatus = x.VerificationStatus,
|
||||
InstallmentList = x.Installments.Select(ins => new InstitutionContractInstallmentViewModel { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }).OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(),
|
||||
}).ToListAsync();
|
||||
|
||||
@@ -3497,14 +3820,25 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region RollCallServicCompute
|
||||
|
||||
var rollcallServiceList = await
|
||||
_context.RollCallServices.Where(x => 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);
|
||||
Thread.Sleep(500);
|
||||
|
||||
|
||||
|
||||
|
||||
string partyName = item.ContractingPartyName;
|
||||
if (partyName.Length > 18) partyName = $"{partyName.Substring(0, 18)}";
|
||||
@@ -3536,7 +3870,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
|
||||
|
||||
if (item.IsInstallment && !string.IsNullOrWhiteSpace(item.PublicId))
|
||||
if (item.IsInstallment && item.VerificationStatus == InstitutionContractVerificationStatus.Verified)
|
||||
{
|
||||
var instalment = item.InstallmentList
|
||||
.FirstOrDefault(x =>
|
||||
@@ -3576,7 +3910,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
await _financialStatmentRepository.SaveChangesAsync();
|
||||
|
||||
|
||||
if (item.IsInstallment && !string.IsNullOrWhiteSpace(item.PublicId))
|
||||
if (item.IsInstallment && item.VerificationStatus == InstitutionContractVerificationStatus.Verified)
|
||||
{
|
||||
var instalment = item.InstallmentList
|
||||
.FirstOrDefault(x =>
|
||||
@@ -3606,6 +3940,159 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region RollCallServicCompute
|
||||
|
||||
if (item.VerificationStatus != InstitutionContractVerificationStatus.Verified && !item.IsInstallment && item.ContractingPartyId != 30520 && item.ContractingPartyId != 30739)
|
||||
{
|
||||
try
|
||||
{
|
||||
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 =
|
||||
rollcallServiceList.Where(x => workshops.Contains(x.WorkshopId)).ToList();
|
||||
|
||||
if (services.Any())
|
||||
{
|
||||
foreach (var rollCallService in services)
|
||||
{
|
||||
//var spaning = (int)(endOfMonthGr - rollCallService.StartService).TotalDays + 1;
|
||||
int monthCounter = 0;
|
||||
|
||||
//var currentMonthStart = ($"{(endOfMonthGr.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime();
|
||||
//var prevMonthEnd = currentMonthStart.AddDays(-1);
|
||||
//var prevMonthStart = ($"{(prevMonthEnd.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime();
|
||||
|
||||
var monthCurrent = endOfMonthFa.Substring(5, 2);
|
||||
var yearCurrent = endOfMonthFa.Substring(0, 4);
|
||||
var currentMonthName = monthCurrent.ToFarsiMonthByNumber();
|
||||
var workshop = await _context.Workshops.FirstOrDefaultAsync(x => x.id == rollCallService.WorkshopId);
|
||||
|
||||
string rollCallTransactionDescription = "";
|
||||
//if (rollCallService.StartService <= prevMonthStart)
|
||||
//{
|
||||
// var monthPrev = prevMonthEnd.ToFarsi().Substring(5, 2);
|
||||
// var yearPrev = prevMonthEnd.ToFarsi().Substring(0, 4);
|
||||
// var prevMonthName = monthPrev.ToFarsiMonthByNumber();
|
||||
// description =
|
||||
// $"{prevMonthName} و {currentMonthName} {yearCurrent} - {workshop.WorkshopFullName}";
|
||||
// monthCounter = 2;
|
||||
//}
|
||||
//else if (rollCallService.StartService <= currentMonthStart &&
|
||||
// rollCallService.StartService > prevMonthStart)
|
||||
//{
|
||||
// monthCounter = 1;
|
||||
|
||||
// description = $"{currentMonthName} {yearCurrent} - {workshop.WorkshopFullName}";
|
||||
//}
|
||||
|
||||
if (rollCallService.StartService <= firstDayOfMonthGr)
|
||||
{
|
||||
monthCounter = 1;
|
||||
|
||||
rollCallTransactionDescription = $"{currentMonthName} {yearCurrent} - {workshop.WorkshopFullName}";
|
||||
}
|
||||
|
||||
var employees = await
|
||||
_context.RollCallEmployees.Where(x => x.WorkshopId == rollCallService.WorkshopId)
|
||||
.Select(x => x.id).ToListAsync();
|
||||
|
||||
var employeeCount = await _context.RollCallEmployeesStatus
|
||||
.Where(x => employees.Contains(x.RollCallEmployeeId))
|
||||
.CountAsync(x => x.EndDate.Date == activeStatusDate.Date);
|
||||
|
||||
if (employeeCount > 0 && monthCounter > 0)
|
||||
{
|
||||
|
||||
|
||||
|
||||
var dailyWageYearlySalery = await _context.YearlySalaries.Include(i => i.YearlySalaryItemsList)
|
||||
.FirstOrDefaultAsync(x =>
|
||||
x.StartDate.Date <= DateTime.Now.Date && x.EndDate >= DateTime.Now.Date);
|
||||
|
||||
var dailyWage = dailyWageYearlySalery.YearlySalaryItemsList
|
||||
.Where(x => x.ItemName == "مزد روزانه")
|
||||
.Select(x => x.ItemValue).FirstOrDefault();
|
||||
|
||||
var planPercentage = await _context.PlanPercentages.FirstOrDefaultAsync();
|
||||
|
||||
var countPersonnel = employeeCount;
|
||||
var planByCountPerson = await _context.InstitutionPlans
|
||||
.FirstOrDefaultAsync(x => x.CountPerson == countPersonnel);
|
||||
|
||||
var amountForOneMonth = (((dailyWage * planPercentage.RollCallPercent) / 100) *
|
||||
planByCountPerson.CountPerson *
|
||||
planByCountPerson.IncreasePercentage);
|
||||
|
||||
|
||||
var amountWithoutTax = amountForOneMonth * monthCounter;
|
||||
|
||||
|
||||
var tenPercent = amountWithoutTax * 10 / 100;
|
||||
var totalAmonut = amountWithoutTax + tenPercent;
|
||||
|
||||
double roundFloor = Math.Floor(totalAmonut);
|
||||
double result = Math.Ceiling(roundFloor / 10000.0) * 10000;
|
||||
|
||||
|
||||
|
||||
|
||||
var financialStatment = await
|
||||
_context.FinancialStatments.FirstOrDefaultAsync(x =>
|
||||
x.ContractingPartyId == item.ContractingPartyId);
|
||||
long financialStatementId = 0;
|
||||
if (financialStatment != null)
|
||||
{
|
||||
financialStatementId = financialStatment.id;
|
||||
}
|
||||
else
|
||||
{
|
||||
var statement = new FinancialStatment(item.ContractingPartyId, item.ContractingPartyName);
|
||||
await _context.FinancialStatments.AddAsync(statement);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
financialStatementId = statement.id;
|
||||
}
|
||||
|
||||
var transaction = new FinancialTransaction(financialStatementId, endOfMonthGr, endOfMonthFa,
|
||||
rollCallTransactionDescription,
|
||||
"debt", "بابت سرویس حضور غیاب", result, 0, 0);
|
||||
var alreadyCreated = await _context.FinancialTransactions.AnyAsync(x =>
|
||||
x.FinancialStatementId == financialStatementId &&
|
||||
x.Description == rollCallTransactionDescription &&
|
||||
x.DescriptionOption == "بابت سرویس حضور غیاب" &&
|
||||
x.TypeOfTransaction == "debt" &&
|
||||
x.TdateFa == endOfMonthFa);
|
||||
if (!alreadyCreated)
|
||||
{
|
||||
serviceCounter++;
|
||||
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()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
string errMess = $"{item.ContractingPartyId}-RollCall";
|
||||
await _smsService.Alarm("09114221321", errMess);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -3626,16 +4113,16 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public async Task CreateTransaction(DateTime endOfMonthGr, string endOfMonthFa, string description)
|
||||
{
|
||||
await CreateTransactionOldInstitutionContracts(endOfMonthGr, endOfMonthFa, description);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
#region CustomViewModels
|
||||
|
||||
public class WorkshopsAndEmployeeViewModel
|
||||
|
||||
Reference in New Issue
Block a user