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.

1656 lines
123 KiB

  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_agentMaster] Script Date: 12/6/2023 11:18:25 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. /*
  9. alter table agentMaster add BANKCODE varchar(50),BANKBRANCH varchar(50),BANKACCOUNTNUMBER varchar(50),ACCOUNTHOLDERNAME varchar(50)
  10. alter table agentMasterMod add BANKCODE varchar(50),BANKBRANCH varchar(50),BANKACCOUNTNUMBER varchar(50),ACCOUNTHOLDERNAME varchar(50)
  11. */
  12. ALTER PROC [dbo].[proc_agentMaster]
  13. @flag VARCHAR(50) = NULL ,
  14. @user VARCHAR(30) = NULL ,
  15. @agentId VARCHAR(30) = NULL ,
  16. @parentId VARCHAR(30) = NULL ,
  17. @agentName NVARCHAR(100) = NULL ,
  18. @agentCode VARCHAR(50) = NULL ,
  19. @agentAddress VARCHAR(200) = NULL ,
  20. @agentCity VARCHAR(100) = NULL ,
  21. @agentCountryId INT = NULL ,
  22. @agentCountry VARCHAR(100) = NULL ,
  23. @agentState VARCHAR(100) = NULL ,
  24. @agentDistrict VARCHAR(100) = NULL ,
  25. @agentZip VARCHAR(20) = NULL ,
  26. @agentLocation INT = NULL ,
  27. @agentPhone1 VARCHAR(50) = NULL ,
  28. @agentPhone2 VARCHAR(50) = NULL ,
  29. @agentFax1 VARCHAR(50) = NULL ,
  30. @agentFax2 VARCHAR(50) = NULL ,
  31. @agentMobile1 VARCHAR(50) = NULL ,
  32. @agentMobile2 VARCHAR(50) = NULL ,
  33. @agentEmail1 VARCHAR(100) = NULL ,
  34. @agentEmail2 VARCHAR(100) = NULL ,
  35. @bankBranch VARCHAR(50)=NULL,
  36. @bankCode VARCHAR(50)=NULL,
  37. @bankAccountNumber VARCHAR(50)=NULL,
  38. @accHolderName VARCHAR(50)=NULL,
  39. @businessOrgType INT = NULL ,
  40. @businessType INT = NULL ,
  41. @agentRole CHAR(1) = NULL ,
  42. @agentType INT = NULL ,
  43. @allowAccountDeposit CHAR(1) = NULL ,
  44. @actAsBranch CHAR(1) = NULL ,
  45. @contractExpiryDate DATETIME = NULL ,
  46. @renewalFollowupDate DATETIME = NULL ,
  47. @isSettlingAgent CHAR(1) = NULL ,
  48. @agentGroup INT = NULL ,
  49. @businessLicense VARCHAR(100) = NULL ,
  50. @agentBlock CHAR(1) = NULL ,
  51. @agentcompanyName VARCHAR(200) = NULL ,
  52. @companyAddress VARCHAR(200) = NULL ,
  53. @companyCity VARCHAR(100) = NULL ,
  54. @companyCountry VARCHAR(100) = NULL ,
  55. @companyState VARCHAR(100) = NULL ,
  56. @companyDistrict VARCHAR(100) = NULL ,
  57. @companyZip VARCHAR(50) = NULL ,
  58. @companyPhone1 VARCHAR(50) = NULL ,
  59. @companyPhone2 VARCHAR(50) = NULL ,
  60. @companyFax1 VARCHAR(50) = NULL ,
  61. @companyFax2 VARCHAR(50) = NULL ,
  62. @companyEmail1 VARCHAR(100) = NULL ,
  63. @companyEmail2 VARCHAR(100) = NULL ,
  64. @localTime INT = NULL ,
  65. @localCurrency INT = NULL ,
  66. @agentDetails VARCHAR(MAX) = NULL ,
  67. @parentName VARCHAR(100) = NULL ,
  68. @haschanged CHAR(1) = NULL ,
  69. @isActive CHAR(1) = NULL ,
  70. @isDeleted CHAR(1) = NULL ,
  71. @sortBy VARCHAR(50) = NULL ,
  72. @sortOrder VARCHAR(5) = NULL ,
  73. @pageSize INT = NULL ,
  74. @pageNumber INT = NULL ,
  75. @populateBranch CHAR(1) = NULL ,
  76. @headMessage VARCHAR(MAX) = NULL ,
  77. @mapCodeInt VARCHAR(20) = NULL ,
  78. @mapCodeDom VARCHAR(20) = NULL ,
  79. @commCodeInt VARCHAR(20) = NULL ,
  80. @commCodeDom VARCHAR(20) = NULL ,
  81. @urlRoot VARCHAR(200) = NULL ,
  82. @joinedDate DATETIME = NULL ,
  83. @mapCodeIntAc VARCHAR(50) = NULL ,
  84. @mapCodeDomAc VARCHAR(50) = NULL ,
  85. @payOption INT = NULL ,
  86. @agentSettCurr VARCHAR(50) = NULL ,
  87. @contactPerson1 VARCHAR(200) = NULL ,
  88. @contactPerson2 VARCHAR(200) = NULL ,
  89. @isHeadOffice CHAR(1) = NULL ,
  90. @locationCode VARCHAR(200) = NULL,
  91. @isIntl BIT = NULL ,
  92. @isApiPartner BIT = NULL,
  93. @partnerBankcode VARCHAR(15) = NULL,
  94. @branchCode VARCHAR(3)=NULL,
  95. @intlSuperAgentId BIGINT=NULL,
  96. @isInternal CHAR(1)=NULL
  97. AS
  98. ----------------------------------------------------------------------
  99. --#1146 added new @flag ='onlineBranchList' for JME web online
  100. ----------------------------------------------------------------------
  101. SET NOCOUNT ON
  102. DECLARE @glcode VARCHAR(10) , @acct_num VARCHAR(20)
  103. CREATE TABLE #tempACnum ( acct_num VARCHAR(20) );
  104. SET XACT_ABORT ON
  105. BEGIN TRY
  106. IF @mapCodeInt IS NULL
  107. SET @mapCodeInt = ISNULL(@mapCodeInt,@agentId)
  108. CREATE TABLE #msg ( errorCode INT , msg VARCHAR(100) , id INT )
  109. DECLARE @sql VARCHAR(MAX) ,
  110. @oldValue VARCHAR(MAX) ,
  111. @newValue VARCHAR(MAX) ,
  112. @tableName VARCHAR(50) ,
  113. @logIdentifier VARCHAR(100) ,
  114. @logParamMain VARCHAR(100) ,
  115. @tableAlias VARCHAR(100) ,
  116. @modType VARCHAR(6) ,
  117. @module INT ,
  118. @select_field_list VARCHAR(MAX) ,
  119. @extra_field_list VARCHAR(MAX) ,
  120. @table VARCHAR(MAX) ,
  121. @sql_filter VARCHAR(MAX) ,
  122. @ApprovedFunctionId INT
  123. SELECT @logIdentifier = 'agentId' , @logParamMain = 'agentMaster' , @tableAlias = 'Agent Setup'
  124. ,@module = 20 , @ApprovedFunctionId = 20111030
  125. IF @flag = 'au'
  126. BEGIN
  127. SELECT @agentId = agentId
  128. FROM applicationUsers WITH ( NOLOCK )
  129. WHERE userName = @user
  130. SELECT agentId ,
  131. agentName ,
  132. agentType = ISNULL(agentType, 0)
  133. FROM agentMaster WITH ( NOLOCK )
  134. WHERE agentId = @agentId
  135. RETURN
  136. END
  137. ELSE IF @flag = 'agl'
  138. BEGIN
  139. SELECT agentId ,
  140. agentName ,
  141. agentAddress
  142. FROM agentMaster WITH ( NOLOCK )
  143. WHERE agentCountry = @agentCountry
  144. AND ISNULL(isSettlingAgent, 'N') = 'Y'
  145. AND ISNULL(isDeleted, 'N') <> 'Y'
  146. AND ISNULL(isActive, 'N') = 'Y'
  147. ORDER BY agentName ASC
  148. RETURN
  149. END
  150. ELSE IF @flag = 'banklist' -- Populate Bank List for Domestic A/C Deposit(Send)
  151. BEGIN
  152. --SELECT agentId ,
  153. -- agentName
  154. -- FROM agentMaster WITH ( NOLOCK )
  155. -- WHERE IsDom = 1
  156. -- AND ISNULL(isDeleted, 'N') <> 'Y'
  157. -- AND ISNULL(isActive, 'N') = 'Y'
  158. -- AND ISNULL(agentBlock, 'U') <> 'Y'
  159. -- ORDER BY agentName
  160. SELECT agentId ,agentName
  161. FROM agentMaster WITH ( NOLOCK )
  162. WHERE ISNULL(isActive, 'N') = 'Y'
  163. AND agentType=2903
  164. ORDER BY agentName
  165. END
  166. ELSE IF @flag = 'banklist2' --All Bank and FInance list doing A/C Deposit(International/Domestic)
  167. BEGIN
  168. SELECT agentId ,
  169. agentName
  170. FROM agentMaster WITH ( NOLOCK )
  171. WHERE ( (
  172. ( allowAccountDeposit = 'Y' OR payOption IN ( 20 )) AND agentType = 2903 )
  173. OR ( payOption = 40 AND agentType = 2905
  174. )
  175. )
  176. AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(agentBlock, 'U') <> 'B'
  177. ORDER BY agentName
  178. END
  179. ELSE IF @flag = 'bbl' --Populate Bank Branch list
  180. BEGIN
  181. IF EXISTS(
  182. SELECT agentId ,agentName = UPPER(agentName)
  183. FROM agentMaster WITH ( NOLOCK )
  184. WHERE ISNULL(isActive, 'N') = 'Y'
  185. AND ISNULL(isDeleted, 'N') <> 'Y'
  186. AND ISNULL(agentBlock, 'U') <> 'B'
  187. AND parentId = @parentId AND agentType = 2904
  188. )
  189. BEGIN
  190. SELECT agentId ,
  191. agentName = UPPER(agentName)
  192. FROM agentMaster WITH ( NOLOCK )
  193. WHERE ISNULL(isActive, 'N') = 'Y'
  194. AND ISNULL(isDeleted, 'N') <> 'Y'
  195. AND ISNULL(agentBlock, 'U') <> 'B'
  196. AND parentId = @parentId
  197. AND agentType = 2904
  198. ORDER BY agentName
  199. RETURN
  200. END
  201. SELECT agentId =0, agentName = 'Any Branch'
  202. RETURN
  203. END
  204. ELSE IF @flag = 'bc' --breadCrumb
  205. BEGIN
  206. DECLARE @breadCrumb VARCHAR(500) = NULL ,@agName VARCHAR(MAX)
  207. WHILE ( @agentId <> 0 )
  208. BEGIN
  209. SELECT @agentName = agentName ,
  210. @agentId = parentId ,
  211. @agentType = agentType ,
  212. @actAsBranch = ISNULL(actAsBranch,
  213. 'N')
  214. FROM agentMaster WITH ( NOLOCK )
  215. WHERE agentId = @agentId
  216. IF @agentType = 2900
  217. SET @agName = '<img src="'+ @urlRoot + '/Images/headoffice.png" />'+ @agentName
  218. ELSE IF @agentType = 2901
  219. SET @agName = '<img src="'+ @urlRoot+ '/Images/hub.png" />'+ @agentName
  220. ELSE IF @agentType = 2902
  221. SET @agName = '<img src="'+ @urlRoot+ '/Images/superagent.png" />'+ @agentName
  222. ELSE IF @agentType = 2903 AND @actAsBranch = 'N'
  223. SET @agName = '<img src="' + @urlRoot + '/Images/agents.png" />'+ @agentName
  224. ELSE IF @agentType = 2903 AND @actAsBranch = 'Y'
  225. SET @agName = '<img src="'+ @urlRoot + '/Images/branch.png" />' + @agentName
  226. ELSE IF @agentType = 2904
  227. SET @agName = '<img src="'+ @urlRoot + '/Images/branch.png" />'+ @agentName
  228. SET @breadCrumb = @agName + ISNULL('' + @breadCrumb,'')
  229. END
  230. SELECT @breadCrumb
  231. RETURN
  232. END
  233. ELSE IF @flag = 'hl'
  234. BEGIN
  235. SELECT [0] , [1]
  236. FROM ( SELECT NULL [0] , 'All' [1]
  237. UNION ALL
  238. SELECT am.agentId [0] ,am.agentName [1] FROM agentMaster am WITH ( NOLOCK )
  239. WHERE am.agentType = 2901
  240. AND ISNULL(am.isDeleted, 'N') <> 'Y'
  241. AND ISNULL(am.isActive,'N') = 'Y'
  242. ) x
  243. ORDER BY CASE WHEN x.[0] IS NULL THEN CAST(x.[0] AS VARCHAR) ELSE x.[1] END
  244. RETURN
  245. END
  246. ELSE IF @flag = 'hl2'
  247. BEGIN
  248. SELECT agentId ,
  249. agentName
  250. FROM agentMaster WITH ( NOLOCK )
  251. WHERE agentType = 2901
  252. AND ISNULL(isDeleted, 'N') <> 'Y'
  253. AND ISNULL(isActive, 'N') = 'Y'
  254. RETURN
  255. END
  256. ELSE IF @flag = 'sal' -- Select Super Agent
  257. BEGIN
  258. SELECT agentId ,
  259. agentName
  260. FROM agentMaster WITH ( NOLOCK )
  261. WHERE agentType = 2902
  262. --AND agentCountryId = @agentCountry
  263. AND ISNULL(isDeleted,
  264. 'N') <> 'Y'
  265. AND ISNULL(isActive,
  266. 'N') = 'Y'
  267. RETURN
  268. END
  269. ELSE IF @flag = 'alc' -- Select Agent According to CountryId
  270. BEGIN
  271. SELECT agentId ,
  272. agentName
  273. FROM agentMaster WITH ( NOLOCK )
  274. WHERE agentType = 2903
  275. AND agentCountryId = @agentCountryId
  276. AND ISNULL(isDeleted,'N') = 'N'
  277. --AND ISNULL(isActive, 'N') = 'Y'
  278. AND ISNULL(agentBlock,'U') <> 'B'
  279. ORDER BY agentName
  280. RETURN
  281. END
  282. ELSE IF @flag = 'alc1' -- Select Agent According to Country Name
  283. BEGIN
  284. SELECT
  285. agentId ,
  286. agentName
  287. FROM agentMaster WITH ( NOLOCK )
  288. WHERE agentType = 2903
  289. AND agentCountry = @agentCountry
  290. AND ISNULL(isDeleted,
  291. 'N') = 'N'
  292. --AND ISNULL(isActive, 'N') = 'Y'
  293. AND ISNULL(agentBlock,
  294. 'U') <> 'B'
  295. ORDER BY agentName
  296. RETURN
  297. END
  298. ELSE IF @flag = 'cal'
  299. BEGIN
  300. SELECT
  301. countryId ,
  302. countryName
  303. FROM countryMaster WITH ( NOLOCK )
  304. WHERE ISNULL(isDeleted,'N') <> 'Y'
  305. AND ISNULL(isOperativeCountry,'N') = 'Y'
  306. ORDER BY countryName
  307. RETURN
  308. END
  309. ELSE IF @flag = 'al' -- Select Agent according to Super Agent and Country
  310. BEGIN
  311. SELECT agentId ,agentName
  312. FROM agentMaster WITH ( NOLOCK )
  313. WHERE agentType = 2903
  314. AND agentCountryId = @agentCountry
  315. AND parentId = @parentId AND ISNULL(isActive, 'N') = 'Y'
  316. AND isSettlingAgent = 'Y'
  317. RETURN
  318. END
  319. ELSE IF @flag = 'al1' -- Select Agent according to Super Agent and Country
  320. BEGIN
  321. SELECT agentId ,agentName
  322. FROM agentMaster WITH ( NOLOCK )
  323. WHERE agentType = 2903
  324. AND agentCountry = @agentCountry
  325. AND parentId = @parentId
  326. AND ISNULL(isDeleted,'N') <> 'Y'
  327. AND ISNULL(isActive,'N') = 'Y'
  328. RETURN
  329. END
  330. ELSE IF @flag = 'al2' -- Select Agent according to Hub and Country
  331. BEGIN
  332. ;
  333. WITH
  334. ret
  335. AS ( SELECT agentId ,parentId ,agentType ,agentCountryId ,agentName ,actAsBranch ,isDeleted ,isActive
  336. FROM agentMaster (nolock) WHERE agentId = @agentId
  337. UNION ALL
  338. SELECT t.agentId ,t.parentId ,t.agentType ,t.agentCountryId ,t.agentName ,t.actAsBranch ,t.isDeleted ,t.isActive
  339. FROM agentMaster t
  340. INNER JOIN ret r ON t.parentId = r.agentId
  341. )
  342. SELECT
  343. agentId ,agentName
  344. FROM ret WITH ( NOLOCK )
  345. WHERE ( agentType = 2903 )
  346. AND agentCountryId = ISNULL(@agentCountry,agentCountryId)
  347. AND ISNULL(isDeleted,'N') <> 'Y' AND ISNULL(isActive,'N') = 'Y'
  348. RETURN
  349. END
  350. ELSE IF @flag = 'al3' --Select All Agent
  351. BEGIN
  352. SELECT agentId ,agentName
  353. FROM agentMaster(NOLOCK)
  354. WHERE
  355. --agentType = 2903 AND
  356. ISNULL(isSettlingAgent,'N') = 'Y'
  357. AND ISNULL(isDeleted,'N') <> 'Y'
  358. ORDER BY agentName
  359. RETURN
  360. END
  361. ELSE IF @flag = 'al4' --Select Agent According to User
  362. BEGIN
  363. SELECT @parentId = agentId
  364. FROM applicationUsers WITH ( NOLOCK )
  365. WHERE userName = @user;
  366. WITH
  367. ret
  368. AS ( SELECT * FROM agentMaster( NOLOCK )
  369. WHERE agentId = @parentId
  370. UNION ALL
  371. SELECT t.* FROM agentMaster t( NOLOCK )
  372. INNER JOIN ret r ON t.parentId = r.agentId
  373. )
  374. SELECT agentId , agentName
  375. FROM ret WITH ( NOLOCK )
  376. WHERE ISNULL(isDeleted, 'N') <> 'Y'
  377. AND ISNULL(isActive, 'N') = 'Y'
  378. RETURN
  379. END
  380. ELSE IF @flag = 'al5' --Select All Agent
  381. BEGIN
  382. SELECT agentId ,agentName
  383. FROM agentMaster (NOLOCK)
  384. WHERE (
  385. ( agentType = 2903 AND ISNULL(actAsBranch,'N') = 'Y')
  386. OR agentType = 2903 OR agentType = 2901
  387. )
  388. AND ISNULL(isDeleted,'N') <> 'Y'
  389. AND ISNULL(isActive,'N') = 'Y'
  390. AND ISNULL(agentBlock,'U') <> 'B'
  391. ORDER BY agentName
  392. RETURN
  393. END
  394. ELSE IF @flag = 'al6' --Select international Agent
  395. BEGIN
  396. SELECT agentId , agentName
  397. FROM agentMaster(NOLOCK)
  398. WHERE agentCountry <> 'Nepal'
  399. AND ISNULL(isSettlingAgent, 'N') = 'Y'
  400. AND ISNULL(isDeleted, 'N') <> 'Y'
  401. --AND ISNULL(isActive, 'N') = 'Y'
  402. AND ISNULL(agentBlock, 'U') <> 'B'
  403. ORDER BY agentName
  404. RETURN
  405. END
  406. ELSE IF @flag = 'al7' --Select domestic Agent
  407. BEGIN
  408. SELECT agentId , agentName
  409. FROM agentMaster(NOLOCK)
  410. WHERE agentType = 2903
  411. AND agentCountry = 'Nepal'
  412. AND ISNULL(isDeleted, 'N') <> 'Y'
  413. AND ISNULL(isActive, 'N') = 'Y'
  414. ORDER BY agentName
  415. RETURN
  416. END
  417. ELSE IF @flag = 'all' --Select Agent from locationId
  418. BEGIN
  419. SELECT agentId , agentName
  420. FROM agentMaster(NOLOCK)
  421. WHERE agentType IN ( 2903, 2904 )
  422. AND agentLocation = @agentLocation
  423. AND ISNULL(isSettlingAgent, 'N') = 'Y'
  424. AND ISNULL(isDeleted, 'N') <> 'Y'
  425. --AND ISNULL(isActive, 'N') = 'Y'
  426. AND ISNULL(agentBlock, 'U') <> 'B'
  427. ORDER BY agentName
  428. RETURN
  429. END
  430. ELSE IF @flag = 'bl' -- Select Branch According to Agent
  431. BEGIN
  432. SELECT agentId ,
  433. agentName = UPPER(agentName)
  434. FROM agentMaster WITH ( NOLOCK )
  435. WHERE ISNULL(isActive, 'N') = 'Y'
  436. AND ISNULL(isDeleted, 'N') <> 'Y'
  437. AND ISNULL(agentBlock, 'U') <> 'B'
  438. AND agentType=2904
  439. --AND IsIntl = 1
  440. AND parentId = @parentId
  441. ORDER BY agentAddress
  442. RETURN
  443. RETURN
  444. END
  445. ELSE IF @flag = 'bankbl' -- Select Branch According to Agent
  446. BEGIN
  447. SELECT agentId ,
  448. agentName = UPPER(agentName)
  449. FROM agentMaster WITH ( NOLOCK )
  450. WHERE ISNULL(isActive, 'N') = 'Y'
  451. AND ISNULL(isDeleted, 'N') <> 'Y'
  452. AND ISNULL(agentBlock, 'U') <> 'B'
  453. AND agentType=2903
  454. AND IsIntl = 1
  455. --AND parentId = @parentId
  456. ORDER BY agentAddress
  457. RETURN
  458. RETURN
  459. END
  460. ELSE IF @flag = 'hc' --hasChanged
  461. BEGIN
  462. SELECT
  463. [0] , [1]
  464. FROM
  465. ( SELECT NULL [0] , 'All' [1]
  466. UNION ALL
  467. SELECT 'Y' [0] , 'Yes' [1]
  468. UNION ALL
  469. SELECT 'N' [0] , 'No' [1]
  470. ) x
  471. ORDER BY CASE WHEN x.[0] IS NULL THEN CAST(x.[0] AS VARCHAR) ELSE x.[1] END
  472. RETURN
  473. END
  474. ELSE IF @flag = 'rbl' -- ## Regional Branch List
  475. BEGIN
  476. SELECT am.agentId , am.agentName
  477. FROM agentMaster am
  478. WITH ( NOLOCK )
  479. INNER JOIN regionalBranchAccessSetup rba ON am.agentId = rba.memberAgentId
  480. WHERE rba.agentId = @agentId
  481. AND ISNULL(rba.isDeleted, 'N') <> 'Y'
  482. AND ISNULL(rba.isActive, 'Y') = 'Y'
  483. RETURN
  484. END
  485. ELSE IF @flag = 'rblByAId' --Regional Branch List
  486. BEGIN
  487. SELECT mapCodeInt agentId , agentName
  488. FROM agentMaster a
  489. WITH ( NOLOCK )
  490. INNER JOIN regionalBranchAccessSetup rba ON a.agentId = rba.memberAgentId
  491. LEFT JOIN api_districtList b
  492. WITH ( NOLOCK ) ON a.agentLocation = b.districtCode
  493. WHERE rba.agentId = @agentId
  494. AND ISNULL(a.isDeleted, 'N') = 'N'
  495. AND ISNULL(a.isActive, 'N') = 'Y'
  496. RETURN
  497. END
  498. ELSE IF @flag = 'rblByAId2' -- ## Regional Branch List
  499. BEGIN
  500. SELECT agentId = a.agentId ,
  501. agentName = a.agentName
  502. FROM agentMaster a WITH ( NOLOCK )
  503. WHERE a.parentId = @parentId
  504. AND ISNULL(a.isDeleted, 'N') = 'N'
  505. AND ISNULL(a.isActive, 'N') = 'Y'
  506. AND ISNULL(a.apiAgent, 'N') = 'N'
  507. ORDER BY a.agentName;
  508. RETURN
  509. END
  510. ELSE IF @flag = 'n'
  511. BEGIN
  512. SELECT COUNT(*)
  513. FROM
  514. agentMaster
  515. WHERE
  516. ( ISNULL(actAsBranch, 'N') = 'Y' OR agentType = 2904 )
  517. AND ISNULL(isDeleted, 'N') = 'N'
  518. END
  519. ELSE IF @flag IN ('s', 's2' )
  520. BEGIN
  521. DECLARE @hasRight CHAR(1)
  522. SET @hasRight = dbo.FNAHasRight(@user,CAST(@ApprovedFunctionId AS VARCHAR))
  523. IF ( @user IN ('admin','admin1' ) OR @parentId = 10001)
  524. BEGIN
  525. SET @table = '(
  526. SELECT
  527. parentId = ISNULL(amh.parentId, am.parentId)
  528. ,agentId = ISNULL(amh.agentId, am.agentId)
  529. ,agentCode = ISNULL(amh.agentCode, am.agentCode)
  530. ,mapCodeInt = ISNULL(amh.mapCodeInt, am.mapCodeInt)
  531. ,agentName = ISNULL(amh.agentName, am.agentName)
  532. ,agentAddress = ISNULL(amh.agentAddress, am.agentAddress)
  533. ,agentCity = ISNULL(amh.agentCity, am.agentCity)
  534. ,agentCountry = ISNULL(amh.agentCountry, am.agentCountry)
  535. ,agentState = ISNULL(amh.agentState, am.agentState)
  536. ,agentDistrict = ISNULL(amh.agentDistrict, am.agentDistrict)
  537. ,agentZip = ISNULL(amh.agentZip, am.agentZip)
  538. ,agentLocation = ISNULL(amh.agentLocation, am.agentLocation)
  539. ,agentPhone1 = ISNULL(amh.agentPhone1, am.agentPhone1)
  540. ,agentPhone2 = ISNULL(amh.agentPhone2, am.agentPhone2)
  541. ,agentFax1 = ISNULL(amh.agentFax1, am.agentFax1)
  542. ,agentFax2 = ISNULL(amh.agentFax2, am.agentFax2)
  543. ,agentMobile1 = ISNULL(amh.agentMobile1, am.agentMobile1)
  544. ,agentMobile2 = ISNULL(amh.agentMobile2, am.agentMobile2)
  545. ,agentEmail1 = ISNULL(amh.agentEmail1, am.agentEmail1)
  546. ,agentEmail2 = ISNULL(amh.agentEmail2, am.agentEmail2)
  547. ,bankBranch=ISNULL(amh.bankBranch, am.bankBranch)
  548. ,bankCode=ISNULL(amh.bankCode, am.bankCode)
  549. ,bankAccountNumber=ISNULL(amh.bankAccountNumber, am.bankAccountNumber)
  550. ,accountHolderName=ISNULL(amh.accountHolderName, am.accountHolderName)
  551. ,businessOrgType = ISNULL(amh.businessOrgType, am.businessOrgType)
  552. ,businessType = ISNULL(amh.businessType, am.businessType)
  553. ,agentRole = ISNULL(amh.agentRole, am.agentRole)
  554. ,agentType = ISNULL(amh.agentType, am.agentType)
  555. ,actAsBranch = ISNULL(amh.actAsBranch, am.actAsBranch)
  556. ,contractExpiryDate = ISNULL(amh.contractExpiryDate, am.contractExpiryDate)
  557. ,renewalFollowupDate = ISNULL(amh.renewalFollowupDate, am.renewalFollowupDate)
  558. ,isSettlingAgent = ISNULL(amh.isSettlingAgent, am.isSettlingAgent)
  559. ,agentGrp = ISNULL(amh.agentGrp, am.agentGrp)
  560. ,businessLicense = ISNULL(amh.businessLicense, am.businessLicense)
  561. ,agentBlock = ISNULL(amh.agentBlock, am.agentBlock)
  562. ,isActive = ISNULL(amh.isActive, am.isActive)
  563. ,localTime = ISNULL(amh.localTime, am.localTime)
  564. ,am.createdDate
  565. ,am.createdBy
  566. ,amh.modType
  567. ,modifiedDate = CASE WHEN am.approvedBy IS NULL THEN am.createdDate ELSE amh.createdDate END
  568. ,modifiedBy = CASE WHEN am.approvedBy IS NULL THEN am.createdBy ELSE amh.createdBy END
  569. ,hasChanged = CASE WHEN (am.approvedBy IS NULL) OR
  570. (amh.agentId IS NOT NULL)
  571. THEN ''Y'' ELSE ''N'' END
  572. FROM agentMaster am WITH(NOLOCK)
  573. LEFT JOIN agentMasterMod amh ON am.agentId = amh.agentId
  574. AND (
  575. amh.createdBy = ''' + @user + '''
  576. OR ''Y'' = ''' + @hasRight + '''
  577. )
  578. WHERE ISNULL(am.isDeleted, ''N'') <> ''Y''
  579. AND (
  580. am.approvedBy IS NOT NULL
  581. OR am.createdBy = ''' + @user + '''
  582. OR ''Y'' = ''' + @hasRight
  583. + '''
  584. )
  585. --AND NOT(ISNULL(amh.modType, '''') = ''D'' AND amh.createdBy = '''
  586. + @user + ''')
  587. ) '
  588. --print @table
  589. END
  590. ELSE
  591. BEGIN
  592. IF OBJECT_ID('tempdb..#agentId') IS NOT NULL
  593. DROP TABLE #agentId
  594. CREATE TABLE #agentId ( agentId INT )
  595. INSERT INTO #agentId
  596. SELECT agentId
  597. FROM agentMaster(nolock) WHERE ISNULL(isDeleted,'N') = 'N'
  598. DELETE FROM #agentId
  599. FROM #agentId ag
  600. INNER JOIN agentGroupMaping agm ON agm.agentId = ag.agentId
  601. WHERE agm.groupCat = '6900' AND ISNULL(agm.isDeleted, 'N') = 'N'
  602. INSERT INTO #agentId
  603. SELECT DISTINCT agm.agentId
  604. FROM userGroupMapping ugm (nolock)
  605. INNER JOIN agentGroupMaping agm (nolock) ON agm.groupDetail = ugm.groupDetail
  606. AND ISNULL(agm.isDeleted, 'N') = 'N'
  607. AND ISNULL(ugm.isDeleted,'N') = 'N'
  608. WHERE ugm.userName = @user
  609. SET @table = '(
  610. SELECT
  611. parentId = ISNULL(amh.parentId, am.parentId)
  612. ,agentId = ISNULL(amh.agentId, am.agentId)
  613. ,agentCode = ISNULL(amh.agentCode, am.agentCode)
  614. ,mapCodeInt = ISNULL(amh.mapCodeInt, am.mapCodeInt)
  615. ,agentName = ISNULL(amh.agentName, am.agentName)
  616. ,agentAddress = ISNULL(amh.agentAddress, am.agentAddress)
  617. ,agentCity = ISNULL(amh.agentCity, am.agentCity)
  618. ,agentCountry = ISNULL(amh.agentCountry, am.agentCountry)
  619. ,agentState = ISNULL(amh.agentState, am.agentState)
  620. ,agentDistrict = ISNULL(amh.agentDistrict, am.agentDistrict)
  621. ,agentZip = ISNULL(amh.agentZip, am.agentZip)
  622. ,agentLocation = ISNULL(amh.agentLocation, am.agentLocation)
  623. ,agentPhone1 = ISNULL(amh.agentPhone1, am.agentPhone1)
  624. ,agentPhone2 = ISNULL(amh.agentPhone2, am.agentPhone2)
  625. ,agentFax1 = ISNULL(amh.agentFax1, am.agentFax1)
  626. ,agentFax2 = ISNULL(amh.agentFax2, am.agentFax2)
  627. ,agentMobile1 = ISNULL(amh.agentMobile1, am.agentMobile1)
  628. ,agentMobile2 = ISNULL(amh.agentMobile2, am.agentMobile2)
  629. ,agentEmail1 = ISNULL(amh.agentEmail1, am.agentEmail1)
  630. ,agentEmail2 = ISNULL(amh.agentEmail2, am.agentEmail2)
  631. ,bankBranch=ISNULL(amh.bankBranch, am.bankBranch)
  632. ,bankCode=ISNULL(amh.bankCode, am.bankCode)
  633. ,bankAccountNumber=ISNULL(amh.bankAccountNumber, am.bankAccountNumber)
  634. ,accountHolderName=ISNULL(amh.accountHolderName, am.accountHolderName)
  635. ,businessOrgType = ISNULL(amh.businessOrgType, am.businessOrgType)
  636. ,businessType = ISNULL(amh.businessType, am.businessType)
  637. ,agentRole = ISNULL(amh.agentRole, am.agentRole)
  638. ,agentType = ISNULL(amh.agentType, am.agentType)
  639. ,actAsBranch = ISNULL(amh.actAsBranch, am.actAsBranch)
  640. ,contractExpiryDate = ISNULL(amh.contractExpiryDate, am.contractExpiryDate)
  641. ,renewalFollowupDate = ISNULL(amh.renewalFollowupDate, am.renewalFollowupDate)
  642. ,isSettlingAgent = ISNULL(amh.isSettlingAgent, am.isSettlingAgent)
  643. ,agentGrp = ISNULL(amh.agentGrp, am.agentGrp)
  644. ,businessLicense = ISNULL(amh.businessLicense, am.businessLicense)
  645. ,agentBlock = ISNULL(amh.agentBlock, am.agentBlock)
  646. ,isActive = ISNULL(amh.isActive, am.isActive)
  647. ,localTime = ISNULL(amh.localTime, am.localTime)
  648. ,am.createdDate
  649. ,am.createdBy
  650. ,amh.modType
  651. ,modifiedDate = CASE WHEN am.approvedBy IS NULL THEN am.createdDate ELSE amh.createdDate END
  652. ,modifiedBy = CASE WHEN am.approvedBy IS NULL THEN am.createdBy ELSE amh.createdBy END
  653. ,hasChanged = CASE WHEN (am.approvedBy IS NULL) OR
  654. (amh.agentId IS NOT NULL)
  655. THEN ''Y'' ELSE ''N'' END
  656. FROM agentMaster am WITH(NOLOCK)
  657. INNER JOIN
  658. (
  659. --select distinct agentId from
  660. --(
  661. -- select agentId from agentMaster
  662. -- where agentId not in(
  663. -- select distinct b.agentId from agentGroupMaping b where b.groupCat=''6900'' and isDeleted is null)
  664. -- union all
  665. -- select distinct b.agentId from userGroupMapping a inner join agentGroupMaping b on a.groupDetail=b.groupDetail
  666. -- where a.userName=''' + @user
  667. + ''' and b.isDeleted is null
  668. --)a
  669. SELECT DISTINCT agentId FROM #agentId
  670. )b on am.agentId = b.agentId
  671. LEFT JOIN agentMasterMod amh ON am.agentId = amh.agentId
  672. AND (
  673. amh.createdBy = ''' + @user + '''
  674. OR ''Y'' = ''' + @hasRight + '''
  675. )
  676. WHERE ISNULL(am.isDeleted, ''N'') <> ''Y''
  677. AND (
  678. am.approvedBy IS NOT NULL
  679. OR am.createdBy = ''' + @user + '''
  680. OR ''Y'' = ''' + @hasRight
  681. + '''
  682. )
  683. --AND NOT(ISNULL(amh.modType, '''') = ''D'' AND amh.createdBy = '''
  684. + @user + ''')
  685. ) '
  686. PRINT(@table)
  687. END
  688. END
  689. ELSE IF @flag = 'a'
  690. BEGIN
  691. IF EXISTS ( SELECT 'X' FROM agentMasterMod WITH ( NOLOCK ) WHERE agentId = @agentId AND createdBy = @user )
  692. BEGIN
  693. SELECT m.* ,
  694. contractExpiryDate1 = CONVERT(VARCHAR, m.contractExpiryDate, 101) ,
  695. renewalFollowupDate1 = CONVERT(VARCHAR, m.renewalFollowupDate, 101) ,
  696. am.modifiedBy ,
  697. am.modifiedDate,
  698. am.branchCode
  699. FROM agentMasterMod m WITH ( NOLOCK )
  700. LEFT JOIN agentMaster am WITH ( NOLOCK ) ON m.agentId = am.agentId
  701. WHERE m.agentId = @agentId
  702. END
  703. ELSE
  704. BEGIN
  705. SELECT * ,
  706. contractExpiryDate1 = CONVERT(VARCHAR, contractExpiryDate, 101) ,
  707. renewalFollowupDate1 = CONVERT(VARCHAR, renewalFollowupDate, 101)
  708. FROM agentMaster
  709. WHERE agentId = @agentId
  710. END
  711. END
  712. IF @flag = 'pullDefault'
  713. BEGIN
  714. SELECT * ,
  715. contractExpiryDate1 = CONVERT(VARCHAR, contractExpiryDate, 101) ,
  716. renewalFollowupDate1 = CONVERT(VARCHAR, renewalFollowupDate, 101)
  717. FROM agentMaster
  718. WHERE agentId = @agentId
  719. END
  720. ELSE IF @flag = 'i'
  721. BEGIN
  722. IF EXISTS ( SELECT 'X' FROM agentMaster(nolock)
  723. WHERE agentName = @agentName
  724. AND agentType IN ( 2901, 2902, 2903, 2904 )
  725. AND ISNULL(isDeleted, 'N') <> 'Y'
  726. AND ISNULL(isActive, 'N') = 'Y' )
  727. BEGIN
  728. EXEC proc_errorHandler 1, 'Agent with this name already exists', NULL
  729. RETURN
  730. END
  731. IF @payOption = 20
  732. SET @mapCodeIntAc = @mapCodeInt
  733. BEGIN TRANSACTION
  734. INSERT INTO agentMaster
  735. (parentId , agentName , agentAddress , agentCity , agentCountryId , agentCountry , agentState , agentDistrict ,
  736. agentZip , agentLocation , agentPhone1 , agentPhone2 , agentFax1 , agentFax2 , agentMobile1 , agentMobile2 , agentEmail1 ,
  737. agentEmail2 , bankBranch, bankCode, bankAccountNumber, accountHolderName, businessOrgType , businessType , agentRole ,
  738. agentType , allowAccountDeposit , actAsBranch , contractExpiryDate , renewalFollowupDate , isSettlingAgent , agentGrp ,
  739. businessLicense , agentBlock , agentCompanyName , companyAddress , companyCity , companyCountry , companyState ,
  740. companyDistrict , companyZip , companyPhone1 , companyPhone2 ,companyFax1 , companyFax2 , companyEmail1 , companyEmail2 ,
  741. localTime , localCurrency , agentDetails , createdDate , createdBy , headMessage , mapCodeInt , mapCodeDom ,
  742. commCodeInt , commCodeDom , joinedDate , mapCodeIntAc , mapCodeDomAc , payOption , isActive,isMigrated , agentSettCurr ,
  743. contactPerson1 , contactPerson2 ,isHeadOffice, IsIntl, isApiPartner, routingCode,branchCode
  744. )
  745. SELECT @parentId , @agentName , @agentAddress , @agentCity , @agentCountryId , @agentCountry , @agentState , @agentDistrict ,
  746. @agentZip , @agentLocation , @agentPhone1 ,@agentPhone2 , @agentFax1 , @agentFax2 , @agentMobile1 , @agentMobile2 , @agentEmail1 ,
  747. @agentEmail2 , @bankBranch, @bankCode, @bankAccountNumber, @accHolderName, @businessOrgType ,@businessType ,@agentRole ,
  748. @agentType ,@allowAccountDeposit ,@actAsBranch ,@contractExpiryDate ,@renewalFollowupDate ,@isSettlingAgent , @agentGroup ,
  749. @businessLicense ,@agentBlock ,@agentcompanyName ,@companyAddress ,@companyCity ,@companyCountry ,@companyState ,
  750. @companyDistrict ,@companyZip ,@companyPhone1 ,@companyPhone2 ,@companyFax1 ,@companyFax2 ,@companyEmail1 ,@companyEmail2 ,
  751. @localTime ,@localCurrency ,@agentDetails ,GETDATE() ,@user ,@headMessage ,@mapCodeInt ,@mapCodeDom ,@commCodeInt ,@commCodeDom ,
  752. @joinedDate ,@mapCodeIntAc ,@mapCodeDomAc ,@payOption ,'N','Y' ,@agentSettCurr ,
  753. @contactPerson1 ,@contactPerson2 ,@isHeadOffice, @IsIntl, @isApiPartner, @partnerBankcode,@branchCode
  754. SET @agentId = SCOPE_IDENTITY()
  755. UPDATE agentMaster
  756. SET agentCode = 'IME' + CAST(@agentId AS VARCHAR) ,
  757. mapCodeInt = @agentId ,
  758. mapCodeDom = @agentId ,
  759. mapCodeIntAc = @agentId ,
  760. mapCodeDomAc = @agentId ,
  761. commCodeInt = '10' + CAST(@agentId AS VARCHAR) ,
  762. commCodeDom = '11' + CAST(@agentId AS VARCHAR)
  763. WHERE agentId = @agentId
  764. COMMIT TRANSACTION
  765. EXEC proc_errorHandler 0, 'Record has been added successfully.', @agentId
  766. END
  767. ELSE IF @flag = 'u'
  768. BEGIN
  769. IF EXISTS ( SELECT 'X' FROM agentMaster WITH ( NOLOCK )
  770. WHERE agentId = @agentId AND approvedBy IS NULL AND createdBy <> @user )
  771. BEGIN
  772. EXEC proc_errorHandler 1,'You can not modify this record. Previous Modification has not been approved yet.',@agentId
  773. RETURN
  774. END
  775. IF EXISTS ( SELECT 'X' FROM agentMasterMod WITH ( NOLOCK )WHERE agentId = @agentId AND createdBy <> @user )
  776. BEGIN
  777. EXEC proc_errorHandler 1, 'You can not modify this record. Previous Modification has not been approved yet.',@agentId
  778. RETURN
  779. END
  780. IF @payOption = 20
  781. SET @mapCodeIntAc = @mapCodeInt
  782. IF EXISTS ( SELECT 'X' FROM agentMaster WITH ( NOLOCK )
  783. WHERE agentId = @agentId AND approvedBy IS NULL AND createdBy = @user )
  784. BEGIN
  785. UPDATE agentMaster
  786. SET
  787. agentName = @agentName,
  788. agentAddress = @agentAddress ,
  789. agentCity = @agentCity ,
  790. agentCountryId = @agentCountryId ,
  791. agentCountry = @agentCountry ,
  792. agentState = @agentState ,
  793. agentDistrict = @agentDistrict ,
  794. agentZip = @agentZip ,
  795. agentLocation = @agentLocation ,
  796. agentPhone1 = @agentPhone1 ,
  797. agentPhone2 = @agentPhone2 ,
  798. agentFax1 = @agentFax1 ,
  799. agentFax2 = @agentFax2 ,
  800. agentMobile1 = @agentMobile1 ,
  801. agentMobile2 = @agentMobile2 ,
  802. agentEmail1 = @agentEmail1 ,
  803. agentEmail2 = @agentEmail2 ,
  804. bankBranch = @bankBranch,
  805. bankCode = @bankCode,
  806. bankAccountNumber = @bankAccountNumber,
  807. accountHolderName=@accHolderName,
  808. businessOrgType = @businessOrgType ,
  809. businessType = @businessType ,
  810. agentRole = @agentRole ,
  811. agentType = @agentType ,
  812. allowAccountDeposit = @allowAccountDeposit ,
  813. contractExpiryDate = @contractExpiryDate ,
  814. renewalFollowupDate = @renewalFollowupDate ,
  815. agentGrp = @agentGroup ,
  816. businessLicense = @businessLicense ,
  817. agentBlock = @agentBlock ,
  818. agentCompanyName = @agentcompanyName ,
  819. companyAddress = @companyAddress ,
  820. companyCity = @companyCity ,
  821. companyCountry = @companyCountry ,
  822. companyState = @companyState ,
  823. companyDistrict = @companyDistrict ,
  824. companyZip = @companyZip ,
  825. companyPhone1 = @companyPhone1 ,
  826. companyPhone2 = @companyPhone2 ,
  827. companyFax1 = @companyFax1 ,
  828. companyFax2 = @companyFax2 ,
  829. companyEmail1 = @companyEmail1 ,
  830. companyEmail2 = @companyEmail2 ,
  831. localTime = @localTime ,
  832. localCurrency = @localCurrency ,
  833. isActive = @isActive ,
  834. agentDetails = @agentDetails ,
  835. headMessage = @headMessage ,
  836. mapCodeInt = @mapCodeInt ,
  837. mapCodeDom = @mapCodeDom ,
  838. commCodeInt = @commCodeInt ,
  839. commCodeDom = @commCodeDom ,
  840. mapCodeIntAc = @mapCodeIntAc ,
  841. mapCodeDomAc = @mapCodeDomAc ,
  842. payOption = @payOption ,
  843. agentSettCurr = @agentSettCurr ,
  844. contactPerson1 = @contactPerson1 ,
  845. contactPerson2 = @contactPerson2 ,
  846. isHeadOffice = @isHeadOffice ,
  847. isApiPartner = @isApiPartner ,
  848. IsIntl = @isIntl,
  849. routingCode = @partnerBankcode
  850. WHERE agentId = @agentId
  851. EXEC FastMoneyPro_account.[dbo].[spa_agentdetail] @flag = 'u',
  852. @agent_id = @agentId,
  853. @agent_name = @agentName,
  854. @agent_short_name = NULL,
  855. @agent_address = '5',
  856. @agent_city = @agentCity,
  857. @agent_address2 = @agentAddress,
  858. @agent_phone = @agentPhone1,
  859. @agent_fax = @agentFax1,
  860. @agent_email = @agentEmail1,
  861. @agent_contact_person = NULL,
  862. @agent_contact_person_mobile = NULL,
  863. @agent_status = @isActive,
  864. @bankbranch = @bankBranch,
  865. @bankcode = @bankCode,
  866. @bankaccno = @bankAccountNumber,
  867. @accholderName=@accHolderName,
  868. @MAP_code = @mapCodeInt,
  869. @MAP_code2 = @commCodeInt,
  870. @agenttype = @agentType,
  871. @agent_imecode = @mapCodeDom,
  872. @TDS_PCNT = 0.00,
  873. @tid = @commCodeDom,
  874. @agentzone = @agentState,
  875. @agentdistrict = @agentdistrict,
  876. @agent_panno = @businessLicense,
  877. @username = @user,
  878. @company_id = '1',
  879. @commissionDeduction = 5,
  880. @agent_country = @agentCountry
  881. END
  882. ELSE
  883. BEGIN BEGIN
  884. DELETE FROM agentMasterMod WHERE agentId = @agentId
  885. INSERT INTO agentMasterMod
  886. (
  887. agentId , agentCode ,parentId ,agentName ,agentAddress ,agentCity ,agentCountryId ,agentCountry ,agentState ,agentDistrict ,
  888. agentZip ,agentLocation ,agentPhone1 ,agentPhone2 ,agentFax1 ,agentFax2 ,agentMobile1 ,agentMobile2 ,agentEmail1 ,agentEmail2 ,
  889. bankbranch,bankcode,bankaccountnumber,accountHolderName,businessOrgType ,businessType ,agentRole ,agentType ,
  890. allowAccountDeposit ,contractExpiryDate ,renewalFollowupDate ,isSettlingAgent ,agentGrp ,businessLicense ,agentBlock ,
  891. agentCompanyName ,companyAddress ,companyCity,companyCountry ,companyState ,companyDistrict ,companyZip ,companyPhone1 ,
  892. companyPhone2 ,companyFax1 ,companyFax2 ,companyEmail1 ,companyEmail2 ,localTime ,localCurrency ,isActive ,agentDetails ,
  893. createdDate ,createdBy ,modType ,headMessage ,mapCodeInt ,mapCodeDom ,commCodeInt ,commCodeDom ,mapCodeIntAc ,
  894. mapCodeDomAc ,payOption ,agentSettCurr ,contactPerson1 ,contactPerson2 ,isHeadOffice, IsIntl, isApiPartner, routingCode
  895. )
  896. SELECT
  897. @agentId ,@agentCode ,@parentId ,@agentName ,@agentAddress ,@agentCity ,@agentCountryId ,@agentCountry ,@agentState ,@agentDistrict ,
  898. @agentZip ,@agentLocation ,@agentPhone1 ,@agentPhone2 ,@agentFax1 ,@agentFax2 ,@agentMobile1 ,@agentMobile2 ,@agentEmail1 ,@agentEmail2 ,
  899. @bankbranch,@bankcode,@bankaccountnumber,@accHolderName,@businessOrgType ,@businessType ,@agentRole ,@agentType ,
  900. @allowAccountDeposit ,@contractExpiryDate ,@renewalFollowupDate ,@isSettlingAgent ,@agentGroup ,@businessLicense ,@agentBlock ,
  901. @agentcompanyName ,@companyAddress ,@companyCity ,@companyCountry ,@companyState ,@companyDistrict ,@companyZip ,@companyPhone1 ,
  902. @companyPhone2 ,@companyFax1 ,@companyFax2 ,@companyEmail1 ,@companyEmail2 ,@localTime ,@localCurrency ,@isActive ,@agentDetails ,
  903. GETDATE() ,@user ,'U' ,@headMessage ,@mapCodeInt ,@mapCodeDom ,@commCodeInt ,@commCodeDom ,@mapCodeIntAc ,
  904. @mapCodeDomAc ,@payOption ,@agentSettCurr ,@contactPerson1 ,@contactPerson2 ,@isHeadOffice, @IsIntl, @isApiPartner, @partnerBankcode
  905. END
  906. END
  907. EXEC proc_errorHandler 0, 'Record updated successfully', @agentId
  908. END
  909. ELSE IF @flag = 'd'
  910. BEGIN
  911. IF EXISTS ( SELECT 'X' FROM agentMaster WITH ( NOLOCK )
  912. WHERE agentId = @agentId AND approvedBy IS NULL AND createdBy <> @user )
  913. BEGIN
  914. EXEC proc_errorHandler 1, 'You can not delete this record. Previous Modification has not been approved yet.', @agentId
  915. RETURN
  916. END
  917. IF EXISTS ( SELECT 'X' FROM agentMasterMod WITH ( NOLOCK )
  918. WHERE agentId = @agentId AND createdBy <> @user )
  919. BEGIN
  920. EXEC proc_errorHandler 1, 'You can not delete this record. Previous Modification has not been approved yet.', @agentId
  921. RETURN
  922. END
  923. BEGIN TRANSACTION
  924. IF EXISTS ( SELECT 'X' FROM agentMaster WITH ( NOLOCK )
  925. WHERE agentId = @agentId AND approvedBy IS NULL AND createdBy = @user )
  926. BEGIN
  927. DELETE FROM agentMaster WHERE agentId = @agentId
  928. END
  929. ELSE
  930. BEGIN
  931. DELETE FROM agentMasterMod WHERE agentId = @agentId
  932. INSERT INTO agentMasterMod
  933. ( agentId ,parentId , agentName , agentCode ,agentAddress ,agentCity ,agentCountryId ,agentCountry ,agentState ,
  934. agentDistrict ,agentZip ,agentLocation ,agentPhone1 ,agentPhone2 ,agentFax1 ,agentFax2 ,agentMobile1 ,agentMobile2 ,
  935. agentEmail1 ,agentEmail2 ,bankbranch,bankcode,bankaccountnumber,accountHolderName,businessOrgType ,businessType ,
  936. agentRole ,agentType ,allowAccountDeposit ,actAsBranch ,contractExpiryDate ,renewalFollowupDate ,agentGrp ,businessLicense ,
  937. agentBlock ,agentCompanyName ,companyAddress ,companyCity ,companyCountry ,companyState ,companyDistrict ,companyZip ,
  938. companyPhone1 ,companyPhone2 ,companyFax1 ,companyFax2 ,companyEmail1 ,companyEmail2 ,localTime ,localCurrency ,isActive ,
  939. agentDetails ,createdDate ,createdBy ,modType ,headMessage ,mapCodeInt ,mapCodeDom ,commCodeInt ,commCodeDom ,
  940. mapCodeIntAc ,mapCodeDomAc ,payOption ,contactPerson1 ,contactPerson2 ,isHeadOffice, routingCode
  941. )
  942. SELECT
  943. agentId ,parentId ,agentName ,agentCode ,agentAddress ,agentCity ,@agentCountryId ,agentCountry ,agentState ,
  944. agentDistrict ,agentZip ,agentLocation ,agentPhone1 ,agentPhone2 ,agentFax1 ,agentFax2 ,agentMobile1 ,agentMobile2 ,
  945. agentEmail1 ,agentEmail2 ,bankbranch,bankcode,bankaccountnumber,accountHolderName,businessOrgType ,businessType ,
  946. agentRole ,agentType ,allowAccountDeposit ,actAsBranch ,contractExpiryDate ,renewalFollowupDate ,agentGrp ,businessLicense ,
  947. agentBlock ,agentCompanyName ,companyAddress ,companyCity ,companyCountry ,companyState ,companyDistrict ,companyZip ,
  948. companyPhone1 ,companyPhone2 ,companyFax1 ,companyFax2 ,companyEmail1 ,companyEmail2 ,localTime ,localCurrency ,isActive ,
  949. agentDetails ,GETDATE() ,@user ,'D' ,@headMessage ,@mapCodeInt ,@mapCodeDom ,@commCodeInt ,@commCodeDom ,
  950. @mapCodeIntAc ,@mapCodeDomAc ,@payOption ,@contactPerson1 ,@contactPerson2 ,isHeadOffice, @partnerBankcode
  951. FROM agentMaster
  952. WHERE agentId = @agentId
  953. END
  954. COMMIT TRANSACTION
  955. EXEC proc_errorHandler 0,'Record deleted successfully', @agentId
  956. END
  957. ELSE IF @flag = 's'
  958. BEGIN
  959. IF @sortBy IS NULL
  960. SET @sortBy = 'agentId'
  961. IF @sortOrder IS NULL
  962. SET @sortOrder = 'ASC'
  963. SET @table = '(
  964. SELECT
  965. main.parentId
  966. ,main.agentId
  967. ,main.agentCode
  968. ,main.mapCodeInt
  969. ,main.agentName
  970. ,main.agentAddress
  971. ,main.agentCity
  972. ,agentLocation = adl.districtName
  973. ,main.agentDistrict
  974. ,main.agentState
  975. ,countryName = main.agentCountry
  976. ,main.agentPhone1
  977. ,main.agentPhone2
  978. ,main.agentType
  979. ,main.actAsBranch
  980. ,main.contractExpiryDate
  981. ,main.renewalFollowupDate
  982. ,main.isSettlingAgent
  983. ,main.haschanged
  984. ,agentType1 = sdv.detailTitle
  985. ,main.modifiedBy
  986. ,main.createdBy
  987. ,main.businessOrgType
  988. ,main.businessType
  989. ,main.agentBlock
  990. ,main.isActive
  991. FROM ' + @table
  992. + ' main
  993. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON main.agentType = sdv.valueId
  994. LEFT JOIN api_districtList adl WITH(NOLOCK) ON main.agentLocation = adl.districtCode
  995. WHERE main.agentType NOT IN (2905,2906)
  996. ) x'
  997. SET @sql_filter = ''
  998. IF @businessType IS NOT NULL
  999. SET @sql_filter = @sql_filter + ' AND businessType = ''' + CAST(@businessType AS VARCHAR) +''''
  1000. IF @haschanged IS NOT NULL
  1001. SET @sql_filter = @sql_filter + ' AND haschanged = ''' + CAST(@haschanged AS VARCHAR) + ''''
  1002. IF @agentCountry IS NOT NULL
  1003. SET @sql_filter = @sql_filter + ' AND ISNULL(countryName, '''') = ''' + CAST(@agentCountry AS VARCHAR) + ''''
  1004. IF @agentType IS NOT NULL
  1005. SET @sql_filter = @sql_filter + ' AND ISNULL(agentType, '''') = ' + CAST(@agentType AS VARCHAR)
  1006. IF @agentName IS NOT NULL
  1007. SET @sql_filter = @sql_filter + ' AND ISNULL(agentName, '''') LIKE ''%' + @agentName + '%'''
  1008. IF @agentLocation IS NOT NULL
  1009. SET @sql_filter = @sql_filter + ' AND ISNULL(agentLocation, '''') = ' + CAST(@agentLocation AS VARCHAR)
  1010. IF @agentId IS NOT NULL
  1011. SET @sql_filter = @sql_filter + ' AND agentId = ' + CAST(@agentId AS VARCHAR)
  1012. IF @parentId IS NOT NULL
  1013. SET @sql_filter = @sql_filter + ' AND parentId = '+ CAST(@parentId AS VARCHAR)
  1014. IF @businessOrgType IS NOT NULL
  1015. SET @sql_filter = @sql_filter + ' AND isnull(businessOrgType,'''') = ''' + CAST(@businessOrgType AS VARCHAR) + ''''
  1016. IF @businessType IS NOT NULL
  1017. SET @sql_filter = @sql_filter + ' AND isnull(businessType,'''') = ''' + CAST(@businessType AS VARCHAR) + ''''
  1018. IF @actAsBranch IS NOT NULL
  1019. SET @sql_filter = @sql_filter + ' AND ISNULL(actAsBranch, ''N'') = ''' + @actAsBranch + ''''
  1020. IF @populateBranch = 'Y'
  1021. SET @sql_filter = @sql_filter + ' AND (ISNULL(agentType, '''') = 2904 OR actAsBranch = ''Y'')'
  1022. IF @contractExpiryDate IS NOT NULL
  1023. SET @sql_filter = @sql_filter + ' AND contractExpiryDate = ''' + @contractExpiryDate + ''''
  1024. IF @renewalFollowupDate IS NOT NULL
  1025. SET @sql_filter = @sql_filter + ' AND renewalFollowupDate = ''' + @renewalFollowupDate + ''''
  1026. IF @isSettlingAgent IS NOT NULL
  1027. SET @sql_filter = @sql_filter + ' AND ISNULL(isSettlingAgent, ''N'') = ''' + @isSettlingAgent + ''''
  1028. IF @agentCode IS NOT NULL
  1029. SET @sql_filter = @sql_filter + ' AND agentCode = ''' + @agentCode + ''''
  1030. IF @mapCodeInt IS NOT NULL
  1031. SET @sql_filter = @sql_filter + ' AND mapCodeInt = ''' + @mapCodeInt + ''''
  1032. --IF @isInternal IS NOT NULL
  1033. -- SET @sql_filter = @sql_filter + ' AND isIntl = ''' + CASE WHEN @isInternal = 'Y' THEN '0' ELSE '1' END+ ''''
  1034. IF @agentBlock IS NOT NULL
  1035. BEGIN
  1036. IF @agentBlock = 'Y'
  1037. SET @agentBlock = 'B'
  1038. ELSE
  1039. SET @agentBlock = 'U'
  1040. SET @sql_filter = @sql_filter + ' AND ISNULL(agentBlock,''U'') = ''' + @agentBlock + ''''
  1041. END
  1042. IF @isActive IS NOT NULL
  1043. SET @sql_filter = @sql_filter + ' AND ISNULL(isActive,''Y'') = ''' + @isActive + ''''
  1044. SET @select_field_list = '
  1045. parentId
  1046. ,agentId
  1047. ,agentCode
  1048. ,mapCodeInt
  1049. ,agentName
  1050. ,agentAddress
  1051. ,agentCity
  1052. ,agentLocation
  1053. ,agentDistrict
  1054. ,agentState
  1055. ,agentPhone1
  1056. ,agentPhone2
  1057. ,agentType
  1058. ,agentType1
  1059. ,contractExpiryDate
  1060. ,renewalFollowupDate
  1061. ,isSettlingAgent
  1062. ,countryName
  1063. ,haschanged
  1064. ,modifiedBy
  1065. ,createdBy
  1066. ,isActive
  1067. ,agentBlock
  1068. ,businessType
  1069. '
  1070. --PRINT @table
  1071. EXEC dbo.proc_paging @table, @sql_filter,@select_field_list, @extra_field_list,@sortBy, @sortOrder, @pageSize,@pageNumber
  1072. END
  1073. ELSE IF @flag = 't'
  1074. BEGIN
  1075. SET @sql = '
  1076. SELECT
  1077. main.parentId
  1078. ,main.agentId
  1079. ,main.agentName
  1080. ,main.agentAddress
  1081. ,main.agentType
  1082. ,agentGroup = ag.detailTitle
  1083. ,agentType1 = sdv.detailTitle
  1084. ,main.haschanged
  1085. ,main.modifiedBy
  1086. FROM ' + @table
  1087. + ' main
  1088. LEFT JOIN staticDataValue sdv ON main.agentType = sdv.valueId
  1089. LEFT JOIN staticDataValue ag ON main.agentGrp = ag.valueId
  1090. WHERE ISNULL(main.parentId, '''') = ''' + ISNULL(@parentId,
  1091. '') + ''''
  1092. --PRINT @sql
  1093. EXECUTE (@sql)
  1094. END
  1095. ELSE IF @flag = 'reject'
  1096. BEGIN
  1097. IF NOT EXISTS ( SELECT 'X' FROM agentMaster WITH ( NOLOCK ) WHERE agentId = @agentId AND approvedBy IS NULL )
  1098. AND NOT EXISTS ( SELECT 'X' FROM agentMasterMod WITH ( NOLOCK ) WHERE agentId = @agentId )
  1099. BEGIN
  1100. EXEC proc_errorHandler 1, '<center>Modification approval is not pending.</center>', @agentId
  1101. RETURN
  1102. END
  1103. IF EXISTS ( SELECT 'X' FROM agentMaster WHERE agentId = @agentId AND approvedBy IS NULL )
  1104. BEGIN --New record
  1105. BEGIN TRANSACTION
  1106. SET @modType = 'Reject'
  1107. EXEC [dbo].proc_GetColumnToRow @logParamMain, @logIdentifier, @agentId, @oldValue OUTPUT
  1108. INSERT INTO #msg( errorCode , msg , id)
  1109. EXEC proc_applicationLogs 'i', NULL, @modType, @tableAlias, @agentId, @user, @oldValue, @newValue
  1110. IF EXISTS ( SELECT 'x' FROM #msg WHERE errorCode <> '0' )
  1111. BEGIN
  1112. IF @@TRANCOUNT > 0
  1113. ROLLBACK TRANSACTION
  1114. EXEC proc_errorHandler 1, 'Failed to reject the transaction.', @agentId
  1115. RETURN
  1116. END
  1117. DELETE FROM agentMaster WHERE agentId = @agentId
  1118. IF @@TRANCOUNT > 0
  1119. COMMIT TRANSACTION
  1120. END
  1121. ELSE
  1122. BEGIN
  1123. BEGIN TRANSACTION
  1124. SET @modType = 'Reject'
  1125. EXEC [dbo].proc_GetColumnToRow @logParamMain, @logIdentifier, @agentId, @oldValue OUTPUT
  1126. INSERT INTO #msg ( errorCode , msg , id )
  1127. EXEC proc_applicationLogs 'i', NULL, @modType, @tableAlias, @agentId, @user, @oldValue, @newValue
  1128. IF EXISTS ( SELECT 'x' FROM #msg WHERE errorCode <> '0' )
  1129. BEGIN
  1130. IF @@TRANCOUNT > 0
  1131. ROLLBACK TRANSACTION
  1132. EXEC proc_errorHandler 1, 'Failed to reject the transaction.', @agentId
  1133. RETURN
  1134. END
  1135. DELETE FROM agentMasterMod WHERE @agentId = @agentId
  1136. IF @@TRANCOUNT > 0
  1137. COMMIT TRANSACTION
  1138. END
  1139. EXEC proc_errorHandler 0, 'Changes rejected successfully.', @agentId
  1140. END
  1141. ELSE IF @flag = 'approve'
  1142. BEGIN
  1143. SELECT @intlSuperAgentId = DBO.FNAGetIntlAgentId();
  1144. IF NOT EXISTS ( SELECT 'X' FROM agentMaster WITH ( NOLOCK ) WHERE agentId = @agentId AND approvedBy IS NULL )
  1145. AND NOT EXISTS ( SELECT 'X' FROM agentMasterMod WITH ( NOLOCK ) WHERE agentId = @agentId )
  1146. BEGIN
  1147. EXEC proc_errorHandler 1, '<center>Modification approval is not pending.</center>',@agentId
  1148. RETURN
  1149. END
  1150. BEGIN TRANSACTION
  1151. IF EXISTS ( SELECT 'X' FROM agentMaster(nolock) WHERE approvedBy IS NULL AND agentId = @agentId )
  1152. SET @modType = 'I'
  1153. ELSE
  1154. SELECT @modType = modType , @payOption = payOption FROM agentMasterMod(nolock) WHERE agentId = @agentId
  1155. IF @modType = 'I'
  1156. BEGIN --New record
  1157. UPDATE agentMaster SET isActive = 'Y' ,
  1158. approvedBy = @user ,
  1159. approvedDate = GETDATE()
  1160. WHERE agentId = @agentId
  1161. EXEC [dbo].proc_GetColumnToRow @logParamMain,@logIdentifier,@agentId,@newValue OUTPUT
  1162. --Account Creation (for partners)
  1163. IF EXISTS ( SELECT 'X' FROM agentMaster(nolock) WHERE agentId = @agentId AND ISNULL(isSettlingAgent, 'N') = 'Y' AND isApiPartner = 1 AND ISNULL(isIntl, 0) = 0 AND parentId <> @intlSuperAgentId)
  1164. BEGIN
  1165. SELECT @agentName = agentName+' - Principle' FROM agentMaster(NOLOCK) WHERE agentId = @agentId
  1166. SELECT @acct_num = MAX(CAST(ACCT_NUM as bigint)+1) FROM FastMoneyPro_Account.dbo.ac_master (NOLOCK) WHERE gl_code='77'
  1167. SET @acct_num = ISNULL(@acct_num, 771000001)
  1168. ----## AUTO CREATE LEDGER FOR PARTNER AGENT
  1169. insert into FastMoneyPro_Account.dbo.ac_master (acct_num, acct_name,gl_code, agent_id,
  1170. acct_ownership,dr_bal_lim, acct_rpt_code,acct_opn_date,clr_bal_amt, system_reserved_amt,
  1171. lien_amt, utilised_amt, available_amt,created_date,created_by,company_id)
  1172. values(@acct_num,@agentName,'77', @agentId,'c',0,'TP',getdate(),0,0,0,0,0,getdate(),@user,1)
  1173. SELECT @acct_num = MAX(cast(ACCT_NUM as bigint)+1) ,@agentName = replace(@agentName,'Principle','Comm Payable')
  1174. FROM FastMoneyPro_Account.dbo.ac_master (NOLOCK) WHERE gl_code='78'
  1175. SET @acct_num = ISNULL(@acct_num, 781000001)
  1176. insert into FastMoneyPro_Account.dbo.ac_master (acct_num, acct_name,gl_code, agent_id,
  1177. acct_ownership,dr_bal_lim, acct_rpt_code,acct_opn_date,clr_bal_amt, system_reserved_amt,
  1178. lien_amt, utilised_amt, available_amt,created_date,created_by,company_id)
  1179. values(@acct_num,@agentName,'78', @agentId,'c',0,'TC',getdate(),0,0,0,0,0,getdate(),@user,1)
  1180. INSERT INTO creditLimit (
  1181. agentId ,currency , limitAmt ,perTopUpAmt ,maxLimitAmt ,expiryDate ,isActive ,createdBy ,createdDate ,approvedBy
  1182. ,approvedDate ,topUpTillYesterday ,topUpToday ,todaysSent ,todaysPaid ,todaysCancelled ,lienAmt
  1183. )
  1184. SELECT @agentId ,5 ,0 ,0 ,0 ,@contractExpiryDate ,'Y' ,@user ,GETDATE() ,@user
  1185. ,GETDATE() ,0 ,0 ,0 ,0 ,0 ,0
  1186. END
  1187. ----Account Creation (for own branches)
  1188. --IF EXISTS ( SELECT 'X' FROM agentMaster(nolock) WHERE agentId = @agentId AND ISNULL(isSettlingAgent, 'N') = 'Y' AND isApiPartner = 0 AND ISNULL(isIntl, 0) = 0 AND parentId = @intlSuperAgentId AND ISNULL(actAsBranch, 'N') = 'Y')
  1189. --BEGIN
  1190. -- SELECT @agentName = agentName+' - Receivable' FROM agentMaster(NOLOCK) WHERE agentId = @agentId
  1191. -- SELECT @acct_num = MAX(CAST(ACCT_NUM as bigint)+1) FROM FastMoneyPro_Account.dbo.ac_master (NOLOCK) WHERE gl_code='104'
  1192. -- SET @acct_num = ISNULL(@acct_num, 1041000001)
  1193. -- ----## AUTO CREATE LEDGER FOR PARTNER AGENT, BR = BRANCH RECEIVABLE
  1194. -- insert into FastMoneyPro_Account.dbo.ac_master (acct_num, acct_name,gl_code, agent_id,
  1195. -- acct_ownership,dr_bal_lim, acct_rpt_code,acct_opn_date,clr_bal_amt, system_reserved_amt,
  1196. -- lien_amt, utilised_amt, available_amt,created_date,created_by,company_id)
  1197. -- values(@acct_num,@agentName,'104', @agentId,'c',0,'BR',getdate(),0,0,0,0,0,getdate(),@user,1)
  1198. -- INSERT INTO creditLimit (
  1199. -- agentId ,currency , limitAmt ,perTopUpAmt ,maxLimitAmt ,expiryDate ,isActive ,createdBy ,createdDate ,approvedBy
  1200. -- ,approvedDate ,topUpTillYesterday ,topUpToday ,todaysSent ,todaysPaid ,todaysCancelled ,lienAmt
  1201. -- )
  1202. -- SELECT @agentId ,5 ,0 ,0 ,0 ,@contractExpiryDate ,'Y' ,@user ,GETDATE() ,@user
  1203. -- ,GETDATE() ,0 ,0 ,0 ,0 ,0 ,0
  1204. --END
  1205. --Account Creation (for partners)
  1206. --IF EXISTS ( SELECT 'X' FROM agentMaster(nolock)
  1207. -- WHERE agentId = @agentId AND ISNULL(isSettlingAgent, 'N') = 'Y'
  1208. -- AND ISNULL(isIntl, 0) = 1 AND isApiPartner = 0
  1209. -- AND parentId = @intlSuperAgentId AND ISNULL(actAsBranch, 'N') = 'N')
  1210. --BEGIN
  1211. -- SELECT @agentName = agentName+' - Principle Receivable' FROM agentMaster(NOLOCK) WHERE agentId = @agentId
  1212. -- SELECT @acct_num = MAX(CAST(ACCT_NUM as bigint)+1) FROM FastMoneyPro_Account.dbo.ac_master (NOLOCK) WHERE gl_code='105'
  1213. -- SET @acct_num = ISNULL(@acct_num, 1051000001)
  1214. -- ----## AUTO CREATE LEDGER FOR PARTNER AGENT, AR = AGENT RECEIVABLE
  1215. -- insert into FastMoneyPro_Account.dbo.ac_master (acct_num, acct_name,gl_code, agent_id,
  1216. -- acct_ownership,dr_bal_lim, acct_rpt_code,acct_opn_date,clr_bal_amt, system_reserved_amt,
  1217. -- lien_amt, utilised_amt, available_amt,created_date,created_by,company_id)
  1218. -- values(@acct_num,@agentName,'105', @agentId,'c',0,'APR',getdate(),0,0,0,0,0,getdate(),@user,1)
  1219. -- insert into FastMoneyPro_Account.dbo.ac_master (acct_num, acct_name,gl_code, agent_id,
  1220. -- acct_ownership,dr_bal_lim, acct_rpt_code,acct_opn_date,clr_bal_amt, system_reserved_amt,
  1221. -- lien_amt, utilised_amt, available_amt,created_date,created_by,company_id)
  1222. -- values(@acct_num+1,replace(@agentName,'Principle Receivable','Comm Payable'),'105', @agentId,'c',0,'ACP',getdate(),0,0,0,0,0,getdate(),@user,1)
  1223. -- INSERT INTO creditLimit (
  1224. -- agentId ,currency , limitAmt ,perTopUpAmt ,maxLimitAmt ,expiryDate ,isActive ,createdBy ,createdDate ,approvedBy
  1225. -- ,approvedDate ,topUpTillYesterday ,topUpToday ,todaysSent ,todaysPaid ,todaysCancelled ,lienAmt
  1226. -- )
  1227. -- SELECT @agentId ,5 ,0 ,0 ,0 ,@contractExpiryDate ,'Y' ,@user ,GETDATE() ,@user
  1228. -- ,GETDATE() ,0 ,0 ,0 ,0 ,0 ,0
  1229. --END
  1230. END
  1231. ELSE
  1232. IF @modType = 'U'
  1233. BEGIN
  1234. EXEC [dbo].proc_GetColumnToRow @logParamMain,@logIdentifier,@agentId,@oldValue OUTPUT
  1235. UPDATE main
  1236. SET main.parentId = mode.parentId ,
  1237. main.agentName = mode.agentName ,
  1238. main.agentAddress = mode.agentAddress ,
  1239. main.agentCity = mode.agentCity ,
  1240. main.agentCountry = mode.agentCountry ,
  1241. main.agentState = mode.agentState ,
  1242. main.agentDistrict = mode.agentDistrict ,
  1243. main.agentZip = mode.agentZip ,
  1244. main.agentLocation = mode.agentLocation ,
  1245. main.agentPhone1 = mode.agentPhone1 ,
  1246. main.agentPhone2 = mode.agentPhone2 ,
  1247. main.agentFax1 = mode.agentFax1 ,
  1248. main.agentFax2 = mode.agentFax2 ,
  1249. main.agentMobile1 = mode.agentMobile1 ,
  1250. main.agentMobile2 = mode.agentMobile2 ,
  1251. main.agentEmail1 = mode.agentEmail1 ,
  1252. main.agentEmail2 = mode.agentEmail2 ,
  1253. main.bankbranch=mode.bankBranch,
  1254. main.bankCode=mode.bankCode,
  1255. main.bankaccountnumber=mode.bankaccountnumber,
  1256. main.accountholdername=mode.accountholdername,
  1257. main.businessOrgType = mode.businessOrgType ,
  1258. main.businessType = mode.businessType ,
  1259. main.agentRole = mode.agentRole ,
  1260. main.agentType = mode.agentType ,
  1261. main.allowAccountDeposit = mode.allowAccountDeposit ,
  1262. main.contractExpiryDate = mode.contractExpiryDate ,
  1263. main.renewalFollowupDate = mode.renewalFollowupDate ,
  1264. main.agentGrp = mode.agentGrp ,
  1265. main.businessLicense = mode.businessLicense ,
  1266. main.agentBlock = mode.agentBlock ,
  1267. main.agentCompanyName = mode.agentCompanyName ,
  1268. main.companyAddress = mode.companyAddress ,
  1269. main.companyCity = mode.companyCity ,
  1270. main.companyCountry = mode.companyCountry ,
  1271. main.companyState = mode.companyState ,
  1272. main.companyDistrict = mode.companyDistrict ,
  1273. main.companyZip = mode.companyZip ,
  1274. main.companyPhone1 = mode.companyPhone1 ,
  1275. main.companyPhone2 = mode.companyPhone2 ,
  1276. main.companyFax1 = mode.companyFax1 ,
  1277. main.companyFax2 = mode.companyFax2 ,
  1278. main.companyEmail1 = mode.companyEmail1 ,
  1279. main.companyEmail2 = mode.companyEmail2 ,
  1280. main.localTime = mode.localTime ,
  1281. main.localCurrency = mode.localCurrency ,
  1282. main.agentDetails = mode.agentDetails ,
  1283. main.headMessage = mode.headMessage ,
  1284. main.mapCodeInt = mode.mapCodeInt ,
  1285. main.mapCodeDom = mode.mapCodeDom ,
  1286. main.commCodeInt = mode.commCodeInt ,
  1287. main.commCodeDom = mode.commCodeDom ,
  1288. main.mapCodeIntAc = mode.mapCodeIntAc ,
  1289. main.mapCodeDomAc = mode.mapCodeDomAc ,
  1290. main.payOption = mode.payOption ,
  1291. main.modifiedDate = GETDATE() ,
  1292. main.modifiedBy = @user ,
  1293. main.isActive = mode.isActive ,
  1294. main.agentSettCurr = mode.agentSettCurr ,
  1295. main.contactPerson1 = mode.contactPerson1 ,
  1296. main.contactPerson2 = mode.contactPerson2 ,
  1297. main.isHeadOffice = mode.isHeadOffice ,
  1298. main.isIntl = mode.IsIntl ,
  1299. main.isApiPartner = mode.isApiPartner,
  1300. main.routingCode = mode.routingCode
  1301. FROM agentMaster main
  1302. INNER JOIN agentMasterMod mode ON mode.agentId = main.agentId
  1303. WHERE mode.agentId = @agentId
  1304. EXEC [dbo].proc_GetColumnToRow @logParamMain,@logIdentifier,@agentId,@newValue OUTPUT
  1305. --Agent Account Creation
  1306. --IF EXISTS ( SELECT 'X' FROM agentMaster WITH ( NOLOCK ) WHERE agentId = @agentId AND ISNULL(isSettlingAgent,'N') = 'Y' )
  1307. --BEGIN
  1308. --IF NOT EXISTS ( SELECT 'X' FROM creditLimit WITH ( NOLOCK ) WHERE agentId = @agentId )
  1309. --BEGIN
  1310. -- SELECT @agentCountry = agentCountry ,@contractExpiryDate = contractExpiryDate
  1311. -- FROM agentMaster WITH ( NOLOCK )
  1312. -- WHERE agentId = @agentId
  1313. -- INSERT INTO creditLimit (
  1314. -- agentId ,currency ,limitAmt ,perTopUpAmt ,maxLimitAmt ,expiryDate ,isActive ,createdBy ,createdDate ,approvedBy ,
  1315. -- approvedDate ,topUpTillYesterday ,topUpToday ,todaysSent ,todaysPaid ,todaysCancelled ,lienAmt
  1316. -- )
  1317. -- SELECT @agentId ,'KRW' ,0 ,0 ,0 ,@contractExpiryDate ,'Y' ,@user ,GETDATE() ,@user ,
  1318. -- GETDATE() ,0 ,0 ,0 ,0 ,0 ,0
  1319. -- END
  1320. --END
  1321. --End Commission Account Creation
  1322. END
  1323. ELSE
  1324. IF @modType = 'D'
  1325. BEGIN
  1326. EXEC [dbo].proc_GetColumnToRow @logParamMain,@logIdentifier,@agentId,@oldValue OUTPUT
  1327. UPDATE agentMaster
  1328. SET isDeleted = 'Y' ,isActive = 'N' ,modifiedDate = GETDATE() ,modifiedBy = @user
  1329. WHERE agentId = @agentId
  1330. END
  1331. DELETE FROM agentMasterMod WHERE agentId = @agentId
  1332. INSERT INTO #msg ( errorCode , msg ,id)
  1333. EXEC proc_applicationLogs 'i',NULL, @modType,@tableAlias, @agentId,@user, @oldValue,@newValue, @module
  1334. IF EXISTS ( SELECT 'x' FROM #msg WHERE errorCode <> '0' )
  1335. BEGIN
  1336. IF @@TRANCOUNT > 0
  1337. ROLLBACK TRANSACTION
  1338. EXEC proc_errorHandler 1,'Could not approve the changes.',@agentId
  1339. RETURN
  1340. END
  1341. IF @@TRANCOUNT > 0
  1342. COMMIT TRANSACTION
  1343. EXEC proc_errorHandler 0,'Changes approved successfully.',@agentId
  1344. END
  1345. ELSE IF @flag = 'AGENTDDL' --AGENT BUT NOT ACT AS BRANCH & SUPER AGENT LIST ONLY ## using only in message setting
  1346. BEGIN
  1347. SELECT agentId ,
  1348. agentName
  1349. FROM agentMaster
  1350. WHERE agentCountryId = @agentCountryId
  1351. AND agentType IN ( 2902, 2903 )
  1352. AND ISNULL(actAsBranch, 'N') = 'N'
  1353. END
  1354. ELSE IF @flag = 's2'
  1355. BEGIN
  1356. IF @sortBy IS NULL
  1357. SET @sortBy = 'agentId'
  1358. IF @sortOrder IS NULL
  1359. SET @sortOrder = 'ASC'
  1360. SET @table = '(
  1361. SELECT
  1362. main.parentId
  1363. ,main.agentId
  1364. ,main.agentCode
  1365. ,main.mapCodeInt
  1366. ,main.agentName
  1367. ,main.agentAddress
  1368. ,main.agentCity
  1369. ,agentLocation = adl.districtName
  1370. ,main.agentDistrict
  1371. ,main.agentState
  1372. ,countryName = main.agentCountry
  1373. ,main.agentPhone1
  1374. ,main.agentPhone2
  1375. ,main.agentType
  1376. ,main.actAsBranch
  1377. ,main.contractExpiryDate
  1378. ,main.renewalFollowupDate
  1379. ,main.isSettlingAgent
  1380. ,main.haschanged
  1381. ,agentType1 = sdv.detailTitle
  1382. ,main.modifiedBy
  1383. ,main.createdBy
  1384. ,main.businessOrgType
  1385. ,main.businessType
  1386. ,main.agentBlock
  1387. ,main.isActive
  1388. ,link = CASE WHEN main.agentRole = ''B'' THEN ''<a href="SendingLimit/List.aspx?agentId='' + CAST(main.agentId AS VARCHAR) + ''">Collection Limit</a> | <a href="ReceivingLimit/List.aspx?agentId='' + CAST(main.agentId AS VARCHAR) + ''">Receiving Limit<
  1389. /a>'' WHEN main.agentRole = ''S'' THEN ''<a href="SendingLimit/List.aspx?agentId='' + CAST(main.agentId AS VARCHAR) + ''">Collection Limit</a>''
  1390. WHEN main.agentRole = ''R'' THEN ''<a href="ReceivingLimit/List.aspx?agentId='' + CAST(main.agentId AS VARCHAR) + ''">Receiving Limit</a>''
  1391. ELSE ''Please define operation type'' END
  1392. FROM ' + @table
  1393. + ' main
  1394. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON main.agentType = sdv.valueId
  1395. LEFT JOIN api_districtList adl WITH(NOLOCK) ON main.agentLocation = adl.districtCode
  1396. WHERE main.agentType = 2903 AND main.agentRole IS NOT NULL
  1397. ) x'
  1398. SET @sql_filter = ''
  1399. IF @haschanged IS NOT NULL
  1400. SET @sql_filter = @sql_filter + ' AND haschanged = ''' + CAST(@haschanged AS VARCHAR) + ''''
  1401. IF @agentCountry IS NOT NULL
  1402. SET @sql_filter = @sql_filter + ' AND ISNULL(countryName, '''') LIKE ''%' + CAST(@agentCountry AS VARCHAR) + '%'''
  1403. IF @agentType IS NOT NULL
  1404. SET @sql_filter = @sql_filter + ' AND ISNULL(agentType, '''') = ' + CAST(@agentType AS VARCHAR)
  1405. IF @agentName IS NOT NULL
  1406. SET @sql_filter = @sql_filter + ' AND ISNULL(agentName, '''') LIKE ''%' + @agentName + '%'''
  1407. IF @agentLocation IS NOT NULL
  1408. SET @sql_filter = @sql_filter + ' AND ISNULL(agentLocation, '''') = ' + CAST(@agentLocation AS VARCHAR)
  1409. IF @agentId IS NOT NULL
  1410. SET @sql_filter = @sql_filter + ' AND agentId = ' + CAST(@agentId AS VARCHAR)
  1411. IF @parentId IS NOT NULL
  1412. SET @sql_filter = @sql_filter + ' AND parentId = ' + CAST(@parentId AS VARCHAR)
  1413. IF @businessOrgType IS NOT NULL
  1414. SET @sql_filter = @sql_filter + ' AND isnull(businessOrgType,'''') = ''' + CAST(@businessOrgType AS VARCHAR) + ''''
  1415. IF @businessType IS NOT NULL
  1416. SET @sql_filter = @sql_filter + ' AND isnull(businessType,'''') = ''' + CAST(@businessType AS VARCHAR) + ''''
  1417. IF @actAsBranch IS NOT NULL
  1418. SET @sql_filter = @sql_filter + ' AND ISNULL(actAsBranch, ''N'') = ''' + @actAsBranch + ''''
  1419. IF @populateBranch = 'Y'
  1420. SET @sql_filter = @sql_filter + ' AND (ISNULL(agentType, '''') = 2904 OR actAsBranch = ''Y'')'
  1421. IF @contractExpiryDate IS NOT NULL
  1422. SET @sql_filter = @sql_filter + ' AND contractExpiryDate = ''' + @contractExpiryDate + ''''
  1423. IF @renewalFollowupDate IS NOT NULL
  1424. SET @sql_filter = @sql_filter + ' AND renewalFollowupDate = ''' + @renewalFollowupDate + ''''
  1425. IF @agentCode IS NOT NULL
  1426. SET @sql_filter = @sql_filter + ' AND agentCode = ''' + @agentCode + ''''
  1427. IF @mapCodeInt IS NOT NULL
  1428. SET @sql_filter = @sql_filter + ' AND mapCodeInt = ''' + @mapCodeInt + ''''
  1429. IF @agentBlock IS NOT NULL
  1430. BEGIN
  1431. IF @agentBlock = 'Y'
  1432. SET @agentBlock = 'B'
  1433. ELSE
  1434. SET @agentBlock = 'U'
  1435. SET @sql_filter = @sql_filter + ' AND agentBlock = ''' + @agentBlock + ''''
  1436. END
  1437. IF @isActive IS NOT NULL
  1438. SET @sql_filter = @sql_filter + ' AND isActive = ''' + @isActive + ''''
  1439. SET @select_field_list = '
  1440. parentId
  1441. ,agentId
  1442. ,agentCode
  1443. ,mapCodeInt
  1444. ,agentName
  1445. ,agentAddress
  1446. ,agentCity
  1447. ,agentLocation
  1448. ,agentDistrict
  1449. ,agentState
  1450. ,agentPhone1
  1451. ,agentPhone2
  1452. ,agentType
  1453. ,agentType1
  1454. ,contractExpiryDate
  1455. ,renewalFollowupDate
  1456. ,isSettlingAgent
  1457. ,countryName
  1458. ,haschanged
  1459. ,modifiedBy
  1460. ,createdBy
  1461. ,isActive
  1462. ,agentBlock
  1463. ,link
  1464. '
  1465. EXEC dbo.proc_paging @table, @sql_filter, @select_field_list, @extra_field_list, @sortBy, @sortOrder, @pageSize, @pageNumber
  1466. RETURN
  1467. END
  1468. ELSE IF @flag = 'cobankList'
  1469. BEGIN
  1470. SELECT agentId ,
  1471. agentName ,
  1472. agentType
  1473. FROM agentMaster (NOLOCK)
  1474. WHERE agentGrp IN ( '8026', '9906' )
  1475. AND agentType = '2903'
  1476. AND ISNULL(isDeleted, 'N') <> 'Y'
  1477. ORDER BY agentName ASC
  1478. RETURN
  1479. END
  1480. ELSE IF @flag = 'co-agent' -- cooperative branch list
  1481. BEGIN
  1482. SELECT agentId ,
  1483. agentName ,
  1484. agentType ,
  1485. parentId
  1486. FROM agentMaster (NOLOCK)
  1487. WHERE ISNULL(isDeleted, 'N') <> 'Y'
  1488. AND parentId = @agentId
  1489. UNION ALL
  1490. SELECT agentId ,
  1491. agentName ,
  1492. agentType ,
  1493. parentId
  1494. FROM agentMaster (NOLOCK)
  1495. WHERE ISNULL(isDeleted, 'N') <> 'Y'
  1496. AND agentId = @agentId
  1497. RETURN
  1498. END
  1499. IF @flag ='getBranchList'
  1500. BEGIN
  1501. SELECT agentId,agentName FROM dbo.agentMaster WHERE parentId='393877'
  1502. AND ISNULL(isActive,'Y')<>'N'
  1503. END
  1504. IF @flag ='onlineBranchList'
  1505. BEGIN
  1506. SELECT agentId,agentName, agentAddress, agentPhone1, agentEmail1 FROM dbo.agentMaster WHERE parentId='393877' AND actAsBranch = 'Y' AND agentId not in( '394395','394389')
  1507. AND ISNULL(isActive,'Y')<>'N'
  1508. SELECT agentId,agentName, agentAddress, CASE agentPhone1 WHEN '1' THEN '' ELSE agentPhone1 END AS agentPhone1, agentEmail1 FROM dbo.agentMaster WHERE parentId='393877' AND actAsBranch = 'N'
  1509. AND ISNULL(isActive,'Y')<>'N'
  1510. END
  1511. END TRY
  1512. BEGIN CATCH
  1513. IF @@TRANCOUNT > 0
  1514. ROLLBACK TRANSACTION
  1515. SELECT 1 error_code , ERROR_MESSAGE() mes , NULL id
  1516. END CATCH