﻿USE [FabApprovalSystem]
GO
	/****** Object:  StoredProcedure [dbo].[MRBGetItem]    Script Date: 11/21/2024 11:29:05 AM ******/
SET
	ANSI_NULLS ON
GO
SET
	QUOTED_IDENTIFIER ON
GO
	-- =============================================
	-- Author:		<Author,,Name>
	-- Create date: <Create Date,,>
	-- Description:	<Description,,>
	-- =============================================
	CREATE PROCEDURE [dbo].[MRBGetItem] @MRBNumber INT,
	@UserID INT,
	@IsITAR INT OUTPUT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
SET
	NOCOUNT ON;

DECLARE @RHRowCount INT DECLARE @ITARRowCount INT -- find if there are any Radhard parts	
SELECT
	@RHRowCount = COUNT(*)
FROM
	MRB M
	INNER JOIN MRBLot L ON M.MRBNumber = L.MRBNumber
WHERE
	(L.ProductFamily = 'RH')
	AND M.MRBNumber = @MRBNumber 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
SELECT
	M.*,
	U.FirstName + ' ' + U.LastName AS OwnerName
FROM
	MRB M
	LEFT JOIN Users U ON M.Owner = U.UserID
WHERE
	MRBNumber = @MRBNumber
SELECT
	PartGroupID
FROM
	MRBPartGroupAffected
WHERE
	MRBNumber = @MRBNumber
SELECT
	ModuleID
FROM
	MRBModuleByMRB
WHERE
	MRBNumber = @MRBNumber
SELECT
	DispositionID
FROM
	MRBDispositionByMRB
WHERE
	MRBNumber = @MRBNumber
SELECT
	RiskAssessmentID
FROM
	MRBRiskAssessmentByMRB
WHERE
	MRBNumber = @MRBNumber
END
GO