Compare commits
6 Commits
Feature/In
...
Feature/la
| Author | SHA1 | Date | |
|---|---|---|---|
| 8efffe8b75 | |||
| fdf7fa0d3c | |||
| 5cde26e7f3 | |||
| b448c43bb7 | |||
| 6045153865 | |||
| 5d16020c6a |
@@ -17,7 +17,7 @@ public class InstitutionContract : EntityBase
|
||||
string contractEndFa, double contractAmount, double dailyCompenseation, double obligation,
|
||||
double totalAmount, int extensionNo, string workshopManualCount, string employeeManualCount, string description,
|
||||
string officialCompany, string typeOfcontract, string hasValueAddedTax, double valueAddedTax,
|
||||
List<InstitutionContractWorkshopInitial> workshopDetails)
|
||||
List<InstitutionContractWorkshopInitial> workshopDetails, long lawId)
|
||||
{
|
||||
ContractNo = contractNo;
|
||||
RepresentativeId = representativeId;
|
||||
@@ -54,8 +54,11 @@ public class InstitutionContract : EntityBase
|
||||
Installments = [];
|
||||
WorkshopGroup = new InstitutionContractWorkshopGroup(id, workshopDetails);
|
||||
PublicId = Guid.NewGuid();
|
||||
LawId = lawId;
|
||||
}
|
||||
|
||||
public long LawId { get; private set; }
|
||||
|
||||
public string ContractNo { get; private set; }
|
||||
|
||||
public long RepresentativeId { get; private set; }
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Company.Domain.LawAgg
|
||||
public LawType Type { get; private set; }
|
||||
public string HeadTitle { get; private set; }
|
||||
public string NotificationsJson { get; private set; }
|
||||
public int Version { get; private set; }
|
||||
|
||||
[NotMapped]
|
||||
public List<string> Notifications
|
||||
@@ -26,14 +27,15 @@ namespace Company.Domain.LawAgg
|
||||
set => NotificationsJson = JsonSerializer.Serialize(value);
|
||||
}
|
||||
|
||||
public Law(string title, LawType lawType, List<string> notifications, string headTitle )
|
||||
public Law(string title, LawType lawType, List<string> notifications, string headTitle, int version = 1)
|
||||
{
|
||||
Title = title;
|
||||
IsActive = true;
|
||||
IsActive = true; // آخرین نسخه فعال است
|
||||
Items = new List<LawItem>();
|
||||
Type = lawType;
|
||||
Notifications = notifications ?? new List<string>();
|
||||
HeadTitle = headTitle;
|
||||
Version = version;
|
||||
}
|
||||
|
||||
public void Edit(string title)
|
||||
@@ -46,7 +48,6 @@ namespace Company.Domain.LawAgg
|
||||
Items.Add(new LawItem(header, details, orderNumber));
|
||||
}
|
||||
|
||||
|
||||
public void SetItem(List<LawItem> items)
|
||||
{
|
||||
Items = items ?? new List<LawItem>();
|
||||
@@ -67,6 +68,32 @@ namespace Company.Domain.LawAgg
|
||||
{
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
public void SetAsLatestVersion()
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public void SetAsOldVersion()
|
||||
{
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
public Law CreateNewVersion(string title, List<string> notifications, string headTitle, List<LawItem> items)
|
||||
{
|
||||
var newVersion = new Law(
|
||||
title,
|
||||
this.Type,
|
||||
notifications,
|
||||
headTitle,
|
||||
this.Version + 1
|
||||
);
|
||||
|
||||
newVersion.SetItem(items);
|
||||
newVersion.SetAsLatestVersion();
|
||||
|
||||
return newVersion;
|
||||
}
|
||||
}
|
||||
|
||||
public class LawItem
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace CompanyManagment.App.Contracts.InstitutionContract;
|
||||
|
||||
public class CreateInstitutionContract
|
||||
{
|
||||
public long LawId { get; set; }
|
||||
public string ContractNo { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "انتخاب معرف اجباری است")]
|
||||
|
||||
@@ -100,6 +100,8 @@ public class CreateInstitutionContractRequest
|
||||
public double TaxAmount { get; set; }
|
||||
|
||||
public double OneMonthAmount { get; set; }
|
||||
|
||||
public long LawId { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// مدت زمان قرارداد نهاد
|
||||
|
||||
@@ -242,6 +242,7 @@ public class InstitutionContractExtensionCompleteRequest
|
||||
{
|
||||
public Guid TemporaryId { get; set; }
|
||||
public bool IsInstallment { get; set; }
|
||||
public long LawId { get; set; }
|
||||
}
|
||||
|
||||
public class InstitutionContractExtensionPaymentResponse
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace CompanyManagment.App.Contracts.Law
|
||||
public LawType Type { get; set; }
|
||||
public string HeadTitle { get; set; }
|
||||
public List<string> Notifications { get; set; }
|
||||
public int Version { get; set; }
|
||||
}
|
||||
|
||||
public class LawItemViewModel
|
||||
|
||||
@@ -209,7 +209,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
|
||||
command.ContractStartFa, contractEndGr, command.ContractEndFa, command.ContractAmount,
|
||||
command.DailyCompenseation, command.Obligation,
|
||||
command.TotalAmount, 0, command.WorkshopManualCount, command.EmployeeManualCount, command.Description,
|
||||
command.OfficialCompany, command.TypeOfContract, command.HasValueAddedTax, command.ValueAddedTax, []);
|
||||
command.OfficialCompany, command.TypeOfContract, command.HasValueAddedTax, command.ValueAddedTax, [],command.LawId);
|
||||
|
||||
_institutionContractRepository.Create(createContract);
|
||||
_institutionContractRepository.SaveChanges();
|
||||
@@ -318,7 +318,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
|
||||
command.DailyCompenseation, command.Obligation,
|
||||
command.TotalAmount, command.ExtensionNo, command.WorkshopManualCount, command.EmployeeManualCount,
|
||||
command.Description, command.OfficialCompany, command.TypeOfContract, command.HasValueAddedTax,
|
||||
command.ValueAddedTax, []);
|
||||
command.ValueAddedTax, [],command.LawId);
|
||||
|
||||
_institutionContractRepository.Create(createContract);
|
||||
_institutionContractRepository.SaveChanges();
|
||||
@@ -1046,7 +1046,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
|
||||
command.Workshops.Count.ToString(),
|
||||
command.Workshops.Sum(x => x.PersonnelCount).ToString(), command.Description,
|
||||
"NotOfficial", "JobRelation", hasValueAddedTax,
|
||||
command.TaxAmount, workshopDetails);
|
||||
command.TaxAmount, workshopDetails,command.LawId);
|
||||
|
||||
|
||||
FinancialStatment financialStatement;
|
||||
|
||||
@@ -20,9 +20,16 @@ public class LawApplication : ILawApplication
|
||||
public OperationResult Create(CreateLaw command)
|
||||
{
|
||||
var operation = new OperationResult();
|
||||
if (_lawRepository.Exists(x => x.Type == command.Type))
|
||||
|
||||
// قبل از ایجاد قانون جدید، همه قوانین قدیمی از این نوع را غیرفعال میکنیم
|
||||
var existingLaws = _lawRepository.Get().Where(x => x.Type == command.Type).ToList();
|
||||
if (existingLaws.Any())
|
||||
{
|
||||
return operation.Failed("این قانون قبلا ثبت شده است");
|
||||
foreach (var existingLaw in existingLaws)
|
||||
{
|
||||
existingLaw.Deactivate();
|
||||
}
|
||||
_lawRepository.SaveChanges();
|
||||
}
|
||||
|
||||
var law = new Law(command.Title, command.Type, command.Notifications, command.HeadTitle);
|
||||
@@ -56,6 +63,8 @@ public class LawApplication : ILawApplication
|
||||
{
|
||||
return operation.Failed("باید حداقل یک بند برای قانون باید ثبت شود");
|
||||
}
|
||||
|
||||
// Create new items list for the new version
|
||||
var orderNumber = 1;
|
||||
var lawItems = command.Items.Select(x =>
|
||||
{
|
||||
@@ -63,12 +72,17 @@ public class LawApplication : ILawApplication
|
||||
orderNumber++;
|
||||
return res;
|
||||
}).ToList();
|
||||
|
||||
law.Edit(command.Title);
|
||||
|
||||
law.SetItem(lawItems);
|
||||
|
||||
|
||||
// Mark the current version as old version
|
||||
law.SetAsOldVersion();
|
||||
|
||||
// Create a new version based on the old one
|
||||
var newVersion = law.CreateNewVersion(command.Title, command.Notifications, command.HeadTitle, lawItems);
|
||||
|
||||
// Save the new version
|
||||
_lawRepository.Create(newVersion);
|
||||
_lawRepository.SaveChanges();
|
||||
|
||||
return operation.Succcedded();
|
||||
}
|
||||
|
||||
@@ -82,13 +96,13 @@ public class LawApplication : ILawApplication
|
||||
return operation.Failed("باید حداقل یک بند برای قانون باید ثبت شود");
|
||||
}
|
||||
|
||||
// Check if law exists by type
|
||||
var existingLaw = _lawRepository.Get().FirstOrDefault(x => x.Type == command.Type);
|
||||
// Check if active law exists by type
|
||||
var existingLaw = _lawRepository.Get().FirstOrDefault(x => x.Type == command.Type && x.IsActive);
|
||||
|
||||
if (existingLaw == null)
|
||||
{
|
||||
// If law doesn't exist, create a new one
|
||||
var law = new Law(command.Title, command.Type,command.Notifications, command.HeadTitle);
|
||||
var law = new Law(command.Title, command.Type, command.Notifications, command.HeadTitle);
|
||||
|
||||
var orderNumber = 1;
|
||||
foreach (var item in command.Items)
|
||||
@@ -102,7 +116,10 @@ public class LawApplication : ILawApplication
|
||||
}
|
||||
else
|
||||
{
|
||||
// If law exists, update it
|
||||
// Mark the current version as old version
|
||||
existingLaw.SetAsOldVersion();
|
||||
|
||||
// Create new items list for the new version
|
||||
var orderNumber = 1;
|
||||
var lawItems = command.Items.Select(x =>
|
||||
{
|
||||
@@ -111,9 +128,11 @@ public class LawApplication : ILawApplication
|
||||
return res;
|
||||
}).ToList();
|
||||
|
||||
existingLaw.Edit(command.Title);
|
||||
existingLaw.SetItem(lawItems);
|
||||
// Create a new version based on the old one
|
||||
var newVersion = existingLaw.CreateNewVersion(command.Title, command.Notifications, command.HeadTitle, lawItems);
|
||||
|
||||
// Save the new version
|
||||
_lawRepository.Create(newVersion);
|
||||
_lawRepository.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -128,8 +147,17 @@ public class LawApplication : ILawApplication
|
||||
if (law == null)
|
||||
return operation.Failed(ApplicationMessages.RecordNotFound);
|
||||
|
||||
// غیرفعال کردن همه نسخههای قبلی از این نوع قانون
|
||||
var otherLaws = _lawRepository.Get().Where(x => x.Type == law.Type && x.id != law.id).ToList();
|
||||
foreach (var otherLaw in otherLaws)
|
||||
{
|
||||
otherLaw.Deactivate();
|
||||
}
|
||||
|
||||
// فعال کردن این نسخه به عنوان آخرین نسخه
|
||||
law.Activate();
|
||||
_lawRepository.SaveChanges();
|
||||
|
||||
return operation.Succcedded();
|
||||
}
|
||||
|
||||
@@ -149,9 +177,11 @@ public class LawApplication : ILawApplication
|
||||
public OperationResult ActivateByType(LawType type)
|
||||
{
|
||||
var operation = new OperationResult();
|
||||
var law = _lawRepository.Get().FirstOrDefault(x => x.Type == type);
|
||||
|
||||
if (law == null)
|
||||
|
||||
// غیرفعال کردن همه نسخههای قبلی از این نوع قانون
|
||||
var existingLaws = _lawRepository.Get().Where(x => x.Type == type).ToList();
|
||||
|
||||
if (!existingLaws.Any())
|
||||
{
|
||||
// If law doesn't exist, create a new active one with default values
|
||||
var newLaw = new Law(GetDefaultTitleForLawType(type), type, new List<string>(), "");
|
||||
@@ -160,21 +190,36 @@ public class LawApplication : ILawApplication
|
||||
_lawRepository.SaveChanges();
|
||||
return operation.Succcedded();
|
||||
}
|
||||
|
||||
law.Activate();
|
||||
|
||||
// فعال کردن آخرین نسخه (با بالاترین شماره نسخه)
|
||||
var latestVersion = existingLaws.OrderByDescending(x => x.Version).First();
|
||||
|
||||
// غیرفعال کردن سایر نسخهها
|
||||
foreach (var law in existingLaws.Where(x => x.id != latestVersion.id))
|
||||
{
|
||||
law.Deactivate();
|
||||
}
|
||||
|
||||
// فعال کردن آخرین نسخه
|
||||
latestVersion.Activate();
|
||||
_lawRepository.SaveChanges();
|
||||
|
||||
return operation.Succcedded();
|
||||
}
|
||||
|
||||
public OperationResult DeactivateByType(LawType type)
|
||||
{
|
||||
var operation = new OperationResult();
|
||||
var law = _lawRepository.Get().FirstOrDefault(x => x.Type == type);
|
||||
var laws = _lawRepository.Get().Where(x => x.Type == type).ToList();
|
||||
|
||||
if (law == null)
|
||||
if (!laws.Any())
|
||||
return operation.Failed("قانون مورد نظر یافت نشد");
|
||||
|
||||
law.Deactivate();
|
||||
foreach (var law in laws)
|
||||
{
|
||||
law.Deactivate();
|
||||
}
|
||||
|
||||
_lawRepository.SaveChanges();
|
||||
return operation.Succcedded();
|
||||
}
|
||||
@@ -187,6 +232,8 @@ public class LawApplication : ILawApplication
|
||||
Id = law.id,
|
||||
Title = law.Title,
|
||||
Type = law.Type,
|
||||
HeadTitle = law.HeadTitle,
|
||||
Notifications = law.Notifications,
|
||||
Items = law.Items.OrderBy(x => x.OrderNumber).Select(x => new LawItemViewModel
|
||||
{
|
||||
Header = x.Header,
|
||||
@@ -197,10 +244,8 @@ public class LawApplication : ILawApplication
|
||||
|
||||
public async Task<List<LawViewModel>> GetList(LawSearchModel searchModel)
|
||||
{
|
||||
// Get filtered laws from database
|
||||
// Get all laws from database, including version information
|
||||
return await _lawRepository.GetList(searchModel);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private string GetDefaultTitleForLawType(LawType lawType)
|
||||
@@ -225,6 +270,9 @@ public class LawApplication : ILawApplication
|
||||
IsActive = law.IsActive,
|
||||
CreatedAt = law.CreationDate,
|
||||
Type = law.Type,
|
||||
HeadTitle = law.HeadTitle,
|
||||
Notifications = law.Notifications,
|
||||
Version = law.Version,
|
||||
Items = law.Items.OrderBy(x=>x.OrderNumber).Select(x => new LawItemViewModel
|
||||
{
|
||||
Header = x.Header,
|
||||
@@ -235,6 +283,7 @@ public class LawApplication : ILawApplication
|
||||
|
||||
public async Task<LawViewModel> GetLawByType(LawType type)
|
||||
{
|
||||
// Only get the active (latest) version of the law
|
||||
var lawViewModel = await _lawRepository.GetByType(type);
|
||||
|
||||
// If no law exists for this type, return a default empty law
|
||||
@@ -247,6 +296,7 @@ public class LawApplication : ILawApplication
|
||||
IsActive = false,
|
||||
CreatedAt = DateTime.Now,
|
||||
Type = type,
|
||||
Version = 1,
|
||||
Items = new List<LawItemViewModel>()
|
||||
};
|
||||
}
|
||||
|
||||
10962
CompanyManagment.EFCore/Migrations/20251013055841_Add Law Id to institutionContract.Designer.cs
generated
Normal file
10962
CompanyManagment.EFCore/Migrations/20251013055841_Add Law Id to institutionContract.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CompanyManagment.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddLawIdtoinstitutionContract : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Version",
|
||||
table: "Law",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "LawId",
|
||||
table: "InstitutionContracts",
|
||||
type: "bigint",
|
||||
nullable: false,
|
||||
defaultValue: 0L);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Version",
|
||||
table: "Law");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LawId",
|
||||
table: "InstitutionContracts");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3130,6 +3130,9 @@ namespace CompanyManagment.EFCore.Migrations
|
||||
b.Property<bool>("IsInstallment")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<long>("LawId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<double>("Obligation")
|
||||
.HasColumnType("float");
|
||||
|
||||
@@ -4073,6 +4076,9 @@ namespace CompanyManagment.EFCore.Migrations
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<int>("Version")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("Law", (string)null);
|
||||
|
||||
@@ -2227,7 +2227,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
extensionNo, workshopsCount, employeeCount,
|
||||
previousInstitutionContract.Description,
|
||||
"NotOfficial", "JobRelation", hasValueAddedTax,
|
||||
payment.Tax.MoneyToDouble(),[]);
|
||||
payment.Tax.MoneyToDouble(),[],
|
||||
request.LawId);
|
||||
|
||||
await CreateAsync(entity);
|
||||
await SaveChangesAsync();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -49,7 +49,8 @@ public class LawRepository:RepositoryBase<long,Law>,ILawRepository
|
||||
|
||||
public async Task<List<LawViewModel>> GetList(LawSearchModel searchModel)
|
||||
{
|
||||
var query = _context.Laws.Include(x => x.Items).AsQueryable();
|
||||
var query = _context.Laws.Include(x => x.Items)
|
||||
.Where(x=>x.IsActive).AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(searchModel.Title))
|
||||
query = query.Where(x => x.Title.Contains(searchModel.Title));
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a asp-page="/Index" class="waves-effect btnDashboard">
|
||||
<a href="https://admin@(AppSetting.Value.Domain)/dashboard" class="waves-effect btnDashboard">
|
||||
<div class="menuTitle">
|
||||
<i class="md md-home"></i>
|
||||
<span> پیشخان </span>
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
<div id="sidebar-menu">
|
||||
<ul>
|
||||
<li>
|
||||
<a asp-area="Admin" asp-page="/Index" class="waves-effect btnDashboard">
|
||||
<a href="https://admin@(AppSetting.Value.Domain)/dashboard" class="waves-effect btnDashboard">
|
||||
<div class="menuTitle">
|
||||
<i class="md md-home"></i>
|
||||
<span> پیشخان </span>
|
||||
@@ -633,7 +633,7 @@
|
||||
</span>
|
||||
</a>
|
||||
<ul class="list-unstyled sdf10">
|
||||
<li permission="307"><a class="clik10" asp-area="Admin" asp-page="/Company/InstitutionContracts/Index">
|
||||
<li permission="307"><a class="clik10" href="https://admin@(AppSetting.Value.Domain)/institution-contract">
|
||||
<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg" style="width: 7px;margin: 0 6px;">
|
||||
<circle cx="6.5" cy="6.5" r="6.5" fill="white"/>
|
||||
</svg>
|
||||
|
||||
Reference in New Issue
Block a user