Merge pull request 'Weidget_Dashboard_Jobs' (#157) from Weidget_Dashboard_Jobs into Purchase_Invoice_Management

Reviewed-on: #157
This commit is contained in:
ashutosh.nehete 2025-12-08 05:00:34 +00:00
commit 6c35bd3bf8

View File

@ -4,6 +4,7 @@ using Marco.Pms.Model.Dtos.Attendance;
using Marco.Pms.Model.Entitlements;
using Marco.Pms.Model.Expenses;
using Marco.Pms.Model.OrganizationModel;
using Marco.Pms.Model.ServiceProject;
using Marco.Pms.Model.Utilities;
using Marco.Pms.Model.ViewModels.Activities;
using Marco.Pms.Model.ViewModels.AttendanceVM;
@ -1634,5 +1635,114 @@ namespace Marco.Pms.Services.Controllers
.Select(sp => new BasicProjectVM { Id = sp.Id, Name = sp.Name })
.ToListAsync();
}
[HttpGet("job/progression")]
public async Task<IActionResult> GetJobProgressionAsync([FromQuery] Guid? projectId)
{
Guid AssignedStatus = Guid.Parse("cfa1886d-055f-4ded-84c6-42a2a8a14a66");
Guid InProgressStatus = Guid.Parse("5a6873a5-fed7-4745-a52f-8f61bf3bd72d");
Guid ReviewDoneStatus = Guid.Parse("ed10ab57-dbaa-4ca5-8ecd-56745dcbdbd7");
Guid ClosedStatus = Guid.Parse("3ddeefb5-ae3c-4e10-a922-35e0a452bb69");
if (tenantId == Guid.Empty)
{
_logger.LogWarning("Invalid request: TenantId is empty on progression endpoint");
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid TenantId", "Provided Invalid TenantId", 400));
}
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
var jobIds = await _context.JobEmployeeMappings
.Where(jem => jem.AssigneeId == loggedInEmployee.Id && jem.TenantId == tenantId)
.Select(jem => jem.JobTicketId)
.ToListAsync();
var query = _context.JobTickets
.Include(jt => jt.Project)
.Include(jt => jt.CreatedBy).ThenInclude(e => e!.JobRole)
.Where(jt => jt.StatusId != ReviewDoneStatus
&& jt.StatusId != ClosedStatus
&& jt.Project != null
&& jt.CreatedBy != null
&& jt.TenantId == tenantId);
if (projectId.HasValue)
{
using var scope = _serviceScopeFactory.CreateScope();
var _permission = scope.ServiceProvider.GetRequiredService<PermissionServices>();
var hasPermission = await _permission.HasServiceProjectPermission(loggedInEmployee.Id, projectId.Value);
if (!hasPermission)
{
return StatusCode(403,
ApiResponse<object>.ErrorResponse("You do not have permission to access this resource", "You do not have permission to access this resource", 403));
}
query = query.Where(jt => jt.ProjectId == projectId.Value);
}
var jobs = await query
.ToListAsync();
var inProgressJobIds = jobs.Where(jt => jt.StatusId == InProgressStatus).Select(jt => jt.Id).ToList();
var latestTagIns = await _context.JobAttendance
.Include(ja => ja.Employee)
.Where(ja => inProgressJobIds.Contains(ja.JobTicketId)
&& ja.Action == TAGGING_MARK_TYPE.TAG_IN
&& ja.TaggedOutAt == null
&& ja.TenantId == tenantId)
.GroupBy(ja => ja.JobTicketId)
.Select(g => new
{
JobTicketId = g.Key,
Employee = g.Select(ja => ja.Employee).FirstOrDefault(),
TagInAt = g.Max(ja => ja.TaggedInAt)
})
.ToListAsync();
var assignedJobs = jobs
.Where(jt => jt.StatusId == AssignedStatus)
.Take(5)
.Select(jt => new
{
Project = jt.Project!.Name,
AssignedBy = jt.CreatedBy!.FirstName + " " + jt.CreatedBy.LastName,
Title = jt.Title,
AssignedAt = jt.CreatedAt,
})
.ToList();
var inProgressJobs = jobs
.Where(jt => jt.StatusId == InProgressStatus)
.Take(5)
.Select(jt => new
{
Project = jt.Project!.Name,
AssignedBy = jt.CreatedBy!.FirstName + " " + jt.CreatedBy.LastName,
Title = jt.Title,
AssignedAt = jt.CreatedAt,
})
.ToList();
var selfAssignedJobs = jobs
.Where(jt => jobIds.Contains(jt.Id))
.Take(5)
.Select(jt => new
{
Project = jt.Project!.Name,
AssignedBy = jt.CreatedBy!.FirstName + " " + jt.CreatedBy.LastName,
Title = jt.Title,
AssignedAt = jt.CreatedAt,
})
.ToList();
var response = new
{
AssignedJobs = assignedJobs,
InProgressJobs = inProgressJobs,
AllJobs = selfAssignedJobs
};
return Ok(ApiResponse<object>.SuccessResponse(response, "job progression fetched successfully", 200));
}
}
}