

/****** Object:  StoredProcedure [dbo].[vesp_RofstHeaderInsert]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstHeaderInsert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstHeaderInsert]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetRofstByID]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetRofstByID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetRofstByID]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetDatabases]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetDatabases]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetDatabases]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetDatabaseByID]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetDatabaseByID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetDatabaseByID]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildrenByRoid]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetChildrenByRoid]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByRoid]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildrenByRofstID]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetChildrenByRofstID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByRofstID]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildrenByID]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetChildrenByID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetChildrenByID]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildByRoid]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetChildByRoid]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByRoid]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildByID]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetChildByID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByID]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildByAccPageID]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataGetChildByAccPageID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataGetChildByAccPageID]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataExists]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDataExists]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDataExists]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDatabaseInsert]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstDatabaseInsert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstDatabaseInsert]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstChildInsert]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vesp_RofstChildInsert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[vesp_RofstChildInsert]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RofstHeader_ROFsts]') AND parent_object_id = OBJECT_ID(N'[dbo].[RofstHeader]'))
ALTER TABLE [dbo].[RofstHeader] DROP CONSTRAINT [FK_RofstHeader_ROFsts]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RofstDatabase_RofstHeader]') AND parent_object_id = OBJECT_ID(N'[dbo].[RofstDatabase]'))
ALTER TABLE [dbo].[RofstDatabase] DROP CONSTRAINT [FK_RofstDatabase_RofstHeader]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RofstChild_RofstDatabase]') AND parent_object_id = OBJECT_ID(N'[dbo].[RofstChild]'))
ALTER TABLE [dbo].[RofstChild] DROP CONSTRAINT [FK_RofstChild_RofstDatabase]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DF_RofstHeader_CreateDate]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[RofstHeader] DROP CONSTRAINT [DF_RofstHeader_CreateDate]
END
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DF_RofstHeader_CreateUserID]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[RofstHeader] DROP CONSTRAINT [DF_RofstHeader_CreateUserID]
END
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DF_RofstDatabase_ParentID]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[RofstDatabase] DROP CONSTRAINT [DF_RofstDatabase_ParentID]
END
GO
/****** Object:  Index [IX_RofstID_Roid]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[RofstChild]') AND name = N'IX_RofstID_Roid')
DROP INDEX [IX_RofstID_Roid] ON [dbo].[RofstChild]
GO
/****** Object:  Index [IX_RofstID_DbiID_ParentID]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[RofstChild]') AND name = N'IX_RofstID_DbiID_ParentID')
DROP INDEX [IX_RofstID_DbiID_ParentID] ON [dbo].[RofstChild]
GO
/****** Object:  View [dbo].[vwRofstData_RofstHeaders]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vwRofstData_RofstHeaders]'))
DROP VIEW [dbo].[vwRofstData_RofstHeaders]
GO
/****** Object:  View [dbo].[vwRofstData_RofstGroups]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vwRofstData_RofstGroups]'))
DROP VIEW [dbo].[vwRofstData_RofstGroups]
GO
/****** Object:  View [dbo].[vwRofstData_RofstDatabases]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vwRofstData_RofstDatabases]'))
DROP VIEW [dbo].[vwRofstData_RofstDatabases]
GO
/****** Object:  View [dbo].[vwRofstData_RofstChildren]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vwRofstData_RofstChildren]'))
DROP VIEW [dbo].[vwRofstData_RofstChildren]
GO
/****** Object:  Table [dbo].[RofstHeader]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RofstHeader]') AND type in (N'U'))
DROP TABLE [dbo].[RofstHeader]
GO
/****** Object:  Table [dbo].[RofstDatabase]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RofstDatabase]') AND type in (N'U'))
DROP TABLE [dbo].[RofstDatabase]
GO
/****** Object:  Table [dbo].[RofstChild]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RofstChild]') AND type in (N'U'))
DROP TABLE [dbo].[RofstChild]
GO

/****** Object:  UserDefinedFunction [dbo].[vefn_ParseStringListToTable]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vefn_ParseStringListToTable]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[vefn_ParseStringListToTable]
GO
/****** Object:  UserDefinedFunction [dbo].[vefn_NumOfOccurrences]    Script Date: 4/13/2022 2:38:17 PM ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vefn_NumOfOccurrences]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[vefn_NumOfOccurrences]
GO
/****** Object:  UserDefinedFunction [dbo].[vefn_NumOfOccurrences]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- ==========================================================================================
-- Author:		Jake Ropar
-- Create Date: 3/1/2022
-- Description:	Returns the number of occurences of a specific value in a specified string
-- ==========================================================================================

CREATE FUNCTION [dbo].[vefn_NumOfOccurrences](@Text VarChar(Max), @Value VarChar(Max)) Returns Int
WITH EXECUTE AS OWNER
AS
BEGIN
	
	Declare @ValueCount Int;

	If (Len(@Value) = 0)
		Set @ValueCount = 0;
	Else
		Set @ValueCount = (Len(@Text) - Len(Replace(@Text, @Value, ''))) / Len(@Value);

	Return @ValueCount;

END
GO
/****** Object:  UserDefinedFunction [dbo].[vefn_ParseStringListToTable]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- ==========================================================================================
-- Author:		Jake Ropar
-- Create Date: 3/26/2018
-- Description:	Splits a delimited list of strings into a table of string values
-- ==========================================================================================

Create Function [dbo].[vefn_ParseStringListToTable] ( @List VarChar(Max), @Delimeter VarChar(1) = null )
Returns @RetVal Table (ListPosition Int Identity(1,1) Not Null, ListValue VarChar(Max) Not Null)
With Execute As Owner
As
Begin

	Declare @Position Int;
	Declare @TextPosition Int;
	Declare @Length smallint;
	Declare @String VarChar(Max);
	Declare @TempString VarChar(Max);
	Declare @LeftOver VarChar(Max);

    Set @TextPosition = 1;
	Set @LeftOver = '';
	Set @Delimeter = IsNull(@Delimeter, ',');

	If (DataLength(@List) = 1)
		Insert @RetVal (ListValue) Values (Cast(@List as VarChar(Max)));
	Else
		Begin
			While (@TextPosition <= DataLength(@List) / 2)
			Begin

				 Set @Length = (4000 - DataLength(@LeftOver) / 2);
				 Set @TempString = LTrim(@LeftOver + Substring(@List, @TextPosition, @Length));
				 Set @TextPosition = @TextPosition + @Length;
				 Set @Position = CharIndex(@Delimeter, @TempString);

				 While (@Position > 0)
				 Begin

					Set @String = Substring(@TempString, 1, @Position - 1);

					Insert @RetVal (ListValue) Values (Cast(@String as VarChar(Max)));

					Set @TempString = LTrim(Substring(@TempString, @Position + 1, Len(@TempString)));
					Set @Position = CharIndex(@Delimeter, @TempString);

				 End

				 Set @LeftOver = @TempString;
			End
		End

	If (LTrim(RTrim(@LeftOver)) <> '')
         Insert @RetVal (ListValue) Values (Cast(@LeftOver as VarChar(Max)));

	Return;
End

GO


/****** Object:  Table [dbo].[RofstChild]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RofstChild](
	[RofstChildID] [int] IDENTITY(1,1) NOT NULL,
	[RofstID] [int] NOT NULL,
	[dbiID] [int] NOT NULL,
	[ID] [int] NOT NULL,
	[ParentID] [int] NOT NULL,
	[type] [int] NOT NULL,
	[title] [varchar](max) NOT NULL,
	[roid] [varchar](50) NOT NULL,
	[appid] [varchar](max) NULL,
	[value] [varchar](max) NULL,
 CONSTRAINT [PK_RofstChild] PRIMARY KEY CLUSTERED 
(
	[RofstChildID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RofstDatabase]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RofstDatabase](
	[RofstID] [int] NOT NULL,
	[dbiID] [int] NOT NULL,
	[dbiType] [int] NOT NULL,
	[dbiAW] [int] NOT NULL,
	[dbiTitle] [varchar](max) NOT NULL,
	[dbiAP] [varchar](max) NOT NULL,
	[ID] [int] NOT NULL,
	[ParentID] [int] NOT NULL,
 CONSTRAINT [PK_RofstDatabase_1] PRIMARY KEY CLUSTERED 
(
	[RofstID] ASC,
	[dbiID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[RofstHeader]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RofstHeader](
	[RofstID] [int] NOT NULL,
	[hSize] [int] NOT NULL,
	[hMonth] [int] NOT NULL,
	[hDay] [int] NOT NULL,
	[hcYear] [int] NOT NULL,
	[hcMonth] [int] NOT NULL,
	[hcDay] [int] NOT NULL,
	[hcHour] [int] NOT NULL,
	[hcMin] [int] NOT NULL,
	[hcSec] [int] NOT NULL,
	[hcHund] [int] NOT NULL,
	[CreateUserID] [varchar](50) NOT NULL,
	[CreateDate] [datetime] NOT NULL,
 CONSTRAINT [PK_RofstHeader] PRIMARY KEY CLUSTERED 
(
	[RofstID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[vwRofstData_RofstChildren]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
	
/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2024
 Description:	(RofstData) Master View for RofstChildren (RoChild & Groups)
==========================================================================================================
*/
Create View [dbo].[vwRofstData_RofstChildren]
As

	Select rc.RofstChildID as 'RofstChildID',
		rd.RofstID as 'RofstID',
		-- RoDatabase Info
		rd.dbiID as 'dbiID',
		rd.dbiType as 'dbiType',
		rd.dbiAW as 'dbiAW',
		rd.dbiTitle as 'dbiTitle',
		rd.dbiAP as 'dbiAP',
		-- RoChild Info
		rc.ID as 'ID',
		rc.ParentID as 'ParentID',
		rc.[type] as 'type',
		rc.title as 'title',
		rc.roid as 'roid',
		rc.appid as 'appid',
		rc.[value] as 'value',
		Case When (Not rc.[value] is null) Then rd.dbiAP + '-' + rc.appid Else null End as 'AccPageID'
	From RofstChild rc With (NoLock)
		inner join RofstDatabase rd With (NoLock) on rc.RofstID = rd.RofstID and rc.dbiID = rd.dbiID;


