﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[ECNGetItemForRead_05132020]    Script Date: 11/21/2024 11:29:04 AM ******/
SET
	ANSI_NULLS ON
GO
SET
	QUOTED_IDENTIFIER ON
GO
	CREATE PROCEDURE [dbo].[ECNGetItemForRead_05132020] -- Add the parameters for the stored procedure here
	@ECNNumber INT,
	@UserID INT,
	@IsITAR INT OUTPUT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	DECLARE @RHRowCount INT DECLARE @ITARRowCount INT -- find if there are any Radhard parts
SELECT
	@RHRowCount = (
		SELECT
			COUNT(*)
		FROM
			ECN E
		WHERE
			(
				E.IsRH = 1
				AND E.IsAU = 0
				AND E.IsIndustrial = 0
				AND E.IsMA = 0
			)
			AND E.ECNNumber = @ECNNumber
	) IF (@RHRowCount > 0) BEGIN -- get the ITAR accessibility
SELECT
	@ITARRowCount = COUNT(*)
FROM
	dbo.fnIsUserITARCompliant(@UserID) IF (@ITARRowCount > 0)
SET
	@IsITAR = 1
	ELSE
SET
	@IsITAR = 0
END -- Insert statements for procedure here
SELECT
	E.*,
	U.FirstName + ' ' + U.LastName AS 'OriginatorName',
	U1.FirstName + ' ' + U1.LastName AS RecordLockByName
FROM
	ECN E
	INNER JOIN Users U ON E.OriginatorID = U.UserID
	LEFT JOIN Users U1 ON E.RecordLockedBy = U1.UserID
WHERE
	ECNNumber = @ECNNumber
SELECT
	DepartmentID
FROM
	ECNAffectedDepartment
WHERE
	ECNNumber = @ECNNumber
SELECT
	ModuleID
FROM
	ECNAffectedModule
WHERE
	ECNNumber = @ECNNumber
SELECT
	AreaID
FROM
	ECNAffectedArea
WHERE
	ECNNumber = @ECNNumber
SELECT
	TechnologyID
FROM
	ECNAffectedTechnology
WHERE
	ECNNumber = @ECNNumber
SELECT
	AcknowledgementTrainingByID
FROM
	ECNAcknowledgementBy
WHERE
	ECNNumber = @ECNNumber
SELECT
	AcknowledgementTrainingByID
FROM
	ECNTrainingBy
WHERE
	ECNNumber = @ECNNumber
SELECT
	ProductFamilyID
FROM
	ECNAffectedProductFamily
WHERE
	ECNNumber = @ECNNumber
END
GO