Compare commits

...

3 Commits

6 changed files with 121 additions and 54 deletions

View File

@@ -124,7 +124,7 @@ public class FineRepository : RepositoryBase<long, Fine>, IFineRepository
}
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
var list = query.ToList().Select(x => new FineViewModel()
var list = query.OrderByDescending(x=>x.FineDate).ToList().Select(x => new FineViewModel()
{
Amount = x.Amount.ToMoney(),
AmountDouble = x.Amount,

View File

@@ -97,7 +97,7 @@ public class LoanRepository : RepositoryBase<long, Loan>, ILoanRepository
query = query.Where(x => x.StartInstallmentPayment >= startDate && x.StartInstallmentPayment <= endDate);
}
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
var list = query.ToList().Select(x => new LoanViewModel()
var list = query.OrderByDescending(x=>x.StartInstallmentPayment).ToList().Select(x => new LoanViewModel()
{
Amount = x.Amount.ToMoney(),
AmountDouble = x.Amount,

View File

@@ -6,6 +6,7 @@ using _0_Framework.InfraStructure;
using Company.Domain.RewardAgg;
using CompanyManagment.App.Contracts.Reward;
using Microsoft.EntityFrameworkCore;
using SharpCompress.Compressors.Xz;
namespace CompanyManagment.EFCore.Repository;
@@ -119,12 +120,12 @@ public class RewardRepository : RepositoryBase<long, Reward>, IRewardRepository
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
var list = query.ToList().Select(x => new RewardViewModel
var list = query.ToList().OrderByDescending(x=>x.GrantDate).Select(x => new RewardViewModel
{
WorkshopId = x.WorkshopId,
Amount = x.Amount.ToMoney(),
AmountDouble = x.Amount,
Description = x.Description,
Description = x.Description ?? "",
EmployeeFullName = employees.FirstOrDefault(e => e.id == x.EmployeeId).FullName,
EmployeeId = x.EmployeeId,
GrantDateFa = x.GrantDate.ToFarsi(),

View File

@@ -9,20 +9,20 @@ using WorkFlow.Application.Contracts.WorkFlow;
namespace Query.AdminReports.Handlers
{
public interface IGetWorkshopWithRollCallHandler
{
List<WorkshopWithRollCallServiceQueryModel> Handle(WorkshopWithRollCallServiceQueryParameters parameters);
}
public interface IGetWorkshopWithRollCallHandler
{
List<WorkshopWithRollCallServiceQueryModel> Handle(WorkshopWithRollCallServiceQueryParameters parameters);
}
public class GetWorkshopWithRollCallHandler: IGetWorkshopWithRollCallHandler
{
public class GetWorkshopWithRollCallHandler : IGetWorkshopWithRollCallHandler
{
private readonly CompanyContext _companyContext;
private readonly IWorkFlowApplication workFlowApplication;
public GetWorkshopWithRollCallHandler(CompanyContext companyContext, IWorkFlowApplication workFlowApplication)
{
_companyContext = companyContext;
this.workFlowApplication = workFlowApplication;
_companyContext = companyContext;
this.workFlowApplication = workFlowApplication;
}
public List<WorkshopWithRollCallServiceQueryModel> Handle(WorkshopWithRollCallServiceQueryParameters parameters)
@@ -30,7 +30,6 @@ namespace Query.AdminReports.Handlers
var now = DateTime.Now.Date;
var lastWeek = now.AddDays(-7);
//workshop filter by parameters
var rollCallServiceQuery = _companyContext.RollCallServices.AsSplitQuery();
@@ -46,35 +45,49 @@ namespace Query.AdminReports.Handlers
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.ServiceType == parameters.RollCallServiceType);
if (parameters.FilterMode == FilterMode.Active)
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.StartService.Date <= now && x.EndService.Date >= now);
else if (parameters.FilterMode == FilterMode.DeActive)
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.EndService.Date < now || x.StartService.Date > now);
rollCallServiceQuery =
rollCallServiceQuery.Where(x => x.StartService.Date <= now && x.EndService.Date >= now);
var workshopsWithService = rollCallServiceQuery.Join(allWorkshops, x => x.WorkshopId, y => y.id, (rcs, workshop) =>
new WorkshopWithRollCallServiceQueryModel()
{
WorkshopId = workshop.id,
RollCallServiceType = rcs.ServiceType,
WorkshopName = workshop.WorkshopFullName,
MaxPersonValid = rcs.MaxPersonValid,
IsActive = rcs.StartService <= DateTime.Now && rcs.EndService >= DateTime.Now,
ServiceStart = rcs.StartService,
ServiceEnd = rcs.EndService
});
else if (parameters.FilterMode == FilterMode.DeActive)
rollCallServiceQuery =
rollCallServiceQuery.Where(x => x.EndService.Date < now || x.StartService.Date > now);
var workshopsWithService = rollCallServiceQuery.Join(allWorkshops, x => x.WorkshopId, y => y.id,
(rcs, workshop) =>
new WorkshopWithRollCallServiceQueryModel()
{
WorkshopId = workshop.id,
RollCallServiceType = rcs.ServiceType,
WorkshopName = workshop.WorkshopFullName,
MaxPersonValid = rcs.MaxPersonValid,
IsActive = rcs.StartService <= DateTime.Now && rcs.EndService >= DateTime.Now,
ServiceStart = rcs.StartService,
ServiceEnd = rcs.EndService
});
//workshop population
var workshopLeftWorks = _companyContext.Workshops.AsSplitQuery().Where(x => workshopsWithService.Any(y => y.WorkshopId == x.id)).Include(x => x.LeftWorks).Include(x => x.LeftWorkInsurances)
.Select(x => new
{
WorkshopId = x.id,
LeftWorks = x.LeftWorks.Where(y => y.StartWorkDate <= lastWeek && y.LeftWorkDate > now).Select(y => y.EmployeeId),
LeftWorkInsurances = x.LeftWorkInsurances.Where(y => y.StartWorkDate <= lastWeek && (y.LeftWorkDate > now || y.LeftWorkDate == null)).Select(y => y.EmployeeId)
}).ToList();
var workshopLeftWorks = _companyContext.Workshops.AsSplitQuery()
.Where(x => workshopsWithService.Any(y => y.WorkshopId == x.id)).Include(x => x.LeftWorks)
.Include(x => x.LeftWorkInsurances)
.Select(x => new
{
WorkshopId = x.id,
LeftWorks = x.LeftWorks.Where(y => y.StartWorkDate <= lastWeek && y.LeftWorkDate > now)
.Select(y => y.EmployeeId),
LeftWorkInsurances = x.LeftWorkInsurances
.Where(y => y.StartWorkDate <= lastWeek && (y.LeftWorkDate > now || y.LeftWorkDate == null))
.Select(y => y.EmployeeId)
}).ToList();
var workshopsWorkingEmployeesList = workshopLeftWorks
.Select(x => new { x.WorkshopId, TotalWorkingEmployeesCount = x.LeftWorks.Concat(x.LeftWorkInsurances).Distinct().Count(), EmployeeIds = x.LeftWorks.Concat(x.LeftWorkInsurances).Distinct() }).ToList();
.Select(x =>
new
{
x.WorkshopId,
TotalWorkingEmployeesCount = x.LeftWorks.Concat(x.LeftWorkInsurances).Distinct().Count(),
EmployeeIds = x.LeftWorks.Concat(x.LeftWorkInsurances).Distinct()
}).ToList();
var activeEmployees = _companyContext.RollCallEmployees.AsSplitQuery()
@@ -83,15 +96,25 @@ namespace Query.AdminReports.Handlers
workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId))
.Select(x => new { x.WorkshopId, x.EmployeeId });
var lastWeekRollCalls = _companyContext.RollCalls.AsSplitQuery().Where(x => x.StartDate.HasValue && x.StartDate.Value >= lastWeek
&& workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId)).GroupBy(x => x.EmployeeId).Select(x => x.Key);
var lastWeekRollCalls = _companyContext.RollCalls.AsSplitQuery()
.Where(x => x.StartDate.HasValue &&
x.StartDate.Value >= lastWeek
&& workshopsWithService
.Any(y => y.WorkshopId == x.WorkshopId))
.GroupBy(x => x.EmployeeId)
.Select(x => x.Key);
var leaves = _companyContext.LeaveList.AsSplitQuery().Where(x => x.StartLeave <= lastWeek && x.EndLeave >= now && (x.LeaveType == "استعلاجی" || x.PaidLeaveType == "روزانه")
&& workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId)).Select(x => x.EmployeeId);
var leaves = _companyContext.LeaveList.AsSplitQuery().Where(x =>
x.StartLeave <= lastWeek && x.EndLeave >= now &&
(x.LeaveType == "استعلاجی" || x.PaidLeaveType == "روزانه")
&& workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId))
.Select(x => x.EmployeeId);
var activeEmployeesList = activeEmployees.ToList().Where(x => workshopsWorkingEmployeesList.Any(w => w.WorkshopId == x.WorkshopId && w.EmployeeIds.Contains(x.EmployeeId)));
var activeEmployeesList = activeEmployees.ToList().Where(x =>
workshopsWorkingEmployeesList.Any(w =>
w.WorkshopId == x.WorkshopId && w.EmployeeIds.Contains(x.EmployeeId)));
var lastWeekRollCallsList = lastWeekRollCalls.ToList();
var leavesList = leaves.ToList();
var workshopsWithServiceList = workshopsWithService.ToList();
@@ -107,12 +130,13 @@ namespace Query.AdminReports.Handlers
MaxPersonValid = x.MaxPersonValid,
WorkshopName = x.WorkshopName,
ActiveEmployeesCount = activeEmployeesList.Count(y => y.WorkshopId == x.WorkshopId),
ActiveEmployeesWithRollCallInLastWeekCount = activeEmployeesList.Count(y => y.WorkshopId == x.WorkshopId &&
ActiveEmployeesWithRollCallInLastWeekCount = activeEmployeesList.Count(y =>
y.WorkshopId == x.WorkshopId &&
lastWeekRollCallsList.Contains(y.EmployeeId) && !leavesList.Contains(y.EmployeeId)),
TotalEmployeesCount = workshopsWorkingEmployeesList.FirstOrDefault(y => y.WorkshopId == x.WorkshopId)?.TotalWorkingEmployeesCount ?? 0,
TotalEmployeesCount = workshopsWorkingEmployeesList
.FirstOrDefault(y => y.WorkshopId == x.WorkshopId)?.TotalWorkingEmployeesCount ?? 0,
//UndoneWorkFlowsCount = workFlowApplication.GetAllWorkFlowCount(x.WorkshopId).Result
}).OrderByDescending(x => x.IsActive).ToList();
}
}
}
}

