diff --git a/Company.Domain/InstitutionPlanAgg/IPlanPercentageRepository.cs b/Company.Domain/InstitutionPlanAgg/IPlanPercentageRepository.cs index b8406a4f..ad2575f3 100644 --- a/Company.Domain/InstitutionPlanAgg/IPlanPercentageRepository.cs +++ b/Company.Domain/InstitutionPlanAgg/IPlanPercentageRepository.cs @@ -2,6 +2,7 @@ using CompanyManagment.App.Contracts.InstitutionPlan; using CompanyManagment.App.Contracts.TemporaryClientRegistration; using System.Collections.Generic; +using System.Threading.Tasks; namespace Company.Domain.InstitutionPlanAgg; @@ -26,4 +27,10 @@ public interface IPlanPercentageRepository : IRepository /// /// InstitutionPlanViewModel GetInstitutionPlanForWorkshop(WorkshopTempViewModel command); + + /// + /// دریافت دیتای مودال ایجاد + /// + /// + Task GetCreateModalData(); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionPlan/CreateServiceAmountDto.cs b/CompanyManagment.App.Contracts/InstitutionPlan/CreateServiceAmountDto.cs new file mode 100644 index 00000000..6800b2f5 --- /dev/null +++ b/CompanyManagment.App.Contracts/InstitutionPlan/CreateServiceAmountDto.cs @@ -0,0 +1,51 @@ +namespace CompanyManagment.App.Contracts.InstitutionPlan; + +public class CreateServiceAmountDto +{ + /// + /// آی دی + /// + public long Id { get; set; } + + /// + /// قرارداد و تصفیه + /// درصد از مزد روزانه + /// string + /// + public string ContractAndCheckoutPercentStr { get; set; } + + /// + /// بیمه + /// درصد از مزد روزانه + /// string + /// + public string InsurancePercentStr { get; set; } + + /// + /// حضورغباب + /// درصد از مزد روزانه + /// string + /// + public string RollCallPercentStr { get; set; } + + /// + /// فیش غیر رسمی + /// درصد از مزد روزانه + /// string + /// + public string CustomizeCheckoutPercentStr { get; set; } + + /// + /// خدمات حضوری قرداد و تصفیه + /// درصد از مزد روزانه + /// string + /// + public string ContractAndCheckoutInPersonPercentStr { get; set; } + + /// + /// خدمات حضوری بیمه + /// درصد از مزد روزانه + /// string + /// + public string InsuranceInPersonPercentStr { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionPlan/IInstitutionPlanApplication.cs b/CompanyManagment.App.Contracts/InstitutionPlan/IInstitutionPlanApplication.cs index 2e2293c0..2eb91460 100644 --- a/CompanyManagment.App.Contracts/InstitutionPlan/IInstitutionPlanApplication.cs +++ b/CompanyManagment.App.Contracts/InstitutionPlan/IInstitutionPlanApplication.cs @@ -1,6 +1,7 @@ -using System.Collections.Generic; -using _0_Framework.Application; +using _0_Framework.Application; using CompanyManagment.App.Contracts.TemporaryClientRegistration; +using System.Collections.Generic; +using System.Threading.Tasks; namespace CompanyManagment.App.Contracts.InstitutionPlan; @@ -34,4 +35,18 @@ public interface IInstitutionPlanApplication /// /// InstitutionPlanViewModel GetInstitutionPlanForWorkshop(WorkshopTempViewModel command); + + + /// + /// دریافت دیتای درصد سرویس برای مودال ایجاد + /// + /// + Task GetCreateModalData(); + + /// + /// ایجاد درصد سرویس + /// + /// + /// + Task CreateInstitutionPlanPercentage(CreateServiceAmountDto command); } \ No newline at end of file diff --git a/CompanyManagment.Application/InstitutionPlanApplication.cs b/CompanyManagment.Application/InstitutionPlanApplication.cs index 6137c992..53e2f1f7 100644 --- a/CompanyManagment.Application/InstitutionPlanApplication.cs +++ b/CompanyManagment.Application/InstitutionPlanApplication.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework.Application; using Company.Domain.InstitutionPlanAgg; using CompanyManagment.App.Contracts.InstitutionPlan; @@ -84,4 +85,68 @@ public class InstitutionPlanApplication : IInstitutionPlanApplication { return _planPercentageRepository.GetInstitutionPlanForWorkshop(command); } + + + #region ForApi + + public async Task GetCreateModalData() + { + return await _planPercentageRepository.GetCreateModalData(); + } + + + public async Task CreateInstitutionPlanPercentage(CreateServiceAmountDto command) + { + var op = new OperationResult(); + if (string.IsNullOrWhiteSpace(command.ContractAndCheckoutInPersonPercentStr) || command.ContractAndCheckoutInPersonPercentStr == "0" || + string.IsNullOrWhiteSpace(command.ContractAndCheckoutPercentStr) || (command.ContractAndCheckoutPercentStr == "0" || + string.IsNullOrWhiteSpace(command.CustomizeCheckoutPercentStr) || command.CustomizeCheckoutPercentStr == "0" || + string.IsNullOrWhiteSpace(command.InsuranceInPersonPercentStr) || command.InsuranceInPersonPercentStr == "0" || + string.IsNullOrWhiteSpace(command.InsurancePercentStr) || command.InsurancePercentStr == "0" || + string.IsNullOrWhiteSpace(command.RollCallPercentStr) || command.RollCallPercentStr == "0")) + return op.Failed("هیچ یک از فیلدها نمیتوانند صفر باشند"); + + int contractAndCheckoutInPersonPercent = 0; + int contractAndCheckoutPercent = 0; + int customizeCheckoutPercent = 0; + int insuranceInPersonPercent = 0; + int insurancePercent = 0; + int rollCallPercent = 0; + + try + { + contractAndCheckoutInPersonPercent = Convert.ToInt32(command.ContractAndCheckoutInPersonPercentStr); + contractAndCheckoutPercent = Convert.ToInt32(command.ContractAndCheckoutPercentStr); + customizeCheckoutPercent = Convert.ToInt32(command.CustomizeCheckoutPercentStr); + insuranceInPersonPercent = Convert.ToInt32(command.InsuranceInPersonPercentStr); + insurancePercent = Convert.ToInt32(command.InsurancePercentStr); + rollCallPercent = Convert.ToInt32(command.RollCallPercentStr); + } + catch (Exception e) + { + return op.Failed("لطفا عدد معتبر وارد کنید"); + + } + + var firstPlan =await _planPercentageRepository.GetCreateModalData(); + if (firstPlan != null) + { + var planPercentage = _planPercentageRepository.Get(firstPlan.Id); + planPercentage.Edit(contractAndCheckoutPercent, insurancePercent, rollCallPercent, customizeCheckoutPercent, contractAndCheckoutInPersonPercent, insuranceInPersonPercent); + _planPercentageRepository.SaveChanges(); + } + else + { + var create = new PlanPercentage(contractAndCheckoutPercent, insurancePercent, rollCallPercent, + customizeCheckoutPercent, contractAndCheckoutInPersonPercent, insuranceInPersonPercent); + await _planPercentageRepository.CreateAsync(create); + await _planPercentageRepository.SaveChangesAsync(); + } + + + + return op.Succcedded(); + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/PlanPercentageRepository.cs b/CompanyManagment.EFCore/Repository/PlanPercentageRepository.cs index 2657de37..91b2366b 100644 --- a/CompanyManagment.EFCore/Repository/PlanPercentageRepository.cs +++ b/CompanyManagment.EFCore/Repository/PlanPercentageRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.InfraStructure; using Company.Domain.InstitutionPlanAgg; @@ -44,6 +45,7 @@ public class PlanPercentageRepository : RepositoryBase, IP }).FirstOrDefault(); } + public List GetInstitutionPlanList(int pageIndex, int countPeron) { var planPercentage = _context.PlanPercentages.FirstOrDefault(); @@ -303,4 +305,23 @@ public class PlanPercentageRepository : RepositoryBase, IP return new InstitutionPlanViewModel(); } + + + #region ForApi + + public async Task GetCreateModalData() + { + return await _context.PlanPercentages.Select(x => new CreateServiceAmountDto() + { + Id = x.id, + ContractAndCheckoutInPersonPercentStr = $"{x.ContractAndCheckoutInPersonPercent}", + CustomizeCheckoutPercentStr = $"{x.CustomizeCheckoutPercent}", + ContractAndCheckoutPercentStr = $"{x.ContractAndCheckoutPercent}", + InsuranceInPersonPercentStr = $"{x.InsuranceInPersonPercent}", + InsurancePercentStr = $"{x.InsurancePercent}", + RollCallPercentStr = $"{x.RollCallPercent}", + }).FirstOrDefaultAsync(); + } + + #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/ServiceAmountsManagement.cs b/ServiceHost/Areas/Admin/Controllers/ServiceAmountsManagement.cs new file mode 100644 index 00000000..edfc1416 --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/ServiceAmountsManagement.cs @@ -0,0 +1,52 @@ +using _0_Framework.Application; +using AccountManagement.Application.Contracts.Ticket; +using CompanyManagment.App.Contracts.InstitutionPlan; +using CompanyManagment.App.Contracts.Workshop; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Admin.Controllers; + +public class ServiceAmountsManagement : AdminBaseController +{ + private readonly IInstitutionPlanApplication _institutionPlanApplication; + private readonly IAuthHelper _authHelper; + + public ServiceAmountsManagement(IInstitutionPlanApplication institutionPlanApplication, IAuthHelper authHelper) + { + _institutionPlanApplication = institutionPlanApplication; + _authHelper = authHelper; + } + + + /// + /// دریافت دیتای مودال ایجاد + /// + /// + [HttpGet("GetCreateModalData")] + public async Task> GetCreateModalData() + { + if(!_authHelper.HasPermission(315)) + return Forbid(); + var data = await _institutionPlanApplication.GetCreateModalData(); + + return data; + } + + /// + /// ذخیره درصدها + /// + /// + /// + [HttpPost("CreateServicePercentage")] + public async Task> CreateServicePercentage([FromBody] CreateServiceAmountDto command) + { + + if (!_authHelper.HasPermission(315)) + return new OperationResult().Failed("اجازه دسترسی ندارید"); + + var result = await _institutionPlanApplication.CreateInstitutionPlanPercentage(command); + + return result; + } +} \ No newline at end of file