feat: simplify institution plan calculator by removing contract start type parameter and updating response properties

This commit is contained in:
MahanCh
2025-08-30 13:42:52 +03:30
parent 4bc3fd2fbc
commit 866725e3b4
4 changed files with 186 additions and 243 deletions

View File

@@ -66,15 +66,13 @@ public interface ITemporaryClientRegistrationApplication
/// این متد برای زمانی است که کارگاه ها در مرحله ثبت نام موقت هستند
/// و هنوز در دیتابیس ثبت نشده اند
/// </summary>
/// <param name="contractingPartyTempId"></param>
/// <param name="totalPaymentMonth"></param>
/// <param name="duration"></param>
/// <param name="contractStartType"></param>
/// <param name="contractingPartyTempId"></param>
/// <param name="paymentModel"></param>
/// <returns></returns>
Task<ReviewAndPaymentViewModel> GetTotalPaymentAndWorkshopList(long contractingPartyTempId,
double totalPaymentMonth,
InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths, string contractStartType = "currentMonth");
Task<ReviewAndPaymentViewModel> GetTotalPaymentAndWorkshopList( double totalPaymentMonth,
InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths);
/// <summary>
/// ایجاد یا ویرایش قرارداد موقت

View File

@@ -1,26 +1,20 @@
using System;
using System.Collections.Generic;
using CompanyManagment.App.Contracts.InstitutionContract;
using CompanyManagment.App.Contracts.Workshop;
namespace CompanyManagment.App.Contracts.TemporaryClientRegistration;
public class ReviewAndPaymentViewModel
{
/// <summary>
/// جمع کل
/// double
/// </summary>
public double SumOfWorkshopsPaymentDouble { get; set; }
/// <summary>
/// جمع کل
/// string
/// تخفیف
/// </summary>
public string SumOfWorkshopsPaymentPaymentStr { get; set; }
public string Discount { get; set; }
public string SumOfWorkshopsPayment { get; set; }
/// <summary>
/// مبلغ پرداخت بدون مالیات
/// Double
@@ -45,9 +39,7 @@ public class ReviewAndPaymentViewModel
/// string
/// </summary>
public string OneTimeTotalPaymentStr { get; set; }
/// <summary>
/// مبلغ پرداخت بدون مالیات
/// Double
@@ -85,66 +77,29 @@ public class ReviewAndPaymentViewModel
/// </summary>
public string ValueAddedTaxStr { get; set; }
/// <summary>
/// بازه قرداد
/// با عدد مشخص میشود
/// مثلا یک ماه عدد 1
/// </summary>
public InstitutionContractDuration Duration { get; set; }
/// <summary>
/// OneTime پرداخت یکجا
/// -
/// Monthly پرداخت ماهانه
/// </summary>
public string PaymentModel { get; set; }
/// <summary>
/// لیست کارگاه های ایجاد شده
/// </summary>
public List<WorkshopTempViewModel> WorkshopTempViewList { get; set; }
/// <summary>
/// آی دی طرف حساب
/// </summary>
public long ContractingPartTempId { get; set; }
/// <summary>
/// لیست اقساط ماهیانه
/// </summary>
public List<MonthlyInstallment> MonthlyInstallments { get; set; }
/// <summary>
/// شروع قرارداد - شمسی
/// </summary>
public string ContractStartFa { get; set; }
/// <summary>
/// تاریخ شروع قرارداد در اول ماه جاری
/// -
/// شمسی
/// شروع قرارداد - میلادی
/// </summary>
public string ContractStartCurrentMonthFa { get; set; }
/// <summary>
/// تاریخ شروع قرارداد در اول ماه جاری
/// -
/// میلادی
/// </summary>
public DateTime ContractStartCurrentMonthGr { get; set; }
/// <summary>
/// تاریخ شروع قرارداد در اول ماه بعد
/// -
/// شمسی
/// </summary>
public string ContractStartNextMonthFa{ get; set; }
/// <summary>
/// تاریخ شروع قرارداد در اول ماه بعد
/// -
/// میلادی
/// </summary>
public DateTime ContractStartNextMonthGr { get; set; }
public DateTime ContractStartGr { get; set; }
/// <summary>
/// تاریخ پایان قرارداد

View File

@@ -363,6 +363,7 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
}
/// <summary>
/// بررسی و پرداخت
/// اطلاعات کامل مبالغ
@@ -372,149 +373,151 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
public async Task<ReviewAndPaymentViewModel> GetTotalPaymentAndWorkshopList(long contractingPartyTempId,
InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths, string paymentModel = "OneTime", string contractStartType = "currentMonth")
{
//دریافت کارگاه ها
var workshops = await _workshopTempRepository.GetWorkshopTemp(contractingPartyTempId);
double totalPayment1MonthDouble = 0;
//بدست آوردن جمع کل برای یک ماه
foreach (var workshop in workshops)
{
totalPayment1MonthDouble += workshop.WorkshopServicesAmount;
}
if (totalPayment1MonthDouble == 0)
return new ReviewAndPaymentViewModel();
var result = new ReviewAndPaymentViewModel();
int months = 0;
months = (int)duration;
//رند کردن مبالغ کارگاه ها
var roundAmount = (((Convert.ToInt64(totalPayment1MonthDouble))) / 1000000) * 1000000;
double roundAmount2 = roundAmount;
//بدست آوردن جمع کل مبالغ کارگاه بر اساس مدت قراداد
result.SumOfWorkshopsPaymentDouble = months * roundAmount2;
result.SumOfWorkshopsPaymentPaymentStr = result.SumOfWorkshopsPaymentDouble.ToMoney();
result.Duration = duration;
result.PaymentModel = paymentModel;
var tenPercent = result.SumOfWorkshopsPaymentDouble * 10 / 100;
//مالیات
result.ValueAddedTaxDouble = tenPercent;
result.ValueAddedTaxStr = tenPercent.ToMoney();
//پرداخت یکجا
#region OneTimePaymentResult
double discountOneTimePeyment = result.SumOfWorkshopsPaymentDouble - tenPercent;
//مبلغ بدون مالیات و با تخفیف
result.OneTimeWithoutTaxPaymentDouble = discountOneTimePeyment;
result.OneTimeWithoutTaxPaymentStr = discountOneTimePeyment.ToMoney();
//مبلغ با مالیات
result.OneTimeTotalPaymentDouble = discountOneTimePeyment + tenPercent;
result.OneTimeTotalPaymentStr = result.OneTimeTotalPaymentDouble.ToMoney();
#endregion
//پرداخت ماهیانه
#region MonthlyPaymentResult
//مبلغ بدون مالیات
result.MonthlyWithoutTaxPaymentDouble = result.SumOfWorkshopsPaymentDouble;
result.MonthlyWithoutTaxPaymentStr = result.SumOfWorkshopsPaymentDouble.ToMoney();
// مبلغ با مالیات
result.MonthlyTotalPaymentDouble = result.SumOfWorkshopsPaymentDouble + tenPercent;
result.MonthlyTotalPaymentStr = result.MonthlyTotalPaymentDouble.ToMoney();
var installmentList = new List<MonthlyInstallment>();
var startDate = (DateTime.Now).ToFarsi();
result.ContractStartCurrentMonthFa = $"{startDate.Substring(0, 8)}01";
result.ContractStartCurrentMonthGr = result.ContractStartCurrentMonthFa.ToGeorgianDateTime();
startDate = result.ContractStartCurrentMonthFa;
result.ContractStartNextMonthGr = ((startDate.FindeEndOfMonth()).ToGeorgianDateTime()).AddDays(1);
result.ContractStartNextMonthFa = result.ContractStartNextMonthGr.ToFarsi();
if (contractStartType == "nextMonth")
startDate = result.ContractStartNextMonthFa;
var findeEnd = Tools.FindEndOfContract(startDate, ((int)duration).ToString());
var contractEndDate = findeEnd.endDateGr;
result.ContractEndGr = contractEndDate;
result.ContractEndFa = contractEndDate.ToFarsi();
if (duration == InstitutionContractDuration.OneMonth)
{
installmentList.Add(new MonthlyInstallment()
{
InstallmentAmountStr = result.MonthlyTotalPaymentStr,
InstallmentCounter = "سررسید پرداخت اول",
InstalmentDate = (DateTime.Now).ToFarsi()
});
result.MonthlyInstallments = installmentList;
}
else
{
int instalmentCount = (int)duration;
var instalmentAmount = result.MonthlyTotalPaymentDouble / instalmentCount;
var findEndOfMonth = startDate.FindeEndOfMonth();
for (int i = 1; i <= instalmentCount; i++)
{
if (i == 1)
{
startDate = (DateTime.Now).ToFarsi();
}
else if (i > 1)
{
var currentMonthStart = ((findEndOfMonth.ToGeorgianDateTime()).AddDays(1)).ToFarsi();
startDate = currentMonthStart.FindeEndOfMonth();
findEndOfMonth = startDate;
}
installmentList.Add(new MonthlyInstallment()
{
InstallmentAmountStr = instalmentAmount.ToMoney(),
InstallmentCounter = i switch
{
1 => "سررسید پرداخت اول",
2 => "سررسید پرداخت دوم",
3 => "سررسید پرداخت سوم",
4 => "سررسید پرداخت چهارم",
5 => "سررسید پرداخت پنجم",
6 => "سررسید پرداخت ششم",
7 => "سررسید پرداخت هفتم",
8 => "سررسید پرداخت هشتم",
9 => "سررسید پرداخت نهم",
10 => "سررسید پرداخت دهم",
11 => "سررسید پرداخت یازدهم",
12 => "سررسید پرداخت دوازدهم",
_ => "سررسید پرداخت دوازدهم",
},
InstalmentDate = startDate
});
}
}
#endregion
result.MonthlyInstallments = installmentList;
result.ContractingPartTempId = contractingPartyTempId;
return result;
throw new NotImplementedException();
// //دریافت کارگاه ها
// var workshops = await _workshopTempRepository.GetWorkshopTemp(contractingPartyTempId);
//
// double totalPayment1MonthDouble = 0;
//
// //بدست آوردن جمع کل برای یک ماه
// foreach (var workshop in workshops)
// {
// totalPayment1MonthDouble += workshop.WorkshopServicesAmount;
// }
//
// if (totalPayment1MonthDouble == 0)
// return new ReviewAndPaymentViewModel();
//
// var result = new ReviewAndPaymentViewModel();
//
// int months = 0;
// months = (int)duration;
// //رند کردن مبالغ کارگاه ها
// var roundAmount = (((Convert.ToInt64(totalPayment1MonthDouble))) / 1000000) * 1000000;
// double roundAmount2 = roundAmount;
// //بدست آوردن جمع کل مبالغ کارگاه بر اساس مدت قراداد
// result.SumOfWorkshopsPaymentDouble = months * roundAmount2;
// result.SumOfWorkshopsPaymentPaymentStr = result.SumOfWorkshopsPaymentDouble.ToMoney();
//
//
// result.Duration = duration;
// result.PaymentModel = paymentModel;
//
//
// var tenPercent = result.SumOfWorkshopsPaymentDouble * 10 / 100;
// //مالیات
// result.ValueAddedTaxDouble = tenPercent;
// result.ValueAddedTaxStr = tenPercent.ToMoney();
// //پرداخت یکجا
//
// #region OneTimePaymentResult
//
// double discountOneTimePeyment = result.SumOfWorkshopsPaymentDouble - tenPercent;
//
//
// //مبلغ بدون مالیات و با تخفیف
// result.OneTimeWithoutTaxPaymentDouble = discountOneTimePeyment;
// result.OneTimeWithoutTaxPaymentStr = discountOneTimePeyment.ToMoney();
//
// //مبلغ با مالیات
// result.OneTimeTotalPaymentDouble = discountOneTimePeyment + tenPercent;
// result.OneTimeTotalPaymentStr = result.OneTimeTotalPaymentDouble.ToMoney();
//
// #endregion
//
// //پرداخت ماهیانه
//
// #region MonthlyPaymentResult
//
// //مبلغ بدون مالیات
// result.MonthlyWithoutTaxPaymentDouble = result.SumOfWorkshopsPaymentDouble;
// result.MonthlyWithoutTaxPaymentStr = result.SumOfWorkshopsPaymentDouble.ToMoney();
//
// // مبلغ با مالیات
// result.MonthlyTotalPaymentDouble = result.SumOfWorkshopsPaymentDouble + tenPercent;
// result.MonthlyTotalPaymentStr = result.MonthlyTotalPaymentDouble.ToMoney();
// var installmentList = new List<MonthlyInstallment>();
//
// var startDate = (DateTime.Now).ToFarsi();
// result.ContractStartCurrentMonthFa = $"{startDate.Substring(0, 8)}01";
// result.ContractStartCurrentMonthGr = result.ContractStartCurrentMonthFa.ToGeorgianDateTime();
// startDate = result.ContractStartCurrentMonthFa;
//
// result.ContractStartNextMonthGr = ((startDate.FindeEndOfMonth()).ToGeorgianDateTime()).AddDays(1);
// result.ContractStartNextMonthFa = result.ContractStartNextMonthGr.ToFarsi();
//
// if (contractStartType == "nextMonth")
// startDate = result.ContractStartNextMonthFa;
//
//
// var findeEnd = Tools.FindEndOfContract(startDate, ((int)duration).ToString());
// var contractEndDate = findeEnd.endDateGr;
// result.ContractEndGr = contractEndDate;
// result.ContractEndFa = contractEndDate.ToFarsi();
//
// if (duration == InstitutionContractDuration.OneMonth)
// {
// installmentList.Add(new MonthlyInstallment()
// {
// InstallmentAmountStr = result.MonthlyTotalPaymentStr,
// InstallmentCounter = "سررسید پرداخت اول",
// InstalmentDate = (DateTime.Now).ToFarsi()
// });
// result.MonthlyInstallments = installmentList;
// }
// else
// {
// int instalmentCount = (int)duration;
// var instalmentAmount = result.MonthlyTotalPaymentDouble / instalmentCount;
// var findEndOfMonth = startDate.FindeEndOfMonth();
// for (int i = 1; i <= instalmentCount; i++)
// {
// if (i == 1)
// {
// startDate = (DateTime.Now).ToFarsi();
// }
// else if (i > 1)
// {
// var currentMonthStart = ((findEndOfMonth.ToGeorgianDateTime()).AddDays(1)).ToFarsi();
// startDate = currentMonthStart.FindeEndOfMonth();
// findEndOfMonth = startDate;
// }
//
// installmentList.Add(new MonthlyInstallment()
// {
// InstallmentAmountStr = instalmentAmount.ToMoney(),
// InstallmentCounter = i switch
// {
// 1 => "سررسید پرداخت اول",
// 2 => "سررسید پرداخت دوم",
// 3 => "سررسید پرداخت سوم",
// 4 => "سررسید پرداخت چهارم",
// 5 => "سررسید پرداخت پنجم",
// 6 => "سررسید پرداخت ششم",
// 7 => "سررسید پرداخت هفتم",
// 8 => "سررسید پرداخت هشتم",
// 9 => "سررسید پرداخت نهم",
// 10 => "سررسید پرداخت دهم",
// 11 => "سررسید پرداخت یازدهم",
// 12 => "سررسید پرداخت دوازدهم",
// _ => "سررسید پرداخت دوازدهم",
// },
// InstalmentDate = startDate
// });
// }
// }
//
// #endregion
//
// result.MonthlyInstallments = installmentList;
// result.ContractingPartTempId = contractingPartyTempId;
//
// return result;
}
public async Task<ReviewAndPaymentViewModel> GetTotalPaymentAndWorkshopList(long contractingPartyTempId,
double totalPaymentMonth, InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths, string contractStartType = "currentMonth")
public async Task<ReviewAndPaymentViewModel> GetTotalPaymentAndWorkshopList(double totalPaymentMonth,
InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths)
{
//دریافت کارگاه ها
@@ -538,14 +541,14 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
var roundAmount = (((Convert.ToInt64(totalPayment1MonthDouble))) / 1000000) * 1000000;
double roundAmount2 = roundAmount;
//بدست آوردن جمع کل مبالغ کارگاه بر اساس مدت قراداد
result.SumOfWorkshopsPaymentDouble = months * roundAmount2;
result.SumOfWorkshopsPaymentPaymentStr = result.SumOfWorkshopsPaymentDouble.ToMoney();
var sumOfWorkshopsPaymentDouble = months * roundAmount2;
result.SumOfWorkshopsPayment = sumOfWorkshopsPaymentDouble.ToMoney();
result.Duration = duration;
var tenPercent = result.SumOfWorkshopsPaymentDouble * 10 / 100;
var tenPercent = sumOfWorkshopsPaymentDouble * 10 / 100;
//مالیات
result.ValueAddedTaxDouble = tenPercent;
result.ValueAddedTaxStr = tenPercent.ToMoney();
@@ -553,7 +556,7 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
#region OneTimePaymentResult
double discountOneTimePeyment = result.SumOfWorkshopsPaymentDouble - tenPercent;
double discountOneTimePeyment = sumOfWorkshopsPaymentDouble - tenPercent;
//مبلغ بدون مالیات و با تخفیف
@@ -571,29 +574,21 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
#region MonthlyPaymentResult
//مبلغ بدون مالیات
result.MonthlyWithoutTaxPaymentDouble = result.SumOfWorkshopsPaymentDouble;
result.MonthlyWithoutTaxPaymentStr = result.SumOfWorkshopsPaymentDouble.ToMoney();
result.MonthlyWithoutTaxPaymentDouble = sumOfWorkshopsPaymentDouble;
result.MonthlyWithoutTaxPaymentStr = sumOfWorkshopsPaymentDouble.ToMoney();
// مبلغ با مالیات
result.MonthlyTotalPaymentDouble = result.SumOfWorkshopsPaymentDouble + tenPercent;
result.MonthlyTotalPaymentDouble = sumOfWorkshopsPaymentDouble + tenPercent;
result.MonthlyTotalPaymentStr = result.MonthlyTotalPaymentDouble.ToMoney();
var installmentList = new List<MonthlyInstallment>();
var startDate = (DateTime.Now).ToFarsi();
result.ContractStartCurrentMonthFa = $"{startDate.Substring(0, 8)}01";
result.ContractStartCurrentMonthGr = result.ContractStartCurrentMonthFa.ToGeorgianDateTime();
startDate = result.ContractStartCurrentMonthFa;
var installmentstart = (DateTime.Now).ToFarsi();
result.ContractStartFa = installmentstart;
result.ContractStartGr = result.ContractStartFa.ToGeorgianDateTime();
result.ContractStartNextMonthGr = ((startDate.FindeEndOfMonth()).ToGeorgianDateTime()).AddDays(1);
result.ContractStartNextMonthFa = result.ContractStartNextMonthGr.ToFarsi();
if (contractStartType == "nextMonth")
startDate = result.ContractStartNextMonthFa;
var findeEnd = Tools.FindEndOfContract(startDate, ((int)duration).ToString());
var findeEnd = Tools.FindEndOfContract(installmentstart, ((int)duration).ToString());
var contractEndDate = findeEnd.endDateGr;
result.ContractEndGr = contractEndDate;
result.ContractEndGr = contractEndDate;
result.ContractEndFa = contractEndDate.ToFarsi();
if (duration == InstitutionContractDuration.OneMonth)
@@ -610,20 +605,19 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
{
int instalmentCount = (int)duration;
var instalmentAmount = result.MonthlyTotalPaymentDouble / instalmentCount;
var findEndOfMonth = startDate.FindeEndOfMonth();
var findEndOfMonth = installmentstart.FindeEndOfMonth();
int currentInstallmentStartday = int.Parse(installmentstart.Substring(8, 2));
for (int i = 1; i <= instalmentCount; i++)
{
if (i == 1)
// Adjust the day for months with fewer days
int endDayOfMonth = int.Parse(findEndOfMonth.Substring(8, 2));
if (currentInstallmentStartday > endDayOfMonth)
{
startDate = (DateTime.Now).ToFarsi();
}
else if (i > 1)
{
var currentMonthStart = ((findEndOfMonth.ToGeorgianDateTime()).AddDays(1)).ToFarsi();
startDate = currentMonthStart.FindeEndOfMonth();
findEndOfMonth = startDate;
installmentstart = installmentstart.Substring(0, 8) + endDayOfMonth.ToString("D2");
}
installmentList.Add(new MonthlyInstallment()
{
InstallmentAmountStr = instalmentAmount.ToMoney(),
@@ -643,7 +637,7 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
12 => "سررسید پرداخت دوازدهم",
_ => "سررسید پرداخت دوازدهم",
},
InstalmentDate = startDate
InstalmentDate = installmentstart
});
}
}
@@ -651,7 +645,6 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
#endregion
result.MonthlyInstallments = installmentList;
result.ContractingPartTempId = contractingPartyTempId;
return result;
}
@@ -892,8 +885,6 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
}
public async Task<OperationResult> SendAgreementLink(long contractingPartyTempId)
{
var op = new OperationResult();

View File

@@ -609,7 +609,7 @@ public class institutionContractController : AdminBaseController
public async Task<ActionResult<InstitutionPlanCalculatorResponse>> InstitutionPlanCalculator(
[FromBody] InstitutionPlanCalculatorRequest request)
{
var res = await _temporaryClientRegistration.GetTotalPaymentAndWorkshopList(0, request.TotalAmountMonth,duration: request.Duration, contractStartType: request.ContractStartType);
var res = await _temporaryClientRegistration.GetTotalPaymentAndWorkshopList(request.TotalAmountMonth,duration: request.Duration);
var response = new InstitutionPlanCalculatorResponse
{
Installments = res.MonthlyInstallments,
@@ -618,7 +618,7 @@ public class institutionContractController : AdminBaseController
OneTimeTotalAmount = res.OneTimeTotalPaymentStr,
MonthlyTotalAmount= res.MonthlyTotalPaymentStr,
TotalTax = res.ValueAddedTaxStr,
ContractStart = request.ContractStartType == "currentMonth"?res.ContractStartCurrentMonthFa:res.ContractStartNextMonthFa,
ContractStart = res.ContractStartFa,
ContractEnd = res.ContractEndFa
};
return response;
@@ -684,8 +684,7 @@ public class WorkshopServiceCalculatorResponse
}
public record InstitutionPlanCalculatorRequest(double TotalAmountMonth,
InstitutionContractDuration Duration = InstitutionContractDuration.TwelveMonths,
string ContractStartType = "currentMonth");
InstitutionContractDuration Duration = InstitutionContractDuration.TwelveMonths);
public class CreateInquiryRequest
{