From efbd74479bc201e80f161cbde5c88a2821cb3642 Mon Sep 17 00:00:00 2001 From: MahanCh Date: Wed, 6 Aug 2025 14:23:21 +0330 Subject: [PATCH] fix error --- .../CreateInstitutionContractRequest.cs | 1 + .../InstitutionContractApplication.cs | 114 ++++++++++++++++++ ServiceHost/appsettings.Development.json | 2 +- 3 files changed, 116 insertions(+), 1 deletion(-) diff --git a/CompanyManagment.App.Contracts/InstitutionContract/CreateInstitutionContractRequest.cs b/CompanyManagment.App.Contracts/InstitutionContract/CreateInstitutionContractRequest.cs index 3ad9f0b0..0707a07d 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/CreateInstitutionContractRequest.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/CreateInstitutionContractRequest.cs @@ -25,4 +25,5 @@ public class CreateInstitutionContractRequest public string WorkshopManualCount { get; set; } public string EmployeeManualCount { get; set; } public string Description { get; set; } + public int ExtensionNo { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index 2962cfc1..3e044a96 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -1133,6 +1133,120 @@ public class InstitutionContractApplication : IInstitutionContractApplication await _institutionContractRepository.SaveChangesAsync(); return opration.Succcedded(command.Id); } + + public async Task ExtensionَAsync(CreateInstitutionContractRequest command) + { + bool dateMessages = false; + string dateMaessageResult = String.Empty; + var opration = new OperationResult(); + + command.ExtensionNo += 1; + if (_institutionContractRepository.Exists(x => + x.ExtensionNo == command.ExtensionNo && x.ContractingPartyId == command.ContractingPartyId && + x.TypeOfContract == command.TypeOfContract)) + return opration.Failed("برای این قرارداد قبلا تمدید ایجاد شده است"); + + + if (string.IsNullOrWhiteSpace(command.ContractDateFa)) + { + dateMaessageResult = "تاریخ قراراداد اجباری است. "; + dateMessages = true; + } + + if (string.IsNullOrWhiteSpace(command.ContractStartFa)) + { + dateMaessageResult += "تاریخ شروع قراراداد اجباری است. "; + dateMessages = true; + } + + if (string.IsNullOrWhiteSpace(command.ContractEndFa)) + { + dateMaessageResult += "تاریخ پایان قراراداد اجباری است. "; + dateMessages = true; + } + + if (dateMessages) + return opration.Failed(dateMaessageResult); + + var firstContract = + _institutionContractRepository.GetFirstContract(command.ContractingPartyId, command.TypeOfContract); + + var syear = firstContract.ContractStartFa.Substring(0, 4); + var smonth = firstContract.ContractStartFa.Substring(5, 2); + var sday = firstContract.ContractStartFa.Substring(8, 2); + var contractingParty = _contractingPartyRepository.GetDetails(command.ContractingPartyId); + //شماره قرارداد + var contractNo = $"{syear}{smonth}{sday}/{contractingParty.ArchiveCode}/{command.ExtensionNo}"; + + + var contractStartGr = command.ContractStartFa.ToGeorgianDateTime(); + var contractEndGr = command.ContractEndFa.ToGeorgianDateTime(); + + var contractDateGr = command.ContractDateFa.ToGeorgianDateTime(); + if (_institutionContractRepository.Exists(x => + ((contractStartGr >= x.ContractStartGr && contractStartGr <= x.ContractEndGr) || + (contractEndGr >= x.ContractStartGr && contractEndGr <= x.ContractEndGr)) && + x.TypeOfContract == command.TypeOfContract && x.ContractingPartyId == command.ContractingPartyId)) + return opration.Failed("تاریخ شروع و پایان وارد شده با قرارداد دیگری تداخل دارد"); + if (command.Address != null && command.State == null) + { + return opration.Failed("لطفا استان و شهر را انتخاب کنید"); + } + + if ((command.Address != null && command.State != null) && command.City == "شهرستان") + { + return opration.Failed("لطفا شهر را انتخاب کنید"); + } + + if (command.Address == null && command.State != null) + { + return opration.Failed("لطفا آدرس را وارد کنید"); + } + + if (string.IsNullOrWhiteSpace(command.OfficialCompany)) + return opration.Failed("رسمی یا غیر رسمی بودن پرداخت را مشخص کنید"); + if (command.OfficialCompany == "Official" && string.IsNullOrWhiteSpace(command.HasValueAddedTax)) + return opration.Failed("وضعیت ارزش افزوده را مشخص کنید"); + if (string.IsNullOrWhiteSpace(command.TypeOfContract)) + return opration.Failed("عنوان قرارداد را انتخاب کنید"); + if (string.IsNullOrWhiteSpace(command.ContractAmountString)) + command.ContractAmountString = "0"; + if (string.IsNullOrWhiteSpace(command.DailyCompenseationString)) + command.DailyCompenseationString = "0"; + if (string.IsNullOrWhiteSpace(command.ObligationString)) + command.ObligationString = "0"; + if (string.IsNullOrWhiteSpace(command.TotalAmountString)) + command.TotalAmountString = "0"; + var valueAddedTax = string.IsNullOrWhiteSpace(command.ValueAddedTaxStr) + ? 0 + : command.ValueAddedTaxStr.MoneyToDouble(); + var contractAmountStr = command.ContractAmountString.ToDoubleMoney(); + var contractAmount = Convert.ToDouble(contractAmountStr); + var DailyCompenseationStr = command.DailyCompenseationString.ToDoubleMoney(); + var dailyCompenseation = Convert.ToDouble(DailyCompenseationStr); + var ObligationStr = command.ObligationString.ToDoubleMoney(); + var obligation = Convert.ToDouble(ObligationStr); + var TotalAmountStr = command.TotalAmountString.ToDoubleMoney(); + var totalAmount = Convert.ToDouble(TotalAmountStr); + var contractingPartyName = contractingParty.LName; + var representative = _representativeRepository.GetDetails(command.RepresentativeId).FullName; + + var createContract = new InstitutionContract(contractNo, command.RepresentativeId, representative, + command.ContractingPartyId, + contractingPartyName, contractDateGr, command.ContractDateFa, command.State, command.City, + command.Address, contractStartGr, + command.ContractStartFa, contractEndGr, command.ContractEndFa, contractAmount, + dailyCompenseation, obligation, + totalAmount, command.ExtensionNo, command.WorkshopManualCount, command.EmployeeManualCount, + command.Description, command.OfficialCompany, command.TypeOfContract, command.HasValueAddedTax, + valueAddedTax); + + _institutionContractRepository.Create(createContract); + _institutionContractRepository.SaveChanges(); + + + return opration.Succcedded(createContract.id); + } } #region CustomViewModels diff --git a/ServiceHost/appsettings.Development.json b/ServiceHost/appsettings.Development.json index b426d7d0..decb7c62 100644 --- a/ServiceHost/appsettings.Development.json +++ b/ServiceHost/appsettings.Development.json @@ -12,7 +12,7 @@ //"MesbahDb": "Data Source=DESKTOP-NUE119G\\MSNEW;Initial Catalog=Mesbah_db;Integrated Security=True" //server - //"MesbahDb": "Data Source=171.22.24.15;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]18[3019]#@ATt;TrustServerCertificate=true;", + "MesbahDbServer": "Data Source=171.22.24.15;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]18[3019]#@ATt;TrustServerCertificate=true;", //local