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.

1664 lines
123 KiB

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