Compare commits

..

4 Commits

28 changed files with 514 additions and 128 deletions

View File

@@ -8,5 +8,6 @@ namespace Company.Domain.BankAgg
{
public void Remove(Bank entity);
List<BankViewModel> Search(string name);
List<BankSelectList> GetBanksForSelectList();
}
}

View File

@@ -1,7 +1,11 @@
using System;
using _0_Framework.Domain;
using CompanyManagment.App.Contracts.EmployeeBankInformation;
using System.Collections.Generic;
using System.Security.AccessControl;
using System.Threading.Tasks;
using CompanyManagment.App.Contracts.Workshop;
namespace Company.Domain.EmployeeBankInformationAgg
{
@@ -11,14 +15,31 @@ namespace Company.Domain.EmployeeBankInformationAgg
void Remove(EmployeeBankInformation bankInformation);
void RemoveRange(List<EmployeeBankInformation> entities);
[Obsolete("از متد async استفاده کنید")]
List<GroupedEmployeeBankInformationViewModel> Search(long workshopId, EmployeeBankInformationSearchModel searchParams);
Task<List<GroupedEmployeeBankInformationViewModel>> SearchAsync(long workshopId,
EmployeeBankInformationSearchModel searchParams);
GroupedEmployeeBankInformationViewModel GetByEmployeeId(long workshopId, long employeeId);
List<EmployeeBankInformation> GetRangeByEmployeeId(long workshopId, long employeeId);
EmployeeBankInformationViewModel GetDetails(long id);
List<GroupedEmployeeBankInformationViewModel> GetAllByWorkshopId(long workshopId);
List<EmployeeBankInformationViewModelForExcel> SearchForExcel(long workshopId,
EmployeeBankInformationSearchModel searchParams);
List<EmployeeBankInformationViewModelForExcel> SearchForExcel(long workshopId, EmployeeBankInformationSearchModel searchParams);
/// <summary>
/// جزئیات اطلاعات بانکی بر اساس پرسنل
/// </summary>
/// <param name="workshopId"></param>
/// <param name="employeeId"></param>
/// <returns></returns>
Task<GetEmployeeBankInfoDetailsDto> GetDetailsByEmployeeIdAsync(long workshopId, long employeeId);
}
}

View File

@@ -10,5 +10,12 @@ namespace CompanyManagment.App.Contracts.Bank
OperationResult Create(CreateBank command);
OperationResult Edit(EditBank command);
List<BankViewModel> Search(string name);
List<BankSelectList> GetBanksForSelectList();
}
public class BankSelectList:SelectListViewModel
{
}
}

View File

@@ -0,0 +1,14 @@
namespace CompanyManagment.App.Contracts.EmployeeBankInformation;
public class GetEmployeeBankInfoDetailsBankItemDto
{
public long Id { get; set; }
public string CardNumber { get; set; }
public string ShebaNumber { get; set; }
public string BankAccountNumber { get; set; }
public string BankName { get; set; }
public string BankLogoPath { get; set; }
public bool IsDefault { get; set; }
public long BankId { get; set; }
}

View File

@@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace CompanyManagment.App.Contracts.EmployeeBankInformation;
public class GetEmployeeBankInfoDetailsDto
{
public long EmployeeId { get; set; }
public string EmployeeFullName { get; set; }
public List<GetEmployeeBankInfoDetailsBankItemDto> BankItems { get; set; }
}

View File

@@ -1,5 +1,7 @@
using _0_Framework.Application;
using System;
using _0_Framework.Application;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace CompanyManagment.App.Contracts.EmployeeBankInformation
{
@@ -8,6 +10,7 @@ namespace CompanyManagment.App.Contracts.EmployeeBankInformation
OperationResult Create(CreateEmployeeInformation command);
OperationResult GroupCreate(long workshopId, List<CreateEmployeeInformation> command);
OperationResult Edit(EditEmployeeInformation command);
[Obsolete("از متد Async استفاده شود")]
List<GroupedEmployeeBankInformationViewModel> Search(long workshopId, EmployeeBankInformationSearchModel searchParams);
List<EmployeeBankInformationViewModelForExcel> SearchForExcel(long workshopId,
EmployeeBankInformationSearchModel searchParams);
@@ -17,5 +20,22 @@ namespace CompanyManagment.App.Contracts.EmployeeBankInformation
OperationResult RemoveByEmployeeId(long workshopId, long employeeId);
List<GroupedEmployeeBankInformationViewModel> GetAllByWorkshopId(long workshopId);
OperationResult SetDefault(long workshopId, long bankInfoId);
/// <summary>
/// گرفتن لیست اطلاعات بانکی
/// </summary>
/// <param name="workshopId"></param>
/// <param name="searchParams"></param>
/// <returns></returns>
Task<List<GroupedEmployeeBankInformationViewModel>> SearchAsync
(long workshopId, EmployeeBankInformationSearchModel searchParams);
/// <summary>
/// جزئیات اطلاعات بانکی بر اساس پرسنل
/// </summary>
/// <param name="workshopId"></param>
/// <param name="employeeId"></param>
/// <returns></returns>
Task<GetEmployeeBankInfoDetailsDto> GetDetailsByEmployeeIdAsync(long workshopId, long employeeId);
}
}

View File

@@ -104,5 +104,10 @@ namespace CompanyManagment.Application
Id = x.Id
}).ToList();
}
public List<BankSelectList> GetBanksForSelectList()
{
return _bankRepository.GetBanksForSelectList();
}
}
}

