feat: implement amendment completion functionality with payment details

This commit is contained in:
2025-10-23 11:44:12 +03:30
parent 8d24339f04
commit 1a70569a36
7 changed files with 80 additions and 9 deletions

View File

@@ -75,4 +75,5 @@ public interface IInstitutionContractRepository : IRepository<long, InstitutionC
#endregion
Task<List<InstitutionContractSelectListViewModel>> GetInstitutionContractSelectList(string search, string selected);
Task AmendmentComplete(InstitutionContractAmendmentCompleteRequest request);
}

View File

@@ -248,6 +248,11 @@ public class InstitutionContract : EntityBase
{
WorkshopGroup = null;
}
public void AddAmendment(InstitutionContractAmendment amendment)
{
Amendments.Add(amendment);
}
}
public class InstitutionContractAmendment : EntityBase
@@ -255,13 +260,13 @@ 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;
}

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

@@ -241,11 +241,14 @@ public interface IInstitutionContractApplication
#endregion
Task<OperationResult> ResendVerifyLink(long institutionContractId);
Task<OperationResult> AmendmentComplete(InstitutionContractAmendmentCompleteRequest request);
Task AmendmentComplete(InstitutionContractAmendmentCompleteRequest request);
}
public class InstitutionContractAmendmentCompleteRequest
{
public Guid TempId { get; set; }
public bool IsInstallment { get; set; }
public long LawId { get; set; }
}
public class InsertAmendmentTempWorkshopResponse

View File

@@ -1377,9 +1377,9 @@ public class InstitutionContractApplication : IInstitutionContractApplication
return new OperationResult().Succcedded();
}
public Task<OperationResult> AmendmentComplete(InstitutionContractAmendmentCompleteRequest request)
public async Task AmendmentComplete(InstitutionContractAmendmentCompleteRequest request)
{
throw new NotImplementedException();
await _institutionContractRepository.AmendmentComplete(request);
}

View File

@@ -2451,7 +2451,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;
@@ -2510,6 +2511,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;
}
@@ -2654,6 +2662,43 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
}
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 amendment = new InstitutionContractAmendment(institutionContract.id,installments,amount,
request.IsInstallment,,request.LawId);
institutionContract.AddAmendment(amendment);
}
private InstitutionContractExtensionPaymentResponse CalculateInPersonPayment(
InstitutionContractExtensionPlanDetail selectedPlan, double baseAmount, double tenPercent,

View File

@@ -556,12 +556,14 @@ public class institutionContractController : AdminBaseController
return res;
}
public async Task<ActionResult<OperationResult>> CompleteAmendment(
[HttpPost("amendment/complete/")]
public async Task<ActionResult> AmendmentComplete(
InstitutionContractAmendmentCompleteRequest request)
{
var res = await _institutionContractApplication.AmendmentComplete(request);
return res;
await _institutionContractApplication.AmendmentComplete(request);
return Ok();
}