feat: implement amendment completion functionality with payment details
This commit is contained in:
@@ -75,4 +75,5 @@ public interface IInstitutionContractRepository : IRepository<long, InstitutionC
|
||||
#endregion
|
||||
|
||||
Task<List<InstitutionContractSelectListViewModel>> GetInstitutionContractSelectList(string search, string selected);
|
||||
Task AmendmentComplete(InstitutionContractAmendmentCompleteRequest request);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user