diff --git a/Marco.Pms.Services/Service/ExpensesService.cs b/Marco.Pms.Services/Service/ExpensesService.cs index aaea0c0..f13a0fc 100644 --- a/Marco.Pms.Services/Service/ExpensesService.cs +++ b/Marco.Pms.Services/Service/ExpensesService.cs @@ -1209,7 +1209,7 @@ namespace Marco.Pms.Services.Service pr.CreatedBy != null && pr.CreatedBy.JobRole != null); - if (hasViewSelfPermissionTask.Result) + if (hasViewSelfPermissionTask.Result && !hasViewAllPermissionTask.Result) { paymentRequestQuery = paymentRequestQuery.Where(pr => pr.CreatedById == loggedInEmployee.Id); } @@ -1994,8 +1994,21 @@ namespace Marco.Pms.Services.Service paymentRequest.IsAdvancePayment = model.IsAdvancePayment; + var paymentRequestUID = $"{paymentRequest.UIDPrefix}/{paymentRequest.UIDPostfix:D5}"; + + try + { + await _context.SaveChangesAsync(); + _logger.LogInfo("PaymentRequest updated successfully with UID: {PaymentRequestUID}", paymentRequestUID); + } + catch (DbUpdateException dbEx) + { + _logger.LogError(dbEx, "Database Exception during Payment Request update"); + return ApiResponse.ErrorResponse("Database exception during payment request updation", ExceptionMapper(dbEx), 500); + } + // Handle bill attachment updates: add new attachments and delete deactivated ones - if (model.BillAttachments?.Any() == true) + if (model.BillAttachments?.Any() == true && !statusCheck) { var newBillAttachments = model.BillAttachments.Where(ba => ba.DocumentId == null && ba.IsActive).ToList(); if (newBillAttachments.Any()) @@ -2071,12 +2084,11 @@ namespace Marco.Pms.Services.Service // Prepare response view model with updated details var response = _mapper.Map(paymentRequest); - response.PaymentRequestUID = $"{paymentRequest.UIDPrefix}/{paymentRequest.UIDPostfix:D5}"; + response.PaymentRequestUID = paymentRequestUID; response.Currency = currency; response.ExpenseCategory = _mapper.Map(expenseCategory); response.Project = _mapper.Map(project); - _logger.LogInfo("PaymentRequest updated successfully with UID: {PaymentRequestUID}", response.PaymentRequestUID); return ApiResponse.SuccessResponse(response, "Payment Request updated successfully.", 200); } catch (ArgumentException ex) @@ -2134,6 +2146,11 @@ namespace Marco.Pms.Services.Service #endregion #region =================================================================== Recurring Payment Functions =================================================================== + public async Task> CreateRecurringPaymentAsync(RecurringTemplateDto model, Employee loggedInEmployee, Guid tenantId) + { + var recurringPayment = _mapper.Map(model); + return ApiResponse.SuccessResponse(recurringPayment, "Recurring Payment Template created successfully", 201); + } #endregion #region =================================================================== Helper Functions =================================================================== diff --git a/Marco.Pms.Services/Service/ServiceInterfaces/IExpensesService.cs b/Marco.Pms.Services/Service/ServiceInterfaces/IExpensesService.cs index e48ddea..0974d2d 100644 --- a/Marco.Pms.Services/Service/ServiceInterfaces/IExpensesService.cs +++ b/Marco.Pms.Services/Service/ServiceInterfaces/IExpensesService.cs @@ -33,6 +33,7 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces #endregion #region =================================================================== Recurring Payment Functions =================================================================== + Task> CreateRecurringPaymentAsync(RecurringTemplateDto model, Employee loggedInEmployee, Guid tenantId); #endregion } }