Merge pull request 'Implemented an API endpoint that retrieves the number of planned tasks and completed tasks for a specific project on a given date' (#72) from Ashutosh_Task#348_Activities_Report into Issue_May_4W
Reviewed-on: #72
This commit is contained in:
commit
56aeceb1f9
9
Marco.Pms.Model/ViewModels/DashBoard/ActivityReport.cs
Normal file
9
Marco.Pms.Model/ViewModels/DashBoard/ActivityReport.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace Marco.Pms.Model.ViewModels.DashBoard
|
||||||
|
{
|
||||||
|
public class ActivityReport
|
||||||
|
{
|
||||||
|
public List<PerformedActivites>? PerformedActivites { get; set; }
|
||||||
|
public double TotalPlannedWork { get; set; }
|
||||||
|
public double TotalCompletedWork { get; set; }
|
||||||
|
}
|
||||||
|
}
|
15
Marco.Pms.Model/ViewModels/DashBoard/PerformedActivites.cs
Normal file
15
Marco.Pms.Model/ViewModels/DashBoard/PerformedActivites.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace Marco.Pms.Model.ViewModels.DashBoard
|
||||||
|
{
|
||||||
|
public class PerformedActivites
|
||||||
|
{
|
||||||
|
public string? BuldingName { get; set; }
|
||||||
|
public string? FloorName { get; set; }
|
||||||
|
public string? WorkAreaName { get; set; }
|
||||||
|
public string? ActivityName { get; set; }
|
||||||
|
public string? Comment { get; set; }
|
||||||
|
public double Pending { get; set; }
|
||||||
|
public double AssignedToday { get; set; }
|
||||||
|
public double CompletedToday { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -276,5 +276,86 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
_logger.LogInfo($"Attendance record for project {projectId} for date {currentDate.Date} by employee {LoggedInEmployee.Id}");
|
_logger.LogInfo($"Attendance record for project {projectId} for date {currentDate.Date} by employee {LoggedInEmployee.Id}");
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(projectAttendanceVM, $"Attendance record for project {project.Name} for date {currentDate.Date}", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(projectAttendanceVM, $"Attendance record for project {project.Name} for date {currentDate.Date}", 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("activities/{projectId}")]
|
||||||
|
public async Task<IActionResult> GetActivities(Guid projectId, [FromQuery] string? date)
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
|
||||||
|
DateTime currentDate = DateTime.UtcNow;
|
||||||
|
List<ProjectProgressionVM>? projectProgressionVMs = new List<ProjectProgressionVM>();
|
||||||
|
if (date != null && DateTime.TryParse(date, out currentDate) == false)
|
||||||
|
{
|
||||||
|
_logger.LogError($"user send invalid date");
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid date.", "Invalid date.", 400));
|
||||||
|
|
||||||
|
}
|
||||||
|
Project? project = await _context.Projects.FirstOrDefaultAsync(p => p.Id == projectId);
|
||||||
|
if (project == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Employee {EmployeeId} was attempted to get activities performed for date {Date}, but project not found in database", LoggedInEmployee.Id, currentDate);
|
||||||
|
return NotFound(ApiResponse<object>.ErrorResponse("Project not found", "Project not found", 404));
|
||||||
|
}
|
||||||
|
|
||||||
|
var buildings = await _context.Buildings.Where(b => b.ProjectId == project.Id).ToListAsync();
|
||||||
|
var buildingIds = buildings.Select(b => b.Id).Distinct().ToList();
|
||||||
|
|
||||||
|
var floors = await _context.Floor.Where(f => buildingIds.Contains(f.BuildingId)).ToListAsync();
|
||||||
|
var floorIds = floors.Select(f => f.Id).Distinct().ToList();
|
||||||
|
|
||||||
|
var areas = await _context.WorkAreas.Where(a => floorIds.Contains(a.FloorId)).ToListAsync();
|
||||||
|
var areaIds = areas.Select(a => a.Id).Distinct().ToList();
|
||||||
|
|
||||||
|
var workItems = await _context.WorkItems.Include(i => i.ActivityMaster).Where(i => areaIds.Contains(i.WorkAreaId)).ToListAsync();
|
||||||
|
var itemIds = workItems.Select(i => i.Id).Distinct().ToList();
|
||||||
|
|
||||||
|
var tasks = await _context.TaskAllocations.Where(t => itemIds.Contains(t.WorkItemId) && t.AssignmentDate.Date == currentDate.Date).ToListAsync();
|
||||||
|
double totalPlannedTask = 0;
|
||||||
|
double totalCompletedTask = 0;
|
||||||
|
List<PerformedActivites> performedActivites = new List<PerformedActivites>();
|
||||||
|
|
||||||
|
foreach (var task in tasks)
|
||||||
|
{
|
||||||
|
totalPlannedTask += task.PlannedTask;
|
||||||
|
totalCompletedTask += task.CompletedTask;
|
||||||
|
|
||||||
|
WorkItem workItem = workItems.FirstOrDefault(i => i.Id == task.WorkItemId) ?? new WorkItem();
|
||||||
|
string activityName = (workItem.ActivityMaster != null ? workItem.ActivityMaster.ActivityName : "") ?? "";
|
||||||
|
|
||||||
|
WorkArea workArea = areas.FirstOrDefault(a => a.Id == workItem.WorkAreaId) ?? new WorkArea();
|
||||||
|
string areaName = workArea.AreaName ?? "";
|
||||||
|
|
||||||
|
Floor floor = floors.FirstOrDefault(f => f.Id == workArea.FloorId) ?? new Floor();
|
||||||
|
string floorName = floor.FloorName ?? "";
|
||||||
|
|
||||||
|
Building building = buildings.FirstOrDefault(b => b.Id == floor.BuildingId) ?? new Building();
|
||||||
|
string buildingName = building.Name ?? "";
|
||||||
|
|
||||||
|
double pending = workItem.PlannedWork - workItem.CompletedWork;
|
||||||
|
|
||||||
|
PerformedActivites performedTask = new PerformedActivites
|
||||||
|
{
|
||||||
|
ActivityName = activityName,
|
||||||
|
BuldingName = buildingName,
|
||||||
|
FloorName = floorName,
|
||||||
|
WorkAreaName = areaName,
|
||||||
|
AssignedToday = task.PlannedTask,
|
||||||
|
Pending = pending,
|
||||||
|
CompletedToday = task.CompletedTask,
|
||||||
|
Comment = task.Description
|
||||||
|
};
|
||||||
|
performedActivites.Add(performedTask);
|
||||||
|
}
|
||||||
|
ActivityReport report = new ActivityReport
|
||||||
|
{
|
||||||
|
PerformedActivites = performedActivites,
|
||||||
|
TotalCompletedWork = totalCompletedTask,
|
||||||
|
TotalPlannedWork = totalPlannedTask
|
||||||
|
};
|
||||||
|
_logger.LogInfo($"Record of performed activities for project {projectId} for date {currentDate.Date} by employee {LoggedInEmployee.Id}");
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(report, $"Record of performed activities for project {project.Name} for date {currentDate.Date}", 200));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user