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.

1134 lines
66 KiB

10 months ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_searchCustomerIRH] Script Date: 11/22/2023 11:47:32 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_searchCustomerIRH]
  9. --DECLARE
  10. @user VARCHAR(20) = NULL
  11. ,@flag VARCHAR(20) = NULL
  12. ,@searchType VARCHAR(20) = NULL
  13. ,@searchValue VARCHAR(80) = NULL
  14. ,@country VARCHAR(50) = NULL
  15. ,@senderId VARCHAR(20) = NULL
  16. ,@recId VARCHAR(20) = NULL
  17. ,@agentType CHAR(1) = NULL --I-Internal, E-External
  18. ,@sCountryId VARCHAR(50) = NULL
  19. ,@settlementAgent VARCHAR(50) = NULL
  20. ,@customerId VARCHAR(10) = NULL
  21. ,@relation VARCHAR(100) = NULL
  22. ,@relationOther VARCHAR(100) = NULL
  23. ,@purpose VARCHAR(100) = NULL
  24. ,@purposeOther VARCHAR(100) = NULL
  25. ,@visaStatus VARCHAR(100) = NULL
  26. ,@occupation VARCHAR(100) = NULL
  27. ,@occupationOther VARCHAR(100) = NULL
  28. ,@RID BIGINT = NULL
  29. ,@goodsType VARCHAR(100) = NULL
  30. ,@goodsOrigin VARCHAR(100) = NULL
  31. ,@portOfShipment VARCHAR(100) = NULL
  32. AS
  33. SET NOCOUNT ON;
  34. ----------------------------------------
  35. --JME-561 July 21 -> Show Customer Document in Send Money
  36. --JME-544 July 22 -> document view issue for receiver. Set application/pdf
  37. --SEP 21 -->#134 -> Allow edit option of address in Town Area
  38. --#621 ->Disabled customer allowed to do txn
  39. -----------------------------------------
  40. --SELECT @flag ='s', @searchType = 'customerId', @searchValue = '282083105155', @sCountryId = '119', @settlementAgent = '4880'
  41. DECLARE @SQL VARCHAR(MAX)
  42. ,@TranId VARCHAR(50)
  43. DECLARE @idType VARCHAR(30)
  44. DECLARE @senderName VARCHAR(100)
  45. DECLARE @membershipId VARCHAR(50)
  46. DECLARE @txnList TABLE (
  47. id BIGINT NOT NULL
  48. ,receiver VARCHAR(100)
  49. ,rIdNumber VARCHAR(50)
  50. ,rMobile VARCHAR(50)
  51. )
  52. IF @flag = 'SAVE'
  53. BEGIN
  54. IF EXISTS (
  55. SELECT 'X'
  56. FROM customerMaster(NOLOCK)
  57. WHERE customerId = @customerId
  58. AND ISNULL(isCDDIUpdated, 0) = 0
  59. )
  60. BEGIN
  61. UPDATE customerMaster
  62. SET OCCUPATION = @occupation
  63. ,occupationOther = @occupationOther
  64. ,visaStatus = @visaStatus
  65. ,isCDDIUpdated = 1
  66. WHERE CUSTOMERID = @customerId
  67. END
  68. IF EXISTS (
  69. SELECT 'X'
  70. FROM receiverinformation(NOLOCK)
  71. WHERE RECEIVERID = @RID
  72. AND ISNULL(isCDDIUpdated, 0) = 0
  73. )
  74. BEGIN
  75. UPDATE receiverinformation
  76. SET relationOther = @relationOther
  77. ,purposeOther = @purposeOther
  78. ,relationship = @relation
  79. ,purposeOfRemit = @purpose
  80. ,isCDDIUpdated = 1
  81. ,goodsType = @goodsType
  82. ,goodsOrigin = @goodsOrigin
  83. ,portOfShipment = @portOfShipment
  84. WHERE RECEIVERID = @RID
  85. END
  86. EXEC proc_errorHandler 0
  87. ,'Updated successfully!'
  88. ,NULL
  89. END
  90. IF @FLAG IN (
  91. 'SenderH'
  92. ,'s'
  93. ) --Direct Search By Passport/Mobile Number
  94. BEGIN
  95. DECLARE @customers TABLE (
  96. customerId BIGINT
  97. ,idNumber VARCHAR(50)
  98. )
  99. DECLARE @SenderIDimage VARCHAR(500)
  100. ,@fileName VARCHAR(200)
  101. IF ISNULL(@searchValue, '') = ''
  102. BEGIN
  103. EXEC proc_errorHandler 1
  104. ,'Please enter value to search'
  105. ,NULL
  106. RETURN
  107. END
  108. IF @searchType = 'email'
  109. BEGIN
  110. SET @SQL = '
  111. SELECT TOP 1 customerId, idNumber FROM customerMaster WITH(NOLOCK)
  112. WHERE ISNULL(isDeleted, ''N'') = ''N'' AND ISNULL(isBlacklisted, ''N'') = ''N''
  113. '
  114. IF @sCountryId IS NOT NULL
  115. SET @SQL = @SQL + ' AND country = ''' + @sCountryId + ''''
  116. IF @searchValue IS NOT NULL
  117. SET @SQL = @SQL + ' AND email=''' + @searchValue + ''''
  118. ELSE
  119. SET @SQL = @SQL + ' AND 1 = 2'
  120. PRINT @SQL
  121. INSERT INTO @customers
  122. EXEC (@SQL)
  123. IF NOT EXISTS (
  124. SELECT 'X'
  125. FROM @customers
  126. )
  127. BEGIN
  128. EXEC proc_errorHandler 1
  129. ,'Customer not found with the respected search'
  130. ,NULL
  131. RETURN
  132. END
  133. END
  134. SELECT TOP 1 @fileName = [fileName]
  135. FROM customerDocument WITH (NOLOCK)
  136. WHERE customerId = @customerId
  137. ORDER BY createdDate DESC
  138. IF @fileName IS NULL
  139. 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" />'
  140. ELSE
  141. 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 + '" />'
  142. DECLARE @txnSum INT
  143. ,@txnCount VARCHAR(20)
  144. ,@date VARCHAR(20) = CONVERT(VARCHAR, GETDATE(), 111)
  145. SET @txnSum = ISNULL(@txnSum, 0)
  146. SET @txnCount = ISNULL(@txnCount, 0)
  147. DECLARE @receiverName VARCHAR(200)
  148. ,@rCustomerId VARCHAR(20)
  149. ,@receiverCountry VARCHAR(100)
  150. ,@receiverAddress VARCHAR(200)
  151. ,@receiverCity VARCHAR(100)
  152. ,@receiverEmail VARCHAR(100)
  153. ,@receiverPhone VARCHAR(50)
  154. ,@receiverMobile VARCHAR(50)
  155. ,@receiverIDDescription VARCHAR(50)
  156. ,@receiverID VARCHAR(30)
  157. ,@paymentType VARCHAR(100)
  158. ,@rBankAcNo VARCHAR(50)
  159. ,@paidCType VARCHAR(3)
  160. ,@receiveCType VARCHAR(3)
  161. ,@pBank INT
  162. ,@pBankBranch INT
  163. ,@pBankBranchName VARCHAR(50)
  164. ,@receiverCountryId INT
  165. SELECT TOP 1 @receiverName = ReceiverName
  166. ,@rCustomerId = CustomerId
  167. ,@receiverCountry = UPPER(ReceiverCountry)
  168. ,@receiverAddress = ReceiverAddress
  169. ,@receiverCity = receiverCity
  170. ,@receiverEmail = ''
  171. ,@receiverPhone = ReceiverPhone
  172. ,@receiverMobile = receiver_mobile
  173. ,@receiverIDDescription = ReceiverIDDescription
  174. ,@ReceiverID = ReceiverID
  175. ,@paymentType = CASE paymentType
  176. WHEN 'Cash Pay'
  177. THEN 'CASH PAYMENT'
  178. WHEN 'Bank Transfer'
  179. THEN 'BANK DEPOSIT'
  180. WHEN 'Account Deposit To Other Bank'
  181. THEN 'BANK DEPOSIT'
  182. ELSE UPPER(paymentType)
  183. END
  184. ,@pBank = pBank
  185. ,@pBankBranch = pBankBranch
  186. ,@pBankBranchName = pBankBranchName
  187. ,@rBankAcNo = rBankACNo
  188. ,@paidCType = paidCType
  189. ,@receiveCType = receiveCType
  190. FROM customerTxnHistory WITH (NOLOCK)
  191. WHERE senderPassport = @searchValue
  192. ORDER BY tranNo DESC
  193. DECLARE @rFirstName VARCHAR(100)
  194. ,@rMiddleName VARCHAR(100)
  195. ,@rLastName1 VARCHAR(100)
  196. ,@rLastName2 VARCHAR(100)
  197. ,@rFullName VARCHAR(100)
  198. ,@totalRows INT
  199. SELECT @rFirstName = firstName
  200. ,@rMiddleName = middleName
  201. ,@rLastName1 = lastName1
  202. ,@rLastName2 = lastName2
  203. FROM dbo.FNASplitName(@receiverName)
  204. SELECT TOP 1 0 errorCode
  205. ,customerId = CM.customerId
  206. ,sMemId = CM.membershipId
  207. ,sfirstName = CM.firstName
  208. ,smiddleName = ISNULL(CM.middleName, '')
  209. ,slastName1 = ISNULL(CM.lastName1, '')
  210. ,slastName2 = ISNULL(CM.lastName2, '')
  211. ,sState = ISNULL(CM.STATE, '')
  212. ,scountry = ISNULL(CM.nativecountry, '')
  213. ,saddress = ISNULL(CM.address, '')
  214. ,saddress2 = ISNULL(CM.address2, '')
  215. ,szipCode = ISNULL(CM.zipCode, '')
  216. ,sDistrict = CM.district
  217. ,sCity = CM.city
  218. ,semail = ISNULL(CM.email, '')
  219. ,sgender = CASE
  220. WHEN CM.gender = 97
  221. THEN 'Male'
  222. WHEN CM.gender = 98
  223. THEN 'Female'
  224. END
  225. ,shomePhone = ISNULL(CM.homePhone, '')
  226. ,sworkPhone = isnull(CM.workPhone, '')
  227. ,smobile = CM.mobile
  228. ,sdob = convert(VARCHAR(20), CM.dob, 111)
  229. ,sCustomerType = custType.detailTitle
  230. ,sOccupation = CM.occupation
  231. ,idName = sdv.detailTitle
  232. ,sidNumber = ISNULL(CM.idNumber, '')
  233. ,svalidDate = ISNULL(CONVERT(VARCHAR, CM.idExpiryDate, 111), '')
  234. ,senderName = CM.fullName
  235. ,companyName = CM.companyName
  236. ,receiverName = @receiverName
  237. ,rId = @rCustomerId
  238. ,rfirstName = @rFirstName
  239. ,rmiddleName = @rMiddleName
  240. ,rlastName1 = @rLastName1
  241. ,rlastName2 = @rLastName2
  242. ,rcountry = @receiverCountry
  243. ,raddress = @receiverAddress
  244. ,raddress2 = ''
  245. ,rState = ''
  246. ,rzipCode = ''
  247. ,rDistrict = ''
  248. ,rCity = @receiverCity
  249. ,remail = ISNULL(@receiverEmail, '')
  250. ,rgender = ''
  251. ,rhomePhone = ISNULL(@receiverPhone, '')
  252. ,rworkPhone = ISNULL(@receiverPhone, '')
  253. ,rmobile = ISNULL(@receiverMobile, '')
  254. ,rdob = ''
  255. ,ridtype = @receiverIDDescription
  256. ,ridNumber = @receiverID
  257. ,rvalidDate = ''
  258. ,purposeOfRemit = ''
  259. ,sourceOfFund = ''
  260. ,relWithSender = ''
  261. ,pCountry = @receiverCountry
  262. ,paymentMethod = @paymentType
  263. ,pAgent = ''
  264. ,pBank = ISNULL(@pBank, '')
  265. ,pBankBranch = ISNULL(@pBankBranch, '')
  266. ,pBankBranchName = ISNULL(@pBankBranchName, '')
  267. ,accountNo = ISNULL(@rBankAcNo, '')
  268. ,collCurr = @paidCType
  269. ,payoutCurr = @receiveCType
  270. ,salaryRange = cm.salaryRange
  271. ,txnSum = dbo.ShowDecimal(CAST(@txnSum AS VARCHAR(200)))
  272. ,txnSum2 = @txnSum
  273. ,txnPerDayCustomerLimit = isnull(dbo.FNAGetPerDayCustomerLimit(@settlementAgent), 0)
  274. ,txnCount = @txnCount
  275. ,SenderIDimage = @SenderIDimage
  276. INTO #sTemp
  277. FROM dbo.customerMaster CM WITH (NOLOCK)
  278. LEFT JOIN staticDataValue sdv WITH (NOLOCK) ON sdv.valueId = CM.idType
  279. LEFT JOIN staticDataValue custType WITH (NOLOCK) ON CM.customerType = custType.valueId
  280. WHERE CM.customerId IN (
  281. SELECT customerId
  282. FROM @customers
  283. )
  284. AND country = @sCountryId
  285. IF NOT EXISTS (
  286. SELECT 'x'
  287. FROM #sTemp
  288. )
  289. BEGIN
  290. EXEC proc_errorHandler 1
  291. ,'Customer not found with the respected search'
  292. ,NULL
  293. RETURN
  294. END
  295. SELECT *
  296. FROM #sTemp
  297. --DROP TABLE #sTemp
  298. RETURN
  299. END
  300. IF @FLAG IN ('s-new') --Direct Search By Passport/Mobile Number
  301. BEGIN
  302. DECLARE @IdNumber VARCHAR(30)
  303. ,@AVAILABLEBALANCE MONEY
  304. IF ISNULL(@customerId, '') = ''
  305. BEGIN
  306. EXEC proc_errorHandler 1
  307. ,'Please enter value to search'
  308. ,NULL
  309. RETURN
  310. END
  311. --SELECT @AVAILABLEBALANCE = availableLimit
  312. --FROM DBO.FNAGetUserCashLimitDetails(@user, NULL)
  313. SELECT @IdNumber = idNumber
  314. FROM customerMaster(NOLOCK)
  315. WHERE customerId = @customerId
  316. DECLARE @kycStatus INT
  317. ,@MSG VARCHAR(150)
  318. ,@visaStatusNotFound VARCHAR(10)
  319. ,@remittanceAllowed INT
  320. SELECT @kycStatus = kycStatus
  321. FROM TBL_CUSTOMER_KYC(NOLOCK)
  322. WHERE CUSTOMERID = @customerId
  323. AND ISDELETED = 0
  324. --AND kycStatus='11044'
  325. ORDER BY KYC_DATE
  326. SELECT @remittanceAllowed = remittanceAllowed FROM customerMaster(NOLOCK)
  327. WHERE CUSTOMERID = @customerId
  328. --IF ISNULL(@kycStatus, 0) <> 11044
  329. --BEGIN
  330. -- IF @kycStatus IS NOT NULL
  331. -- SELECT @MSG = 'KYC for selected customer is not completed, it is in status : ' + detailTitle
  332. -- FROM staticDataValue(NOLOCK)
  333. -- WHERE valueId = @kycStatus
  334. -- ELSE
  335. -- SELECT @MSG = 'Please complete KYC status first'
  336. -- EXEC proc_errorHandler 1
  337. -- ,@MSG
  338. -- ,NULL
  339. -- RETURN
  340. --END
  341. IF ISNULL(@remittanceAllowed,0) ='0'
  342. BEGIN
  343. SELECT @MSG = 'This customer is not allowed perform transaction.'
  344. EXEC proc_errorHandler 1
  345. ,@MSG
  346. ,NULL
  347. RETURN
  348. END
  349. --SELECT @visaStatus = visaStatus
  350. --FROM customermaster cm(NOLOCK)
  351. --INNER JOIN STATICDATAVALUE VISASTATUS ON VISASTATUS.VALUEID = cm.visastatus
  352. --WHERE cm.customerId = @customerId
  353. -- AND ISNULL(VISASTATUS.isActive, 'N') = 'Y'
  354. --IF @visaStatus IS NULL
  355. --BEGIN
  356. -- SET @visaStatusNotFound = 'true'
  357. --END
  358. --IF @IdNumber IS NULL
  359. --BEGIN
  360. -- EXEC proc_errorHandler 1
  361. -- ,'Invalid customer, Please udpate Identity Type Card Number to proceed!'
  362. -- ,NULL
  363. -- RETURN
  364. --END
  365. SELECT TOP 1 @fileName = [fileName]
  366. FROM customerDocument WITH (NOLOCK)
  367. WHERE customerId = @customerId
  368. AND fileType = 'custDoc'
  369. ORDER BY createdDate DESC
  370. IF @fileName IS NULL
  371. 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" />'
  372. ELSE
  373. 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 + '" />'
  374. SET @txnSum = ISNULL(@txnSum, 0)
  375. SET @txnCount = ISNULL(@txnCount, 0)
  376. SELECT TOP 1 @receiverName = ReceiverName
  377. ,@rCustomerId = CustomerId
  378. ,@receiverCountry = UPPER(ReceiverCountry)
  379. ,@receiverCountryId = CM.countryId
  380. ,@receiverAddress = ReceiverAddress
  381. ,@receiverCity = receiverCity
  382. ,@receiverEmail = ''
  383. ,@receiverPhone = ReceiverPhone
  384. ,@receiverMobile = receiver_mobile
  385. ,@receiverIDDescription = ReceiverIDDescription
  386. ,@ReceiverID = ReceiverID
  387. ,@paymentType = CASE paymentType
  388. WHEN 'Cash Pay'
  389. THEN 'CASH PAYMENT'
  390. WHEN 'Bank Transfer'
  391. THEN 'BANK DEPOSIT'
  392. WHEN 'Account Deposit To Other Bank'
  393. THEN 'BANK DEPOSIT'
  394. ELSE UPPER(paymentType)
  395. END
  396. ,@pBank = pBank
  397. ,@pBankBranch = pBankBranch
  398. ,@pBankBranchName = pBankBranchName
  399. ,@rBankAcNo = rBankACNo
  400. ,@paidCType = paidCType
  401. ,@receiveCType = receiveCType
  402. FROM customerTxnHistory T WITH (NOLOCK)
  403. INNER JOIN countryMaster CM(NOLOCK) ON CM.countryName = T.ReceiverCountry
  404. WHERE senderPassport = @IdNumber
  405. ORDER BY tranNo DESC
  406. IF @receiverEmail IS NULL
  407. OR @receiverEmail = ''
  408. BEGIN
  409. SELECT @receiverEmail = email
  410. FROM dbo.receiverInformation
  411. WHERE mobile LIKE '%' + @receiverMobile + '%'
  412. END
  413. SELECT @rFirstName = firstName
  414. ,@rMiddleName = middleName
  415. ,@rLastName1 = lastName1
  416. ,@rLastName2 = lastName2
  417. FROM dbo.FNASplitName(@receiverName)
  418. SELECT TOP 1 0 errorCode
  419. ,customerId = CM.customerId
  420. ,sMemId = CM.membershipId
  421. ,sfirstName = CM.firstName
  422. ,smiddleName = ISNULL(CM.middleName, '')
  423. ,slastName1 = ISNULL(CM.lastName1, '')
  424. ,slastName2 = ISNULL(CM.lastName2, '')
  425. ,sState = ISNULL(CM.STATE, '')
  426. ,scountry = ISNULL(CM.nativecountry, '')
  427. ,saddress = ISNULL(CM.address, '')
  428. ,saddress2 = ISNULL(CM.address2, '')
  429. ,szipCode = ISNULL(CM.zipCode, '')
  430. ,sDistrict = CM.district
  431. ,sCity = CM.city
  432. ,semail = ISNULL(CM.email, '')
  433. ,sgender = CASE
  434. WHEN CM.gender = 97
  435. THEN 'Male'
  436. WHEN CM.gender = 98
  437. THEN 'Female'
  438. END
  439. ,shomePhone = ISNULL(CM.telNo, '')
  440. ,sworkPhone = isnull(CM.workPhone, '')
  441. ,smobile = CM.mobile
  442. ,sdob = convert(VARCHAR(20), CM.dob, 23)
  443. ,sCustomerType = custType.detailTitle
  444. ,sOccupation = CM.occupation
  445. ,idName = sdv.detailTitle
  446. ,sidNumber = ISNULL(CM.idNumber, '')
  447. ,svalidDate = ISNULL(CONVERT(VARCHAR, CM.idExpiryDate, 23), '')
  448. ,senderName = CM.fullName
  449. ,companyName = CASE
  450. WHEN cm.companyName IS NULL
  451. AND CM.customerType = '4701'
  452. THEN cm.firstName
  453. END
  454. ,receiverName = @receiverName
  455. ,rId = @rCustomerId
  456. ,rfirstName = @rFirstName
  457. ,rmiddleName = @rMiddleName
  458. ,rlastName1 = @rLastName1
  459. ,rlastName2 = @rLastName2
  460. ,rcountry = @receiverCountry
  461. ,raddress = @receiverAddress
  462. ,raddress2 = ''
  463. ,rState = ''
  464. ,rzipCode = ''
  465. ,rDistrict = ''
  466. ,rCity = @receiverCity
  467. ,remail = ISNULL(@receiverEmail, '')
  468. ,rgender = ''
  469. ,rhomePhone = ISNULL(@receiverPhone, '')
  470. ,rworkPhone = ISNULL(@receiverPhone, '')
  471. ,rmobile = ISNULL(@receiverMobile, '')
  472. ,rdob = ''
  473. ,ridtype = @receiverIDDescription
  474. ,ridNumber = @receiverID
  475. ,rvalidDate = ''
  476. ,purposeOfRemit = ''
  477. ,sourceOfFund = sourceOfFund
  478. ,relWithSender = ''
  479. ,pCountry = @receiverCountry
  480. ,pCountryId = @receiverCountryId
  481. ,paymentMethod = @paymentType
  482. ,pAgent = ''
  483. ,pBank = ISNULL(@pBank, '')
  484. ,pBankBranch = ISNULL(@pBankBranch, '')
  485. ,pBankBranchName = ISNULL(@pBankBranchName, '')
  486. ,accountNo = ISNULL(@rBankAcNo, '')
  487. ,collCurr = @paidCType
  488. ,payoutCurr = @receiveCType
  489. ,salaryRange = cm.salaryRange
  490. ,txnSum = dbo.ShowDecimal(CAST(@txnSum AS VARCHAR(200)))
  491. ,txnSum2 = @txnSum
  492. ,txnPerDayCustomerLimit = isnull(dbo.FNAGetPerDayCustomerLimit(@settlementAgent), 0)
  493. ,txnCount = @txnCount
  494. ,SenderIDimage = @SenderIDimage
  495. ,idIssueDate = ISNULL(CONVERT(VARCHAR, CM.idIssueDate, 23), '')
  496. ,street = ISNULL(CM.streetUnicode, CM.street)
  497. ,CM.organizationType
  498. ,CM.customerType
  499. ,CM.PLACEOFISSUE
  500. ,AVAILABLEBALANCE = ISNULL(@AVAILABLEBALANCE, 0)
  501. ,CM.monthlyIncome
  502. ,visaStatusNotFound = @visaStatusNotFound
  503. ,cm.additionalAddress
  504. ,showCDDI = CASE
  505. WHEN ISNULL(isCDDIUpdated, 0) = 0
  506. THEN 'Y'
  507. ELSE 'N'
  508. END
  509. ,cm.otherIdNumber
  510. ,sdv.valueId [idTypeValue]
  511. ,VISASTATUS.detailTitle visaStatus
  512. ,rewardPoints = CAST(dbo.[FNA_GET_AVAILABLE_BALANCE_POINTS](@customerId) AS INT)
  513. INTO #sTempNew
  514. FROM dbo.customerMaster CM WITH (NOLOCK)
  515. LEFT JOIN staticDataValue sdv WITH (NOLOCK) ON sdv.valueId = CM.idType
  516. LEFT JOIN staticDataValue custType WITH (NOLOCK) ON CM.customerType = custType.valueId
  517. LEFT JOIN STATICDATAVALUE VISASTATUS ON VISASTATUS.VALUEID = cm.visastatus
  518. WHERE CM.customerId IN (@customerId)
  519. AND country = @sCountryId
  520. IF NOT EXISTS (
  521. SELECT 'x'
  522. FROM #sTempNew
  523. )
  524. BEGIN
  525. EXEC proc_errorHandler 1
  526. ,'Customer not found with the respected search'
  527. ,NULL
  528. RETURN
  529. END
  530. SELECT *
  531. FROM #sTempNew
  532. SELECT documentType = CASE
  533. WHEN cd.documentType = '0'
  534. AND filetype = 'application/pdf'
  535. THEN cd.filedescription
  536. ELSE ISNULL(sdv.detailTitle, 'signature')
  537. END
  538. ,fileType = CASE
  539. WHEN ISNULL(cd.fileType, 'image/jpeg') IN ('receiver')
  540. THEN 'application/pdf'
  541. ELSE ISNULL(cd.fileType, 'image/jpeg')
  542. END
  543. ,uploadedDate = CONVERT(VARCHAR(10), cd.createddate, 111)
  544. ,fileName = '<a onclick="showDocument(' + Cast(cd.cdId AS VARCHAR) + ',''' + CASE
  545. WHEN ISNULL(cd.fileType, 'image/jpeg') IN ('receiver')
  546. THEN 'application/pdf'
  547. ELSE ISNULL(cd.fileType, 'image/jpeg')
  548. END + ''');">' + cd.fileName + '</a>'
  549. FROM dbo.customerDocument cd
  550. LEFT JOIN dbo.staticDataValue sdv ON sdv.valueId = cd.documentType
  551. WHERE cd.customerId = @customerId
  552. AND ISNULL(isDeleted, 'N') = 'N'
  553. ORDER BY cd.createdDate;
  554. SELECT fullName = firstName + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName1, '')
  555. ,receiverId
  556. FROM dbo.receiverInformation(NOLOCK)
  557. WHERE customerId = @customerId
  558. AND ISNULL(ISDELETED, 0) <> 1
  559. ORDER BY FULLNAME ASC
  560. --DROP TABLE #sTemp
  561. RETURN
  562. END
  563. ELSE IF @flag = 'ASN'
  564. BEGIN
  565. IF NOT EXISTS (
  566. SELECT *
  567. FROM dbo.customerMaster(NOLOCK)
  568. WHERE customerId = @recId
  569. )
  570. BEGIN
  571. EXEC proc_errorHandler 1
  572. ,'No result found'
  573. ,NULL
  574. RETURN
  575. END
  576. SELECT TOP 1 0 errorCode
  577. ,customerId = CM.idNumber
  578. ,sMemId = CM.membershipId
  579. ,sfirstName = CM.firstName
  580. ,smiddleName = ISNULL(CM.middleName, '')
  581. ,slastName1 = ISNULL(CM.lastName1, '')
  582. ,slastName2 = ISNULL(CM.lastName2, '')
  583. ,sState = ISNULL(CM.STATE, '')
  584. ,scountry = ISNULL(CM.nativecountry, '')
  585. ,saddress = ISNULL(CM.address, '')
  586. ,saddress2 = ISNULL(CM.address2, '')
  587. ,szipCode = ISNULL(CM.zipCode, '')
  588. ,sDistrict = CM.district
  589. ,sCity = CM.city
  590. ,semail = ISNULL(CM.email, '')
  591. ,sgender = CASE
  592. WHEN CM.gender = 97
  593. THEN 'Male'
  594. WHEN CM.gender = 98
  595. THEN 'Female'
  596. END
  597. ,shomePhone = ISNULL(CM.homePhone, '')
  598. ,sworkPhone = isnull(CM.workPhone, '')
  599. ,smobile = CM.mobile
  600. ,sdob = convert(VARCHAR(20), CM.dob, 111)
  601. ,sCustomerType = custType.detailTitle
  602. ,sOccupation = CM.occupation
  603. ,idName = sdv.detailTitle
  604. ,sidNumber = ISNULL(CM.idNumber, '')
  605. ,svalidDate = ISNULL(CONVERT(VARCHAR, CM.idExpiryDate, 111), '')
  606. ,senderName = CM.fullName
  607. ,companyName = CM.companyName
  608. ,receiverName = @receiverName
  609. ,rId = @rCustomerId
  610. ,rfirstName = @rFirstName
  611. ,rmiddleName = @rMiddleName
  612. ,rlastName1 = @rLastName1
  613. ,rlastName2 = @rLastName2
  614. ,rcountry = @receiverCountry
  615. ,raddress = @receiverAddress
  616. ,raddress2 = ''
  617. ,rState = ''
  618. ,rzipCode = ''
  619. ,rDistrict = ''
  620. ,rCity = @receiverCity
  621. ,remail = ISNULL(@receiverEmail, '')
  622. ,rgender = ''
  623. ,rhomePhone = ISNULL(@receiverPhone, '')
  624. ,rworkPhone = ISNULL(@receiverPhone, '')
  625. ,rmobile = ISNULL(@receiverMobile, '')
  626. ,rdob = ''
  627. ,ridtype = @receiverIDDescription
  628. ,ridNumber = @receiverID
  629. ,rvalidDate = ''
  630. ,purposeOfRemit = ''
  631. ,sourceOfFund = ''
  632. ,relWithSender = ''
  633. ,pCountry = @receiverCountry
  634. ,paymentMethod = @paymentType
  635. ,pAgent = ''
  636. ,pBank = ISNULL(@pBank, '')
  637. ,pBankBranch = ISNULL(@pBankBranch, '')
  638. ,pBankBranchName = ISNULL(@pBankBranchName, '')
  639. ,accountNo = ISNULL(@rBankAcNo, '')
  640. ,collCurr = @paidCType
  641. ,payoutCurr = @receiveCType
  642. ,salaryRange = cm.salaryRange
  643. ,txnSum = dbo.ShowDecimal(CAST(@txnSum AS VARCHAR(200)))
  644. ,txnSum2 = @txnSum
  645. ,txnPerDayCustomerLimit = isnull(dbo.FNAGetPerDayCustomerLimit(@settlementAgent), 0)
  646. ,txnCount = @txnCount
  647. ,SenderIDimage = @SenderIDimage
  648. FROM dbo.customerMaster CM WITH (NOLOCK)
  649. LEFT JOIN staticDataValue sdv WITH (NOLOCK) ON sdv.valueId = CM.idType
  650. LEFT JOIN staticDataValue custType WITH (NOLOCK) ON CM.customerType = custType.valueId
  651. WHERE CM.customerId = @recId
  652. END
  653. ELSE IF @flag = 'srr' --Search Recent Receiver List
  654. BEGIN
  655. SELECT @membershipId = isnull(membershipId, '')
  656. ,@senderName = fullName
  657. FROM customers WITH (NOLOCK)
  658. WHERE idNumber = @senderId
  659. SET @SQL = '
  660. IF OBJECT_ID(''tempdb..#TEMP'') IS NOT NULL DROP TABLE #TEMP
  661. SELECT TOP 5 TR.customerId id,TS.fullName,COUNT(1) NO_OF_TXN
  662. INTO #TEMP
  663. FROM dbo.tranReceivers TR(NOLOCK)
  664. INNER JOIN dbo.tranSenders TS(NOLOCK) ON TR.tranId = TS.tranId
  665. WHERE TS.customerId = ''' + @senderId + '''
  666. GROUP BY TR.customerId,TS.fullName
  667. ORDER BY NO_OF_TXN DESC'
  668. SET @SQL = @SQL + '
  669. SELECT TOP 5 T.id ,
  670. membershiId=RI.membershipId,
  671. senderName=T.fullName,
  672. receiverName = RI.firstName+ISNULL('' ''+ri.middleName,'''')+ISNULL('' ''+ri.lastName1,'''') ,
  673. rMobile=RI.mobile,
  674. bank='''',
  675. payMode='''',
  676. bankBranch='''',
  677. acNo=ri.receiverAccountNo,
  678. idType=RI.idType,
  679. idNumber=RI.idNumber
  680. FROM dbo.receiverInformation RI(NOLOCK)
  681. INNER JOIN #TEMP T ON T.id = RI.receiverId'
  682. IF @searchValue IS NOT NULL
  683. SET @SQL = @SQL + ' AND RI.firstName+ISNULL('' ''+ri.middleName,'''')+ISNULL('' ''+ri.lastName1,'''') LIKE ''' + @searchValue + '%'''
  684. --SET @SQL = @SQL + '
  685. --GROUP BY receiverName ,CTH.receiver_mobile ,CTH.rBankName ,CTH.rBankBranch ,CTH.rBankACNo ,CTH.membershipId ,senderName ,CTH.Tranno
  686. --ORDER BY MAX(ri.receiverId) DESC'
  687. PRINT 1
  688. PRINT (@SQL)
  689. EXEC (@SQL)
  690. RETURN
  691. END
  692. ELSE IF @flag = 'sth' --Sender Txn History
  693. BEGIN
  694. --******Inficare System Search******
  695. SELECT @senderName = fullName
  696. FROM customers WITH (NOLOCK)
  697. WHERE idNumber = @senderId
  698. SET @SQL = '
  699. SELECT TOP 5
  700. id = ms.Tranno
  701. ,senderName = ''' + @senderName + '''
  702. ,receiverName = ms.ReceiverName
  703. ,tAmt = ms.paidAmt
  704. ,createdDate = CONVERT(VARCHAR , ms.confirmDate, 111)
  705. ,ICN = dbo.FNADecryptString(ms.refno)
  706. ,payMode = ms.paymentType
  707. ,bank = CASE WHEN ms.paymentType = ''Bank Transfer'' THEN ms.rBankName
  708. WHEN ms.paymentType = ''Account Deposit to Other Bank'' THEN ms.ben_bank_name ELSE ms.rBankName END
  709. ,bankBranch = CASE WHEN ms.paymentType = ''Bank Transfer'' THEN ms.rBankBranch
  710. WHEN ms.paymentType = ''Account Deposit to Other Bank'' THEN ms.rBankAcType ELSE ms.rBankBranch END
  711. ,acNo = ms.rBankACNo
  712. FROM customerTxnHistory ms WITH(NOLOCK)
  713. WHERE senderPassport = ''' + @senderId + '''
  714. '
  715. IF @recId IS NOT NULL
  716. SET @SQL = @SQL + ' AND ms.ReceiverName LIKE ''' + @recId + '%'''
  717. SET @SQL = @SQL + ' ORDER BY ms.Tranno DESC'
  718. EXEC (@SQL)
  719. RETURN
  720. END
  721. ELSE IF @flag = 'advS' --Advance Search(Load Customer Grid)
  722. BEGIN
  723. SET @searchValue = ISNULL(@searchValue, '')
  724. SET @SQL = '
  725. SELECT DISTINCT TOP 15
  726. errorCode = ''0''
  727. ,customerId = C.customerId
  728. ,membershipId = C.membershipId
  729. ,senderName = C.fullName
  730. ,countryName = CM.countryName
  731. ,address = C.address
  732. ,mobile = C.mobile
  733. ,nativeCountry = C.nativeCountry
  734. ,email = C.email
  735. ,idNumber = C.idNumber
  736. ,idType = SV.detailTitle
  737. ,validDate = CONVERT(VARCHAR, C.idExpiryDate, 111)
  738. ,cUstId = C.idNumber
  739. FROM customerMaster C WITH(NOLOCK)
  740. INNER JOIN countryMaster CM WITH (NOLOCK) ON C.country = CM.countryId
  741. LEFT JOIN staticDataValue SV WITH (NOLOCK) ON SV.valueId = C.idType
  742. WHERE ISNULL(C.isDeleted,''N'') = ''N'' AND ISNULL(isBlackListed, ''N'') = ''N''
  743. '
  744. IF @sCountryId IS NOT NULL
  745. SET @SQL = @SQL + ' AND c.country = ''' + @sCountryId + ''''
  746. IF @searchType = 'firstName'
  747. SET @SQL = @SQL + ' AND C.fullName LIKE ''' + @searchValue + '%'''
  748. ELSE IF @searchType = 'Address'
  749. SET @SQL = @SQL + ' AND C.Address LIKE ''' + @searchValue + '%'''
  750. ELSE IF @searchType = 'Passport'
  751. SET @SQL = @SQL + ' AND C.idType = 1302 AND C.idNumber = ''' + @searchValue + ''''
  752. ELSE IF @searchType IS NOT NULL
  753. AND @searchType <> 'IC'
  754. SET @SQL = @SQL + ' AND C.' + @searchType + ' = ''' + @searchValue + ''''
  755. ELSE
  756. SET @SQL = @SQL + ' AND 1 = 2'
  757. --PRINT @SQL
  758. EXEC (@SQL)
  759. END
  760. ELSE IF @flag = 'advS-new' --Advance Search(Load Customer Grid)
  761. BEGIN
  762. SET @searchValue = ISNULL(@searchValue, '')
  763. SET @SQL = '
  764. SELECT DISTINCT TOP 15
  765. errorCode = ''0''
  766. ,customerId = C.customerId
  767. ,membershipId = C.membershipId
  768. ,senderName = C.fullName
  769. ,countryName = CM.countryName
  770. ,address = C.address
  771. ,mobile = C.mobile
  772. ,nativeCountry = C.nativeCountry
  773. ,email = C.email
  774. ,idNumber = C.idNumber
  775. ,idType = SV.detailTitle
  776. ,validDate = CONVERT(VARCHAR, C.idExpiryDate, 111)
  777. ,cUstId = C.idNumber
  778. FROM customerMaster C WITH(NOLOCK)
  779. INNER JOIN countryMaster CM WITH (NOLOCK) ON C.country = CM.countryId
  780. LEFT JOIN staticDataValue SV WITH (NOLOCK) ON SV.valueId = C.idType
  781. WHERE ISNULL(C.isDeleted,''N'') = ''N'' AND ISNULL(isBlackListed, ''N'') = ''N''
  782. '
  783. IF @sCountryId IS NOT NULL
  784. SET @SQL = @SQL + ' AND c.country = ''' + @sCountryId + ''''
  785. IF @searchType = 'name'
  786. SET @SQL = @SQL + ' AND C.fullName LIKE ''' + @searchValue + '%'''
  787. ELSE IF @searchType = 'email'
  788. SET @SQL = @SQL + ' AND C.email LIKE ''' + @searchValue + '%'''
  789. ELSE IF @searchType = 'membershipId'
  790. SET @SQL = @SQL + ' AND C.membershipId LIKE ''' + @searchValue + '%'''
  791. ELSE IF @searchType = 'dob'
  792. SET @SQL = @SQL + ' AND C.dob LIKE ''' + @searchValue + '%'''
  793. ELSE
  794. SET @SQL = @SQL + ' AND 1 = 2'
  795. --PRINT @SQL
  796. EXEC (@SQL)
  797. END
  798. ELSE IF @searchType = 'ICN' --Search By ICN
  799. BEGIN
  800. EXEC proc_errorHandler 1
  801. ,'Search By ICN is not allowed for now'
  802. ,NULL
  803. RETURN
  804. SELECT TOP 1 @SenderId = C.customerId
  805. ,@TranId = trn.id
  806. ,@ReceiverID = cast(R.customerId AS VARCHAR(20))
  807. --,S.customerId
  808. FROM customers C
  809. LEFT JOIN tranSenders S WITH (NOLOCK) ON C.customerId = S.customerId
  810. LEFT JOIN remitTran trn WITH (NOLOCK) ON S.tranId = trn.id
  811. LEFT JOIN tranReceivers R WITH (NOLOCK) ON R.tranId = trn.id
  812. WHERE trn.controlNo = dbo.FNADecryptString(@searchValue)
  813. AND R.tranId IS NOT NULL
  814. ORDER BY trn.id DESC
  815. --select @searchValue
  816. IF NOT EXISTS (
  817. SELECT 'A'
  818. FROM customers
  819. WHERE customerId = @SenderId
  820. )
  821. BEGIN
  822. EXEC proc_errorHandler 1
  823. ,'This Member is not found.'
  824. ,NULL
  825. RETURN;
  826. END
  827. IF EXISTS (
  828. SELECT 'A'
  829. FROM customers
  830. WHERE customerId = @SenderId
  831. AND ISNULL(isBlackListed, 'N') = 'Y'
  832. )
  833. BEGIN
  834. EXEC proc_errorHandler 1
  835. ,'This customer is blacklisted. Cannot proceed for transaction.'
  836. ,NULL
  837. RETURN;
  838. END
  839. SELECT 0 errorCode
  840. ,*
  841. FROM (
  842. SELECT membershipId [sMemId]
  843. ,firstName sfirstName
  844. ,isnull(middleName, '') smiddleName
  845. ,isnull(lastName1, '') slastName1
  846. ,isnull(lastName2, '') slastName2
  847. ,country scountry
  848. ,isnull([address], '') saddress
  849. ,isnull([State], '') sState
  850. ,isnull(zipCode, '') szipCode
  851. ,district [sDistrict]
  852. ,city [sCity]
  853. ,email semail
  854. ,homePhone shomePhone
  855. ,isnull(workPhone, '') sWorkPhone
  856. ,mobile smobile
  857. ,convert(VARCHAR(20), dob, 111) sdob
  858. ,Typ.detailTitle sCustomerType
  859. ,Ocu.detailTitle sOccupation
  860. ,relativeName sRelativeName
  861. ,Rel.detailTitle sRelation
  862. ,Cont.countryName scountryName
  863. ,ID.idType sidType
  864. ,ID.idNumber sidNumber
  865. ,ID.validDate svalidDate
  866. FROM customers C WITH (NOLOCK)
  867. LEFT JOIN customerIdentity ID WITH (NOLOCK) ON C.customerId = ID.idType
  868. JOIN staticDataValue Rel WITH (NOLOCK) ON C.relationId = Rel.valueId
  869. JOIN staticDataValue Ocu WITH (NOLOCK) ON C.occupation = Ocu.valueId
  870. JOIN staticDataValue Typ WITH (NOLOCK) ON C.customerType = Typ.valueId
  871. JOIN countryMaster Cont WITH (NOLOCK) ON C.country = Cont.countryId
  872. WHERE C.customerId = @SenderId
  873. ) AS sender
  874. LEFT JOIN (
  875. SELECT membershipId [rMemId]
  876. ,firstName rfirstName
  877. ,isnull(middleName, '') rmiddleName
  878. ,isnull(lastName1, '') rlastName1
  879. ,isnull(lastName2, '') rlastName2
  880. ,country [rcountry]
  881. ,isnull([address], '') raddress
  882. ,isnull([State], '') rState
  883. ,isnull(zipCode, '') rzipCode
  884. ,district [rDistrict]
  885. ,city [rCity]
  886. ,email remail
  887. ,homePhone rhomePhone
  888. ,isnull(workPhone, '') sWorkPhone
  889. ,mobile rmobile
  890. ,convert(VARCHAR(20), dob, 111) rdob
  891. ,Typ.detailTitle rCustomerType
  892. ,Ocu.detailTitle rOccupation
  893. ,relativeName rRelativeName
  894. ,Rel.detailTitle rRelation
  895. ,Cont.countryName rcountryName
  896. ,ID.idType ridType
  897. ,ID.idNumber ridNumber
  898. ,ID.validDate rvalidDate
  899. FROM customers C WITH (NOLOCK)
  900. LEFT JOIN customerIdentity ID WITH (NOLOCK) ON C.customerId = ID.idType
  901. JOIN staticDataValue Rel WITH (NOLOCK) ON C.relationId = Rel.valueId
  902. JOIN staticDataValue Ocu WITH (NOLOCK) ON C.occupation = Ocu.valueId
  903. JOIN staticDataValue Typ WITH (NOLOCK) ON C.customerType = Typ.valueId
  904. JOIN countryMaster Cont WITH (NOLOCK) ON C.country = Cont.countryId
  905. WHERE C.customerId = @ReceiverID
  906. ) AS REC ON sender.sMemId = REC.rMemId
  907. END
  908. ELSE IF @flag = 'R' --Load Receiver after picked
  909. BEGIN
  910. DECLARE @TRANLIST TABLE (
  911. tranId BIGINT
  912. ,customerId INT
  913. )
  914. --*****Inficare Search Receiver******
  915. --INSERT INTO @TRANLIST(tranId)
  916. --SELECT MAX(ms.Tranno) FROM irh_ime_plus_01.dbo.moneySend ms WITH(NOLOCK)
  917. --WHERE senderPassport = @senderId
  918. --GROUP BY ms.Tranno
  919. SELECT @rFullName = receiverName
  920. FROM customerTxnHistory WITH (NOLOCK)
  921. WHERE Tranno = @recId
  922. SELECT @rFirstName = firstName
  923. ,@rMiddleName = middleName
  924. ,@rLastName1 = lastName1
  925. ,@rLastName2 = lastName2
  926. FROM dbo.FNASplitName(@rFullName)
  927. SELECT DISTINCT ID = ms.Tranno
  928. ,[sid] = ms.senderPassport
  929. ,[senderName] = ms.SenderName
  930. ,sidType = ms.senderFax
  931. ,sidNumber = ms.senderPassport
  932. ,smobile = ms.sender_mobile
  933. ,saddress = ms.SenderAddress
  934. ,tranNo = dbo.FNADecryptString(ms.refno)
  935. ,[receiverName] = ms.receiverName
  936. ,firstName = @rFirstName
  937. ,middleName = @rMiddleName
  938. ,lastName1 = @rLastName1
  939. ,lastName2 = @rLastName2
  940. ,pBranchName = ms.rBankBranch
  941. ,paymentMethod = CASE ms.paymentType
  942. WHEN 'Cash Pay'
  943. THEN 'CASH PAYMENT'
  944. WHEN 'Bank Transfer'
  945. THEN 'BANK DEPOSIT'
  946. WHEN 'Account Deposit to Other Bank'
  947. THEN 'BANK DEPOSIT'
  948. ELSE UPPER(ms.paymentType)
  949. END
  950. ,tAmt = ms.paidAmt
  951. ,createdDate = CONVERT(VARCHAR, ms.confirmDate, 111)
  952. ,sCountry = ms.SenderCountry
  953. ,idType = ms.receiverIDDescription
  954. ,idNumber = ms.receiverID
  955. ,validDate = ''
  956. ,dob = ''
  957. ,homePhone = ReceiverPhone
  958. ,mobile = receiver_mobile
  959. ,[address] = ReceiverAddress
  960. ,[state] = ReceiverCity
  961. ,zipCode = ''
  962. ,country = ReceiverCountry
  963. ,email = ''
  964. ,accountNo = ISNULL(ms.rBankACNo, '')
  965. ,pBank = ISNULL(pBank, 0)
  966. ,pBankBranch = ISNULL(pBankBranch, 0)
  967. ,pBankBranchName = ISNULL(pBankBranchName, '')
  968. FROM customerTxnHistory ms WITH (NOLOCK)
  969. WHERE
  970. --ms.SenderName LIKE ISNULL(@searchValue + '%', '%') AND
  971. ms.Tranno = @recId
  972. END
  973. ELSE IF @flag = 'branchByAgent'
  974. BEGIN
  975. IF @agentType = 'I'
  976. BEGIN
  977. SET @SQL = '
  978. SELECT TOP 20
  979. agentId
  980. ,agentName
  981. ,agentAddress
  982. ,agentCity = ISNULL(agentCity,'''')
  983. ,agentPhone1 = ISNULL(agentPhone1 ,'''')
  984. ,agentState = ISNULL(agentState, '''')
  985. ,extCode = ISNULL(extCode, '''')
  986. FROM agentMaster WITH(NOLOCK)
  987. WHERE ISNULL(isDeleted, ''N'') = ''N''
  988. AND agentType = ''2904''
  989. AND parentId = ''' + @senderId + '''
  990. '
  991. IF @searchValue IS NOT NULL
  992. SET @SQL = @SQL + ' AND ' + @searchType + ' LIKE ''%' + @searchValue + '%'''
  993. SET @SQL = @SQL + ' ORDER BY agentName ASC'
  994. END
  995. ELSE IF @agentType = 'E'
  996. BEGIN
  997. IF @searchType = 'agentName'
  998. SET @searchType = 'branchName'
  999. ELSE IF @searchType = 'agentAddress'
  1000. SET @searchType = 'address'
  1001. ELSE IF @searchType = 'agentCity'
  1002. SET @searchType = 'city'
  1003. ELSE IF @searchType = 'agentPhone1'
  1004. SET @searchType = 'phone'
  1005. ELSE IF @searchType = 'agentState'
  1006. SET @searchType = 'State'
  1007. ELSE IF @searchType = 'extCode'
  1008. SET @searchType = 'externalCode'
  1009. SET @SQL = '
  1010. SELECT TOP 10
  1011. agentId = extBranchId
  1012. ,agentName = branchName
  1013. ,agentAddress = address
  1014. ,agentCity = ISNULL(city, '''')
  1015. ,agentPhone1 = ISNULL(phone, '''')
  1016. ,agentState = ISNULL(State, '''')
  1017. ,extCode = ISNULL(externalCode, '''')
  1018. FROM externalBankBranch WITH(NOLOCK)
  1019. WHERE ISNULL(isDeleted, ''N'') = ''N''
  1020. AND extBankId = ''' + @senderId + '''
  1021. AND ISNULL(isBlocked,''N'') = ''N''
  1022. '
  1023. IF @searchValue IS NOT NULL
  1024. SET @SQL = @SQL + ' AND ' + @searchType + ' LIKE ''' + @searchValue + '%'''
  1025. SET @SQL = @SQL + ' ORDER BY agentName ASC'
  1026. END
  1027. EXEC (@SQL)
  1028. PRINT (@SQL)
  1029. RETURN
  1030. END
  1031. ELSE IF @flag = 'locationByAgent'
  1032. BEGIN
  1033. SELECT TOP 50 L.LocationId
  1034. ,L.Address
  1035. ,L.City
  1036. ,A.agentName
  1037. FROM agentDoorToDoorLocation L WITH (NOLOCK)
  1038. INNER JOIN agentMaster A WITH (NOLOCK) ON L.agentId = A.agentId
  1039. WHERE L.agentId = @senderId
  1040. AND L.Address LIKE ISNULL(@searchValue + '%', '%')
  1041. ORDER BY L.Address
  1042. END