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.

696 lines
19 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_message] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_message]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_message] 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_message]
  12. @flag VARCHAR(50) = NULL
  13. ,@user VARCHAR(30) = NULL
  14. ,@msgId VARCHAR(30) = NULL
  15. ,@countryId INT = NULL
  16. ,@countryName VARCHAR(200) = NULL
  17. ,@agentId INT = NULL
  18. ,@branchId INT = NULL
  19. ,@agentName VARCHAR(200) = NULL
  20. ,@branchName VARCHAR(200) = NULL
  21. ,@headMsg NVARCHAR(MAX) = NULL
  22. ,@commonMsg NVARCHAR(MAX) = NULL
  23. ,@countrySpecificMsg NVARCHAR(MAX) = NULL
  24. ,@promotionalMsg NVARCHAR(MAX) = NULL
  25. ,@newsFeederMsg NVARCHAR(MAX) = NULL
  26. ,@isActive VARCHAR(10) = NULL
  27. ,@msgType CHAR(1) = NULL
  28. ,@sortBy VARCHAR(50) = NULL
  29. ,@sortOrder VARCHAR(5) = NULL
  30. ,@pageSize INT = NULL
  31. ,@pageNumber INT = NULL
  32. ,@transactionType varchar(10) = NULL
  33. ,@userType VARCHAR(2) = NULL
  34. ,@rCountry VARCHAR(50) = NULL
  35. ,@rAgent VARCHAR(100) = NULL
  36. AS
  37. SET NOCOUNT ON
  38. SET XACT_ABORT ON
  39. BEGIN TRY
  40. CREATE TABLE #msg(errorCode INT, msg VARCHAR(100), id INT)
  41. DECLARE
  42. @sql VARCHAR(MAX)
  43. ,@oldValue VARCHAR(MAX)
  44. ,@newValue VARCHAR(MAX)
  45. ,@module VARCHAR(10)
  46. ,@tableAlias VARCHAR(100)
  47. ,@logIdentifier VARCHAR(50)
  48. ,@logParamMod VARCHAR(100)
  49. ,@logParamMain VARCHAR(100)
  50. ,@table VARCHAR(MAX)
  51. ,@select_field_list VARCHAR(MAX)
  52. ,@extra_field_list VARCHAR(MAX)
  53. ,@sql_filter VARCHAR(MAX)
  54. ,@modType VARCHAR(6)
  55. SELECT
  56. @logIdentifier = 'msgId'
  57. ,@logParamMain = 'message'
  58. ,@logParamMod = 'messageMod'
  59. ,@module = '10'
  60. ,@tableAlias = 'Message Setup'
  61. IF @flag = 'ml' --Message list for agent/admin user
  62. BEGIN
  63. /*
  64. --SELECT * FROM [message]
  65. --SELECT commonMsg [Message] FROM message
  66. -- WHERE commonMsg IS NOT NULL AND (userType = @userType OR userType IS NULL)
  67. -- AND ISNULL(isActive, 'Active') = 'Active'
  68. --UNION ALL
  69. --SELECT countrySpecificMsg FROM message WHERE countrySpecificMsg IS NOT NULL AND countryId = @countryId AND (userType = @userType OR userType IS NULL)
  70. --UNION ALL
  71. if exists(select 'x' from
  72. (
  73. SELECT 'x' a FROM message
  74. WHERE newsFeederMsg IS NOT NULL AND (countryId = @countryId AND agentId is null)
  75. AND ISNULL(isActive, 'Active') = 'Active' AND ISNULL(isDeleted,'')<>'Y'
  76. UNION ALL
  77. SELECT 'x' a FROM message
  78. WHERE newsFeederMsg IS NOT NULL AND
  79. agentId in (select parentId from agentMaster where agentId = @agentId)
  80. AND ISNULL(isActive, 'Active') = 'Active' AND ISNULL(isDeleted,'')<>'Y'
  81. )s)
  82. begin
  83. SELECT newsFeederMsg FROM message
  84. WHERE newsFeederMsg IS NOT NULL AND (countryId = @countryId AND agentId is null)
  85. AND ISNULL(isActive, 'Active') = 'Active' AND ISNULL(isDeleted,'')<>'Y'
  86. UNION ALL
  87. SELECT newsFeederMsg FROM message
  88. WHERE newsFeederMsg IS NOT NULL AND
  89. agentId in (select parentId from agentMaster where agentId = @agentId)
  90. AND ISNULL(isActive, 'Active') = 'Active' AND ISNULL(isDeleted,'')<>'Y'
  91. return;
  92. end
  93. SELECT commonMsg FROM message
  94. WHERE commonMsg IS NOT NULL
  95. AND countryId = @countryId
  96. AND ISNULL(isActive, 'Active') = 'Active'
  97. AND ISNULL(isDeleted,'')<>'Y'
  98. UNION ALL
  99. SELECT commonMsg FROM message
  100. WHERE commonMsg IS NOT NULL
  101. AND countryId is null
  102. AND ISNULL(isActive, 'Active') = 'Active'
  103. AND ISNULL(isDeleted,'')<>'Y'
  104. RETURN
  105. SELECT newsFeederMsg FROM message
  106. WHERE newsFeederMsg IS NOT NULL AND (countryId = @countryId AND agentId is null)
  107. AND ISNULL(isActive, 'Active') = 'Active' AND ISNULL(isDeleted,'')<>'Y'
  108. UNION ALL
  109. SELECT newsFeederMsg FROM message
  110. WHERE newsFeederMsg IS NOT NULL AND
  111. agentId in (select parentId from agentMaster where agentId = @agentId)
  112. AND ISNULL(isActive, 'Active') = 'Active' AND ISNULL(isDeleted,'')<>'Y'
  113. */
  114. -->> News for all
  115. DECLARE @agentNature AS VARCHAR(50) = null
  116. if @agentId is not null
  117. SELECT @agentNature = agentRole FROM agentMaster with(nolock) where agentId = @agentId
  118. -->> all
  119. select newsFeederMsg from [message] WITH(NOLOCK)
  120. where newsFeederMsg is not null
  121. and countryId is null
  122. and agentId is null
  123. and (msgType ='B' or msgType = @agentNature)
  124. and ISNULL(isDeleted,'N') = 'N'
  125. and isnull(isActive,'Active') = 'Active'
  126. union all
  127. -->> country specific
  128. select newsFeederMsg from [message] WITH(NOLOCK)
  129. where newsFeederMsg is not null
  130. and countryId = @countryId
  131. and agentId is null
  132. and (msgType = 'B' or msgType = @agentNature)
  133. and ISNULL(isDeleted,'N') = 'N'
  134. and isnull(isActive,'Active') = 'Active'
  135. union all
  136. -->> country & agent specific
  137. select newsFeederMsg from [message] WITH(NOLOCK)
  138. where newsFeederMsg is not null
  139. and countryId = @countryId
  140. and agentId = @agentId
  141. and (msgType = 'B' or msgType = @agentNature)
  142. and ISNULL(isDeleted,'N') = 'N'
  143. and isnull(isActive,'Active') = 'Active'
  144. END
  145. IF @flag IN ('i', 'u', 'd')
  146. BEGIN
  147. IF @flag IN ('d')
  148. BEGIN
  149. SELECT @headMsg = headMsg
  150. , @commonMsg = commonMsg
  151. , @countrySpecificMsg = countrySpecificMsg
  152. , @promotionalMsg = promotionalMsg
  153. , @newsFeederMsg = newsFeederMsg
  154. FROM message WITH(NOLOCK) WHERE msgId = @msgId
  155. END
  156. IF @headMsg IS NOT NULL
  157. SET @tableAlias = 'Head Message'
  158. ELSE IF @commonMsg IS NOT NULL
  159. SET @tableAlias = 'Common Message'
  160. ELSE IF @promotionalMsg IS NOT NULL
  161. SET @tableAlias = 'Promotional Message'
  162. ELSE IF @countrySpecificMsg IS NOT NULL
  163. SET @tableAlias = 'Country Specific Message'
  164. ELSE IF @newsFeederMsg IS NOT NULL
  165. SET @tableAlias = 'News Feeder Message'
  166. END
  167. IF @flag = 'i'
  168. BEGIN
  169. --IF EXISTS(SELECT 'X' FROM message WHERE countryId = @countryId AND commonMsg IS NOT NULL AND @msgType IS NULL AND @commonMsg IS NOT NULL)
  170. --BEGIN
  171. -- EXEC proc_errorHandler 1, 'Message Setup already done for this country', @msgId
  172. -- RETURN
  173. --END
  174. --IF EXISTS(SELECT 'X' FROM message WHERE countryId = @countryId AND msgType = @msgType AND countrySpecificMsg IS NOT NULL AND @countrySpecificMsg IS NOT NULL)
  175. --BEGIN
  176. -- EXEC proc_errorHandler 1, 'Message Setup already done for this country and message type', @msgId
  177. -- RETURN
  178. --END
  179. --IF EXISTS(SELECT 'X' FROM message WHERE agentId = @agentId AND msgType = @msgType AND promotionalMsg IS NOT NULL AND @promotionalMsg IS NOT NULL)
  180. --BEGIN
  181. -- EXEC proc_errorHandler 1, 'Message Setup already done for this agent and message type', @msgId
  182. -- RETURN
  183. --END
  184. IF EXISTS(
  185. SELECT 'X' FROM message WHERE msgType = @msgType
  186. AND ISNULL(countryId, 0) = ISNULL(@countryId, ISNULL(countryId, 0))
  187. AND ISNULL(agentId, 0) = ISNULL(@agentId, ISNULL(agentId, 0))
  188. AND rCountry = @rCountry
  189. AND ISNULL(rAgent, '') = ISNULL(@rAgent, ISNULL(rAgent, ''))
  190. AND ISNULL(transactionType, '') = ISNULL(@transactionType, ISNULL(transactionType, ''))
  191. AND ISNULL(isDeleted, 'N') = 'N'
  192. )
  193. BEGIN
  194. EXEC proc_errorHandler 1, 'Message Setup already done', @msgId
  195. RETURN
  196. END
  197. BEGIN TRANSACTION
  198. INSERT INTO [message] (
  199. countryId
  200. ,agentId
  201. ,headMsg
  202. ,commonMsg
  203. ,countrySpecificMsg
  204. ,promotionalMsg
  205. ,newsFeederMsg
  206. ,isActive
  207. ,msgType
  208. ,createdBy
  209. ,createdDate
  210. ,userType
  211. ,transactionType
  212. ,rCountry
  213. ,rAgent
  214. ,branchId
  215. )
  216. SELECT
  217. @countryId
  218. ,@agentId
  219. ,@headMsg
  220. ,@commonMsg
  221. ,@countrySpecificMsg
  222. ,@promotionalMsg
  223. ,@newsFeederMsg
  224. ,@isActive
  225. ,@msgType
  226. ,@user
  227. ,GETDATE()
  228. ,@userType
  229. ,@transactionType
  230. ,@rCountry
  231. ,@rAgent
  232. ,@branchId
  233. SET @msgId = SCOPE_IDENTITY()
  234. SET @modType = 'Insert'
  235. EXEC [dbo].proc_GetColumnToRow @logParamMain, @logIdentifier, @msgId , @newValue OUTPUT
  236. INSERT INTO #msg(errorCode, msg, id)
  237. EXEC proc_applicationLogs 'i', NULL, @modType, @tableAlias, @msgId, @user, @oldValue, @newValue
  238. IF EXISTS (SELECT 'x' FROM #msg WHERE errorCode <> '0')
  239. BEGIN
  240. IF @@TRANCOUNT > 0
  241. ROLLBACK TRANSACTION
  242. EXEC proc_errorHandler 1, 'Failed to add new record.', @msgId
  243. RETURN
  244. END
  245. IF @@TRANCOUNT > 0
  246. COMMIT TRANSACTION
  247. EXEC proc_errorHandler 0, 'Record has been added successfully.', @msgId
  248. END
  249. ELSE IF @flag = 'a'
  250. BEGIN
  251. SELECT * FROM message WITH(NOLOCK) WHERE msgId = @msgId
  252. END
  253. ELSE IF @flag = 'populateAgent'
  254. BEGIN
  255. SELECT agentId,agentName
  256. FROM agentMaster WITH(NOLOCK) WHERE agentRole = @msgType and isnull(isDeleted,'N')<>'Y'
  257. ORDER BY agentName
  258. END
  259. ELSE IF @flag = 'u'
  260. BEGIN
  261. IF EXISTS(
  262. SELECT 'X' FROM message WHERE msgType = @msgType
  263. AND ISNULL(countryId, 0) = ISNULL(@countryId, ISNULL(countryId, 0))
  264. AND ISNULL(agentId, 0) = ISNULL(@agentId, ISNULL(agentId, 0))
  265. AND rCountry = @rCountry
  266. AND ISNULL(rAgent, '') = ISNULL(@rAgent, ISNULL(rAgent, ''))
  267. AND ISNULL(transactionType, '') = ISNULL(@transactionType, ISNULL(transactionType, ''))
  268. AND ISNULL(isDeleted, 'N') = 'N' AND msgId <> @msgId
  269. )
  270. BEGIN
  271. EXEC proc_errorHandler 1, 'Message Setup already done', @msgId
  272. RETURN
  273. END
  274. BEGIN TRANSACTION
  275. UPDATE message SET
  276. countryId = @countryId
  277. ,agentId = @agentId
  278. ,headMsg = @headMsg
  279. ,commonMsg = @commonMsg
  280. ,countrySpecificMsg = @countrySpecificMsg
  281. ,promotionalMsg = @promotionalMsg
  282. ,newsFeederMsg = @newsFeederMsg
  283. ,isActive = @isActive
  284. ,msgType = @msgType
  285. ,modifiedBy = @user
  286. ,modifiedDate = GETDATE()
  287. ,userType = @userType
  288. ,transactionType = @transactionType
  289. ,rCountry = @rCountry
  290. ,rAgent = @rAgent
  291. ,branchId = @branchId
  292. WHERE msgId = @msgId
  293. EXEC [dbo].proc_GetColumnToRow @logParamMain, @logIdentifier, @msgId, @newValue OUTPUT
  294. INSERT INTO #msg(errorCode, msg, id)
  295. EXEC proc_applicationLogs 'i', NULL, @modType, @tableAlias, @msgId, @user, @oldValue, @newValue
  296. IF EXISTS (SELECT 'x' FROM #msg WHERE errorCode <> '0')
  297. BEGIN
  298. IF @@TRANCOUNT > 0
  299. ROLLBACK TRANSACTION
  300. EXEC proc_errorHandler 1, 'Failed to update record.', @msgId
  301. RETURN
  302. END
  303. IF @@TRANCOUNT > 0
  304. COMMIT TRANSACTION
  305. EXEC proc_errorHandler 0, 'Record updated successfully.', @msgId
  306. END
  307. ELSE IF @flag = 'd'
  308. BEGIN
  309. BEGIN TRANSACTION
  310. UPDATE message SET
  311. isDeleted = 'Y'
  312. ,modifiedDate = GETDATE()
  313. ,modifiedBy = @user
  314. WHERE msgId = @msgId
  315. SET @modType = 'Delete'
  316. EXEC [dbo].proc_GetColumnToRow @logParamMain, @logIdentifier, @msgId, @oldValue OUTPUT
  317. INSERT INTO #msg(errorCode, msg, id)
  318. EXEC proc_applicationLogs 'i', NULL, @modType, @tableAlias, @msgId, @user, @oldValue, @newValue
  319. IF EXISTS (SELECT 'x' FROM #msg WHERE errorCode <> '0')
  320. BEGIN
  321. IF @@TRANCOUNT > 0
  322. ROLLBACK TRANSACTION
  323. EXEC proc_errorHandler 1, 'Failed to delete record.', @msgId
  324. RETURN
  325. END
  326. IF @@TRANCOUNT > 0
  327. COMMIT TRANSACTION
  328. EXEC proc_errorHandler 0, 'Record deleted successfully.', @msgId
  329. END
  330. ELSE IF @flag IN ('s1') --Common Message
  331. BEGIN
  332. IF @sortBy IS NULL
  333. SET @sortBy = 'msgId'
  334. IF @sortOrder IS NULL
  335. SET @sortOrder = 'ASC'
  336. SET @table = '(
  337. SELECT
  338. main.msgId
  339. ,main.countryId
  340. ,countryName = ISNULL(cm.countryName, ''All'')
  341. ,main.agentId
  342. ,agentName = ISNULL(am.agentName, ''All'')
  343. ,main.headMsg
  344. ,main.commonMsg
  345. ,main.countrySpecificMsg
  346. ,main.promotionalMsg
  347. ,main.newsFeederMsg
  348. ,main.isActive
  349. ,main.msgType
  350. ,main.createdBy
  351. ,main.createdDate
  352. ,main.isDeleted
  353. FROM message main WITH(NOLOCK)
  354. LEFT JOIN countryMaster cm WITH(NOLOCK) ON main.countryId = cm.countryId
  355. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  356. WHERE main.commonMsg IS NOT NULL
  357. ) x'
  358. END
  359. ELSE IF @flag IN ('s2') --countrySpecificMsg
  360. BEGIN
  361. IF @sortBy IS NULL
  362. SET @sortBy = 'msgId'
  363. IF @sortOrder IS NULL
  364. SET @sortOrder = 'ASC'
  365. SET @table = '(
  366. SELECT
  367. main.msgId
  368. ,main.countryId
  369. ,CountryName = CASE WHEN SC.countryName IS NULL THEN ''ALL'' ELSE SC.countryName END
  370. ,rCountry = CASE WHEN RC.countryName IS NULL THEN ''ALL'' ELSE RC.countryName END
  371. ,main.agentId
  372. ,AgentName = CASE WHEN SA.agentName IS NULL THEN ''ALL'' ELSE SA.agentName END
  373. ,rAgent = CASE WHEN RA.agentName IS NULL THEN ''ALL'' ELSE RA.agentName END
  374. ,main.headMsg
  375. ,main.commonMsg
  376. ,main.countrySpecificMsg
  377. ,main.promotionalMsg
  378. ,main.newsFeederMsg
  379. ,main.isActive
  380. ,msgType = CASE WHEN main.msgType = ''S'' THEN ''Send''
  381. WHEN main.msgType = ''R'' THEN ''Receive''
  382. WHEN main.msgType = ''B'' THEN ''Both''
  383. ELSE '''' END
  384. ,main.createdBy
  385. ,main.createdDate
  386. ,main.isDeleted
  387. ,main.branchId
  388. ,branchName = ISNULL(SA.agentName, ''All'')
  389. FROM message main WITH(NOLOCK)
  390. LEFT JOIN countryMaster sc WITH(NOLOCK) ON main.countryId = sc.countryId
  391. LEFT JOIN countryMaster Rc WITH(NOLOCK) ON main.rCountry = RC.countryId
  392. LEFT JOIN agentMaster SA WITH(NOLOCK) ON main.agentId = SA.agentId
  393. LEFT JOIN agentMaster RA WITH(NOLOCK) ON main.rAgent = RA.agentId
  394. WHERE main.countrySpecificMsg IS NOT NULL
  395. ) x'
  396. SET @sql_filter = ''
  397. SET @sql_filter = @sql_filter + ' AND ISNULL(isDeleted, '''') <> ''Y'''
  398. IF @countryName IS NOT NULL
  399. SET @sql_filter = @sql_filter + ' AND countryName LIKE ''%' + @countryName + '%'''
  400. IF @agentName IS NOT NULL
  401. SET @sql_filter = @sql_filter + ' AND agentName LIKE ''%' + @agentName + '%'''
  402. IF @rCountry IS NOT NULL
  403. SET @sql_filter = @sql_filter + ' AND rCountry LIKE ''%' + @rCountry + '%'''
  404. IF @rAgent IS NOT NULL
  405. SET @sql_filter = @sql_filter + ' AND rAgent LIKE ''%' + @rAgent + '%'''
  406. print @table
  407. SET @select_field_list ='
  408. msgId
  409. ,countryId
  410. ,countryName
  411. ,rcountry
  412. ,agentId
  413. ,agentName
  414. , ragent
  415. ,headMsg
  416. ,commonMsg
  417. ,countrySpecificMsg
  418. ,promotionalMsg
  419. ,newsFeederMsg
  420. ,isActive
  421. ,msgType
  422. ,createdBy
  423. ,createdDate
  424. ,isDeleted '
  425. EXEC dbo.proc_paging
  426. @table
  427. ,@sql_filter
  428. ,@select_field_list
  429. ,@extra_field_list
  430. ,@sortBy
  431. ,@sortOrder
  432. ,@pageSize
  433. ,@pageNumber
  434. END
  435. ELSE IF @flag IN ('s3') --promotionalMsg
  436. BEGIN
  437. IF @sortBy IS NULL
  438. SET @sortBy = 'msgId'
  439. IF @sortOrder IS NULL
  440. SET @sortOrder = 'ASC'
  441. SET @table = '(
  442. SELECT
  443. main.msgId
  444. ,main.countryId
  445. ,countryName = cm.countryName
  446. ,main.agentId
  447. ,agentName = am.agentName
  448. ,main.headMsg
  449. ,main.commonMsg
  450. ,main.countrySpecificMsg
  451. ,main.promotionalMsg
  452. ,main.newsFeederMsg
  453. ,main.isActive
  454. ,msgType = CASE WHEN main.msgType = ''S'' THEN ''Send''
  455. WHEN main.msgType = ''R'' THEN ''Receive''
  456. WHEN main.msgType = ''B'' THEN ''Both''
  457. ELSE '''' END
  458. ,main.createdBy
  459. ,main.createdDate
  460. ,main.isDeleted
  461. FROM message main WITH(NOLOCK)
  462. LEFT JOIN countryMaster cm WITH(NOLOCK) ON main.countryId = cm.countryId
  463. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  464. WHERE main.promotionalMsg IS NOT NULL
  465. ) x'
  466. END
  467. ELSE IF @flag IN ('s4') --head msg
  468. BEGIN
  469. IF @sortBy IS NULL
  470. SET @sortBy = 'msgId'
  471. IF @sortOrder IS NULL
  472. SET @sortOrder = 'ASC'
  473. SET @table = '(
  474. SELECT
  475. main.msgId
  476. ,main.countryId
  477. ,countryName = ISNULL(cm.countryName, ''All'')
  478. ,main.agentId
  479. ,agentName = am.agentName
  480. ,main.headMsg
  481. ,main.commonMsg
  482. ,main.countrySpecificMsg
  483. ,main.promotionalMsg
  484. ,main.newsFeederMsg
  485. ,main.isActive
  486. ,main.msgType
  487. ,main.createdBy
  488. ,main.createdDate
  489. ,main.isDeleted
  490. FROM message main WITH(NOLOCK)
  491. LEFT JOIN countryMaster cm WITH(NOLOCK) ON main.countryId = cm.countryId
  492. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  493. WHERE main.headMsg IS NOT NULL
  494. ) x'
  495. END
  496. ELSE IF @flag IN ('s5') --newsfeeder
  497. BEGIN
  498. IF @sortBy IS NULL
  499. SET @sortBy = 'msgId'
  500. IF @sortOrder IS NULL
  501. SET @sortOrder = 'ASC'
  502. SET @table = '(
  503. SELECT
  504. main.msgId
  505. ,main.countryId
  506. ,countryName = ISNULL(cm.countryName, ''All'')
  507. ,main.agentId
  508. ,agentName = ISNULL(am.agentName, ''All'')
  509. ,main.headMsg
  510. ,main.commonMsg
  511. ,main.countrySpecificMsg
  512. ,main.promotionalMsg
  513. ,main.newsFeederMsg
  514. ,main.isActive
  515. ,userType = isnull(sd.detailDesc,''All'')
  516. ,msgType = CASE WHEN main.msgType = ''S'' THEN ''Send''
  517. WHEN main.msgType = ''R'' THEN ''Receive''
  518. WHEN main.msgType = ''B'' THEN ''Both''
  519. ELSE '''' END
  520. ,main.createdBy
  521. ,main.createdDate
  522. ,main.isDeleted
  523. ,main.branchId
  524. ,branchName = ISNULL(am1.agentName, ''All'')
  525. ,isActiveF = case when main.isActive = ''Active'' then ''Y'' when main.isActive = ''Inactive'' then ''N'' else NULL end
  526. ,userTypeF = userType
  527. FROM message main WITH(NOLOCK)
  528. LEFT JOIN countryMaster cm WITH(NOLOCK) ON main.countryId = cm.countryId
  529. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  530. LEFT JOIN staticDatavalue sd ON sd.detailTitle = main.userType
  531. left join agentmaster am1 with(nolock) on main.branchId= am1.agentId
  532. WHERE main.newsFeederMsg IS NOT NULL
  533. ) x'
  534. END
  535. IF @flag IN('s1','s3','s4','s5')
  536. BEGIN
  537. SET @sql_filter = ''
  538. SET @sql_filter = @sql_filter + ' AND ISNULL(isDeleted, '''') <> ''Y'''
  539. IF @countryName IS NOT NULL
  540. SET @sql_filter = @sql_filter + ' AND countryName LIKE ''%' + @countryName + '%'''
  541. IF @agentName IS NOT NULL
  542. SET @sql_filter = @sql_filter + ' AND agentName LIKE ''%' + @agentName + '%'''
  543. IF @flag='s5'
  544. BEGIN
  545. if @branchName is not null or @branchName <> ''
  546. SET @sql_filter = @sql_filter + ' AND branchName LIKE ''%' + @branchName + '%'''
  547. if @userType is not null or @userType <> ''
  548. SET @sql_filter = @sql_filter + ' AND userTypeF = ''' + @userType + ''''
  549. if @isActive is not null or @isActive <> ''
  550. SET @sql_filter = @sql_filter + ' AND isActiveF = ''' + @isActive + ''''
  551. SET @select_field_list ='
  552. msgId
  553. ,countryId
  554. ,countryName
  555. ,agentId
  556. ,agentName
  557. ,headMsg
  558. ,commonMsg
  559. ,countrySpecificMsg
  560. ,promotionalMsg
  561. ,newsFeederMsg
  562. ,isActive
  563. ,userType
  564. ,msgType
  565. ,createdBy
  566. ,createdDate
  567. ,isDeleted
  568. ,branchId
  569. ,branchName '
  570. END
  571. ELSE
  572. BEGIN
  573. SET @select_field_list ='
  574. msgId
  575. ,countryId
  576. ,countryName
  577. ,agentId
  578. ,agentName
  579. ,headMsg
  580. ,commonMsg
  581. ,countrySpecificMsg
  582. ,promotionalMsg
  583. ,newsFeederMsg
  584. ,isActive
  585. ,msgType
  586. ,createdBy
  587. ,createdDate
  588. ,isDeleted '
  589. END
  590. EXEC dbo.proc_paging
  591. @table
  592. ,@sql_filter
  593. ,@select_field_list
  594. ,@extra_field_list
  595. ,@sortBy
  596. ,@sortOrder
  597. ,@pageSize
  598. ,@pageNumber
  599. END
  600. if @flag='userType'
  601. begin
  602. select null VALUE ,'All' [TEXT]
  603. union all
  604. select detailTitle,detailDesc from staticDataValue with(nolock) where typeId=7300
  605. end
  606. END TRY
  607. BEGIN CATCH
  608. IF @@TRANCOUNT > 0
  609. ROLLBACK TRANSACTION
  610. DECLARE @errorMessage VARCHAR(MAX)
  611. SET @errorMessage = ERROR_MESSAGE()
  612. EXEC proc_errorHandler 1, @errorMessage, @msgId
  613. END CATCH
  614. GO