Merge branch 'Feature/InstitutionContract/upgrade' into Main

This commit is contained in:
2025-10-26 18:03:46 +03:30
9 changed files with 322 additions and 26 deletions

View File

@@ -27,7 +27,8 @@ public interface ISmsService
Task<double> GetCreditAmount();
public Task<bool> SendInstitutionVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId);
public Task<bool> SendInstitutionCreationVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId);
public Task<bool> SendInstitutionAmendmentVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId);
public Task<bool> SendInstitutionVerificationCode(string number, string code, string contractingPartyFullName,
long contractingPartyId, long institutionContractId);

View File

@@ -6,7 +6,6 @@ using _0_Framework.Application;
using _0_Framework.Domain;
using CompanyManagment.App.Contracts.InstitutionContract;
using CompanyManagment.App.Contracts.Workshop;
using Microsoft.AspNetCore.Mvc;
namespace Company.Domain.InstitutionContractAgg;
@@ -77,4 +76,5 @@ public interface IInstitutionContractRepository : IRepository<long, InstitutionC
Task<List<InstitutionContractSelectListViewModel>> GetInstitutionContractSelectList(string search, string selected);
Task<List<InstitutionContractPrintViewModel>> PrintAllAsync(List<long> ids);
Task AmendmentComplete(InstitutionContractAmendmentCompleteRequest request);
}

View File

