diff --git a/CompanyManagment.App.Contracts/TemporaryClientRegistration/ITemporaryClientRegistrationApplication.cs b/CompanyManagment.App.Contracts/TemporaryClientRegistration/ITemporaryClientRegistrationApplication.cs index 0379e70d..f2cc87c8 100644 --- a/CompanyManagment.App.Contracts/TemporaryClientRegistration/ITemporaryClientRegistrationApplication.cs +++ b/CompanyManagment.App.Contracts/TemporaryClientRegistration/ITemporaryClientRegistrationApplication.cs @@ -68,11 +68,12 @@ public interface ITemporaryClientRegistrationApplication /// /// /// + /// /// /// /// - Task GetTotalPaymentAndWorkshopList( double totalPaymentMonth, - InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths); + Task GetTotalPaymentAndWorkshopList(double totalPaymentMonth, + InstitutionContractDuration duration , bool hasInPersonContract); /// /// ایجاد یا ویرایش قرارداد موقت diff --git a/CompanyManagment.App.Contracts/TemporaryClientRegistration/ReviewAndPaymentViewModel.cs b/CompanyManagment.App.Contracts/TemporaryClientRegistration/ReviewAndPaymentViewModel.cs index 4803d7a7..a9e11980 100644 --- a/CompanyManagment.App.Contracts/TemporaryClientRegistration/ReviewAndPaymentViewModel.cs +++ b/CompanyManagment.App.Contracts/TemporaryClientRegistration/ReviewAndPaymentViewModel.cs @@ -13,13 +13,10 @@ public class ReviewAndPaymentViewModel /// public string Discount { get; set; } - public string SumOfWorkshopsPayment { get; set; } - /// - /// مبلغ پرداخت بدون مالیات - /// Double + /// مقدار جمع مبلغ کارگاه ها /// - public double OneTimeWithoutTaxPaymentDouble { get; set; } + public string SumOfWorkshopsPayment { get; set; } /// /// مبلغ پرداخت بدون مالیات @@ -27,65 +24,30 @@ public class ReviewAndPaymentViewModel /// public string OneTimeWithoutTaxPaymentStr { get; set; } - - /// - /// مبلغ پرداخت کامل - /// Double - /// - public double OneTimeTotalPaymentDouble { get; set; } - /// /// مبلغ پرداخت کامل /// string /// public string OneTimeTotalPaymentStr { get; set; } - - /// - /// مبلغ پرداخت بدون مالیات - /// Double - /// - public double MonthlyWithoutTaxPaymentDouble { get; set; } /// - /// مبلغ پرداخت بدون مالیات + /// مبلغ پرداخت بدون مالیات ماهانه /// string /// public string MonthlyWithoutTaxPaymentStr { get; set; } - /// - /// مبلغ پرداخت کامل - /// Double - /// - public double MonthlyTotalPaymentDouble { get; set; } - - /// - /// مبلغ پرداخت کامل - /// string + /// مبلغ پرداخت کامل ماهانه + /// string /// public string MonthlyTotalPaymentStr { get; set; } - - /// - /// مالیات بر ارزش افزوده - /// Double - /// - public double ValueAddedTaxDouble { get; set; } - + /// /// مالیات بر ارزش افزوده /// string /// public string ValueAddedTaxStr { get; set; } - - /// - /// بازه قرداد - /// با عدد مشخص میشود - /// مثلا یک ماه عدد 1 - /// - public InstitutionContractDuration Duration { get; set; } - - /// /// لیست اقساط ماهیانه /// diff --git a/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs b/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs index 9fb6adf5..3bce3cde 100644 --- a/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs +++ b/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs @@ -363,7 +363,6 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati } - /// /// بررسی و پرداخت /// اطلاعات کامل مبالغ @@ -371,7 +370,8 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati /// /// public async Task GetTotalPaymentAndWorkshopList(long contractingPartyTempId, - InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths, string paymentModel = "OneTime", string contractStartType = "currentMonth") + InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths, + string paymentModel = "OneTime", string contractStartType = "currentMonth") { throw new NotImplementedException(); // //دریافت کارگاه ها @@ -514,10 +514,10 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati // // return result; } - - + + public async Task GetTotalPaymentAndWorkshopList(double totalPaymentMonth, - InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths) + InstitutionContractDuration duration, bool hasInPersonContract) { //دریافت کارگاه ها @@ -543,81 +543,85 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati //بدست آوردن جمع کل مبالغ کارگاه بر اساس مدت قراداد var sumOfWorkshopsPaymentDouble = months * roundAmount2; result.SumOfWorkshopsPayment = sumOfWorkshopsPaymentDouble.ToMoney(); - - - result.Duration = duration; - - - var tenPercent = sumOfWorkshopsPaymentDouble * 10 / 100; - //مالیات - result.ValueAddedTaxDouble = tenPercent; - result.ValueAddedTaxStr = tenPercent.ToMoney(); - //پرداخت یکجا - - #region OneTimePaymentResult - - double discountOneTimePeyment = sumOfWorkshopsPaymentDouble - tenPercent; - - - //مبلغ بدون مالیات و با تخفیف - result.OneTimeWithoutTaxPaymentDouble = discountOneTimePeyment; - result.OneTimeWithoutTaxPaymentStr = discountOneTimePeyment.ToMoney(); - - //مبلغ با مالیات - result.OneTimeTotalPaymentDouble = discountOneTimePeyment + tenPercent; - result.OneTimeTotalPaymentStr = result.OneTimeTotalPaymentDouble.ToMoney(); - - #endregion - - //پرداخت ماهیانه - - #region MonthlyPaymentResult - - //مبلغ بدون مالیات - result.MonthlyWithoutTaxPaymentDouble = sumOfWorkshopsPaymentDouble; - result.MonthlyWithoutTaxPaymentStr = sumOfWorkshopsPaymentDouble.ToMoney(); - - // مبلغ با مالیات - result.MonthlyTotalPaymentDouble = sumOfWorkshopsPaymentDouble + tenPercent; - result.MonthlyTotalPaymentStr = result.MonthlyTotalPaymentDouble.ToMoney(); - var installmentList = new List(); - - var installmentstart = (DateTime.Now).ToFarsi(); - installmentstart = "1404/02/30"; - result.ContractStartFa = installmentstart; - result.ContractStartGr = result.ContractStartFa.ToGeorgianDateTime(); - - var findeEnd = Tools.FindEndOfContract(installmentstart, ((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 + + if (hasInPersonContract) { + var tenPercent = sumOfWorkshopsPaymentDouble * 10 / 100; + //مالیات + result.ValueAddedTaxStr = tenPercent.ToMoney(); + //پرداخت یکجا + + #region OneTimePaymentResult + + double discountOneTimePeyment = sumOfWorkshopsPaymentDouble - tenPercent; + + result.Discount = tenPercent.ToMoney(); + + //مبلغ بدون مالیات و با تخفیف + result.OneTimeWithoutTaxPaymentStr = discountOneTimePeyment.ToMoney(); + + //مبلغ با مالیات + var oneTimePayment = discountOneTimePeyment + tenPercent; + result.OneTimeTotalPaymentStr = oneTimePayment.ToMoney(); + + #endregion + + + //پرداخت ماهیانه + + #region MonthlyPaymentResult + + //مبلغ بدون مالیات + + result.MonthlyWithoutTaxPaymentStr = sumOfWorkshopsPaymentDouble.ToMoney(); + + // مبلغ با مالیات + var monthlyTotalPaymentDouble = sumOfWorkshopsPaymentDouble + tenPercent; + result.MonthlyTotalPaymentStr = monthlyTotalPaymentDouble.ToMoney(); + var installmentList = new List(); + + var installmentstart = (DateTime.Now).ToFarsi(); + installmentstart = "1404/06/30"; + + result.ContractStartFa = installmentstart; + result.ContractStartGr = result.ContractStartFa.ToGeorgianDateTime(); + + var findeEnd = Tools.FindEndOfContract(installmentstart, ((int)duration).ToString()); + var contractEndDate = findeEnd.endDateGr; + result.ContractEndGr = contractEndDate; + result.ContractEndFa = contractEndDate.ToFarsi(); + int instalmentCount = (int)duration; - var instalmentAmount = result.MonthlyTotalPaymentDouble / instalmentCount; - var findEndOfMonth = installmentstart.FindeEndOfMonth(); - int currentInstallmentStartday = int.Parse(installmentstart.Substring(8, 2)); + var instalmentAmount = monthlyTotalPaymentDouble / instalmentCount; + int currentInstallmentStartDay = int.Parse(installmentstart.Substring(8, 2)); + bool endOfMonth = currentInstallmentStartDay == 31; + // Loop through each installment period for (int i = 1; i <= instalmentCount; i++) { - // Adjust the day for months with fewer days - int endDayOfMonth = int.Parse(findEndOfMonth.Substring(8, 2)); - if (currentInstallmentStartday > endDayOfMonth) + string installmentDate; + // For first installment, use the initial date + if (i == 1) { - installmentstart = installmentstart.Substring(0, 8) + endDayOfMonth.ToString("D2"); + installmentDate = installmentstart; + } + else + { + var currentDay = int.Parse(installmentstart.Substring(8, 2)); + var currentMonth = int.Parse(installmentstart.Substring(5, 2)); + var currentYear = int.Parse(installmentstart.Substring(0, 4)); + + // Get next month's date + var nextMonthFa = installmentstart.ToGeorgianDateTime().AddMonthsFa(1, out var nextMonth); + var maxDayInNextMonth = int.Parse(nextMonthFa.FindeEndOfMonth().Substring(8, 2)); + + // Use original day if possible, otherwise use last day of month + var dayToUse = Math.Min(int.Parse(installmentstart.Substring(8, 2)), maxDayInNextMonth); + installmentDate = nextMonthFa.Substring(0, 8) + dayToUse.ToString("D2"); + + // Update installmentstart for next iteration + installmentstart = installmentDate; } - installmentList.Add(new MonthlyInstallment() { @@ -638,16 +642,33 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati 12 => "سررسید پرداخت دوازدهم", _ => "سررسید پرداخت دوازدهم", }, - InstalmentDate = installmentstart + InstalmentDate = installmentDate }); - installmentstart = installmentstart.ToGeorgianDateTime().AddMonthsFa(1,out _).Substring(0,8) + installmentstart.Substring(8,2); - findEndOfMonth = installmentstart.FindeEndOfMonth(); } + #endregion + + result.MonthlyInstallments = installmentList; + } + else + { + var discount = duration switch + { + InstitutionContractDuration.OneMonth => 0, + InstitutionContractDuration.ThreeMonths => 5, + InstitutionContractDuration.SixMonths => 10, + InstitutionContractDuration.TwelveMonths => 15, + _ => throw new ArgumentOutOfRangeException(nameof(duration), duration, null) + }; + + var discountAmount = (sumOfWorkshopsPaymentDouble * discount) / 100; + var discountedPayment = sumOfWorkshopsPaymentDouble - discountAmount; + result.Discount = discountAmount.ToMoney(); + var taxDouble = (discountedPayment * 10)/100; + result.ValueAddedTaxStr =taxDouble.ToMoney(); + result.OneTimeWithoutTaxPaymentStr = discountedPayment.ToMoney(); + result.OneTimeTotalPaymentStr =( discountedPayment + taxDouble).ToMoney(); } - #endregion - - result.MonthlyInstallments = installmentList; return result; } diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index 0027b43a..541f0e65 100644 --- a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs +++ b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs @@ -609,7 +609,7 @@ public class institutionContractController : AdminBaseController public async Task> InstitutionPlanCalculator( [FromBody] InstitutionPlanCalculatorRequest request) { - var res = await _temporaryClientRegistration.GetTotalPaymentAndWorkshopList(request.TotalAmountMonth,duration: request.Duration); + var res = await _temporaryClientRegistration.GetTotalPaymentAndWorkshopList(request.TotalAmountMonth,duration: request.Duration,request.HasInPersonContract); var response = new InstitutionPlanCalculatorResponse { Installments = res.MonthlyInstallments, @@ -621,7 +621,8 @@ public class institutionContractController : AdminBaseController ContractStart = res.ContractStartFa, ContractEnd = res.ContractEndFa, Discount = res.Discount??"0", - + ValueAddedTax = res.ValueAddedTaxStr, + TotalAmountWithTax = res.OneTimeTotalPaymentStr }; return response; } @@ -679,6 +680,7 @@ public class InstitutionPlanCalculatorResponse public string ContractStart { get; set; } public string ContractEnd { get; set; } public string Discount { get; set; } + public string ValueAddedTax { get; set; } } public class WorkshopServiceCalculatorResponse @@ -686,7 +688,7 @@ public class WorkshopServiceCalculatorResponse public string TotalAmount { get; set; } } -public record InstitutionPlanCalculatorRequest(double TotalAmountMonth, +public record InstitutionPlanCalculatorRequest(double TotalAmountMonth,bool HasInPersonContract, InstitutionContractDuration Duration = InstitutionContractDuration.TwelveMonths); public class CreateInquiryRequest