View File

@@ -4,6 +4,7 @@ using Company.Domain.EmployeeBankInformationAgg;
using CompanyManagment.App.Contracts.EmployeeBankInformation;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CompanyManagment.Application
{
@@ -101,7 +102,13 @@ namespace CompanyManagment.Application
}
//todo: add CardNumber, BankAccountNumber, etc validations
public async Task<List<GroupedEmployeeBankInformationViewModel>> SearchAsync(long workshopId,
EmployeeBankInformationSearchModel searchParams)
{
return await _employeeBankInformationRepository.SearchAsync(workshopId, searchParams);
}
public OperationResult Edit(EditEmployeeInformation command)
{
OperationResult op = new();
@@ -168,9 +175,6 @@ namespace CompanyManagment.Application
{
var entity = _employeeBankInformationRepository.GetByEmployeeId(workshopId, employeeId);
if (entity == null)
return new();
return entity;
}
@@ -211,6 +215,12 @@ namespace CompanyManagment.Application
return _employeeBankInformationRepository.GetAllByWorkshopId(workshopId);
}
public async Task<GetEmployeeBankInfoDetailsDto> GetDetailsByEmployeeIdAsync(long workshopId, long employeeId)
{
return await _employeeBankInformationRepository.GetDetailsByEmployeeIdAsync(workshopId, employeeId);
}
#region Private Methods
private OperationResult ValidateCreateOperation(List<GroupedEmployeeBankInformationViewModel> workshopEmployeeBankInfoList, CreateEmployeeInformation command)
@@ -253,8 +263,7 @@ namespace CompanyManagment.Application
return !workshopRecords.Exists(x =>
x.WorkshopId == workshopId && x.EmployeeId == employeeId);
}
#endregion
}
}

View File

@@ -1524,8 +1524,7 @@ public class InsuranceListApplication : IInsuranceListApplication
var dateOfBirth = employeeData.DateOfBirthGr.ToFarsi();
var dateOfIssue = employeeData.DateOfIssueGr.ToFarsi();
var leftDate = employeeData.LeftWorkDateGr != null ? employeeData.LeftWorkDateGr.Value.AddDays(-1) : new DateTime();
var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employeeData.StartWorkDateGr, leftDate, startDateGr, endDateGr, employeeData.EmployeeId);
var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employeeData.StartWorkDateGr, leftDate, startDateGr, endDateGr, employeeData.EmployeeId);
var leftWorkFa = workingDays.hasLeftWorkInMonth ? employeeData.LeftWorkDateGr.ToFarsi() : "";
var startWorkFa = employeeData.StartWorkDateGr.ToFarsi();
var workshop = _workShopRepository.GetDetails(workshopId);
@@ -1607,7 +1606,7 @@ public class InsuranceListApplication : IInsuranceListApplication
MaritalStatus = employeeData.MaritalStatus,
StartMonthCurrent = startMonthFa,
WorkingDays = employeeData.WorkingDays,
WorkingDays = workingDays.countWorkingDays,
StartWorkDate = startWorkFa,
StartWorkDateGr = employeeData.StartWorkDateGr,
LeftWorkDate = leftWorkFa,

View File

@@ -31,4 +31,13 @@ public class BankRepository:RepositoryBase<long,Bank>,IBankRepository
BankLogoPictureMediaId = x.BankLogoMediaId
}).ToList();
}
public List<BankSelectList> GetBanksForSelectList()
{
return context.Banks.Select(x => new BankSelectList()
{
Id = x.id,
Text = x.BankName
}).ToList();
}
}

View File

