Merge pull request 'Implemented an API to retrieve a pending checkout and pending regularization request for logged in employee' (#70) from Ashutosh_Task#346_Pending_Attendance into Issue_May_4W
Reviewed-on: #70
This commit is contained in:
commit
6b33c4baf4
@ -1,9 +1,11 @@
|
|||||||
using Marco.Pms.DataAccess.Data;
|
using Marco.Pms.DataAccess.Data;
|
||||||
using Marco.Pms.Model.Activities;
|
using Marco.Pms.Model.Activities;
|
||||||
|
using Marco.Pms.Model.Dtos.Attendance;
|
||||||
using Marco.Pms.Model.Projects;
|
using Marco.Pms.Model.Projects;
|
||||||
using Marco.Pms.Model.Utilities;
|
using Marco.Pms.Model.Utilities;
|
||||||
using Marco.Pms.Model.ViewModels.DashBoard;
|
using Marco.Pms.Model.ViewModels.DashBoard;
|
||||||
using MarcoBMS.Services.Helpers;
|
using MarcoBMS.Services.Helpers;
|
||||||
|
using MarcoBMS.Services.Service;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -17,15 +19,19 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ApplicationDbContext _context;
|
private readonly ApplicationDbContext _context;
|
||||||
private readonly UserHelper _userHelper;
|
private readonly UserHelper _userHelper;
|
||||||
public DashboardController(ApplicationDbContext context, UserHelper userHelper)
|
private readonly ILoggingService _logger;
|
||||||
|
public DashboardController(ApplicationDbContext context, UserHelper userHelper, ILoggingService logger)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_userHelper = userHelper;
|
_userHelper = userHelper;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
[HttpGet("progression")]
|
[HttpGet("progression")]
|
||||||
public async Task<IActionResult> GetGraph([FromQuery] double days, [FromQuery] string FromDate, [FromQuery] Guid? projectId)
|
public async Task<IActionResult> GetGraph([FromQuery] double days, [FromQuery] string FromDate, [FromQuery] Guid? projectId)
|
||||||
{
|
{
|
||||||
var tenantId = _userHelper.GetTenantId();
|
var tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
|
||||||
DateTime fromDate = new DateTime();
|
DateTime fromDate = new DateTime();
|
||||||
DateTime toDate = new DateTime();
|
DateTime toDate = new DateTime();
|
||||||
List<ProjectProgressionVM>? projectProgressionVMs = new List<ProjectProgressionVM>();
|
List<ProjectProgressionVM>? projectProgressionVMs = new List<ProjectProgressionVM>();
|
||||||
@ -78,6 +84,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
flagDays -= 1;
|
flagDays -= 1;
|
||||||
}
|
}
|
||||||
|
_logger.LogInfo("Project Progression report for all projects fetched successfully by employee {EmployeeId}", LoggedInEmployee.Id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -125,6 +132,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
flagDays -= 1;
|
flagDays -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_logger.LogInfo("Project Progression for project {ProjectId} fetched successfully by employee {EmployeeId}", projectId, LoggedInEmployee.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(projectProgressionVMs, "Success", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(projectProgressionVMs, "Success", 200));
|
||||||
@ -134,6 +142,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
public async Task<IActionResult> GetProjectCount()
|
public async Task<IActionResult> GetProjectCount()
|
||||||
{
|
{
|
||||||
var tenantId = _userHelper.GetTenantId();
|
var tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
|
||||||
var projects = await _context.Projects.Where(p => p.TenantId == tenantId).ToListAsync();
|
var projects = await _context.Projects.Where(p => p.TenantId == tenantId).ToListAsync();
|
||||||
var projectStatus = await _context.StatusMasters.Where(s => s.Status == "Active" || s.Status == "In Progress").ToListAsync();
|
var projectStatus = await _context.StatusMasters.Where(s => s.Status == "Active" || s.Status == "In Progress").ToListAsync();
|
||||||
@ -145,6 +154,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
TotalProjects = projects.Count(),
|
TotalProjects = projects.Count(),
|
||||||
OngoingProjects = ongoingProjects.Count()
|
OngoingProjects = ongoingProjects.Count()
|
||||||
};
|
};
|
||||||
|
_logger.LogInfo("Number of total ongoing projects fetched by employee {EmployeeId}", LoggedInEmployee.Id);
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(projectDashboardVM, "Success", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(projectDashboardVM, "Success", 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +163,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
public async Task<IActionResult> GetTotalEmployees()
|
public async Task<IActionResult> GetTotalEmployees()
|
||||||
{
|
{
|
||||||
var tenantId = _userHelper.GetTenantId();
|
var tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
var date = DateTime.UtcNow.Date;
|
var date = DateTime.UtcNow.Date;
|
||||||
|
|
||||||
var Employees = await _context.Employees.Where(e => e.TenantId == tenantId && e.IsActive == true).Select(e => e.Id).ToListAsync();
|
var Employees = await _context.Employees.Where(e => e.TenantId == tenantId && e.IsActive == true).Select(e => e.Id).ToListAsync();
|
||||||
@ -164,6 +175,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
TotalEmployees = Employees.Count(),
|
TotalEmployees = Employees.Count(),
|
||||||
InToday = checkedInEmployee.Distinct().Count()
|
InToday = checkedInEmployee.Distinct().Count()
|
||||||
};
|
};
|
||||||
|
_logger.LogInfo("Today's total checked in employees fetched by employee {EmployeeId}", LoggedInEmployee.Id);
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(teamDashboardVM, "Success", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(teamDashboardVM, "Success", 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +183,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
public async Task<IActionResult> GetTotalTasks()
|
public async Task<IActionResult> GetTotalTasks()
|
||||||
{
|
{
|
||||||
var tenantId = _userHelper.GetTenantId();
|
var tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
var Tasks = await _context.WorkItems.Where(t => t.TenantId == tenantId).Select(t => new { PlannedWork = t.PlannedWork, CompletedWork = t.CompletedWork }).ToListAsync();
|
var Tasks = await _context.WorkItems.Where(t => t.TenantId == tenantId).Select(t => new { PlannedWork = t.PlannedWork, CompletedWork = t.CompletedWork }).ToListAsync();
|
||||||
TasksDashboardVM tasksDashboardVM = new TasksDashboardVM
|
TasksDashboardVM tasksDashboardVM = new TasksDashboardVM
|
||||||
{
|
{
|
||||||
@ -183,8 +195,33 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
tasksDashboardVM.TotalTasks += task.PlannedWork;
|
tasksDashboardVM.TotalTasks += task.PlannedWork;
|
||||||
tasksDashboardVM.CompletedTasks += task.CompletedWork;
|
tasksDashboardVM.CompletedTasks += task.CompletedWork;
|
||||||
}
|
}
|
||||||
|
_logger.LogInfo("Total targeted tasks and total completed tasks fetched by employee {EmployeeId}", LoggedInEmployee.Id);
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(tasksDashboardVM, "Success", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(tasksDashboardVM, "Success", 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("pending-attendance")]
|
||||||
|
public async Task<IActionResult> GetPendingAttendance()
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
|
||||||
|
var attendance = await _context.Attendes.Where(a => a.EmployeeID == LoggedInEmployee.Id && a.TenantId == tenantId).ToListAsync();
|
||||||
|
if (attendance.Any())
|
||||||
|
{
|
||||||
|
var pendingRegularization = attendance.Where(a => a.Activity == ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE).ToList().Count;
|
||||||
|
var pendingCheckOut = attendance.Where(a => a.OutTime == null).ToList().Count;
|
||||||
|
var response = new
|
||||||
|
{
|
||||||
|
PendingRegularization = pendingRegularization,
|
||||||
|
PendingCheckOut = pendingCheckOut
|
||||||
|
};
|
||||||
|
_logger.LogInfo("Number of pending regularization and pending check-out are fetched successfully for employee {EmployeeId}", LoggedInEmployee.Id);
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(response, "Pending regularization and pending check-out are fetched successfully", 200));
|
||||||
|
}
|
||||||
|
_logger.LogError("No attendance entry was found for employee {EmployeeId}", LoggedInEmployee.Id);
|
||||||
|
return NotFound(ApiResponse<object>.ErrorResponse("No attendance entry was found for this employee", "No attendance entry was found for this employee", 404));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user