From ced5c8c576cf24ca03b06c748c88bc5e3aa04fb1 Mon Sep 17 00:00:00 2001 From: SamSys Date: Sun, 4 Aug 2024 18:19:16 +0330 Subject: [PATCH] CreateWorkshopAccount and report Fixed lost codes --- .../Account/AccountLeftWorkViewModel.cs | 4 + .../Account/AccountSearchModel.cs | 25 +- .../Account/AccountViewModel.cs | 43 +- .../Account/ChangePassword.cs | 15 +- .../Account/CreateAccount.cs | 47 +- .../Account/EditAccount.cs | 11 +- .../Account/EditClientAccount.cs | 11 +- .../Account/IAccountApplication.cs | 69 +- .../Account/Login.cs | 13 +- .../Account/RegisterAccount.cs | 37 +- .../Account/WorkshopSelectList.cs | 14 + ...untManagement.Application.Contracts.csproj | 4 + .../AccountApplication.cs | 9 +- .../AccountAgg/IAccountRepository.cs | 1 + .../IAccountLeftworkRepository.cs | 10 + .../Repository/AccountLeftworkRepository.cs | 81 +- .../Repository/AccountRepository.cs | 12 + .../IWorkshopAccountRepository.cs | 3 + .../Report/AllReport.cs | 8 +- .../Repository/ReportRepository.cs | 93 +- .../Repository/WorkshopAccountRepository.cs | 40 +- .../Accounts/Account/AccountLeftWork.cshtml | 1005 +++++++++++++++-- .../Pages/Accounts/Account/Index.cshtml.cs | 3 +- .../Admin/Pages/Company/Reports/Index.cshtml | 16 +- .../Pages/Company/Reports/Index.cshtml.cs | 6 +- 25 files changed, 1308 insertions(+), 272 deletions(-) create mode 100644 AccountManagement.Application.Contracts/Account/WorkshopSelectList.cs diff --git a/AccountManagement.Application.Contracts/Account/AccountLeftWorkViewModel.cs b/AccountManagement.Application.Contracts/Account/AccountLeftWorkViewModel.cs index cea5b36e..4c6564ae 100644 --- a/AccountManagement.Application.Contracts/Account/AccountLeftWorkViewModel.cs +++ b/AccountManagement.Application.Contracts/Account/AccountLeftWorkViewModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc.Rendering; namespace AccountManagement.Application.Contracts.Account; @@ -11,4 +12,7 @@ public class AccountLeftWorkViewModel public string LeftDateFa { get; set; } public List AccountList { get; set; } public List WorkshopAccountlist { get; set; } + public SelectList WorkshopSelectList { get; set; } + + public SelectList AccountSelectList { get; set; } } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/AccountSearchModel.cs b/AccountManagement.Application.Contracts/Account/AccountSearchModel.cs index 6267ddd0..68540f6c 100644 --- a/AccountManagement.Application.Contracts/Account/AccountSearchModel.cs +++ b/AccountManagement.Application.Contracts/Account/AccountSearchModel.cs @@ -1,14 +1,13 @@ -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public class AccountSearchModel { - public class AccountSearchModel - { - public string Fullname { get; set; } - public string Username { get; set; } - public string Mobile { get; set; } - public long RoleId { get; set; } - public string RoleName { get; set; } - public string VerifyCode { get; set; } - public string IsActiveString { get; set; } - public string positionId { get; set; } - } -} + public string Fullname { get; set; } + public string Username { get; set; } + public string Mobile { get; set; } + public long RoleId { get; set; } + public string RoleName { get; set; } + public string VerifyCode { get; set; } + public string IsActiveString { get; set; } + public string positionId { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/AccountViewModel.cs b/AccountManagement.Application.Contracts/Account/AccountViewModel.cs index f023b884..2794917e 100644 --- a/AccountManagement.Application.Contracts/Account/AccountViewModel.cs +++ b/AccountManagement.Application.Contracts/Account/AccountViewModel.cs @@ -1,27 +1,26 @@ using System; -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public class AccountViewModel { - public class AccountViewModel - { - public long Id { get; set; } - public string Fullname { get; set; } - public string Username { get; set; } - public string Mobile { get; set; } - public long RoleId { get; set; } - public string Role { get; set; } - public string ProfilePhoto { get; set; } - public string CreationDate { get; set; } - public string RoleName { get; set; } - public string VerifyCode { get; set; } - public string IsActiveString { get; set; } - public DateTime CreationDateGr { get; set; } + public long Id { get; set; } + public string Fullname { get; set; } + public string Username { get; set; } + public string Mobile { get; set; } + public long RoleId { get; set; } + public string Role { get; set; } + public string ProfilePhoto { get; set; } + public string CreationDate { get; set; } + public string RoleName { get; set; } + public string VerifyCode { get; set; } + public string IsActiveString { get; set; } + public DateTime CreationDateGr { get; set; } - #region Mahan + #region Mahan - public int PositionValue { get; set; } - public long PositionId { get; set; } - #endregion - public string AdminAreaPermission { get; set; } - } -} + public int PositionValue { get; set; } + public long PositionId { get; set; } + #endregion + public string AdminAreaPermission { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/ChangePassword.cs b/AccountManagement.Application.Contracts/Account/ChangePassword.cs index 00ad81d1..0d134d56 100644 --- a/AccountManagement.Application.Contracts/Account/ChangePassword.cs +++ b/AccountManagement.Application.Contracts/Account/ChangePassword.cs @@ -1,9 +1,8 @@ -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public class ChangePassword { - public class ChangePassword - { - public long Id { get; set; } - public string Password { get; set; } - public string RePassword { get; set; } - } -} + public long Id { get; set; } + public string Password { get; set; } + public string RePassword { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/CreateAccount.cs b/AccountManagement.Application.Contracts/Account/CreateAccount.cs index fc6a661c..da243966 100644 --- a/AccountManagement.Application.Contracts/Account/CreateAccount.cs +++ b/AccountManagement.Application.Contracts/Account/CreateAccount.cs @@ -5,35 +5,34 @@ using System.ComponentModel.DataAnnotations; using AccountManagement.Application.Contracts.Role; using Microsoft.AspNetCore.Http; -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public class CreateAccount { - public class CreateAccount - { - [Required(ErrorMessage = ValidationMessages.IsRequired)] - public string Fullname { get; set; } + [Required(ErrorMessage = ValidationMessages.IsRequired)] + public string Fullname { get; set; } - [Required(ErrorMessage = ValidationMessages.IsRequired)] - public string Username { get; set; } + [Required(ErrorMessage = ValidationMessages.IsRequired)] + public string Username { get; set; } - [Required(ErrorMessage = ValidationMessages.IsRequired)] - public string Password { get; set; } + [Required(ErrorMessage = ValidationMessages.IsRequired)] + public string Password { get; set; } - [Required(ErrorMessage = "این مقدار نمی تواند خالی باشد")] + [Required(ErrorMessage = "این مقدار نمی تواند خالی باشد")] - [RegularExpression("^[0-9]*$", ErrorMessage = "لطفا فقط عدد وارد کنید")] - public string Mobile { get; set; } + [RegularExpression("^[0-9]*$", ErrorMessage = "لطفا فقط عدد وارد کنید")] + public string Mobile { get; set; } - public long RoleId { get; set; } + public long RoleId { get; set; } - public IFormFile ProfilePhoto { get; set; } - public string ProfilePhotoStr { get; set; } - public List Roles { get; set; } + public IFormFile ProfilePhoto { get; set; } + public string ProfilePhotoStr { get; set; } + public List Roles { get; set; } - public string AdminAreaPermission { get; set; } - public string ClientAriaPermission { get; set; } - public string NationalCode { get; set; } - public string Email { get; set; } - public string VerifyCode { get; set; } - public string IsActiveString { get; set; } - } -} + public string AdminAreaPermission { get; set; } + public string ClientAriaPermission { get; set; } + public string NationalCode { get; set; } + public string Email { get; set; } + public string VerifyCode { get; set; } + public string IsActiveString { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/EditAccount.cs b/AccountManagement.Application.Contracts/Account/EditAccount.cs index de626562..b322c34b 100644 --- a/AccountManagement.Application.Contracts/Account/EditAccount.cs +++ b/AccountManagement.Application.Contracts/Account/EditAccount.cs @@ -1,7 +1,6 @@ -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public class EditAccount : CreateAccount { - public class EditAccount : CreateAccount - { - public long Id { get; set; } - } -} + public long Id { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/EditClientAccount.cs b/AccountManagement.Application.Contracts/Account/EditClientAccount.cs index 0ff820de..eef61835 100644 --- a/AccountManagement.Application.Contracts/Account/EditClientAccount.cs +++ b/AccountManagement.Application.Contracts/Account/EditClientAccount.cs @@ -4,10 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public class EditClientAccount : RegisterAccount { - public class EditClientAccount : RegisterAccount - { - public long Id { get; set; } - } -} + public long Id { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs index 2e14ddb5..08f1c7ea 100644 --- a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs +++ b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs @@ -3,40 +3,45 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public interface IAccountApplication { - public interface IAccountApplication - { - AccountViewModel GetAccountBy(long id); - OperationResult Create(CreateAccount command); - OperationResult RegisterClient(RegisterAccount command); - OperationResult Edit(EditAccount command); - OperationResult EditClient(EditClientAccount command); - OperationResult ChangePassword(ChangePassword command); - OperationResult Login(Login command); - OperationResult LoginWithMobile(long id); - EditAccount GetDetails(long id); - List Search(AccountSearchModel searchModel); - void Logout(); - List GetAccounts(); - List GetClientsAccount(); - Task SetVerifyCode(string phone, long id); - Task SendVerifyCodeToChangingPass(string phone, long id); - EditAccount GetByVerifyCode(string code, string phone); - EditAccount GetByUserNameAndId(long id, string username); - OperationResult Active(long id); - OperationResult DeActive(long id); - OperationResult DirectLogin(long id); + AccountViewModel GetAccountBy(long id); + OperationResult Create(CreateAccount command); + OperationResult RegisterClient(RegisterAccount command); + OperationResult Edit(EditAccount command); + OperationResult EditClient(EditClientAccount command); + OperationResult ChangePassword(ChangePassword command); + OperationResult Login(Login command); + OperationResult LoginWithMobile(long id); + EditAccount GetDetails(long id); + List Search(AccountSearchModel searchModel); + void Logout(); + List GetAccounts(); + List GetClientsAccount(); + Task SetVerifyCode(string phone, long id); + Task SendVerifyCodeToChangingPass(string phone, long id); + EditAccount GetByVerifyCode(string code, string phone); + EditAccount GetByUserNameAndId(long id, string username); + OperationResult Active(long id); + OperationResult DeActive(long id); + OperationResult DirectLogin(long id); - AccountLeftWorkViewModel WorkshopList(long accountId); + AccountLeftWorkViewModel WorkshopList(long accountId); + OperationResult SaveWorkshopAccount( + List workshopAccountList, + string startDate, + string leftDate, + long accountId); - #region Mahan - List AccountsForAssign(long accountId); - List GetAccountsByPositionId(long positionId); + OperationResult CreateNewWorkshopAccount(long currentAccountId, long newAccountId); + #region Mahan + List AccountsForAssign(long accountId); + List GetAccountsByPositionId(long positionId); - List GetAccountLowerPositionvalue(); - OperationResult ReLogin(); + List GetAccountLowerPositionvalue(); + OperationResult ReLogin(); - #endregion - } -} + #endregion +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/Login.cs b/AccountManagement.Application.Contracts/Account/Login.cs index 28279086..bc772164 100644 --- a/AccountManagement.Application.Contracts/Account/Login.cs +++ b/AccountManagement.Application.Contracts/Account/Login.cs @@ -1,8 +1,7 @@ -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public class Login { - public class Login - { - public string Username { get; set; } - public string Password { get; set; } - } -} + public string Username { get; set; } + public string Password { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/RegisterAccount.cs b/AccountManagement.Application.Contracts/Account/RegisterAccount.cs index f8ffb1e7..78b9fcf0 100644 --- a/AccountManagement.Application.Contracts/Account/RegisterAccount.cs +++ b/AccountManagement.Application.Contracts/Account/RegisterAccount.cs @@ -7,31 +7,30 @@ using System.Threading.Tasks; using _0_Framework.Application; using Microsoft.AspNetCore.Http; -namespace AccountManagement.Application.Contracts.Account +namespace AccountManagement.Application.Contracts.Account; + +public class RegisterAccount { - public class RegisterAccount - { - [Required(ErrorMessage = "نام و نام خانوادگی نمی تواند خالی باشد")] - public string Fullname { get; set; } + [Required(ErrorMessage = "نام و نام خانوادگی نمی تواند خالی باشد")] + public string Fullname { get; set; } - [Required(ErrorMessage = "نام کاربری نمی تواند خالی باشد")] - public string Username { get; set; } + [Required(ErrorMessage = "نام کاربری نمی تواند خالی باشد")] + public string Username { get; set; } - [Required(ErrorMessage = "گذرواژه نمیتواند خالی باشد")] - public string Password { get; set; } + [Required(ErrorMessage = "گذرواژه نمیتواند خالی باشد")] + public string Password { get; set; } - [Required(ErrorMessage = "شماره موبایل نمی تواند خالی باشد")] + [Required(ErrorMessage = "شماره موبایل نمی تواند خالی باشد")] - [RegularExpression("^[0-9]*$", ErrorMessage = "شماره موبایل معتبر وارد کنید")] - public string Mobile { get; set; } + [RegularExpression("^[0-9]*$", ErrorMessage = "شماره موبایل معتبر وارد کنید")] + public string Mobile { get; set; } - [Required(ErrorMessage = "کد ملی نمی تواند خالی باشد")] - public string NationalCode { get; set; } + [Required(ErrorMessage = "کد ملی نمی تواند خالی باشد")] + public string NationalCode { get; set; } - public string Email { get; set; } + public string Email { get; set; } - public IFormFile ProfilePhoto { get; set; } + public IFormFile ProfilePhoto { get; set; } - public long ContractingPartyId { get; set; } - } -} + public long ContractingPartyId { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Account/WorkshopSelectList.cs b/AccountManagement.Application.Contracts/Account/WorkshopSelectList.cs new file mode 100644 index 00000000..8e17212f --- /dev/null +++ b/AccountManagement.Application.Contracts/Account/WorkshopSelectList.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccountManagement.Application.Contracts.Account; + +public class WorkshopSelectList +{ + public long Id { get; set; } + + public string WorkshopFullName { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/AccountManagement.Application.Contracts.csproj b/AccountManagement.Application.Contracts/AccountManagement.Application.Contracts.csproj index e03c4387..36069642 100644 --- a/AccountManagement.Application.Contracts/AccountManagement.Application.Contracts.csproj +++ b/AccountManagement.Application.Contracts/AccountManagement.Application.Contracts.csproj @@ -4,6 +4,10 @@ net8.0 + + + + diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index be8bbc3f..23fcacd0 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -13,6 +13,7 @@ using AccountManagement.Domain.AccountLeftWorkAgg; using AccountManagement.Domain.CameraAccountAgg; using AccountManagement.Domain.RoleAgg; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Rendering; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; using TaskManager.Domain.PositionAgg; //using AccountManagement.Domain.RoleAgg; @@ -418,8 +419,8 @@ public class AccountApplication : IAccountApplication public AccountLeftWorkViewModel WorkshopList(long accountId) { string fullname = this._accountRepository.GetById(accountId).Fullname; - List source = this._accountLeftworkRepository.WorkshopList(accountId); - List userWorkshopIds = source.Select((Func)(x => x.WorkshopId)).ToList(); + List source =_accountLeftworkRepository.WorkshopList(accountId); + List userWorkshopIds = source.Select(x => x.WorkshopId).ToList(); List allWorkshops = this._accountLeftworkRepository.GetAllWorkshops(); List accountSelectList = this._accountRepository.GetAdminAccountSelectList(); (string StartWorkFa, string LeftWorkFa) byAccountId = this._accountLeftworkRepository.GetByAccountId(accountId); @@ -430,8 +431,8 @@ public class AccountApplication : IAccountApplication StartDateFa = byAccountId.StartWorkFa, LeftDateFa = byAccountId.LeftWorkFa, WorkshopAccountlist = source, - WorkshopSelectList = new SelectList((IEnumerable)allWorkshops.Where((Func)(x => !userWorkshopIds.Contains(x.Id))), "Id", "WorkshopFullName"), - AccountSelectList = new SelectList((IEnumerable)accountSelectList, "Id", "Fullname") + WorkshopSelectList = new SelectList(allWorkshops.Where(x => !userWorkshopIds.Contains(x.Id)), "Id", "WorkshopFullName"), + AccountSelectList = new SelectList(accountSelectList, "Id", "Fullname") }; } diff --git a/AccountManagement.Domain/AccountAgg/IAccountRepository.cs b/AccountManagement.Domain/AccountAgg/IAccountRepository.cs index 834b2426..65d20cd0 100644 --- a/AccountManagement.Domain/AccountAgg/IAccountRepository.cs +++ b/AccountManagement.Domain/AccountAgg/IAccountRepository.cs @@ -13,6 +13,7 @@ namespace AccountManagement.Domain.AccountAgg EditAccount GetByVerifyCode(string code, string phone); EditAccount GetByUserNameAndId(long id, string username); List GetAccounts(); + List GetAdminAccountSelectList(); List GetClientsAccount(); List Search(AccountSearchModel searchModel); Task RemoveCode(long id); diff --git a/AccountManagement.Domain/AccountLeftWorkAgg/IAccountLeftworkRepository.cs b/AccountManagement.Domain/AccountLeftWorkAgg/IAccountLeftworkRepository.cs index c95caacc..f9c943a5 100644 --- a/AccountManagement.Domain/AccountLeftWorkAgg/IAccountLeftworkRepository.cs +++ b/AccountManagement.Domain/AccountLeftWorkAgg/IAccountLeftworkRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using _0_Framework.Application; using _0_Framework.Domain; using AccountManagement.Application.Contracts.Account; @@ -9,4 +10,13 @@ public interface IAccountLeftworkRepository : IRepository { (string StartWorkFa, string LeftWorkFa) GetByAccountId(long accountId); List WorkshopList(long accountId); + List GetAllWorkshops(); + + OperationResult CopyWorkshopToNewAccount(long currentAccountId, long newAccountId); + + OperationResult SaveWorkshopAccount( + List workshopAccountList, + string startDate, + string leftDate, + long accountId); } \ No newline at end of file diff --git a/AccountMangement.Infrastructure.EFCore/Repository/AccountLeftworkRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/AccountLeftworkRepository.cs index f51ddcb4..77232f33 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/AccountLeftworkRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/AccountLeftworkRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using _0_Framework.Application; using _0_Framework.InfraStructure; using AccountManagement.Application.Contracts.Account; @@ -8,6 +9,7 @@ using AccountManagement.Domain.AccountLeftWorkAgg; using Company.Domain.LeftWorkAgg; using Company.Domain.WorkingHoursItemsAgg; using Company.Domain.WorkshopAccountAgg; +using CompanyManagment.App.Contracts.Workshop; using Microsoft.EntityFrameworkCore; namespace AccountMangement.Infrastructure.EFCore.Repository; @@ -16,12 +18,14 @@ public class AccountLeftworkRepository : RepositoryBase, { private readonly AccountContext _accountContext; private readonly IWorkshopAccountRepository _workshopAccountRepository; + private readonly IWorkshopApplication _workshopApplication; - public AccountLeftworkRepository(AccountContext accountContext, IWorkshopAccountRepository workshopAccountRepository) : base(accountContext) + public AccountLeftworkRepository(AccountContext accountContext, IWorkshopAccountRepository workshopAccountRepository, IWorkshopApplication workshopApplication) : base(accountContext) { _accountContext = accountContext; _workshopAccountRepository = workshopAccountRepository; - } + _workshopApplication = workshopApplication; + } public (string StartWorkFa, string LeftWorkFa) GetByAccountId(long accountId) { @@ -53,4 +57,75 @@ public class AccountLeftworkRepository : RepositoryBase, IsActiveSting = x.IsActiveSting, }).ToList(); } -} \ No newline at end of file + + public List GetAllWorkshops() + { + return this._workshopApplication.GetWorkshopAll().Select(x => new WorkshopSelectList() + { + Id = x.Id, + WorkshopFullName = x.WorkshopFullName + }).ToList(); + } + + public OperationResult CopyWorkshopToNewAccount(long currentAccountId, long newAccountId) + { + List accountViewModelList = new List(); + OperationResult operationResult = new OperationResult(); + List list =_workshopAccountRepository.GetList(currentAccountId); + List newPrsonIds =_workshopAccountRepository.GetList(newAccountId).Select(x => x.WorkshopId).ToList(); + if (list.Count <= 0) + return operationResult.Failed("پرسنل هیچ کارگاهی برای انتقال ندارد"); + List source = newPrsonIds.Count <= 0 ? list : list.Where(x => !newPrsonIds.Contains(x.WorkshopId)).ToList(); + try + { + var res = source.Select(x => new WorkshopAccountViewModel() + { + AccountId = newAccountId, + WorkshopId = x.WorkshopId, + Insurance = x.Insurance, + Tax = x.Tax, + ContractAndCheckout = x.ContractAndCheckout, + WorkshopName = x.WorkshopName, + IsActiveSting = "true" + }).ToList(); + _workshopAccountRepository.CreateNewWorkshopAccountByList(res); + return operationResult.Succcedded(); + } + catch (Exception ex) + { + return operationResult.Failed("خطا در انجام عملیات"); + } + } + + public OperationResult SaveWorkshopAccount( + List workshopAccountList, + string startDate, + string leftDate, + long accountId) + { + OperationResult operationResult = new OperationResult(); + DateTime start = startDate.ToGeorgianDateTime(); + DateTime leftWorkGr = new DateTime(2150, 1, 1); + if (!string.IsNullOrWhiteSpace(leftDate) && leftDate.Length == 10) + leftWorkGr = leftDate.ToGeorgianDateTime(); + if (start > leftWorkGr) + return operationResult.Failed("تاریخ شروع بکار از تاریخ ترک کار بزرگتر است"); + if (start == leftWorkGr) + return operationResult.Failed("تاریخ شروع بکار و ترک کار برابرند"); + var oldLefts = _accountContext.AccountLeftWorks.Where(x => x.AccountId == accountId).ToList(); + _accountContext.AccountLeftWorks.RemoveRange(oldLefts); + Create(new AccountLeftWork(start, leftWorkGr, accountId)); + SaveChanges(); + var workshopAccountViewModel = workshopAccountList.Select(x => new WorkshopAccountViewModel() + { + AccountId = x.AccountId, + WorkshopId = x.WorkshopId, + Insurance = x.Insurance, + ContractAndCheckout = x.ContractAndCheckout, + Tax = x.Tax, + IsActiveSting = x.IsActiveSting + }).ToList(); + _workshopAccountRepository.SaveWorkshopAccount(workshopAccountViewModel); + return operationResult.Succcedded(); + } +} diff --git a/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs index 0ffa6c33..5ab11099 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs @@ -7,6 +7,8 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Linq.Expressions; +using System.Reflection; using System.Threading.Tasks; using AccountManagement.Domain.RoleAgg; using Microsoft.AspNetCore.Http; @@ -93,6 +95,16 @@ public class AccountRepository : RepositoryBase, IAccountReposito }).ToList(); } + public List GetAdminAccountSelectList() + { + return _context.Accounts.Where(x => x.AdminAreaPermission == "true").Select(x => new AccountViewModel() + { + Id = x.id, + Fullname = x.Fullname, + }).ToList(); + + } + public List GetClientsAccount() { return _context.Accounts.Select(x => new AccountViewModel diff --git a/Company.Domain/WorkshopAccountAgg/IWorkshopAccountRepository.cs b/Company.Domain/WorkshopAccountAgg/IWorkshopAccountRepository.cs index 23005556..2c3c59b1 100644 --- a/Company.Domain/WorkshopAccountAgg/IWorkshopAccountRepository.cs +++ b/Company.Domain/WorkshopAccountAgg/IWorkshopAccountRepository.cs @@ -7,4 +7,7 @@ namespace Company.Domain.WorkshopAccountAgg; public interface IWorkshopAccountRepository: IRepository { List GetList(long accountId); + void CreateNewWorkshopAccountByList(List workshopAccountList); + + void SaveWorkshopAccount(List workshopAccountList); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Report/AllReport.cs b/CompanyManagment.App.Contracts/Report/AllReport.cs index 37f67cea..31ad2a8d 100644 --- a/CompanyManagment.App.Contracts/Report/AllReport.cs +++ b/CompanyManagment.App.Contracts/Report/AllReport.cs @@ -18,10 +18,10 @@ namespace CompanyManagment.App.Contracts.Report public int CheckoutSignaturePercent { get; set; } public string Year { get; set; } public string Month { get; set; } - public List AccountResults { get; set; } - - //قراداد - public int AllContract { get; set; } + public List ContractAccountResults { get; set; } + public List CheckoutAccountResults { get; set; } + //قراداد + public int AllContract { get; set; } public int ContractNotDone { get; set; } public int ContrcatDone { get; set; } public int ContractSignNotDone { get; set; } diff --git a/CompanyManagment.EFCore/Repository/ReportRepository.cs b/CompanyManagment.EFCore/Repository/ReportRepository.cs index 0da175af..efced907 100644 --- a/CompanyManagment.EFCore/Repository/ReportRepository.cs +++ b/CompanyManagment.EFCore/Repository/ReportRepository.cs @@ -56,7 +56,7 @@ public class ReportRepository : IReportRepository ContractLeftWorkCount = 0, CheckoutLeftWorkCount = 0, ContractingPartId = x.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(), - AccountIdList = _context.WorkshopAccounts.Where(m => m.WorkshopId == x.id).Select(a => a.AccountId).ToList(), + AccountIdList = _context.WorkshopAccounts.Where(m => m.WorkshopId == x.id && m.ContractAndCheckout == "true" && m.IsActiveSting == "true").Select(a => a.AccountId).ToList(), #region Contracts //contractLeft This Mont @@ -92,7 +92,7 @@ public class ReportRepository : IReportRepository #endregion - }).Where(e => blockContractingPartyIds.Contains(e.ContractingPartId)); + }).Where(e => blockContractingPartyIds.Contains(e.ContractingPartId) && e.AccountIdList.Count > 0); var workshopsList = workshops.Select(x => new ActiveWorkshops { @@ -165,19 +165,17 @@ public class ReportRepository : IReportRepository }); Console.WriteLine("Ripo query 2 >>>>>: " + watch.Elapsed); - var accountResult = result.Select(x => new ActiveWorkshops() + var contractAccountResult = result.Select(x => new ActiveWorkshops() { Id = x.Id, - AccountId = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5) - ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.id : 0, - AccountFullname = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5) - ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.Fullname : "", + //AccountId = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5) + // ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.id : 0, + //AccountFullname = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5) + // ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.Fullname : "", + AccountId = _accountContext.AccountLeftWorks.Any(e=> x.AccountIdList.Contains(e.AccountId) && e.StartWorkGr <= currentMonthStart && e.LeftWorkGr >= currentMonthEnd) ? + _accountContext.AccountLeftWorks.FirstOrDefault(e => x.AccountIdList.Contains(e.AccountId) && e.StartWorkGr <= currentMonthStart && e.LeftWorkGr >= currentMonthEnd)!.AccountId : 0, - ContractLeftWorkCount = x.ContractLeftWorkCount, - CheckoutLeftWorkCount = x.CheckoutLeftWorkCount, - - CheckoutDoneCount = x.CheckoutDoneCount, - CheckoutSignDoneCount = x.CheckoutSignDoneCount, + ContractLeftWorkCount = x.ContractLeftWorkCount, ContrctDoneCount = x.ContrctDoneCount, ContrctSignDoneCount = x.ContrctSignDoneCount, @@ -185,46 +183,67 @@ public class ReportRepository : IReportRepository WorkshopFullName = x.WorkshopFullName, }).Where(x => x.AccountId != 0).ToList(); - watch.Restart(); - //قرارداد هایی که باید اسجاد می شد - var contractToBe = accountResult.Sum(x => x.ContractLeftWorkCount); - // تصفیه هایی که باید ایجاد می شد - var checkoutToBe = accountResult.Sum(x => x.CheckoutLeftWorkCount); + var checkoutAccountResult = result.Select(x => new ActiveWorkshops() + { + Id = x.Id, + //AccountId = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5) + // ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.id : 0, + //AccountFullname = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5) + // ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.Fullname : "", + AccountId = _accountContext.AccountLeftWorks.Any(e => x.AccountIdList.Contains(e.AccountId) && e.StartWorkGr <= nextMonthStart && e.LeftWorkGr >= nextMonthEnd) ? + _accountContext.AccountLeftWorks.FirstOrDefault(e => x.AccountIdList.Contains(e.AccountId) && e.StartWorkGr <= nextMonthStart && e.LeftWorkGr >= nextMonthEnd)!.AccountId : 0, + CheckoutLeftWorkCount = x.CheckoutLeftWorkCount, + CheckoutDoneCount = x.CheckoutDoneCount, + CheckoutSignDoneCount = x.CheckoutSignDoneCount, + + IsActiveString = x.IsActiveString, + WorkshopFullName = x.WorkshopFullName, + + }).Where(x => x.AccountId != 0).ToList(); + watch.Restart(); + //قرارداد هایی که باید اسجاد می شد + var contractToBe = contractAccountResult.Sum(x => x.ContractLeftWorkCount); + //قراردادهای ایجاد شده - var createdContracts = accountResult.Sum(x => x.ContrctDoneCount); + var createdContracts = contractAccountResult.Sum(x => x.ContrctDoneCount); // قراداد های امضاء شده - var signedContracts = accountResult.Sum(x => x.ContrctSignDoneCount); - + var signedContracts = contractAccountResult.Sum(x => x.ContrctSignDoneCount); + + + // تصفیه هایی که باید ایجاد می شد + var checkoutToBe = checkoutAccountResult.Sum(x => x.CheckoutLeftWorkCount); // تصفیه های ایجاد شده - var createdCheckouts = accountResult.Sum(x => x.CheckoutDoneCount); + var createdCheckouts = checkoutAccountResult.Sum(x => x.CheckoutDoneCount); //تصفیه های امضاء شده - var signedChckouts = accountResult.Sum(x => x.CheckoutSignDoneCount); + var signedChckouts = checkoutAccountResult.Sum(x => x.CheckoutSignDoneCount); - var groupResult = accountResult.GroupBy(x => x.AccountId).Select(x => new AccountResults() + var contractGroupResult = contractAccountResult.GroupBy(x => x.AccountId).Select(x => new AccountResults() { AccountId = x.Key, - AccountFullName = x.FirstOrDefault()?.AccountFullname, - //ContractToBe = x.Sum(c=>c.ContractLeftWorkCount), - //CheckoutoBe = x.Sum(c => c.CheckoutLeftWorkCount), - //ContractDone = x.Sum(c => c.ContrctDoneCount), - //ContractSignDone = x.Sum(c => c.ContrctSignDoneCount), - //CheckoutDone = x.Sum(c => c.CheckoutDoneCount), - //CheckoutSignDone = x.Sum(c => c.CheckoutSignDoneCount), + AccountFullName = _accountContext.Accounts.FirstOrDefault(a=>a.id == x.Key)!.Fullname, + ContractDonePercent = (x.Sum(c => c.ContrctDoneCount) * 100) / x.Sum(c => c.ContractLeftWorkCount), - CheckoutDonePercent = (x.Sum(c => c.CheckoutDoneCount) * 100) / x.Sum(c => c.CheckoutLeftWorkCount), ContractSignPercent = x.Sum(c => c.ContrctDoneCount) > 0 ? (x.Sum(c => c.ContrctSignDoneCount) * 100) / (x.Sum(c => c.ContrctDoneCount)) : 0, - CheckoutSignPercent = x.Sum(c => c.CheckoutDoneCount) > 0 ? (x.Sum(c => c.CheckoutSignDoneCount) * 100) / (x.Sum(c => c.CheckoutDoneCount)) : 0, + }).ToList(); + var checkoutGroupResult = checkoutAccountResult.GroupBy(x => x.AccountId).Select(x => new AccountResults() + { + AccountId = x.Key, + AccountFullName = _accountContext.Accounts.FirstOrDefault(a => a.id == x.Key)!.Fullname, + + CheckoutDonePercent = (x.Sum(c => c.CheckoutDoneCount) * 100) / x.Sum(c => c.CheckoutLeftWorkCount), + CheckoutSignPercent = x.Sum(c => c.CheckoutDoneCount) > 0 ? (x.Sum(c => c.CheckoutSignDoneCount) * 100) / (x.Sum(c => c.CheckoutDoneCount)) : 0, - #region ComputePercentage + }).ToList(); + #region ComputePercentage - //قرارداد - var contractPercent = (createdContracts * 100) / contractToBe; + //قرارداد + var contractPercent = (createdContracts * 100) / contractToBe; //امضاء قراداد var contractSignaturePercent = createdContracts > 0 ? (signedContracts * 100) / createdContracts : 0; // تصفیه @@ -246,8 +265,8 @@ public class ReportRepository : IReportRepository Year = $"{currentYear}", Month = nowFa.Substring(5, 2), - AccountResults = groupResult, - + ContractAccountResults = contractGroupResult, + CheckoutAccountResults = checkoutGroupResult, AllContract = contractToBe, ContractNotDone = contractToBe - createdContracts, diff --git a/CompanyManagment.EFCore/Repository/WorkshopAccountRepository.cs b/CompanyManagment.EFCore/Repository/WorkshopAccountRepository.cs index c5109501..1e7f9d0b 100644 --- a/CompanyManagment.EFCore/Repository/WorkshopAccountRepository.cs +++ b/CompanyManagment.EFCore/Repository/WorkshopAccountRepository.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Linq.Expressions; using _0_Framework.InfraStructure; using Company.Domain.WorkshopAccountAgg; using CompanyManagment.App.Contracts.Workshop; @@ -33,4 +34,41 @@ public class WorkshopAccountRepository : RepositoryBase, }).ToList(); } -} \ No newline at end of file + + public void CreateNewWorkshopAccountByList(List workshopAccountList) + { + + var addNew = workshopAccountList.Select(x => new WorkshopAccount() + { + AccountId = x.AccountId, + WorkshopId = x.WorkshopId, + ContractAndCheckout = x.ContractAndCheckout, + Insurance = x.Insurance, + Tax = x.Tax, + IsActiveSting = "true" + }).ToList(); + _Context.WorkshopAccounts.AddRange(addNew); + _Context.SaveChanges(); + } + + public void SaveWorkshopAccount(List workshopAccountList) + { + if (workshopAccountList.Count > 0) + { + long accountId = workshopAccountList.Select(x => x.AccountId).FirstOrDefault(); + var removeOld = this._Context.WorkshopAccounts.Where(x => x.AccountId == accountId).ToList(); + var addNew = workshopAccountList.Select(x => new WorkshopAccount() + { + AccountId = x.AccountId, + WorkshopId = x.WorkshopId, + ContractAndCheckout = x.ContractAndCheckout, + Insurance = x.Insurance, + Tax = x.Tax, + IsActiveSting = x.IsActiveSting + }).ToList(); + _Context.WorkshopAccounts.RemoveRange(removeOld); + _Context.WorkshopAccounts.AddRange(addNew); + _Context.SaveChanges(); + } + } +} diff --git a/ServiceHost/Areas/Admin/Pages/Accounts/Account/AccountLeftWork.cshtml b/ServiceHost/Areas/Admin/Pages/Accounts/Account/AccountLeftWork.cshtml index 5ea8e18f..75fac18a 100644 --- a/ServiceHost/Areas/Admin/Pages/Accounts/Account/AccountLeftWork.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Accounts/Account/AccountLeftWork.cshtml @@ -1,6 +1,7 @@ @model AccountManagement.Application.Contracts.Account.AccountLeftWorkViewModel +@Html.AntiForgeryToken() @{ - + } - -
-
- کپی کارگاه ها به  : - - - تایید - -
- -
- ترک کار  : - -
-
- شروع بکار  : - -
- -
- -
- -
-
-
- -- -
-
- بیمه -
+ +
+ +
-
- مالیات -
-
- قرداد و تصفیه -
+
+
+ شروع بکار  : +
+
+ +
+
+
+
+
+
+ ترک کار  : +
+
+ +
+
+ +
+ + +
+
+
+ کپی کارگاه ها به پرسنل دیگر + +
+
- - + + تایید +
- نام کارگاه - + افزودن کارگاه جدید +
+ +
+ + افزودن + +
+
-
+
+ +
+
+
+ وضعیت +
+ + +
+
+
+ مالیات +
+ + +
+
+
+ بیمه +
+ + +
+
+
+ قرداد و تصفیه +
+ + +
+
+
+ + +
+ +
+ +
@foreach (var item in @Model.WorkshopAccountlist) { -
+
-
- +
+
+ @if (@item.IsActiveSting == "true") + { + + + } + else + { + + + } + +
+
-
+
- - -
+ + @if (@item.Tax == "true") + { + + + } + else + { + + + }
-
-
- - -
-
-
- - -
+
+
+ @if (@item.Insurance == "true") + { + + + } + else + { + + + } + +
+
+
+
+ @if (@item.ContractAndCheckout == "true") + { + + + } + else + { + + + } + +
@@ -299,15 +626,545 @@
-
+
@item.WorkshopName - +
}
+
+
+ ذخیره + +
+
+ + diff --git a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs index dce53d05..5ffc6e4f 100644 --- a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs @@ -230,7 +230,7 @@ public class IndexModel : PageModel isSuccess = false, mess = "تاریخ شروع بکار خالی است" }); - OperationResult operationResult = this._accountApplication.SaveWorkshopAccount(workshopAccountlistViewModel, startDate, leftDate, accountId); + OperationResult operationResult = _accountApplication.SaveWorkshopAccount(workshopAccountlistViewModel, startDate, leftDate, accountId); return operationResult.IsSuccedded ? (IActionResult)new JsonResult((object)new { isSuccess = true, @@ -255,4 +255,3 @@ public class IndexModel : PageModel }); } } -} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Pages/Company/Reports/Index.cshtml b/ServiceHost/Areas/Admin/Pages/Company/Reports/Index.cshtml index 81c50a4f..69ad58cd 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/Reports/Index.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Company/Reports/Index.cshtml @@ -380,7 +380,7 @@
@{ var firstItem1 = true; - foreach (var personnel in Model.Personnel.OrderBy(x => x.ContractDonePercent)) + foreach (var personnel in Model.PersonnelContract.OrderBy(x => x.ContractDonePercent)) { if (firstItem1) { @@ -426,7 +426,7 @@ } var firstItem2 = true; - foreach (var personnel in Model.Personnel.OrderBy(x => x.ContractSignPercent)) + foreach (var personnel in Model.PersonnelContract.OrderBy(x => x.ContractSignPercent)) {