@@ -6,6 +6,8 @@ using CompanyManagment.App.Contracts.EmployeeBankInformation;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using _0_Framework.Exceptions;
namespace CompanyManagment.EFCore.Repository;
@@ -76,6 +78,76 @@ public class EmployeeBankInformationRepository : RepositoryBase<long, EmployeeBa
}).ToList();
}
public async Task<List<GroupedEmployeeBankInformationViewModel>> SearchAsync(long workshopId, EmployeeBankInformationSearchModel searchParams)
{
var bankInfoQuery = _companyContext.EmployeeBankInformationSet
.Where(x => x.WorkshopId == workshopId)
.Select(x => new
{
x.BankId,
x.EmployeeId,
x.WorkshopId,
}).AsQueryable();
if (searchParams.BankId > 0)
bankInfoQuery = bankInfoQuery.Where(x => x.BankId == searchParams.BankId);
if (searchParams.EmployeeId > 0)
bankInfoQuery = bankInfoQuery.Where(x => x.EmployeeId == searchParams.EmployeeId);
var bankInfoList = await bankInfoQuery.ToListAsync();
var employeeIds = bankInfoList.Select(x => x.EmployeeId).Distinct().ToList();
var employees = await _companyContext.Employees
.Where(x => employeeIds.Contains(x.id)).ToListAsync();
var personnelCodes = await _companyContext.PersonnelCodeSet
.Where(x=>employeeIds.Contains(x.EmployeeId) && x.WorkshopId == workshopId)
.ToDictionaryAsync(x=>x.EmployeeId,x=>x.PersonnelCode);
var bankIds = bankInfoList.Select(x=>x.BankId).Distinct().ToList();
var banks =await _companyContext.Banks.Where(x => bankIds.Contains(x.id)).ToListAsync();
//Get bank logos from account context
var mediaIds = banks.Select(x=>x.BankLogoMediaId).ToList();
var banksLogos = _accountContext.Medias.Where(y => mediaIds.Contains(y.id))
.Select(media => new { media.Path, MediaId = media.id }).ToList();
var banksWithLogo = banks.Select(x => new
{
Logo = banksLogos.FirstOrDefault(l => l.MediaId == x.BankLogoMediaId),
Bank = x
}).ToList();
return bankInfoList.GroupBy(x => x.EmployeeId).Select(x =>
{
var employee = employees.FirstOrDefault(e=>e.id == x.Key);
var selectBankId = x.Select(b => b.BankId);
var selectBanks = banksWithLogo
.Where(b => selectBankId.Contains(b.Bank.id)).ToList();
return new GroupedEmployeeBankInformationViewModel()
{
BankPicturesList =
selectBanks.Select(y => y.Logo.Path).ToList(),
EmployeeId = x.Key,
WorkshopId = workshopId,
EmployeeName = employee?.FullName ?? "",
TotalBankAccountsCount = x.Count(),
PersonnelCode = personnelCodes.TryGetValue(x.Key,out var value)?
value.ToString() :
"",
BankNamesList = selectBanks.Select(y => y.Bank.BankName).ToList()
};
}).ToList();
}
public void RemoveByEmployeeId(IEnumerable<EmployeeBankInformation> entities)
{
@@ -265,4 +337,55 @@ public class EmployeeBankInformationRepository : RepositoryBase<long, EmployeeBa
};
}).ToList();
}
public async Task<GetEmployeeBankInfoDetailsDto> GetDetailsByEmployeeIdAsync(long workshopId, long employeeId)
{
var employeeBankInfos =await _companyContext.EmployeeBankInformationSet
.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId).ToListAsync();
if (employeeBankInfos.Count == 0)
{
throw new NotFoundException("اطلاعات بانکی یافت نشد");
}
var employee = await _companyContext.Employees
.FirstOrDefaultAsync(x=>x.id == employeeId);
if (employee == null)
{
throw new NotFoundException("پرسنل مورد نظر یافت نشد");
}
var employeeFullName = employee.FullName;
var bankIds = employeeBankInfos.Select(x => x.BankId).Distinct().ToList();
var banks = await _companyContext.Banks.Where(x => bankIds.Contains(x.id)).ToListAsync();
var mediaIds = banks.Select(x => x.BankLogoMediaId).ToList();
var bankLogos = await _accountContext.Medias.Where(x=>mediaIds.Contains(x.id)).ToListAsync();
var res = new GetEmployeeBankInfoDetailsDto()
{
EmployeeId = employeeId,
EmployeeFullName = employeeFullName,
BankItems = employeeBankInfos.Select(x =>
{
var bank = banks.FirstOrDefault(y => y.id == x.BankId);
var bankLogo = bankLogos.FirstOrDefault(l => bank?.BankLogoMediaId == l.id);
return new GetEmployeeBankInfoDetailsBankItemDto()
{
BankId = x.BankId,
BankAccountNumber = x.BankAccountNumber,
BankLogoPath = bankLogo?.Path ?? "",
BankName = bank?.BankName ?? "",
CardNumber = x.CardNumber,
ShebaNumber = x.ShebaNumber,
IsDefault = x.IsDefault,
Id = x.id
};
}).ToList()
};
return res;
}
}

View File

@@ -209,38 +209,22 @@ public class CreateOrEditCheckoutCommandHandler : IBaseCommandHandler<CreateOrEd
}
}
////حقوق نهایی
//var monthlySalaryPay = (totalHoursWorked * monthlySalaryDefined) / mandatoryHours;
//// اگر اضافه کار داشت حقوق تعین شده به عنوان حقوق نهایی در نظر گرفته میشود
//monthlySalaryPay = monthlySalaryPay > monthlySalaryDefined ? monthlySalaryDefined : monthlySalaryPay;
//حقوق نهایی
var monthlySalaryPay = (totalHoursWorked * monthlySalaryDefined) / mandatoryHours;
// اگر اضافه کار داشت حقوق تعین شده به عنوان حقوق نهایی در نظر گرفته میشود
monthlySalaryPay = monthlySalaryPay > monthlySalaryDefined ? monthlySalaryDefined : monthlySalaryPay;
////حقوق کسر شده
//var deductionFromSalary = monthlySalaryDefined - monthlySalaryPay;
//new chang salary compute
var monthlySalaryPay = totalHoursWorked * monthlySalaryDefined;
//حقوق کسر شده
var deductionFromSalary = monthlySalaryDefined - monthlySalaryPay;
//زمان باقی مانده
var remainingTime = totalHoursWorked - mandatoryHours;
//تناسب به دقیقه
#region MyRegion
//var monthlySalaryDefinedTest = monthlySalaryDefined * mandatoryHours;
//var monthlySalaryPayTest = totalHoursWorked * monthlySalaryDefined;
////// اگر اضافه کار داشت حقوق تعین شده به عنوان حقوق نهایی در نظر گرفته میشود
//monthlySalaryPayTest = monthlySalaryPayTest > monthlySalaryDefinedTest ? monthlySalaryDefinedTest : monthlySalaryPayTest;
//////حقوق کسر شده
//var deductionFromSalaryTest = monthlySalaryDefinedTest - monthlySalaryPayTest;
#endregion
var computeResult = new ComputeResultDto
{
MandatoryHours = mandatoryHours,
MonthlySalaryPay = monthlySalaryPay,
DeductionFromSalary = 0 /*deductionFromSalary*/,
DeductionFromSalary = deductionFromSalary,
RemainingHours = remainingTime
};
Console.WriteLine(mandatoryHours);

