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.

722 lines
45 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sendTransactionLoadData] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. /*
  9. proc_sendTransactionLoadData 'b', 'admin'
  10. EXEC proc_sendTransactionLoadData @flag = 'sc', @agentId = '48', @deliveryMethod = '1', @amount = '1111111', @mode = 'ta', @user = 'admin'
  11. */
  12. CREATE proc [dbo].[proc_sendTransactionLoadData] (
  13. @flag VARCHAR(50)
  14. ,@user VARCHAR(30) = NULL
  15. ,@controlNo VARCHAR(30) = NULL
  16. ,@sBranch INT = NULL
  17. ,@sCountry INT = NULL
  18. ,@sFirstName VARCHAR(30) = NULL
  19. ,@sMiddleName VARCHAR(30) = NULL
  20. ,@sLastName1 VARCHAR(30) = NULL
  21. ,@sLastName2 VARCHAR(30) = NULL
  22. ,@sPhone VARCHAR(30) = NULL
  23. ,@sMemId VARCHAR(30) = NULL
  24. ,@sId BIGINT = NULL
  25. ,@sTranId VARCHAR(50) = NULL
  26. ,@rCountry INT = NULL
  27. ,@rFirstName VARCHAR(30) = NULL
  28. ,@rMiddleName VARCHAR(30) = NULL
  29. ,@rLastName1 VARCHAR(30) = NULL
  30. ,@rLastName2 VARCHAR(30) = NULL
  31. ,@rPhone VARCHAR(30) = NULL
  32. ,@rMemId VARCHAR(30) = NULL
  33. ,@rId BIGINT = NULL
  34. ,@pSuperAgent INT = NULL
  35. ,@pCountry INT = NULL
  36. ,@pCountryName VARCHAR(100) = NULL
  37. ,@collCurr VARCHAR(3) = NULL
  38. ,@pCurrency VARCHAR(3) = NULL
  39. ,@deliveryMethod VARCHAR(50) = NULL
  40. ,@pState VARCHAR(100) = NULL
  41. ,@pDistrict VARCHAR(100) = NULL
  42. ,@pLocation INT = NULL
  43. ,@pBankBranch INT = NULL
  44. ,@pCity VARCHAR(30) = NULL
  45. ,@pPayer VARCHAR(30) = NULL
  46. ,@customerId INT = NULL
  47. ,@agentId INT = NULL
  48. ,@senderId INT = NULL
  49. ,@benId INT = NULL
  50. ,@amount MONEY = NULL
  51. ,@mode VARCHAR(10) = NULL
  52. ,@msgType CHAR(1) = NULL
  53. ,@sortBy VARCHAR(50) = NULL
  54. ,@sortOrder VARCHAR(5) = NULL
  55. ,@pageSize INT = NULL
  56. ,@pageNumber INT = NULL
  57. )
  58. AS
  59. --SELECT * FROM customers
  60. --select * from customerDocument
  61. --select * from customerIdentity
  62. DECLARE
  63. @select_field_list VARCHAR(MAX)
  64. ,@extra_field_list VARCHAR(MAX)
  65. ,@table VARCHAR(MAX)
  66. ,@sql_filter VARCHAR(MAX)
  67. DECLARE @ssAgent INT = NULL
  68. ,@sAgent INT = NULL
  69. ,@rsAgent INT = NULL
  70. ,@rAgent INT = NULL
  71. ,@code VARCHAR(50)
  72. ,@userName VARCHAR(50)
  73. ,@password VARCHAR(50)
  74. SET NOCOUNT ON
  75. SET XACT_ABORT ON
  76. --select * from customers
  77. SELECT @pageSize = 15, @pageNumber = 1
  78. --EXEC proc_GetAPI @user OUTPUT,@code OUTPUT, @userName OUTPUT, @password OUTPUT
  79. IF @flag = 'cti' --All transaction information (sender, receiver, payout)
  80. BEGIN
  81. SELECT DISTINCT
  82. c.customerId
  83. ,c.membershipId
  84. ,Name = c.firstName + ISNULL(' ' + c.middleName, '') + ISNULL(' ' + c.lastName1, '') + ISNULL(' ' + c.lastName2, '')
  85. ,Country = cm.countryName
  86. ,Address
  87. ,[State] = csm.stateName
  88. ,Phone = COALESCE(mobile, homePhone, workPhone)
  89. ,city
  90. FROM customers c WITH(NOLOCK)
  91. LEFT JOIN countryMaster cm WITH(NOLOCK) ON c.country = cm.countryId
  92. LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON c.state = csm.stateId
  93. WHERE c.customerId = @senderId
  94. SELECT DISTINCT
  95. c.customerId
  96. ,c.membershipId
  97. ,Name = c.firstName + ISNULL( ' ' + c.middleName, '') + ISNULL( ' ' + c.lastName1, '') + ISNULL( ' ' + c.lastName2, '')
  98. ,Country = cm.countryName
  99. ,Address
  100. ,[State] = csm.stateName
  101. ,Phone = COALESCE(mobile, homePhone, workPhone)
  102. ,city
  103. FROM customers c WITH(NOLOCK)
  104. LEFT JOIN countryMaster cm WITH(NOLOCK) ON c.country = cm.countryId
  105. LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON c.state = csm.stateId
  106. WHERE c.customerId = @benId
  107. SELECT
  108. agentId = NULL
  109. ,agentCode = NULL
  110. ,name = 'Any'
  111. ,address = NULL
  112. ,city = loc.districtName
  113. ,state = csm.stateName
  114. ,district = dist.districtName
  115. ,Phone = NULL
  116. ,country = cm.countryName
  117. ,trn.createdDate
  118. FROM remitTran trn WITH(NOLOCK)
  119. LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON trn.pState = csm.stateId
  120. LEFT JOIN api_districtList loc WITH(NOLOCK) ON trn.pLocation = loc.districtCode
  121. LEFT JOIN zoneDistrictMap dist WITH(NOLOCK) ON trn.pDistrict = dist.districtId
  122. LEFT JOIN countryMaster cm WITH(NOLOCK) ON trn.pCountry = cm.countryId
  123. WHERE trn.controlNo = @controlNo
  124. END
  125. ELSE IF @flag = 'msg'
  126. BEGIN
  127. DECLARE @headMsg NVARCHAR(MAX)
  128. ,@commonMsg NVARCHAR(MAX)
  129. ,@countrySpecificMsg NVARCHAR(MAX)
  130. SELECT @sAgent = agentId FROM applicationUsers WHERE userName = @user
  131. SELECT @sCountry = agentCountry FROM agentMaster WHERE agentId = @sAgent
  132. --Head Message
  133. SELECT @headMsg = headMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') <> 'Y'
  134. IF(@headMsg IS NULL)
  135. SELECT @headMsg = headMsg FROM message WHERE countryId IS NULL AND headMsg IS NOT NULL AND ISNULL(isDeleted, 'N') <> 'Y'
  136. --Common Message
  137. SELECT @commonMsg = commonMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') <> 'Y'
  138. IF(@commonMsg IS NULL)
  139. SELECT @commonMsg = commonMsg FROM message WHERE countryId IS NULL AND commonMsg IS NOT NULL AND ISNULL(isDeleted, 'N') <> 'Y'
  140. --Country Specific Message
  141. SELECT @countrySpecificMsg = countrySpecificMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') <> 'Y'
  142. IF(@countrySpecificMsg IS NULL)
  143. SELECT @countrySpecificMsg = countrySpecificMsg FROM message WHERE countryId IS NULL AND countrySpecificMsg IS NOT NULL AND msgType = @msgType AND ISNULL(isDeleted, 'N') <> 'Y'
  144. SELECT @headMsg AS headMsg,@commonMsg AS commonMsg, @countrySpecificMsg AS countrySpecificMsg
  145. END
  146. ELSE IF @flag = 'sc'
  147. BEGIN
  148. --EXEC proc_sendTransactionLoadData @flag = 'sc', @amount= '100000', @pLocation = '109'
  149. DECLARE @payoutMethod CHAR(1)
  150. --SELECT
  151. -- @sBranch = agentId
  152. --FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  153. --SELECT SC = ISNULL([dbo].FNAGetSC(@sBranch, @pSuperAgent, @pCountry, @pDistrict, @agentId , @deliveryMethod, @amount), 0)
  154. --DOMESTIC Service Charge:
  155. --SELECT @payoutMethod = CASE WHEN @deliveryMethod = 2201 THEN 'c'
  156. -- WHEN @deliveryMethod = 2202 THEN 'd' END
  157. Exec [192.168.2.1].ime_plus_01.dbo.spa_SOAP_Domestic_ServiceCharge
  158. @code,@userName,@password,'1234',@amount, 'c', @pLocation
  159. END
  160. ELSE IF @flag = 'scTBL'
  161. BEGIN
  162. DECLARE
  163. @masterId INT
  164. ,@masterType CHAR(1)
  165. ,@sc MONEY
  166. IF @sBranch IS NULL
  167. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  168. DECLARE @deliveryMethodId INT
  169. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod
  170. IF @deliveryMethod = 'Bank Deposit'
  171. BEGIN
  172. SELECT @pLocation = agentLocation FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  173. END
  174. SELECT
  175. @masterId = masterId
  176. ,@masterType = masterType
  177. ,@sc = amount
  178. FROM [dbo].FNAGetSC(@sBranch, @pSuperAgent, @pCountry, @pLocation, @agentId, @deliveryMethodId, @amount, @collCurr)
  179. IF(@masterType = 'S')
  180. BEGIN
  181. SELECT fromAmt, toAmt, pcnt, maxAmt, minAmt FROM sscDetail WHERE sscMasterId = @masterId
  182. END
  183. ELSE
  184. BEGIN
  185. SELECT fromAmt, toAmt, pcnt, maxAmt, minAmt FROM dscDetail WHERE dscMasterId = @masterId
  186. END
  187. END
  188. ELSE IF @flag = 'scLocal'
  189. BEGIN
  190. --EXEC proc_sendTransactionLoadData @flag = 'sc', @amount= '100000', @pLocation = '109'
  191. DECLARE @agentType INT
  192. IF @sBranch IS NULL
  193. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  194. SELECT @agentType = agentType FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  195. IF @agentType = 2903
  196. BEGIN
  197. SET @sAgent = @sBranch
  198. END
  199. ELSE
  200. BEGIN
  201. SELECT @sAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  202. END
  203. SELECT @pSuperAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent
  204. SELECT @pCountry = countryId FROM countryMaster WITH(NOLOCK)
  205. WHERE countryName = (SELECT agentCountry FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent)
  206. IF @deliveryMethod = 'Bank Deposit'
  207. BEGIN
  208. SELECT @pLocation = agentLocation FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  209. END
  210. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod
  211. SELECT sc = ISNULL(amount, -1) FROM [dbo].FNAGetSC(@sBranch, @pSuperAgent, @pCountry, @pLocation, @agentId , @deliveryMethodId, @amount, @collCurr)
  212. END
  213. ELSE IF @flag = 'acBal'
  214. BEGIN
  215. --EXEC proc_sendTransactionLoadData @flag = 'acBal', @user = 'shree_b1'
  216. DECLARE @settlingAgent INT
  217. IF @agentId IS NULL
  218. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  219. ELSE
  220. SELECT @sBranch = @agentId
  221. SELECT @sAgent = parentId, @agentType = agentType FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  222. IF @agentType = 2903
  223. SET @sAgent = @sBranch
  224. SELECT @ssAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent
  225. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sBranch AND isSettlingAgent = 'Y'
  226. IF @settlingAgent IS NULL
  227. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sAgent AND isSettlingAgent = 'Y'
  228. IF @settlingAgent IS NULL
  229. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @ssAgent AND isSettlingAgent = 'Y'
  230. SELECT
  231. availableBal = ISNULL(dbo.FNAGetLimitBal(@settlingAgent), 0)
  232. ,balCurrency = cm.currencyCode
  233. ,limExpiry = ISNULL(CONVERT(VARCHAR, expiryDate, 101), 'N/A')
  234. FROM creditLimit cl
  235. LEFT JOIN currencyMaster cm WITH(NOLOCK) ON cl.currency = cm.currencyId
  236. WHERE agentId = @settlingAgent
  237. END
  238. ELSE IF @flag = 'er' --Exchage Rate
  239. BEGIN
  240. --DECLARE
  241. -- @collCurr INT = 1
  242. -- ,@payCurr INT = 1
  243. SELECT
  244. cm.currencyId
  245. ,cm.currencyCode
  246. ,cm.currencyName
  247. --,exRate = [dbo].FNAGetEchangeRate(@sBranch, @agentId, @collCurr, @payCurr)
  248. FROM agentCurrency ac WITH(NOLOCK)
  249. INNER JOIN (
  250. SELECT
  251. parentId
  252. FROM agentMaster WHERE agentId = @agentId
  253. ) agent ON agent.parentId = ac.agentId
  254. INNER JOIN currencyMaster cm WITH(NOLOCK) ON ac.currencyId = cm.currencyId
  255. END
  256. ELSE IF @flag = 'fer'
  257. BEGIN
  258. DECLARE
  259. @isAnywhere CHAR(1)
  260. ,@isTranMode CHAR(1)
  261. ,@sending BIGINT
  262. ,@receiving BIGINT
  263. SELECT @sending = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  264. SELECT @isAnywhere = CASE WHEN @agentId IS NULL THEN 'Y' ELSE 'N' END
  265. SELECT @receiving = CASE WHEN @isAnywhere = 'Y' THEN @pCountry ELSE @agentId END
  266. SELECT @receiving = CASE WHEN @agentId IS NULL THEN @pCountry ELSE @agentId END
  267. SELECT @sAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sending
  268. SELECT @ssAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent
  269. SELECT @rAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @agentId
  270. SELECT @rsAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @rAgent
  271. --CREATE FUNCTION [dbo].FNAGetEchangeRateForTran(@ssAgent BIGINT, @sending BIGINT, @rsAgent BIGINT, @receiving BIGINT
  272. --, @collCurr INT, @payCurr INT, @isAnywhere CHAR(1), @isTranMode CHAR(1), @user VARCHAR(30))
  273. IF @collCurr = @pCurrency
  274. BEGIN
  275. SELECT 1
  276. RETURN
  277. END
  278. SELECT [dbo].FNAGetEchangeRateForTran(@ssAgent, @sending, @pSuperAgent, @receiving, @collCurr, @pCurrency, @isAnywhere, 'Y', @user)
  279. END
  280. ELSE IF @flag IN ('tranId', 'senderId') --Get Details By Tran Id OR sender ID
  281. BEGIN
  282. DECLARE @tranRowId BIGINT
  283. IF @senderId IS NOT NULL
  284. BEGIN
  285. SELECT @tranRowId = ISNULL(lastTranId, 0) FROM customers WHERE customerId = @senderId
  286. SELECT @agentId = pBranch FROM remitTran WHERE Id = @tranRowId
  287. SELECT @senderId = customerId FROM tranSenders WITH(NOLOCK) WHERE tranId = @tranRowId
  288. SELECT @benId = customerId FROM tranReceivers WITH(NOLOCK) WHERE tranId = @tranRowId
  289. END
  290. ELSE IF @sTranId IS NOT NULL --control Id
  291. BEGIN
  292. SELECT
  293. @tranRowId = id
  294. ,@agentId = pBranch
  295. FROM remitTran WHERE controlNo = @sTranId
  296. SELECT @senderId = customerId FROM tranSenders WITH(NOLOCK) WHERE tranId = @tranRowId
  297. SELECT @benId = customerId FROM tranReceivers WITH(NOLOCK) WHERE tranId = @tranRowId
  298. END
  299. SELECT SenderId = ISNULL(@senderId, 0), BenId = ISNULL(@benId, 0), AgentId = ISNULL(@agentId, 0)
  300. END
  301. ELSE IF @flag = 's'
  302. BEGIN
  303. SET @table = '(
  304. SELECT DISTINCT
  305. c.customerId
  306. ,c.membershipId
  307. ,Name = c.firstName + ISNULL( '' '' + c.middleName, '''') + ISNULL( '' '' + c.lastName1, '''') + ISNULL( '' '' + c.lastName2, '''')
  308. ,Country = ccm.countryName
  309. ,Address
  310. ,[State] = csm.stateName
  311. ,Phone = COALESCE(mobile, homePhone, workPhone)
  312. ,city
  313. FROM customers c WITH(NOLOCK)
  314. LEFT JOIN customerIdentity ci WITH(NOLOCK) ON c.customerId = ci.customerId
  315. LEFT JOIN countryMaster ccm WITH(NOLOCK) ON c.country = ccm.countryId
  316. LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON c.state = csm.stateId
  317. WHERE ISNULL(ci.isDeleted, '''') <> ''Y'''
  318. SET @sql_filter = ''
  319. IF @senderId IS NOT NULL
  320. SET @table = @table + ' AND c.customerId = ' + CAST(@senderId AS VARCHAR)
  321. IF @sCountry IS NOT NULL
  322. SET @table = @table + ' AND c.country = ' + CAST(@sCountry AS VARCHAR)
  323. IF @sFirstName IS NOT NULL
  324. SET @table = @table + ' AND c.firstName LIKE ''' + @sFirstName + '%'''
  325. IF @sMiddleName IS NOT NULL
  326. SET @table = @table + ' AND c.middleName LIKE ''' + @sMiddleName + '%'''
  327. IF @sLastName1 IS NOT NULL
  328. SET @table = @table + ' AND c.lastName1 LIKE ''' + @sLastName1 + '%'''
  329. IF @sLastName2 IS NOT NULL
  330. SET @table = @table + ' AND c.lastName2 LIKE ''' + @sLastName2 + '%'''
  331. IF @sPhone IS NOT NULL
  332. SET @table = @table + ' AND (
  333. ISNULL(c.homePhone, '''') LIKE ''' + @sPhone + '%''
  334. OR ISNULL(c.workPhone, '''') LIKE ''' + @sPhone + '%''
  335. OR ISNULL(c.mobile, '''') LIKE ''' + @sPhone + '%''
  336. )'
  337. IF @sMemId IS NOT NULL
  338. SET @table = @table + ' AND c.membershipId = ''' + CAST(@sMemId AS VARCHAR) + ''''
  339. IF @sId IS NOT NULL
  340. SET @table = @table + ' AND ci.idNumber LIKE ''' + CAST(@sId AS VARCHAR) + '%'''
  341. IF (
  342. @senderId IS NULL
  343. AND @sFirstName IS NULL
  344. AND @sMiddleName IS NULL
  345. AND @sLastName1 IS NULL
  346. AND @sLastName2 IS NULL
  347. AND @sPhone IS NULL
  348. AND @sMemId IS NULL
  349. AND @sId IS NULL
  350. )
  351. SET @table = @table + ' AND 1<>1'
  352. SET @select_field_list ='
  353. customerId
  354. ,membershipId
  355. ,Name
  356. ,Country
  357. ,Address
  358. ,[State]
  359. ,Phone
  360. ,city
  361. '
  362. SET @table = @table + ') x'
  363. EXEC dbo.proc_paging
  364. @table
  365. ,@sql_filter
  366. ,@select_field_list
  367. ,@extra_field_list
  368. ,@sortBy
  369. ,@sortOrder
  370. ,@pageSize
  371. ,@pageNumber
  372. END
  373. ELSE IF @flag = 'b'
  374. BEGIN
  375. SET @table = '(
  376. SELECT DISTINCT
  377. c.customerId
  378. ,c.membershipId
  379. ,Name = c.firstName + ISNULL( '' '' + c.middleName, '''') + ISNULL( '' '' + c.lastName1, '''') + ISNULL( '' '' + c.lastName2, '''')
  380. ,Country = ccm.countryName
  381. ,Address
  382. ,[State] = csm.stateName
  383. ,Phone = COALESCE(mobile, homePhone, workPhone)
  384. ,city
  385. FROM customers c WITH(NOLOCK)
  386. LEFT JOIN customerIdentity ci WITH(NOLOCK) ON c.customerId = ci.customerId
  387. LEFT JOIN countryMaster ccm WITH(NOLOCK) ON c.country = ccm.countryId
  388. LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON c.state = csm.stateId
  389. WHERE ISNULL(ci.isDeleted, '''') <> ''Y''
  390. '
  391. IF @benId IS NOT NULL
  392. SET @table = @table + ' AND c.customerId = ' + CAST(@benId AS VARCHAR)
  393. IF @benId IS NULL
  394. BEGIN
  395. IF @rCountry IS NOT NULL
  396. SET @table = @table + ' AND c.country = ' + CAST(@rCountry AS VARCHAR)
  397. IF @rFirstName IS NOT NULL
  398. SET @table = @table + ' AND c.firstName LIKE ''' + @rFirstName + '%'''
  399. IF @rMiddleName IS NOT NULL
  400. SET @table = @table + ' AND c.middleName LIKE ''' + @rMiddleName + '%'''
  401. IF @rLastName1 IS NOT NULL
  402. SET @table = @table + ' AND c.LastName1 LIKE ''' + @rLastName1 + '%'''
  403. IF @rLastName2 IS NOT NULL
  404. SET @table = @table + ' AND c.LastName2 LIKE ''' + @rLastName2 + '%'''
  405. IF @rPhone IS NOT NULL
  406. SET @table = @table + ' AND (
  407. ISNULL(c.homePhone, '''') LIKE ''' + @rPhone + '%''
  408. OR ISNULL(c.workPhone, '''') LIKE ''' + @rPhone + '%''
  409. OR ISNULL(c.mobile, '''') LIKE ''' + @rPhone + '%''
  410. )'
  411. IF @rMemId IS NOT NULL
  412. SET @table = @table + ' AND c.membershipId = ''' + CAST(@rMemId AS VARCHAR) + ''''
  413. IF @rId IS NOT NULL
  414. SET @table = @table + ' AND ci.idNumber LIKE ''' + CAST(@rId AS VARCHAR) + '%'''
  415. IF (
  416. @benId IS NULL
  417. AND @rFirstName IS NULL
  418. AND @rMiddleName IS NULL
  419. AND @rLastName1 IS NULL
  420. AND @rLastName2 IS NULL
  421. AND @rPhone IS NULL
  422. AND @rMemId IS NULL
  423. AND @rId IS NULL
  424. )
  425. SET @table = @table + ' AND 1<>1'
  426. END
  427. SET @table = @table + ') x'
  428. SET @sql_filter = ''
  429. SET @select_field_list ='
  430. customerId
  431. ,membershipId
  432. ,Name
  433. ,Country
  434. ,Address
  435. ,[State]
  436. ,Phone
  437. ,city
  438. '
  439. EXEC dbo.proc_paging
  440. @table
  441. ,@sql_filter
  442. ,@select_field_list
  443. ,@extra_field_list
  444. ,@sortBy
  445. ,@sortOrder
  446. ,@pageSize
  447. ,@pageNumber
  448. END
  449. ELSE IF @flag = 'p'
  450. BEGIN
  451. SET @table = '(
  452. SELECT
  453. DISTINCT
  454. am.agentId
  455. ,am.agentCode
  456. ,name = am.agentName
  457. ,address = am.agentAddress
  458. ,city = agentCity
  459. ,district = agentDistrict
  460. ,[State] = agentState
  461. ,Phone = COALESCE(agentMobile1, agentMobile2, agentPhone1, agentPhone2)
  462. ,Country = am.agentCountry
  463. FROM agentMaster am WITH(NOLOCK)
  464. LEFT JOIN agentCurrency ac WITH(NOLOCK) ON am.agentId = ac.agentId
  465. INNER JOIN currencyMaster cm WITH(NOLOCK) ON ac.currencyId = cm.currencyId
  466. WHERE
  467. ISNULL(am.isDeleted, '''') <> ''Y''
  468. AND ISNULL(am.isActive, '''') = ''Y''
  469. AND (agentType = ''2904'' OR actAsBranch = ''Y'')
  470. AND (am.parentId IN (SELECT agentId FROM agentMaster WHERE parentId = ' + CAST(ISNULL(@pSuperAgent,0) AS VARCHAR) + ') OR am.parentId = ' + CAST(ISNULL(@pSuperAgent, 0) AS VARCHAR) + ')
  471. '
  472. --PRINT (@table)
  473. IF @agentId IS NOT NULL
  474. SET @table = @table + ' AND am.agentId = ' + CAST(@agentId AS VARCHAR)
  475. IF @agentId IS NULL
  476. BEGIN
  477. --IF @pSuperAgent IS NOT NULL
  478. -- SET @table = @table + ' AND am.parentId IN (' + SELECT agentId FROM agentMaster WHERE parentId = @pCountry + ')'
  479. IF @pCountry IS NOT NULL
  480. SET @table = @table + ' AND am.agentCountry = ''' + @pCountryName + ''''
  481. IF @pCurrency IS NOT NULL
  482. SET @table = @table + ' AND cm.currencyCode = ''' + @pCurrency + ''''
  483. IF @pState IS NOT NULL
  484. SET @table = @table + ' AND am.agentState = ''' + @pState + ''''
  485. IF @pDistrict IS NOT NULL
  486. SET @table = @table + ' AND am.agentDistrict = ''' + @pDistrict + ''''
  487. IF @pLocation IS NOT NULL
  488. SET @table = @table + ' AND am.agentLocation = ' + CAST(@pLocation AS VARCHAR)
  489. IF @pCity IS NOT NULL
  490. SET @table = @table + ' AND am.agentCity LIKE ''' + @pCity + '%'''
  491. --IF @deliveryMethod IS NOT NULL
  492. -- SET @table = @table + ' AND x.serviceType = ' + CAST(@deliveryMethod AS VARCHAR)
  493. IF @pPayer IS NOT NULL
  494. SET @table = @table + ' AND (
  495. am.agentName LIKE ''' + @pPayer + '%''
  496. OR am.agentCode LIKE ''' + @pPayer + '%''
  497. )
  498. '
  499. END
  500. SET @table = @table + ') x'
  501. SET @sql_filter = ''
  502. SET @select_field_list ='
  503. agentId
  504. ,agentCode
  505. ,name
  506. ,address
  507. ,country
  508. ,city
  509. ,[State]
  510. ,Phone
  511. '
  512. EXEC dbo.proc_paging
  513. @table
  514. ,@sql_filter
  515. ,@select_field_list
  516. ,@extra_field_list
  517. ,@sortBy
  518. ,@sortOrder
  519. ,@pageSize
  520. ,@pageNumber
  521. END
  522. ELSE IF @flag = 'cust'
  523. BEGIN
  524. SELECT
  525. c.customerId
  526. ,membershipId
  527. ,Name = c.firstName + ISNULL( ' ' + c.middleName, '') + ISNULL(' ' + c.lastName1, '') + ISNULL(' ' + c.lastName2, '')
  528. ,[state] = ISNULL(csm.stateName, 'NA')
  529. ,[address] = ISNULL([address], 'NA')
  530. ,Phone = COALESCE(mobile, homePhone, workPhone)
  531. ,country = ISNULL(ccm.countryName, 'NA')
  532. FROM customers c WITH(NOLOCK)
  533. LEFT JOIN countryMaster ccm WITH(NOLOCK) ON c.country = ccm.countryId
  534. LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON c.state = csm.stateId
  535. WHERE c.customerId = @customerId
  536. END
  537. ELSE IF @flag = 'pay'
  538. BEGIN
  539. SELECT
  540. am.agentId
  541. ,code = am.agentCode
  542. ,name = am.agentName
  543. ,address = am.agentAddress
  544. ,city = agentCity
  545. ,[State] = ISNULL(csm.stateName, 'NA')
  546. ,Phone = COALESCE(agentMobile1, agentMobile2, agentPhone1, agentPhone2)
  547. ,Country = am.agentCountry
  548. ,am.parentId
  549. ,am.agentType
  550. FROM agentMaster am WITH(NOLOCK)
  551. LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON am.agentState = csm.stateId
  552. WHERE
  553. ISNULL(am.isDeleted, '') <> 'Y'
  554. AND ISNULL(am.isActive, '') = 'Y'
  555. AND agentId = @agentId
  556. END
  557. ELSE IF @flag = 'p_curr'
  558. BEGIN
  559. SELECT
  560. DISTINCT
  561. currencyId = cm.currencyCode
  562. ,cm.currencyCode
  563. FROM countryCurrency cc WITH(NOLOCK)
  564. INNER JOIN currencyMaster cm WITH(NOLOCK) ON cc.currencyId = cm.currencyId
  565. WHERE cc.countryId = @pCountry --ISNULL(@pCountry, cc.countryId )
  566. AND (spFlag IS NULL OR spFlag = 5201)
  567. ORDER BY cm.currencyCode
  568. END
  569. ELSE IF @flag = 'c_curr'
  570. BEGIN
  571. /*EXEC proc_sendTransactionLoadData @flag = 'c_curr', @user = 'ahalia'*/
  572. DECLARE @agentCountryId INT
  573. SELECT @agentId = agentId FROM applicationUsers WHERE userName = @user
  574. SELECT @agentCountryId = agentCountryId FROM agentMaster WITH(NOLOCK) WHERE agentId = @agentId
  575. SELECT DISTINCT currencyId, currencyCode, currencyName FROM
  576. (
  577. SELECT
  578. currencyId = cm.currencyCode
  579. ,cm.currencyCode
  580. ,currencyName = cm.currencyCode + ' - ' + cm.currencyName
  581. FROM countryCurrency cc WITH(NOLOCK)
  582. INNER JOIN currencyMaster cm WITH(NOLOCK) ON cc.currencyId = cm.currencyId
  583. WHERE countryId = @agentCountryId AND applyToAgent = 'Y'
  584. UNION ALL
  585. SELECT
  586. currencyId = cm.currencyCode
  587. ,cm.currencyCode
  588. ,currencyName = cm.currencyCode + ' - ' + cm.currencyName
  589. FROM agentCurrency ac WITH(NOLOCK)
  590. INNER JOIN (
  591. SELECT
  592. parentId
  593. FROM agentMaster WHERE agentId = @agentId
  594. ) agent ON agent.parentId = ac.agentId
  595. INNER JOIN currencyMaster cm WITH(NOLOCK) ON ac.currencyId = cm.currencyId
  596. )x
  597. ORDER BY currencyCode ASC
  598. END
  599. ELSE IF @flag = 'dm' -- deliverymethod
  600. BEGIN
  601. SELECT
  602. stm.serviceTypeId
  603. ,stm.typeTitle
  604. FROM serviceTypeMaster stm WITH (NOLOCK)
  605. WHERE ISNULL(stm.isDeleted, 'N') <> 'Y'
  606. AND ISNULL(stm.isActive, 'N') = 'Y'
  607. END
  608. GO