Getting all employees in attendence module regardless of project
This commit is contained in:
parent
d8329f1fab
commit
bab03a8e47
@ -608,6 +608,20 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
var featureIds = await generalHelper.GetFeatureIdsByTenentIdAsync(tenantId);
|
var featureIds = await generalHelper.GetFeatureIdsByTenentIdAsync(tenantId);
|
||||||
_logger.LogInfo("Enabled features for TenantId: {TenantId} -> {FeatureIds}", tenantId, string.Join(",", featureIds));
|
_logger.LogInfo("Enabled features for TenantId: {TenantId} -> {FeatureIds}", tenantId, string.Join(",", featureIds));
|
||||||
|
|
||||||
|
if (!(featureIds?.Any() ?? false))
|
||||||
|
{
|
||||||
|
featureIds = new List<Guid>
|
||||||
|
{
|
||||||
|
new Guid("a4e25142-449b-4334-a6e5-22f70e4732d7"), // Expense Management feature
|
||||||
|
new Guid("81ab8a87-8ccd-4015-a917-0627cee6a100"), // Employee Management feature
|
||||||
|
new Guid("52c9cf54-1eb2-44d2-81bb-524cf29c0a94"), // Attendance Management feature
|
||||||
|
new Guid("a8cf4331-8f04-4961-8360-a3f7c3cc7462"), // Document Management feature
|
||||||
|
new Guid("be3b3afc-6ccf-4566-b9b6-aafcb65546be"), // Masters Management feature
|
||||||
|
new Guid("39e66f81-efc6-446c-95bd-46bff6cfb606"), // Directory Management feature
|
||||||
|
new Guid("6d4c82d6-dbce-48ab-b8b8-f785f4d8c914") // Organization Management feature
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Aggregate menus based on enabled features
|
// Aggregate menus based on enabled features
|
||||||
var response = featureIds
|
var response = featureIds
|
||||||
.Where(id => featureMenus.ContainsKey(id))
|
.Where(id => featureMenus.ContainsKey(id))
|
||||||
|
@ -190,17 +190,26 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
|
|
||||||
var result = new List<EmployeeAttendanceVM>();
|
var result = new List<EmployeeAttendanceVM>();
|
||||||
//Attendance? attendance = null;
|
//Attendance? attendance = null;
|
||||||
ProjectAllocation? teamMember = null;
|
|
||||||
|
|
||||||
if (dateFrom == null) fromDate = DateTime.UtcNow.Date;
|
if (dateFrom == null) fromDate = DateTime.UtcNow.Date;
|
||||||
if (dateTo == null && dateFrom != null) toDate = fromDate.AddDays(-1);
|
if (dateTo == null && dateFrom != null) toDate = fromDate.AddDays(-1);
|
||||||
|
|
||||||
if (hasTeamAttendancePermission)
|
if (hasTeamAttendancePermission)
|
||||||
{
|
{
|
||||||
List<Attendance> lstAttendance = await _context.Attendes.Where(c => c.ProjectID == projectId && c.AttendanceDate.Date >= fromDate.Date && c.AttendanceDate.Date <= toDate.Date && c.TenantId == tenantId).ToListAsync();
|
List<Attendance> lstAttendance = await _context.Attendes
|
||||||
|
.Include(a => a.Employee)
|
||||||
|
.ThenInclude(e => e!.Organization)
|
||||||
|
.Include(a => a.Employee)
|
||||||
|
.ThenInclude(e => e!.JobRole)
|
||||||
|
.Where(a => a.ProjectID == projectId &&
|
||||||
|
a.AttendanceDate.Date >= fromDate.Date &&
|
||||||
|
a.AttendanceDate.Date <= toDate.Date &&
|
||||||
|
a.TenantId == tenantId &&
|
||||||
|
a.Employee != null &&
|
||||||
|
a.Employee.Organization != null &&
|
||||||
|
a.Employee.JobRole != null
|
||||||
|
).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
List<ProjectAllocation> projectteam = await _projectServices.GetTeamByProject(tenantId, projectId, organizationId, true);
|
|
||||||
var jobRole = await _context.JobRoles.ToListAsync();
|
var jobRole = await _context.JobRoles.ToListAsync();
|
||||||
foreach (Attendance? attendance in lstAttendance)
|
foreach (Attendance? attendance in lstAttendance)
|
||||||
{
|
{
|
||||||
@ -209,70 +218,56 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
Id = attendance.Id,
|
Id = attendance.Id,
|
||||||
CheckInTime = attendance.InTime,
|
CheckInTime = attendance.InTime,
|
||||||
CheckOutTime = attendance.OutTime,
|
CheckOutTime = attendance.OutTime,
|
||||||
Activity = attendance.Activity
|
Activity = attendance.Activity,
|
||||||
|
EmployeeId = attendance.EmployeeId,
|
||||||
|
FirstName = attendance.Employee?.FirstName,
|
||||||
|
LastName = attendance.Employee?.LastName,
|
||||||
|
JobRoleName = attendance.Employee?.JobRole?.Name,
|
||||||
|
OrganizationName = attendance.Employee?.Organization?.Name
|
||||||
|
|
||||||
};
|
};
|
||||||
teamMember = projectteam.Find(x => x.EmployeeId == attendance.EmployeeId);
|
result.Add(result1);
|
||||||
if (teamMember != null)
|
|
||||||
{
|
|
||||||
result1.EmployeeAvatar = null;
|
|
||||||
result1.EmployeeId = teamMember.EmployeeId;
|
|
||||||
if (teamMember.Employee != null)
|
|
||||||
{
|
|
||||||
result1.FirstName = teamMember.Employee.FirstName;
|
|
||||||
result1.LastName = teamMember.Employee.LastName;
|
|
||||||
result1.JobRoleName = teamMember.Employee.JobRole != null ? teamMember.Employee.JobRole.Name : null;
|
|
||||||
result1.OrganizationName = teamMember.Employee.Organization?.Name;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result1.FirstName = null;
|
|
||||||
result1.LastName = null;
|
|
||||||
result1.JobRoleName = null;
|
|
||||||
result1.OrganizationName = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Add(result1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (hasSelfAttendancePermission)
|
else if (hasSelfAttendancePermission)
|
||||||
{
|
{
|
||||||
List<Attendance> lstAttendances = await _context.Attendes
|
var lstAttendanceQuery = _context.Attendes
|
||||||
.Where(c => c.ProjectID == projectId && c.EmployeeId == LoggedInEmployee.Id && c.AttendanceDate.Date >= fromDate.Date && c.AttendanceDate.Date <= toDate.Date && c.TenantId == tenantId)
|
.Include(a => a.Employee)
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var projectAllocationQuery = _context.ProjectAllocations
|
|
||||||
.Include(pa => pa.Employee)
|
|
||||||
.ThenInclude(e => e!.Organization)
|
.ThenInclude(e => e!.Organization)
|
||||||
.Where(pa => pa.ProjectId == projectId && pa.EmployeeId == LoggedInEmployee.Id && pa.TenantId == tenantId && pa.IsActive);
|
.Include(a => a.Employee)
|
||||||
|
.ThenInclude(e => e!.JobRole)
|
||||||
|
.Where(a => a.ProjectID == projectId &&
|
||||||
|
a.EmployeeId == LoggedInEmployee.Id &&
|
||||||
|
a.AttendanceDate.Date >= fromDate.Date &&
|
||||||
|
a.AttendanceDate.Date <= toDate.Date &&
|
||||||
|
a.TenantId == tenantId &&
|
||||||
|
a.Employee != null &&
|
||||||
|
a.Employee.Organization != null &&
|
||||||
|
a.Employee.JobRole != null);
|
||||||
|
|
||||||
if (organizationId.HasValue)
|
if (organizationId.HasValue)
|
||||||
{
|
{
|
||||||
projectAllocationQuery = projectAllocationQuery.Where(pa => pa.Employee != null && pa.Employee.OrganizationId == organizationId);
|
lstAttendanceQuery = lstAttendanceQuery.Where(a => a.Employee != null && a.Employee.OrganizationId == organizationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var projectAllocation = await projectAllocationQuery.FirstOrDefaultAsync();
|
var lstAttendances = await lstAttendanceQuery.ToListAsync();
|
||||||
|
|
||||||
foreach (var attendance in lstAttendances)
|
foreach (var attendance in lstAttendances)
|
||||||
{
|
{
|
||||||
if (projectAllocation != null)
|
EmployeeAttendanceVM result1 = new EmployeeAttendanceVM
|
||||||
{
|
{
|
||||||
EmployeeAttendanceVM result1 = new EmployeeAttendanceVM
|
Id = attendance.Id,
|
||||||
{
|
EmployeeAvatar = null,
|
||||||
Id = attendance.Id,
|
EmployeeId = attendance.EmployeeId,
|
||||||
EmployeeAvatar = null,
|
FirstName = attendance.Employee?.FirstName,
|
||||||
EmployeeId = projectAllocation.EmployeeId,
|
LastName = attendance.Employee?.LastName,
|
||||||
FirstName = projectAllocation.Employee?.FirstName,
|
JobRoleName = attendance.Employee?.JobRole?.Name,
|
||||||
LastName = projectAllocation.Employee?.LastName,
|
OrganizationName = attendance.Employee?.Organization?.Name,
|
||||||
JobRoleName = projectAllocation.Employee?.JobRole?.Name,
|
CheckInTime = attendance.InTime,
|
||||||
OrganizationName = projectAllocation.Employee?.Organization?.Name,
|
CheckOutTime = attendance.OutTime,
|
||||||
CheckInTime = attendance.InTime,
|
Activity = attendance.Activity
|
||||||
CheckOutTime = attendance.OutTime,
|
};
|
||||||
Activity = attendance.Activity
|
result.Add(result1);
|
||||||
};
|
|
||||||
result.Add(result1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_logger.LogInfo("{count} Attendance records fetched successfully", result.Count);
|
_logger.LogInfo("{count} Attendance records fetched successfully", result.Count);
|
||||||
@ -280,6 +275,7 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("project/team")]
|
[HttpGet("project/team")]
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves employee attendance records for a specified project and date.
|
/// Retrieves employee attendance records for a specified project and date.
|
||||||
/// The result is filtered based on the logged-in employee's permissions (Team or Self).
|
/// The result is filtered based on the logged-in employee's permissions (Team or Self).
|
||||||
@ -325,13 +321,17 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
|
|
||||||
if (hasTeamAttendancePermission)
|
if (hasTeamAttendancePermission)
|
||||||
{
|
{
|
||||||
|
if (!organizationId.HasValue)
|
||||||
|
{
|
||||||
|
organizationId = loggedInEmployee.OrganizationId;
|
||||||
|
}
|
||||||
_logger.LogInfo("EmployeeId: {EmployeeId} has Team Attendance permission. Fetching team attendance.", loggedInEmployee.Id);
|
_logger.LogInfo("EmployeeId: {EmployeeId} has Team Attendance permission. Fetching team attendance.", loggedInEmployee.Id);
|
||||||
result = await GetTeamAttendanceAsync(tenantId, projectId, organizationId, forDate, includeInactive);
|
result = await GetTeamAttendanceAsync(tenantId, projectId, organizationId.Value, forDate, includeInactive);
|
||||||
}
|
}
|
||||||
else if (await _permission.HasPermission(PermissionsMaster.SelfAttendance, loggedInEmployee.Id))
|
else if (await _permission.HasPermission(PermissionsMaster.SelfAttendance, loggedInEmployee.Id))
|
||||||
{
|
{
|
||||||
_logger.LogInfo("EmployeeId: {EmployeeId} has Self Attendance permission. Fetching self attendance.", loggedInEmployee.Id);
|
_logger.LogInfo("EmployeeId: {EmployeeId} has Self Attendance permission. Fetching self attendance.", loggedInEmployee.Id);
|
||||||
result = await GetSelfAttendanceAsync(tenantId, projectId, loggedInEmployee.Id, organizationId, forDate);
|
result = await GetSelfAttendanceAsync(tenantId, projectId, loggedInEmployee.Id, forDate);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -813,50 +813,39 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches attendance for an entire project team using a single, optimized database query.
|
/// Fetches attendance for an entire project team using a single, optimized database query.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task<List<EmployeeAttendanceVM>> GetTeamAttendanceAsync(Guid tenantId, Guid projectId, Guid? organizationId, DateTime forDate, bool includeInactive)
|
private async Task<List<EmployeeAttendanceVM>> GetTeamAttendanceAsync(Guid tenantId, Guid projectId, Guid organizationId, DateTime forDate, bool includeInactive)
|
||||||
{
|
{
|
||||||
// This single query joins ProjectAllocations with Employees and performs a LEFT JOIN with Attendances.
|
// This single query joins ProjectAllocations with Employees and performs a LEFT JOIN with Attendances.
|
||||||
// This is far more efficient than fetching collections and joining them in memory.
|
// This is far more efficient than fetching collections and joining them in memory.
|
||||||
var query = _context.ProjectAllocations
|
var query = _context.Employees
|
||||||
.Include(pa => pa.Employee)
|
.Include(e => e!.Organization)
|
||||||
.ThenInclude(e => e!.Organization)
|
.Include(e => e!.JobRole)
|
||||||
.Include(pa => pa.Employee)
|
.Where(e => e.OrganizationId == organizationId && e.Organization != null && e.JobRole != null && e.IsActive);
|
||||||
.ThenInclude(e => e!.JobRole)
|
|
||||||
.Where(pa => pa.TenantId == tenantId && pa.ProjectId == projectId);
|
|
||||||
|
|
||||||
// Apply filters based on optional parameters
|
|
||||||
if (!includeInactive)
|
|
||||||
{
|
|
||||||
query = query.Where(pa => pa.IsActive);
|
|
||||||
}
|
|
||||||
if (organizationId.HasValue)
|
|
||||||
{
|
|
||||||
query = query.Where(pa => pa.Employee != null && pa.Employee.OrganizationId == organizationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Attendance> lstAttendance = await _context.Attendes.Where(c => c.ProjectID == projectId && c.AttendanceDate.Date == forDate && c.TenantId == tenantId).ToListAsync();
|
List<Attendance> lstAttendance = await _context.Attendes.Where(c => c.ProjectID == projectId && c.AttendanceDate.Date == forDate && c.TenantId == tenantId).ToListAsync();
|
||||||
|
|
||||||
var teamAttendance = await query
|
var employees = await query
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var response = teamAttendance
|
var response = employees
|
||||||
.Select(teamMember =>
|
.Select(employee =>
|
||||||
{
|
{
|
||||||
var result1 = new EmployeeAttendanceVM()
|
var result1 = new EmployeeAttendanceVM()
|
||||||
{
|
{
|
||||||
EmployeeAvatar = null,
|
EmployeeAvatar = null,
|
||||||
EmployeeId = teamMember.EmployeeId,
|
EmployeeId = employee.Id,
|
||||||
FirstName = teamMember.Employee?.FirstName,
|
FirstName = employee.FirstName,
|
||||||
LastName = teamMember.Employee?.LastName,
|
LastName = employee.LastName,
|
||||||
OrganizationName = teamMember.Employee?.Organization?.Name,
|
OrganizationName = employee.Organization!.Name,
|
||||||
JobRoleName = teamMember.Employee?.JobRole?.Name,
|
JobRoleName = employee.JobRole!.Name,
|
||||||
};
|
};
|
||||||
|
|
||||||
//var member = emp.Where(e => e.Id == teamMember.EmployeeId);
|
//var member = emp.Where(e => e.Id == teamMember.EmployeeId);
|
||||||
|
|
||||||
|
|
||||||
var attendance = lstAttendance.Find(x => x.EmployeeId == teamMember.EmployeeId) ?? new Attendance();
|
var attendance = lstAttendance.Find(x => x.EmployeeId == employee.Id) ?? new Attendance();
|
||||||
if (attendance != null)
|
if (attendance != null)
|
||||||
{
|
{
|
||||||
result1.Id = attendance.Id;
|
result1.Id = attendance.Id;
|
||||||
@ -875,7 +864,7 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches a single attendance record for the logged-in employee.
|
/// Fetches a single attendance record for the logged-in employee.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task<List<EmployeeAttendanceVM>> GetSelfAttendanceAsync(Guid tenantId, Guid projectId, Guid employeeId, Guid? organizationId, DateTime forDate)
|
private async Task<List<EmployeeAttendanceVM>> GetSelfAttendanceAsync(Guid tenantId, Guid projectId, Guid employeeId, DateTime forDate)
|
||||||
{
|
{
|
||||||
List<EmployeeAttendanceVM> result = new List<EmployeeAttendanceVM>();
|
List<EmployeeAttendanceVM> result = new List<EmployeeAttendanceVM>();
|
||||||
|
|
||||||
@ -883,29 +872,22 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
Attendance lstAttendance = await _context.Attendes
|
Attendance lstAttendance = await _context.Attendes
|
||||||
.FirstOrDefaultAsync(c => c.ProjectID == projectId && c.EmployeeId == employeeId && c.AttendanceDate.Date == forDate && c.TenantId == tenantId) ?? new Attendance();
|
.FirstOrDefaultAsync(c => c.ProjectID == projectId && c.EmployeeId == employeeId && c.AttendanceDate.Date == forDate && c.TenantId == tenantId) ?? new Attendance();
|
||||||
|
|
||||||
var projectAllocationQuery = _context.ProjectAllocations
|
var employee = await _context.Employees
|
||||||
.Include(pa => pa.Employee)
|
.Include(e => e.Organization)
|
||||||
.ThenInclude(e => e!.Organization)
|
.Include(e => e.JobRole)
|
||||||
.Where(pa => pa.ProjectId == projectId && pa.EmployeeId == employeeId && pa.TenantId == tenantId && pa.IsActive);
|
.FirstOrDefaultAsync(e => e.Id == employeeId && e.IsActive);
|
||||||
|
|
||||||
if (organizationId.HasValue)
|
if (employee != null && employee.JobRole != null && employee.Organization != null)
|
||||||
{
|
|
||||||
projectAllocationQuery = projectAllocationQuery.Where(pa => pa.Employee != null && pa.Employee.OrganizationId == organizationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
var projectAllocation = await projectAllocationQuery.FirstOrDefaultAsync();
|
|
||||||
|
|
||||||
if (projectAllocation != null)
|
|
||||||
{
|
{
|
||||||
EmployeeAttendanceVM result1 = new EmployeeAttendanceVM
|
EmployeeAttendanceVM result1 = new EmployeeAttendanceVM
|
||||||
{
|
{
|
||||||
Id = lstAttendance.Id,
|
Id = lstAttendance.Id,
|
||||||
EmployeeAvatar = null,
|
EmployeeAvatar = null,
|
||||||
EmployeeId = projectAllocation.EmployeeId,
|
EmployeeId = employee.Id,
|
||||||
FirstName = projectAllocation.Employee?.FirstName,
|
FirstName = employee.FirstName,
|
||||||
OrganizationName = projectAllocation.Employee?.Organization?.Name,
|
OrganizationName = employee.Organization.Name,
|
||||||
LastName = projectAllocation.Employee?.LastName,
|
LastName = employee.LastName,
|
||||||
JobRoleName = projectAllocation.Employee?.JobRole?.Name,
|
JobRoleName = employee.JobRole.Name,
|
||||||
CheckInTime = lstAttendance.InTime,
|
CheckInTime = lstAttendance.InTime,
|
||||||
CheckOutTime = lstAttendance.OutTime,
|
CheckOutTime = lstAttendance.OutTime,
|
||||||
Activity = lstAttendance.Activity
|
Activity = lstAttendance.Activity
|
||||||
|
@ -273,12 +273,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
return StatusCode(403,
|
return StatusCode(403,
|
||||||
ApiResponse<object>.ErrorResponse("Access denied", "User does not have the required permissions for this action.", 403));
|
ApiResponse<object>.ErrorResponse("Access denied", "User does not have the required permissions for this action.", 403));
|
||||||
}
|
}
|
||||||
if (!hasManagePermission && (hasModifyPermission || hasViewPermission) && id != loggedInEmployee.TenantId)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Permission denied: User {EmployeeId} attempted to access tenant details of other tenant.", loggedInEmployee.Id);
|
|
||||||
return StatusCode(403,
|
|
||||||
ApiResponse<object>.ErrorResponse("Access denied", "User does not have the required permissions for this action.", 403));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a single DbContext for main tenant fetch and related data requests
|
// Create a single DbContext for main tenant fetch and related data requests
|
||||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
@ -297,6 +292,13 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
_logger.LogInfo("Tenant {TenantId} found.", tenant.Id);
|
_logger.LogInfo("Tenant {TenantId} found.", tenant.Id);
|
||||||
|
|
||||||
|
if (!hasManagePermission && (hasModifyPermission || hasViewPermission) && tenant.OrganizationId != loggedInEmployee.OrganizationId)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Permission denied: User {EmployeeId} attempted to access tenant details of other tenant.", loggedInEmployee.Id);
|
||||||
|
return StatusCode(403,
|
||||||
|
ApiResponse<object>.ErrorResponse("Access denied", "User does not have the required permissions for this action.", 403));
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch dependent data in parallel to improve performance
|
// Fetch dependent data in parallel to improve performance
|
||||||
var employeesTask = Task.Run(async () =>
|
var employeesTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
@ -550,7 +552,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
JobRole = adminJobRole, // Link to the newly created role
|
JobRole = adminJobRole, // Link to the newly created role
|
||||||
CurrentAddress = model.BillingAddress,
|
CurrentAddress = model.BillingAddress,
|
||||||
IsActive = true,
|
IsActive = true,
|
||||||
IsSystem = false,
|
IsSystem = true,
|
||||||
IsPrimary = true,
|
IsPrimary = true,
|
||||||
OrganizationId = organization.Id,
|
OrganizationId = organization.Id,
|
||||||
HasApplicationAccess = true
|
HasApplicationAccess = true
|
||||||
@ -566,43 +568,36 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
};
|
};
|
||||||
_context.ApplicationRoles.Add(applicationRole);
|
_context.ApplicationRoles.Add(applicationRole);
|
||||||
|
|
||||||
var rolePermissionMappigs = new List<RolePermissionMappings> {
|
var featureIds = new List<Guid>
|
||||||
new RolePermissionMappings
|
{
|
||||||
{
|
new Guid("a4e25142-449b-4334-a6e5-22f70e4732d7"), // Expense Management feature
|
||||||
ApplicationRoleId = applicationRole.Id,
|
new Guid("81ab8a87-8ccd-4015-a917-0627cee6a100"), // Employee Management feature
|
||||||
FeaturePermissionId = PermissionsMaster.ModifyTenant
|
new Guid("52c9cf54-1eb2-44d2-81bb-524cf29c0a94"), // Attendance Management feature
|
||||||
},
|
new Guid("a8cf4331-8f04-4961-8360-a3f7c3cc7462"), // Document Management feature
|
||||||
new RolePermissionMappings
|
new Guid("be3b3afc-6ccf-4566-b9b6-aafcb65546be"), // Masters Management feature
|
||||||
{
|
new Guid("39e66f81-efc6-446c-95bd-46bff6cfb606"), // Directory Management feature
|
||||||
ApplicationRoleId = applicationRole.Id,
|
new Guid("6d4c82d6-dbce-48ab-b8b8-f785f4d8c914") // Organization Management feature
|
||||||
FeaturePermissionId = PermissionsMaster.ViewTenant
|
|
||||||
},
|
|
||||||
new RolePermissionMappings
|
|
||||||
{
|
|
||||||
ApplicationRoleId = applicationRole.Id,
|
|
||||||
FeaturePermissionId = PermissionsMaster.ManageMasters
|
|
||||||
},
|
|
||||||
new RolePermissionMappings
|
|
||||||
{
|
|
||||||
ApplicationRoleId = applicationRole.Id,
|
|
||||||
FeaturePermissionId = PermissionsMaster.ViewMasters
|
|
||||||
},
|
|
||||||
new RolePermissionMappings
|
|
||||||
{
|
|
||||||
ApplicationRoleId = applicationRole.Id,
|
|
||||||
FeaturePermissionId = PermissionsMaster.ViewOrganization
|
|
||||||
},
|
|
||||||
new RolePermissionMappings
|
|
||||||
{
|
|
||||||
ApplicationRoleId = applicationRole.Id,
|
|
||||||
FeaturePermissionId = PermissionsMaster.AddOrganization
|
|
||||||
},
|
|
||||||
new RolePermissionMappings
|
|
||||||
{
|
|
||||||
ApplicationRoleId = applicationRole.Id,
|
|
||||||
FeaturePermissionId = PermissionsMaster.EditOrganization
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var permissionIds = await _context.FeaturePermissions.Where(fp => featureIds.Contains(fp.FeatureId)).Select(fp => fp.Id).ToListAsync();
|
||||||
|
|
||||||
|
var rolePermissionMappigs = permissionIds.Select(p => new RolePermissionMappings
|
||||||
|
{
|
||||||
|
ApplicationRoleId = applicationRole.Id,
|
||||||
|
FeaturePermissionId = p
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
rolePermissionMappigs.Add(new RolePermissionMappings
|
||||||
|
{
|
||||||
|
ApplicationRoleId = applicationRole.Id,
|
||||||
|
FeaturePermissionId = PermissionsMaster.ModifyTenant
|
||||||
|
});
|
||||||
|
rolePermissionMappigs.Add(new RolePermissionMappings
|
||||||
|
{
|
||||||
|
ApplicationRoleId = applicationRole.Id,
|
||||||
|
FeaturePermissionId = PermissionsMaster.ViewTenant
|
||||||
|
});
|
||||||
|
|
||||||
_context.RolePermissionMappings.AddRange(rolePermissionMappigs);
|
_context.RolePermissionMappings.AddRange(rolePermissionMappigs);
|
||||||
|
|
||||||
_context.EmployeeRoleMappings.Add(new EmployeeRoleMapping
|
_context.EmployeeRoleMappings.Add(new EmployeeRoleMapping
|
||||||
@ -651,6 +646,22 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
_context.OrgServiceMappings.AddRange(serviceOrgMappings);
|
_context.OrgServiceMappings.AddRange(serviceOrgMappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _masteData = scope.ServiceProvider.GetRequiredService<MasterDataService>();
|
||||||
|
|
||||||
|
var expensesTypeMaster = _masteData.GetExpensesTypeesData(tenant.Id);
|
||||||
|
var paymentModeMatser = _masteData.GetPaymentModesData(tenant.Id);
|
||||||
|
var documentCategoryMaster = _masteData.GetDocumentCategoryData(tenant.Id);
|
||||||
|
|
||||||
|
var employeeDocumentId = documentCategoryMaster.Where(dc => dc.Name == "Employee Documents").Select(dc => dc.Id).FirstOrDefault();
|
||||||
|
var projectDocumentId = documentCategoryMaster.Where(dc => dc.Name == "Project Documents").Select(dc => dc.Id).FirstOrDefault();
|
||||||
|
|
||||||
|
var documentTypeMaster = _masteData.GetDocumentTypeData(tenant.Id, employeeDocumentId, projectDocumentId);
|
||||||
|
|
||||||
|
_context.ExpensesTypeMaster.AddRange(expensesTypeMaster);
|
||||||
|
_context.PaymentModeMatser.AddRange(paymentModeMatser);
|
||||||
|
_context.DocumentCategoryMasters.AddRange(documentCategoryMaster);
|
||||||
|
_context.DocumentTypeMasters.AddRange(documentTypeMaster);
|
||||||
|
|
||||||
// All entities are now added to the context. Save them all in a single database operation.
|
// All entities are now added to the context. Save them all in a single database operation.
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
@ -253,16 +253,29 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
!ts.IsCancelled &&
|
!ts.IsCancelled &&
|
||||||
ts.EndDate.Date >= DateTime.UtcNow.Date); // FIX: Subscription should not be expired
|
ts.EndDate.Date >= DateTime.UtcNow.Date); // FIX: Subscription should not be expired
|
||||||
|
|
||||||
|
var featureIds = new List<Guid>
|
||||||
|
{
|
||||||
|
new Guid("a4e25142-449b-4334-a6e5-22f70e4732d7"), // Expense Management feature
|
||||||
|
new Guid("81ab8a87-8ccd-4015-a917-0627cee6a100"), // Employee Management feature
|
||||||
|
new Guid("52c9cf54-1eb2-44d2-81bb-524cf29c0a94"), // Attendance Management feature
|
||||||
|
new Guid("a8cf4331-8f04-4961-8360-a3f7c3cc7462"), // Document Management feature
|
||||||
|
new Guid("be3b3afc-6ccf-4566-b9b6-aafcb65546be"), // Masters Management feature
|
||||||
|
new Guid("39e66f81-efc6-446c-95bd-46bff6cfb606"), // Directory Management feature
|
||||||
|
new Guid("6d4c82d6-dbce-48ab-b8b8-f785f4d8c914"), // Organization Management feature
|
||||||
|
new Guid("2f3509b7-160d-410a-b9b6-daadd96c986d") // Tenant Management feature
|
||||||
|
};
|
||||||
|
|
||||||
if (tenantSubscription == null)
|
if (tenantSubscription == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("No active subscription found for tenant: {TenantId}", tenantId);
|
_logger.LogWarning("No active subscription found for tenant: {TenantId}", tenantId);
|
||||||
return new List<Guid>();
|
return featureIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogDebug("Active subscription found for tenant: {TenantId}, PlanId: {PlanId}",
|
_logger.LogDebug("Active subscription found for tenant: {TenantId}, PlanId: {PlanId}",
|
||||||
tenantId, tenantSubscription.Plan!.Id);
|
tenantId, tenantSubscription.Plan!.Id);
|
||||||
|
|
||||||
var featureIds = new List<Guid> { new Guid("2f3509b7-160d-410a-b9b6-daadd96c986d"), new Guid("be3b3afc-6ccf-4566-b9b6-aafcb65546be") };
|
//var featureIds = new List<Guid> { new Guid("2f3509b7-160d-410a-b9b6-daadd96c986d"), new Guid("be3b3afc-6ccf-4566-b9b6-aafcb65546be") };
|
||||||
|
|
||||||
|
|
||||||
// Step 2: Get feature details from Plan
|
// Step 2: Get feature details from Plan
|
||||||
var featureDetails = await _featureDetailsHelper.GetFeatureDetails(tenantSubscription.Plan!.FeaturesId);
|
var featureDetails = await _featureDetailsHelper.GetFeatureDetails(tenantSubscription.Plan!.FeaturesId);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Marco.Pms.Model.Forum;
|
using Marco.Pms.Model.DocumentManager;
|
||||||
|
using Marco.Pms.Model.Forum;
|
||||||
using Marco.Pms.Model.Master;
|
using Marco.Pms.Model.Master;
|
||||||
|
|
||||||
namespace Marco.Pms.Services.Service
|
namespace Marco.Pms.Services.Service
|
||||||
@ -335,6 +336,194 @@ namespace Marco.Pms.Services.Service
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
public List<DocumentCategoryMaster> GetDocumentCategoryData(Guid tenantId)
|
||||||
|
{
|
||||||
|
return new List<DocumentCategoryMaster> {
|
||||||
|
new DocumentCategoryMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Project Documents",
|
||||||
|
Description = "Project documents are formal records that outline the plans, progress, and details necessary to execute and manage a project effectively.",
|
||||||
|
EntityTypeId = Guid.Parse("c8fe7115-aa27-43bc-99f4-7b05fabe436e"),
|
||||||
|
CreatedAt = new DateTime(2025, 9, 15, 12, 42, 3, 202, DateTimeKind.Utc),
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentCategoryMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Employee Documents",
|
||||||
|
Description = "Employment details along with legal IDs like passports or driver’s licenses to verify identity and work authorization.",
|
||||||
|
EntityTypeId = Guid.Parse("dbb9555a-7a0c-40f2-a9ed-f0463f1ceed7"),
|
||||||
|
CreatedAt = new DateTime(2025, 9, 15, 12, 42, 3, 202, DateTimeKind.Utc),
|
||||||
|
TenantId = tenantId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public List<DocumentTypeMaster> GetDocumentTypeData(Guid tenantId, Guid employeeDocumentId, Guid projectDocumentId)
|
||||||
|
{
|
||||||
|
return new List<DocumentTypeMaster> {
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Aadhaar card",
|
||||||
|
RegexExpression = "^[2-9][0-9]{11}$",
|
||||||
|
AllowedContentType = "application/pdf,image/jpeg",
|
||||||
|
MaxSizeAllowedInMB = 2,
|
||||||
|
IsValidationRequired = true,
|
||||||
|
IsMandatory = true,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = employeeDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Pan Card",
|
||||||
|
RegexExpression = "^[A-Z]{5}[0-9]{4}[A-Z]{1}$",
|
||||||
|
AllowedContentType = "application/pdf,image/jpeg",
|
||||||
|
MaxSizeAllowedInMB = 2,
|
||||||
|
IsValidationRequired = true,
|
||||||
|
IsMandatory = true,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = employeeDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Voter Card",
|
||||||
|
RegexExpression = "^[A-Z]{3}[0-9]{7}$",
|
||||||
|
AllowedContentType = "application/pdf,image/jpeg",
|
||||||
|
MaxSizeAllowedInMB = 2,
|
||||||
|
IsValidationRequired = true,
|
||||||
|
IsMandatory = true,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = employeeDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Passport",
|
||||||
|
RegexExpression = "^[A-PR-WY][1-9]\\d\\s?\\d{4}[1-9]$",
|
||||||
|
AllowedContentType = "application/pdf,image/jpeg",
|
||||||
|
MaxSizeAllowedInMB = 2,
|
||||||
|
IsValidationRequired = true,
|
||||||
|
IsMandatory = true,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = employeeDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Bank Passbook",
|
||||||
|
RegexExpression = "^\\d{9,18}$",
|
||||||
|
AllowedContentType = "application/pdf,image/jpeg",
|
||||||
|
MaxSizeAllowedInMB = 2,
|
||||||
|
IsValidationRequired = true,
|
||||||
|
IsMandatory = true,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = employeeDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Bill of Quantities (BOQ)",
|
||||||
|
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
MaxSizeAllowedInMB = 1,
|
||||||
|
IsValidationRequired = false,
|
||||||
|
IsMandatory = false,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = projectDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Work Order",
|
||||||
|
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
MaxSizeAllowedInMB = 1,
|
||||||
|
IsValidationRequired = false,
|
||||||
|
IsMandatory = false,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = projectDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Letter of Agreement",
|
||||||
|
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
MaxSizeAllowedInMB = 1,
|
||||||
|
IsValidationRequired = false,
|
||||||
|
IsMandatory = false,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = projectDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Health and Safety Document",
|
||||||
|
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
MaxSizeAllowedInMB = 1,
|
||||||
|
IsValidationRequired = false,
|
||||||
|
IsMandatory = false,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = projectDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Standard Operating Procedure (SOP)",
|
||||||
|
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
MaxSizeAllowedInMB = 1,
|
||||||
|
IsValidationRequired = false,
|
||||||
|
IsMandatory = false,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = projectDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
},
|
||||||
|
new DocumentTypeMaster
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = "Drawings",
|
||||||
|
AllowedContentType = "application/pdf,image/vnd.dwg,application/acad",
|
||||||
|
MaxSizeAllowedInMB = 20,
|
||||||
|
IsValidationRequired = false,
|
||||||
|
IsMandatory = false,
|
||||||
|
CreatedAt = new DateTime(2025, 9, 3, 10, 46, 49, 955, DateTimeKind.Utc),
|
||||||
|
IsSystem = true,
|
||||||
|
IsActive = true,
|
||||||
|
DocumentCategoryId = projectDocumentId,
|
||||||
|
TenantId = tenantId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
public List<object> GetData(Guid tenantId)
|
public List<object> GetData(Guid tenantId)
|
||||||
{
|
{
|
||||||
return new List<object>
|
return new List<object>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user