Added the API to get list of advance payment transaction
This commit is contained in:
parent
c71343d550
commit
8b44fb6f39
@ -281,9 +281,17 @@ namespace Marco.Pms.Services.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region =================================================================== Payment Request Functions ===================================================================
|
||||
#region =================================================================== Advance Payment Functions ===================================================================
|
||||
|
||||
[HttpGet("get/transactions/{employeeId}")]
|
||||
public async Task<IActionResult> GetAdvancePaymentTransaction(Guid employeeId)
|
||||
{
|
||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
var response = await _expensesService.GetAdvancePaymentTransactionAsync(employeeId, loggedInEmployee, tenantId);
|
||||
|
||||
return StatusCode(response.StatusCode, response);
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -3147,8 +3147,53 @@ namespace Marco.Pms.Services.Service
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region =================================================================== Payment Request Functions ===================================================================
|
||||
#region =================================================================== Advance Payment Functions ===================================================================
|
||||
public async Task<ApiResponse<object>> GetAdvancePaymentTransactionAsync(Guid employeeId, Employee loggedInEmployee, Guid tenantId)
|
||||
{
|
||||
_logger.LogInfo("Start GetAdvancePaymentTransactionAsync called by EmployeeId: {EmployeeId} for TenantId: {TenantId} and EmployeeId param: {ParamEmployeeId}",
|
||||
loggedInEmployee.Id, tenantId, employeeId);
|
||||
|
||||
try
|
||||
{
|
||||
// Fetch advance payment transactions for specified employee, including related navigation properties
|
||||
var transactions = await _context.AdvancePaymentTransactions
|
||||
.Include(apt => apt.Project)
|
||||
.Include(apt => apt.Employee).ThenInclude(e => e!.JobRole)
|
||||
.Include(apt => apt.CreatedBy).ThenInclude(e => e!.JobRole)
|
||||
.Where(apt => apt.EmployeeId == employeeId && apt.TenantId == tenantId && apt.IsActive)
|
||||
.OrderByDescending(apt => apt.CreatedAt)
|
||||
.ToListAsync();
|
||||
|
||||
// Check if any transactions found
|
||||
if (transactions == null || !transactions.Any())
|
||||
{
|
||||
_logger.LogWarning("No advance payment transactions found for EmployeeId: {EmployeeId} in TenantId: {TenantId}.", employeeId, tenantId);
|
||||
return ApiResponse<object>.ErrorResponse("No advance payment transactions found.", null, 404);
|
||||
}
|
||||
|
||||
// Map transactions to view model with formatted FinanceUId
|
||||
var response = transactions.Select(transaction =>
|
||||
{
|
||||
var result = _mapper.Map<AdvancePaymentTransactionVM>(transaction);
|
||||
result.FinanceUId = $"{transaction.FinanceUIdPrefix}/{transaction.FinanceUIdPostfix:D5}";
|
||||
return result;
|
||||
}).ToList();
|
||||
|
||||
_logger.LogInfo("Fetched {Count} advance payment transactions for EmployeeId: {EmployeeId} in TenantId: {TenantId}.", response.Count, employeeId, tenantId);
|
||||
|
||||
return ApiResponse<object>.SuccessResponse(response, "Advance payment transactions fetched successfully.", 200);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception occurred in GetAdvancePaymentTransactionAsync for EmployeeId: {EmployeeId} in TenantId: {TenantId}: {Message}",
|
||||
employeeId, tenantId, ex.Message);
|
||||
return ApiResponse<object>.ErrorResponse("Internal exception occurred.", ExceptionMapper(ex), 500);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_logger.LogInfo("End GetAdvancePaymentTransactionAsync called by EmployeeId: {EmployeeId}", loggedInEmployee.Id);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -37,8 +37,8 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces
|
||||
Task<ApiResponse<object>> EditRecurringPaymentAsync(Guid id, UpdateRecurringTemplateDto model, Employee loggedInEmployee, Guid tenantId);
|
||||
#endregion
|
||||
|
||||
#region =================================================================== Payment Request Functions ===================================================================
|
||||
|
||||
#region =================================================================== Advance Payment Functions ===================================================================
|
||||
Task<ApiResponse<object>> GetAdvancePaymentTransactionAsync(Guid id, Employee loggedInEmployee, Guid tenantId);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user