From f92257b251749ed0e9e76ba2c6bff2c79918a0f2 Mon Sep 17 00:00:00 2001 From: MahanCh Date: Wed, 6 Aug 2025 13:49:11 +0330 Subject: [PATCH 1/2] add order by for Get list --- .../Repository/InstitutionContractRepository.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index 90c1f8a1..2a89c94a 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -1151,7 +1151,21 @@ public class InstitutionContractRepository : RepositoryBase + x.contract.IsActiveString == "blue" ? 0 : // DeactiveWithoutDebt + (x.contract.ContractEndGr >= now && x.contract.ContractEndGr <= endOfMonth) ? 1 : // PendingToRenewal + x.contractingParty.IsBlock == "true" ? 2 : // Block + x.contract.ContractAmount == 0 ? 3 : // Free + !x.contractingParty.Employers + .SelectMany(e => e.WorkshopEmployers) + .Any() ? 4 : // WithoutWorkshop + 5 // Active + ); + + var list = await orderedQuery.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); var res = new PagedResult() { From 547751946457cf2f563d96a2965ef612b9fe621f Mon Sep 17 00:00:00 2001 From: MahanCh Date: Wed, 6 Aug 2025 14:07:12 +0330 Subject: [PATCH 2/2] add extensionAsync in institutionContract for Api --- .../IInstitutionContractApplication.cs | 11 + .../institutionContractController.cs | 269 +++++++++++++++++- 2 files changed, 278 insertions(+), 2 deletions(-) diff --git a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs index d4057f0a..6638dec5 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs @@ -88,6 +88,13 @@ public interface IInstitutionContractApplication /// /// Task EditAsync(EditInstitutionContractRequest command); + /// + /// تمدید قرارداد + /// + /// + /// + Task ExtensionَAsync(CreateInstitutionContractRequest command); + #endregion } @@ -120,3 +127,7 @@ public class InstitutionContractStatusCount public InstitutionContractStatus Status { get; set; } public int Count { get; set; } } +public class ExtenstionInstitutionContractRequest:EditInstitutionContractRequest +{ + public long PreviousContractId { get; set; } +} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index 77df5269..342dbc54 100644 --- a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs +++ b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs @@ -1,10 +1,14 @@ using _0_Framework.Application; using AccountManagement.Application.Contracts.Account; using CompanyManagement.Infrastructure.Excel.InstitutionContract; +using CompanyManagment.App.Contracts.Employer; using CompanyManagment.App.Contracts.InstitutionContract; using CompanyManagment.App.Contracts.InstitutionContractContactinfo; using CompanyManagment.App.Contracts.PersonalContractingParty; +using CompanyManagment.App.Contracts.Representative; +using CompanyManagment.App.Contracts.Workshop; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; using ServiceHost.BaseControllers; namespace ServiceHost.Areas.Admin.Controllers; @@ -18,16 +22,20 @@ public class institutionContractController : AdminBaseController private readonly IPersonalContractingPartyApp _contractingPartyApplication; private readonly IContactInfoApplication _contactInfoApplication; private readonly IAccountApplication _accountApplication; + private readonly IEmployerApplication _employerApplication; + private readonly IWorkshopApplication _workshopApplication; public institutionContractController(IInstitutionContractApplication institutionContractApplication, IPersonalContractingPartyApp contractingPartyApplication, IContactInfoApplication contactInfoApplication, - IAccountApplication accountApplication) + IAccountApplication accountApplication, IEmployerApplication employerApplication, IWorkshopApplication workshopApplication) { _institutionContractApplication = institutionContractApplication; _contractingPartyApplication = contractingPartyApplication; _contactInfoApplication = contactInfoApplication; _accountApplication = accountApplication; + _employerApplication = employerApplication; + _workshopApplication = workshopApplication; } /// @@ -344,6 +352,262 @@ public class institutionContractController : AdminBaseController }); } + public ActionResult OnGetExtension(long id) + { + var todayGr = DateTime.Now; + var todayFa = todayGr.ToFarsi(); + var previusContract = _institutionContractApplication.GetDetails(id); + var previusContractEnd = previusContract.ContractEndGr.AddDays(1); + var startFa = previusContractEnd.ToFarsi(); + var endFa = startFa.FindeEndOfYear(); + + + var representativList = new List(); + var contractingPartyList = new List(); + var res = _institutionContractApplication.GetDetails(id); + var representative = new RepresentativeViewModel + { + Id = res.RepresentativeId, + FullName = res.RepresentativeName + }; + representativList.Add(representative); + var contractingParty = new PersonalContractingPartyViewModel + { + id = res.ContractingPartyId, + FullName = _contractingPartyApplication.GetFullName(res.ContractingPartyId) + }; + contractingPartyList.Add(contractingParty); + res.RepresentativeSelectList = + new SelectList(representativList, "Id", "FullName"); + res.ContractingPartiesSelectList = + new SelectList(contractingPartyList, "id", "FullName"); + + var employer = _employerApplication.GetEmployerByContracrtingPartyID(res.ContractingPartyId); + var emplId = employer.Select(x => x.Id).ToList(); + + var w = _workshopApplication.GetWorkshopsByEmployerId(emplId); + var workshopIds = w.Select(x => x.Id).ToList(); + var workshopCount = Convert.ToString(w.Count); + + var pCount = 0; + if (workshopIds.Count > 0) + { + foreach (var workshopId in workshopIds) + { + var p = _workshopApplication.PersonnelCount(workshopId); + pCount += p; + } + + res.EmployeeCount = Convert.ToString(pCount); + } + else + { + res.EmployeeCount = "0"; + } + + + //var left = _leftWorkApplication.GetLeftPersonelByWorkshopId(workshopIds); + + res.WorkshopCount = workshopCount; + + res.WorkshopManualCount = workshopCount; + res.EmployeeManualCount = res.EmployeeCount; + + res.ContractDateFa = todayFa; + res.ContractStartFa = startFa; + res.ContractEndFa = endFa; + res.ContractAmountString = "0"; + res.DailyCompenseationString = "0"; + res.ObligationString = "0"; + res.TotalAmountString = "0"; + res.PrviousContractId = id; + + + if (!string.IsNullOrWhiteSpace(res.EmployeeManualCount)) + { + var countPerson = Convert.ToInt32(res.EmployeeCount); + var finalAmount = _institutionContractApplication.GetcontractAmount(countPerson); + + var syear = Convert.ToInt32(startFa.Substring(0, 4)); + var smonth = Convert.ToInt32(startFa.Substring(5, 2)); + var sday = Convert.ToInt32(startFa.Substring(8, 2)); + + + var eyear = Convert.ToInt32(endFa.Substring(0, 4)); + var emonth = Convert.ToInt32(endFa.Substring(5, 2)); + var eday = Convert.ToInt32(endFa.Substring(8, 2)); + emonth += 1; + + var def = (eyear - syear) * 12 + emonth - smonth; + + + //رند ماهیانه + //int rightMDigits = (int)(finalAmount % 1000000); + //if (rightMDigits < 500000) + //{ + // finalAmount = (int)(finalAmount / 100000) * 100000; + //} + //else + //{ + // finalAmount = (int)(finalAmount / 100000 + 1) * 100000; + //} + finalAmount = (int)(finalAmount / 1000000) * 1000000; + + double compute = 0; + double tenPercent = 0; + if (res.HasValueAddedTax == "true") + { + tenPercent = finalAmount * 10 / 100; + res.ContractAmountOAlone = finalAmount.ToMoney(); + + //افزودن 10 درصد + finalAmount += tenPercent; + res.ContractAmountString = finalAmount.ToMoney(); + res.ValueAddedTaxStr = tenPercent.ToMoney(); + compute = finalAmount * def; + res.ObligationString = compute.ToMoney(); + res.TotalAmountString = res.ObligationString; + } + else + { + res.ContractAmountOAlone = finalAmount.ToMoney(); + res.ContractAmountString = res.ContractAmountOAlone; + res.ValueAddedTaxStr = "0"; + compute = finalAmount * def; + res.ObligationString = compute.ToMoney(); + res.TotalAmountString = res.ObligationString; + } + + + //رند سالانه + + //int rightYDigits = (int)(compute % 10000000); + //if (rightYDigits < 5000000) + + //compute = (int)(compute / 1000000) * 1000000; + } + + var contactInfo = _contactInfoApplication.GetContactInfolist(id); + if (contactInfo.Count > 0) + { + res.ContactInfoCounter = contactInfo.Count; + res.ContactInformationList = contactInfo; + } + else + { + res.ContactInfoCounter = 0; + } + + + return res; + } + + public async Task> OnPostExtension(ExtenstionInstitutionContractRequest command) + { + var op = new OperationResult(); + + var phoneNumber = command.ContactInfos.FirstOrDefault(x => + x.SendSmsString == "true" && x.Position == "طرف قرارداد" && x.PhoneType == "شماره همراه"); + var conractingParty = _contractingPartyApplication.GetDetails(command.ContractingPartyId); + + if (conractingParty.IsLegal == "حقیقی" && string.IsNullOrWhiteSpace(conractingParty.Nationalcode)) + return new JsonResult(op.Failed("کد ملی طرف حساب وجود ندارد")); + if (conractingParty.IsLegal == "حقوقی" && string.IsNullOrWhiteSpace(conractingParty.NationalId)) + return new JsonResult(op.Failed("شناسه ملی طرف حساب وجود ندارد")); + if(phoneNumber == null) + return new JsonResult(op.Failed("تعیین شماره همراه با سمت طرف قرارداد اجباریست")); + + + var counter = command.ContactInfos.Count; + + var result = await _institutionContractApplication.ExtensionَAsync(command); + + if (result.IsSuccedded && counter > 0) + { + for (var i = 0; i <= counter - 1; i++) + { + if (command.ContactInfos[i].PhoneNumber != null) + { + var contactinfo = new CreateContactInfo + { + InstitutionContractId = result.SendId, + PhoneType = command.ContactInfos[i].PhoneType, + Position = command.ContactInfos[i].Position, + PhoneNumber = command.ContactInfos[i].PhoneNumber, + FnameLname = command.ContactInfos[i].FnameLname, + SendSms = command.ContactInfos[i].SendSmsString == "true" ? true : false + }; + _contactInfoApplication.Create(contactinfo); + } + + Thread.Sleep(500); + } + } + + + if (result.IsSuccedded) + { + _institutionContractApplication.DeActive(command.PreviousContractId); + _institutionContractApplication.ReActiveAllAfterCreateNew(command.ContractingPartyId); + } + var contractingPartyId = _institutionContractApplication.GetDetails(result.SendId); + + var getOldContarct = _institutionContractApplication.NewSearch(new InstitutionContractSearchModel() + { ContractingPartyId = contractingPartyId.ContractingPartyId, IsActiveString = "both" }).Where(x => x.IsActiveString == "false" || x.IsActiveString == "blue").ToList(); + if (result.IsSuccedded && counter > 0) + { + + if (getOldContarct.Count > 0) + { + foreach (var item in getOldContarct) + { + _contactInfoApplication.RemoveContactInfo(item.Id); + foreach (var phone in command.ContactInfos) + { + if (phone.PhoneNumber != null) + { + var contactinfo = new CreateContactInfo + { + InstitutionContractId = item.Id, + PhoneType = phone.PhoneType, + Position = phone.Position, + PhoneNumber = phone.PhoneNumber, + FnameLname = phone.FnameLname, + SendSms = phone.SendSmsString == "true" ? true : false + }; + _contactInfoApplication.Create(contactinfo); + } + + Thread.Sleep(500); + } + } + + //ساخت اکانت کلاینت + var userPass = conractingParty.IsLegal == "حقیقی" + ? conractingParty.Nationalcode + : conractingParty.NationalId; + var checkExistAccount = _accountApplication.CheckExistClientAccount(userPass); + if (!checkExistAccount) + { + + var createAcc = new RegisterAccount + { + Fullname = conractingParty.LName, + Username = userPass, + Password = userPass, + Mobile = phoneNumber.PhoneNumber, + NationalCode = userPass + }; + var res = _accountApplication.RegisterClient(createAcc); + if (res.IsSuccedded) + _institutionContractApplication.CreateContractingPartyAccount(command.ContractingPartyId, res.SendId); + } + } + } + + return result; + } + /// /// دانلود اکسل @@ -359,4 +623,5 @@ public class institutionContractController : AdminBaseController "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"قرارداد های مالی.xlsx"); } -} \ No newline at end of file +} +