Refactor institution contract discount calculation to use TotalAmount instead of PaymentAmount

This commit is contained in:
2025-11-29 13:26:04 +03:30
parent 5e5910e0fd
commit 452b0b6277
4 changed files with 33 additions and 32 deletions

View File

@@ -102,7 +102,7 @@ public class CreateInstitutionContractRequest
public double OneMonthAmount { get; set; }
public long LawId { get; set; }
public int DiscountPercentage { get; set; }
public double DiscountAmount { get; set; }

View File

@@ -267,7 +267,7 @@ public interface IInstitutionContractApplication
public class InstitutionContractResetDiscountForCreateRequest
{
public int Percentage { get; set; }
public double PaymentAmount { get; set; }
public double TotalAmount { get; set; }
public bool IsInstallment { get; set; }
public InstitutionContractDuration Duration { get; set; }
}
@@ -276,7 +276,7 @@ public class InstitutionContractSetDiscountForExtensionRequest
{
public Guid TempId { get; set; }
public int DiscountPercentage { get; set; }
public double PaymentAmount { get; set; }
public double TotalAmount { get; set; }
public bool IsInstallment { get; set; }
}
public class InstitutionContractResetDiscountForExtensionRequest
@@ -289,7 +289,7 @@ public class InstitutionContractResetDiscountForExtensionRequest
public class InstitutionContractSetDiscountRequest
{
public int DiscountPercentage { get; set; }
public double PaymentAmount { get; set; }
public double TotalAmount { get; set; }
public InstitutionContractDuration Duration { get; set; }
public bool IsInstallment { get; set; }
}

View File

