From 7d6b57affdabd06b3b3501609de5aebace318096 Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 18 Oct 2025 16:50:40 +0330 Subject: [PATCH] feat: make Workshops property public and update CalculateInstallment method visibility --- .../IInstitutionContractApplication.cs | 2 +- .../InstitutionContractApplication.cs | 2 +- .../InstitutionContractRepository.cs | 116 +++++++++++++++--- 3 files changed, 99 insertions(+), 21 deletions(-) diff --git a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs index 9a290f56..fd2d8cfe 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs @@ -240,7 +240,7 @@ public interface IInstitutionContractApplication public class InsitutionContractAmendmentPaymentRequest { - List Workshops { get; set; } + public List Workshops { get; set; } public long InstitutionContractId { get; set; } } diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index c67d29f1..45289281 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -1407,7 +1407,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication return operation.Succcedded(personalContractingParty); } - private List CalculateInstallment(double amount, int installmentCount, + public static List CalculateInstallment(double amount, int installmentCount, string loanStartDate, bool getRounded) { int day = Convert.ToInt32(loanStartDate.Substring(8, 2)); diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index ae238e9b..ea5fe182 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; using System.Drawing; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using _0_Framework.Application; @@ -2235,7 +2236,7 @@ public class InstitutionContractRepository : RepositoryBase x.ContractingPartyId == contractingParty.id)) { @@ -2343,9 +2343,10 @@ public class InstitutionContractRepository : RepositoryBase x.CurrentWorkshops) .FirstOrDefaultAsync(x => x.id == institutionContractId); - if (institutionContract.WorkshopGroup.CurrentWorkshops.Any(x=>x.Price == 0)) + if (institutionContract.WorkshopGroup.CurrentWorkshops.Any(x => x.Price == 0)) { - throw new BadRequestException("این قرارداد قابل ارتقا به صورت ظاهری نیست لطفا به صورت دیتابیسی اقدام به ویرایش کنید"); + throw new BadRequestException( + "این قرارداد قابل ارتقا به صورت ظاهری نیست لطفا به صورت دیتابیسی اقدام به ویرایش کنید"); } var workshops = institutionContract.WorkshopGroup.CurrentWorkshops.Select(x => new WorkshopTempViewModel() @@ -2363,7 +2364,6 @@ public class InstitutionContractRepository : RepositoryBase GetAmendmentPaymentDetails(InsitutionContractAmendmentPaymentRequest request) + public async Task GetAmendmentPaymentDetails( + InsitutionContractAmendmentPaymentRequest request) { - var institutionContract =await _context.InstitutionContractSet + var institutionContract = await _context.InstitutionContractSet .Include(x => x.WorkshopGroup) .ThenInclude(x => x.CurrentWorkshops) .FirstOrDefaultAsync(x => x.id == request.InstitutionContractId); @@ -2383,10 +2384,86 @@ public class InstitutionContractRepository : RepositoryBase x.ContractAndCheckoutInPerson); + if (!haContractInPerson) + { + if (request.Workshops.Any(x => x.ContractAndCheckoutInPerson)) + { + throw new BadRequestException("برای قرارداد آنلاین نمیتوان سرویس حضوری انتخاب کرد"); + } + } + + var pc = new PersianCalendar(); + + int startYear = pc.GetYear(amendmentStart); + int startMonth = pc.GetMonth(amendmentStart); + int startDay = pc.GetDayOfMonth(amendmentStart); + + int endYear = pc.GetYear(amendmentEnd); + int endMonth = pc.GetMonth(amendmentEnd); + int endDay = pc.GetDayOfMonth(amendmentEnd); + + // اختلاف خام ماه‌ها + int monthDiff = (endYear - startYear) * 12 + (endMonth - startMonth); + + // اگر حتی چند روز از ماه بعدی هم گذشته بود → رند به بالا + if (endDay > startDay) + monthDiff++; + + var sumOneMonth = request.Workshops.Sum(x => x.WorkshopServicesAmount); + //TODO:مقدار جمع مبالغ باید از دیتابیس موقت گرفته شود. + + var baseAmount = monthDiff * sumOneMonth; + var tax = baseAmount*0.10; + var totalPayment = tax+baseAmount; + + + var res = new InsitutionContractAmendmentPaymentResponse() + { + ContractStart = amendmentStart.ToFarsi(), + ContractEnd = amendmentEnd.ToFarsi(), + OneMonthAmount = sumOneMonth.ToMoney(), + TotalAmount = baseAmount.ToMoney(), + }; + + res.OneTime = new InstitutionContractPaymentOneTimeViewModel() + { + TotalAmount = baseAmount.ToMoney(), + PaymentAmount = totalPayment.ToMoney(), + Tax = tax.ToMoney() + }; + + if (haContractInPerson) + { + var installment = InstitutionMonthlyInstallmentCaculation(monthDiff,totalPayment, amendmentStart.ToFarsi()); + var firstInstallment = new MonthlyInstallment() + { + InstallmentAmountStr = installment.First().InstallmentAmountStr, + InstallmentCounter = installment.First().InstallmentCounter, + InstalmentDate = amendmentStart.ToFarsi() + }; + var lastInstallment = new MonthlyInstallment() + { + InstallmentAmountStr = installment.Last().InstallmentAmountStr, + InstallmentCounter = installment.Last().InstallmentCounter, + InstalmentDate = installment.Last().InstalmentDate + }; + installment.Remove(installment.First()); + installment.Remove(installment.Last()); + installment.Insert(0, firstInstallment); + installment.Add(lastInstallment); + res.Monthly = new InstitutionContractPaymentMonthlyViewModel() + { + Installments = installment, + TotalAmount = baseAmount.ToMoney(), + PaymentAmount = totalPayment.ToMoney(), + Tax = tax.ToMoney() + + }; + + } + return res; } private InstitutionContractExtensionPaymentResponse CalculateInPersonPayment( @@ -2411,7 +2488,7 @@ public class InstitutionContractRepository : RepositoryBase InstitutionMonthlyInstallmentCaculation(InstitutionContractDuration duration, + public static List InstitutionMonthlyInstallmentCaculation(int duration, double monthlyTotalPaymentDouble, string installmentstart) { @@ -2501,7 +2578,7 @@ public class InstitutionContractRepository : RepositoryBase(); - int instalmentCount = (int)duration; + int instalmentCount = duration; var instalmentAmount = monthlyTotalPaymentDouble / instalmentCount; int currentInstallmentStartDay = int.Parse(installmentstart.Substring(8, 2)); bool endOfMonth = currentInstallmentStartDay == 31; @@ -2561,6 +2638,7 @@ public class InstitutionContractRepository : RepositoryBase