Guest User

Untitled

a guest
Nov 16th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.33 KB | None | 0 0
  1. create or replace FUNCTION "dbUserReg".tbUserRegVW_UserData ( in _UserID int , in AccID int
  2. ,in _id int = null
  3. )
  4. returns table (
  5. id int
  6. , ContactID int
  7. -- * Ancestor fields - tbContact
  8. ,prefix text, FirstName text, LastName text, Suffix text
  9. -- ,PrefixEng text, FirstNameEng text, LastNameEng text, SuffixEng text
  10. -- ,StatNames text
  11. -- ,CitizenID text, TaxID text
  12. --,PhoneWork text, PhoneWorkExt text
  13. --,PhoneHome text, PhoneHomeExt text
  14. --,PhoneResident text, PhoneResidentExt text
  15. ,Mobile1 text --, Mobile2 text
  16. --,FaxWork text,FaxHome text,FaxResident text
  17. ,EmailHome text -- , URLHome text
  18. --,AddrHome text,AddrWork text,AddrResident text
  19. --,AddrHomeID int,AddrWorkID int,AddrResidentID int
  20. --* Employee info
  21. --,EmpNo text
  22. --, Groups text
  23. --* Orgnaization
  24. --,OrgID int
  25. -- ,OrgNo text
  26. -- ,OrgName text
  27. --,StartJob date
  28. --,FinishJob date
  29. --,RemarkOrg text
  30. --* Position
  31. --,PositionID int -- Active position
  32. -- ,PositionName text
  33. --,StartPos date
  34. --,FinishPos date
  35. --,RemarkPos text
  36. --* Employment
  37. --,StartEmp date
  38. --,FinishEmp date
  39. --,RemarkEmp text
  40. --* Wages unit
  41. --,uomid int
  42. -- ,uom text
  43. -- * User and A/C
  44. ,UID int , ACC int
  45. ,CompID int
  46. ,CompPrefix text , CompFirstName text, CompSuffix text
  47. ,UserName text
  48. ,UserPass text
  49. ,Salt text
  50.  
  51. ,SysRole text -- "dbUserAcc".UserSystemRole
  52. ,EmpID int
  53. ,Deleted boolean
  54. ,UserID int
  55. ,OrgID int
  56.  
  57. ,Grp Text
  58. ,privilege text
  59. ,idgrp int
  60. ,dis smallint
  61. ,fqty smallint
  62. ,user_role boolean
  63. ,acname text
  64. ,acname_contactid int
  65. ) AS $$
  66. begin
  67. return query
  68. select
  69. ab.id
  70. -- * Data
  71. ,ab.Contactid -- a.ID ContactID
  72. ,a.prefix ::text, a.FirstName ::text, a.LastName ::text, a.Suffix ::text
  73. -- ,a.PrefixEng::text, a.FirstNameEng::text, a.LastNameEng::text, a.SuffixEng::text
  74. -- ,a.StatNames
  75. -- ,a.CitizenID::text , a.TaxID::text
  76. --,a.PhoneWork::text, a.PhoneWorkExt::text
  77. --,a.PhoneHome::text, a.PhoneHomeExt::text
  78. --,a.PhoneResident::text, a.PhoneResidentExt::text
  79. ,a1.tvalue ::text Mobile1 -- ,a.Mobile1::text --, a.Mobile2::text
  80. -- ,a.FaxWork::text ,a.FaxHome::text ,a.FaxResident::text
  81. ,a2.tvalue ::text EmailHome -- ,a.EmailHome::text --, a.URLHome::text
  82. -- ,a.AddrHome::text ,a.AddrWork::text ,a.AddrResident ::text
  83. -- ,a.AddrHomeID ,a.AddrWorkID ,a.AddrResidentID
  84. -- * Employee info
  85. --,a3.Tvalue::text EmpNo -- 33
  86. --,"dbContact".tbcontgrp_getgroups( a.id ) Groups
  87. --* Organization of the employee
  88. --,aa1.orgid
  89. -- ,aa1111.tvalue::text OrgNo --36
  90. -- ,concat_ws(' ',aa111.prefix,aa111.firstname,aa111.lastname,aa111.suffix ) OrgName
  91. --,aa1.StartJob
  92. --,aa1.FinishJob
  93. --,aa1.Remark RemarkOrg
  94. --* Position
  95. --,aa21.id PositionID
  96. -- ,aa21.title::text PositionName --42
  97. --,aa2.StartJob StartPos
  98. --,aa2.FinishJob FinishPos
  99. --,aa2.Remark RemarkPos
  100. --* Employment
  101. --,aa3.StartJob StartEmp
  102. --,aa3.FinishJob FinishEmp
  103. --,aa3.Remark RemarkEmp
  104. --* Wages unit
  105. --,aa.uomid
  106. -- ,a4.title::text --50
  107. -- ,aa.fqty, aa.sqty, aa.dis , aa.idgrp, aa.idprev, aa.seq, aa.path
  108. , ab.UID, ab.ACC
  109.  
  110. ,a5.id CompID -- 53
  111. ,a51.prefix ::text, a51.FirstName ::text, a51.Suffix ::text
  112. ,ab.username ::text
  113. -- ,repeat('*', length(a6.userpass)) ::text -- UserPass
  114. ,a6.userpassword ::text
  115. ,a6.salt
  116.  
  117. ,a6.SysRole
  118. ,ab.EmpID
  119. ,ab.deleted
  120. ,ab.userid
  121. ,ab.orgid
  122. ,ab1.firstname::text Grp
  123. ,ab.privilege
  124. ,ab.idgrp
  125. ,ab.dis
  126. ,ab.fqty
  127. ,ab.user_role
  128. ,ab.acname
  129. ,ab.org_contactid acname_contactid
  130. from
  131. "dbUserReg".tbUserReg ab
  132. right join "dbSys".grpGetData( _userid, accid, '"dbUserReg".tbuserreg' ) ab0 on (ab0.id = ab.id )
  133.  
  134. --left join "dbHR".tbEmp aa on (aa.id = ab.empid )
  135. -- left join "dbContact".tbContact_GetData(_UserID, AccID , _id:= ab.contactid ) a on (a.id = ab.ContactID )
  136. left join "dbContact".tbcontact a on ( a.id = ab.contactid )
  137. left join "dbContact".tbcontphone a1 on ( a1.pid = a.id and a1.title = 'Mobile' and a1.tcustom = '#1' )
  138. -- left join "dbContact".tbcontemail a2 on ( a2.pid = a.id and a2.title = 'Email' and a2.tcustom is null )
  139. left join "dbContact".tbcontemail a2 on ( a2.pid = a.id and a2.title = 'Email' and a2.tcustom ='1' )
  140. --left outer join "dbContact".tbContNumber a3 on ( a3.pid = a.id and a3.Title = 'Employee No' and a3.TCustom is null )
  141.  
  142. -- ** Active organization this employee reside
  143. /*
  144. left join "dbHR".tbEmporg aa1 on ( aa1.pid = aa.id and aa1.active and aa1.kind = 'Organization' )
  145. left join "dbHR".tborg aa11 on ( aa11.id = aa1.orgid )
  146. left join "dbContact".tbcontact aa111 on ( aa111.id = aa11.contactid )
  147. left outer join "dbContact".tbContNumber aa1111 on ( aa1111.pid = a.id and aa1111.Title = 'Default' and aa1111.TCustom = 'Dept No' )
  148. left join "dbHR".tbEmporg aa2 on ( aa2.pid = aa.id and aa2.active and aa2.kind = 'Position' )
  149. left join "dbHR".tbposition aa21 on ( aa21.id = aa2.positionID )
  150. left join "dbHR".tbEmporg aa3 on ( aa3.pid = aa.id and aa3.active and aa3.kind = 'Employment' )
  151. --** Unit of measurement-wages
  152. left join "dbBase".tbuom a4 on ( a4.id = aa.uomid ) */
  153.  
  154. --* Company
  155. left join "dbHR".tborg a5 on ( a5.acc= ab.acc and a5.company = true )
  156. left join "dbContact".tbcontact a51 on ( a51.id = a5.contactid )
  157. --* System role
  158. left join "dbUserAcc".tbuser a6 on ( a6.id = ab.userid )
  159.  
  160. left join "dbUserReg".tbuserreg ab1 on ( ab1.id = ab.idgrp )
  161.  
  162.  
  163. where ab.acc = AccID
  164. -- and ab.deleted =false
  165. and ab.acc is not null
  166. and a6.SysRole <>'Import'
  167. /*
  168. and case
  169. -- when _id is null then a.acc=accid -- a.UID in (select a1.UID from "dbUserAcc".tbaccuser a1 where a1.PID = AccID )
  170. when _id is null then a.acc= a.UID in (select a1.UID from "dbUserAcc".tbaccuser a1 where a1.PID = AccID )
  171. else true
  172. end */
  173.  
  174. and case
  175. when _id is null then a.UID in (select a1.UID from "dbUserAcc".tbaccuser a1 where a1.PID = AccID )
  176. else a.id = _id
  177. end
  178.  
  179. order by ab0.path
  180. ;
  181.  
  182. end $$ LANGUAGE plpgsql;
Add Comment
Please, Sign In to add comment