@@ -252,6 +252,11 @@ public class InstitutionContract : EntityBase
{
WorkshopGroup = null;
}
public void AddAmendment(InstitutionContractAmendment amendment)
{
Amendments.Add(amendment);
}
}
public class InstitutionContractAmendment : EntityBase
@@ -259,14 +264,15 @@ public class InstitutionContractAmendment : EntityBase
private InstitutionContractAmendment(){}
public InstitutionContractAmendment(long institutionContractId,
List<InstitutionContractInstallment> installments, double amount, bool hasInstallment,
InstitutionContractAmendmentChange amendmentChange, long lawId)
List<InstitutionContractAmendmentChange> amendmentChanges, long lawId)
{
InstitutionContractId = institutionContractId;
Installments = installments is { Count: > 0} ? installments : [];
Amount = amount;
HasInstallment = hasInstallment;
AmendmentChanges = [amendmentChange];
AmendmentChanges = amendmentChanges;
LawId = lawId;
VerificationStatus = InstitutionContractVerificationStatus.PendingForVerify;
}
public long InstitutionContractId { get; set; }
@@ -280,6 +286,15 @@ public class InstitutionContractAmendment : EntityBase
public long LawId { get; set; }
public string VerifierPhoneNumber { get; private set; }
public string VerifierFullName { get; private set; }
public InstitutionContractVerificationStatus VerificationStatus { get; set; }
public DateTime VerifyCodeCreation { get; set; }
public void SetVerifyCode(string code,string verifierFullName, string verifierPhoneNumber)
{
VerifyCode = code;
@@ -287,25 +302,22 @@ public class InstitutionContractAmendment : EntityBase
VerifierFullName = verifierFullName;
VerifierPhoneNumber = verifierPhoneNumber;
}
public string VerifierPhoneNumber { get; private set; }
public string VerifierFullName { get; private set; }
public DateTime VerifyCodeCreation { get; set; }
public void Verified()
{
VerificationStatus = InstitutionContractVerificationStatus.Verified;
}
}
public class InstitutionContractAmendmentChange : EntityBase
{
private InstitutionContractAmendmentChange() { }
private InstitutionContractAmendmentChange(long institutionContractAmendmentId,
InstitutionContractAmendment institutionContractAmendment, InstitutionContractAmendmentChangeType changeType,
DateTime changeDateGr, bool? hasRollCallPlan, bool? hasCustomizeCheckoutPlan, bool? hasContractPlan,
private InstitutionContractAmendmentChange(InstitutionContractAmendmentChangeType changeType,
DateTime changeDateGr, bool? hasCustomizeCheckoutPlan, bool? hasContractPlan,
bool? hasContractPlanInPerson, bool? hasInsurancePlan, bool? hasInsurancePlanInPerson, int? personnelCount,
long? workshopDetailsId)
bool? hasRollCallPlan, bool? hasRollCallInPerson,
long? currentWorkshopId, int personnelCountDifference)
{
InstitutionContractAmendmentId = institutionContractAmendmentId;
InstitutionContractAmendment = institutionContractAmendment;
ChangeType = changeType;
ChangeDateGr = changeDateGr;
HasRollCallPlan = hasRollCallPlan;
@@ -315,9 +327,80 @@ public class InstitutionContractAmendmentChange : EntityBase
HasInsurancePlan = hasInsurancePlan;
HasInsurancePlanInPerson = hasInsurancePlanInPerson;
PersonnelCount = personnelCount;
WorkshopDetailsId = workshopDetailsId;
PersonnelCountDifference = personnelCountDifference;
CurrentWorkshopId = currentWorkshopId;
HasRollCallInPerson = hasRollCallInPerson;
}
/// <summary>
/// تغییر تعداد پرسنل
/// </summary>
public static InstitutionContractAmendmentChange CreatePersonCountChange(
DateTime changeDateGr, int personnelCount, int personnelCountDifference,
long currentWorkshopId)
{
return new InstitutionContractAmendmentChange(
changeType: InstitutionContractAmendmentChangeType.PersonCount,
changeDateGr: changeDateGr,
hasCustomizeCheckoutPlan: null,
hasContractPlan: null,
hasContractPlanInPerson: null,
hasInsurancePlan: null,
hasInsurancePlanInPerson: null,
personnelCount: personnelCount,
hasRollCallPlan: null,
hasRollCallInPerson: null,
currentWorkshopId: currentWorkshopId,
personnelCountDifference: personnelCountDifference);
}
/// <summary>
/// تغییر خدمات
/// </summary>
public static InstitutionContractAmendmentChange CreateServicesChange(
DateTime changeDateGr, long currentWorkshopId, bool hasRollCallPlan, bool hasRollCallInPerson,
bool hasCustomizeCheckoutPlan, bool hasContractPlan, bool hasContractPlanInPerson,
bool hasInsurancePlan, bool hasInsurancePlanInPerson)
{
return new InstitutionContractAmendmentChange(
changeType: InstitutionContractAmendmentChangeType.Services,
changeDateGr: changeDateGr,
hasCustomizeCheckoutPlan: hasCustomizeCheckoutPlan,
hasContractPlan: hasContractPlan,
hasContractPlanInPerson: hasContractPlanInPerson,
hasInsurancePlan: hasInsurancePlan,
hasInsurancePlanInPerson: hasInsurancePlanInPerson,
personnelCount: null,
hasRollCallPlan: hasRollCallPlan,
hasRollCallInPerson: hasRollCallInPerson,
currentWorkshopId: currentWorkshopId,
personnelCountDifference: 0);
}
/// <summary>
/// ایجاد کارگاه جدید
/// </summary>
public static InstitutionContractAmendmentChange CreateWorkshopCreatedChange(
DateTime changeDateGr, bool hasRollCallPlan, bool hasRollCallInPerson,
bool hasCustomizeCheckoutPlan, bool hasContractPlan, bool hasContractPlanInPerson,
bool hasInsurancePlan, bool hasInsurancePlanInPerson,int personnelCount)
{
return new InstitutionContractAmendmentChange(
changeType: InstitutionContractAmendmentChangeType.WorkshopCreated,
changeDateGr: changeDateGr,
hasCustomizeCheckoutPlan: hasCustomizeCheckoutPlan,
hasContractPlan: hasContractPlan,
hasContractPlanInPerson: hasContractPlanInPerson,
hasInsurancePlan: hasInsurancePlan,
hasInsurancePlanInPerson: hasInsurancePlanInPerson,
personnelCount: personnelCount,
hasRollCallPlan: hasRollCallPlan,
hasRollCallInPerson: hasRollCallInPerson,
currentWorkshopId: null,
personnelCountDifference: 0);
}
public long InstitutionContractAmendmentId { get; private set; }
public InstitutionContractAmendment InstitutionContractAmendment { get; private set; }
public InstitutionContractAmendmentChangeType ChangeType { get; private set; }
@@ -328,6 +411,8 @@ public class InstitutionContractAmendmentChange : EntityBase
/// </summary>
public bool? HasRollCallPlan { get; private set; }
public bool? HasRollCallInPerson { get; set; }
/// <summary>
/// پلن فیش غیر رسمی
/// </summary>
@@ -357,11 +442,17 @@ public class InstitutionContractAmendmentChange : EntityBase
/// تعداد پرسنل
/// </summary>
public int? PersonnelCount { get; private set; }
/// <summary>
/// مقدار تغییرات تعداد پرسنل
/// </summary>
public int PersonnelCountDifference { get; set; }
/// <summary>
/// تعداد کارگاه
/// </summary>
public long? WorkshopDetailsId { get; private set; }
public long? CurrentWorkshopId { get; private set; }
}
public enum InstitutionContractAmendmentChangeType

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CompanyManagment.App.Contracts.InstitutionContract;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
@@ -25,7 +26,21 @@ public class InstitutionContractAmendmentTemp
public Guid Id { get; private set; }
public List<InstitutionContractAmendmentTempPrevWorkshop> PrevWorkshops { get; private set; }
public List<InstitutionContractAmendmentTempNewWorkshop> NewWorkshops { get; private set; }
public InstitutionContractPaymentMonthlyViewModel MonthlyPayment { get; set; }
public InstitutionContractPaymentOneTimeViewModel OneTimePayment { get; set; }
public long InstitutionContractId { get; private set; }
public int MonthDifference { get; set; }
public void AddPaymentDetails(InstitutionContractPaymentMonthlyViewModel resMonthly, InstitutionContractPaymentOneTimeViewModel resOneTime, int monthDiff)
{
MonthlyPayment = resMonthly;
OneTimePayment = resOneTime;
MonthDifference = monthDiff;
}
}
public class InstitutionContractAmendmentTempNewWorkshop : InstitutionContractAmendmentTempPrevWorkshop