View File

@@ -13,15 +13,8 @@
public int ActiveEmployeesWithRollCallInLastWeekCount { get; set; }
public int UndoneWorkFlowsCount { get; set; }
public float ActiveEmployeesWithRollCallPercentage
{
get
{
return ((float)ActiveEmployeesWithRollCallInLastWeekCount / ActiveEmployeesCount) * 100;
}
}
public float ActiveEmployeesWithRollCallPercentage => ActiveEmployeesCount == 0 ? 0f : ((float)ActiveEmployeesWithRollCallInLastWeekCount / ActiveEmployeesCount) * 100f;
public int MaxPersonValid { get; set; }
public bool IsActive { get; set; }

View File

@@ -0,0 +1,49 @@
using _0_Framework.Application;
using AccountManagement.Application.Contracts.Account;
using Microsoft.AspNetCore.Mvc;
using Query.AdminReports.Handlers;
using Query.AdminReports.Models;
using ServiceHost.BaseControllers;
using WorkFlow.Application.Contracts.WorkFlow;
namespace ServiceHost.Areas.Admin.Controllers;
public class RollCallController:AdminBaseController
{
private readonly IGetWorkshopWithRollCallHandler _workshopWithRollCallHandler;
private readonly IWorkFlowApplication _workFlowApplication;
private readonly long _currentAccountId;
public RollCallController(IGetWorkshopWithRollCallHandler workshopWithRollCallHandler,IAuthHelper _authHelper, IWorkFlowApplication workFlowApplication)
{
_workshopWithRollCallHandler = workshopWithRollCallHandler;
_workFlowApplication = workFlowApplication;
_currentAccountId = _authHelper.CurrentAccountId();
}
[HttpGet("report")]
public ActionResult<List<WorkshopWithRollCallServiceQueryModel>> GetRollCallReport([FromQuery] WorkshopWithRollCallServiceQueryParameters searchModel)
{
var result = _workshopWithRollCallHandler.Handle(searchModel);
return result;
}
[HttpGet("report/workshops-select-list")]
public ActionResult<List<WorkshopSelectList>> GetWorkshopsSelectList()
{
var result = _workshopWithRollCallHandler.Handle(new WorkshopWithRollCallServiceQueryParameters())
.Select(x => new WorkshopSelectList
{
Id = x.WorkshopId,
WorkshopFullName = x.WorkshopName
}).Distinct().ToList();
return result;
}
[HttpGet("repoert/workfloecount/{workshopId}")]
public async Task<ActionResult<int>> GetWorkFlowCountByWorkshopId(long workshopId)
{
var result = await _workFlowApplication.GetAllWorkFlowCount(workshopId, _currentAccountId);
return result;
}
}