View File

@@ -1,11 +1,10 @@
using DNTPersianUtils.Core;
using GozareshgirProgramManager.Application._Common.Interfaces;
using GozareshgirProgramManager.Application._Common.Interfaces;
using GozareshgirProgramManager.Application._Common.Models;
using GozareshgirProgramManager.Application.Modules.SalaryPaymentSettings.Queries.GetUserListWhoHaveSettings;
using GozareshgirProgramManager.Domain._Common;
using GozareshgirProgramManager.Domain.CheckoutAgg.Enums;
using Microsoft.EntityFrameworkCore;
using PersianDateTime = PersianTools.Core.PersianDateTime;
using PersianTools.Core;
namespace GozareshgirProgramManager.Application.Modules.Checkouts.Queries.GetUserToGropCreate;
@@ -46,8 +45,8 @@ public class GetUserToGroupCreatingQueryHandler : IBaseQueryHandler<GetUserToGro
"ایجاد فیش فقط برای ماه های گذشته امکان پذیر است");
//var lastMonthStart = lastMonth;
var lastMonthEnd = ((selectedDate.ToFarsi().FindeEndOfMonth())).ToGeorgianDateTime();
var lastMonthStart = lastMonth;
var lastMonthEnd = lastMonth;
var query =
await (from u in _context.Users
@@ -61,8 +60,8 @@ public class GetUserToGroupCreatingQueryHandler : IBaseQueryHandler<GetUserToGro
// LEFT JOIN
//فیش
join ch in _context.Checkouts
.Where(x => x.CheckoutStartDate < lastMonthEnd
&& x.CheckoutEndDate > selectedDate)
.Where(x => x.CheckoutStartDate < lastMonthStart
&& x.CheckoutEndDate >= lastMonthStart)
on u.Id equals ch.UserId into chJoin
from ch in chJoin.DefaultIfEmpty()

View File

@@ -0,0 +1,16 @@
using GozareshgirProgramManager.Application._Common.Interfaces;
using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.AddTaskToPhase;
/// <summary>
/// Command to add a task to an existing phase
/// </summary>
public record AddTaskToPhaseCommand(
Guid PhaseId,
string Name,
string? Description = null,
ProjectTaskPriority Priority = ProjectTaskPriority.Medium,
int OrderIndex = 0,
DateTime? DueDate = null
) : IBaseCommand;

View File

@@ -0,0 +1,53 @@
using GozareshgirProgramManager.Application._Common.Interfaces;
using GozareshgirProgramManager.Application._Common.Models;
using GozareshgirProgramManager.Domain._Common;
using GozareshgirProgramManager.Domain.ProjectAgg.Repositories;
using MediatR;
namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.AddTaskToPhase;
public class AddTaskToPhaseCommandHandler : IRequestHandler<AddTaskToPhaseCommand, OperationResult>
{
private readonly IProjectPhaseRepository _phaseRepository;
private readonly IUnitOfWork _unitOfWork;
public AddTaskToPhaseCommandHandler(
IProjectPhaseRepository phaseRepository,
IUnitOfWork unitOfWork)
{
_phaseRepository = phaseRepository;
_unitOfWork = unitOfWork;
}
public async Task<OperationResult> Handle(AddTaskToPhaseCommand request, CancellationToken cancellationToken)
{
try
{
// Get phase
var phase = await _phaseRepository.GetByIdAsync(request.PhaseId);
if (phase == null)
{
return OperationResult.NotFound("فاز یافت نشد");
}
// Add task
var task = phase.AddTask(request.Name, request.Description);
task.SetPriority(request.Priority);
task.SetOrderIndex(request.OrderIndex);
if (request.DueDate.HasValue)
{
task.SetDates(dueDate: request.DueDate);
}
// Save changes
await _unitOfWork.SaveChangesAsync(cancellationToken);
return OperationResult.Success();
}
catch (Exception ex)
{
return OperationResult.Failure($"خطا در افزودن تسک: {ex.Message}");
}
}
}

View File

@@ -4,5 +4,4 @@ using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.CreateProject;
public record CreateProjectCommand(string Name,ProjectHierarchyLevel Level,
ProjectTaskPriority? Priority,
Guid? ParentId):IBaseCommand;

View File

@@ -16,8 +16,7 @@ public class CreateProjectCommandHandler : IBaseCommandHandler<CreateProjectComm
private readonly IUnitOfWork _unitOfWork;
public CreateProjectCommandHandler(IProjectRepository projectRepository, IUnitOfWork unitOfWork,
IProjectTaskRepository projectTaskRepository, IProjectPhaseRepository projectPhaseRepository)
public CreateProjectCommandHandler(IProjectRepository projectRepository, IUnitOfWork unitOfWork, IProjectTaskRepository projectTaskRepository, IProjectPhaseRepository projectPhaseRepository)
{
_projectRepository = projectRepository;
_unitOfWork = unitOfWork;
@@ -56,8 +55,8 @@ public class CreateProjectCommandHandler : IBaseCommandHandler<CreateProjectComm
{
if (!request.ParentId.HasValue)
throw new BadRequestException("برای ایجاد فاز، شناسه پروژه الزامی است");
if (!_projectRepository.Exists(x => x.Id == request.ParentId.Value))
if(!_projectRepository.Exists(x=>x.Id == request.ParentId.Value))
{
throw new BadRequestException("والد پروژه یافت نشد");
}
@@ -70,15 +69,14 @@ public class CreateProjectCommandHandler : IBaseCommandHandler<CreateProjectComm
{
if (!request.ParentId.HasValue)
throw new BadRequestException("برای ایجاد تسک، شناسه فاز الزامی است");
if (!_projectPhaseRepository.Exists(x => x.Id == request.ParentId.Value))
if(!_projectPhaseRepository.Exists(x=>x.Id == request.ParentId.Value))
{
throw new BadRequestException("والد پروژه یافت نشد");
}
var priority = request.Priority ?? ProjectTaskPriority.Low;
var projectTask = new ProjectTask(request.Name, request.ParentId.Value, priority);
var projectTask = new ProjectTask(request.Name, request.ParentId.Value);
await _projectTaskRepository.CreateAsync(projectTask);
}
}
}

View File

@@ -10,10 +10,8 @@ public class GetProjectItemDto
public int Percentage { get; init; }
public ProjectHierarchyLevel Level { get; init; }
public Guid? ParentId { get; init; }
public TimeSpan TotalTime { get; init; }
public TimeSpan RemainingTime { get; init; }
public int TotalHours { get; set; }
public int Minutes { get; set; }
public AssignmentStatus Front { get; set; }
public AssignmentStatus Backend { get; set; }
public AssignmentStatus Design { get; set; }

View File

@@ -16,8 +16,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
_context = context;
}
public async Task<OperationResult<GetProjectsListResponse>> Handle(GetProjectsListQuery request,
CancellationToken cancellationToken)
public async Task<OperationResult<GetProjectsListResponse>> Handle(GetProjectsListQuery request, CancellationToken cancellationToken)
{
var projects = new List<GetProjectDto>();
var phases = new List<GetPhaseDto>();
@@ -52,14 +51,13 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
{
return new List<GetProjectDto>();
}
var entities = await query
.OrderByDescending(p => p.CreationDate)
.ToListAsync(cancellationToken);
var result = new List<GetProjectDto>();
foreach (var project in entities)
{
var (percentage, totalTime,remainingTime) = await CalculateProjectPercentage(project, cancellationToken);
var (percentage, totalTime) = await CalculateProjectPercentage(project, cancellationToken);
result.Add(new GetProjectDto
{
Id = project.Id,
@@ -67,12 +65,10 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
Level = ProjectHierarchyLevel.Project,
ParentId = null,
Percentage = percentage,
TotalTime = totalTime,
RemainingTime = remainingTime
TotalHours = (int)totalTime.TotalHours,
Minutes = totalTime.Minutes,
});
}
result = result.OrderByDescending(x => x.Percentage).ToList();
return result;
}
@@ -83,14 +79,13 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
{
query = query.Where(x => x.ProjectId == parentId);
}
var entities = await query
.OrderByDescending(p => p.CreationDate)
.ToListAsync(cancellationToken);
var result = new List<GetPhaseDto>();
foreach (var phase in entities)
{
var (percentage, totalTime,remainingTime) = await CalculatePhasePercentage(phase, cancellationToken);
var (percentage, totalTime) = await CalculatePhasePercentage(phase, cancellationToken);
result.Add(new GetPhaseDto
{
Id = phase.Id,
@@ -98,12 +93,10 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
Level = ProjectHierarchyLevel.Phase,
ParentId = phase.ProjectId,
Percentage = percentage,
TotalTime = totalTime,
RemainingTime = remainingTime
TotalHours = (int)totalTime.TotalHours,
Minutes = totalTime.Minutes,
});
}
result = result.OrderByDescending(x => x.Percentage).ToList();
return result;
}
@@ -114,7 +107,6 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
{
query = query.Where(x => x.PhaseId == parentId);
}
var entities = await query
.OrderByDescending(t => t.CreationDate)
.ToListAsync(cancellationToken);
@@ -126,7 +118,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
foreach (var task in entities)
{
var (percentage, totalTime,remainingTime) = await CalculateTaskPercentage(task, cancellationToken);
var (percentage, totalTime) = await CalculateTaskPercentage(task, cancellationToken);
var sections = await _context.TaskSections
.Include(s => s.Activities)
.Include(s => s.Skill)
@@ -148,12 +140,13 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
// محاسبه SpentTime و RemainingTime
var spentTime = TimeSpan.FromTicks(sections.Sum(s => s.Activities.Sum(a => a.GetTimeSpent().Ticks)));
var remainingTime = totalTime - spentTime;
// ساخت section DTOs برای تمام Skills
var sectionDtos = allSkills.Select(skill =>
{
var section = sections.FirstOrDefault(s => s.SkillId == skill.Id);
if (section == null)
{
// اگر section وجود نداشت، یک DTO با وضعیت Unassigned برمی‌گردانیم
@@ -191,20 +184,18 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
Level = ProjectHierarchyLevel.Task,
ParentId = task.PhaseId,
Percentage = percentage,
TotalTime = totalTime,
TotalHours = (int)totalTime.TotalHours,
Minutes = totalTime.Minutes,
SpentTime = spentTime,
RemainingTime = remainingTime,
Sections = sectionDtos,
Priority = task.Priority
});
}
result = result.OrderByDescending(x => x.Percentage).ToList();
return result;
}
private async Task SetSkillFlags<TItem>(List<TItem> items, CancellationToken cancellationToken)
where TItem : GetProjectItemDto
private async Task SetSkillFlags<TItem>(List<TItem> items, CancellationToken cancellationToken) where TItem : GetProjectItemDto
{
if (!items.Any())
return;
@@ -222,8 +213,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
}
private async Task SetSkillFlagsForProjects<TItem>(List<TItem> items, List<Guid> projectIds,
CancellationToken cancellationToken) where TItem : GetProjectItemDto
private async Task SetSkillFlagsForProjects<TItem>(List<TItem> items, List<Guid> projectIds, CancellationToken cancellationToken) where TItem : GetProjectItemDto
{
// For projects: gather all phases, then tasks, then sections
var phases = await _context.ProjectPhases
@@ -253,8 +243,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
}
}
private async Task SetSkillFlagsForPhases<TItem>(List<TItem> items, List<Guid> phaseIds,
CancellationToken cancellationToken) where TItem : GetProjectItemDto
private async Task SetSkillFlagsForPhases<TItem>(List<TItem> items, List<Guid> phaseIds, CancellationToken cancellationToken) where TItem : GetProjectItemDto
{
// For phases: gather tasks, then sections
var tasks = await _context.ProjectTasks
@@ -280,81 +269,68 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
}
}
private async Task<(int Percentage, TimeSpan TotalTime,TimeSpan RemainingTime)> CalculateProjectPercentage(Project project,
CancellationToken cancellationToken)
private async Task<(int Percentage, TimeSpan TotalTime)> CalculateProjectPercentage(Project project, CancellationToken cancellationToken)
{
var phases = await _context.ProjectPhases
.Where(ph => ph.ProjectId == project.Id)
.ToListAsync(cancellationToken);
if (!phases.Any())
return (0, TimeSpan.Zero,TimeSpan.Zero);
return (0, TimeSpan.Zero);
var phasePercentages = new List<int>();
var totalTime = TimeSpan.Zero;
var remainingTime = TimeSpan.Zero;
foreach (var phase in phases)
{
var (phasePercentage, phaseTime,phaseRemainingTime) = await CalculatePhasePercentage(phase, cancellationToken);
var (phasePercentage, phaseTime) = await CalculatePhasePercentage(phase, cancellationToken);
phasePercentages.Add(phasePercentage);
totalTime += phaseTime;
remainingTime += phaseRemainingTime;
}
var averagePercentage = phasePercentages.Any() ? (int)phasePercentages.Average() : 0;
return (averagePercentage, totalTime,remainingTime);
return (averagePercentage, totalTime);
}
private async Task<(int Percentage, TimeSpan TotalTime,TimeSpan RemainingTime)> CalculatePhasePercentage(ProjectPhase phase,
CancellationToken cancellationToken)
private async Task<(int Percentage, TimeSpan TotalTime)> CalculatePhasePercentage(ProjectPhase phase, CancellationToken cancellationToken)
{
var tasks = await _context.ProjectTasks
.Where(t => t.PhaseId == phase.Id)
.ToListAsync(cancellationToken);
if (!tasks.Any())
return (0, TimeSpan.Zero,TimeSpan.Zero);
return (0, TimeSpan.Zero);
var taskPercentages = new List<int>();
var totalTime = TimeSpan.Zero;
var remainingTime = TimeSpan.Zero;
foreach (var task in tasks)
{
var (taskPercentage, taskTime,taskRemainingTime) = await CalculateTaskPercentage(task, cancellationToken);
var (taskPercentage, taskTime) = await CalculateTaskPercentage(task, cancellationToken);
taskPercentages.Add(taskPercentage);
totalTime += taskTime;
remainingTime += taskRemainingTime;
}
var averagePercentage = taskPercentages.Any() ? (int)taskPercentages.Average() : 0;
return (averagePercentage, totalTime,remainingTime);
return (averagePercentage, totalTime);
}
private async Task<(int Percentage, TimeSpan TotalTime, TimeSpan RemainingTime)> CalculateTaskPercentage(
ProjectTask task, CancellationToken cancellationToken)
private async Task<(int Percentage, TimeSpan TotalTime)> CalculateTaskPercentage(ProjectTask task, CancellationToken cancellationToken)
{
var sections = await _context.TaskSections
.Include(s => s.Activities)
.Include(x => x.AdditionalTimes)
.Include(x=>x.AdditionalTimes)
.Where(s => s.TaskId == task.Id)
.ToListAsync(cancellationToken);
if (!sections.Any())
return (0, TimeSpan.Zero, TimeSpan.Zero);
return (0, TimeSpan.Zero);
var sectionPercentages = new List<int>();
var totalTime = TimeSpan.Zero;
var spentTime = TimeSpan.Zero;
foreach (var section in sections)
{
var (sectionPercentage, sectionTime) = CalculateSectionPercentage(section);
var sectionSpent = TimeSpan.FromTicks(section.Activities.Sum(x => x.GetTimeSpent().Ticks));
sectionPercentages.Add(sectionPercentage);
totalTime += sectionTime;
spentTime += sectionSpent;
}
var remainingTime = totalTime - spentTime;
var averagePercentage = sectionPercentages.Any() ? (int)sectionPercentages.Average() : 0;
return (averagePercentage, totalTime, remainingTime);
return (averagePercentage, totalTime);
}
private static (int Percentage, TimeSpan TotalTime) CalculateSectionPercentage(TaskSection section)
{
return ((int)section.GetProgressPercentage(), section.FinalEstimatedHours);
return ((int)section.GetProgressPercentage(),section.FinalEstimatedHours);
}
private static AssignmentStatus GetAssignmentStatus(TaskSection? section)
@@ -365,7 +341,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
// بررسی وجود user
bool hasUser = section.CurrentAssignedUserId > 0;
// بررسی وجود time (InitialEstimatedHours بزرگتر از صفر باشد)
bool hasTime = section.InitialEstimatedHours > TimeSpan.Zero;
@@ -380,4 +356,5 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
// تعیین تکلیف نشده: نه user دارد نه time
return AssignmentStatus.Unassigned;
}
}
}