View File

@@ -244,7 +244,7 @@ public interface IInstitutionContractApplication
#endregion
Task<OperationResult> ResendVerifyLink(long institutionContractId);
Task AmendmentComplete(InstitutionContractAmendmentCompleteRequest request);
/// <summary>
/// دیتای پرینت قرارداد مالی
/// </summary>
@@ -253,6 +253,15 @@ public interface IInstitutionContractApplication
Task<InstitutionContractPrintViewModel> PrintOneAsync(long id);
}
public class InstitutionContractAmendmentCompleteRequest
{
public Guid TempId { get; set; }
public bool IsInstallment { get; set; }
public long LawId { get; set; }
}
public class InstitutionContractPrintViewModel
{
public InstitutionContratVerificationParty FirstParty { get; set; }

View File

@@ -1140,7 +1140,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
CreateContractingPartyAccount(contractingParty.id, res.SendId);
await _smsService.SendInstitutionVerificationLink(contractingParty.Phone, contractingPartyFullName,
await _smsService.SendInstitutionCreationVerificationLink(contractingParty.Phone, contractingPartyFullName,
entity.PublicId, contractingParty.id,entity.id );
await _institutionContractRepository.SaveChangesAsync();
@@ -1377,7 +1377,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
if (contractingParty == null)
throw new NotFoundException("طرف قرارداد یافت نشد");
var contractingPartyFullName = contractingParty.FName + " " + contractingParty.LName;
await _smsService.SendInstitutionVerificationLink(contractingParty.Phone, contractingPartyFullName,
await _smsService.SendInstitutionCreationVerificationLink(contractingParty.Phone, contractingPartyFullName,
institutionContract.PublicId, contractingParty.id, institutionContract.id);
return new OperationResult().Succcedded();
}
@@ -1387,6 +1387,11 @@ public class InstitutionContractApplication : IInstitutionContractApplication
return (await _institutionContractRepository.PrintAllAsync([id])).FirstOrDefault();
}
public async Task AmendmentComplete(InstitutionContractAmendmentCompleteRequest request)
{
await _institutionContractRepository.AmendmentComplete(request);
}
private async Task<OperationResult<PersonalContractingParty>> CreateLegalContractingPartyEntity(
CreateInstitutionContractLegalPartyRequest request, long representativeId, string address, string city,

View File

@@ -29,7 +29,6 @@ using CompanyManagment.App.Contracts.Law;
using CompanyManagment.App.Contracts.TemporaryClientRegistration;
using CompanyManagment.App.Contracts.Workshop;
using CompanyManagment.App.Contracts.WorkshopPlan;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@@ -2342,7 +2341,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
await SaveChangesAsync();
await _smsService.SendInstitutionVerificationLink(contractingParty.Phone, contractingPartyFullName,
await _smsService.SendInstitutionCreationVerificationLink(contractingParty.Phone, contractingPartyFullName,
entity.PublicId, contractingParty.id, entity.id);
@@ -2374,6 +2373,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
x.WorkshopId??0,x.id)).ToList();
await _institutionAmendmentTemp
.DeleteManyAsync(x => x.InstitutionContractId == institutionContractId);;
var temp = new InstitutionContractAmendmentTemp(workshops, institutionContractId);
@@ -2456,7 +2457,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
if (endDay > startDay)
monthDiff++;
var sumOneMonth = institutionContractAmendmentTemp.NewWorkshops.Sum(x => x.PriceDifference);
var sumOneMonth = institutionContractAmendmentTemp
.NewWorkshops.Sum(x => x.PriceDifference);
var baseAmount = monthDiff * sumOneMonth;
var tax = baseAmount*0.10;
@@ -2515,6 +2517,13 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
};
}
institutionContractAmendmentTemp.AddPaymentDetails(res.Monthly, res.OneTime, monthDiff);
await _institutionAmendmentTemp
.ReplaceOneAsync(x => x.Id == institutionContractAmendmentTemp.Id, institutionContractAmendmentTemp);
return res;
}
@@ -2765,6 +2774,120 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
return res;
}
public async Task AmendmentComplete(InstitutionContractAmendmentCompleteRequest request)
{
var amendmentTemp = await _institutionAmendmentTemp
.Find(x=>x.Id == request.TempId).FirstOrDefaultAsync();
if (amendmentTemp == null)
throw new BadRequestException("دیتای وارد شده نامعتبر است");
var institutionContract = await _context.InstitutionContractSet
.Include(x=>x.Amendments)
.Include(x=>x.WorkshopGroup)
.ThenInclude(x=>x.CurrentWorkshops)
.FirstOrDefaultAsync(x => x.id == amendmentTemp.InstitutionContractId);
List<InstitutionContractInstallment> installments = [];
double amount = 0;
if (request.IsInstallment)
{
installments = amendmentTemp.MonthlyPayment.Installments.Select(x=>
new InstitutionContractInstallment(x.InstalmentDate.ToGeorgianDateTime(),
x.InstallmentAmountStr.MoneyToDouble(), "")).ToList();
amount = amendmentTemp.MonthlyPayment.PaymentAmount.MoneyToDouble();
}
else
{
amount = amendmentTemp.OneTimePayment.PaymentAmount.MoneyToDouble();
}
var newWorkshops = amendmentTemp
.NewWorkshops.Where(x=>x.CurrentWorkshopId ==0).ToList();
var newWorkshopTempIds = newWorkshops.Select(x=>x.Id).ToList();
var changes = newWorkshops.Select(x=>
InstitutionContractAmendmentChange.CreateWorkshopCreatedChange(DateTime.Now,x.RollCall,x.RollCallInPerson,x.CustomizeCheckout,
x.ContractAndCheckout,x.ContractAndCheckoutInPerson,x.Insurance,x.InsuranceInPerson,x.CountPerson)).ToList();
var changedWorkshops = amendmentTemp.NewWorkshops
.Where(x => !newWorkshopTempIds.Contains(x.Id)).ToList();
foreach (var changedWorkshop in changedWorkshops)
{
var prev = amendmentTemp.PrevWorkshops.FirstOrDefault(x => x.Id == changedWorkshop.Id);
if (prev == null)
throw new BadRequestException("دیتای وارد شده ناقص ذخیره شده است");
// مقایسه مقادیر بولین بین prev و changedWorkshop برای تشخیص تغییرات
var changedBooleans = new Dictionary<string, (bool Previous, bool Current)>();
if (prev.CustomizeCheckout != changedWorkshop.CustomizeCheckout)
changedBooleans.Add("CustomizeCheckout", (prev.CustomizeCheckout, changedWorkshop.CustomizeCheckout));
if (prev.ContractAndCheckout != changedWorkshop.ContractAndCheckout)
changedBooleans.Add("ContractAndCheckout", (prev.ContractAndCheckout, changedWorkshop.ContractAndCheckout));
if (prev.ContractAndCheckoutInPerson != changedWorkshop.ContractAndCheckoutInPerson)
changedBooleans.Add("ContractAndCheckoutInPerson", (prev.ContractAndCheckoutInPerson, changedWorkshop.ContractAndCheckoutInPerson));
if (prev.Insurance != changedWorkshop.Insurance)
changedBooleans.Add("Insurance", (prev.Insurance, changedWorkshop.Insurance));
if (prev.InsuranceInPerson != changedWorkshop.InsuranceInPerson)
changedBooleans.Add("InsuranceInPerson", (prev.InsuranceInPerson, changedWorkshop.InsuranceInPerson));
if (prev.RollCall != changedWorkshop.RollCall)
changedBooleans.Add("RollCall", (prev.RollCall, changedWorkshop.RollCall));
if (prev.RollCallInPerson != changedWorkshop.RollCallInPerson)
changedBooleans.Add("RollCallInPerson", (prev.RollCallInPerson, changedWorkshop.RollCallInPerson));
// اگر تغییری وجود داشته باشد، آن را به لیست تغییرات اضافه کن
if (changedBooleans.Any())
{
var change = InstitutionContractAmendmentChange.CreateServicesChange(
DateTime.Now,
changedWorkshop.WorkshopId,
changedWorkshop.RollCall,
changedWorkshop.RollCallInPerson,
changedWorkshop.CustomizeCheckout,
changedWorkshop.ContractAndCheckout,
changedWorkshop.ContractAndCheckoutInPerson,
changedWorkshop.Insurance,
changedWorkshop.InsuranceInPerson);
changes.Add(change);
}
if (changedWorkshop.CountPerson != prev.CountPerson)
{
var difference = changedWorkshop.CountPerson - prev.CountPerson;
var change = InstitutionContractAmendmentChange.CreatePersonCountChange(
DateTime.Now,
changedWorkshop.CountPerson,
difference,changedWorkshop.WorkshopId);
changes.Add(change);
}
}
var amendment = new InstitutionContractAmendment(institutionContract.id,installments,amount,
request.IsInstallment,changes,request.LawId);
institutionContract.AddAmendment(amendment);
await _smsService.SendInstitutionAmendmentVerificationLink(
institutionContract.VerifierPhoneNumber,
institutionContract.ContractingPartyName,
institutionContract.PublicId,
institutionContract.ContractingPartyId,
institutionContract.id
);
await _context.SaveChangesAsync();
}
private InstitutionContractExtensionPaymentResponse CalculateInPersonPayment(
InstitutionContractExtensionPlanDetail selectedPlan, double baseAmount, double tenPercent,

View File

@@ -332,7 +332,7 @@ public class SmsService : ISmsService
}
}
public async Task<bool> SendInstitutionVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId)
public async Task<bool> SendInstitutionCreationVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId)
{
var guidStr=institutionId.ToString();
var firstPart = guidStr.Substring(0, 15);
@@ -343,7 +343,26 @@ public class SmsService : ISmsService
new("CODE1",firstPart),
new("CODE2",secondPart)
});
var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "لینک تاییدیه قرارداد مالی",
var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "لینک تاییدیه ایجاد قرارداد مالی",
fullName, number, contractingPartyId, institutionContractId);
await _smsResultRepository.CreateAsync(smsResult);
await _smsResultRepository.SaveChangesAsync();
return verificationSendResult.Status == 0;
}
public async Task<bool> SendInstitutionAmendmentVerificationLink(string number, string fullName, Guid institutionId,
long contractingPartyId, long institutionContractId)
{
var guidStr=institutionId.ToString();
var firstPart = guidStr.Substring(0, 15);
var secondPart = guidStr.Substring(15);
var verificationSendResult =await SmsIr.VerifySendAsync(number, 527519, new VerifySendParameter[]
{
new("FULLNAME", fullName),
new("CODE1",firstPart),
new("CODE2",secondPart)
});
var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "لینک تاییدیه ارتقا قرارداد مالی",
fullName, number, contractingPartyId, institutionContractId);
await _smsResultRepository.CreateAsync(smsResult);
await _smsResultRepository.SaveChangesAsync();