@@ -1872,11 +1872,11 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
public InstitutionContractExtensionPaymentResponse CalculateDiscount(InstitutionContractSetDiscountRequest request)
{
var baseAmount = request.PaymentAmount;
var baseAmount = request.TotalAmount;
var discountAmount = (baseAmount * request.DiscountPercentage) / 100;
var paymentAmount = baseAmount - discountAmount;
var taxAmount = paymentAmount * 0.10;
var totalAmount = paymentAmount + taxAmount;
var totalAmount = baseAmount - discountAmount;
var taxAmount = totalAmount * 0.10;
var paymentAmount = totalAmount + taxAmount;
InstitutionContractPaymentMonthlyViewModel monthlyPayment = null;
InstitutionContractPaymentOneTimeViewModel oneTimePayment = null;
@@ -1923,30 +1923,30 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
if (request.IsInstallment)
{
var newPaymentAmount = request.PaymentAmount / (1 - (request.Percentage / 100));
var taxAmount = (newPaymentAmount * 0.10);
var paymentAmount = (newPaymentAmount + taxAmount);
var newTotalAmount = request.TotalAmount / (1 - (request.Percentage / 100));
var taxAmount = (newTotalAmount * 0.10);
var paymentAmount = (newTotalAmount + taxAmount);
monthlyPayment = new InstitutionContractPaymentMonthlyViewModel()
{
PaymentAmount = newPaymentAmount.ToMoney(),
TotalAmount = newTotalAmount.ToMoney(),
Tax = taxAmount.ToMoney(),
DiscountedAmount = "0",
DiscountPercetage = 0,
TotalAmount =paymentAmount.ToMoney(),
PaymentAmount = paymentAmount.ToMoney(),
Installments = InstitutionMonthlyInstallmentCaculation((int)request.Duration,
paymentAmount, DateTime.Now.ToFarsi())
};
}
else
{
var newPaymentAmount = request.PaymentAmount / (1 - (request.Percentage / 100));
var taxAmount = (newPaymentAmount * 0.10);
var paymentAmount = (newPaymentAmount + taxAmount);
var newTotalAmount = request.TotalAmount / (1 - (request.Percentage / 100));
var taxAmount = (newTotalAmount * 0.10);
var paymentAmount = (newTotalAmount + taxAmount);
oneTimePayment = new InstitutionContractPaymentOneTimeViewModel()
{
PaymentAmount = newPaymentAmount.ToMoney(),
TotalAmount = newTotalAmount.ToMoney(),
Tax = taxAmount.ToMoney(),
TotalAmount = paymentAmount.ToMoney(),
PaymentAmount = paymentAmount.ToMoney(),
DiscountedAmount = "0",
DiscountPercetage = 0
};
@@ -2292,7 +2292,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
var calculateRequest = new InstitutionContractSetDiscountRequest()
{
Duration = institutionTemp.Duration.Value,
PaymentAmount = request.PaymentAmount,
TotalAmount = request.TotalAmount,
DiscountPercentage = request.DiscountPercentage,
IsInstallment = request.IsInstallment
};
@@ -2333,18 +2333,19 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
if (request.IsInstallment)
{
var prevMonthlyPayment = institutionTemp.MonthlyPayment;
var resetPaymentAmount = prevMonthlyPayment.PaymentAmount.MoneyToDouble() / (1 - (prevMonthlyPayment.DiscountPercetage / 100.0));
var resetTax = (resetPaymentAmount * 0.10);
var totalAmount = (resetPaymentAmount + resetTax);
var resetTotalAmount = prevMonthlyPayment.TotalAmount.MoneyToDouble() /
(1 - (prevMonthlyPayment.DiscountPercetage / 100.0));
var resetTax = (resetTotalAmount * 0.10);
var paymentAmount = (resetTotalAmount + resetTax);
monthlyPayment = new InstitutionContractPaymentMonthlyViewModel()
{
DiscountPercetage = 0,
DiscountedAmount = "0",
PaymentAmount = resetPaymentAmount.ToMoney(),
PaymentAmount = paymentAmount.ToMoney(),
Tax = resetTax.ToMoney(),
TotalAmount = totalAmount.ToMoney(),
TotalAmount = resetTotalAmount.ToMoney(),
Installments = InstitutionMonthlyInstallmentCaculation((int)institutionTemp.Duration.Value,
totalAmount, DateTime.Now.ToFarsi()),
paymentAmount, DateTime.Now.ToFarsi()),
};
institutionTemp.MonthlyPayment = monthlyPayment;
await _institutionExtensionTemp.ReplaceOneAsync(x=>x.Id == institutionTemp.Id,
@@ -2354,16 +2355,16 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
else
{
var prevOneTimePayment = institutionTemp.OneTimePayment;
var resetPaymentAmount = prevOneTimePayment.PaymentAmount.MoneyToDouble() /
(1 - (prevOneTimePayment.DiscountPercetage / 100.0));
var resetTax = (resetPaymentAmount * 0.10);
var resetTotalAmount = prevOneTimePayment.TotalAmount.MoneyToDouble() /
(1 - (prevOneTimePayment.DiscountPercetage / 100.0));
var resetTax = (resetTotalAmount * 0.10);
oneTimePayment = new InstitutionContractPaymentOneTimeViewModel()
{
DiscountPercetage = 0,
DiscountedAmount = "0",
PaymentAmount = resetPaymentAmount.ToMoney(),
TotalAmount = resetTotalAmount.ToMoney(),
Tax = resetTax.ToMoney(),
TotalAmount = (resetPaymentAmount + resetTax).ToMoney(),
PaymentAmount = (resetTotalAmount + resetTax).ToMoney(),
};
institutionTemp.OneTimePayment = oneTimePayment;
await _institutionExtensionTemp.ReplaceOneAsync(x=>x.Id == institutionTemp.Id,
@@ -3042,7 +3043,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
{
OneTime = new()
{
TotalAmount = selectedPlan.TotalPayment,
TotalAmount = oneTimeBase.ToMoney(),
Tax = oneTimeTax.ToMoney(),
PaymentAmount = oneTimeTotal.ToMoney()
}

View File

@@ -19,7 +19,7 @@
"sqlDebugging": true,
"dotnetRunMessages": "true",
"nativeDebugging": true,
"applicationUrl": "https://localhost:5004;http://localhost:5003;",
"applicationUrl": "https://localhost:5004;http://localhost:5003;https://192.168.0.117:5005",
"jsWebView2Debugging": false,
"hotReloadEnabled": true
},