

Insert Into dbo.Scripts
Values('Hotfix 21060711 General Insert Practice Bankfeed Account', GetDate(), '|~|')
Go


--Insert into default COA
Declare @Temp Table
	(TemplateID Int
	,LocationID Int)


DELETE FROM @Temp

INSERT	
INTO 	@Temp

SELECT	TemplateID,LocationID
FROM 	dbo.Template t
WHERE	TemplateID Not In (Select TemplateID From dbo.AccountTemplate Where TemplateID = t.TemplateID And AccountUID = '{116A4CC2-B84D-45F1-A91C-966F5FA041CB}' ) 
AND		AdminSubTypeID In(1,2,3)




INSERT AccountTemplate (TemplateID,AccountUID,AccountGroupID,AccountCode,CurrencyTypeID,Description,LongDescription,IsPickable,IsCore,ParentAccount_AccountID,TaxCodeID,Balance,EntryCount,AssetClassID,CreditorClaimTypeID,IsDefault,IsInactive,CreatedDate,CreatedBy,UpdatedDate,UpdatedBy,TS)
SELECT t.TemplateID
	,'{116A4CC2-B84D-45F1-A91C-966F5FA041CB}'
	,1090
	,Null
	,0
	,'Bankfeed' ,Null,1,1,Null,NULL,0,0,NULL,Null,0,0,GetDate(),'Admin',GetDate(),'Admin',NewID()

FROM 	@Temp t

Update AccountTemplate
Set AssetClassID = CASE WHEN AdminSubTypeID = 2 THEN 900 ELSE 20 END
From Accounttemplate at
Inner
Join Template t
On t.templateID = at.TemplateID
Where AccountUID = '{116A4CC2-B84D-45F1-A91C-966F5FA041CB}'

Go





DECLARE @Admin Table
	(AdminID Int
	,CurrencyTypeID Int
	,AssetClassID Int)

INSERT	
INTO 	@Admin

SELECT	AdminID
	,BaseCurrencyType_CurrencyTypeID
	,Null --CASE WHEN AdminSubTypeID = 2 THEN 900 ELSE 20 END

FROM 	dbo.Admin a
INNER
JOIN	dbo.AdminType at
On		at.adminTypeID = a.AdminTypeID

WHERE	AdminID Not In (Select AdminID From dbo.Account Where AdminID = a.AdminID And AccountUID = '{116A4CC2-B84D-45F1-A91C-966F5FA041CB}' ) 
AND	((AdminStatusID = 1) OR (AdminStatusID = 2 AND a.AdminTypeID = 1000))
AND Exists (Select * from Account Where AdminID = a.AdminID)



INSERT Account (AdminID,AccountUID,AccountGroupID,AccountCode,CurrencyTypeID,Description,LongDescription,IsPickable,IsCore,ParentAccount_AccountID,TaxCodeID,AssetClassID,CreditorClaimTypeID,IsDefault,IsInactive,CreatedDate,CreatedBy,UpdatedDate,UpdatedBy,TS)

SELECT a.AdminID
	,'{116A4CC2-B84D-45F1-A91C-966F5FA041CB}'
	,1090
	,Null
	,a.CurrencyTypeID
	,'Bankfeed' ,Null,1,1,Null,NULL,AssetClassID,Null
	,0,0
	,GetDate(),'Admin',GetDate(),'Admin',NewID()

FROM 	@Admin a

Go






