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.

1094 lines
29 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_autocomplete] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_autocomplete]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_autocomplete] 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_autocomplete] (
  12. @category VARCHAR(50)
  13. ,@searchText VARCHAR(50)
  14. ,@param1 VARCHAR(50) = NULL
  15. ,@param2 VARCHAR(50) = NULL
  16. ,@param3 VARCHAR(50) = NULL
  17. )
  18. AS
  19. DECLARE @SQL AS VARCHAR(MAX)
  20. IF @category = 'user'
  21. BEGIN
  22. DECLARE @branchList TABLE(branchId INT)
  23. IF @param1 IS NULL
  24. BEGIN
  25. INSERT INTO @branchList
  26. SELECT
  27. agentId
  28. FROM agentMaster
  29. WHERE agentType = '2904'
  30. AND parentId = @param2
  31. AND ISNULL(isDeleted, 'N') <> 'Y'
  32. AND ISNULL(isActive, 'N') = 'Y'
  33. END
  34. IF @param1 IS NULL AND @param2 IS NULL
  35. BEGIN
  36. SELECT TOP 20
  37. userID,
  38. userName
  39. FROM applicationUsers
  40. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  41. AND ISNULL(isDeleted,'N' )<> 'Y'
  42. AND ISNULL(isActive, 'N') = 'Y'
  43. ORDER BY userName ASC
  44. RETURN
  45. END
  46. IF @param1 IS NOT NULL AND @param2 IS NOT NULL
  47. BEGIN
  48. INSERT INTO @branchList
  49. SELECT @param1
  50. END
  51. SELECT TOP 20
  52. userID,
  53. userName
  54. FROM applicationUsers
  55. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  56. AND agentId IN (SELECT branchId FROM @branchList)
  57. ORDER BY userName ASC
  58. RETURN
  59. END
  60. IF @category = 'menuSearchAdmin'
  61. BEGIN
  62. IF @param1 = 'admin'
  63. BEGIN
  64. SELECT TOP 20 linkPage, menuName FROM dbo.applicationMenus WITH(NOLOCK) WHERE AgentMenuGroup IS NULL
  65. AND menuName LIKE ISNULL(@searchText, '') + '%'
  66. END
  67. ELSE
  68. BEGIN
  69. SELECT TOP 20 AM.linkPage ,
  70. AM.menuName
  71. FROM dbo.applicationUserRoles AR WITH(NOLOCK)
  72. INNER JOIN dbo.applicationRoleFunctions AF WITH(NOLOCK) ON AF.roleId = AR.roleId
  73. INNER JOIN dbo.applicationMenus AM WITH(NOLOCK) ON AM.functionId = AF.functionId
  74. INNER JOIN dbo.applicationUsers AU WITH(NOLOCK) ON AU.userId = AR.userId
  75. WHERE AU.userName = @param1
  76. AND AM.AgentMenuGroup IS NULL
  77. AND menuName LIKE ISNULL(@searchText, '') + '%';
  78. END
  79. END
  80. IF @category='agentRatingList'
  81. BEGIN
  82. SELECT TOP 20 agentId,agentName FROM agentlistriskprofile
  83. WHERE
  84. agentName LIKE ISNULL(@searchText, '') + '%'
  85. ORDER BY agentName ASC
  86. RETURN
  87. END
  88. IF @category = 'menuSearchAgent'
  89. BEGIN
  90. SELECT TOP 20 AM.linkPage ,
  91. AM.menuName
  92. FROM dbo.applicationUserRoles AR WITH(NOLOCK)
  93. INNER JOIN dbo.applicationRoleFunctions AF WITH(NOLOCK) ON AF.roleId = AR.roleId
  94. INNER JOIN dbo.applicationMenus AM WITH(NOLOCK) ON AM.functionId = AF.functionId
  95. INNER JOIN dbo.applicationUsers AU WITH(NOLOCK) ON AU.userId = AR.userId
  96. WHERE AU.userName = @param1
  97. AND AM.AgentMenuGroup IS NOT NULL
  98. AND menuName LIKE ISNULL(@searchText, '') + '%';
  99. END
  100. IF @category = 'users'
  101. BEGIN
  102. IF @param1 IS NOT NULL
  103. BEGIN
  104. SELECT TOP 20
  105. userID,
  106. userName
  107. FROM applicationUsers WITH(NOLOCK)
  108. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  109. AND agentId = @param1
  110. AND ISNULL(isDeleted,'N' )<> 'Y'
  111. AND ISNULL(isActive, 'N') = 'Y'
  112. ORDER BY userName ASC
  113. RETURN
  114. END
  115. SELECT TOP 20
  116. userID,
  117. userName
  118. FROM applicationUsers WITH(NOLOCK)
  119. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  120. AND ISNULL(isDeleted,'N' )<> 'Y'
  121. AND ISNULL(isActive, 'N') = 'Y'
  122. ORDER BY userName ASC
  123. RETURN
  124. END
  125. IF @category = 'country'
  126. BEGIN
  127. SELECT TOP 20
  128. countryId,
  129. countryName
  130. FROM countryMaster
  131. WHERE countryName LIKE ISNULL(@searchText, '') + '%'
  132. AND ISNULL(isOperativeCountry,'')='Y'
  133. ORDER BY countryName ASC
  134. RETURN
  135. END
  136. IF @category = 'countryOp'
  137. BEGIN
  138. SELECT TOP 20
  139. countryId,
  140. countryName
  141. FROM countryMaster
  142. WHERE countryName LIKE ISNULL(@searchText, '') + '%'
  143. ORDER BY countryName ASC
  144. RETURN
  145. END
  146. IF @category = 'countrySend'
  147. BEGIN
  148. SELECT TOP 20
  149. countryId,
  150. countryName
  151. FROM countryMaster
  152. WHERE countryName LIKE ISNULL(@searchText, '') + '%'
  153. AND ISNULL(isOperativeCountry,'') = 'Y'
  154. AND ISNULL(operationType,'B') IN ('B','S','R')
  155. ORDER BY countryName ASC
  156. RETURN
  157. END
  158. IF @category = 'countryPay'
  159. BEGIN
  160. SELECT TOP 20
  161. countryId,
  162. countryName
  163. FROM countryMaster
  164. WHERE countryName LIKE ISNULL(@searchText, '') + '%'
  165. AND ISNULL(isOperativeCountry,'') = 'Y'
  166. AND ISNULL(operationType,'B') IN ('B','R')
  167. ORDER BY countryName ASC
  168. RETURN
  169. END
  170. IF @category = 'branch'
  171. BEGIN
  172. SELECT TOP 20
  173. agentId,
  174. agentName
  175. FROM agentMaster
  176. WHERE agentType = '2904'
  177. AND parentId = @param1
  178. AND ISNULL(isDeleted, 'N') <> 'Y'
  179. AND agentName LIKE ISNULL(@searchText, '') + '%'
  180. ORDER BY agentName ASC
  181. RETURN
  182. END
  183. IF @category = 'branchExt' -- branch filter external or internal
  184. BEGIN
  185. IF RIGHT(@param1,1) = 'I'
  186. BEGIN
  187. SELECT TOP 20
  188. agentId,
  189. agentName
  190. FROM agentMaster
  191. WHERE agentType = '2904'
  192. AND parentId = LEFT(@param1,LEN(@param1)-1)
  193. AND ISNULL(isDeleted, 'N') <> 'Y'
  194. AND agentName LIKE ISNULL(@searchText, '') + '%'
  195. ORDER BY agentName ASC
  196. RETURN
  197. END
  198. IF RIGHT(@param1,1) = 'E'
  199. BEGIN
  200. SELECT TOP 20
  201. ebb.extBranchId agentId
  202. ,branchName agentName
  203. FROM externalBank eb
  204. LEFT JOIN externalBankBranch ebb ON eb.extBankId=ebb.extbankid
  205. WHERE eb.extBankId = LEFT(@param1,LEN(@param1)-1)
  206. AND ebb.branchName LIKE ISNULL(@searchText, '') + '%'
  207. ORDER BY branchName
  208. RETURN
  209. END
  210. END
  211. IF @category = 'agentWiseUser' -- --@author:bibash; Select branch user according to the branch parent
  212. BEGIN
  213. IF @param1 IS NOT NULL AND @param2 IS NULL
  214. BEGIN
  215. SELECT TOP 20
  216. userID,
  217. userName
  218. FROM applicationUsers au WITH(NOLOCK)
  219. INNER JOIN agentMaster am WITH(NOLOCK) ON am.agentId= au.agentId
  220. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  221. AND am.parentId = @param1
  222. AND ISNULL(au.isDeleted,'N' )<> 'Y'
  223. AND ISNULL(au.isActive, 'N') = 'Y'
  224. ORDER BY userName ASC
  225. RETURN
  226. END
  227. ELSE IF @param2 IS NOT NULL AND @param1 IS NULL
  228. BEGIN
  229. SELECT TOP 20
  230. userID,
  231. userName
  232. FROM applicationUsers au WITH(NOLOCK)
  233. INNER JOIN agentMaster am WITH(NOLOCK) ON am.agentId= au.agentId
  234. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  235. AND am.agentCountryId = @param2
  236. AND ISNULL(au.isDeleted,'N' )<> 'Y'
  237. AND ISNULL(au.isActive, 'N') = 'Y'
  238. ORDER BY userName ASC
  239. RETURN
  240. END
  241. ELSE
  242. BEGIN
  243. SELECT TOP 20
  244. userID,
  245. userName
  246. FROM applicationUsers au WITH(NOLOCK)
  247. INNER JOIN agentMaster am WITH(NOLOCK) ON am.agentId= au.agentId
  248. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  249. AND am.parentId = @param1
  250. AND am.agentCountryId = @param2
  251. AND ISNULL(au.isDeleted,'N' )<> 'Y'
  252. AND ISNULL(au.isActive, 'N') = 'Y'
  253. ORDER BY userName ASC
  254. RETURN
  255. END
  256. END
  257. IF @category = 's-r-agent' -- sending / receiving agent according to sending /receiving country
  258. BEGIN
  259. SELECT TOP 20
  260. agentId,
  261. agentName
  262. FROM agentMaster
  263. WHERE agentType = '2903'
  264. AND ISNULL(isDeleted, 'N') <> 'Y'
  265. AND agentName LIKE ISNULL(@searchText, '') + '%'
  266. AND agentCountryId = @param1
  267. ORDER BY agentName ASC
  268. RETURN
  269. END
  270. IF @category = 'agent'
  271. BEGIN
  272. SELECT TOP 20 a.agentId,agentName agentName
  273. FROM
  274. (
  275. SELECT
  276. agentId,
  277. agentName+ISNULL('(' + b.districtName + ')', '') agentName
  278. FROM agentMaster a WITH(NOLOCK)
  279. LEFT JOIN api_districtList b WITH(NOLOCK) ON a.agentLocation = b.districtCode
  280. WHERE
  281. ----(actAsBranch = 'Y' OR agentType = 2904) AND
  282. ISNULL(a.isDeleted, 'N') = 'N'
  283. AND ISNULL(a.isActive, 'N') = 'Y'
  284. AND ISNULL(agentBlock,'U') <>'B'
  285. and a.parentId not IN (1543,5006)
  286. )A WHERE A.agentName LIKE '%'+ ISNULL(@searchText, '') + '%'
  287. ORDER BY A.agentName
  288. RETURN
  289. END
  290. IF @category = 'all-agent'
  291. BEGIN
  292. SELECT TOP 20
  293. agentId,
  294. agentName
  295. FROM agentMaster
  296. WHERE agentName LIKE ISNULL(@searchText, '') + '%'
  297. AND agentCountry = 'Nepal'
  298. AND ISNULL(isDeleted, 'N') = 'N'
  299. AND ISNULL(isActive, 'N') = 'Y'
  300. ORDER BY agentName ASC
  301. RETURN
  302. END
  303. IF @category = 'adminUser'
  304. BEGIN
  305. SELECT TOP 20
  306. userID,
  307. userName
  308. FROM applicationUsers
  309. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  310. AND userType = 'HO'
  311. ORDER BY userName ASC
  312. RETURN
  313. END
  314. IF @category = 'internalBranch' -- --@author:bibash; Select internal branchName
  315. BEGIN
  316. SELECT TOP 20 branch.agentId, branch.agentName FROM agentMaster agent WITH(NOLOCK)
  317. INNER JOIN agentMaster branch WITH(NOLOCK) ON branch.parentId= agent.agentId
  318. WHERE ISNULL(branch.isDeleted, 'N') <> 'Y'
  319. AND branch.agentType = '2904' AND agent.isInternal ='Y'
  320. AND branch.agentName LIKE ISNULL(@searchText, '') + '%'
  321. ORDER BY branch.agentName ASC
  322. RETURN
  323. END
  324. --EXEC proc_autocomplete @category='benBankByCountryName', @searchText='PRIME', @param1='Bangladesh'
  325. IF @category = 'benBankByCountryName' -->> Beneficiary Bank By Country Name
  326. BEGIN
  327. SET @SQL = 'SELECT TOP 20 * FROM
  328. (
  329. SELECT agentId bankId,agentName+'' (Bank)'' BankName
  330. FROM agentMaster WITH(NOLOCK) WHERE agentType=2903 AND agentCountry = '''+@param1+'''
  331. UNION ALL
  332. SELECT extBankId bankId,bankName+'' (Ext. Bank)'' BankName
  333. FROM externalBank WITH(NOLOCK) WHERE country = '''+@param1+'''
  334. AND isnull(internalCode,'''') NOT IN (SELECT agentid FROM agentMaster WITH(NOLOCK) WHERE agentType=2903 AND agentCountry = '''+@param1+''')
  335. )x WHERE BankName LIKE ''%'+@searchText+'%'''
  336. SET @SQL = @SQL+ ' ORDER BY BankName ASC'
  337. PRINT(@SQL);
  338. EXEC(@SQL)
  339. END
  340. IF @category = 'sendAgentByCountryName' -->> Sending Agent By Country Name
  341. BEGIN
  342. SET @SQL = 'SELECT TOP 20 agentId, agentName
  343. FROM agentMaster WITH(NOLOCK)
  344. WHERE agentName LIKE ''%'+@searchText+'%'''
  345. IF @param1 IS NOT NULL
  346. SET @SQL = @SQL + ' AND agentCountry = '''+@param1+''''
  347. SET @SQL = @SQL+ ' ORDER BY agentName ASC'
  348. EXEC(@SQL)
  349. END
  350. IF @category = 'value' -- Select Values of ColumnName Accroding to TableName
  351. BEGIN
  352. SET @SQL = 'SELECT TOP 20 ' +@param2+ ' id, ' +@param2+ ' FROM ' + @param1 + ' WITH(NOLOCK) WHERE ' +@param2+' LIKE '''+@searchText+'%'' ORDER BY ''' + @param2 +''' ASC'
  353. PRINT @SQL
  354. EXEC (@SQL)
  355. RETURN
  356. END
  357. IF @category = 'allBranch' --@author:bibash; Select all branch name
  358. BEGIN
  359. SELECT TOP 20 branch.agentId, branch.agentName FROM agentMaster agent WITH(NOLOCK)
  360. INNER JOIN agentMaster branch WITH(NOLOCK) ON branch.parentId= agent.agentId
  361. WHERE ISNULL(branch.isDeleted, 'N') <> 'Y'
  362. AND branch.agentType = '2904'
  363. AND branch.agentName LIKE ISNULL(@searchText, '') + '%'
  364. ORDER BY branch.agentName ASC
  365. RETURN
  366. END
  367. IF @category = 'pbranchByAgent' -- Select branchName List According to AgentName By pralhad
  368. BEGIN
  369. DECLARE @branchSelection VARCHAR(50)
  370. SELECT @branchSelection=ISNULL(branchSelection,'A') FROM receiveTranLimit WHERE agentId = @param1
  371. SELECT TOP 20
  372. agentId [serviceTypeId],
  373. agentName [typeTitle],@branchSelection [branchSelection]
  374. FROM agentMaster am WITH(NOLOCK)
  375. WHERE ISNULL(am.isDeleted, 'N') <> 'Y'
  376. AND am.agentType = '2904'
  377. AND am.parentId = @param1
  378. AND agentName LIKE @searchText+'%'
  379. ORDER BY agentName ASC
  380. RETURN
  381. END
  382. IF @category = 'internalAgentByExtBankId' -->> Selecting Agent by External Bank Id
  383. BEGIN
  384. DECLARE @countryId INT,@countryName AS VARCHAR(200)
  385. SELECT @countryName = country FROM externalBank WITH(NOLOCK) WHERE extBankId=@param1
  386. SELECT @countryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName=@countryName
  387. SELECT a.agentId,a.agentName FROM agentMaster a WITH(NOLOCK) INNER JOIN
  388. (
  389. SELECT agentId FROM receiveTranLimit WITH(NOLOCK) WHERE countryId=ISNULL(@countryId,countryId) AND tranType='3'
  390. )b ON a.agentId=b.agentId
  391. WHERE ISNULL(a.isDeleted, 'N') <> 'Y'
  392. AND a.agentName LIKE ISNULL(@searchText, '') + '%'
  393. RETURN
  394. END
  395. IF @category = 'agent-a'
  396. BEGIN
  397. SELECT TOP 20
  398. am.agentId
  399. ,am.agentName
  400. ,am.agentLocation
  401. ,am.agentCountry
  402. ,COALESCE(am.agentMobile1, am.agentMobile2, am.agentPhone1, am.agentPhone2) Phone
  403. ,pa.agentName parentName
  404. FROM agentMaster am WITH(NOLOCK)
  405. LEFT JOIN agentMaster pa WITH(NOLOCK) ON am.parentId = pa.agentId
  406. WHERE am.agentId = @searchText
  407. RETURN
  408. END
  409. IF @category='allBank'
  410. BEGIN
  411. SELECT TOP 20
  412. bankId = extBankId,
  413. bankName
  414. FROM externalBank
  415. WHERE internalCode IS NOT NULL
  416. RETURN
  417. END
  418. IF @category='ime-private-agent'
  419. BEGIN
  420. --SELECT TOP 20 a.agentId,agentName+'|'+CAST(agentId AS VARCHAR) agentName
  421. --FROM
  422. --(
  423. -- SELECT agentId,agentName+' '+b.districtName agentName
  424. -- FROM agentMaster a WITH(NOLOCK)
  425. -- LEFT JOIN api_districtList b WITH(NOLOCK) ON a.agentLocation=b.districtCode
  426. -- WHERE actAsBranch = 'Y'
  427. -- AND agentType = 2903
  428. -- AND ISNULL(a.isDeleted, 'N') = 'N'
  429. -- --AND ISNULL(a.isActive, 'N') = 'Y'
  430. -- OR (agentType = 2904 and parentId = 4618)
  431. -- OR (agentType = 2904 and parentId = 21107)
  432. -- OR (agentType = 2904 and parentId = 22194)
  433. -- OR a.agentId = 1194
  434. -- --OR (a.agentId = 20653)
  435. -- OR (agentType = 2904)
  436. --)A WHERE A.agentName LIKE '%'+@searchText+'%' ORDER BY A.agentName
  437. SELECT TOP 20 a.agentId,agentName+'|'+CAST(agentId AS VARCHAR) agentName
  438. FROM
  439. (
  440. SELECT agentId,agentName+' '+b.districtName agentName
  441. FROM agentMaster a WITH(NOLOCK)
  442. LEFT JOIN api_districtList b WITH(NOLOCK) ON a.agentLocation=b.districtCode
  443. WHERE
  444. agentGrp <> '4301'
  445. AND ISNULL(a.isDeleted, 'N') = 'N'
  446. AND (
  447. (agentType = 2903 AND actAsBranch = 'Y')
  448. OR agentType = 2904
  449. )
  450. )A WHERE A.agentName LIKE '%'+@searchText+'%' ORDER BY A.agentName
  451. END
  452. IF @category='domestic-agent'
  453. BEGIN
  454. SELECT TOP 20 a.agentId,agentName+'|'+CAST(agentId AS VARCHAR) agentName
  455. FROM
  456. (
  457. SELECT agentId,agentName+' '+b.districtName agentName
  458. FROM agentMaster a WITH(NOLOCK) LEFT JOIN api_districtList b WITH(NOLOCK)
  459. ON a.agentLocation=b.districtCode
  460. WHERE agentType = 2903
  461. AND ISNULL(a.isDeleted, 'N') = 'N'
  462. AND ISNULL(a.isActive, 'N') = 'Y'
  463. )A WHERE A.agentName LIKE '%'+@searchText+'%' ORDER BY A.agentName
  464. END
  465. IF @category='CountryAgentLogin'
  466. BEGIN
  467. SELECT TOP 20
  468. agentId,
  469. agentName
  470. FROM agentMaster
  471. WHERE agentName LIKE ISNULL(@searchText, '') + '%'
  472. AND agentCountryId = @param1
  473. AND ISNULL(isDeleted, 'N') = 'N'
  474. AND ISNULL(isActive, 'N') = 'Y'
  475. ORDER BY agentName ASC
  476. RETURN
  477. END
  478. IF @category='CountryAgentTxn'
  479. BEGIN
  480. SELECT TOP 20
  481. agentId,
  482. agentName
  483. FROM agentMaster
  484. WHERE agentName LIKE ISNULL(@searchText, '') + '%'
  485. AND agentCountry = @param1
  486. AND ISNULL(isDeleted, 'N') = 'N'
  487. AND ISNULL(isActive, 'N') = 'Y'
  488. ORDER BY agentName ASC
  489. RETURN
  490. END
  491. IF @category='AgentUser'
  492. BEGIN
  493. SELECT TOP 20
  494. userId,
  495. userName
  496. FROM applicationUsers
  497. WHERE userName LIKE ISNULL(@searchText, '') + '%'
  498. AND agentId = @param1
  499. AND ISNULL(isDeleted, 'N') = 'N'
  500. AND ISNULL(isActive, 'N') = 'Y'
  501. ORDER BY userName ASC
  502. RETURN
  503. END
  504. -------->>>>For transaction Analysis Report--------->>>>
  505. IF @category='zoneRpt'
  506. BEGIN
  507. SELECT top 20
  508. stateId
  509. ,stateName
  510. FROM countryStateMaster a WITH(NOLOCK)
  511. inner join countryMaster b with(nolock) on a.countryId=b.countryId
  512. WHERE (b.countryName = @param1 or b.countryId=@param1)
  513. AND stateName like '%'+@searchText+'%'
  514. AND ISNULL(A.isDeleted, 'N') <> 'Y'
  515. ORDER BY stateName
  516. RETURN
  517. END
  518. IF @category='districtRpt'
  519. BEGIN
  520. SELECT top 20
  521. districtId
  522. ,districtName
  523. FROM zoneDistrictMap WITH(NOLOCK)
  524. WHERE zone = isnull(@param1,zone)
  525. AND ISNULL(isDeleted, 'N') <> 'Y'
  526. AND districtName like '%'+@searchText+'%'
  527. ORDER BY districtName
  528. RETURN
  529. END
  530. IF @category='locationRpt'
  531. BEGIN
  532. SELECT DISTINCT top 20
  533. locationId = districtCode
  534. ,locationName = districtName
  535. FROM api_districtList adl WITH(NOLOCK)
  536. LEFT JOIN apiLocationMapping alm WITH(NOLOCK) ON adl.districtCode = alm.apiDistrictCode
  537. WHERE ISNULL(isDeleted, 'N') = 'N'
  538. AND ISNULL(adl.isActive,'Y')='Y'
  539. AND alm.districtId = ISNULL(@param1, alm.districtId)
  540. AND districtName like '%'+@searchText+'%'
  541. ORDER BY districtName
  542. RETURN
  543. END
  544. IF @category='agentRpt'
  545. BEGIN
  546. SELECT top 20
  547. agentId
  548. ,agentName
  549. FROM agentMaster with(nolock)
  550. WHERE agentType = 2903
  551. AND agentCountry='Nepal'
  552. AND ISNULL(isDeleted, 'N') <> 'Y'
  553. --AND ISNULL(isActive, 'N') = 'Y'
  554. AND ISNULL(agentBlock,'U') <>'B'
  555. AND agentName like '%'+@searchText+'%'
  556. AND agentGrp = isnull(@param1,agentGrp)
  557. ORDER BY agentName
  558. RETURN
  559. END
  560. IF @category='agentdistRpt'
  561. BEGIN
  562. SELECT top 20
  563. agentId
  564. ,agentName
  565. FROM agentMaster with(nolock)
  566. WHERE agentType = 2903
  567. AND agentCountry='Nepal'
  568. AND ISNULL(isDeleted, 'N') <> 'Y'
  569. --AND ISNULL(isActive, 'N') = 'Y'
  570. AND ISNULL(agentBlock,'U') <>'B'
  571. AND agentName like '%'+@searchText+'%'
  572. AND agentDistrict = isnull(@param1,agentDistrict)
  573. ORDER BY agentName
  574. RETURN
  575. END
  576. IF @category='branchRpt'
  577. BEGIN
  578. select top 20
  579. agentId
  580. ,agentName
  581. from agentMaster with (nolock)
  582. where parentId = @param1
  583. AND agentName LIKE '%'+@searchText+'%'
  584. AND ISNULL(agentBlock,'U') <>'B'
  585. RETURN
  586. END
  587. IF @category='countryRptInt'
  588. BEGIN
  589. select top 20
  590. countryId
  591. ,countryName
  592. from countryMaster with(nolock) where countryName like '%'+@searchText+'%'
  593. RETURN
  594. END
  595. IF @category='agentRptInt'
  596. BEGIN
  597. SELECT top 20
  598. agentId
  599. ,agentName
  600. FROM agentMaster
  601. WHERE ISNULL(isSettlingAgent, 'N') = 'Y'
  602. AND ISNULL(isDeleted, 'N') <> 'Y'
  603. --AND ISNULL(isActive, 'N') = 'Y'
  604. AND ISNULL(agentBlock,'U') <>'B'
  605. AND agentName like '%'+@searchText+'%'
  606. AND (agentCountry <> 'Nepal' or agentId = 4734)
  607. AND agentCountryId = isnull(@param1,agentCountryId)
  608. ORDER BY agentName
  609. RETURN
  610. END
  611. IF @category='branchRptInt'
  612. BEGIN
  613. select top 20
  614. agentId
  615. ,agentName
  616. from agentMaster with (nolock)
  617. where parentId=@param1
  618. AND agentName LIKE '%'+@searchText+'%'
  619. AND parentId = @param1
  620. --AND ISNULL(isDeleted, 'N') <> 'Y'
  621. AND ISNULL(isActive, 'N') = 'Y'
  622. AND ISNULL(agentBlock,'U') <>'B'
  623. RETURN
  624. END
  625. IF @category='send-agent'
  626. BEGIN
  627. SELECT TOP 20 map_code,agent_name
  628. FROM FastMoneyPro_account.dbo.agentTable with(nolock)
  629. WHERE agent_status<>'n' AND AGENT_TYPE='receiving'
  630. AND (IsMainAgent ='y' OR ISNULL(central_sett,'n') ='n')
  631. AND agent_name like '%'+@searchText+'%'
  632. ORDER BY agent_name
  633. RETURN
  634. END
  635. IF @category = 'agentSummBal' -->>Agent summary Balance Rpt Ddl
  636. BEGIN
  637. SELECT TOP 20
  638. mapcodeInt
  639. ,agentName
  640. FROM agentMaster am WITH(NOLOCK)
  641. where agentName like '%'+@searchText+'%'
  642. and mapcodeInt is not null
  643. AND ISNULL(agentBlock,'U') <>'B'
  644. order by agentName asc
  645. RETURN
  646. END
  647. IF @category = 'd-agentname-only'
  648. BEGIN
  649. SELECT TOP 20
  650. agentName
  651. FROM agentMaster a WITH(NOLOCK)
  652. WHERE agentCountry = 'Nepal'
  653. AND (actAsBranch = 'Y' OR agentType = 2904)
  654. AND ISNULL(a.isDeleted, 'N') = 'N'
  655. --AND ISNULL(a.isActive, 'N') = 'Y'
  656. AND ISNULL(agentBlock,'U') <>'B'
  657. AND A.agentName LIKE '%'+@searchText+'%'
  658. ORDER BY A.agentName
  659. END
  660. IF @category = 'd-agent-only'
  661. BEGIN
  662. SELECT TOP 20 a.agentId,agentName
  663. FROM
  664. (
  665. SELECT agentId,agentName+' '+b.districtName agentName
  666. FROM agentMaster a WITH(NOLOCK)
  667. LEFT JOIN api_districtList b WITH(NOLOCK) ON a.agentLocation=b.districtCode
  668. WHERE agentCountry = 'Nepal'
  669. AND (actAsBranch = 'Y' OR agentType = 2904)
  670. AND ISNULL(a.isDeleted, 'N') = 'N'
  671. --AND ISNULL(a.isActive, 'N') = 'Y'
  672. AND ISNULL(agentBlock,'U') <>'B'
  673. )A WHERE A.agentName LIKE '%'+@searchText+'%' ORDER BY A.agentName
  674. END
  675. ---->>>>>For Customer report
  676. IF @category='sAgent'
  677. BEGIN
  678. SELECT top 20
  679. agentId
  680. ,agentName
  681. FROM agentMaster with(nolock)
  682. WHERE agentType = 2903
  683. AND agentCountry='Nepal'
  684. AND ISNULL(isDeleted, 'N') <> 'Y'
  685. --AND ISNULL(isActive, 'N') = 'Y'
  686. AND ISNULL(agentBlock,'U') <>'B'
  687. AND agentName like '%'+@searchText+'%'
  688. AND agentState =isnull(@param1,agentState)
  689. ORDER BY agentName
  690. RETURN
  691. END
  692. IF @category = 'sZone'
  693. BEGIN
  694. SELECT top 20
  695. stateId
  696. ,stateName
  697. FROM countryStateMaster a WITH(NOLOCK)
  698. inner join countryMaster b with(nolock) on a.countryId=b.countryId
  699. WHERE (b.countryName = 'Nepal' or b.countryId=151)
  700. AND ISNULL(A.isDeleted, 'N') <> 'Y'
  701. AND stateName like '%'+@searchText+'%'
  702. ORDER BY stateName
  703. END
  704. IF @category='send-agent-regional'
  705. BEGIN
  706. SELECT TOP 20 map_code,agent_name
  707. FROM FastMoneyPro_account.dbo.agentTable at with(nolock)
  708. INNER JOIN userZoneMapping zp WITH(NOLOCK) ON at.agentZone = zp.zoneName
  709. WHERE agent_status<>'n'
  710. AND AGENT_TYPE='receiving'
  711. AND (IsMainAgent ='y' OR ISNULL(central_sett,'n') ='n')
  712. AND zp.userName = @param1
  713. AND agent_name like '%'+@searchText+'%'
  714. and zp.isDeleted IS null
  715. ORDER BY agent_name
  716. RETURN
  717. END
  718. -- ## regional transaction analysis report
  719. IF @category='zone-r-rpt'
  720. BEGIN
  721. SELECT TOP 20
  722. stateId
  723. ,stateName
  724. FROM countryStateMaster a WITH(NOLOCK)
  725. inner join countryMaster b with(nolock) on a.countryId=b.countryId
  726. inner JOIN dbo.userZoneMapping zm WITH(nolock) ON a.stateName = zm.zoneName
  727. WHERE (b.countryName = @param1 or b.countryId=@param1)
  728. AND stateName like '%'+@searchText+'%'
  729. AND ISNULL(A.isDeleted, 'N') <> 'Y'
  730. AND zm.userName = @param2
  731. AND zm.isDeleted IS null
  732. ORDER BY stateName
  733. RETURN
  734. END
  735. IF @category='district-r-rpt'
  736. BEGIN
  737. SELECT top 20
  738. districtId
  739. ,districtName
  740. FROM zoneDistrictMap d WITH(NOLOCK)
  741. INNER JOIN countryStateMaster z WITH(NOLOCK) ON d.zone = z.stateId
  742. INner JOIN dbo.userZoneMapping zm WITH(NOLOCK) ON z.stateName = zm.zoneName
  743. WHERE d.zone = isnull(@param1,d.zone)
  744. AND ISNULL(d.isDeleted, 'N') <> 'Y'
  745. AND d.districtName like '%'+@searchText+'%'
  746. AND zm.userName = @param2
  747. AND zm.isDeleted IS NULL
  748. ORDER BY districtName
  749. RETURN
  750. END
  751. IF @category='location-r-rpt'
  752. BEGIN
  753. SELECT DISTINCT
  754. locationId = adl.districtCode
  755. ,locationName = adl.districtName
  756. FROM api_districtList adl WITH(NOLOCK)
  757. LEFT JOIN apiLocationMapping alm WITH(NOLOCK) ON adl.districtCode = alm.apiDistrictCode
  758. LEFT JOIN zoneDistrictMap d WITH(NOLOCK) ON alm.districtId = d.districtId
  759. LEFT JOIN countryStateMaster z WITH(NOLOCK) ON d.zone = z.stateId
  760. LEFT JOIN dbo.userZoneMapping zm WITH(NOLOCK) ON z.stateName = zm.zoneName
  761. WHERE ISNULL(adl.isDeleted, 'N') = 'N'
  762. AND ISNULL(adl.isActive,'Y')='Y'
  763. AND alm.districtId = ISNULL(@param1, alm.districtId)
  764. AND adl.districtName like '%'+@searchText+'%'
  765. AND zm.userName = @param2
  766. AND zm.isDeleted IS NULL
  767. ORDER BY adl.districtName
  768. RETURN
  769. END
  770. IF @category='agent-r-rpt'
  771. BEGIN
  772. SELECT top 20
  773. agentId
  774. ,agentName
  775. FROM agentMaster am with(nolock)
  776. INNER JOIN dbo.userZoneMapping zm WITH(NOLOCK) ON am.agentState = zm.zoneName
  777. WHERE agentType = 2903
  778. AND agentCountry='Nepal'
  779. AND ISNULL(am.isDeleted, 'N') <> 'Y'
  780. AND ISNULL(agentBlock,'U') <>'B'
  781. AND agentName like '%'+@searchText+'%'
  782. AND agentLocation = isnull(@param1,agentLocation)
  783. and zm.userName = @param2
  784. AND zm.isDeleted IS NULL
  785. ORDER BY agentName
  786. RETURN
  787. END
  788. IF @category='branch-r-rpt'
  789. BEGIN
  790. select top 20
  791. agentId
  792. ,agentName
  793. from agentMaster am with (nolock)
  794. INNER JOIN dbo.userZoneMapping zm WITH(NOLOCK) ON am.agentState = zm.zoneName
  795. where am.parentId = @param1
  796. and am.agentName like '%'+@searchText+'%'
  797. AND ISNULL(am.isDeleted, 'N') <> 'Y'
  798. AND ISNULL(agentBlock,'U') <>'B'
  799. and zm.userName = @param2
  800. AND zm.isDeleted IS null
  801. RETURN
  802. END
  803. IF @category='ext-bank'
  804. BEGIN
  805. SELECT TOP 20
  806. bankId = extBankId,
  807. bankName
  808. FROM externalBank ext
  809. WHERE ext.internalCode IS NOT NULL
  810. AND ISNULL(ext.isBlocked,'N') <> 'Y'
  811. AND ISNULL(ext.isDeleted,'N') <> 'Y'
  812. AND ext.bankName like '%'+@searchText+'%'
  813. RETURN
  814. END
  815. IF @category='agent-sett'
  816. BEGIN
  817. SELECT TOP 20 am.agentId,am.agentName
  818. FROM agentMaster am WITH(NOLOCK)
  819. WHERE ISNULL(am.isDeleted, 'N') <> 'Y'
  820. AND ISNULL(am.isActive, 'N') = 'Y'
  821. AND agentName like '%'+@searchText+'%'
  822. and agentType IN (2903)
  823. AND agentCountry = 'Nepal'
  824. ORDER BY agentName
  825. RETURN
  826. END
  827. IF @category='agentList'
  828. BEGIN
  829. select top 20
  830. agentId
  831. ,agentName
  832. from agentMaster am with (nolock)
  833. where agentName like '%'+@searchText+'%'
  834. --AND (agentType = '2904' OR (agentType = 2903 AND actAsBranch = 'Y'))
  835. RETURN
  836. END
  837. IF @category='zoneagendistrictRpt'
  838. BEGIN
  839. IF @param1 is not null and @param2 is null
  840. BEGIN
  841. SELECT top 20
  842. agentId
  843. ,agentName
  844. FROM agentMaster with(nolock)
  845. WHERE (agentType = '2904' OR (agentType = 2903 AND actAsBranch = 'Y'))
  846. AND agentCountry='Nepal'
  847. AND ISNULL(isDeleted, 'N') <> 'Y'
  848. --AND ISNULL(isActive, 'N') = 'Y'
  849. AND ISNULL(agentBlock,'U') <>'B'
  850. AND agentName like '%'+@searchText+'%'
  851. AND agentState =isnull(@param1,agentState)
  852. ORDER BY agentName
  853. RETURN
  854. END
  855. IF @param2 is not null and @param1 is null
  856. BEGIN
  857. SELECT top 20
  858. agentId
  859. ,agentName
  860. FROM agentMaster with(nolock)
  861. WHERE (agentType = '2904' OR (agentType = 2903 AND actAsBranch = 'Y'))
  862. AND agentCountry='Nepal'
  863. AND ISNULL(isDeleted, 'N') <> 'Y'
  864. --AND ISNULL(isActive, 'N') = 'Y'
  865. AND ISNULL(agentBlock,'U') <>'B'
  866. AND agentName like '%'+@searchText+'%'
  867. AND agentDistrict =isnull(@param2,agentDistrict)
  868. ORDER BY agentName
  869. RETURN
  870. END
  871. IF @param1 is not null and @param2 is not null
  872. BEGIN
  873. SELECT top 20
  874. agentId
  875. ,agentName
  876. FROM agentMaster with(nolock)
  877. WHERE (agentType = '2904' OR (agentType = 2903 AND actAsBranch = 'Y'))
  878. AND agentCountry='Nepal'
  879. AND ISNULL(isDeleted, 'N') <> 'Y'
  880. --AND ISNULL(isActive, 'N') = 'Y'
  881. AND ISNULL(agentBlock,'U') <>'B'
  882. AND agentName like '%'+@searchText+'%'
  883. AND agentState =isnull(@param1,agentState)
  884. AND agentDistrict =isnull(@param2,agentDistrict)
  885. ORDER BY agentName
  886. RETURN
  887. END
  888. SELECT top 20
  889. agentId
  890. ,agentName
  891. FROM agentMaster with(nolock)
  892. WHERE (agentType = '2904' OR (agentType = 2903 AND actAsBranch = 'Y'))
  893. AND agentCountry='Nepal'
  894. AND ISNULL(isDeleted, 'N') <> 'Y'
  895. --AND ISNULL(isActive, 'N') = 'Y'
  896. AND ISNULL(agentBlock,'U') <>'B'
  897. AND agentName like '%'+@searchText+'%'
  898. ORDER BY agentName
  899. END
  900. IF @category = 'cooperative'
  901. BEGIN
  902. SELECT TOP 20
  903. agentId
  904. ,agentName
  905. ,agentType FROM agentMaster (NOLOCK)
  906. WHERE (agentGrp='8026' OR agentGrp = '9906') AND agentType='2903'
  907. AND ISNULL(isDeleted, 'N') <> 'Y'
  908. AND agentName LIKE '%' + @searchText +'%'
  909. AND agentId<>@param1
  910. ORDER BY agentName ASC
  911. END
  912. IF @category = 'co-agent' -- cooperative branch list
  913. BEGIN
  914. IF EXISTS(select 'x' from agentMaster (NOLOCK) WHERE ISNULL(isDeleted, 'N') <> 'Y' AND parentId=@param1)
  915. BEGIN
  916. SELECT TOP 20
  917. agentId
  918. ,agentName
  919. ,agentType
  920. ,parentId FROM agentMaster (NOLOCK)
  921. WHERE ISNULL(isDeleted, 'N') <> 'Y'
  922. AND parentId=@param1
  923. ORDER BY agentName ASC
  924. RETURN
  925. END
  926. ELSE
  927. BEGIN
  928. SELECT TOP 20
  929. agentId
  930. ,agentName
  931. ,agentType
  932. ,parentId FROM agentMaster (NOLOCK)
  933. WHERE ISNULL(isDeleted, 'N') <> 'Y'
  934. AND agentId=@param1
  935. ORDER BY agentName ASC
  936. RETURN
  937. END
  938. END
  939. IF @category='Reconcil-agent'
  940. BEGIN
  941. SELECT TOP 20
  942. agentId
  943. ,agentName+'|'+CAST(agentId AS VARCHAR)
  944. FROM agentMaster (NOLOCK)
  945. WHERE ISNULL(isDeleted, 'N') <> 'Y'
  946. AND agentName LIKE '%' + @searchText +'%'
  947. ORDER BY agentName ASC
  948. END
  949. ELSE IF @category='agentByGrp'
  950. BEGIN
  951. Select TOP 20 agentId,agentName
  952. from dbo.agentMaster (NOLOCK)
  953. where agentName like @searchText + '%'
  954. AND agentGrp = @param1
  955. order by agentName
  956. END
  957. ELSE IF @category='locationRpt'
  958. BEGIN
  959. SELECT DISTINCT top 20
  960. locationId = districtCode
  961. ,locationName = districtName
  962. FROM api_districtList adl WITH(NOLOCK)
  963. LEFT JOIN apiLocationMapping alm WITH(NOLOCK) ON adl.districtCode = alm.apiDistrictCode
  964. WHERE ISNULL(isDeleted, 'N') = 'N'
  965. AND ISNULL(adl.isActive,'Y')='Y'
  966. AND alm.districtId = ISNULL(@param1, alm.districtId)
  967. AND districtName like '%'+@searchText+'%'
  968. ORDER BY districtName
  969. RETURN
  970. END
  971. ELSE IF @category='cityList'
  972. BEGIN
  973. select cityName,cityName from CityMaster(nolock)
  974. where cityName like '%'+@searchText+'%'
  975. END
  976. ELSE IF @category='CustomerInfo'
  977. BEGIN
  978. if len(@searchText)<2
  979. BEGIN
  980. SELECT TOP 35 idNumber,idNumber +' | ' + fullName + mobile FROM CustomerMaster(NOLOCK) WHERE 1=2
  981. RETURN
  982. END
  983. SELECT TOP 35 idNumber,idNumber +' | '+ fullName +' | ' + mobile FROM CustomerMaster(NOLOCK)
  984. WHERE idNumber like @searchText+'%' or fullName like @searchText+'%' OR mobile like @searchText+'%'
  985. END
  986. ELSE IF @category='CustomerEmail'
  987. BEGIN
  988. if len(@searchText)<2
  989. begin
  990. select top 35 customerId,email +' | '+mobile from CustomerMaster(nolock) where 1=2
  991. return
  992. end
  993. select top 35 customerId,email +' | '+mobile from CustomerMaster(nolock)
  994. where email like @searchText+'%'
  995. END
  996. ELSE IF @category='CustomerInfoWallet'
  997. BEGIN
  998. if len(@searchText)<2
  999. begin
  1000. select top 35 walletAccountNo,walletAccountNo +' | '+fullName from CustomerMaster(nolock) where 1=2
  1001. return
  1002. end
  1003. select top 35 walletAccountNo,walletAccountNo +' | '+fullName from CustomerMaster(nolock)
  1004. where walletAccountNo like @searchText+'%' or fullName like @searchText+'%'
  1005. END
  1006. GO