View File

@@ -541,18 +541,51 @@ public class institutionContractController : AdminBaseController
var res =await _institutionContractApplication.InsertAmendmentTempWorkshops(request);
return res;
}
[HttpDelete("amendment/remove-temp-workshops/{workshopTempId:guid}")]
public async Task<ActionResult> RemoveAmendmentWorkshops(Guid workshopTempId)
{
await _institutionContractApplication.RemoveAmendmentWorkshops(workshopTempId);
return Ok();
}
[HttpPost("amendment/payment-details")]
public async Task<ActionResult<InsitutionContractAmendmentPaymentResponse>> GetAmendmentPaymentDetails([FromBody]InsitutionContractAmendmentPaymentRequest request)
{
var res =await _institutionContractApplication.GetAmendmentPaymentDetails(request);
return res;
}
[HttpPost("amendment/complete/")]
public async Task<ActionResult> AmendmentComplete(
InstitutionContractAmendmentCompleteRequest request)
{
await _institutionContractApplication.AmendmentComplete(request);
return Ok();
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("/api/institutionContract/amendment-Verification/{id:guid}")]
[AllowAnonymous]
public async Task<ActionResult<GetInstitutionVerificationDetailsViewModel>> GetAmendmentVerificationDetails(Guid id)
{
return await _institutionContractApplication.GetAmendmentVerificationDetails(id);
}
[HttpPost("/api/institutionContract/Verify-amendment")]
[AllowAnonymous]
public async Task<ActionResult<OperationResult>> VerifyAmendment([FromBody] InstitutionVerificationRequest command)
{
var res = await _institutionContractApplication.AmendmentVerifyOtp(command.Id, command.Code);
return res;
}
[HttpGet("edit-old/{id}")]