RollCall Control For client in admin - checkoutPrint change
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using Company.Domain.RollCallAgg;
|
||||
using CompanyManagment.EFCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Query.AdminReports.Models;
|
||||
using System.Data;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
||||
|
||||
namespace Query.AdminReports.Handlers
|
||||
{
|
||||
public interface IGetWorkshopWithRollCallHandler
|
||||
{
|
||||
List<WorkshopWithRollCallServiceQueryModel> Handle(WorkshopWithRollCallServiceQueryParameters parameters);
|
||||
}
|
||||
|
||||
public class GetWorkshopWithRollCallHandler: IGetWorkshopWithRollCallHandler
|
||||
{
|
||||
private readonly CompanyContext _companyContext;
|
||||
|
||||
public GetWorkshopWithRollCallHandler(CompanyContext companyContext)
|
||||
{
|
||||
_companyContext = companyContext;
|
||||
}
|
||||
|
||||
public List<WorkshopWithRollCallServiceQueryModel> Handle(WorkshopWithRollCallServiceQueryParameters parameters)
|
||||
{
|
||||
var now = DateTime.Now.Date;
|
||||
var lastWeek = now.AddDays(-7);
|
||||
|
||||
|
||||
//workshop filter by parameters
|
||||
var rollCallServiceQuery = _companyContext.RollCallServices
|
||||
.Where(x => x.StartService.Date <= DateTime.Now.Date && x.EndService.Date >= DateTime.Now.Date);
|
||||
var allWorkshops = _companyContext.Workshops.Select(x => new { x.id, x.WorkshopFullName });
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(parameters.WorkshopName))
|
||||
allWorkshops = allWorkshops.Where(x => x.WorkshopFullName.Contains(parameters.WorkshopName));
|
||||
if (!string.IsNullOrWhiteSpace(parameters.RollCallServiceType))
|
||||
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.ServiceType == parameters.RollCallServiceType);
|
||||
|
||||
var workshopsWithService = rollCallServiceQuery.Join(allWorkshops, x => x.WorkshopId, y => y.id, (rcs, workshop) =>
|
||||
new WorkshopWithRollCallServiceQueryModel()
|
||||
{
|
||||
WorkshopId = workshop.id,
|
||||
RollCallServiceType = rcs.ServiceType,
|
||||
WorkshopName = workshop.WorkshopFullName
|
||||
});
|
||||
|
||||
|
||||
//workshop population
|
||||
var workshopLeftWorks = _companyContext.Workshops.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() }).ToList();
|
||||
|
||||
|
||||
|
||||
var activeEmployees = _companyContext.RollCallEmployees.Include(x => x.EmployeesStatus).Where(x => x.EmployeesStatus.Any(y =>
|
||||
y.EndDate.Date >= now) && workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId)).Select(x => new { x.WorkshopId, x.EmployeeId });
|
||||
|
||||
var lastWeekRollCalls = _companyContext.RollCalls.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.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();
|
||||
var lastWeekRollCallsList = lastWeekRollCalls.ToList();
|
||||
var leavesList = leaves.ToList();
|
||||
var workshopsWithServiceList = workshopsWithService.ToList();
|
||||
return workshopsWithServiceList.Select(x => new WorkshopWithRollCallServiceQueryModel()
|
||||
{
|
||||
WorkshopId = x.WorkshopId,
|
||||
RollCallServiceType = x.RollCallServiceType,
|
||||
WorkshopName = x.WorkshopName,
|
||||
ActiveEmployeesCount = activeEmployeesList.Count(y => y.WorkshopId == x.WorkshopId),
|
||||
ActiveEmployeesWithRollCallInLastWeekCount = activeEmployeesList.Count(y => y.WorkshopId == x.WorkshopId &&
|
||||
lastWeekRollCalls.Contains(y.EmployeeId) && !leavesList.Contains(y.EmployeeId)),
|
||||
TotalEmployeesCount = workshopsWorkingEmployeesList.FirstOrDefault(y => y.WorkshopId == x.WorkshopId).TotalWorkingEmployeesCount
|
||||
}).ToList();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Query.AdminReports.Models;
|
||||
|
||||
public class WorkshopWithRollCallServiceQueryParameters
|
||||
{
|
||||
public string WorkshopName { get; set; }
|
||||
public string RollCallServiceType { get; set; }
|
||||
}
|
||||
24
Query/AdminReports/Models/WorkshopWithRollCallViewModel.cs
Normal file
24
Query/AdminReports/Models/WorkshopWithRollCallViewModel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace Query.AdminReports.Models
|
||||
{
|
||||
public class WorkshopWithRollCallServiceQueryModel
|
||||
{
|
||||
public string WorkshopName { get; set; }
|
||||
public long WorkshopId { get; set; }
|
||||
public string RollCallServiceType { get; set; }
|
||||
|
||||
public int TotalEmployeesCount { get; set; }
|
||||
|
||||
public int ActiveEmployeesCount { get; set; }
|
||||
|
||||
public int ActiveEmployeesWithRollCallInLastWeekCount { get; set; }
|
||||
|
||||
|
||||
public float ActiveEmployeesWithRollCallPercentage
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((float)ActiveEmployeesWithRollCallInLastWeekCount / ActiveEmployeesCount) * 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Globalization;
|
||||
using CompanyManagment.EFCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Query.ClientReports.Models;
|
||||
|
||||
namespace Query.ClientReports.Handler
|
||||
{
|
||||
public class NotSignedContractEmployeesQueryHandler
|
||||
{
|
||||
private readonly CompanyContext _companyContext;
|
||||
|
||||
public NotSignedContractEmployeesQueryHandler(CompanyContext companyContext)
|
||||
{
|
||||
_companyContext = companyContext;
|
||||
}
|
||||
|
||||
public List<NotSignedContractEmployeesQueryModel> Handle(long workshopId, int yearFa, int monthFa)
|
||||
{
|
||||
var date = new DateTime(yearFa, monthFa, 1, new PersianCalendar());
|
||||
|
||||
int nextMonth;
|
||||
int nextMonthYear;
|
||||
if (monthFa == 12)
|
||||
{
|
||||
nextMonthYear = yearFa + 1;
|
||||
nextMonth = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextMonth = monthFa + 1;
|
||||
nextMonthYear = yearFa;
|
||||
}
|
||||
|
||||
var nextMonthDate = new DateTime(nextMonthYear, nextMonth, 1, new PersianCalendar());
|
||||
var query = _companyContext.Employees.Include(x => x.Contracts).Where(x =>
|
||||
!x.Contracts.Any(y => y.ContarctStart < nextMonthDate && y.ContractEnd >= date && y.Signature == "0"));
|
||||
|
||||
return query.Select(x => new NotSignedContractEmployeesQueryModel()
|
||||
{
|
||||
MonthFa = monthFa,
|
||||
YearFa = yearFa,
|
||||
EmployeeFullName = x.FName + " " + x.LName,
|
||||
EmployeeId = x.id
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
namespace Query.ClientReports.Models
|
||||
{
|
||||
public class NotSignedContractEmployeesQueryModel
|
||||
{
|
||||
public long EmployeeId { get; set; }
|
||||
public string EmployeeFullName { get; set; }
|
||||
public int YearFa { get; set; }
|
||||
public int MonthFa { get; set; }
|
||||
}
|
||||
}
|
||||
13
Query/Query.csproj
Normal file
13
Query/Query.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CompanyManagment.EFCore\CompanyManagment.EFCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user