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.

1653 lines
122 KiB

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