﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[GetApproversList]    Script Date: 11/21/2024 11:29:04 AM ******/
SET
	ANSI_NULLS ON
GO
SET
	QUOTED_IDENTIFIER ON
GO
	-- =============================================
	-- Author:		<Author,,Name>
	-- Create date: <Create Date,,>
	-- Description:	<Description,,>
	-- =============================================
	CREATE PROCEDURE [dbo].[GetApproversList] -- Add the parameters for the stored procedure here
	@IssueID INT,
	@Step INT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
SET
	NOCOUNT ON;

-- Insert statements for procedure here
SELECT
	U.UserID,
	U.FirstName + ' ' + U.LastName AS 'FullName',
	CASE
		WHEN ItemStatus = 0 THEN 'Pending'
		WHEN ItemStatus = 1 THEN 'Approved'
		WHEN ItemStatus = 2 THEN 'Denied'
		WHEN ItemStatus = 3 THEN 'Waiting'
		WHEN ItemStatus = 4 THEN 'Skipped'
		WHEN ItemStatus = 5 THEN 'ReAssigned'
		WHEN ItemStatus = 6 THEN 'Terminated'
	END AS 'Status',
	RoleName,
	SubRole AS 'SubRoleName',
	AssignedDate,
	CompletedDate,
	Comments
FROM
	Approval A
	INNER JOIN Users U ON A.UserID = U.UserID
WHERE
	IssueID = @IssueID
	AND DocumentTypeID = 1
ORDER BY
	ItemStatus
END
GO