add SmsSettings Table
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
|
||||
using Company.Domain.ContarctingPartyAgg;
|
||||
using Company.Domain.InstitutionContractAgg;
|
||||
using Hangfire;
|
||||
|
||||
namespace BackgroundInstitutionContract.Task.Jobs;
|
||||
@@ -7,22 +9,20 @@ public class JobSchedulerRegistrator
|
||||
{
|
||||
private readonly IBackgroundJobClient _backgroundJobClient;
|
||||
private readonly SmsReminder _smsReminder;
|
||||
private static DateTime? _lastRunDateMorning;
|
||||
private static DateTime? _lastRunDateEvening;
|
||||
private readonly IInstitutionContractRepository _institutionContractRepository;
|
||||
private static DateTime? _lastRunDebtReminder;
|
||||
|
||||
public JobSchedulerRegistrator(SmsReminder smsReminder, IBackgroundJobClient backgroundJobClient)
|
||||
|
||||
public JobSchedulerRegistrator(SmsReminder smsReminder, IBackgroundJobClient backgroundJobClient, IInstitutionContractRepository institutionContractRepository)
|
||||
{
|
||||
_smsReminder = smsReminder;
|
||||
_backgroundJobClient = backgroundJobClient;
|
||||
_institutionContractRepository = institutionContractRepository;
|
||||
}
|
||||
|
||||
public void Register()
|
||||
{
|
||||
RecurringJob.AddOrUpdate(
|
||||
"Task.Test",
|
||||
() => SmsReminderCheckAndSchedule(),
|
||||
"*/1 * * * *" // هر 5 دقیقه یکبار چک کن
|
||||
);
|
||||
|
||||
|
||||
RecurringJob.AddOrUpdate(
|
||||
"Task.ReminderDebtSMS",
|
||||
@@ -38,43 +38,11 @@ public class JobSchedulerRegistrator
|
||||
public void DebtSmsReminder()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
_backgroundJobClient.Enqueue(() => _smsReminder.Execute());
|
||||
_lastRunDateMorning = now;
|
||||
}
|
||||
|
||||
public void SmsReminderCheckAndSchedule()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
var startMorning = new TimeSpan(9, 0, 0);
|
||||
var endMorning = new TimeSpan(9, 40, 0);
|
||||
|
||||
var startEvening = new TimeSpan(15, 30, 0);
|
||||
var endEvening = new TimeSpan(15, 40, 0);
|
||||
|
||||
// صبح
|
||||
if (now.DayOfWeek != DayOfWeek.Friday &&
|
||||
now.TimeOfDay >= startMorning &&
|
||||
now.TimeOfDay < endMorning)
|
||||
if (_lastRunDebtReminder?.Date != now.Date)
|
||||
{
|
||||
if (_lastRunDateMorning?.Date != now.Date)
|
||||
{
|
||||
_backgroundJobClient.Enqueue(() => _smsReminder.Execute());
|
||||
_lastRunDateMorning = now;
|
||||
}
|
||||
}
|
||||
|
||||
// عصر - پنجشنبه و جمعه تعطیل است
|
||||
if (now.DayOfWeek != DayOfWeek.Friday &&
|
||||
now.DayOfWeek != DayOfWeek.Thursday &&
|
||||
now.TimeOfDay >= startEvening &&
|
||||
now.TimeOfDay < endEvening)
|
||||
{
|
||||
if (_lastRunDateEvening?.Date != now.Date)
|
||||
{
|
||||
_backgroundJobClient.Enqueue(() => _smsReminder.Execute());
|
||||
_lastRunDateEvening = now;
|
||||
}
|
||||
_backgroundJobClient.Enqueue(() => _institutionContractRepository.SendReminderSmsForBackgroundTask());
|
||||
_lastRunDebtReminder = now;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -79,7 +79,13 @@ public interface IInstitutionContractRepository : IRepository<long, InstitutionC
|
||||
Task<List<InstitutionContractPrintViewModel>> PrintAllAsync(List<long> ids);
|
||||
|
||||
|
||||
#region DebtReminderSMS
|
||||
#region ReminderSMS
|
||||
/// <summary>
|
||||
/// دریافت لیست - ارسال پیامک
|
||||
/// فراخوانی از سمت بک گراند سرویس
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<bool> SendReminderSmsForBackgroundTask();
|
||||
|
||||
/// <summary>
|
||||
///دریافت لیست بدهکارن
|
||||
|
||||
10
Company.Domain/SmsResultAgg/ISmsSettingsRepository.cs
Normal file
10
Company.Domain/SmsResultAgg/ISmsSettingsRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using _0_Framework.Domain;
|
||||
|
||||
namespace Company.Domain.SmsResultAgg;
|
||||
|
||||
public interface ISmsSettingsRepository : IRepository<long, SmsSetting>
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -162,6 +162,12 @@ public class CompanyContext : DbContext
|
||||
|
||||
//-------Main-Project----------------------------
|
||||
|
||||
#region SmsSettings
|
||||
|
||||
public DbSet<SmsSetting> SmsSettings { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Mahan
|
||||
|
||||
//-----------------------------RollCallWorkshopSettings-----------------------------
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Company.Domain.SmsResultAgg;
|
||||
using System;
|
||||
using _0_Framework.Application.Enums;
|
||||
using Company.Domain.SmsResultAgg;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
@@ -8,6 +10,21 @@ public class SmsSettingMapping : IEntityTypeConfiguration<SmsSetting>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<SmsSetting> builder)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
builder.ToTable("SmsSettings");
|
||||
builder.HasKey(x => x.id);
|
||||
|
||||
|
||||
builder.Property(x => x.DayOfMonth)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.TimeOfDay)
|
||||
.HasColumnType("time(0)")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.TypeOfSmsSetting).HasConversion(
|
||||
v => v.ToString(),
|
||||
v => (TypeOfSmsSetting)Enum.Parse(typeof(TypeOfSmsSetting), v)).HasMaxLength(30);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11140
CompanyManagment.EFCore/Migrations/20251115080049_SmsSettingsTable.Designer.cs
generated
Normal file
11140
CompanyManagment.EFCore/Migrations/20251115080049_SmsSettingsTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CompanyManagment.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class SmsSettingsTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SmsSettings",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
TypeOfSmsSetting = table.Column<string>(type: "nvarchar(30)", maxLength: 30, nullable: false),
|
||||
DayOfMonth = table.Column<int>(type: "int", nullable: false),
|
||||
TimeOfDay = table.Column<TimeSpan>(type: "time(0)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SmsSettings", x => x.id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "SmsSettings");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5637,6 +5637,30 @@ namespace CompanyManagment.EFCore.Migrations
|
||||
b.ToTable("SmsResults", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Company.Domain.SmsResultAgg.SmsSetting", b =>
|
||||
{
|
||||
b.Property<long>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("id"));
|
||||
|
||||
b.Property<int>("DayOfMonth")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<TimeSpan>("TimeOfDay")
|
||||
.HasColumnType("time(0)");
|
||||
|
||||
b.Property<string>("TypeOfSmsSetting")
|
||||
.IsRequired()
|
||||
.HasMaxLength(30)
|
||||
.HasColumnType("nvarchar(30)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("SmsSettings", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Company.Domain.SubtitleAgg.EntitySubtitle", b =>
|
||||
{
|
||||
b.Property<long>("id")
|
||||
|
||||
@@ -87,69 +87,69 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
public EditInstitutionContract GetDetails(long id)
|
||||
{
|
||||
return _context.InstitutionContractSet.Select(x => new EditInstitutionContract()
|
||||
{
|
||||
Id = x.id,
|
||||
ContractNo = x.ContractNo,
|
||||
ContractStartGr = x.ContractStartGr,
|
||||
ContractStartFa = x.ContractStartFa,
|
||||
ContractEndGr = x.ContractEndGr,
|
||||
ContractEndFa = x.ContractEndFa,
|
||||
RepresentativeName = x.RepresentativeName,
|
||||
ContractingPartyName = x.ContractingPartyName,
|
||||
RepresentativeId = x.RepresentativeId,
|
||||
ContractingPartyId = x.ContractingPartyId,
|
||||
ContractDateFa = x.ContractDateFa,
|
||||
State = x.State,
|
||||
City = x.City,
|
||||
Address = x.Address,
|
||||
Description = x.Description,
|
||||
WorkshopManualCount = x.WorkshopManualCount,
|
||||
EmployeeManualCount = x.EmployeeManualCount,
|
||||
ContractAmountString = x.ContractAmount.ToMoney(),
|
||||
ContractAmount = x.ContractAmount,
|
||||
DailyCompenseationString = x.DailyCompenseation.ToMoney(),
|
||||
ObligationString = x.Obligation.ToMoney(),
|
||||
TotalAmountString = x.TotalAmount.ToMoney(),
|
||||
ExtensionNo = x.ExtensionNo,
|
||||
OfficialCompany = x.OfficialCompany,
|
||||
TypeOfContract = x.TypeOfContract,
|
||||
Signature = x.Signature,
|
||||
HasValueAddedTax = x.HasValueAddedTax,
|
||||
ValueAddedTax = x.ValueAddedTax,
|
||||
})
|
||||
{
|
||||
Id = x.id,
|
||||
ContractNo = x.ContractNo,
|
||||
ContractStartGr = x.ContractStartGr,
|
||||
ContractStartFa = x.ContractStartFa,
|
||||
ContractEndGr = x.ContractEndGr,
|
||||
ContractEndFa = x.ContractEndFa,
|
||||
RepresentativeName = x.RepresentativeName,
|
||||
ContractingPartyName = x.ContractingPartyName,
|
||||
RepresentativeId = x.RepresentativeId,
|
||||
ContractingPartyId = x.ContractingPartyId,
|
||||
ContractDateFa = x.ContractDateFa,
|
||||
State = x.State,
|
||||
City = x.City,
|
||||
Address = x.Address,
|
||||
Description = x.Description,
|
||||
WorkshopManualCount = x.WorkshopManualCount,
|
||||
EmployeeManualCount = x.EmployeeManualCount,
|
||||
ContractAmountString = x.ContractAmount.ToMoney(),
|
||||
ContractAmount = x.ContractAmount,
|
||||
DailyCompenseationString = x.DailyCompenseation.ToMoney(),
|
||||
ObligationString = x.Obligation.ToMoney(),
|
||||
TotalAmountString = x.TotalAmount.ToMoney(),
|
||||
ExtensionNo = x.ExtensionNo,
|
||||
OfficialCompany = x.OfficialCompany,
|
||||
TypeOfContract = x.TypeOfContract,
|
||||
Signature = x.Signature,
|
||||
HasValueAddedTax = x.HasValueAddedTax,
|
||||
ValueAddedTax = x.ValueAddedTax,
|
||||
})
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
|
||||
public EditInstitutionContract GetFirstContract(long contractingPartyId, string typeOfContract)
|
||||
{
|
||||
return _context.InstitutionContractSet.Select(x => new EditInstitutionContract()
|
||||
{
|
||||
Id = x.id,
|
||||
ContractNo = x.ContractNo,
|
||||
ContractStartGr = x.ContractStartGr,
|
||||
ContractStartFa = x.ContractStartFa,
|
||||
ContractEndGr = x.ContractEndGr,
|
||||
ContractEndFa = x.ContractEndFa,
|
||||
RepresentativeName = x.RepresentativeName,
|
||||
ContractingPartyName = x.ContractingPartyName,
|
||||
RepresentativeId = x.RepresentativeId,
|
||||
ContractingPartyId = x.ContractingPartyId,
|
||||
ContractDateFa = x.ContractDateFa,
|
||||
State = x.State,
|
||||
City = x.City,
|
||||
Address = x.Address,
|
||||
Description = x.Description,
|
||||
WorkshopManualCount = x.WorkshopManualCount,
|
||||
EmployeeManualCount = x.EmployeeManualCount,
|
||||
ContractAmountString = x.ContractAmount.ToMoney(),
|
||||
DailyCompenseationString = x.DailyCompenseation.ToMoney(),
|
||||
ObligationString = x.Obligation.ToMoney(),
|
||||
TotalAmountString = x.TotalAmount.ToMoney(),
|
||||
ExtensionNo = x.ExtensionNo,
|
||||
OfficialCompany = x.OfficialCompany,
|
||||
TypeOfContract = x.TypeOfContract,
|
||||
Signature = x.Signature
|
||||
})
|
||||
{
|
||||
Id = x.id,
|
||||
ContractNo = x.ContractNo,
|
||||
ContractStartGr = x.ContractStartGr,
|
||||
ContractStartFa = x.ContractStartFa,
|
||||
ContractEndGr = x.ContractEndGr,
|
||||
ContractEndFa = x.ContractEndFa,
|
||||
RepresentativeName = x.RepresentativeName,
|
||||
ContractingPartyName = x.ContractingPartyName,
|
||||
RepresentativeId = x.RepresentativeId,
|
||||
ContractingPartyId = x.ContractingPartyId,
|
||||
ContractDateFa = x.ContractDateFa,
|
||||
State = x.State,
|
||||
City = x.City,
|
||||
Address = x.Address,
|
||||
Description = x.Description,
|
||||
WorkshopManualCount = x.WorkshopManualCount,
|
||||
EmployeeManualCount = x.EmployeeManualCount,
|
||||
ContractAmountString = x.ContractAmount.ToMoney(),
|
||||
DailyCompenseationString = x.DailyCompenseation.ToMoney(),
|
||||
ObligationString = x.Obligation.ToMoney(),
|
||||
TotalAmountString = x.TotalAmount.ToMoney(),
|
||||
ExtensionNo = x.ExtensionNo,
|
||||
OfficialCompany = x.OfficialCompany,
|
||||
TypeOfContract = x.TypeOfContract,
|
||||
Signature = x.Signature
|
||||
})
|
||||
.Where(x => x.ContractingPartyId == contractingPartyId && x.TypeOfContract == typeOfContract)
|
||||
.OrderBy(x => x.ExtensionNo).FirstOrDefault();
|
||||
}
|
||||
@@ -567,40 +567,40 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
}).ToList(),
|
||||
}).ToList();
|
||||
listQuery = listQuery.Select(x => new InstitutionContractViewModel()
|
||||
{
|
||||
Id = x.Id,
|
||||
ContractNo = x.ContractNo,
|
||||
ContractStartGr = x.ContractStartGr,
|
||||
ContractStartFa = x.ContractStartFa,
|
||||
ContractEndGr = x.ContractEndGr,
|
||||
ContractEndFa = x.ContractEndFa,
|
||||
RepresentativeId = x.RepresentativeId,
|
||||
RepresentativeName = x.RepresentativeName,
|
||||
ContractingPartyName = x.ContractingPartyName,
|
||||
ContractingPartyId = x.ContractingPartyId,
|
||||
ContractAmount = x.ContractAmount,
|
||||
TotalAmount = x.TotalAmount,
|
||||
SearchAmount = x.SearchAmount,
|
||||
IsActiveString = x.IsActiveString,
|
||||
OfficialCompany = x.OfficialCompany,
|
||||
TypeOfContract = x.TypeOfContract,
|
||||
Signature = x.Signature,
|
||||
ExpireColor = x.ExpireColor,
|
||||
IsExpier = x.IsExpier,
|
||||
BalanceDouble = x.BalanceDouble,
|
||||
BalanceStr = x.BalanceStr,
|
||||
EmployerViewModels = x.EmployerViewModels,
|
||||
EmployerNo = x.EmployerNo,
|
||||
EmployerName = x.EmployerViewModels.Select(n => n.FullName).FirstOrDefault(),
|
||||
WorkshopViewModels = x.WorkshopViewModels,
|
||||
WorkshopCount = x.WorkshopCount,
|
||||
IsContractingPartyBlock = x.IsContractingPartyBlock,
|
||||
BlockTimes = x.BlockTimes,
|
||||
EmployeeCount =
|
||||
{
|
||||
Id = x.Id,
|
||||
ContractNo = x.ContractNo,
|
||||
ContractStartGr = x.ContractStartGr,
|
||||
ContractStartFa = x.ContractStartFa,
|
||||
ContractEndGr = x.ContractEndGr,
|
||||
ContractEndFa = x.ContractEndFa,
|
||||
RepresentativeId = x.RepresentativeId,
|
||||
RepresentativeName = x.RepresentativeName,
|
||||
ContractingPartyName = x.ContractingPartyName,
|
||||
ContractingPartyId = x.ContractingPartyId,
|
||||
ContractAmount = x.ContractAmount,
|
||||
TotalAmount = x.TotalAmount,
|
||||
SearchAmount = x.SearchAmount,
|
||||
IsActiveString = x.IsActiveString,
|
||||
OfficialCompany = x.OfficialCompany,
|
||||
TypeOfContract = x.TypeOfContract,
|
||||
Signature = x.Signature,
|
||||
ExpireColor = x.ExpireColor,
|
||||
IsExpier = x.IsExpier,
|
||||
BalanceDouble = x.BalanceDouble,
|
||||
BalanceStr = x.BalanceStr,
|
||||
EmployerViewModels = x.EmployerViewModels,
|
||||
EmployerNo = x.EmployerNo,
|
||||
EmployerName = x.EmployerViewModels.Select(n => n.FullName).FirstOrDefault(),
|
||||
WorkshopViewModels = x.WorkshopViewModels,
|
||||
WorkshopCount = x.WorkshopCount,
|
||||
IsContractingPartyBlock = x.IsContractingPartyBlock,
|
||||
BlockTimes = x.BlockTimes,
|
||||
EmployeeCount =
|
||||
((x.WorkshopViewModels.Sum(w => w.LeftWorkIds.Count)) + (x.WorkshopViewModels.Sum(w =>
|
||||
w.InsuranceLeftWorkIds.Count(c => !w.LeftWorkIds.Contains(c))))).ToString(),
|
||||
ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0,
|
||||
}).OrderBy(x => x.WorkshopCount != "0" && string.IsNullOrWhiteSpace(x.ExpireColor))
|
||||
ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0,
|
||||
}).OrderBy(x => x.WorkshopCount != "0" && string.IsNullOrWhiteSpace(x.ExpireColor))
|
||||
.ThenBy(x => x.WorkshopCount == "0" && string.IsNullOrWhiteSpace(x.ExpireColor))
|
||||
.ThenBy(x => x.IsExpier == "true")
|
||||
.ThenBy(x => x.ExpireColor == "purple")
|
||||
@@ -1113,7 +1113,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
? x.contractingParty.FName + " " + x.contractingParty.LName
|
||||
: x.contractingParty.FName + " " + x.contractingParty.LName + " " + x.contractingParty.SureName
|
||||
: x.contractingParty.SureName == null ? x.contractingParty.LName
|
||||
: x.contractingParty.LName + " " + x.contractingParty.SureName).Contains(keyword)||
|
||||
: x.contractingParty.LName + " " + x.contractingParty.SureName).Contains(keyword) ||
|
||||
x.contractingParty.Employers.Any(e =>
|
||||
e.FullName.Contains(keyword) ||
|
||||
e.WorkshopEmployers.Any(we =>
|
||||
@@ -1338,7 +1338,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
ContractingPartyId = x.contractingParty.id,
|
||||
Workshops = workshopDetails,
|
||||
IsInPersonContract = x.contract.WorkshopGroup?.CurrentWorkshops
|
||||
.Any(y=>y.Services.ContractInPerson)??true,
|
||||
.Any(y => y.Services.ContractInPerson) ?? true,
|
||||
IsOldContract = x.contract.WorkshopGroup?.CurrentWorkshops == null
|
||||
|| x.contract.WorkshopGroup.CurrentWorkshops.Count == 0
|
||||
|| x.contract.WorkshopGroup.CurrentWorkshops.Any(y => y.Price == 0)
|
||||
@@ -1820,7 +1820,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
query.party.IsLegal == "حقیقی" ? query.party.Nationalcode : query.party.NationalId,
|
||||
LegalType = query.party.IsLegal == "حقیقی" ? LegalType.Real : LegalType.Legal,
|
||||
},
|
||||
FirstParty =_firstParty
|
||||
FirstParty = _firstParty
|
||||
};
|
||||
|
||||
return res;
|
||||
@@ -1848,7 +1848,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
public async Task<InstitutionContract> GetByPublicIdAsync(Guid id)
|
||||
{
|
||||
return await _context.InstitutionContractSet.Include(x=>x.ContactInfoList).FirstOrDefaultAsync(x => x.PublicId == id);
|
||||
return await _context.InstitutionContractSet.Include(x => x.ContactInfoList).FirstOrDefaultAsync(x => x.PublicId == id);
|
||||
}
|
||||
|
||||
#region Extension
|
||||
@@ -2287,7 +2287,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
entity.WorkshopGroup.InitialWorkshops.Add(workshopDetail);
|
||||
}
|
||||
|
||||
// Save the changes again
|
||||
// Save the changes again
|
||||
await SaveChangesAsync();
|
||||
|
||||
|
||||
@@ -2368,7 +2368,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
.Include(x => x.WorkshopGroup)
|
||||
.ThenInclude(x => x.CurrentWorkshops)
|
||||
.FirstOrDefaultAsync(x => x.id == institutionContractId);
|
||||
|
||||
|
||||
if (institutionContract.WorkshopGroup.CurrentWorkshops.Any(x => x.Price == 0))
|
||||
{
|
||||
throw new BadRequestException(
|
||||
@@ -2376,18 +2376,18 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
}
|
||||
|
||||
var workshops = institutionContract.WorkshopGroup.CurrentWorkshops
|
||||
.Select(x => new InstitutionContractAmendmentTempPrevWorkshop(x.WorkshopName,x.PersonnelCount,
|
||||
x.Services.Contract,x.Services.ContractInPerson,x.Services.Insurance,
|
||||
x.Services.InsuranceInPerson,x.Services.RollCall,x.Services.RollCallInPerson,
|
||||
x.Services.CustomizeCheckout,x.Price,
|
||||
x.WorkshopId??0,x.id)).ToList();
|
||||
.Select(x => new InstitutionContractAmendmentTempPrevWorkshop(x.WorkshopName, x.PersonnelCount,
|
||||
x.Services.Contract, x.Services.ContractInPerson, x.Services.Insurance,
|
||||
x.Services.InsuranceInPerson, x.Services.RollCall, x.Services.RollCallInPerson,
|
||||
x.Services.CustomizeCheckout, x.Price,
|
||||
x.WorkshopId ?? 0, x.id)).ToList();
|
||||
|
||||
|
||||
|
||||
|
||||
var temp = new InstitutionContractAmendmentTemp(workshops, institutionContractId);
|
||||
|
||||
|
||||
await _institutionAmendmentTemp.InsertOneAsync(temp);
|
||||
|
||||
|
||||
var prevWorkshops = workshops.Select(x =>
|
||||
new InstitutionContractAmendmentTempWorkshopViewModel()
|
||||
{
|
||||
@@ -2405,7 +2405,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
WorkshopId = x.WorkshopId,
|
||||
WorkshopTempId = x.Id,
|
||||
CurrentWorkshopId = x.CurrentWorkshopId,
|
||||
TempId =temp.Id
|
||||
TempId = temp.Id
|
||||
})
|
||||
.ToList();
|
||||
var res = new InstitutionContractAmendmentWorkshopsResponse()
|
||||
@@ -2413,7 +2413,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
Workshops = prevWorkshops,
|
||||
TempId = temp.Id
|
||||
};
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -2421,21 +2421,21 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
InsitutionContractAmendmentPaymentRequest request)
|
||||
{
|
||||
var institutionContractAmendmentTemp = await _institutionAmendmentTemp
|
||||
.Find(x=>x.Id == request.TempId)
|
||||
.Find(x => x.Id == request.TempId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (institutionContractAmendmentTemp == null)
|
||||
throw new NotFoundException("دیتای وارد شده نامعتبر است");
|
||||
|
||||
var amendmentStart = DateTime.Now;
|
||||
|
||||
|
||||
var institutionContract = await _context.InstitutionContractSet
|
||||
.Include(x=>x.WorkshopGroup)
|
||||
.ThenInclude(x=>x.CurrentWorkshops)
|
||||
.Include(x => x.WorkshopGroup)
|
||||
.ThenInclude(x => x.CurrentWorkshops)
|
||||
.FirstOrDefaultAsync(x => x.id == institutionContractAmendmentTemp.InstitutionContractId);
|
||||
|
||||
if (institutionContract == null)
|
||||
throw new NotFoundException("قرارداد مؤسسه یافت نشد");
|
||||
|
||||
|
||||
var amendmentEnd = institutionContract.ContractEndGr;
|
||||
|
||||
var haContractInPerson = institutionContract.WorkshopGroup.CurrentWorkshops
|
||||
@@ -2464,12 +2464,12 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
// اگر حتی چند روز از ماه بعدی هم گذشته بود → رند به بالا
|
||||
if (endDay > startDay)
|
||||
monthDiff++;
|
||||
|
||||
|
||||
var sumOneMonth = institutionContractAmendmentTemp.NewWorkshops.Sum(x => x.PriceDifference);
|
||||
|
||||
|
||||
var baseAmount = monthDiff * sumOneMonth;
|
||||
var tax = baseAmount*0.10;
|
||||
var totalPayment = tax+baseAmount;
|
||||
var tax = baseAmount * 0.10;
|
||||
var totalPayment = tax + baseAmount;
|
||||
|
||||
|
||||
var res = new InsitutionContractAmendmentPaymentResponse()
|
||||
@@ -2479,41 +2479,41 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
OneMonthAmount = sumOneMonth.ToMoney(),
|
||||
TotalAmount = baseAmount.ToMoney(),
|
||||
};
|
||||
|
||||
|
||||
res.OneTime = new InstitutionContractPaymentOneTimeViewModel()
|
||||
{
|
||||
TotalAmount = baseAmount.ToMoney(),
|
||||
PaymentAmount = totalPayment.ToMoney(),
|
||||
Tax = tax.ToMoney()
|
||||
};
|
||||
|
||||
|
||||
if (haContractInPerson)
|
||||
{
|
||||
var installment = InstitutionMonthlyInstallmentCaculation(monthDiff,totalPayment, amendmentStart.ToFarsi());
|
||||
|
||||
var installment = InstitutionMonthlyInstallmentCaculation(monthDiff, totalPayment, amendmentStart.ToFarsi());
|
||||
|
||||
var firstPrevInstallment = installment.First();
|
||||
var lastPrevInstallment = installment.Last();
|
||||
|
||||
|
||||
var firstInstallment = new MonthlyInstallment()
|
||||
{
|
||||
InstallmentAmountStr = firstPrevInstallment.InstallmentAmountStr,
|
||||
InstallmentCounter = firstPrevInstallment.InstallmentCounter,
|
||||
InstalmentDate = amendmentStart.ToFarsi()
|
||||
};
|
||||
|
||||
|
||||
var lastInstallment = new MonthlyInstallment()
|
||||
{
|
||||
InstallmentAmountStr = lastPrevInstallment.InstallmentAmountStr,
|
||||
InstallmentCounter = lastPrevInstallment.InstallmentCounter,
|
||||
InstalmentDate = lastPrevInstallment.InstalmentDate
|
||||
};
|
||||
|
||||
|
||||
installment.Remove(firstPrevInstallment);
|
||||
installment.Remove(lastPrevInstallment);
|
||||
|
||||
|
||||
installment.Insert(0, firstInstallment);
|
||||
installment.Add(lastInstallment);
|
||||
|
||||
|
||||
res.Monthly = new InstitutionContractPaymentMonthlyViewModel()
|
||||
{
|
||||
Installments = installment,
|
||||
@@ -2530,15 +2530,15 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
public async Task<InsertAmendmentTempWorkshopResponse> InsertAmendmentTempWorkshops(
|
||||
InstitutionContractAmendmentTempWorkshopViewModel request)
|
||||
{
|
||||
var amendmentTemp =await _institutionAmendmentTemp
|
||||
.Find(x=> x.Id == request.TempId).FirstOrDefaultAsync();
|
||||
|
||||
var amendmentTemp = await _institutionAmendmentTemp
|
||||
.Find(x => x.Id == request.TempId).FirstOrDefaultAsync();
|
||||
|
||||
if (amendmentTemp == null)
|
||||
throw new BadRequestException("دیتای وارد شده نامعتبر است");
|
||||
|
||||
|
||||
var workshopTemp = amendmentTemp.NewWorkshops
|
||||
.FirstOrDefault(x => x.Id == request.WorkshopTempId);
|
||||
|
||||
|
||||
var planForWorkshop = new WorkshopTempViewModel()
|
||||
{
|
||||
WorkshopName = request.WorkshopName,
|
||||
@@ -2553,7 +2553,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
};
|
||||
var price = _planPercentageRepository.GetInstitutionPlanForWorkshop(planForWorkshop)
|
||||
.OnlineAndInPersonSumAmountDouble;
|
||||
|
||||
|
||||
if (workshopTemp == null)
|
||||
{
|
||||
var newWorkshopTemp = new InstitutionContractAmendmentTempNewWorkshop(request.WorkshopName,
|
||||
@@ -2562,33 +2562,33 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
request.Insurance, request.InsuranceInPerson,
|
||||
request.RollCall, request.RollCallInPerson,
|
||||
request.CustomizeCheckout, price,
|
||||
request.WorkshopId,0,price);
|
||||
request.WorkshopId, 0, price);
|
||||
|
||||
workshopTemp = newWorkshopTemp;
|
||||
|
||||
|
||||
|
||||
amendmentTemp.NewWorkshops.Add(newWorkshopTemp);
|
||||
|
||||
|
||||
await _institutionAmendmentTemp
|
||||
.ReplaceOneAsync(x => x.Id == amendmentTemp.Id, amendmentTemp);
|
||||
}
|
||||
else
|
||||
{
|
||||
amendmentTemp.NewWorkshops.Remove(workshopTemp);
|
||||
|
||||
|
||||
var differencePrice = price - workshopTemp.Price;
|
||||
workshopTemp.Edit(request.WorkshopName, request.CountPerson,
|
||||
request.ContractAndCheckout, request.ContractAndCheckoutInPerson,
|
||||
request.Insurance, request.InsuranceInPerson,
|
||||
request.RollCall,
|
||||
request.CustomizeCheckout, price,differencePrice);
|
||||
|
||||
request.CustomizeCheckout, price, differencePrice);
|
||||
|
||||
amendmentTemp.NewWorkshops.Add(workshopTemp);
|
||||
|
||||
|
||||
await _institutionAmendmentTemp
|
||||
.ReplaceOneAsync(x => x.Id == amendmentTemp.Id, amendmentTemp);
|
||||
}
|
||||
|
||||
|
||||
return new InsertAmendmentTempWorkshopResponse()
|
||||
{
|
||||
WorkshopTempId = workshopTemp.Id,
|
||||
@@ -2603,16 +2603,16 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
if (amendmentTemp == null)
|
||||
throw new BadRequestException("دیتای وارد شده نامعتبر است");
|
||||
var workshopTemp = amendmentTemp.NewWorkshops.FirstOrDefault(x => x.Id == workshopTempId);
|
||||
if (workshopTemp == null)
|
||||
if (workshopTemp == null)
|
||||
throw new BadRequestException("دیتای وارد شده نامعتبر است");
|
||||
|
||||
if (workshopTemp.CurrentWorkshopId!=0)
|
||||
if (workshopTemp.CurrentWorkshopId != 0)
|
||||
throw new BadRequestException("شما نمی توانید این کارگاه را حذف کنید زیرا در قرارداد اصلی وجود دارد");
|
||||
|
||||
|
||||
amendmentTemp.NewWorkshops.Remove(workshopTemp);
|
||||
|
||||
|
||||
await _institutionAmendmentTemp.ReplaceOneAsync(x => x.Id == amendmentTemp.Id, amendmentTemp);
|
||||
|
||||
|
||||
}
|
||||
public async Task<List<InstitutionContractSelectListViewModel>> GetInstitutionContractSelectList(string search,
|
||||
string selected)
|
||||
@@ -2626,32 +2626,32 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
: x.SureName == null ? x.LName
|
||||
: x.LName + " " + x.SureName
|
||||
});
|
||||
|
||||
|
||||
var workshops = _context.Workshops.Select(x => new InstitutionContractSelectListViewModel()
|
||||
{
|
||||
Id = x.id,
|
||||
Text = x.WorkshopFullName
|
||||
});
|
||||
//کارفرما ها به غیر از آن هایی که به طرف حساب ---- وصل هستند
|
||||
var employers = _context.Employers.Where(x=>x.ContractingPartyId != 30428)
|
||||
var employers = _context.Employers.Where(x => x.ContractingPartyId != 30428)
|
||||
.Select(x => new InstitutionContractSelectListViewModel()
|
||||
{
|
||||
Id = x.id,
|
||||
Text = x.FullName
|
||||
});
|
||||
{
|
||||
Id = x.id,
|
||||
Text = x.FullName
|
||||
});
|
||||
var representatives = _context.RepresentativeSet.Select(x => new InstitutionContractSelectListViewModel()
|
||||
{
|
||||
Id = x.id,
|
||||
Text = x.FName + " " + x.LName
|
||||
});
|
||||
|
||||
|
||||
var res = contractingParties
|
||||
.Union(workshops)
|
||||
.Union(employers)
|
||||
.Union(representatives);
|
||||
|
||||
|
||||
InstitutionContractSelectListViewModel idSelected = null;
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(selected))
|
||||
{
|
||||
idSelected = await res.FirstOrDefaultAsync(x => x.Text == selected);
|
||||
@@ -2660,24 +2660,24 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
{
|
||||
res = res.Where(x => x.Text.Contains(search));
|
||||
}
|
||||
|
||||
|
||||
var list = await res.Take(100).ToListAsync();
|
||||
|
||||
|
||||
if (idSelected != null)
|
||||
list.Add(idSelected);
|
||||
|
||||
return list.DistinctBy(x => x.Id).ToList();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<InstitutionContractPrintViewModel>> PrintAllAsync(List<long> ids)
|
||||
{
|
||||
var query =_context.InstitutionContractSet
|
||||
.Include(x=>x.WorkshopGroup)
|
||||
.ThenInclude(x=>x.InitialWorkshops)
|
||||
.Include(x=>x.WorkshopGroup)
|
||||
.ThenInclude(x=>x.CurrentWorkshops)
|
||||
.Where(x=>ids.Contains(x.id));
|
||||
var query = _context.InstitutionContractSet
|
||||
.Include(x => x.WorkshopGroup)
|
||||
.ThenInclude(x => x.InitialWorkshops)
|
||||
.Include(x => x.WorkshopGroup)
|
||||
.ThenInclude(x => x.CurrentWorkshops)
|
||||
.Where(x => ids.Contains(x.id));
|
||||
|
||||
var contractingPartyIds = query.Select(x => x.ContractingPartyId).ToList();
|
||||
var contractingParties = await _context.PersonalContractingParties
|
||||
@@ -2685,7 +2685,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
.ToListAsync();
|
||||
|
||||
var list = query.ToList();
|
||||
|
||||
|
||||
if (list.Count == 0)
|
||||
throw new NotFoundException("قرارداد مؤسسه یافت نشد");
|
||||
|
||||
@@ -2698,7 +2698,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
{
|
||||
throw new NotFoundException("طرف حساب یافت نشد");
|
||||
}
|
||||
|
||||
|
||||
var law = await _context.Laws
|
||||
.FirstOrDefaultAsync(x => x.id == institution.LawId);
|
||||
|
||||
@@ -2952,20 +2952,35 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
public async Task<bool> SendReminderSmsForBackgroundTask()
|
||||
{
|
||||
|
||||
var now = DateTime.Now;
|
||||
var dayOfMonth = "05";
|
||||
var executeDateDayOfmonth = ($"{now.ToFarsi().Substring(0, 8)}{dayOfMonth}").ToGeorgianDateTime();
|
||||
TimeSpan timeOfDayFromDataBase = new TimeSpan(0,15,20);
|
||||
var executeDate = new DateTime(executeDateDayOfmonth.Year,executeDateDayOfmonth.Month,executeDateDayOfmonth.Day, timeOfDayFromDataBase.Hours,
|
||||
timeOfDayFromDataBase.Minutes, 0);
|
||||
|
||||
if (executeDate == now)
|
||||
{
|
||||
//اجرای تسک
|
||||
}
|
||||
var now = DateTime.Now;
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
// تبدیل تاریخ میلادی به شمسی
|
||||
var persianNow = now.ToFarsi();
|
||||
var dayOfMonth = int.Parse(persianNow.Substring(8, 2));
|
||||
var hour = now.Hour;
|
||||
var minute = now.Minute;
|
||||
var institutionContractDebtReminder = TypeOfSmsSetting.InstitutionContractDebtReminder;
|
||||
var checkAnyToExecute = await _context.SmsSettings
|
||||
.FirstOrDefaultAsync(x =>
|
||||
x.DayOfMonth == dayOfMonth &&
|
||||
x.TimeOfDay.Hours == hour &&
|
||||
x.TimeOfDay.Minutes == minute &&
|
||||
x.TypeOfSmsSetting == institutionContractDebtReminder
|
||||
);
|
||||
|
||||
|
||||
if (checkAnyToExecute != null)
|
||||
{
|
||||
//اجرای تسک
|
||||
|
||||
Console.WriteLine("executed at : " + persianNow + " - " + hour +":"+minute);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2978,7 +2993,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
var previusMonthEnd = currentMonthStart.AddDays(-1);
|
||||
var previusMonthStart = ($"{(previusMonthEnd.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime();
|
||||
var typeOfSms = "یادآور بدهی ماهانه";
|
||||
|
||||
|
||||
//دریافت اطلاعات بدهکارن و ساخت لیست پیامک
|
||||
#region GetSmsListData
|
||||
|
||||
@@ -3020,12 +3035,12 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
var hasFinancialStatement = 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 (hasFinancialStatement && hasPhonNumber)
|
||||
{
|
||||
|
||||
@@ -3041,10 +3056,10 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
SendSms = x.SendSms
|
||||
}).Where(x => x.PhoneNumber.Length == 11).ToListAsync();
|
||||
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}";
|
||||
@@ -3101,14 +3116,14 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
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 });
|
||||
|
||||
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 });
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
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 = 161233, PartyName = partyName, Amount = balanceToMoney, ContractingPartyId = contractingParty.id, AproveId = aprove, TypeOfSmsMethod = "MonthlyBill", Code1 = "", Code2 = "", InstitutionContractId = item.Id });
|
||||
|
||||
}
|
||||
|
||||
@@ -3137,12 +3152,12 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
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 });
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
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 });
|
||||
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 });
|
||||
|
||||
}
|
||||
|
||||
@@ -3289,7 +3304,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -3336,7 +3351,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region CustomViewModels
|
||||
|
||||
public class WorkshopsAndEmployeeViewModel
|
||||
|
||||
Reference in New Issue
Block a user