CREATE or alter PROC [dbo].[mnrPrcExtraInitTblMain]
AS

	Declare 
		@ID uniqueidentifier,
		@SubID uniqueidentifier

	
	--select * from mnrRepTableMain

	delete from mnrRepTableMain where TblName='mnrLogFile'

--------------// mnrFileInfo//---
		set @ID = 0x0
	select @ID = ID from [mnrRepTableMain] where TblOut = 'mnrFileInfo'
	if( ISNULL( @id, 0x0) = 0x0)
	begin
		set @ID = NewID()						
		insert into [dbo].[mnrRepTableMain]( [ID],[Number],[TblName],	[TblOut],  [FldKeyName],[TblDesc],[FldNoteName] )
		select  @ID, 25,'mnrFileInfo','mnrFileInfo','ID','FileInfo','Type'
	end

--------------// mnrBranch//---
		set @ID = 0x0
	select @ID = ID from [mnrRepTableMain] where TblOut = 'mnrBranch'
	if( ISNULL( @id, 0x0) = 0x0)
	begin
		set @ID = NewID()						
		insert into [dbo].[mnrRepTableMain]( [ID],[Number],[TblName],	[TblOut],  [FldKeyName],[TblDesc],[FldNoteName] )
		select  @ID, 26,'mnrBranch','mnrBranch','ID','Branch','Name'
	end

--------------// mnrActivity//---
		set @ID = 0x0
	select @ID = ID from [mnrRepTableMain] where TblOut = 'mnrActivity'
	if( ISNULL( @id, 0x0) = 0x0)
	begin
		set @ID = NewID()						
		insert into [dbo].[mnrRepTableMain]( [ID],[Number],[TblName],	[TblOut],  [FldKeyName],[TblDesc],[FldNoteName] )
		select  @ID, 27,'mnrActivity','mnrActivity','ID','Activity','Name'
	end

--------------// mnrFileOption//---
	set @ID = 0x0
	select @ID = ID from [mnrRepTableMain] where TblOut = 'mnrFileOption'
	if( ISNULL( @id, 0x0) = 0x0)
	begin
		set @ID = NewID()						
		insert into [dbo].[mnrRepTableMain]( [ID],[Number],[TblName],	[TblOut],  [FldKeyName],[TblDesc],[FldNoteName] )
		select  @ID, 28,'mnrFileOption','mnrFileOption','ID','FileOption','StrValue2'
	end
--------------// mnrcurhistory//---
	set @ID = 0x0
	select @ID = ID from [mnrRepTableMain] where TblOut = 'mnrcurhistory'
	if( ISNULL( @id, 0x0) = 0x0)
	begin
		set @ID = NewID()						
		insert into [dbo].[mnrRepTableMain]( [ID],[Number],[TblName],	[TblOut],  [FldKeyName],[TblDesc],[FldNoteName] )
		select  @ID, 29,'mnrcurhistory','mnrcurhistory','ID','curhistory','CurrencyVal'
	end
	--select * from mnrcurhistory

	--select * from [mnrRepTableMain] WHERE TBLNAME='mnrFileOption'
	-- DELETE from [mnrRepTableMain] WHERE TBLNAME='mnrFileOption'
----------------// t//---

	select @ID = ID from [mnrRepTableMain] where TblOut = 'mnrMaterial'
	if( ISNULL( @ID, 0x0) != 0x0)
	begin
-------Sub----->>>>
	set @SubID = 0x0
		select @SubID = ID from [mnrRepTableSub] where TblOut = 'mnrMatStore'
		if( ISNULL( @SubID, 0x0) = 0x0)
		begin
			set @SubID = NewID()
			insert into [dbo].[mnrRepTableSub] ( [ID], [Number], [mnrRepTableMainID], [TblName], [TblOut], [TblDesc], [FldLink], [TblMaster1], [FldMaster1])
			select	@SubID,	1, @ID,'mnrMatStore', 'mnrMatStore', '', 'MatID', 'mnrMaterial', 'ID'
		end

	set @SubID = 0x0
		select @SubID = ID from [mnrRepTableSub] where TblOut = 'mnrmatbarcode'
		if( ISNULL( @SubID, 0x0) = 0x0)
		begin
			set @SubID = NewID()
			insert into [dbo].[mnrRepTableSub] ( [ID], [Number], [mnrRepTableMainID], [TblName], [TblOut], [TblDesc], [FldLink], [TblMaster1], [FldMaster1])
			select	@SubID,	5, @ID,'mnrmatbarcode', 'mnrmatbarcode', '', 'MatID', 'mnrMaterial', 'ID'
		end

    end



	select @ID = ID from [mnrRepTableMain] where TblOut = 'mnrcust'
	if( ISNULL( @ID, 0x0) != 0x0)
	begin
-------Sub----->>>>
	set @SubID = 0x0
		select @SubID = ID from [mnrRepTableSub] where TblOut = 'mnrCustPrice'
		if( ISNULL( @SubID, 0x0) = 0x0)
		begin
			set @SubID = NewID()
			insert into [dbo].[mnrRepTableSub] ( [ID], [Number], [mnrRepTableMainID], [TblName], [TblOut], [TblDesc], [FldLink], [TblMaster1], [FldMaster1])
			select	@SubID,	1, @ID,'mnrCustPrice', 'mnrCustPrice', '', 'CustID', 'mnrcust', 'ID'
		end

    end
--#END#	
--select * from mnrMatStore
--update mnrCustPrice set id=id
--select * from mnrCustPrice
--select * from mnrcust


