You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
8.1 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_online_receiverSetup] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_online_receiverSetup]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_online_receiverSetup] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. CREATE PROCEDURE [dbo].[proc_online_receiverSetup](
  12. @flag VARCHAR (50) =NULL
  13. ,@user VARCHAR (30) =NULL
  14. ,@receiverId VARCHAR (50) =NULL
  15. ,@customerId VARCHAR (50) =NULL
  16. ,@membershipId VARCHAR(50) =NULL
  17. ,@firstName VARCHAR(100) =NULL
  18. ,@middleName VARCHAR(100) =NULL
  19. ,@lastName1 VARCHAR(100) =NULL
  20. ,@lastName2 VARCHAR(100) =NULL
  21. ,@country VARCHAR(200) =NULL
  22. ,@address VARCHAR(500) =NULL
  23. ,@state VARCHAR(200) =NULL
  24. ,@zipCode VARCHAR(50) =NULL
  25. ,@city VARCHAR(100) =NULL
  26. ,@email VARCHAR(150) =NULL
  27. ,@homePhone VARCHAR(100) =NULL
  28. ,@workPhone VARCHAR(100) =NULL
  29. ,@mobile VARCHAR(100) =NULL
  30. ,@relationship VARCHAR(100) =NULL
  31. ,@sortBy VARCHAR(50) = NULL
  32. ,@sortOrder VARCHAR(5) = NULL
  33. ,@pageSize INT = NULL
  34. ,@pageNumber INT = NULL
  35. )
  36. AS
  37. BEGIN
  38. DECLARE
  39. @table VARCHAR(MAX)
  40. ,@select_field_list VARCHAR(MAX)
  41. ,@extra_field_list VARCHAR(MAX)
  42. ,@sql_filter VARCHAR(MAX)
  43. --,@customerId1 VARCHAR(50)
  44. IF @flag='i'
  45. BEGIN
  46. IF EXISTS(SELECT 'X' FROM receiverInformation WITH(NOLOCK) WHERE mobile=@mobile and customerId=@customerId)
  47. BEGIN
  48. SELECT '1' errorCode,'The receiver with this Mobile Number already exists.' msg,null id
  49. RETURN
  50. END
  51. insert into receiverInformation
  52. (
  53. membershipId
  54. ,customerId
  55. ,firstName
  56. ,middleName
  57. ,lastName1
  58. ,lastName2
  59. ,country
  60. ,address
  61. ,state
  62. ,zipCode
  63. ,city
  64. ,email
  65. ,homePhone
  66. ,workPhone
  67. ,mobile
  68. ,relationship
  69. ,isActive
  70. )select
  71. @membershipId
  72. ,@customerId
  73. ,@firstName
  74. ,@middleName
  75. ,@lastName1
  76. ,@lastName2
  77. ,@country
  78. ,@address
  79. ,@state
  80. ,@zipCode
  81. ,@city
  82. ,@email
  83. ,@homePhone
  84. ,@workPhone
  85. ,@mobile
  86. ,@relationship
  87. ,1
  88. Select '0' errorCode,'Receiver Successfully added.' msg,id=@receiverId
  89. return
  90. END
  91. IF @flag='u'
  92. BEGIN
  93. --IF EXISTS(SELECT 'X' FROM receiverInformation WITH(NOLOCK) WHERE mobile=@mobile and receiverId =@receiverId)
  94. --BEGIN
  95. -- SELECT '1' errorCode,'The receiver with this Mobile Number already exists.' msg,null id
  96. -- RETURN
  97. --END
  98. UPDATE receiverInformation SET
  99. firstName =@firstName
  100. ,middleName =@middleName
  101. ,lastName1 =@lastName1
  102. ,lastName2 =@lastName2
  103. ,country =@country
  104. ,address =@address
  105. ,state =@state
  106. ,zipCode =@zipCode
  107. ,city =@city
  108. ,email =@email
  109. ,homePhone =@homePhone
  110. ,workPhone =@workPhone
  111. ,mobile =@mobile
  112. ,relationship =@relationship
  113. WHERE receiverId =@receiverId
  114. select '0' errorCode,'Receiver Information has been updated' msg,id=null
  115. END
  116. IF @flag='d'
  117. BEGIN
  118. UPDATE receiverInformation SET isActive='0' WHERE receiverId=@receiverId
  119. select '0' errorCode,'Receiver Deleted Successfully.' msg,id=@receiverId
  120. END
  121. IF @flag='s'
  122. BEGIN
  123. IF @sortBy IS NULL
  124. SET @sortBy = 'firstName'
  125. IF @sortOrder IS NULL
  126. SET @sortOrder = 'ASC'
  127. SET @table='
  128. (
  129. SELECT
  130. ri.receiverId
  131. ,ri.firstName , ISNULL('' '' + ri.middleName,'''') middleName, ISNULL('' '' + ri.lastName1,'''') lastName1, ISNULL('' '' + ri.lastName2,'''') lastName2
  132. ,ri.firstName + ISNULL('' '' + ri.middleName,'''') + ISNULL('' '' + ri.lastName1,'''') + ISNULL('' '' + ri.lastName2,'''') FullName
  133. ,ri.customerId
  134. ,country
  135. ,ri.address
  136. ,ri.state
  137. ,ri.zipCode
  138. ,ri.city
  139. ,ri.email
  140. ,ri.homePhone
  141. ,ri.workPhone
  142. ,(Select coalesce(ri.mobile,ri.homePhone)) as Mobile
  143. ,relationship
  144. FROM receiverInformation ri WITH (NOLOCK)
  145. WHERE ISNULL(rec.isActive,1) = 1 AND customerId = ''' + @customerId + ''''
  146. SET @sql_filter = ''
  147. IF @country IS NOT NULL
  148. SET @table = @table + ' and country='''+@country+''''
  149. IF @address IS NOT NULL
  150. SET @table = @table + ' AND address like '''+@address+'%'' or city like '''+@city+ '%'''-- or id Like '''+@agentAddress+ '%'''
  151. SET @table = @table + ' )x'
  152. PRINT @table
  153. SET @select_field_list ='
  154. receiverId
  155. ,customerId
  156. ,FullName=firstName + middleName + lastName1 + lastName2
  157. ,firstName
  158. ,middleName
  159. ,lastName1
  160. ,lastName2
  161. ,country
  162. ,address
  163. ,state
  164. ,zipCode
  165. ,city
  166. ,email
  167. ,homePhone
  168. ,workPhone
  169. ,Mobile
  170. ,relationship
  171. '
  172. EXEC dbo.proc_paging
  173. @table
  174. ,@sql_filter
  175. ,@select_field_list
  176. ,@extra_field_list
  177. ,@sortBy
  178. ,@sortOrder
  179. ,@pageSize
  180. ,@pageNumber
  181. END
  182. IF @flag='a'
  183. BEGIN
  184. SELECT [receiverId]
  185. ,[customerId]
  186. ,[membershipId]
  187. ,[firstName]
  188. ,[middleName]
  189. ,[lastName1]
  190. ,[lastName2]
  191. ,[country]
  192. ,[address]
  193. ,[state]
  194. ,[zipCode]
  195. ,[city]
  196. ,[email]
  197. ,[homePhone]
  198. ,[workPhone]
  199. ,[mobile]
  200. ,[relationship]
  201. from receiverInformation WITH (NOLOCK)
  202. where receiverId=@receiverId AND isnull(isActive,1) = 1
  203. END
  204. IF @flag='sDetail'
  205. BEGIN
  206. --select * from receiverInformation
  207. SELECT
  208. ri.receiverId
  209. ,ri.customerId
  210. ,ri.firstName
  211. ,ri.middleName
  212. ,ri.lastName1
  213. ,ri.lastName2
  214. ,ri.country
  215. ,ri.address
  216. ,ri.state
  217. ,ri.zipCode
  218. ,cm.countryId
  219. ,ri.city
  220. ,ri.email
  221. ,ri.homePhone
  222. ,ri.workPhone
  223. ,ri.mobile
  224. ,ri.relationship
  225. FROM receiverInformation ri WITH (NOLOCK)
  226. inner join countryMaster cm WITH (NOLOCK) on ri.country=cm.countryName
  227. WHERE customerId =@customerId and receiverId=@receiverId
  228. AND isnull(ri.isActive,1) = 1
  229. END
  230. IF @flag='getTtranDetail'
  231. BEGIN
  232. --select * from receiverInformation
  233. SELECT
  234. ri.receiverId
  235. ,ri.customerId
  236. ,receiverName=ISNULL(ri.firstName,'') + ' '
  237. + ISNULL(ri.middleName,'')+ ' ' + ISNULL(ri.lastName1,'') + ' ' + ISNULL(ri.lastName2,'')
  238. --,ri.middleName
  239. --,ri.lastName1
  240. --,ri.lastName2
  241. ,countryId=ri.country
  242. ,ri.address
  243. ,ri.state
  244. ,ri.zipCode
  245. ,ri.city
  246. ,ri.email
  247. ,phone=ri.homePhone
  248. ,ri.workPhone
  249. ,ri.mobile
  250. ,ri.relationship
  251. FROM receiverInformation ri WITH (NOLOCK)
  252. INNER JOIN countryMaster cm WITH(NOLOCK) ON ri.country= cm.countryName
  253. WHERE customerId = @customerId and receiverId=@receiverId
  254. AND isnull(ri.isActive,1) = 1
  255. END
  256. IF @flag='recProfile'
  257. BEGIN
  258. select distinct ISNULL(TS.tranid,'') from receiverInformation ri with(nolock)
  259. LEFT JOIN
  260. (SELECT tranid=rt.id,TS.customerId FROM tranSenders tS
  261. INNER JOIN remitTran rt with(nolock) ON tS.tranId = rt.id AND tS.customerId =@customerId ) TS ON ri.customerId=tS.customerId
  262. INNER JOIN tranReceivers tR with(nolock) ON tR.fullName=ISNULL(ri.firstName,'') + ''
  263. + ISNULL(ri.middleName,'')+ '' + ISNULL(ri.lastName1,'') + '' + ISNULL(ri.lastName2,'') AND tR.mobile=ri.mobile
  264. WHERE ri.receiverId = @receiverId AND ri.customerId =@customerId
  265. --SELECT tranId=tR.tranId,* FROM receiverInformation ri
  266. -- LEFT JOIN tranReceivers tR ON ri.customerId=tR.customerId
  267. -- AND tR.fullName=ISNULL(ri.firstName,'') + '' + ISNULL(ri.middleName,'')+ ''
  268. -- + ISNULL(ri.lastName1,'') + '' + ISNULL(ri.lastName2,'') AND tR.mobile=ri.mobile
  269. -- WHERE ri.receiverId = @receiverId AND ri.customerId =@customerId
  270. END
  271. END
  272. --INNER JOIN (
  273. -- SELECT
  274. -- receiverId = MAX(receiverId)
  275. -- ,fullName= ri.firstName + ISNULL('' '' + ri.middleName,'''') + ISNULL('' '' + ri.lastName1,'''') + ISNULL('' '' + ri.lastName2,'''')
  276. -- FROM receiverInformation ri WITH (NOLOCK)
  277. -- GROUP BY ri.firstName + ISNULL('' '' + ri.middleName,'''') + ISNULL('' '' + ri.lastName1,'''') + ISNULL('' '' + ri.lastName2,'''')
  278. --) x ON ri.receiverId = x.receiverId
  279. GO