Fixed the bug of Attendance Regularization

This commit is contained in:
ashutosh.nehete 2025-04-08 16:09:50 +05:30
parent 727e4794da
commit 7ddb1e2f8e
4 changed files with 39 additions and 24 deletions

View File

@ -6,11 +6,12 @@ namespace Marco.Pms.Model.ViewModels.Attendance
{
public int Id { get; set; }
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? EmployeeAvatar { get; set; }
public DateTime? CheckInTime { get; set; }
public DateTime? CheckOutTime { get; set; }
public string? JobRoleName { get; set; }
public ATTENDANCE_MARK_TYPE Activity { get; set; }
}

View File

@ -98,7 +98,7 @@ namespace MarcoBMS.Services.Controllers
}
var result = new List<EmployeeAttendanceVM>();
Attendance attendance = null;
Attendance? attendance = null;
if (dateFrom == null) fromDate = DateTime.UtcNow.Date;
if (dateTo == null && dateFrom != null) toDate = fromDate.AddDays(-1);
@ -119,7 +119,7 @@ namespace MarcoBMS.Services.Controllers
LastName = teamMember.Employee.LastName
};
attendance = lstAttendance.Find(x => x.EmployeeID == teamMember.EmployeeId);
attendance = lstAttendance.Find(x => x.EmployeeID == teamMember.EmployeeId) ?? new Attendance();
if (attendance != null)
{
result1.Id = attendance.Id;
@ -158,7 +158,7 @@ namespace MarcoBMS.Services.Controllers
}
var result = new List<EmployeeAttendanceVM>();
Attendance attendance = null;
Attendance? attendance = null;
if (date == null) forDate = DateTime.UtcNow.Date;
@ -166,18 +166,27 @@ namespace MarcoBMS.Services.Controllers
List<ProjectAllocation> projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, IncludeInActive);
var idList = projectteam.Select(p => p.EmployeeId).ToList();
//var emp = await _context.Employees.Where(e => idList.Contains(e.Id)).Include(e => e.JobRole).ToListAsync();
var jobRole = await _context.JobRoles.ToListAsync();
foreach (ProjectAllocation teamMember in projectteam)
{
if (teamMember.Employee.JobRole != null)
{
var result1 = new EmployeeAttendanceVM()
{
EmployeeAvatar = null,
EmployeeId = teamMember.EmployeeId,
FirstName = teamMember.Employee.FirstName,
LastName = teamMember.Employee.LastName
LastName = teamMember.Employee.LastName,
JobRoleName = teamMember.Employee.JobRole.Name,
};
attendance = lstAttendance.Find(x => x.EmployeeID == teamMember.EmployeeId);
//var member = emp.Where(e => e.Id == teamMember.EmployeeId);
attendance = lstAttendance.Find(x => x.EmployeeID == teamMember.EmployeeId) ?? new Attendance();
if (attendance != null)
{
result1.Id = attendance.Id;
@ -188,9 +197,11 @@ namespace MarcoBMS.Services.Controllers
result.Add(result1);
}
}
result.Sort(delegate (EmployeeAttendanceVM x, EmployeeAttendanceVM y) {
return x.FirstName.CompareTo(y.FirstName);
//return x.FirstName.CompareTo(y.FirstName);
return string.Compare(x.FirstName, y.FirstName, StringComparison.Ordinal);
});
return Ok(ApiResponse<object>.SuccessResponse(result, System.String.Format("{0} Attendance records fetched successfully", result.Count), 200));
@ -215,8 +226,9 @@ namespace MarcoBMS.Services.Controllers
using var transaction = await _context.Database.BeginTransactionAsync();
try
{
Attendance attendance = await _context.Attendes.FirstOrDefaultAsync(a => a.EmployeeID == recordAttendanceDot.EmployeeID &&
a.AttendanceDate.Date == recordAttendanceDot.Date.Date && a.TenantId == TenantId); ;
Attendance? attendance = await _context.Attendes.FirstOrDefaultAsync(a => a.Id == recordAttendanceDot.Id && a.TenantId == TenantId); ;
if (recordAttendanceDot.MarkTime == null) return BadRequest(ApiResponse<object>.ErrorResponse("Invalid Mark Time", "Invalid Mark Time",400));
DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);

View File

@ -20,7 +20,7 @@ namespace Marco.Pms.Services.Controllers
_context = context;
_userHelper = userHelper;
}
[HttpPost("create-activity")]
[HttpPost("activity")]
public async Task<IActionResult> CreateActivity([FromBody] CreateActivityMasterDto createActivity)
{
var tenantId = _userHelper.GetTenantId();

View File

@ -13,6 +13,8 @@
{
try
{
context.Response.Headers.Remove("X-Powered-By");
context.Response.Headers.Remove("Server");
await _next(context);
}
catch (Exception ex)