mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
Merge branch 'fix/pay' into 'development'
[FIX][BE]: fix patch lunas BOP See merge request mbugroup/lti-api!531
This commit is contained in:
@@ -1326,14 +1326,16 @@ func (s *expenseService) Pay(c *fiber.Ctx, id uint) (*expenseDto.ExpenseDetailDT
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Expense is already paid")
|
||||
}
|
||||
|
||||
latestApproval, err := s.ApprovalSvc.LatestByTarget(c.Context(), utils.ApprovalWorkflowExpense, id, nil)
|
||||
latestApproval, err := s.ApprovalSvc.LatestByTarget(c.Context(), utils.ApprovalWorkflowExpense, id, func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("action = ?", entity.ApprovalActionApproved)
|
||||
})
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate workflow")
|
||||
}
|
||||
if latestApproval == nil {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "No approval found. Please create expense first.")
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Expense must be approved by Finance (step 4) before payment")
|
||||
}
|
||||
if latestApproval.StepNumber < uint16(utils.ExpenseStepFinance) || latestApproval.Action == nil || *latestApproval.Action != entity.ApprovalActionApproved {
|
||||
if latestApproval.StepNumber < uint16(utils.ExpenseStepFinance) {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Expense must be approved by Finance (step 4) before payment")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user