GO
/****** Object:  View [dbo].[vwRofstData_RofstDatabases]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
	
/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2024
 Description:	(RofstData) Master View for RofstDatabases
==========================================================================================================
*/
Create View [dbo].[vwRofstData_RofstDatabases]
As

	Select rd.RofstID as 'RofstID',
		rd.dbiID as 'dbiID',
		rd.dbiType as 'dbiType',
		rd.dbiAW as 'dbiAW',
		rd.dbiTitle as 'dbiTitle',
		rd.dbiAP as 'dbiAP',
		rd.ID as 'ID',
		rd.ParentID as 'ParentID'
	From RofstDatabase rd With (NoLock)


GO
/****** Object:  View [dbo].[vwRofstData_RofstGroups]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
	
/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2024
 Description:	(RofstData) Master View for RofstGroups
==========================================================================================================
*/
Create View [dbo].[vwRofstData_RofstGroups]
As

	Select rd.RofstID as 'RofstID',
		-- RoDatabase Info
		rd.dbiID as 'dbiID',
		rd.dbiType as 'dbiType',
		rd.dbiAW as 'dbiAW',
		rd.dbiTitle as 'dbiTitle',
		rd.dbiAP as 'dbiAP',
		-- RoChild Info
		rc.ID as 'ID',
		rc.ParentID as 'ParentID',
		rc.[type] as 'type',
		rc.title as 'title',
		rc.roid as 'riod'
	From RofstChild rc With (NoLock)
		inner join RofstDatabase rd With (NoLock) on rc.RofstID = rd.RofstID and rc.dbiID = rd.dbiID
	Where rc.[value] is null; 

