UFN_PDACCOUNTSYSTEM_GETNUMBEROFSYSTEMSFORUSER

Returns number of accounting systems for user

Return

Return Type
int

Parameters

Parameter Parameter Type Mode Description
@CURRENTAPPUSERID uniqueidentifier IN

Definition

Copy


CREATE function dbo.UFN_PDACCOUNTSYSTEM_GETNUMBEROFSYSTEMSFORUSER
(
    @CURRENTAPPUSERID uniqueidentifier
)
returns int
with execute as caller
as begin

            return(select COUNT(ID) from 
            (
            select 
                T1.ID as ID
            from dbo.PDACCOUNTSYSTEM as T1
            inner join dbo.PDACCOUNTSYSTEMSITE as T2 on T1.ID = T2.PDACCOUNTSYSTEMID
            inner join dbo.UFN_SITESFORUSER(@CURRENTAPPUSERID) as T3 ON T3.SITEID=T2.SITEID
            where T1.ISBASICGL = 1
            union 
            select 
                ID as ID
            from dbo.PDACCOUNTSYSTEM
            where ISBASICGL = 1 and ISDEFAULT = 1 and (select count(*) from dbo.UFN_SITESFORUSER(@CURRENTAPPUSERID)) = 0
            union 
            select 
                ID as ID
            from dbo.PDACCOUNTSYSTEM
            where ISBASICGL = 1 and dbo.UFN_APPUSER_ISSYSADMIN(@CURRENTAPPUSERID) = 1
            union 
            select 
                ID as ID
            from dbo.PDACCOUNTSYSTEM
            where ((select count(id) from SYSTEMROLEAPPUSER where SECURITYMODECODE = 0 and APPUSERID = @CURRENTAPPUSERID) > 0)        
            union
            select 
                ID as ID
            from dbo.PDACCOUNTSYSTEM
            where ISBASICGL = 0 and dbo.UFN_INSTALLEDPRODUCTS_PRODUCTIS('F5138EB6-6666-497A-8FB2-BAE24389AAE4') = 1                            
            )    CountTable)
    end