﻿USE [FabApprovalSystem]
GO
	/****** Object:  UserDefinedFunction [dbo].[fn_GetPRs]    Script Date: 11/21/2024 11:31:55 AM ******/
SET
	ANSI_NULLS ON
GO
SET
	QUOTED_IDENTIFIER ON
GO
	CREATE FUNCTION [dbo].[fn_GetPRs]() RETURNS TABLE AS RETURN (
		SELECT
			'PartsRequest' AS DocumentType,
			'PR' AS SubDoc,
			PR.PRNumber AS IssueID,
			PR.PRNumber AS DocID,
			CreateDate AS IssueDate,
			'' AS LotNos,
			dbo.fnGetApprovalFullNames(PR.PRNumber, 10, ' / ', 0, 1, 1, 0, 0) AS 'PendingApprovers',
			Title,
			Description AS IssueDescription,
			U1.FirstName + ' ' + U1.LastName AS Originator,
			SubmitDate AS SubmitedDate,
			CloseDate
		FROM
			PartsRequest PR
			INNER JOIN Users U1 ON PR.RequestorID = U1.UserID
		WHERE
			CurrentStep >= 0
	)
GO