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.

610 lines
22 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_searchCustomerIRH] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_searchCustomerIRH]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_searchCustomerIRH] 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 PROC [dbo].[proc_searchCustomerIRH]
  12. --DECLARE
  13. @flag VARCHAR(20) = null
  14. ,@searchType VARCHAR(20) = null
  15. ,@searchValue VARCHAR(80) = null
  16. ,@country VARCHAR(50) = NULL
  17. ,@senderId VARCHAR(20) = NULL
  18. ,@recId VARCHAR(20) = NULL
  19. ,@agentType CHAR(1) = NULL --I-Internal, E-External
  20. ,@sCountryId VARCHAR(50) = NULL
  21. ,@settlementAgent VARCHAR(50) = NULL
  22. AS
  23. SET NOCOUNT ON;
  24. --SELECT @flag ='s', @searchType = 'customerId', @searchValue = '282083105155', @sCountryId = '119', @settlementAgent = '4880'
  25. DECLARE @customerId VARCHAR(20)
  26. DECLARE @SQL VARCHAR(MAX), @TranId varchar(50)
  27. DECLARE @idType VARCHAR(30)
  28. DECLARE @senderName VARCHAR(100)
  29. DECLARE @membershipId VARCHAR(50)
  30. DECLARE @txnList TABLE(id BIGINT NOT NULL,receiver VARCHAR(100), rIdNumber VARCHAR(50), rMobile VARCHAR(50))
  31. IF @FLAG IN ('SenderH', 's') --Direct Search By Passport/Mobile Number
  32. BEGIN
  33. DECLARE @customers TABLE(customerId BIGINT, idNumber VARCHAR(50))
  34. DECLARE @SenderIDimage VARCHAR(500), @fileName VARCHAR(200)
  35. IF ISNULL(@searchValue, '') = ''
  36. BEGIN
  37. EXEC proc_errorHandler 1, 'Please enter value to search', NULL
  38. RETURN
  39. END
  40. IF @searchType = 'email'
  41. BEGIN
  42. SET @SQL = '
  43. SELECT TOP 1 customerId, idNumber FROM customerMaster WITH(NOLOCK)
  44. WHERE ISNULL(isDeleted, ''N'') = ''N'' AND ISNULL(isBlacklisted, ''N'') = ''N''
  45. '
  46. IF @sCountryId IS NOT NULL
  47. SET @SQL = @SQL + ' AND country = ''' + @sCountryId + ''''
  48. IF @searchValue IS NOT NULL
  49. SET @SQL = @SQL + ' AND email='''+ @searchValue + ''''
  50. ELSE
  51. SET @SQL = @SQL + ' AND 1 = 2'
  52. PRINT @SQL
  53. INSERT INTO @customers
  54. EXEC(@SQL)
  55. IF NOT EXISTS(SELECT 'X' FROM @customers)
  56. BEGIN
  57. EXEC proc_errorHandler 1, 'Customer not found with the respected search', NULL
  58. RETURN
  59. END
  60. END
  61. SELECT TOP 1 @fileName = [fileName] FROM customerDocument WITH(NOLOCK)
  62. WHERE customerId = @customerId
  63. ORDER BY createdDate DESC
  64. IF @fileName is null
  65. SET @SenderIDimage = 'Customer Id Image: <img alt = "Customer Identity" title = "Click to Add Document" onclick = "ViewImage(' + ISNULL(@customerId,'0') +');" style="height:50px;width:50px;" src="../../../Images/na.gif" />'
  66. ELSE
  67. SET @SenderIDimage = 'Customer Id Image: <img alt = "Customer Identity" title = "Click to Add Document" onclick = "ViewImage(' + ISNULL(@customerId,'0') +');" style="height:50px;width:50px;" src="../../../doc/'+ @fileName + '" />'
  68. DECLARE @txnSum INT,@txnCount varchar(20), @date VARCHAR(20) = CONVERT(VARCHAR, GETDATE(),101)
  69. SET @txnSum = ISNULL(@txnSum, 0)
  70. SET @txnCount = ISNULL(@txnCount, 0)
  71. DECLARE @receiverName VARCHAR(200), @rCustomerId VARCHAR(20), @receiverCountry VARCHAR(100), @receiverAddress VARCHAR(200), @receiverCity VARCHAR(100),
  72. @receiverEmail VARCHAR(100), @receiverPhone VARCHAR(50), @receiverMobile VARCHAR(50), @receiverIDDescription VARCHAR(50), @receiverID VARCHAR(30),
  73. @paymentType VARCHAR(100), @rBankAcNo VARCHAR(50), @paidCType VARCHAR(3), @receiveCType VARCHAR(3), @pBank INT, @pBankBranch INT, @pBankBranchName VARCHAR(50)
  74. SELECT TOP 1
  75. @receiverName = ReceiverName
  76. ,@rCustomerId = CustomerId
  77. ,@receiverCountry = UPPER(ReceiverCountry)
  78. ,@receiverAddress = ReceiverAddress
  79. ,@receiverCity = receiverCity
  80. ,@receiverEmail = ''
  81. ,@receiverPhone = ReceiverPhone
  82. ,@receiverMobile = receiver_mobile
  83. ,@receiverIDDescription = ReceiverIDDescription
  84. ,@ReceiverID = ReceiverID
  85. ,@paymentType = CASE paymentType WHEN 'Cash Pay' THEN 'CASH PAYMENT'
  86. WHEN 'Bank Transfer' THEN 'BANK DEPOSIT'
  87. WHEN 'Account Deposit To Other Bank' THEN 'BANK DEPOSIT'
  88. ELSE UPPER(paymentType) END
  89. ,@pBank = pBank
  90. ,@pBankBranch = pBankBranch
  91. ,@pBankBranchName = pBankBranchName
  92. ,@rBankAcNo = rBankACNo
  93. ,@paidCType = paidCType
  94. ,@receiveCType = receiveCType
  95. FROM customerTxnHistory WITH(NOLOCK)
  96. WHERE senderPassport = @searchValue
  97. ORDER BY tranNo DESC
  98. DECLARE @rFirstName VARCHAR(100), @rMiddleName VARCHAR(100), @rLastName1 VARCHAR(100), @rLastName2 VARCHAR(100), @rFullName VARCHAR(100), @totalRows INT
  99. SELECT @rFirstName = firstName, @rMiddleName = middleName, @rLastName1 = lastName1, @rLastName2 = lastName2 FROM dbo.FNASplitName(@receiverName)
  100. SELECT TOP 1
  101. 0 errorCode
  102. ,customerId = CM.customerId
  103. ,sMemId = CM.membershipId
  104. ,sfirstName = CM.firstName
  105. ,smiddleName = ISNULL(CM.middleName, '')
  106. ,slastName1 = ISNULL(CM.lastName1, '')
  107. ,slastName2 = ISNULL(CM.lastName2, '')
  108. ,sState = ISNULL(CM.state, '')
  109. ,scountry = ISNULL(CM.nativecountry, '')
  110. ,saddress = ISNULL(CM.address, '')
  111. ,saddress2 = ISNULL(CM.address2, '')
  112. ,szipCode = ISNULL(CM.zipCode, '')
  113. ,sDistrict = CM.district
  114. ,sCity = CM.city
  115. ,semail = ISNULL( CM.email, '')
  116. ,sgender = CASE WHEN CM.gender = 97 THEN 'Male' WHEN CM.gender = 98 THEN 'Female' END
  117. ,shomePhone = ISNULL(CM.homePhone, '')
  118. ,sworkPhone = isnull(CM.workPhone, '')
  119. ,smobile = CM.mobile
  120. ,sdob = convert(varchar(20), CM.dob, 101)
  121. ,sCustomerType = custType.detailTitle
  122. ,sOccupation = CM.occupation
  123. ,idName = sdv.detailTitle
  124. ,sidNumber = ISNULL(CM.idNumber, '')
  125. ,svalidDate = ISNULL(CONVERT(VARCHAR,CM.idExpiryDate,101), '')
  126. ,senderName = CM.fullName
  127. ,companyName = CM.companyName
  128. ,receiverName = @receiverName
  129. ,rId = @rCustomerId
  130. ,rfirstName = @rFirstName
  131. ,rmiddleName = @rMiddleName
  132. ,rlastName1 = @rLastName1
  133. ,rlastName2 = @rLastName2
  134. ,rcountry = @receiverCountry
  135. ,raddress = @receiverAddress
  136. ,raddress2 = ''
  137. ,rState = ''
  138. ,rzipCode = ''
  139. ,rDistrict = ''
  140. ,rCity = @receiverCity
  141. ,remail = ISNULL(@receiverEmail, '')
  142. ,rgender = ''
  143. ,rhomePhone = ISNULL(@receiverPhone, '')
  144. ,rworkPhone = ISNULL(@receiverPhone, '')
  145. ,rmobile = ISNULL(@receiverMobile, '')
  146. ,rdob = ''
  147. ,ridtype = @receiverIDDescription
  148. ,ridNumber = @receiverID
  149. ,rvalidDate = ''
  150. ,purposeOfRemit = ''
  151. ,sourceOfFund = ''
  152. ,relWithSender = ''
  153. ,pCountry = @receiverCountry
  154. ,paymentMethod = @paymentType
  155. ,pAgent = ''
  156. ,pBank = ISNULL(@pBank, '')
  157. ,pBankBranch = ISNULL(@pBankBranch, '')
  158. ,pBankBranchName = ISNULL(@pBankBranchName, '')
  159. ,accountNo = ISNULL(@rBankAcNo, '')
  160. ,collCurr = @paidCType
  161. ,payoutCurr = @receiveCType
  162. ,salaryRange = cm.salaryRange
  163. ,txnSum = dbo.ShowDecimal(CAST(@txnSum AS VARCHAR(200)))
  164. ,txnSum2 = @txnSum
  165. ,txnPerDayCustomerLimit = isnull(dbo.FNAGetPerDayCustomerLimit(@settlementAgent),0)
  166. ,txnCount = @txnCount
  167. ,SenderIDimage = @SenderIDimage
  168. INTO #sTemp
  169. FROM dbo.customerMaster CM WITH(NOLOCK)
  170. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON sdv.valueId = CM.idType
  171. LEFT JOIN staticDataValue custType WITH (NOLOCK) ON CM.customerType = custType.valueId
  172. WHERE CM.customerId IN (SELECT customerId FROM @customers) AND country = @sCountryId
  173. IF NOT EXISTS(SELECT 'x' FROM #sTemp)
  174. BEGIN
  175. EXEC proc_errorHandler 1, 'Customer not found with the respected search', NULL
  176. RETURN
  177. END
  178. SELECT * FROM #sTemp
  179. --DROP TABLE #sTemp
  180. RETURN
  181. END
  182. ELSE IF @flag = 'ASN'
  183. BEGIN
  184. IF NOT EXISTS(SELECT * FROM dbo.customerMaster (NOLOCK) WHERE customerId = @recId)
  185. BEGIN
  186. EXEC proc_errorHandler 1, 'No result found', NULL
  187. RETURN
  188. END
  189. SELECT TOP 1
  190. 0 errorCode
  191. ,customerId = CM.idNumber
  192. ,sMemId = CM.membershipId
  193. ,sfirstName = CM.firstName
  194. ,smiddleName = ISNULL(CM.middleName, '')
  195. ,slastName1 = ISNULL(CM.lastName1, '')
  196. ,slastName2 = ISNULL(CM.lastName2, '')
  197. ,sState = ISNULL(CM.state, '')
  198. ,scountry = ISNULL(CM.nativecountry, '')
  199. ,saddress = ISNULL(CM.address, '')
  200. ,saddress2 = ISNULL(CM.address2, '')
  201. ,szipCode = ISNULL(CM.zipCode, '')
  202. ,sDistrict = CM.district
  203. ,sCity = CM.city
  204. ,semail = ISNULL( CM.email, '')
  205. ,sgender = CASE WHEN CM.gender = 97 THEN 'Male' WHEN CM.gender = 98 THEN 'Female' END
  206. ,shomePhone = ISNULL(CM.homePhone, '')
  207. ,sworkPhone = isnull(CM.workPhone, '')
  208. ,smobile = CM.mobile
  209. ,sdob = convert(varchar(20), CM.dob, 101)
  210. ,sCustomerType = custType.detailTitle
  211. ,sOccupation = CM.occupation
  212. ,idName = sdv.detailTitle
  213. ,sidNumber = ISNULL(CM.idNumber, '')
  214. ,svalidDate = ISNULL(CONVERT(VARCHAR,CM.idExpiryDate,101), '')
  215. ,senderName = CM.fullName
  216. ,companyName = CM.companyName
  217. ,receiverName = @receiverName
  218. ,rId = @rCustomerId
  219. ,rfirstName = @rFirstName
  220. ,rmiddleName = @rMiddleName
  221. ,rlastName1 = @rLastName1
  222. ,rlastName2 = @rLastName2
  223. ,rcountry = @receiverCountry
  224. ,raddress = @receiverAddress
  225. ,raddress2 = ''
  226. ,rState = ''
  227. ,rzipCode = ''
  228. ,rDistrict = ''
  229. ,rCity = @receiverCity
  230. ,remail = ISNULL(@receiverEmail, '')
  231. ,rgender = ''
  232. ,rhomePhone = ISNULL(@receiverPhone, '')
  233. ,rworkPhone = ISNULL(@receiverPhone, '')
  234. ,rmobile = ISNULL(@receiverMobile, '')
  235. ,rdob = ''
  236. ,ridtype = @receiverIDDescription
  237. ,ridNumber = @receiverID
  238. ,rvalidDate = ''
  239. ,purposeOfRemit = ''
  240. ,sourceOfFund = ''
  241. ,relWithSender = ''
  242. ,pCountry = @receiverCountry
  243. ,paymentMethod = @paymentType
  244. ,pAgent = ''
  245. ,pBank = ISNULL(@pBank, '')
  246. ,pBankBranch = ISNULL(@pBankBranch, '')
  247. ,pBankBranchName = ISNULL(@pBankBranchName, '')
  248. ,accountNo = ISNULL(@rBankAcNo, '')
  249. ,collCurr = @paidCType
  250. ,payoutCurr = @receiveCType
  251. ,salaryRange = cm.salaryRange
  252. ,txnSum = dbo.ShowDecimal(CAST(@txnSum AS VARCHAR(200)))
  253. ,txnSum2 = @txnSum
  254. ,txnPerDayCustomerLimit = isnull(dbo.FNAGetPerDayCustomerLimit(@settlementAgent),0)
  255. ,txnCount = @txnCount
  256. ,SenderIDimage = @SenderIDimage
  257. FROM dbo.customerMaster CM WITH(NOLOCK)
  258. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON sdv.valueId = CM.idType
  259. LEFT JOIN staticDataValue custType WITH (NOLOCK) ON CM.customerType = custType.valueId
  260. WHERE CM.customerId = @recId
  261. END
  262. ELSE IF @flag = 'srr' --Search Recent Receiver List
  263. BEGIN
  264. --*****Inficare System Search******
  265. SELECT @membershipId = isnull(membershipId,''), @senderName = fullName FROM customers WITH(NOLOCK) WHERE idNumber = @senderId
  266. SET @SQL = '
  267. SELECT TOP 5
  268. id = MAX(ms.tranNo)
  269. ,membershiId = ''' + @membershipId + '''
  270. ,senderName = ''' + @senderName + '''
  271. ,receiverName = ms.ReceiverName
  272. ,rIdNumber = ms.ReceiverID
  273. ,rMobile = ms.receiver_mobile
  274. ,payMode = ms.paymentType
  275. ,bank = CASE WHEN ms.paymentType = ''Bank Transfer'' THEN ms.rBankName
  276. WHEN ms.paymentType = ''Account Deposit to Other Bank'' THEN ms.ben_bank_name ELSE ms.rBankName END
  277. ,bankBranch = CASE WHEN ms.paymentType = ''Bank Transfer'' THEN ms.rBankBranch
  278. WHEN ms.paymentType = ''Account Deposit to Other Bank'' THEN ms.rBankAcType ELSE ms.rBankBranch END
  279. ,acNo = ms.rBankACNo
  280. FROM customerTxnHistory ms WITH(NOLOCK)
  281. WHERE ms.senderPassport = ''' + @senderId + '''
  282. '
  283. IF @searchValue IS NOT NULL
  284. SET @SQL = @SQL + ' AND ms.ReceiverName LIKE ''' + @searchValue + '%'''
  285. SET @SQL = @SQL + '
  286. GROUP BY ms.ReceiverName, ms.ReceiverID, ms.receiver_mobile, ms.paymentType, ms.rBankName, ms.rBankBranch, ms.rBankACNo, ms.ben_bank_name,
  287. ms.rBankAcType
  288. ORDER BY MAX(ms.tranNo) DESC'
  289. EXEC (@SQL)
  290. RETURN
  291. END
  292. ELSE IF @flag = 'sth' --Sender Txn History
  293. BEGIN
  294. --******Inficare System Search******
  295. SELECT @senderName = fullName FROM customers WITH(NOLOCK) WHERE idNumber = @senderId
  296. SET @SQL = '
  297. SELECT TOP 5
  298. id = ms.Tranno
  299. ,senderName = ''' + @senderName + '''
  300. ,receiverName = ms.ReceiverName
  301. ,tAmt = ms.paidAmt
  302. ,createdDate = CONVERT(VARCHAR , ms.confirmDate, 101)
  303. ,ICN = dbo.FNADecryptString(ms.refno)
  304. ,payMode = ms.paymentType
  305. ,bank = CASE WHEN ms.paymentType = ''Bank Transfer'' THEN ms.rBankName
  306. WHEN ms.paymentType = ''Account Deposit to Other Bank'' THEN ms.ben_bank_name ELSE ms.rBankName END
  307. ,bankBranch = CASE WHEN ms.paymentType = ''Bank Transfer'' THEN ms.rBankBranch
  308. WHEN ms.paymentType = ''Account Deposit to Other Bank'' THEN ms.rBankAcType ELSE ms.rBankBranch END
  309. ,acNo = ms.rBankACNo
  310. FROM customerTxnHistory ms WITH(NOLOCK)
  311. WHERE senderPassport = ''' + @senderId + '''
  312. '
  313. IF @recId IS NOT NULL
  314. SET @SQL = @SQL + ' AND ms.ReceiverName LIKE ''' + @recId + '%'''
  315. SET @SQL = @SQL + ' ORDER BY ms.Tranno DESC'
  316. EXEC (@SQL)
  317. RETURN
  318. END
  319. ELSE IF @flag = 'advS' --Advance Search(Load Customer Grid)
  320. BEGIN
  321. SET @searchValue = ISNULL(@searchValue, '')
  322. SET @SQL = '
  323. SELECT DISTINCT TOP 15
  324. errorCode = ''0''
  325. ,customerId = C.customerId
  326. ,membershipId = C.membershipId
  327. ,senderName = C.fullName
  328. ,countryName = CM.countryName
  329. ,address = C.address
  330. ,mobile = C.mobile
  331. ,nativeCountry = C.nativeCountry
  332. ,email = C.email
  333. ,idNumber = C.idNumber
  334. ,idType = SV.detailTitle
  335. ,validDate = CONVERT(VARCHAR, C.idExpiryDate, 101)
  336. ,cUstId = C.idNumber
  337. FROM customerMaster C WITH(NOLOCK)
  338. INNER JOIN countryMaster CM WITH (NOLOCK) ON C.country = CM.countryId
  339. LEFT JOIN staticDataValue SV WITH (NOLOCK) ON SV.valueId = C.idType
  340. WHERE ISNULL(C.isDeleted,''N'') = ''N'' AND ISNULL(isBlackListed, ''N'') = ''N''
  341. '
  342. IF @sCountryId IS NOT NULL
  343. SET @SQL = @SQL + ' AND c.country = ''' + @sCountryId + ''''
  344. IF @searchType = 'firstName'
  345. SET @SQL = @SQL + ' AND C.fullName LIKE ''' + @searchValue + '%'''
  346. ELSE IF @searchType = 'Address'
  347. SET @SQL = @SQL + ' AND C.Address LIKE ''' + @searchValue + '%'''
  348. ELSE IF @searchType = 'Passport'
  349. SET @SQL = @SQL + ' AND C.idType = 1302 AND C.idNumber = ''' + @searchValue + ''''
  350. ELSE IF @searchType IS NOT NULL AND @searchType <> 'IC'
  351. SET @SQL = @SQL + ' AND C.' + @searchType + ' = ''' + @searchValue + ''''
  352. ELSE
  353. SET @SQL = @SQL + ' AND 1 = 2'
  354. --PRINT @SQL
  355. EXEC(@SQL)
  356. END
  357. ELSE IF @searchType = 'ICN' --Search By ICN
  358. BEGIN
  359. EXEC proc_errorHandler 1, 'Search By ICN is not allowed for now', NULL
  360. RETURN
  361. SELECT top 1
  362. @SenderId=C.customerId,
  363. @TranId= trn.id ,
  364. @ReceiverID=cast(R.customerId as varchar(20))
  365. --,S.customerId
  366. FROM customers C
  367. LEFT JOIN tranSenders S WITH(NOLOCK) ON C.customerId = S.customerId
  368. LEFT JOIN remitTran trn WITH(NOLOCK) ON S.tranId = trn.id
  369. LEFT JOIN tranReceivers R WITH(NOLOCK) ON R.tranId = trn.id
  370. WHERE trn.controlNo = dbo.FNADecryptString(@searchValue) and R.tranId is not null
  371. ORDER BY trn.id DESC
  372. --select @searchValue
  373. IF NOT EXISTS(SELECT 'A' FROM customers WHERE customerId=@SenderId)
  374. BEGIN
  375. EXEC proc_errorHandler 1, 'This Member is not found.', NULL
  376. RETURN;
  377. END
  378. IF EXISTS(SELECT 'A' FROM customers WHERE customerId=@SenderId AND ISNULL(isBlackListed,'N')='Y')
  379. BEGIN
  380. EXEC proc_errorHandler 1, 'This customer is blacklisted. Cannot proceed for transaction.', NULL
  381. RETURN;
  382. END
  383. SELECT 0 errorCode,* FROM (
  384. SELECT
  385. membershipId [sMemId], firstName sfirstName, isnull(middleName,'') smiddleName,
  386. isnull(lastName1,'') slastName1, isnull(lastName2,'')slastName2
  387. ,country scountry, isnull([address],'')saddress, isnull([State],'') sState,
  388. isnull(zipCode,'') szipCode, district [sDistrict], city [sCity], email semail
  389. ,homePhone shomePhone, isnull(workPhone,'') sWorkPhone , mobile smobile, convert(varchar(20), dob, 101) sdob,
  390. Typ.detailTitle sCustomerType, Ocu.detailTitle sOccupation
  391. ,relativeName sRelativeName, Rel.detailTitle sRelation, Cont.countryName scountryName, ID.idType sidType,
  392. ID.idNumber sidNumber, ID.validDate svalidDate
  393. FROM customers C WITH (NOLOCK)
  394. LEFT JOIN customerIdentity ID WITH (NOLOCK) ON C.customerId = ID.idType
  395. JOIN staticDataValue Rel WITH (NOLOCK) ON C.relationId = Rel.valueId
  396. JOIN staticDataValue Ocu WITH (NOLOCK) ON C.occupation = Ocu.valueId
  397. JOIN staticDataValue Typ WITH (NOLOCK) ON C.customerType = Typ.valueId
  398. JOIN countryMaster Cont WITH (NOLOCK) ON C.country = Cont.countryId
  399. WHERE C.customerId=@SenderId
  400. ) AS sender
  401. LEFT JOIN (
  402. SELECT
  403. membershipId [rMemId], firstName rfirstName, isnull(middleName,'') rmiddleName,
  404. isnull(lastName1,'') rlastName1, isnull(lastName2,'')rlastName2
  405. ,country [rcountry], isnull([address],'')raddress, isnull([State],'') rState,
  406. isnull(zipCode,'') rzipCode, district [rDistrict], city [rCity], email remail
  407. ,homePhone rhomePhone, isnull(workPhone,'') sWorkPhone , mobile rmobile, convert(varchar(20), dob, 101) rdob,
  408. Typ.detailTitle rCustomerType, Ocu.detailTitle rOccupation ,relativeName rRelativeName, Rel.detailTitle rRelation,
  409. Cont.countryName rcountryName, ID.idType ridType,
  410. ID.idNumber ridNumber, ID.validDate rvalidDate
  411. FROM customers C WITH (NOLOCK)
  412. LEFT JOIN customerIdentity ID WITH (NOLOCK) ON C.customerId = ID.idType
  413. JOIN staticDataValue Rel WITH (NOLOCK) ON C.relationId = Rel.valueId
  414. JOIN staticDataValue Ocu WITH (NOLOCK) ON C.occupation = Ocu.valueId
  415. JOIN staticDataValue Typ WITH (NOLOCK) ON C.customerType = Typ.valueId
  416. JOIN countryMaster Cont WITH (NOLOCK) ON C.country = Cont.countryId
  417. WHERE C.customerId=@ReceiverID
  418. ) as REC ON sender.sMemId=REC.rMemId
  419. END
  420. ELSE IF @flag = 'R' --Load Receiver after picked
  421. BEGIN
  422. DECLARE @TRANLIST TABLE(tranId BIGINT,customerId INT)
  423. --*****Inficare Search Receiver******
  424. --INSERT INTO @TRANLIST(tranId)
  425. --SELECT MAX(ms.Tranno) FROM irh_ime_plus_01.dbo.moneySend ms WITH(NOLOCK)
  426. --WHERE senderPassport = @senderId
  427. --GROUP BY ms.Tranno
  428. SELECT @rFullName = receiverName FROM customerTxnHistory WITH(NOLOCK) WHERE Tranno = @recId
  429. SELECT @rFirstName = firstName, @rMiddleName = middleName, @rLastName1 = lastName1, @rLastName2 = lastName2 FROM dbo.FNASplitName(@rFullName)
  430. SELECT DISTINCT
  431. ID = ms.Tranno
  432. ,[sid] = ms.senderPassport
  433. ,[senderName] = ms.SenderName
  434. ,sidType = ms.senderFax
  435. ,sidNumber = ms.senderPassport
  436. ,smobile = ms.sender_mobile
  437. ,saddress = ms.SenderAddress
  438. ,tranNo = dbo.FNADecryptString(ms.refno)
  439. ,[receiverName] = ms.receiverName
  440. ,firstName = @rFirstName
  441. ,middleName = @rMiddleName
  442. ,lastName1 = @rLastName1
  443. ,lastName2 = @rLastName2
  444. ,pBranchName = ms.rBankBranch
  445. ,paymentMethod = CASE ms.paymentType WHEN 'Cash Pay' THEN 'CASH PAYMENT' WHEN 'Bank Transfer' THEN 'BANK DEPOSIT'
  446. WHEN 'Account Deposit to Other Bank' THEN 'BANK DEPOSIT' ELSE UPPER(ms.paymentType) END
  447. ,tAmt = ms.paidAmt
  448. ,createdDate = CONVERT(VARCHAR,ms.confirmDate,101)
  449. ,sCountry = ms.SenderCountry
  450. ,idType = ms.receiverIDDescription
  451. ,idNumber = ms.receiverID
  452. ,validDate = ''
  453. ,dob = ''
  454. ,homePhone = ReceiverPhone
  455. ,mobile = receiver_mobile
  456. ,[address] = ReceiverAddress
  457. ,[state] = ReceiverCity
  458. ,zipCode = ''
  459. ,country = ReceiverCountry
  460. ,email = ''
  461. ,accountNo = ISNULL(ms.rBankACNo, '')
  462. ,pBank = ISNULL(pBank, 0)
  463. ,pBankBranch = ISNULL(pBankBranch, 0)
  464. ,pBankBranchName = ISNULL(pBankBranchName, '')
  465. FROM customerTxnHistory ms WITH(NOLOCK)
  466. WHERE
  467. --ms.SenderName LIKE ISNULL(@searchValue + '%', '%') AND
  468. ms.Tranno = @recId
  469. END
  470. ELSE IF @flag = 'branchByAgent'
  471. BEGIN
  472. IF @agentType = 'I'
  473. BEGIN
  474. SET @SQL = '
  475. SELECT TOP 20
  476. agentId
  477. ,agentName
  478. ,agentAddress
  479. ,agentCity = ISNULL(agentCity,'''')
  480. ,agentPhone1 = ISNULL(agentPhone1 ,'''')
  481. ,agentState = ISNULL(agentState, '''')
  482. ,extCode = ISNULL(extCode, '''')
  483. FROM agentMaster WITH(NOLOCK)
  484. WHERE ISNULL(isDeleted, ''N'') = ''N''
  485. AND agentType = ''2904''
  486. AND parentId = ''' + @senderId + '''
  487. '
  488. IF @searchValue IS NOT NULL
  489. SET @SQL = @SQL + ' AND ' + @searchType + ' LIKE ''%' + @searchValue + '%'''
  490. SET @SQL = @SQL + ' ORDER BY agentName ASC'
  491. END
  492. ELSE IF @agentType = 'E'
  493. BEGIN
  494. IF @searchType = 'agentName'
  495. SET @searchType = 'branchName'
  496. ELSE IF @searchType = 'agentAddress'
  497. SET @searchType = 'address'
  498. ELSE IF @searchType = 'agentCity'
  499. SET @searchType = 'city'
  500. ELSE IF @searchType = 'agentPhone1'
  501. SET @searchType = 'phone'
  502. ELSE IF @searchType = 'agentState'
  503. SET @searchType = 'State'
  504. ELSE IF @searchType = 'extCode'
  505. SET @searchType = 'externalCode'
  506. SET @SQL = '
  507. SELECT TOP 10
  508. agentId = extBranchId
  509. ,agentName = branchName
  510. ,agentAddress = address
  511. ,agentCity = ISNULL(city, '''')
  512. ,agentPhone1 = ISNULL(phone, '''')
  513. ,agentState = ISNULL(State, '''')
  514. ,extCode = ISNULL(externalCode, '''')
  515. FROM externalBankBranch WITH(NOLOCK)
  516. WHERE ISNULL(isDeleted, ''N'') = ''N''
  517. AND extBankId = ''' + @senderId + '''
  518. AND ISNULL(isBlocked,''N'') = ''N''
  519. '
  520. IF @searchValue IS NOT NULL
  521. SET @SQL = @SQL + ' AND ' + @searchType + ' LIKE ''' + @searchValue + '%'''
  522. SET @SQL = @SQL + ' ORDER BY agentName ASC'
  523. END
  524. EXEC(@SQL)
  525. PRINT(@SQL)
  526. RETURN
  527. END
  528. ELSE IF @flag = 'locationByAgent'
  529. BEGIN
  530. SELECT TOP 50
  531. L.LocationId,
  532. L.Address,
  533. L.City,
  534. A.agentName
  535. FROM agentDoorToDoorLocation L WITH (NOLOCK)
  536. INNER JOIN agentMaster A WITH (NOLOCK) ON L.agentId=A.agentId
  537. WHERE L.agentId = @senderId
  538. AND L.Address LIKE ISNULL(@searchValue+'%','%')
  539. ORDER BY L.Address
  540. END
  541. GO