View File

@@ -9,8 +9,8 @@ public class GetTaskDto
public int Percentage { get; init; }
public ProjectHierarchyLevel Level { get; init; }
public Guid? ParentId { get; init; }
public TimeSpan TotalTime { get; set; }
public int TotalHours { get; set; }
public int Minutes { get; set; }
// Task-specific fields
public TimeSpan SpentTime { get; init; }

View File

@@ -7,6 +7,6 @@ namespace GozareshgirProgramManager.Application.Modules.Projects.Queries.Project
public record ProjectBoardListQuery: IBaseQuery<List<ProjectBoardListResponse>>
{
public long? UserId { get; set; }
public string? ProjectName { get; set; }
public string? SearchText { get; set; }
public TaskSectionStatus? Status { get; set; }
}

View File

@@ -46,11 +46,11 @@ public class ProjectBoardListQueryHandler : IBaseQueryHandler<ProjectBoardListQu
queryable = queryable.Where(x => x.CurrentAssignedUserId == request.UserId);
}
if (!string.IsNullOrWhiteSpace(request.ProjectName))
if (!string.IsNullOrWhiteSpace(request.SearchText))
{
queryable = queryable.Where(x=>x.Task.Name.Contains(request.ProjectName)
|| x.Task.Phase.Name.Contains(request.ProjectName)
|| x.Task.Phase.Project.Name.Contains(request.ProjectName));
queryable = queryable.Where(x=>x.Task.Name.Contains(request.SearchText)
|| x.Task.Phase.Name.Contains(request.SearchText)
|| x.Task.Phase.Project.Name.Contains(request.SearchText));
}
var data = await queryable.ToListAsync(cancellationToken);
@@ -70,9 +70,6 @@ public class ProjectBoardListQueryHandler : IBaseQueryHandler<ProjectBoardListQu
.OrderByDescending(x => x.CurrentAssignedUserId == currentUserId)
.ThenByDescending(x=>x.Task.Priority)
.ThenBy(x => GetStatusOrder(x.Status))
.ThenBy(x=>x.Task.Phase.ProjectId)
.ThenBy(x=>x.Task.PhaseId)
.ThenBy(x=>x.TaskId)
.Select(x =>
{
// محاسبه یکبار برای هر Activity و Cache کردن نتیجه

View File

@@ -62,7 +62,8 @@ public class ProjectSetTimeDetailsQueryHandler
var res = new ProjectSetTimeResponse(
skills.Select(skill =>
{
var section = task.Sections
var section = task
.Sections
.FirstOrDefault(x => x.SkillId == skill.Id);
var user = users.FirstOrDefault(x => x.Id == section?.OriginalAssignedUserId);
return new ProjectSetTimeResponseSkill

View File

@@ -41,7 +41,15 @@ public class ProjectPhase : ProjectHierarchyNode
public ProjectDeployStatus DeployStatus { get; set; }
#region Task Management
public ProjectTask AddTask(string name, string? description = null)
{
var task = new ProjectTask(name, Id, description);
_tasks.Add(task);
AddDomainEvent(new TaskAddedEvent(task.Id, Id, name));
return task;
}
public void RemoveTask(Guid taskId)
{
var task = _tasks.FirstOrDefault(t => t.Id == taskId);

View File

@@ -16,11 +16,11 @@ public class ProjectTask : ProjectHierarchyNode
_sections = new List<TaskSection>();
}
public ProjectTask(string name, Guid phaseId,ProjectTaskPriority priority, string? description = null) : base(name, description)
public ProjectTask(string name, Guid phaseId, string? description = null) : base(name, description)
{
PhaseId = phaseId;
_sections = new List<TaskSection>();
Priority = priority;
Priority = ProjectTaskPriority.Low;
AddDomainEvent(new TaskCreatedEvent(Id, phaseId, name));
}

View File

@@ -0,0 +1,106 @@
using _0_Framework.Application;
using CompanyManagment.App.Contracts.EmployeeBankInformation;
using CompanyManagement.Infrastructure.Excel.EmployeeBankInfo;
using Microsoft.AspNetCore.Mvc;
using ServiceHost.BaseControllers;
namespace ServiceHost.Areas.Client.Controllers;
public class EmployeeBankInfoController : ClientBaseController
{
private readonly IEmployeeBankInformationApplication _employeeBankInformationApplication;
private readonly long _workshopId;
public EmployeeBankInfoController(IEmployeeBankInformationApplication employeeBankInformationApplication,
IAuthHelper authHelper)
{
_employeeBankInformationApplication = employeeBankInformationApplication;
_workshopId = authHelper.GetWorkshopId();
}
[HttpGet]
public async Task<ActionResult<List<GroupedEmployeeBankInformationViewModel>>> GetList(
EmployeeBankInformationSearchModel searchModel)
{
return await _employeeBankInformationApplication.SearchAsync(_workshopId, searchModel);
}
[HttpGet("{employeeId:long}")]
public async Task<ActionResult<GetEmployeeBankInfoDetailsDto>> GetDetails(long employeeId)
{
return await _employeeBankInformationApplication.GetDetailsByEmployeeIdAsync(_workshopId, employeeId);
}
[HttpPost]
public ActionResult<OperationResult> Create([FromBody]CreateEmployeeInformation command)
{
command.WorkshopId = _workshopId;
return _employeeBankInformationApplication.Create(command);
}
[HttpPut]
public ActionResult<OperationResult> Edit([FromBody]EditEmployeeInformation command)
{
command.WorkshopId = _workshopId;
return _employeeBankInformationApplication.Edit(command);
}
[HttpDelete("delete-by-employee/{employeeId:long}")]
public ActionResult<OperationResult> Remove(long employeeId)
{
return _employeeBankInformationApplication.RemoveByEmployeeId(_workshopId, employeeId);
}
[HttpDelete("delete-one/{id:long}")]
public IActionResult OnPostDelete(long id)
{
var result = _employeeBankInformationApplication.Remove(id);
return new JsonResult(new
{
success = result.IsSuccedded,
message = result.Message,
});
}
[HttpPost("excel")]
public ActionResult DownloadExcel([FromBody]DownloadExcelRequest request)
{
var employeeBankInformationViewModelForExcels = _employeeBankInformationApplication.SearchForExcel(_workshopId,
new EmployeeBankInformationSearchModel() { EmployeeBankInfoIds = request.Ids });
var resultViewModel = employeeBankInformationViewModelForExcels.Select(x => new EmployeeBankInfoExcelViewModel
{
Name = x.EmployeeName,
BankAccounts = x.BankInformationList.Select(b => new BankInfoExcelViewModel()
{
IsDefault = b.IsDefault,
ShebaNumber = b.ShebaNumber,
AccountNumber = b.BankAccountNumber,
BankName = b.BankName,
CardNumber = b.CardNumber
}).ToList()
}).ToList();
var bytes = EmployeeBankInfoExcelGenerator.Generate(resultViewModel);
return File(bytes,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
$"اطلاعات بانکی پرسنل.xlsx");
}
[HttpPost("set-default/{bankId:long}")]
public IActionResult SetDefault(long bankId)
{
var result = _employeeBankInformationApplication.SetDefault(_workshopId, bankId);
return new JsonResult(new
{
success = result.IsSuccedded,
message = result.Message,
id = result.SendId
});
}
}
public class DownloadExcelRequest
{
public List<long> Ids { get; set; }
}

View File

@@ -8,6 +8,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Security.Claims;
using CompanyManagement.Infrastructure.Excel.EmployeeBankInfo;
using CompanyManagment.App.Contracts.Bank;
using CompanyManagement.Infrastructure.Excel.EmployeeBankInfo;
namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo
{
@@ -28,7 +30,11 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo
private readonly IWebHostEnvironment _hostEnvironment;
public IndexModel(IPasswordHasher passwordHasher, IWorkshopApplication workshopApplication, IHttpContextAccessor contextAccessor, IAuthHelper authHelper, IEmployeeBankInformationApplication employeeBankInformationApplication, IEmployeeApplication employeeApplication, IBankApplication bankApplication, IWebHostEnvironment hostEnvironment)
public IndexModel(IPasswordHasher passwordHasher, IWorkshopApplication workshopApplication,
IHttpContextAccessor contextAccessor, IAuthHelper authHelper,
IEmployeeBankInformationApplication employeeBankInformationApplication,
IEmployeeApplication employeeApplication, IBankApplication bankApplication,
IWebHostEnvironment hostEnvironment)
{
_passwordHasher = passwordHasher;
_workshopApplication = workshopApplication;
@@ -64,7 +70,8 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo
public IActionResult OnGetEmployeeBankInfoListAjax(EmployeeBankInformationSearchModel searchModel)
{
var resultData = _employeeBankInformationApplication.Search(_workshopId, searchModel);
var resultData = _employeeBankInformationApplication
.Search(_workshopId, searchModel);
return new JsonResult(new
{
success = true,
@@ -242,4 +249,4 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo
$"اطلاعات بانکی پرسنل.xlsx");
}
}
}
}

View File

@@ -0,0 +1,25 @@
using CompanyManagment.App.Contracts.Bank;
using Microsoft.AspNetCore.Mvc;
using ServiceHost.BaseControllers;
namespace ServiceHost.Controllers;
public class BankController : GeneralBaseController
{
private readonly IBankApplication _bankApplication;
public BankController(IBankApplication bankApplication)
{
_bankApplication = bankApplication;
}
/// <summary>
/// دریافت لیست بانک‌ها برای SelectList
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult<List<BankSelectList>> GetBankList()
{
return _bankApplication.GetBanksForSelectList();
}
}