Updated the API to get employee list with current advance payment balance
This commit is contained in:
parent
03ee834505
commit
a7a9fb4012
@ -3368,26 +3368,42 @@ namespace Marco.Pms.Services.Service
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Base query: select employees who have advance payment transactions for the tenant
|
// Base query: select employees who have advance payment transactions for the tenant
|
||||||
var employeeQuery = _context.AdvancePaymentTransactions
|
var advancePaymentQuery = _context.AdvancePaymentTransactions
|
||||||
.Include(apt => apt.Employee)
|
.Include(apt => apt.Employee)
|
||||||
.ThenInclude(e => e!.JobRole)
|
.ThenInclude(e => e!.JobRole)
|
||||||
.Where(apt => apt.TenantId == tenantId && apt.Employee != null)
|
.Where(apt => apt.TenantId == tenantId && apt.Employee != null && apt.Employee.JobRole != null);
|
||||||
.Select(apt => apt.Employee!);
|
|
||||||
|
|
||||||
// Apply search filter if provided (concatenate first and last name for full name search)
|
// Apply search filter if provided (concatenate first and last name for full name search)
|
||||||
if (!string.IsNullOrWhiteSpace(searchString))
|
if (!string.IsNullOrWhiteSpace(searchString))
|
||||||
{
|
{
|
||||||
employeeQuery = employeeQuery.Where(e =>
|
advancePaymentQuery = advancePaymentQuery.Where(apt =>
|
||||||
(e.FirstName + " " + e.LastName).Contains(searchString));
|
(apt.Employee!.FirstName + " " + apt.Employee.LastName).Contains(searchString));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch distinct employees matching criteria
|
// Fetch distinct employees matching criteria
|
||||||
var employees = await employeeQuery
|
var employees = await advancePaymentQuery
|
||||||
.Distinct()
|
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// Map to response view model
|
// Map to response view model
|
||||||
var response = _mapper.Map<List<BasicEmployeeVM>>(employees);
|
var response = employees
|
||||||
|
.GroupBy(apt => apt.EmployeeId)
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
EmployeeId = g.Key,
|
||||||
|
Employee = g.OrderByDescending(apt => apt.CreatedAt).Select(apt => new
|
||||||
|
{
|
||||||
|
Id = apt.Employee!.Id,
|
||||||
|
FirstName = apt.Employee.FirstName,
|
||||||
|
LastName = apt.Employee.LastName,
|
||||||
|
JobRoleName = apt.Employee.JobRole!.Name,
|
||||||
|
BalanceAmount = apt.CurrentBalance
|
||||||
|
}).FirstOrDefault()
|
||||||
|
})
|
||||||
|
.Where(e => e.Employee != null)
|
||||||
|
.Select(e => e.Employee!)
|
||||||
|
.OrderBy(e => e.FirstName).ThenBy(e => e.LastName)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
_logger.LogInfo("Fetched {Count} employees with advance payments for TenantId: {TenantId}", employees.Count, tenantId);
|
_logger.LogInfo("Fetched {Count} employees with advance payments for TenantId: {TenantId}", employees.Count, tenantId);
|
||||||
|
|
||||||
@ -3406,6 +3422,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region =================================================================== Helper Functions ===================================================================
|
#region =================================================================== Helper Functions ===================================================================
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user