From 2feca1f7f8786b5a57fedeae5d02c5383d8351ff Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 29 Dec 2025 19:31:18 +0330 Subject: [PATCH 1/3] add creation --- .../institutionContractController.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index c2a21119..f77e0964 100644 --- a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs +++ b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs @@ -528,6 +528,57 @@ public class institutionContractController : AdminBaseController } } + #region Create + [HttpGet("creation/inquiry/{previousContractId}")] + public async Task> ExtensionInquiry(long previousContractId) + { + var res= await _institutionContractApplication.GetExtensionInquiry(previousContractId); + return res; + } + + [HttpPost("create/workshops")] + public async Task> CreationWorkshops([FromBody] InstitutionContractCreationWorkshopsRequest request) + { + var res =await _institutionContractApplication.GetCreationWorkshops(request); + return res; + } + + [HttpPost("extenstion/institution-plan")] + public async Task> ExtensionInstitutionPlan([FromBody]InstitutionContractExtensionPlanRequest request) + { + var res =await _institutionContractApplication.GetExtensionInstitutionPlan(request); + return res; + } + + [HttpPost("extenstion/payment-method")] + public async Task> GetExtensionPaymentMethod([FromBody]InstitutionContractExtensionPaymentRequest request) + { + var res =await _institutionContractApplication.GetExtensionPaymentMethod(request); + return res; + } + + [HttpPost("extension/set-discount")] + public async Task> SetDiscountForExtension([FromBody]InstitutionContractSetDiscountForExtensionRequest request) + { + var res =await _institutionContractApplication.SetDiscountForExtension(request); + return res; + } + + [HttpPost("extension/reset-discount")] + public async Task> ResetDiscountForExtension([FromBody]InstitutionContractResetDiscountForExtensionRequest request) + { + var res =await _institutionContractApplication.ResetDiscountForExtension(request); + return res; + } + + [HttpPost("extenstion/complete")] + public async Task> ExtensionComplete([FromBody]InstitutionContractExtensionCompleteRequest request) + { + var res =await _institutionContractApplication.ExtensionComplete(request); + return res; + } + + #endregion [HttpGet("extenstion/inquiry/{previousContractId}")] public async Task> ExtensionInquiry(long previousContractId) From 8fca1f3a917c239eaac35e693a41ee4ce8db8e4e Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 29 Dec 2025 22:19:16 +0330 Subject: [PATCH 2/3] feat: add institution contract creation inquiry functionality --- .../IInstitutionContractRepository.cs | 5 + .../InstitutionContractCreationTemp.cs | 320 ++++++++ .../IInstitutionContractApplication.cs | 8 + ...stitutionContractCreationInquiryRequest.cs | 11 + ...stitutionContractExtensionInquiryResult.cs | 17 + ...nstitutionContractExtensionPlanResponse.cs | 19 + .../InstitutionContractApplication.cs | 7 + .../InstitutionContractRepository.cs | 681 +++++++++++++----- .../institutionContractController.cs | 14 +- 9 files changed, 875 insertions(+), 207 deletions(-) create mode 100644 Company.Domain/InstitutionContractCreationTempAgg/InstitutionContractCreationTemp.cs create mode 100644 CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractCreationInquiryRequest.cs diff --git a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs index 54f0e897..993e8309 100644 --- a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs +++ b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs @@ -58,7 +58,11 @@ public interface IInstitutionContractRepository : IRepository GetByPublicIdAsync(Guid id); InstitutionContractDiscountResponse CalculateDiscount(InstitutionContractSetDiscountRequest request,string contractStart = null); InstitutionContractDiscountResponse ResetDiscountCreate(InstitutionContractResetDiscountForCreateRequest request); + + #region Creation + + #endregion #region Extension @@ -160,4 +164,5 @@ public interface IInstitutionContractRepository : IRepository GetIdByInstallmentId(long installmentId); Task GetPreviousContract(long currentInstitutionContractId); + Task CreationInquiry(InstitutionContractCreationInquiryRequest request); } \ No newline at end of file diff --git a/Company.Domain/InstitutionContractCreationTempAgg/InstitutionContractCreationTemp.cs b/Company.Domain/InstitutionContractCreationTempAgg/InstitutionContractCreationTemp.cs new file mode 100644 index 00000000..9a34955e --- /dev/null +++ b/Company.Domain/InstitutionContractCreationTempAgg/InstitutionContractCreationTemp.cs @@ -0,0 +1,320 @@ +using System; +using System.Collections.Generic; +using _0_Framework.Application; +using _0_Framework.Application.Enums; +using CompanyManagment.App.Contracts.InstitutionContract; +using CompanyManagment.App.Contracts.InstitutionContractContactinfo; +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; + +namespace Company.Domain.InstitutionContractCreationTempAgg; + +public class InstitutionContractCreationTemp +{ + public InstitutionContractCreationTemp() + { + Id = Guid.NewGuid(); + } + + [BsonId] // Specifies this field as the _id in MongoDB + [BsonRepresentation(BsonType.String)] // Ensures the GUID is stored as a string + public Guid Id { get; set; } + + /// + /// نوع حقوقی طرف قرارداد (حقیقی یا حقوقی) + /// + public LegalType ContractingPartyLegalType { get; set; } + + /// + /// اطلاعات شخص حقیقی + /// + public InstitutionContractCreationTempRealParty RealParty { get; set; } + + /// + /// اطلاعات شخص حقوقی + /// + public InstitutionContractCreationTempLegalParty LegalParty { get; set; } + + public string Address { get; set; } + public string City { get; set; } + public string Province { get; set; } + public List ContactInfos { get; set; } + + public List Workshops { get; set; } + + public InstitutionContractCreationPlanDetail OneMonth { get; set; } + public InstitutionContractCreationPlanDetail ThreeMonths { get; set; } + public InstitutionContractCreationPlanDetail SixMonths { get; set; } + public InstitutionContractCreationPlanDetail TwelveMonths { get; set; } + public InstitutionContractPaymentMonthlyViewModel MonthlyPayment { get; set; } + public InstitutionContractPaymentOneTimeViewModel OneTimePayment { get; set; } + + public bool HasContractInPerson { get; set; } + + public InstitutionContractDuration? Duration { get; set; } + + public void SetContractingPartyInfo(LegalType legalType, + InstitutionContractCreationTempRealParty realParty, + InstitutionContractCreationTempLegalParty legalParty) + { + ContractingPartyLegalType = legalType; + RealParty = realParty; + LegalParty = legalParty; + } + + public void SetWorkshopsAndPlanAmounts(List workshops, + InstitutionContractCreationPlanDetail oneMonth, + InstitutionContractCreationPlanDetail threeMonth, InstitutionContractCreationPlanDetail sixMonth, + InstitutionContractCreationPlanDetail twelveMonth, bool hasContractInPerson) + { + Workshops = workshops; + OneMonth = oneMonth; + ThreeMonths = threeMonth; + SixMonths = sixMonth; + TwelveMonths = twelveMonth; + HasContractInPerson = hasContractInPerson; + } + + public void SetAmountAndDuration(InstitutionContractDuration duration,InstitutionContractPaymentMonthlyViewModel monthly, + InstitutionContractPaymentOneTimeViewModel oneTime) + { + Duration = duration; + MonthlyPayment = monthly; + OneTimePayment = oneTime; + } + + +} + +public class InstitutionContractCreationTempLegalParty +{ + /// + /// نام شرکت + /// + public string CompanyName { get; set; } + + /// + /// شماره ثبت + /// + public string RegisterId { get; set; } + + /// + /// شناسه ملی شرکت + /// + public string NationalId { get; set; } + + /// + /// شماره تلفن شرکت + /// + public string PhoneNumber { get; set; } + + /// + /// شناسه موقت طرف قرارداد + /// + public long ContractingPartyTempId { get; set; } + + /// + /// کد ملی نماینده قانونی + /// + public string NationalCode { get; set; } + + /// + /// تاریخ تولد نماینده قانونی فارسی + /// + public string BirthDateFa { get; set; } + + /// + /// نام نماینده قانونی + /// + public string FName { get; set; } + + /// + /// نام خانوادگی نماینده قانونی + /// + public string LName { get; set; } + + /// + /// نام پدر نماینده قانونی + /// + public string FatherName { get; set; } + + /// + /// شماره شناسنامه نماینده قانونی + /// + public string IdNumber { get; set; } + + /// + /// وضعیت احراز هویت نماینده قانونی + /// + public bool IsAuth { get; set; } + + /// + /// سمت نماینده قانونی در شرکت + /// + public string Position { get; set; } + + /// + /// جنسیت نماینده قانونی + /// + public Gender Gender { get; set; } + + public string IdNumberSeri { get; set; } + + public string IdNumberSerial { get; set; } +} + +public class InstitutionContractCreationTempRealParty +{ + /// + /// کد ملی + /// + public string NationalCode { get; set; } + + /// + /// تاریخ تولد فارسی + /// + public string BirthDateFa { get; set; } + + /// + /// شماره تلفن + /// + public string PhoneNumber { get; set; } + + /// + /// وضعیت احراز هویت + /// + public bool IsAuth { get; set; } + + /// + /// نام + /// + public string FName { get; set; } + + /// + /// نام خانوادگی + /// + public string LName { get; set; } + + /// + /// نام پدر + /// + public string FatherName { get; set; } + + /// + /// شماره شناسنامه + /// + public string IdNumber { get; set; } + + /// + /// شناسه موقت طرف قرارداد + /// + public long ContractingPartyTempId { get; set; } + + /// + /// جنسیت + /// + public Gender Gender { get; set; } + + public string IdNumberSeri { get; set; } + + public string IdNumberSerial { get; set; } +} + +public class InstitutionContractCreationTempPlan +{ + public InstitutionContractCreationTempPlan(string contractStart, string contractEnd, + string oneMonthPaymentDiscounted, string oneMonthDiscount, string oneMonthOriginalPayment, + string totalPayment, string dailyCompensation, string obligation) + { + ContractStart = contractStart; + ContractEnd = contractEnd; + OneMonthPaymentDiscounted = oneMonthPaymentDiscounted; + OneMonthDiscount = oneMonthDiscount; + OneMonthOriginalPayment = oneMonthOriginalPayment; + TotalPayment = totalPayment; + DailyCompensation = dailyCompensation; + Obligation = obligation; + } + + public string ContractStart { get; set; } + public string ContractEnd { get; set; } + public string OneMonthPaymentDiscounted { get; set; } + public string OneMonthDiscount { get; set; } + public string OneMonthOriginalPayment { get; set; } + public string TotalPayment { get; set; } + public string DailyCompensation { get; set; } + public string Obligation { get; set; } +} + +public class InstitutionContractCreationTempWorkshop +{ + public InstitutionContractCreationTempWorkshop(string workshopName, int countPerson, bool contractAndCheckout, bool contractAndCheckoutInPerson, + bool insurance, bool insuranceInPerson, + bool rollCall,bool rollCallInPerson, bool customizeCheckout,double price,long workshopId) + { + WorkshopName = workshopName; + CountPerson = countPerson; + ContractAndCheckout = contractAndCheckout; + Insurance = insurance; + RollCall = rollCall; + CustomizeCheckout = customizeCheckout; + ContractAndCheckoutInPerson = contractAndCheckoutInPerson; + InsuranceInPerson = insuranceInPerson; + RollCallInPerson = rollCallInPerson; + Price = price; + WorkshopId = workshopId; + } + + public long WorkshopId { get; set; } + + /// + /// نام کارگاه + /// + public string WorkshopName { get; private set; } + + /// + /// تعداد پرسنل + /// + public int CountPerson { get; private set; } + + + #region ServiceSelection + + /// + /// قرارداد و تصفیه + /// + public bool ContractAndCheckout { get; private set; } + + /// + /// بیمه + /// + public bool Insurance { get; private set; } + + /// + /// حضورغباب + /// + public bool RollCall { get; private set; } + + public bool RollCallInPerson { get; set; } + + /// + /// فیش غیر رسمی + /// + public bool CustomizeCheckout { get;private set; } + + /// + /// خدمات حضوری قرداد و تصفیه + /// + public bool ContractAndCheckoutInPerson { get; private set; } + + /// + /// خدمات حضوری بیمه + /// + public bool InsuranceInPerson { get; private set; } + + public double Price{ get; set; } + + #endregion +} + + diff --git a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs index 424d71b0..d53b5d5c 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs @@ -216,6 +216,14 @@ public interface IInstitutionContractApplication Task GetWorkshopInitialDetails(long workshopDetailsId); InstitutionContractDiscountResponse CalculateDiscount(InstitutionContractSetDiscountRequest request); InstitutionContractDiscountResponse ResetDiscountCreate(InstitutionContractResetDiscountForCreateRequest request); + + #region Creation + + + Task CreationInquiry(InstitutionContractCreationInquiryRequest request); + + + #endregion #region Extension diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractCreationInquiryRequest.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractCreationInquiryRequest.cs new file mode 100644 index 00000000..07948863 --- /dev/null +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractCreationInquiryRequest.cs @@ -0,0 +1,11 @@ +using _0_Framework.Application.Enums; + +namespace CompanyManagment.App.Contracts.InstitutionContract; + +public class InstitutionContractCreationInquiryRequest +{ + public string NationalCode { get; set; } + public string DateOfBirth { get; set; } + public string Mobile { get; set; } + public LegalType LegalType { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionInquiryResult.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionInquiryResult.cs index b11bcbf8..39cc238e 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionInquiryResult.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionInquiryResult.cs @@ -24,4 +24,21 @@ public class InstitutionContractExtensionInquiryResult public string Province { get; set; } public List ContactInfoViewModels { get; set; } public long RepresentativeId { get; set; } +} + +public class InstitutionContractCreationInquiryResult +{ + /// + /// اطلاعات شخص حقیقی + /// + public CreateInstitutionContractRealPartyRequest RealParty { get; set; } + + /// + /// اطلاعات شخص حقوقی + /// + public CreateInstitutionContractLegalPartyRequest LegalParty { get; set; } + + public LegalType LegalType { get; set; } + + public Guid TempId { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanResponse.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanResponse.cs index dcdff4ca..a38e001b 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanResponse.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanResponse.cs @@ -8,6 +8,25 @@ public class InstitutionContractExtensionPlanResponse public InstitutionContractExtensionPlanDetail TwelveMonths { get; set; } } public class InstitutionContractExtensionPlanDetail +{ + public string ContractStart { get; set; } + public string ContractEnd { get; set; } + public string OneMonthPaymentDiscounted { get; set; } + public string OneMonthDiscount { get; set; } + public string OneMonthOriginalPayment { get; set; } + public string TotalPayment { get; set; } + public string DailyCompenseation { get; set; } + public string Obligation { get; set; } +} + +public class InstitutionContractCreationPlanResponse +{ + public InstitutionContractCreationPlanDetail OneMonth { get; set; } + public InstitutionContractCreationPlanDetail ThreeMonths { get; set; } + public InstitutionContractCreationPlanDetail SixMonths { get; set; } + public InstitutionContractCreationPlanDetail TwelveMonths { get; set; } +} +public class InstitutionContractCreationPlanDetail { public string ContractStart { get; set; } public string ContractEnd { get; set; } diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index 82373502..580bdf1d 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -1444,6 +1444,13 @@ public class InstitutionContractApplication : IInstitutionContractApplication return _institutionContractRepository.ResetDiscountCreate(request); } + public Task CreationInquiry(InstitutionContractCreationInquiryRequest request) + { + return _institutionContractRepository.CreationInquiry(request); + } + + + public async Task GetExtensionInquiry(long previousContractId) { return await _institutionContractRepository.GetExtensionInquiry(previousContractId); diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index f15189ca..c4b16059 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -35,6 +35,9 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using _0_Framework.Application.UID; +using Company.Domain.InstitutionContractCreationTempAgg; +using Company.Domain.TemporaryClientRegistrationAgg; using ContractingPartyAccount = Company.Domain.ContractingPartyAccountAgg.ContractingPartyAccount; using FinancialStatment = Company.Domain.FinancialStatmentAgg.FinancialStatment; using String = System.String; @@ -49,6 +52,7 @@ public class InstitutionContractRepository : RepositoryBase _institutionExtensionTemp; private readonly IMongoCollection _institutionAmendmentTemp; + private readonly IMongoCollection _institutionContractCreationTemp; private readonly IPlanPercentageRepository _planPercentageRepository; private readonly ISmsService _smsService; private readonly ISmsResultRepository _smsResultRepository; @@ -56,6 +60,8 @@ public class InstitutionContractRepository : RepositoryBase _hubContext; private readonly ILogger _logger; + private readonly IUidService _uidService; + private readonly InstitutionContratVerificationParty _firstParty = new() { @@ -67,11 +73,15 @@ public class InstitutionContractRepository : RepositoryBase hubContext, ILogger logger) : base(context) + IFinancialStatmentRepository financialStatmentRepository, IHubContext hubContext, + ILogger logger, IUidService uidService, IContractingPartyTempRepository contractingPartyTempRepository) : base(context) { _context = context; _employerRepository = employerRepository; @@ -83,78 +93,82 @@ public class InstitutionContractRepository : RepositoryBase("InstitutionContractExtensionTemp"); _institutionAmendmentTemp = database.GetCollection("InstitutionContractAmendmentTemp"); + _institutionContractCreationTemp = + database.GetCollection("InstitutionContractCreationTemp"); } public EditInstitutionContract GetDetails(long id) { return _context.InstitutionContractSet.Select(x => new EditInstitutionContract() - { - Id = x.id, - ContractNo = x.ContractNo, - ContractStartGr = x.ContractStartGr, - ContractStartFa = x.ContractStartFa, - ContractEndGr = x.ContractEndGr, - ContractEndFa = x.ContractEndFa, - RepresentativeName = x.RepresentativeName, - ContractingPartyName = x.ContractingPartyName, - RepresentativeId = x.RepresentativeId, - ContractingPartyId = x.ContractingPartyId, - ContractDateFa = x.ContractDateFa, - State = x.State, - City = x.City, - Address = x.Address, - Description = x.Description, - WorkshopManualCount = x.WorkshopManualCount, - EmployeeManualCount = x.EmployeeManualCount, - ContractAmountString = x.ContractAmount.ToMoney(), - ContractAmount = x.ContractAmount, - DailyCompenseationString = x.DailyCompenseation.ToMoney(), - ObligationString = x.Obligation.ToMoney(), - TotalAmountString = x.TotalAmount.ToMoney(), - ExtensionNo = x.ExtensionNo, - OfficialCompany = x.OfficialCompany, - TypeOfContract = x.TypeOfContract, - Signature = x.Signature, - HasValueAddedTax = x.HasValueAddedTax, - ValueAddedTax = x.ValueAddedTax, - }) + { + Id = x.id, + ContractNo = x.ContractNo, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + RepresentativeName = x.RepresentativeName, + ContractingPartyName = x.ContractingPartyName, + RepresentativeId = x.RepresentativeId, + ContractingPartyId = x.ContractingPartyId, + ContractDateFa = x.ContractDateFa, + State = x.State, + City = x.City, + Address = x.Address, + Description = x.Description, + WorkshopManualCount = x.WorkshopManualCount, + EmployeeManualCount = x.EmployeeManualCount, + ContractAmountString = x.ContractAmount.ToMoney(), + ContractAmount = x.ContractAmount, + DailyCompenseationString = x.DailyCompenseation.ToMoney(), + ObligationString = x.Obligation.ToMoney(), + TotalAmountString = x.TotalAmount.ToMoney(), + ExtensionNo = x.ExtensionNo, + OfficialCompany = x.OfficialCompany, + TypeOfContract = x.TypeOfContract, + Signature = x.Signature, + HasValueAddedTax = x.HasValueAddedTax, + ValueAddedTax = x.ValueAddedTax, + }) .FirstOrDefault(x => x.Id == id); } public EditInstitutionContract GetFirstContract(long contractingPartyId, string typeOfContract) { return _context.InstitutionContractSet.Select(x => new EditInstitutionContract() - { - Id = x.id, - ContractNo = x.ContractNo, - ContractStartGr = x.ContractStartGr, - ContractStartFa = x.ContractStartFa, - ContractEndGr = x.ContractEndGr, - ContractEndFa = x.ContractEndFa, - RepresentativeName = x.RepresentativeName, - ContractingPartyName = x.ContractingPartyName, - RepresentativeId = x.RepresentativeId, - ContractingPartyId = x.ContractingPartyId, - ContractDateFa = x.ContractDateFa, - State = x.State, - City = x.City, - Address = x.Address, - Description = x.Description, - WorkshopManualCount = x.WorkshopManualCount, - EmployeeManualCount = x.EmployeeManualCount, - ContractAmountString = x.ContractAmount.ToMoney(), - DailyCompenseationString = x.DailyCompenseation.ToMoney(), - ObligationString = x.Obligation.ToMoney(), - TotalAmountString = x.TotalAmount.ToMoney(), - ExtensionNo = x.ExtensionNo, - OfficialCompany = x.OfficialCompany, - TypeOfContract = x.TypeOfContract, - Signature = x.Signature - }) + { + Id = x.id, + ContractNo = x.ContractNo, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + RepresentativeName = x.RepresentativeName, + ContractingPartyName = x.ContractingPartyName, + RepresentativeId = x.RepresentativeId, + ContractingPartyId = x.ContractingPartyId, + ContractDateFa = x.ContractDateFa, + State = x.State, + City = x.City, + Address = x.Address, + Description = x.Description, + WorkshopManualCount = x.WorkshopManualCount, + EmployeeManualCount = x.EmployeeManualCount, + ContractAmountString = x.ContractAmount.ToMoney(), + DailyCompenseationString = x.DailyCompenseation.ToMoney(), + ObligationString = x.Obligation.ToMoney(), + TotalAmountString = x.TotalAmount.ToMoney(), + ExtensionNo = x.ExtensionNo, + OfficialCompany = x.OfficialCompany, + TypeOfContract = x.TypeOfContract, + Signature = x.Signature + }) .Where(x => x.ContractingPartyId == contractingPartyId && x.TypeOfContract == typeOfContract) .OrderBy(x => x.ExtensionNo).FirstOrDefault(); } @@ -572,40 +586,40 @@ public class InstitutionContractRepository : RepositoryBase new InstitutionContractViewModel() - { - Id = x.Id, - ContractNo = x.ContractNo, - ContractStartGr = x.ContractStartGr, - ContractStartFa = x.ContractStartFa, - ContractEndGr = x.ContractEndGr, - ContractEndFa = x.ContractEndFa, - RepresentativeId = x.RepresentativeId, - RepresentativeName = x.RepresentativeName, - ContractingPartyName = x.ContractingPartyName, - ContractingPartyId = x.ContractingPartyId, - ContractAmount = x.ContractAmount, - TotalAmount = x.TotalAmount, - SearchAmount = x.SearchAmount, - IsActiveString = x.IsActiveString, - OfficialCompany = x.OfficialCompany, - TypeOfContract = x.TypeOfContract, - Signature = x.Signature, - ExpireColor = x.ExpireColor, - IsExpier = x.IsExpier, - BalanceDouble = x.BalanceDouble, - BalanceStr = x.BalanceStr, - EmployerViewModels = x.EmployerViewModels, - EmployerNo = x.EmployerNo, - EmployerName = x.EmployerViewModels.Select(n => n.FullName).FirstOrDefault(), - WorkshopViewModels = x.WorkshopViewModels, - WorkshopCount = x.WorkshopCount, - IsContractingPartyBlock = x.IsContractingPartyBlock, - BlockTimes = x.BlockTimes, - EmployeeCount = + { + Id = x.Id, + ContractNo = x.ContractNo, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + RepresentativeId = x.RepresentativeId, + RepresentativeName = x.RepresentativeName, + ContractingPartyName = x.ContractingPartyName, + ContractingPartyId = x.ContractingPartyId, + ContractAmount = x.ContractAmount, + TotalAmount = x.TotalAmount, + SearchAmount = x.SearchAmount, + IsActiveString = x.IsActiveString, + OfficialCompany = x.OfficialCompany, + TypeOfContract = x.TypeOfContract, + Signature = x.Signature, + ExpireColor = x.ExpireColor, + IsExpier = x.IsExpier, + BalanceDouble = x.BalanceDouble, + BalanceStr = x.BalanceStr, + EmployerViewModels = x.EmployerViewModels, + EmployerNo = x.EmployerNo, + EmployerName = x.EmployerViewModels.Select(n => n.FullName).FirstOrDefault(), + WorkshopViewModels = x.WorkshopViewModels, + WorkshopCount = x.WorkshopCount, + IsContractingPartyBlock = x.IsContractingPartyBlock, + BlockTimes = x.BlockTimes, + EmployeeCount = ((x.WorkshopViewModels.Sum(w => w.LeftWorkIds.Count)) + (x.WorkshopViewModels.Sum(w => w.InsuranceLeftWorkIds.Count(c => !w.LeftWorkIds.Contains(c))))).ToString(), - ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0, - }).OrderBy(x => x.WorkshopCount != "0" && string.IsNullOrWhiteSpace(x.ExpireColor)) + ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0, + }).OrderBy(x => x.WorkshopCount != "0" && string.IsNullOrWhiteSpace(x.ExpireColor)) .ThenBy(x => x.WorkshopCount == "0" && string.IsNullOrWhiteSpace(x.ExpireColor)) .ThenBy(x => x.IsExpier == "true") .ThenBy(x => x.ExpireColor == "purple") @@ -666,7 +680,6 @@ public class InstitutionContractRepository : RepositoryBase x.ContractingPartyId == institutionContarct.ContractingPartyId); if (financialStatement != null) { - var sumDebtor = financialStatement.FinancialTransactionList .Sum(x => x.Deptor); var sumCreditor = financialStatement.FinancialTransactionList @@ -1114,9 +1127,9 @@ public class InstitutionContractRepository : RepositoryBase g.Key, // g => g.Max(x => x.ExtensionNo) // ); - + var rawQuery = _context.InstitutionContractSet - .Include(x=>x.Installments) + .Include(x => x.Installments) .AsNoTracking() .Join(_context.PersonalContractingParties .AsNoTracking() @@ -1131,33 +1144,33 @@ public class InstitutionContractRepository : RepositoryBase c.IsActiveString == "true" && // c.ContractEndGr >= now && // c.ContractEndGr <= endThisMontGr); - - var joinedQuery = rawQuery.Select(x => new - { - x.contract, - x.contractingParty, - StatusPriority = - x.contract.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify - ? (int)InstitutionContractListStatus.PendingForVerify - : x.contract.IsActiveString == "blue" - ? (int)InstitutionContractListStatus.DeactiveWithDebt - : x.contract.ContractEndGr < now - ? (int)InstitutionContractListStatus.Deactive - : (x.contract.ContractEndGr >= now && x.contract.ContractEndGr <= endThisMontGr && - !_context.InstitutionContractSet.Any(i => - i.ContractingPartyId == x.contract.ContractingPartyId && - x.contract.ExtensionNo + 1 <= i.ExtensionNo && i.IsActiveString == "true")) - ? (int)InstitutionContractListStatus.PendingForRenewal - : x.contractingParty.IsBlock == "true" - ? (int)InstitutionContractListStatus.Block - : x.contract.ContractAmount == 0 - ? (int)InstitutionContractListStatus.Free - : !x.contractingParty.Employers - .SelectMany(e => e.WorkshopEmployers - .Select(we => we.Workshop)).Any() - ? (int)InstitutionContractListStatus.WithoutWorkshop - : (int)InstitutionContractListStatus.Active - }); + + var joinedQuery = rawQuery.Select(x => new + { + x.contract, + x.contractingParty, + StatusPriority = + x.contract.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify + ? (int)InstitutionContractListStatus.PendingForVerify + : x.contract.IsActiveString == "blue" + ? (int)InstitutionContractListStatus.DeactiveWithDebt + : x.contract.ContractEndGr < now + ? (int)InstitutionContractListStatus.Deactive + : (x.contract.ContractEndGr >= now && x.contract.ContractEndGr <= endThisMontGr && + !_context.InstitutionContractSet.Any(i => + i.ContractingPartyId == x.contract.ContractingPartyId && + x.contract.ExtensionNo + 1 <= i.ExtensionNo && i.IsActiveString == "true")) + ? (int)InstitutionContractListStatus.PendingForRenewal + : x.contractingParty.IsBlock == "true" + ? (int)InstitutionContractListStatus.Block + : x.contract.ContractAmount == 0 + ? (int)InstitutionContractListStatus.Free + : !x.contractingParty.Employers + .SelectMany(e => e.WorkshopEmployers + .Select(we => we.Workshop)).Any() + ? (int)InstitutionContractListStatus.WithoutWorkshop + : (int)InstitutionContractListStatus.Active + }); #region Search @@ -1322,7 +1335,7 @@ public class InstitutionContractRepository : RepositoryBasex.InitialWorkshops ) + .Include(x => x.InitialWorkshops) .Include(x => x.CurrentWorkshops) .Where(x => contractIds.Contains(x.InstitutionContractId)) .ToDictionaryAsync(x => x.InstitutionContractId, x => x); @@ -1349,10 +1362,10 @@ public class InstitutionContractRepository : RepositoryBase(x.StatusPriority.ToString()); - + // دریافت WorkshopGroup از dictionary بارگذاری شده workshopGroups.TryGetValue(x.contract.id, out var workshopGroup); - + List currentStateWorkshops = workshopGroup?.CurrentWorkshops .Cast().ToList(); @@ -1394,21 +1407,25 @@ public class InstitutionContractRepository : RepositoryBase x.InitialWorkshops) .Include(x => x.WorkshopGroup) .ThenInclude(x => x.CurrentWorkshops) - .Include(x=>x.Installments) + .Include(x => x.Installments) .FirstOrDefaultAsync(x => x.id == institutionContractId); } @@ -1949,7 +1966,8 @@ public class InstitutionContractRepository : RepositoryBase x.PublicId == id); } - public InstitutionContractDiscountResponse CalculateDiscount(InstitutionContractSetDiscountRequest request,string contractStart=null) + public InstitutionContractDiscountResponse CalculateDiscount(InstitutionContractSetDiscountRequest request, + string contractStart = null) { var baseAmount = request.TotalAmount; var discountAmount = (baseAmount * request.DiscountPercentage) / 100; @@ -2208,10 +2226,12 @@ public class InstitutionContractRepository : RepositoryBase x.WorkshopGroup) .ThenInclude(institutionContractWorkshopGroup => institutionContractWorkshopGroup.CurrentWorkshops) .FirstOrDefaultAsync(x => x.id == extenstionTemp.PreviousId); - - var employerWorkshopIds = _context.Employers.Where(x=>x.ContractingPartyId == prevInstitutionContracts.ContractingPartyId).Include(x=>x.WorkshopEmployers) - .SelectMany(x=>x.WorkshopEmployers).Select(x=>x.WorkshopId).Distinct().ToList(); - + + var employerWorkshopIds = _context.Employers + .Where(x => x.ContractingPartyId == prevInstitutionContracts.ContractingPartyId) + .Include(x => x.WorkshopEmployers) + .SelectMany(x => x.WorkshopEmployers).Select(x => x.WorkshopId).Distinct().ToList(); + if (prevInstitutionContracts == null) { throw new BadRequestException("قرارداد مالی قبلی یافت نشد"); @@ -2224,12 +2244,13 @@ public class InstitutionContractRepository : RepositoryBase x.WorkshopId.Value); - - var workshopsNotInInstitution = employerWorkshopIds.Where(x=> !workshopIds.Contains(x)).ToList(); - - var workshops = await _context.Workshops.Where(x => workshopIds.Contains(x.id) || employerWorkshopIds.Contains(x.id)) + + var workshopsNotInInstitution = employerWorkshopIds.Where(x => !workshopIds.Contains(x)).ToList(); + + var workshops = await _context.Workshops + .Where(x => workshopIds.Contains(x.id) || employerWorkshopIds.Contains(x.id)) .ToListAsync(); - + var workshopDetails = prevInstitutionContracts.WorkshopGroup.CurrentWorkshops .Select(x => { @@ -2271,14 +2292,14 @@ public class InstitutionContractRepository : RepositoryBase workshopsNotInInstitution.Contains(x.WorkshopId) && x.StartWorkDate <= DateTime.Now && x.LeftWorkDate >= DateTime.Now) .GroupBy(x => x.WorkshopId).ToListAsync(); - var notIncludeWorskhopsInContract = workshopsNotInInstitution.Select(x => + var notIncludeWorskhopsInContract = workshopsNotInInstitution.Select(x => { var workshop = workshops.FirstOrDefault(w => w.id == x); - var leftWorks = notIncludeWorskhopsLeftWork.FirstOrDefault(l=>l.Key ==x); + var leftWorks = notIncludeWorskhopsLeftWork.FirstOrDefault(l => l.Key == x); return new WorkshopTempViewModel() { WorkshopName = workshop?.WorkshopName ?? "فاقد کارگاه", @@ -2289,7 +2310,7 @@ public class InstitutionContractRepository : RepositoryBase=100) + if (request.DiscountPercentage >= 100) { throw new BadRequestException("مقدار تخفیف نمی‌تواند برابر یا بیشتر از صد باشد"); } + var institutionTemp = await _institutionExtensionTemp.Find(x => x.Id == request.TempId) .FirstOrDefaultAsync(); if (institutionTemp == null) @@ -2432,7 +2454,7 @@ public class InstitutionContractRepository : RepositoryBase 0) throw new BadRequestException("تخفیف قبلا برای این قرارداد اعمال شده است"); } - + var selectedPlan = institutionTemp.Duration switch { InstitutionContractDuration.OneMonth => institutionTemp.OneMonth, @@ -2449,18 +2471,18 @@ public class InstitutionContractRepository : RepositoryBase(); var institutionContracts = await _context.InstitutionContractSet.Select(x => new InstitutionContractViewModel - { - Id = x.id, - ContractingPartyId = x.ContractingPartyId, - ContractingPartyName = x.ContractingPartyName, - ContractStartGr = x.ContractStartGr, - ContractStartFa = x.ContractStartFa, - ContractEndGr = x.ContractEndGr, - ContractEndFa = x.ContractEndFa, - IsActiveString = x.IsActiveString, - ContractAmountDouble = x.ContractAmount, - OfficialCompany = x.OfficialCompany - }).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate && - x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First()) + { + Id = x.id, + ContractingPartyId = x.ContractingPartyId, + ContractingPartyName = x.ContractingPartyName, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + IsActiveString = x.IsActiveString, + ContractAmountDouble = x.ContractAmount, + OfficialCompany = x.OfficialCompany + }).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate && + x.ContractAmountDouble > 0).GroupBy(x => x.ContractingPartyId).Select(x => x.First()) .ToListAsync(); @@ -4361,8 +4383,6 @@ public class InstitutionContractRepository : RepositoryBase @@ -4408,6 +4428,7 @@ public class InstitutionContractRepository : RepositoryBase /// ارسال پیامک یادآور تایید قراداد مالی /// @@ -4454,18 +4475,23 @@ public class InstitutionContractRepository : RepositoryBase x.CreationDate >= fromAmonthAgo && x.CreationDate.Date != now.Date && x.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify) + .Where(x => x.CreationDate >= fromAmonthAgo && x.CreationDate.Date != now.Date && + x.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify) .Join(_context.PersonalContractingParties, - contract => contract.ContractingPartyId, + contract => contract.ContractingPartyId, contractingParty => contractingParty.id, - (contract, contractingParty) => new { contract, contractingParty }).Select(x => new InstitutionCreationVerificationSmsDto + (contract, contractingParty) => new { contract, contractingParty }).Select(x => + new InstitutionCreationVerificationSmsDto { Number = x.contractingParty.Phone, - FullName = x.contractingParty.IsLegal == "حقیقی" ? $"{x.contractingParty.FName} {x.contractingParty.LName}" : $"{x.contractingParty.LName}", + FullName = x.contractingParty.IsLegal == "حقیقی" + ? $"{x.contractingParty.FName} {x.contractingParty.LName}" + : $"{x.contractingParty.LName}", ContractingPartyId = x.contract.ContractingPartyId, InstitutionContractId = x.contract.id, InstitutionId = x.contract.PublicId, @@ -4474,20 +4500,15 @@ public class InstitutionContractRepository : RepositoryBase new InstitutionContractInstallmentViewModel - { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }) + { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }) .OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(), }).Where(x => - x.ContractStartGr < endOfMonthGr && x.ContractEndGr >= endOfMonthGr && x.ContractAmountDouble > 0 && x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify) + x.ContractStartGr < endOfMonthGr && x.ContractEndGr >= endOfMonthGr && x.ContractAmountDouble > 0 && + x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify) .ToListAsync(); #endregion @@ -4553,13 +4575,14 @@ public class InstitutionContractRepository : RepositoryBase futureContractIds = futureContracts.Select(x => x.ContractingPartyId).ToList(); List deatcivedContract = await _context.InstitutionContractSet .Where(x => x.IsActiveString == "false" && futureContractIds.Contains(x.ContractingPartyId) && - x.ContractEndGr.Date == endOfCurrentMonth.Date && x.ContractAmount > 0 && x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify) + x.ContractEndGr.Date == endOfCurrentMonth.Date && x.ContractAmount > 0 && + x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify) .Select(x => new InstitutionContractViewModel { Id = x.id, @@ -4577,7 +4600,7 @@ public class InstitutionContractRepository : RepositoryBase new InstitutionContractInstallmentViewModel - { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }) + { AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr }) .OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(), }).ToListAsync(); @@ -4587,7 +4610,9 @@ public class InstitutionContractRepository : RepositoryBase - x.SigningType != InstitutionContractSigningType.Legacy && x.IsInstallment == false && x.SigningType != null).ToList(); + x.SigningType != InstitutionContractSigningType.Legacy && x.IsInstallment == false && + x.SigningType != null) + .ToList(); //حذف قراداد هایی که یکجا پرداخت شده اند از لیست ایجاد سند ماهانه institutionContracts = institutionContracts.Except(paidInFull).ToList(); @@ -4699,10 +4724,12 @@ public class InstitutionContractRepository : RepositoryBase GetPreviousContract(long currentInstitutionContractId) { - var institutionContract =await _context.InstitutionContractSet - .FirstOrDefaultAsync(x=>x.id ==currentInstitutionContractId); + var institutionContract = await _context.InstitutionContractSet + .FirstOrDefaultAsync(x => x.id == currentInstitutionContractId); if (institutionContract == null) return null; var previousContract = await _context.InstitutionContractSet @@ -4898,6 +4925,266 @@ public class InstitutionContractRepository : RepositoryBase CreationInquiry( + InstitutionContractCreationInquiryRequest request) + { + var op = new OperationResult(); + + var result = new InstitutionContractCreationInquiryResult(); + + var contractTemp = new InstitutionContractCreationTemp(); + + result.TempId = contractTemp.Id; + + + string idNumberSeri; + string idNumberSerial; + + var dateOfBirth = request.DateOfBirth.Trim(); + var nationalCode = request.NationalCode.Trim(); + var mobile = request.Mobile.Trim(); + + #region Validations + + if (string.IsNullOrWhiteSpace(request.NationalCode) || string.IsNullOrWhiteSpace(request.DateOfBirth) || + string.IsNullOrWhiteSpace(request.Mobile)) + + throw new BadRequestException("هیچ یک از فیلد ها نمیتواند خالی باشد"); + + + if (request.NationalCode.NationalCodeValid() != "valid") + throw new BadRequestException("کد ملی نا معتبر است"); + + if (!request.DateOfBirth.IsPersianDateValid()) + throw new BadRequestException("تاریخ تولد نا معتبر است"); + + if (!request.Mobile.IsMobileValid()) + throw new BadRequestException("شماره همراه نا معتبر است"); + + #endregion + + var dateOfBirthGr = dateOfBirth.ToGeorgianDateTime(); + + var contractingParty = + await _context.PersonalContractingParties.FirstOrDefaultAsync(x => x.Nationalcode == nationalCode); + + if (contractingParty != null) + { + + if (contractingParty.DateOfBirth != null && contractingParty.DateOfBirth != dateOfBirthGr) + throw new BadRequestException("تاریخ تولد مطابقت ندارد"); + + + var idNumberParty = contractingParty.IdNumber; + if (!contractingParty.IsAuthenticated) + { + //دریافت اطلاعات احراز هویت + var apiResponseParty = await _uidService + .GetPersonalInfo(nationalCode, dateOfBirth); + + if (apiResponseParty == null) + throw new InternalServerException("خطا در سرویس احراز هویت"); + + if (apiResponseParty.ResponseContext.Status.Code is 14 or 3) + throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد"); + + if (apiResponseParty.ResponseContext.Status.Code != 0) + throw new BadRequestException($"{apiResponseParty.ResponseContext.Status.Message}"); + + idNumberParty = apiResponseParty.IdentificationInformation.ShenasnamehNumber == "0" + ? apiResponseParty.IdentificationInformation.NationalId + : apiResponseParty.IdentificationInformation.ShenasnamehNumber; + + //چک کردن مطابقت شماره همراه و کد ملی + var isMachMobilAndNationalCode = await _uidService + .IsMachPhoneWithNationalCode(nationalCode, mobile); + + if (isMachMobilAndNationalCode == null) + throw new InternalServerException("خطا در سرویس تطابق کد ملی و شماره همراه"); + + if (!isMachMobilAndNationalCode.IsMatched) + throw new BadRequestException("شماره همراه وارد شده با کد ملی مطابقت ندارد"); + + contractingParty.Authentication(apiResponseParty.BasicInformation.FirstName, + apiResponseParty.BasicInformation.LastName, + apiResponseParty.BasicInformation.FatherName, idNumberParty, + apiResponseParty.IdentificationInformation.ShenasnameSeri, + apiResponseParty.IdentificationInformation.ShenasnameSerial, dateOfBirth, + apiResponseParty.BasicInformation.GenderEnum, + mobile); + idNumberSeri = apiResponseParty.IdentificationInformation.ShenasnameSeri; + idNumberSerial = apiResponseParty.IdentificationInformation.ShenasnameSerial; + + await _context.SaveChangesAsync(); + } + + if (contractingParty.Phone != mobile) + throw new BadRequestException("شما قبلا با شماره همراه دیگری احراز هویت شده اید"); + + if (contractingParty.IsLegal == "حقیقی") + { + var realParty = new CreateInstitutionContractRealPartyRequest + { + FName = contractingParty.FName, + LName = contractingParty.LName, + NationalCode = contractingParty.Nationalcode, + IdNumber = contractingParty.IdNumber, + FatherName = contractingParty.FatherName, + Gender = contractingParty.Gender, + PhoneNumber = contractingParty.Phone, + IsAuth = true, + }; + result.RealParty = realParty; + result.LegalParty = null; + result.LegalType = LegalType.Real; + } + else + { + var legalParty = new CreateInstitutionContractLegalPartyRequest + { + CompanyName = contractingParty.LName, + NationalCode = contractingParty.Nationalcode, + IdNumber = contractingParty.IdNumber, + RegisterId = contractingParty.RegisterId, + FName = contractingParty.CeoFName, + LName = contractingParty.CeoLName, + FatherName = contractingParty.FatherName, + Gender = contractingParty.Gender, + PhoneNumber = contractingParty.Phone, + BirthDateFa = contractingParty.DateOfBirth.ToFarsi(), + NationalId = contractingParty.NationalId, + Position = contractingParty.LegalPosition, + IsAuth = true, + }; + result.LegalParty = legalParty; + result.RealParty = null; + result.LegalType = LegalType.Legal; + } + idNumberSeri = contractingParty.IdNumberSeri; + idNumberSerial = contractingParty.IdNumberSerial; + + } + else + { + //چک کردن مطابقت شماره همراه و کد ملی + var isMachMobilAndNationalCode = await _uidService.IsMachPhoneWithNationalCode(nationalCode, mobile); + + if (isMachMobilAndNationalCode == null) + throw new BadRequestException("خطا در سرویس احراز هویت"); + + if (!isMachMobilAndNationalCode.IsMatched) + throw new BadRequestException("شماره همراه وارد شده با کد ملی مطابقت ندارد"); + + //دریافت اطلاعات احراز هویت + var apiRespons = await _uidService.GetPersonalInfo(nationalCode, dateOfBirth); + + if (apiRespons == null) + throw new InternalServerException("خطا در سرویس احراز هویت"); + + if (apiRespons.ResponseContext.Status.Code is 14 or 3) + throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد"); + + if (apiRespons.ResponseContext.Status.Code == 2) + { + throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد"); + } + + if (apiRespons.ResponseContext.Status.Code != 0) + throw new BadRequestException($"{apiRespons.ResponseContext.Status.Message}"); + + var idNumber = apiRespons.IdentificationInformation.ShenasnamehNumber == "0" + ? apiRespons.IdentificationInformation.NationalId + : apiRespons.IdentificationInformation.ShenasnamehNumber; + + if (request.LegalType == LegalType.Real) + { + result.RealParty = new CreateInstitutionContractRealPartyRequest() + { + FName = apiRespons.BasicInformation.FirstName, + LName = apiRespons.BasicInformation.LastName, + NationalCode = nationalCode, + IdNumber = idNumber, + FatherName = apiRespons.BasicInformation.FatherName, + Gender = apiRespons.BasicInformation.GenderEnum, + PhoneNumber = mobile, + IsAuth = true, + BirthDateFa = apiRespons.IdentificationInformation.BirthDate, + }; + result.LegalParty = null; + } + else + { + result.LegalParty = new CreateInstitutionContractLegalPartyRequest() + { + FName = apiRespons.BasicInformation.FirstName, + LName = apiRespons.BasicInformation.LastName, + NationalCode = nationalCode, + IdNumber = idNumber, + FatherName = apiRespons.BasicInformation.FatherName, + Gender = apiRespons.BasicInformation.GenderEnum, + BirthDateFa = apiRespons.IdentificationInformation.BirthDate, + IsAuth = true, + PhoneNumber = request.Mobile, + + }; + result.RealParty = null; + } + idNumberSeri = apiRespons.IdentificationInformation.ShenasnameSeri; + idNumberSerial = apiRespons.IdentificationInformation.ShenasnameSerial; + } + + InstitutionContractCreationTempRealParty tempRealParty = null; + InstitutionContractCreationTempLegalParty tempLegalParty = null; + if (result.RealParty != null) + { + var realParty = result.RealParty; + tempRealParty = new() + { + BirthDateFa = realParty.BirthDateFa, + FatherName = realParty.FatherName, + FName = realParty.FName, + Gender = realParty.Gender, + IdNumber = realParty.IdNumber, + NationalCode = realParty.NationalCode, + IsAuth = realParty.IsAuth, + LName = realParty.LName, + PhoneNumber = realParty.PhoneNumber, + IdNumberSerial = idNumberSerial, + IdNumberSeri = idNumberSeri, + + }; + } + + if (result.LegalParty !=null) + { + var legalParty = result.LegalParty; + tempLegalParty = new() + { + BirthDateFa = legalParty.BirthDateFa, + FatherName = legalParty.FatherName, + FName = legalParty.FName, + IdNumberSerial = idNumberSerial, + IdNumberSeri = idNumberSeri, + Gender = legalParty.Gender, + IdNumber = legalParty.IdNumber, + LName = legalParty.LName, + NationalCode = legalParty.NationalCode, + CompanyName = legalParty.CompanyName, + RegisterId = legalParty.RegisterId, + NationalId = legalParty.NationalId, + PhoneNumber = legalParty.PhoneNumber, + Position = legalParty.Position, + IsAuth = legalParty.IsAuth, + }; + } + + + contractTemp.SetContractingPartyInfo(result.LegalType,tempRealParty, tempLegalParty); + await _institutionContractCreationTemp.InsertOneAsync(contractTemp); + + return result; + } + #endregion diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index f77e0964..0548a2b4 100644 --- a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs +++ b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs @@ -349,7 +349,7 @@ public class institutionContractController : AdminBaseController [HttpPost("create/inquiry")] public async Task>> CreateInquiry( - [FromBody] CreateInquiryRequest request) + [FromBody] InstitutionContractCreationInquiryRequest request) { var res = await _temporaryClientRegistration.CreateContractingPartyTemp(request.NationalCode, request.DateOfBirth, @@ -529,10 +529,10 @@ public class institutionContractController : AdminBaseController } #region Create - [HttpGet("creation/inquiry/{previousContractId}")] - public async Task> ExtensionInquiry(long previousContractId) + [HttpPost("creation/inquiry/")] + public async Task> CreationInquiry(InstitutionContractCreationInquiryRequest request) { - var res= await _institutionContractApplication.GetExtensionInquiry(previousContractId); + var res= await _institutionContractApplication.CreationInquiry(request); return res; } @@ -936,12 +936,6 @@ public class WorkshopServiceCalculatorResponse public record InstitutionPlanCalculatorRequest(double TotalAmountMonth,bool HasInPersonContract, InstitutionContractDuration Duration = InstitutionContractDuration.TwelveMonths); -public class CreateInquiryRequest -{ - public string NationalCode { get; set; } - public string DateOfBirth { get; set; } - public string Mobile { get; set; } -} public class VerifyCodeRequest { From 836e721b6fa78830ce514edb8a9541a930507ab0 Mon Sep 17 00:00:00 2001 From: mahan Date: Tue, 30 Dec 2025 10:38:07 +0330 Subject: [PATCH 3/3] feat: refactor institution contract creation classes and endpoints --- .../IInstitutionContractRepository.cs | 6 + .../InstitutionContractCreationTemp.cs | 22 +- .../IInstitutionContractApplication.cs | 102 +- ...itutionContractExtensionCompleteRequest.cs | 7 + ...titutionContractExtensionPaymentRequest.cs | 5 + ...itutionContractExtensionPaymentResponse.cs | 7 + ...InstitutionContractExtensionPlanRequest.cs | 7 + ...nstitutionContractExtensionPlanResponse.cs | 10 +- ...ontractResetDiscountForExtensionRequest.cs | 5 + ...nContractSetDiscountForExtensionRequest.cs | 7 + .../InstitutionContractApplication.cs | 31 +- .../InstitutionContractRepository.cs | 921 +++++++++++++++++- .../institutionContractController.cs | 34 +- 13 files changed, 1095 insertions(+), 69 deletions(-) diff --git a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs index 993e8309..c578d7be 100644 --- a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs +++ b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs @@ -165,4 +165,10 @@ public interface IInstitutionContractRepository : IRepository GetIdByInstallmentId(long installmentId); Task GetPreviousContract(long currentInstitutionContractId); Task CreationInquiry(InstitutionContractCreationInquiryRequest request); + Task GetCreationWorkshops(InstitutionContractCreationWorkshopsRequest request); + Task GetCreationInstitutionPlan(InstitutionContractCreationPlanRequest request); + Task GetCreationPaymentMethod(InstitutionContractCreationPaymentRequest request); + Task SetDiscountForCreation(InstitutionContractSetDiscountForCreationRequest request); + Task ResetDiscountForCreation(InstitutionContractResetDiscountForExtensionRequest request); + Task CreationComplete(InstitutionContractExtensionCompleteRequest request); } \ No newline at end of file diff --git a/Company.Domain/InstitutionContractCreationTempAgg/InstitutionContractCreationTemp.cs b/Company.Domain/InstitutionContractCreationTempAgg/InstitutionContractCreationTemp.cs index 9a34955e..9ffa4775 100644 --- a/Company.Domain/InstitutionContractCreationTempAgg/InstitutionContractCreationTemp.cs +++ b/Company.Domain/InstitutionContractCreationTempAgg/InstitutionContractCreationTemp.cs @@ -39,6 +39,8 @@ public class InstitutionContractCreationTemp public string City { get; set; } public string Province { get; set; } public List ContactInfos { get; set; } + public long RepresentativeId { get; set; } + public List Workshops { get; set; } @@ -83,11 +85,25 @@ public class InstitutionContractCreationTemp OneTimePayment = oneTime; } - + + public void SetContractingPartyContactInfo(string address, string city, string province, List requestContactInfos,long representativeId) + { + Address = address; + City = city; + Province = province; + ContactInfos = requestContactInfos; + RepresentativeId = representativeId; + } + } public class InstitutionContractCreationTempLegalParty { + /// + /// آیدی طرف حساب در صورتی که از قبل ایجاد شده باشد + /// + public long Id { get; set; } + /// /// نام شرکت /// @@ -165,6 +181,10 @@ public class InstitutionContractCreationTempLegalParty public class InstitutionContractCreationTempRealParty { + /// + /// آیدی طرف حساب در صورتی که از قبل ایجاد شده باشد + /// + public long Id { get; set; } /// /// کد ملی /// diff --git a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs index d53b5d5c..bd450192 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs @@ -5,8 +5,10 @@ using System.Drawing; using System.Linq; using System.Threading.Tasks; using _0_Framework.Application; +using _0_Framework.Application.Enums; using _0_Framework.Application.Sms; using CompanyManagment.App.Contracts.Checkout; +using CompanyManagment.App.Contracts.InstitutionContractContactinfo; using CompanyManagment.App.Contracts.TemporaryClientRegistration; using CompanyManagment.App.Contracts.Workshop; using CompanyManagment.App.Contracts.WorkshopPlan; @@ -26,21 +28,21 @@ public interface IInstitutionContractApplication /// اطلاعات قرارداد جدید /// نتیجه عملیات OperationResult Create(CreateInstitutionContract command); - + /// /// تمدید قرارداد موجود /// /// اطلاعات قرارداد برای تمدید /// نتیجه عملیات OperationResult Extension(CreateInstitutionContract command); - + /// /// ویرایش قرارداد موجود /// /// اطلاعات جدید قرارداد /// نتیجه عملیات OperationResult Edit(EditInstitutionContract command); - + /// /// دریافت جزئیات قرارداد برای ویرایش /// @@ -54,7 +56,7 @@ public interface IInstitutionContractApplication /// مدل جستجو /// لیست قراردادها List Search(InstitutionContractSearchModel searchModel); - + /// /// جستجوی جدید در قراردادها /// @@ -76,7 +78,7 @@ public interface IInstitutionContractApplication /// لیست شناسه قراردادها /// لیست قراردادها برای چاپ List PrintAll(List id); - + [Obsolete("استفاده نشود، از متد غیرهمزمان استفاده شود")] /// @@ -146,7 +148,7 @@ public interface IInstitutionContractApplication /// شناسه قرارداد /// نتیجه عملیات OperationResult UnSign(long id); - + /// /// ایجاد حساب کاربری برای طرف قرارداد /// @@ -191,25 +193,24 @@ public interface IInstitutionContractApplication /// /// Task EditAsync(EditInstitutionContractRequest command); - - + + /// /// دریافت لیست طرف حساب هایی که ثبت نام آنها تکمیل شده /// جهت نمایش در کارپوشه /// /// Task> RegistrationWorkflowMainList(); + /// /// دریافت آیتم های کارپوشه ثبت نام /// /// /// Task> RegistrationWorkflowItems(long institutionContractId); - - #endregion - + Task GetVerificationDetails(Guid id); Task> SendVerifyOtp(Guid id); Task> VerifyOtpAndMakeGateway(Guid publicId, string code, string callbackUrl); @@ -219,12 +220,29 @@ public interface IInstitutionContractApplication #region Creation - + /// + /// تب ایجاد قرارداد مؤسسه - احراز هویت + /// + /// + /// Task CreationInquiry(InstitutionContractCreationInquiryRequest request); - - #endregion - + /// + /// تب ایجاد قرارداد مؤسسه -مشخصات طرف قرارداد و انتخاب کارگاه ها + /// + /// + /// + Task GetCreationWorkshops( + InstitutionContractCreationWorkshopsRequest request); + /// + /// تب ایجاد قرارداد مؤسسه - مالی + /// + /// + /// + Task GetCreationInstitutionPlan(InstitutionContractCreationPlanRequest request); + + #endregion + #region Extension Task GetExtensionInquiry(long previousContractId); @@ -237,25 +255,31 @@ public interface IInstitutionContractApplication Task GetExtensionPaymentMethod( InstitutionContractExtensionPaymentRequest request); - + Task SetDiscountForExtension( InstitutionContractSetDiscountForExtensionRequest request); + Task ResetDiscountForExtension( InstitutionContractResetDiscountForExtensionRequest request); - + Task ExtensionComplete(InstitutionContractExtensionCompleteRequest request); - Task> GetInstitutionContractSelectList(string search,string selected); + Task> GetInstitutionContractSelectList(string search, string selected); #endregion #region Upgrade (Amendment) Task GetAmendmentWorkshops(long institutionContractId); - Task InsertAmendmentTempWorkshops(InstitutionContractAmendmentTempWorkshopViewModel request); + + Task InsertAmendmentTempWorkshops( + InstitutionContractAmendmentTempWorkshopViewModel request); + Task RemoveAmendmentWorkshops(Guid workshopTempId); - Task GetAmendmentPaymentDetails(InsitutionContractAmendmentPaymentRequest request); - + + Task GetAmendmentPaymentDetails( + InsitutionContractAmendmentPaymentRequest request); + #endregion Task ResendVerifyLink(long institutionContractId); @@ -267,8 +291,9 @@ public interface IInstitutionContractApplication /// Task PrintOneAsync(long id); - Task SetPendingWorkflow(long entityId,InstitutionContractSigningType signingType); + Task SetPendingWorkflow(long entityId, InstitutionContractSigningType signingType); Task GetIdByInstallmentId(long installmentId); + /// /// تایید قرارداد مالی به صورت دستی /// @@ -276,4 +301,37 @@ public interface IInstitutionContractApplication /// Task VerifyInstitutionContractManually(long institutionContractId); + Task GetCreationPaymentMethod(InstitutionContractCreationPaymentRequest request); + Task SetDiscountForCreation(InstitutionContractSetDiscountForCreationRequest request); + Task ResetDiscountForCreation(InstitutionContractResetDiscountForExtensionRequest request); + Task CreationComplete(InstitutionContractExtensionCompleteRequest request); +} + +public class InstitutionContractCreationWorkshopsResponse +{ + public List WorkshopTemps { get; set; } + public string TotalAmount { get; set; } +} + +public class InstitutionContractCreationWorkshopsRequest +{ + public Guid TempId { get; set; } + public string City { get; set; } + public string Province { get; set; } + public string Address { get; set; } + public List ContactInfos { get; set; } + + /// + /// اطلاعات شخص حقیقی + /// + public CreateInstitutionContractRealPartyRequest RealParty { get; set; } + + /// + /// اطلاعات شخص حقوقی + /// + public CreateInstitutionContractLegalPartyRequest LegalParty { get; set; } + + public LegalType LegalType { get; set; } + + public long RepresentativeId { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionCompleteRequest.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionCompleteRequest.cs index f232760c..8de7ac89 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionCompleteRequest.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionCompleteRequest.cs @@ -3,6 +3,13 @@ using System; namespace CompanyManagment.App.Contracts.InstitutionContract; public class InstitutionContractExtensionCompleteRequest +{ + public Guid TemporaryId { get; set; } + public bool IsInstallment { get; set; } + public long LawId { get; set; } +} + +public class InstitutionContractCreationCompleteRequest { public Guid TemporaryId { get; set; } public bool IsInstallment { get; set; } diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPaymentRequest.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPaymentRequest.cs index 8406a53a..46a68eba 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPaymentRequest.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPaymentRequest.cs @@ -3,6 +3,11 @@ using System; namespace CompanyManagment.App.Contracts.InstitutionContract; public class InstitutionContractExtensionPaymentRequest +{ + public InstitutionContractDuration Duration { get; set; } + public Guid TempId { get; set; } +} +public class InstitutionContractCreationPaymentRequest { public InstitutionContractDuration Duration { get; set; } public Guid TempId { get; set; } diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPaymentResponse.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPaymentResponse.cs index 84906caf..5b9a8812 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPaymentResponse.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPaymentResponse.cs @@ -5,4 +5,11 @@ public class InstitutionContractExtensionPaymentResponse public InstitutionContractPaymentOneTimeViewModel OneTime { get; set; } public InstitutionContractPaymentMonthlyViewModel Monthly { get; set; } +} + +public class InstitutionContractCreationPaymentResponse +{ + public InstitutionContractPaymentOneTimeViewModel OneTime { get; set; } + public InstitutionContractPaymentMonthlyViewModel Monthly { get; set; } + } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanRequest.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanRequest.cs index 40804842..b552161c 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanRequest.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanRequest.cs @@ -5,6 +5,13 @@ using CompanyManagment.App.Contracts.TemporaryClientRegistration; namespace CompanyManagment.App.Contracts.InstitutionContract; public class InstitutionContractExtensionPlanRequest +{ + public List WorkshopTemps { get; set; } + public string TotalAmount { get; set; } + public Guid TempId { get; set; } +} + +public class InstitutionContractCreationPlanRequest { public List WorkshopTemps { get; set; } public string TotalAmount { get; set; } diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanResponse.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanResponse.cs index a38e001b..d4a5a2c7 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanResponse.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractExtensionPlanResponse.cs @@ -7,16 +7,8 @@ public class InstitutionContractExtensionPlanResponse public InstitutionContractExtensionPlanDetail SixMonths { get; set; } public InstitutionContractExtensionPlanDetail TwelveMonths { get; set; } } -public class InstitutionContractExtensionPlanDetail +public class InstitutionContractExtensionPlanDetail:InstitutionContractCreationPlanDetail { - public string ContractStart { get; set; } - public string ContractEnd { get; set; } - public string OneMonthPaymentDiscounted { get; set; } - public string OneMonthDiscount { get; set; } - public string OneMonthOriginalPayment { get; set; } - public string TotalPayment { get; set; } - public string DailyCompenseation { get; set; } - public string Obligation { get; set; } } public class InstitutionContractCreationPlanResponse diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractResetDiscountForExtensionRequest.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractResetDiscountForExtensionRequest.cs index 7011e364..43dbe2aa 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractResetDiscountForExtensionRequest.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractResetDiscountForExtensionRequest.cs @@ -3,6 +3,11 @@ using System; namespace CompanyManagment.App.Contracts.InstitutionContract; public class InstitutionContractResetDiscountForExtensionRequest +{ + public Guid TempId { get; set; } + public bool IsInstallment { get; set; } +} +public class InstitutionContractResetCreationForExtensionRequest { public Guid TempId { get; set; } public bool IsInstallment { get; set; } diff --git a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractSetDiscountForExtensionRequest.cs b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractSetDiscountForExtensionRequest.cs index 3df40e5e..c98deddb 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractSetDiscountForExtensionRequest.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/InstitutionContractSetDiscountForExtensionRequest.cs @@ -3,6 +3,13 @@ using System; namespace CompanyManagment.App.Contracts.InstitutionContract; public class InstitutionContractSetDiscountForExtensionRequest +{ + public Guid TempId { get; set; } + public int DiscountPercentage { get; set; } + public double TotalAmount { get; set; } + public bool IsInstallment { get; set; } +} +public class InstitutionContractSetDiscountForCreationRequest { public Guid TempId { get; set; } public int DiscountPercentage { get; set; } diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index 580bdf1d..e186b36b 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -1448,7 +1448,16 @@ public class InstitutionContractApplication : IInstitutionContractApplication { return _institutionContractRepository.CreationInquiry(request); } - + + public Task GetCreationWorkshops(InstitutionContractCreationWorkshopsRequest request) + { + return _institutionContractRepository.GetCreationWorkshops(request); + } + + public Task GetCreationInstitutionPlan(InstitutionContractCreationPlanRequest request) + { + return _institutionContractRepository.GetCreationInstitutionPlan(request); + } public async Task GetExtensionInquiry(long previousContractId) @@ -1669,6 +1678,26 @@ public class InstitutionContractApplication : IInstitutionContractApplication return op.Succcedded(); } + public Task GetCreationPaymentMethod(InstitutionContractCreationPaymentRequest request) + { + return _institutionContractRepository.GetCreationPaymentMethod(request); + } + + public Task SetDiscountForCreation(InstitutionContractSetDiscountForCreationRequest request) + { + return _institutionContractRepository.SetDiscountForCreation(request); + } + + public Task ResetDiscountForCreation(InstitutionContractResetDiscountForExtensionRequest request) + { + return _institutionContractRepository.ResetDiscountForCreation(request); + } + + public Task CreationComplete(InstitutionContractExtensionCompleteRequest request) + { + return _institutionContractRepository.CreationComplete(request); + } + private async Task> CreateLegalContractingPartyEntity( CreateInstitutionContractLegalPartyRequest request, long representativeId, string address, string city, string state) diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index c4b16059..d96c3a24 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -36,7 +36,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using _0_Framework.Application.UID; +using AccountManagement.Application.Contracts.Account; using Company.Domain.InstitutionContractCreationTempAgg; +using Company.Domain.RepresentativeAgg; using Company.Domain.TemporaryClientRegistrationAgg; using ContractingPartyAccount = Company.Domain.ContractingPartyAccountAgg.ContractingPartyAccount; using FinancialStatment = Company.Domain.FinancialStatmentAgg.FinancialStatment; @@ -60,8 +62,8 @@ public class InstitutionContractRepository : RepositoryBase _hubContext; private readonly ILogger _logger; - private readonly IUidService _uidService; - + private readonly IUidService _uidService; + private readonly InstitutionContratVerificationParty _firstParty = new() { @@ -74,6 +76,9 @@ public class InstitutionContractRepository : RepositoryBase hubContext, - ILogger logger, IUidService uidService, IContractingPartyTempRepository contractingPartyTempRepository) : base(context) + ILogger logger, IUidService uidService, + IContractingPartyTempRepository contractingPartyTempRepository, IPersonalContractingPartyRepository contractingPartyRepository, IRepresentativeRepository representativeRepository, IAccountApplication accountApplication) : base(context) { _context = context; _employerRepository = employerRepository; @@ -95,6 +101,9 @@ public class InstitutionContractRepository : RepositoryBase("InstitutionContractExtensionTemp"); _institutionAmendmentTemp = @@ -4968,9 +4977,9 @@ public class InstitutionContractRepository : RepositoryBase x.Nationalcode == nationalCode); + long contractingPartyId = contractingParty?.id ?? 0; if (contractingParty != null) { - if (contractingParty.DateOfBirth != null && contractingParty.DateOfBirth != dateOfBirthGr) throw new BadRequestException("تاریخ تولد مطابقت ندارد"); @@ -5005,13 +5014,27 @@ public class InstitutionContractRepository : RepositoryBase GetCreationWorkshops( + InstitutionContractCreationWorkshopsRequest request) + { + var transaction = await _context.Database.BeginTransactionAsync(); + PersonalContractingParty contractingParty = null; + switch (request.LegalType) + { + case LegalType.Legal: + var legalCommand = request.LegalParty; + + var legalPersonalContractingParty = _context.PersonalContractingParties + .FirstOrDefault(x => x.NationalId == legalCommand.NationalId); + if (!request.LegalParty.IsAuth) + { + if (legalPersonalContractingParty is { IsAuthenticated: false }) + { + legalPersonalContractingParty.UnAuthenticateLegalEdit(legalCommand.FName, legalCommand.LName, + legalCommand.FatherName, legalCommand.IdNumber, legalPersonalContractingParty.IdNumberSeri, + legalPersonalContractingParty.IdNumberSerial, legalCommand.BirthDateFa, legalCommand.Gender, + legalCommand.PhoneNumber); + } + } + + legalPersonalContractingParty?.EditLegalPartyFromInstitution(legalCommand.Position, + legalCommand.CompanyName, + legalCommand.RegisterId, legalCommand.NationalId); + + contractingParty = legalPersonalContractingParty; + break; + case LegalType.Real: + var realCommand = request.RealParty; + var personalContractingParty = _context.PersonalContractingParties + .FirstOrDefault(x => x.Nationalcode == realCommand.NationalCode); + if (!request.RealParty.IsAuth) + { + if (personalContractingParty is { IsAuthenticated: false }) + { + personalContractingParty.UnAuthenticateRealEdit(realCommand.FName, realCommand.LName, + realCommand.FatherName, realCommand.IdNumber, personalContractingParty.IdNumberSeri, + personalContractingParty.IdNumberSerial, realCommand.BirthDateFa, realCommand.Gender, + realCommand.PhoneNumber); + } + + contractingParty = personalContractingParty; + } + + break; + } + + await SaveChangesAsync(); + await transaction.CommitAsync(); + + var creationTemp = await _institutionContractCreationTemp.Find(x => x.Id == request.TempId) + .FirstOrDefaultAsync(); + + if (creationTemp == null) + { + throw new BadRequestException("دیتای درخواست شده نامعتبر است"); + } + + if (contractingParty == null) + { + throw new BadRequestException("طرف قرارداد یافت نشد"); + } + + var employerWorkshopIds = _context.Employers + .Where(x => x.ContractingPartyId == contractingParty.id) + .Include(x => x.WorkshopEmployers) + .SelectMany(x => x.WorkshopEmployers).Select(x => x.WorkshopId).Distinct().ToList(); + + creationTemp.SetContractingPartyContactInfo(request.Address, request.City, request.Province, + request.ContactInfos,request.RepresentativeId); + await _institutionContractCreationTemp.ReplaceOneAsync( + x => x.Id == creationTemp.Id, + creationTemp + ); + + + var workshopsNotInInstitution = employerWorkshopIds.ToList(); + + var workshops = await _context.Workshops + .Where(x => employerWorkshopIds.Contains(x.id)) + .ToListAsync(); + + var notIncludeWorskhopsLeftWork = await _context.LeftWorkList + .Where(x => workshopsNotInInstitution.Contains(x.WorkshopId) && x.StartWorkDate <= DateTime.Now && + x.LeftWorkDate >= DateTime.Now) + .GroupBy(x => x.WorkshopId).ToListAsync(); + + var workshopDetails = workshopsNotInInstitution.Select(x => + { + var workshop = workshops.FirstOrDefault(w => w.id == x); + var leftWorks = notIncludeWorskhopsLeftWork.FirstOrDefault(l => l.Key == x); + return new WorkshopTempViewModel() + { + WorkshopName = workshop?.WorkshopName ?? "فاقد کارگاه", + WorkshopServicesAmount = 0, + WorkshopServicesAmountStr = "0", + WorkshopId = x, + Id = 0, + ContractAndCheckout = false, + ContractAndCheckoutInPerson = false, + CustomizeCheckout = false, + CountPerson = leftWorks?.Count() ?? 0, + Insurance = false, + InsuranceInPerson = false, + RollCall = false, + RollCallInPerson = false, + }; + }).ToList(); + + + var res = new InstitutionContractCreationWorkshopsResponse() + { + TotalAmount = workshopDetails.Sum(x => x.WorkshopServicesAmount).ToMoney(), + WorkshopTemps = workshopDetails + }; + return res; + } + + public async Task GetCreationInstitutionPlan( + InstitutionContractCreationPlanRequest request) + { + if (request.WorkshopTemps.Count == 0) + throw new BadRequestException("هیچ کارگاهی یافت نشد"); + + bool hasInPerson = request.WorkshopTemps.Any(x => x.ContractAndCheckoutInPerson); + double amount = request.TotalAmount.MoneyToDouble(); + + var institutionTemp = + await _institutionContractCreationTemp.Find(x => x.Id == request.TempId).FirstOrDefaultAsync(); + + + var res = new InstitutionContractCreationPlanResponse(); + + + var contractStart = DateTime.Now; + + + if (hasInPerson) + { + res.OneMonth = null; + + res.ThreeMonths = null; + + res.SixMonths = null; + + res.TwelveMonths = + CalculateInstitutionPlan(InstitutionContractDuration.TwelveMonths, amount, true, contractStart); + } + else + { + res.OneMonth = + CalculateInstitutionPlan(InstitutionContractDuration.OneMonth, amount, false, contractStart); + + res.ThreeMonths = + CalculateInstitutionPlan(InstitutionContractDuration.ThreeMonths, amount, false, contractStart); + + res.SixMonths = + CalculateInstitutionPlan(InstitutionContractDuration.SixMonths, amount, false, contractStart); + + res.TwelveMonths = CalculateInstitutionPlan(InstitutionContractDuration.TwelveMonths, amount, false, + contractStart); + } + + var workshops = request.WorkshopTemps + .Select(x => new InstitutionContractCreationTempWorkshop(x.WorkshopName, x.CountPerson, + x.ContractAndCheckout, x.ContractAndCheckoutInPerson, + x.Insurance, x.InsuranceInPerson, x.RollCall, x.RollCall, + x.RollCallInPerson, x.WorkshopServicesAmount, x.WorkshopId)).ToList(); + + institutionTemp.SetWorkshopsAndPlanAmounts(workshops, res.OneMonth, res.ThreeMonths, res.SixMonths, + res.TwelveMonths, hasInPerson); + + await _institutionContractCreationTemp.ReplaceOneAsync(x => x.Id == institutionTemp.Id, institutionTemp); + + return res; + } + + public async Task GetCreationPaymentMethod( + InstitutionContractCreationPaymentRequest request) + { + var institutionTemp = await _institutionContractCreationTemp + .Find(x => x.Id == request.TempId).FirstOrDefaultAsync(); + + if (institutionTemp == null) + throw new BadRequestException("اطلاعات وارد شده نامعتبر است"); + + var duration = request.Duration; + + + var selectedPlan = duration switch + { + InstitutionContractDuration.OneMonth => institutionTemp.OneMonth, + InstitutionContractDuration.ThreeMonths => institutionTemp.ThreeMonths, + InstitutionContractDuration.SixMonths => institutionTemp.SixMonths, + InstitutionContractDuration.TwelveMonths => institutionTemp.TwelveMonths, + _ => throw new ArgumentOutOfRangeException() + }; + + var baseAmount = selectedPlan.TotalPayment.MoneyToDouble(); + var vatOrDiscount = baseAmount * 0.10; + + var calculation = institutionTemp.HasContractInPerson + ? CalculateInPersonPayment((InstitutionContractExtensionPlanDetail)selectedPlan, baseAmount, vatOrDiscount, + request.Duration) + : CalculateOnlinePayment(baseAmount, vatOrDiscount); + + institutionTemp.SetAmountAndDuration(duration, calculation.Monthly, calculation.OneTime); + + await _institutionContractCreationTemp.ReplaceOneAsync(x => x.Id == institutionTemp.Id, institutionTemp); + + var res = new InstitutionContractCreationPaymentResponse() + { + Monthly = calculation.Monthly, + OneTime = calculation.OneTime + }; + return res; + } + + public async Task SetDiscountForCreation( + InstitutionContractSetDiscountForCreationRequest request) + { + if (request.DiscountPercentage <= 0) + throw new BadRequestException("مقدار تخفیف نمی‌تواند برابر یا کمتر از صفر باشد"); + if (request.DiscountPercentage >= 100) + { + throw new BadRequestException("مقدار تخفیف نمی‌تواند برابر یا بیشتر از صد باشد"); + } + + var institutionTemp = await _institutionContractCreationTemp.Find(x => x.Id == request.TempId) + .FirstOrDefaultAsync(); + if (institutionTemp == null) + { + throw new BadRequestException("اطلاعات وارد شده نامعتبر است"); + } + + if (request.IsInstallment) + { + if (institutionTemp.MonthlyPayment.DiscountPercetage > 0) + throw new BadRequestException("تخفیف قبلا برای این قرارداد اعمال شده است"); + } + else + { + if (institutionTemp.OneTimePayment.DiscountPercetage > 0) + throw new BadRequestException("تخفیف قبلا برای این قرارداد اعمال شده است"); + } + + var selectedPlan = institutionTemp.Duration switch + { + InstitutionContractDuration.OneMonth => institutionTemp.OneMonth, + InstitutionContractDuration.ThreeMonths => institutionTemp.ThreeMonths, + InstitutionContractDuration.SixMonths => institutionTemp.SixMonths, + InstitutionContractDuration.TwelveMonths => institutionTemp.TwelveMonths, + _ => throw new ArgumentOutOfRangeException() + }; + var calculateRequest = new InstitutionContractSetDiscountRequest() + { + Duration = institutionTemp.Duration.Value, + TotalAmount = request.TotalAmount, + DiscountPercentage = request.DiscountPercentage, + IsInstallment = request.IsInstallment, + OneMonthAmount = selectedPlan.OneMonthPaymentDiscounted.MoneyToDouble() + }; + var res = CalculateDiscount(calculateRequest, selectedPlan.ContractStart); + + //این به این دلیل هست که متد caclulate discount یکی از مقادیر رو پر میکنه و ما نیاز داریم هر دو مقدار رو داشته باشیم + if (request.IsInstallment) + { + var onetime = institutionTemp.OneTimePayment; + onetime.TotalAmountWithoutDiscount = onetime.TotalAmount; + + onetime.OneMonthPaymentWithoutDiscount = selectedPlan.OneMonthPaymentDiscounted; + institutionTemp.OneTimePayment.TotalAmountWithoutDiscount = onetime.TotalAmount; + institutionTemp.OneTimePayment.OneMonthPaymentWithoutDiscount = selectedPlan.OneMonthPaymentDiscounted; + + res.OneTime = new() + { + PaymentAmount = onetime.PaymentAmount, + Tax = onetime.Tax, + TotalAmount = onetime.TotalAmount, + DiscountedAmount = onetime.DiscountedAmount, + DiscountPercetage = onetime.DiscountPercetage, + }; + + + institutionTemp.MonthlyPayment = new() + { + Installments = res.Monthly.Installments, + PaymentAmount = res.Monthly.PaymentAmount, + Tax = res.Monthly.Tax, + TotalAmount = res.Monthly.TotalAmount, + DiscountedAmount = res.Monthly.DiscountedAmount, + DiscountPercetage = res.Monthly.DiscountPercetage, + TotalAmountWithoutDiscount = institutionTemp.MonthlyPayment.TotalAmount, + OneMonthPaymentWithoutDiscount = selectedPlan.OneMonthPaymentDiscounted, + }; + + selectedPlan.TotalPayment = res.Monthly.TotalAmount; + selectedPlan.Obligation = res.Monthly.Obligation; + selectedPlan.OneMonthPaymentDiscounted = res.Monthly.OneMonthAmount; + selectedPlan.DailyCompenseation = (res.Monthly.OneMonthAmount.MoneyToDouble() * 0.10).ToMoney(); + } + else + { + var monthly = institutionTemp.MonthlyPayment; + + institutionTemp.MonthlyPayment.TotalAmountWithoutDiscount = monthly.TotalAmount; + + res.Monthly = new() + { + PaymentAmount = monthly.PaymentAmount, + Tax = monthly.Tax, + TotalAmount = monthly.TotalAmount, + DiscountedAmount = monthly.DiscountedAmount, + DiscountPercetage = monthly.DiscountPercetage, + Installments = monthly.Installments, + }; + + + institutionTemp.OneTimePayment = new() + { + PaymentAmount = res.OneTime.PaymentAmount, + Tax = res.OneTime.Tax, + TotalAmount = res.OneTime.TotalAmount, + DiscountedAmount = res.OneTime.DiscountedAmount, + DiscountPercetage = res.OneTime.DiscountPercetage, + TotalAmountWithoutDiscount = institutionTemp.OneTimePayment.TotalAmount, + OneMonthPaymentWithoutDiscount = selectedPlan.OneMonthPaymentDiscounted, + }; + selectedPlan.TotalPayment = res.OneTime.TotalAmount; + selectedPlan.Obligation = res.OneTime.Obligation; + selectedPlan.OneMonthPaymentDiscounted = res.OneTime.OneMonthAmount; + selectedPlan.DailyCompenseation = (res.OneTime.OneMonthAmount.MoneyToDouble() * 0.10).ToMoney(); + } + + switch (institutionTemp.Duration) + { + case InstitutionContractDuration.OneMonth: + institutionTemp.OneMonth = selectedPlan; + break; + case InstitutionContractDuration.ThreeMonths: + institutionTemp.ThreeMonths = selectedPlan; + break; + case InstitutionContractDuration.SixMonths: + institutionTemp.SixMonths = selectedPlan; + break; + case InstitutionContractDuration.TwelveMonths: + institutionTemp.TwelveMonths = selectedPlan; + break; + default: + throw new ArgumentOutOfRangeException(); + } + + await _institutionContractCreationTemp.ReplaceOneAsync(x => x.Id == institutionTemp.Id, + institutionTemp); + + return new() + { + OneTime = res.OneTime, + Monthly = res.Monthly + }; + } + + public async Task ResetDiscountForCreation( + InstitutionContractResetDiscountForExtensionRequest request) + { + var institutionTemp = await _institutionContractCreationTemp.Find(x => x.Id == request.TempId) + .FirstOrDefaultAsync(); + if (institutionTemp == null) + { + throw new BadRequestException("اطلاعات وارد شده نامعتبر است"); + } + + InstitutionContractDiscountMonthlyViewModel monthlyPayment = null; + InstitutionContractDiscountOneTimeViewModel oneTimePayment = null; + var selectedPlan = institutionTemp.Duration switch + { + InstitutionContractDuration.OneMonth => institutionTemp.OneMonth, + InstitutionContractDuration.ThreeMonths => institutionTemp.ThreeMonths, + InstitutionContractDuration.SixMonths => institutionTemp.SixMonths, + InstitutionContractDuration.TwelveMonths => institutionTemp.TwelveMonths, + _ => throw new ArgumentOutOfRangeException() + }; + if (request.IsInstallment) + { + var prevMonthlyPayment = institutionTemp.MonthlyPayment; + var resetTotalAmount = prevMonthlyPayment.TotalAmountWithoutDiscount.MoneyToDouble(); + var resetTax = (resetTotalAmount * 0.10); + var paymentAmount = (resetTotalAmount + resetTax); + var newOneMonthAmount = prevMonthlyPayment.OneMonthPaymentWithoutDiscount.MoneyToDouble(); + monthlyPayment = new InstitutionContractDiscountMonthlyViewModel() + { + DiscountPercetage = 0, + DiscountedAmount = "0", + PaymentAmount = paymentAmount.ToMoney(), + Tax = resetTax.ToMoney(), + TotalAmount = resetTotalAmount.ToMoney(), + Installments = InstitutionMonthlyInstallmentCaculation((int)institutionTemp.Duration.Value, + paymentAmount, selectedPlan.ContractStart), + OneMonthAmount = newOneMonthAmount.ToMoney(), + Obligation = resetTotalAmount.ToMoney() + }; + institutionTemp.MonthlyPayment = new InstitutionContractPaymentMonthlyViewModel() + { + Installments = monthlyPayment.Installments, + PaymentAmount = monthlyPayment.PaymentAmount, + Tax = monthlyPayment.Tax, + TotalAmount = monthlyPayment.TotalAmount, + DiscountedAmount = monthlyPayment.DiscountedAmount, + DiscountPercetage = monthlyPayment.DiscountPercetage, + }; + selectedPlan.TotalPayment = monthlyPayment.TotalAmount; + selectedPlan.Obligation = monthlyPayment.Obligation; + selectedPlan.OneMonthPaymentDiscounted = monthlyPayment.OneMonthAmount; + selectedPlan.DailyCompenseation = (monthlyPayment.OneMonthAmount.MoneyToDouble() * 0.10).ToMoney(); + + switch (institutionTemp.Duration) + { + case InstitutionContractDuration.OneMonth: + institutionTemp.OneMonth = selectedPlan; + break; + case InstitutionContractDuration.ThreeMonths: + institutionTemp.ThreeMonths = selectedPlan; + break; + case InstitutionContractDuration.SixMonths: + institutionTemp.SixMonths = selectedPlan; + break; + case InstitutionContractDuration.TwelveMonths: + institutionTemp.TwelveMonths = selectedPlan; + break; + default: + throw new ArgumentOutOfRangeException(); + } + + await _institutionContractCreationTemp.ReplaceOneAsync(x => x.Id == institutionTemp.Id, + institutionTemp); + } + else + { + var prevOneTimePayment = institutionTemp.OneTimePayment; + var resetTotalAmount = prevOneTimePayment.TotalAmountWithoutDiscount.MoneyToDouble(); + var resetTax = (resetTotalAmount * 0.10); + var newOneMonthAmount = prevOneTimePayment.OneMonthPaymentWithoutDiscount.MoneyToDouble(); + + oneTimePayment = new InstitutionContractDiscountOneTimeViewModel() + { + DiscountPercetage = 0, + DiscountedAmount = "0", + TotalAmount = resetTotalAmount.ToMoney(), + Tax = resetTax.ToMoney(), + PaymentAmount = (resetTotalAmount + resetTax).ToMoney(), + OneMonthAmount = newOneMonthAmount.ToMoney(), + Obligation = resetTotalAmount.ToMoney() + }; + institutionTemp.OneTimePayment = new InstitutionContractPaymentOneTimeViewModel() + { + PaymentAmount = oneTimePayment.PaymentAmount, + Tax = oneTimePayment.Tax, + TotalAmount = oneTimePayment.TotalAmount, + DiscountedAmount = oneTimePayment.DiscountedAmount, + DiscountPercetage = oneTimePayment.DiscountPercetage, + TotalAmountWithoutDiscount = institutionTemp.OneTimePayment.TotalAmount, + OneMonthPaymentWithoutDiscount = institutionTemp.OneTimePayment.OneMonthPaymentWithoutDiscount + }; + selectedPlan.TotalPayment = institutionTemp.HasContractInPerson + ? (oneTimePayment.TotalAmount.MoneyToDouble() / (0.9)).ToMoney() + : oneTimePayment.TotalAmount; + selectedPlan.Obligation = oneTimePayment.Obligation; + selectedPlan.OneMonthPaymentDiscounted = oneTimePayment.OneMonthAmount; + selectedPlan.DailyCompenseation = (oneTimePayment.OneMonthAmount.MoneyToDouble() * 0.10).ToMoney(); + + switch (institutionTemp.Duration) + { + case InstitutionContractDuration.OneMonth: + institutionTemp.OneMonth = selectedPlan; + break; + case InstitutionContractDuration.ThreeMonths: + institutionTemp.ThreeMonths = selectedPlan; + break; + case InstitutionContractDuration.SixMonths: + institutionTemp.SixMonths = selectedPlan; + break; + case InstitutionContractDuration.TwelveMonths: + institutionTemp.TwelveMonths = selectedPlan; + break; + default: + throw new ArgumentOutOfRangeException(); + } + + await _institutionContractCreationTemp.ReplaceOneAsync(x => x.Id == institutionTemp.Id, + institutionTemp); + } + + return new InstitutionContractDiscountResponse() + { + OneTime = oneTimePayment, + Monthly = monthlyPayment + }; + } + + + public async Task CreationComplete(InstitutionContractExtensionCompleteRequest request) + { + var institutionContractTemp = await _institutionContractCreationTemp.Find(x => x.Id == request.TemporaryId) + .FirstOrDefaultAsync(); + + if (institutionContractTemp == null) + throw new BadRequestException("اطلاعات وارد شده نامعتبر است"); + + var selectedDuration = institutionContractTemp.Duration switch + { + InstitutionContractDuration.OneMonth => institutionContractTemp.OneMonth, + InstitutionContractDuration.ThreeMonths => institutionContractTemp.ThreeMonths, + InstitutionContractDuration.SixMonths => institutionContractTemp.SixMonths, + InstitutionContractDuration.TwelveMonths => institutionContractTemp.TwelveMonths, + _ => throw new ArgumentOutOfRangeException() + }; + + var contractingPartyId = institutionContractTemp.ContractingPartyLegalType == LegalType.Real + ? institutionContractTemp.RealParty.Id + : institutionContractTemp.LegalParty.Id; + PersonalContractingParty contractingParty; + if (contractingPartyId > 0) + { + contractingParty = await _context.PersonalContractingParties + .FirstOrDefaultAsync(x => x.id == contractingPartyId); + } + else + { + OperationResult contractingPartyResult = institutionContractTemp.ContractingPartyLegalType switch + { + LegalType.Legal => await CreateLegalContractingPartyEntity(institutionContractTemp.LegalParty, institutionContractTemp.RepresentativeId, + institutionContractTemp.Address, + institutionContractTemp.City, institutionContractTemp.Province), + LegalType.Real => await CreateRealContractingPartyEntity(institutionContractTemp.RealParty, institutionContractTemp.RepresentativeId, + institutionContractTemp.Address, + institutionContractTemp.City, institutionContractTemp.Province), + _ => throw new BadRequestException("نوع طرف قرارداد مشخص نشده است") + }; + if (!contractingPartyResult.IsSuccedded) + throw new BadRequestException(contractingPartyResult.Message); + contractingParty = contractingPartyResult.Data; + } + + + //این به این خواطر هست که قبل از این آیدی برای این بوده که بفهمیم طرف حساب وجود داره یا نه ولی الان که مطمئن هستیم که وجود داره ماهیت این آیدی فرق کرده + contractingPartyId = contractingParty.id; + + var payment = request.IsInstallment + ? institutionContractTemp.MonthlyPayment + : institutionContractTemp.OneTimePayment; + + bool dateMessages = false; + string dateMaessageResult = String.Empty; + var opration = new OperationResult(); + + var contractStart = selectedDuration.ContractStart; + + var representative = _representativeRepository.Get(institutionContractTemp.RepresentativeId); + if (representative == null) + return opration.Failed("معرف مورد نظر یافت نشد"); + + if (_context.InstitutionContractSet.Any(x => + x.ContractingPartyId == contractingPartyId && x.IsActiveString == "true")) + return opration.Failed("برای این طرف قرارداد قبلا قرارداد اصلی ایجاد شده است، شما میتوانید از تمدید استفاده کنید"); + + + if (string.IsNullOrWhiteSpace(contractStart)) + { + dateMaessageResult = "تاریخ قراراداد اجباری است. "; + dateMessages = true; + } + + if (string.IsNullOrWhiteSpace(contractStart)) + { + dateMaessageResult += "تاریخ شروع قراراداد اجباری است. "; + dateMessages = true; + } + + if (string.IsNullOrWhiteSpace(selectedDuration.ContractEnd)) + { + dateMaessageResult += "تاریخ پایان قراراداد اجباری است. "; + dateMessages = true; + } + + if (dateMessages) + return opration.Failed(dateMaessageResult); + + + var syear = contractStart.Substring(0, 4); + var smonth = contractStart.Substring(5, 2); + var sday = contractStart.Substring(8, 2); + //شماره قرارداد + var contractNo = $"{syear}{smonth}{sday}/{contractingParty.ArchiveCode}/0"; + + + var contractStartGr = contractStart.ToGeorgianDateTime(); + var contractEndGr = selectedDuration.ContractEnd.ToGeorgianDateTime(); + + var contractDateGr = contractStart.ToGeorgianDateTime(); + + + if (institutionContractTemp.Address != null && institutionContractTemp.Province == null) + { + return opration.Failed("لطفا استان و شهر را انتخاب کنید"); + } + + if ((institutionContractTemp.Address != null && institutionContractTemp.Province != null) && + institutionContractTemp.City == "شهرستان") + { + return opration.Failed("لطفا شهر را انتخاب کنید"); + } + + if (institutionContractTemp.Address == null && institutionContractTemp.Province != null) + { + return opration.Failed("لطفا آدرس را وارد کنید"); + } + + var hasValueAddedTax = payment.Tax.MoneyToDouble() > 0 ? "true" : "false"; + + var workshopsCount = institutionContractTemp.Workshops.Count.ToString(); + + var workshopDetails = institutionContractTemp + .Workshops.Select(x => + { + var res = new InstitutionContractWorkshopInitial(x.WorkshopName, x.RollCall, x.RollCallInPerson, + x.CustomizeCheckout, + x.ContractAndCheckout, + x.ContractAndCheckoutInPerson, x.Insurance, x.InsuranceInPerson, x.CountPerson, x.Price); + if (x.WorkshopId != 0) + { + res.SetWorkshopId(x.WorkshopId); + } + + return res; + }).ToList(); + + var employeeCount = institutionContractTemp.Workshops.Sum(x => x.CountPerson).ToString(); + + var oneMonthPayment = selectedDuration.OneMonthPaymentDiscounted.MoneyToDouble(); + + + var contractingPartyFullName = contractingParty.IsLegal=="حقیقی" + ? contractingParty.FName + " " + contractingParty.LName + : contractingParty.LName; + + var totalAmount = payment.PaymentAmount.MoneyToDouble(); + + + var transaction = await _context.Database.BeginTransactionAsync(); + + var entity = new InstitutionContract(contractNo, representative.id, + representative.FullName, + contractingPartyId, + contractingPartyFullName, contractDateGr, contractStart, + institutionContractTemp.Province, institutionContractTemp.City, + institutionContractTemp.Address, contractStartGr, + contractStart, contractEndGr, selectedDuration.ContractEnd, + oneMonthPayment, selectedDuration.DailyCompenseation.MoneyToDouble(), + selectedDuration.Obligation.MoneyToDouble(), totalAmount, + 0, workshopsCount, employeeCount,null, + "NotOfficial", "JobRelation", hasValueAddedTax, + payment.Tax.MoneyToDouble(), [], + request.LawId, payment.DiscountPercetage, payment.DiscountedAmount.MoneyToDouble()); + + await CreateAsync(entity); + await SaveChangesAsync(); + foreach (var workshop in institutionContractTemp.Workshops) + { + var workshopDetail = new InstitutionContractWorkshopInitial( + workshop.WorkshopName, workshop.RollCall, workshop.RollCallInPerson, + workshop.CustomizeCheckout, workshop.ContractAndCheckout, + workshop.ContractAndCheckoutInPerson, workshop.Insurance, + workshop.InsuranceInPerson, workshop.CountPerson, workshop.Price); + + workshopDetail.SetWorkshopGroup(entity.WorkshopGroup); + + if (workshop.WorkshopId != 0) + { + workshopDetail.SetWorkshopId(workshop.WorkshopId); + } + // Set parent reference + + // Add to the parent's collection + entity.WorkshopGroup.InitialWorkshops.Add(workshopDetail); + } + + // Save the changes again + await SaveChangesAsync(); + + + FinancialStatment financialStatement; + if (_context.FinancialStatments.Any(x => x.ContractingPartyId == contractingParty.id)) + { + financialStatement = + await _context.FinancialStatments.FirstOrDefaultAsync(x => x.ContractingPartyId == contractingParty.id); + } + else + { + financialStatement = new FinancialStatment(contractingParty.id, contractingPartyFullName); + await _context.AddAsync(financialStatement); + } + + + if (request.IsInstallment && payment is InstitutionContractPaymentMonthlyViewModel monthly) + { + var installments = monthly.Installments.Select(x => + new InstitutionContractInstallment(x.InstalmentDate.ToGeorgianDateTime(), + x.InstallmentAmountStr.MoneyToDouble(), "")).ToList(); + + // دریافت مبلغ اولین قسط + //این کار برای این هست که اولین قسط باید با تاریخ امروز باشد و باید به وضعیت مالی بدهی ایجاد شود که یوزر اولین بدهی را وارد کند + var firstInstallmentAmount = installments.First().Amount; + + // حذف اولین قسط + installments.RemoveAt(0); + + // ایجاد قسط جدید با تاریخ امروز + var todayInstallment = new InstitutionContractInstallment(DateTime.Today, firstInstallmentAmount, ""); + + + // اضافه کردن قسط جدید به ابتدای لیست + installments.Insert(0, todayInstallment); + + entity.SetInstallments(installments); + await SaveChangesAsync(); + } + + foreach (var contactInfo in institutionContractTemp.ContactInfos) + { + if (contactInfo.PhoneNumber != null) + { + var contactinfo = new InstitutionContractContactInfo(contactInfo.PhoneType, + contactInfo.Position, contactInfo.PhoneNumber, contactInfo.FnameLname, entity.id, + contactInfo.SendSmsString == "true"); + + _context.InstitutionContractContactInfos.Add(contactinfo); + } + } + var userPass = contractingParty.IsLegal == "حقیقی" + ? contractingParty.Nationalcode + : contractingParty.NationalId; + var createAcc = new RegisterAccount + { + Fullname = contractingParty.LName, + Username = userPass, + Password = userPass, + Mobile = contractingParty.Phone, + NationalCode = userPass + }; + var res = _accountApplication.RegisterClient(createAcc); + if (res.IsSuccedded) + CreateContractingPartyAccount(contractingParty.id, res.SendId); + + await SaveChangesAsync(); + + await _smsService.SendInstitutionCreationVerificationLink(contractingParty.Phone, contractingPartyFullName, + entity.PublicId, contractingParty.id, entity.id); + + + await SaveChangesAsync(); + await transaction.CommitAsync(); + return opration.Succcedded(); + } + + private async Task> CreateLegalContractingPartyEntity( + InstitutionContractCreationTempLegalParty request, long representativeId, string address, string city, + string state) + { + var opration = new OperationResult(); + + + if (representativeId < 1) + return opration.Failed("لطفا معرف را انتخاب کنید"); + + if (_contractingPartyRepository.Exists(x => + x.LName == request.CompanyName && x.NationalId == request.NationalId)) + return opration.Failed("نام شرکت وارد شده تکراری است"); + + + //if (_contractingPartyRepository.Exists(x => + // x.RegisterId == request.RegisterId && x.LName != request.CompanyName)) + // return opration.Failed("شماره ثبت وارد شده تکراری است"); + + + if (_contractingPartyRepository.Exists(x => + x.NationalId == request.NationalId && x.LName != request.CompanyName)) + { + return opration.Failed("شناسه ملی وارد شده تکراری است"); + } + + var archiveCode = _contractingPartyRepository.GetLastNewArchiveCode(); + + + var representative = _representativeRepository.GetDetails(representativeId); + var legalContractingParty = new PersonalContractingParty("*", request.CompanyName, + "*", "*", request.RegisterId, request.NationalId, + "حقوقی", + request.PhoneNumber, request.PhoneNumber, address, representativeId, representative.FullName, + archiveCode, state, city, null, null, + request.FName, request.LName, request.Position); + + if (request.IsAuth) + { + legalContractingParty.LegalAuthentication(request.FName, request.LName, request.FatherName, + request.IdNumber, null, null, request.BirthDateFa, request.Gender, request.PhoneNumber); + } + + await _contractingPartyRepository.CreateAsync(legalContractingParty); + await _contractingPartyRepository.SaveChangesAsync(); + + return opration.Succcedded(legalContractingParty); + } + + private async Task> CreateRealContractingPartyEntity( + InstitutionContractCreationTempRealParty request, long representativeId, string address, + string city, string province) + { + var operation = new OperationResult(); + + + if (representativeId < 1) + return operation.Failed("لطفا معرف را انتخاب کنید"); + + if (_contractingPartyRepository.Exists(x => x.Nationalcode == request.NationalCode)) + { + return operation.Failed("کد ملی وارد شده تکراری است"); + } + + var archiveCode = _contractingPartyRepository.GetLastNewArchiveCode(); + + if (request.NationalCode.NationalCodeValid() != "valid") + { + return operation.Failed("کد ملی وارد شده نا معتبر است"); + } + + var representative = _representativeRepository.GetDetails(representativeId); + + if (representative == null) + return operation.Failed("معرف مورد نظر یافت نشد"); + + var personalContractingParty = new PersonalContractingParty(request.FName, request.LName, + request.NationalCode, request.IdNumber, "*", "*", + "حقیقی", + request.PhoneNumber, request.PhoneNumber, address, representativeId, representative.FullName, archiveCode, + province, city, null, null, null, null); + + if (request.IsAuth) + { + personalContractingParty.Authentication(request.FName, request.LName, request.FatherName, + request.IdNumber, null, null, request.BirthDateFa, request.Gender, request.PhoneNumber); + } + + await _contractingPartyRepository.CreateAsync(personalContractingParty); + await _contractingPartyRepository.SaveChangesAsync(); + + return operation.Succcedded(personalContractingParty); + } #endregion diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index 0548a2b4..d54893a1 100644 --- a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs +++ b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs @@ -536,45 +536,45 @@ public class institutionContractController : AdminBaseController return res; } - [HttpPost("create/workshops")] - public async Task> CreationWorkshops([FromBody] InstitutionContractCreationWorkshopsRequest request) + [HttpPost("creation/workshops")] + public async Task> CreationWorkshops([FromBody] InstitutionContractCreationWorkshopsRequest request) { var res =await _institutionContractApplication.GetCreationWorkshops(request); return res; } - [HttpPost("extenstion/institution-plan")] - public async Task> ExtensionInstitutionPlan([FromBody]InstitutionContractExtensionPlanRequest request) + [HttpPost("creation/institution-plan")] + public async Task> CreationInstitutionPlan([FromBody]InstitutionContractCreationPlanRequest request) { - var res =await _institutionContractApplication.GetExtensionInstitutionPlan(request); + var res =await _institutionContractApplication.GetCreationInstitutionPlan(request); return res; } - [HttpPost("extenstion/payment-method")] - public async Task> GetExtensionPaymentMethod([FromBody]InstitutionContractExtensionPaymentRequest request) + [HttpPost("creation/payment-method")] + public async Task> GetCreationPaymentMethod([FromBody]InstitutionContractCreationPaymentRequest request) { - var res =await _institutionContractApplication.GetExtensionPaymentMethod(request); + var res =await _institutionContractApplication.GetCreationPaymentMethod(request); return res; } - [HttpPost("extension/set-discount")] - public async Task> SetDiscountForExtension([FromBody]InstitutionContractSetDiscountForExtensionRequest request) + [HttpPost("creation/set-discount")] + public async Task> SetDiscountForCreation([FromBody]InstitutionContractSetDiscountForCreationRequest request) { - var res =await _institutionContractApplication.SetDiscountForExtension(request); + var res =await _institutionContractApplication.SetDiscountForCreation(request); return res; } - [HttpPost("extension/reset-discount")] - public async Task> ResetDiscountForExtension([FromBody]InstitutionContractResetDiscountForExtensionRequest request) + [HttpPost("creation/reset-discount")] + public async Task> ResetDiscountForCreation([FromBody]InstitutionContractResetDiscountForExtensionRequest request) { - var res =await _institutionContractApplication.ResetDiscountForExtension(request); + var res =await _institutionContractApplication.ResetDiscountForCreation(request); return res; } - [HttpPost("extenstion/complete")] - public async Task> ExtensionComplete([FromBody]InstitutionContractExtensionCompleteRequest request) + [HttpPost("creation/complete")] + public async Task> CreationComplete([FromBody]InstitutionContractExtensionCompleteRequest request) { - var res =await _institutionContractApplication.ExtensionComplete(request); + var res =await _institutionContractApplication.CreationComplete(request); return res; }