diff --git a/CompanyManagment.App.Contracts/TemporaryClientRegistration/ITemporaryClientRegistrationApplication.cs b/CompanyManagment.App.Contracts/TemporaryClientRegistration/ITemporaryClientRegistrationApplication.cs index 6e9f67be..0379e70d 100644 --- a/CompanyManagment.App.Contracts/TemporaryClientRegistration/ITemporaryClientRegistrationApplication.cs +++ b/CompanyManagment.App.Contracts/TemporaryClientRegistration/ITemporaryClientRegistrationApplication.cs @@ -66,15 +66,13 @@ public interface ITemporaryClientRegistrationApplication /// این متد برای زمانی است که کارگاه ها در مرحله ثبت نام موقت هستند /// و هنوز در دیتابیس ثبت نشده اند /// - /// /// /// - /// + /// /// /// - Task GetTotalPaymentAndWorkshopList(long contractingPartyTempId, - double totalPaymentMonth, - InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths, string contractStartType = "currentMonth"); + Task GetTotalPaymentAndWorkshopList( double totalPaymentMonth, + InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths); /// /// ایجاد یا ویرایش قرارداد موقت diff --git a/CompanyManagment.App.Contracts/TemporaryClientRegistration/ReviewAndPaymentViewModel.cs b/CompanyManagment.App.Contracts/TemporaryClientRegistration/ReviewAndPaymentViewModel.cs index 731e9c56..13cb62f1 100644 --- a/CompanyManagment.App.Contracts/TemporaryClientRegistration/ReviewAndPaymentViewModel.cs +++ b/CompanyManagment.App.Contracts/TemporaryClientRegistration/ReviewAndPaymentViewModel.cs @@ -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 { - /// - /// جمع کل - /// double - /// - public double SumOfWorkshopsPaymentDouble { get; set; } /// - /// جمع کل - /// string + /// تخفیف /// - public string SumOfWorkshopsPaymentPaymentStr { get; set; } - - - + public string Discount { get; set; } + public string SumOfWorkshopsPayment { get; set; } + /// /// مبلغ پرداخت بدون مالیات /// Double @@ -45,9 +39,7 @@ public class ReviewAndPaymentViewModel /// string /// public string OneTimeTotalPaymentStr { get; set; } - - - + /// /// مبلغ پرداخت بدون مالیات /// Double @@ -85,66 +77,29 @@ public class ReviewAndPaymentViewModel /// public string ValueAddedTaxStr { get; set; } - - - + /// /// بازه قرداد /// با عدد مشخص میشود /// مثلا یک ماه عدد 1 /// public InstitutionContractDuration Duration { get; set; } - - /// - /// OneTime پرداخت یکجا - /// - - /// Monthly پرداخت ماهانه - /// - public string PaymentModel { get; set; } - - /// - /// لیست کارگاه های ایجاد شده - /// - public List WorkshopTempViewList { get; set; } - - /// - /// آی دی طرف حساب - /// - public long ContractingPartTempId { get; set; } + /// /// لیست اقساط ماهیانه /// public List MonthlyInstallments { get; set; } + /// + /// شروع قرارداد - شمسی + /// + public string ContractStartFa { get; set; } /// - /// تاریخ شروع قرارداد در اول ماه جاری - /// - - /// شمسی + /// شروع قرارداد - میلادی /// - public string ContractStartCurrentMonthFa { get; set; } - - /// - /// تاریخ شروع قرارداد در اول ماه جاری - /// - - /// میلادی - /// - public DateTime ContractStartCurrentMonthGr { get; set; } - - /// - /// تاریخ شروع قرارداد در اول ماه بعد - /// - - /// شمسی - /// - public string ContractStartNextMonthFa{ get; set; } - - /// - /// تاریخ شروع قرارداد در اول ماه بعد - /// - - /// میلادی - /// - public DateTime ContractStartNextMonthGr { get; set; } + public DateTime ContractStartGr { get; set; } /// /// تاریخ پایان قرارداد diff --git a/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs b/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs index 8f99e5d8..1b6cad2b 100644 --- a/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs +++ b/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs @@ -363,6 +363,7 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati } + /// /// بررسی و پرداخت /// اطلاعات کامل مبالغ @@ -372,149 +373,151 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati public async Task 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(); - - 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(); + // + // 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 GetTotalPaymentAndWorkshopList(long contractingPartyTempId, - double totalPaymentMonth, InstitutionContractDuration duration = InstitutionContractDuration.TwelveMonths, string contractStartType = "currentMonth") + + + public async Task 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(); - 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 SendAgreementLink(long contractingPartyTempId) { var op = new OperationResult(); diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index f08b0967..6fba4117 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(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 {