GO
/****** Object:  View [dbo].[vwRofstData_RofstHeaders]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
	
/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2024
 Description:	(RofstData) Master View for RofstHeaders
==========================================================================================================
*/
Create View [dbo].[vwRofstData_RofstHeaders]
As

	Select rh.RofstID as 'RofstID',
		rh.hSize as 'hSize',
		rh.hMonth as 'hMonth',
		rh.hDay as 'hDay',
		rh.hcYear as 'hcYear',
		rh.hcMonth as 'hcMonth',
		rh.hcDay as 'hcDay',
		rh.hcHour as 'hcHour',
		rh.hcMin as 'hcMin',
		rh.hcSec as 'hcSec',
		rh.hcHund as 'hcHund',
		rh.CreateUserID as 'CreateUserID',
		rh.CreateDate as 'CreateDate'
	From RofstHeader rh With (NoLock)


GO
/****** Object:  Index [IX_RofstID_DbiID_ParentID]    Script Date: 4/13/2022 2:38:17 PM ******/
CREATE NONCLUSTERED INDEX [IX_RofstID_DbiID_ParentID] ON [dbo].[RofstChild]
(
	[RofstID] ASC,
	[dbiID] ASC,
	[ParentID] ASC
)
INCLUDE([ID],[type],[title],[roid],[appid],[value]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object:  Index [IX_RofstID_Roid]    Script Date: 4/13/2022 2:38:17 PM ******/
CREATE NONCLUSTERED INDEX [IX_RofstID_Roid] ON [dbo].[RofstChild]
(
	[RofstID] ASC,
	[roid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RofstDatabase] ADD  CONSTRAINT [DF_RofstDatabase_ParentID]  DEFAULT ((0)) FOR [ParentID]
GO
ALTER TABLE [dbo].[RofstHeader] ADD  CONSTRAINT [DF_RofstHeader_CreateUserID]  DEFAULT ('SYSTEM') FOR [CreateUserID]
GO
ALTER TABLE [dbo].[RofstHeader] ADD  CONSTRAINT [DF_RofstHeader_CreateDate]  DEFAULT (getdate()) FOR [CreateDate]
GO
ALTER TABLE [dbo].[RofstChild]  WITH CHECK ADD  CONSTRAINT [FK_RofstChild_RofstDatabase] FOREIGN KEY([RofstID], [dbiID])
REFERENCES [dbo].[RofstDatabase] ([RofstID], [dbiID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[RofstChild] CHECK CONSTRAINT [FK_RofstChild_RofstDatabase]
GO
ALTER TABLE [dbo].[RofstDatabase]  WITH CHECK ADD  CONSTRAINT [FK_RofstDatabase_RofstHeader] FOREIGN KEY([RofstID])
REFERENCES [dbo].[RofstHeader] ([RofstID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[RofstDatabase] CHECK CONSTRAINT [FK_RofstDatabase_RofstHeader]
GO
ALTER TABLE [dbo].[RofstHeader]  WITH CHECK ADD  CONSTRAINT [FK_RofstHeader_ROFsts] FOREIGN KEY([RofstID])
REFERENCES [dbo].[ROFsts] ([ROFstID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[RofstHeader] CHECK CONSTRAINT [FK_RofstHeader_ROFsts]
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstChildInsert]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstChildInsert]
(
	@RofstID Int,
	@ID Int,
	@ParentID Int,
	@dbiID Int,
	@type Int,
	@title VarChar(Max),
	@roid VarChar(50),
	@appid VarChar(Max) = null,
	@value VarChar(Max) = null
)
With Execute as Owner
As
Begin

	
	-- Create Rofst Child/Group Record
	Insert Into RofstChild (RofstID, ID, ParentID, dbiID, [type], title, roid, appid, [value])
	Values (@RofstID, @ID, @ParentID, @dbiID, @type, @title, @roid, @appid, @value);


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDatabaseInsert]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDatabaseInsert]
(
	@RofstID Int,
	@dbiID Int,
	@dbiType Int,
	@dbiAW Int,
	@dbiTitle VarChar(Max),
	@dbiAP VarChar(Max),
	@ID Int,
	@ParentID Int
)
With Execute as Owner
As
Begin

	
	Insert Into RofstDatabase ( RofstID, dbiID, dbiType, dbiAW, dbiTitle, dbiAP, ID, ParentID)
	Values ( @RofstID, @dbiID, @dbiType, @dbiAW, @dbiTitle, @dbiAP, @ID, @ParentID);
	
Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataExists]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataExists]
(
	@RofstID int
)
With Execute as Owner
As
Begin

	Select Count(1) 
	From RofstHeader with (NoLock)
	Where RofstID = @RofstID;


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildByAccPageID]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetChildByAccPageID]
(
	@RofstID int,
	@AccPageID VarChar(50)
)
With Execute as Owner
As
Begin

	Select rc.ROFstID,
		rc.dbiID,
		rc.ID,
		rc.ParentID,
		rc.[type],
		rc.title,
		rc.roid,
		rc.appid,
		rc.[value],
		rc.AccPageID
	From vwRofstData_RofstChildren rc
	Where rc.RofstID = @RofstID
		And rc.AccPageID = @AccPageID;

Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildByID]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetChildByID]
(
	@RofstID int,
	@DbiID int,
	@ID Int
)
With Execute as Owner
As
Begin

	Select rc.RofstID,
		rc.dbiID,
		rc.ID,
		rc.ParentID,
		rc.[type],
		rc.title,
		rc.roid,
		rc.appid,
		rc.[value],
		rc.AccPageID
	From vwRofstData_RofstChildren rc
	Where rc.RofstID = @RofstID
		And rc.dbiID = @DbiID 
		And rc.ID = @ID;


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildByRoid]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetChildByRoid]
(
	@RofstID int,
	@Roid VarChar(50)
)
With Execute as Owner
As
Begin

	Select rc.ROFstID,
		rc.dbiID,
		rc.ID,
		rc.ParentID,
		rc.[type],
		rc.title,
		rc.roid,
		rc.appid,
		rc.[value],
		rc.AccPageID
	From vwRofstData_RofstChildren rc
	Where rc.RofstID = @RofstID
		And rc.roid = @Roid;

Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildrenByID]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetChildrenByID]
(
	@RofstID int,
	@DbiID int,
	@ID Int
)
With Execute as Owner
As
Begin
		
	
	Select rc.RofstID,
		rc.dbiID,
		rc.ID,
		rc.ParentID,
		rc.[type],
		rc.title,
		rc.roid,
		rc.appid,
		rc.[value],
		rc.AccPageID
	From vwRofstData_RofstChildren rc
	Where rc.RofstID = @RofstID 
		And rc.dbiID = @DbiID 	
		And rc.ParentID = @ID
	Order By rc.ID Asc;


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildrenByRofstID]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetChildrenByRofstID]
(
	@RofstID int
)
With Execute as Owner
As
Begin
		
	Select rc.RofstID,
		rc.dbiID,
		rc.ID,
		rc.ParentID,
		rc.[type],
		rc.title,
		rc.roid,
		rc.appid,
		rc.[value],
		rc.AccPageID
	From vwRofstData_RofstChildren rc 
	Where rc.RofstID = @RofstID
		And Not rc.[value] is null
	Order By rc.dbiID Asc, rc.[type] Asc, rc.roid Asc;


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetChildrenByRoid]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetChildrenByRoid]
(
	@RofstID int,
	@Roid VarChar(50)
)
With Execute as Owner
As
Begin
		
	With RoParent as 
	(
		Select RofstID, dbiID, ID, [type], title, roid
		From vwRofstData_RofstChildren
		Where RofstID = @RofstID And roid = @Roid
	)
	Select rc.RofstID,
		rc.dbiID,
		-- Ro Parent Info
		rp.[type] as 'ParentType',
		rp.title as 'ParentTitle',
		rp.roid as 'ParentRoid',
		-- Ro Child Info
		rc.ID,
		rc.ParentID,
		rc.[type],
		rc.title,
		rc.roid,
		rc.appid,
		rc.[value],
		rc.AccPageID
	From RoParent rp
		inner join vwRofstData_RofstChildren rc on rc.RofstID = rp.RofstID and rc.dbiID = rp.dbiID and rc.ParentID = rp.ID 
	Order By rc.ID Asc;


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetDatabaseByID]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetDatabaseByID]
(
	@RofstID int,
	@dbiID int
)
With Execute as Owner
As
Begin

	Select rd.RofstID,
		rd.dbiID,
		rd.dbiType,
		rd.dbiAW,
		rd.dbiTitle,
		rd.dbiAP,
		rd.ID,
		rd.ParentID
	From vwRofstData_RofstDatabases rd
	Where rd.RofstID = @RofstID
		And rd.dbiID = @dbiID;


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetDatabases]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetDatabases]
(
	@RofstID int
)
With Execute as Owner
As
Begin

	Select rd.RofstID,
		rd.dbiID,
		rd.dbiType,
		rd.dbiAW,
		rd.dbiTitle,
		rd.dbiAP,
		rd.ID,
		rd.ParentID
	From vwRofstData_RofstDatabases rd
	Where rd.RofstID = @RofstID
	Order By rd.dbiID Asc;


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstDataGetRofstByID]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstDataGetRofstByID]
(
	@RofstID int,
	@IncludeRoLookup Bit
)
With Execute as Owner
As
Begin

	Select r.ROFstID,
		r.RODbID,
		Case (@IncludeRoLookup) When 1 Then r.ROLookup Else null End as 'ROLookup',
		r.DTS,
		r.UserID,
		r.LastChanged
	From ROFsts r with (NoLock)
	Where r.RofstID = @RofstID;


Return;
End
	
GO
/****** Object:  StoredProcedure [dbo].[vesp_RofstHeaderInsert]    Script Date: 4/13/2022 2:38:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*****************************************************************************
   Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
       Copyright 2020 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
/*
==========================================================================================================
 Author:		Jake Ropar
 Create Date:	03/24/2022
 Description:	
==========================================================================================================
 */
Create Procedure [dbo].[vesp_RofstHeaderInsert]
(
	@RofstID Int,
	@hSize Int,
	@hMonth Int,
	@hDay Int,
	@hcYear Int,
	@hcMonth Int,
	@hcDay Int,
	@hcHour Int,
	@hcMin Int,
	@hcSec Int,
	@hcHund Int,
	@UserID VarChar(50)
)
With Execute as Owner
As
Begin

	Insert Into RofstHeader (RofstID, hSize, hMonth, hDay, hcYear, hcMonth, hcDay, hcHour, hcMin, hcSec, hcHund, CreateUserID, CreateDate)
	Values (@RofstID, @hSize, @hMonth, @hDay, @hcYear, @hcMonth, @hcDay, @hcHour, @hcMin, @hcSec, @hcHund, @UserID, GetDate());
	
Return;
End
	
GO
