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.

2322 lines
142 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_online_approve_Customer] Script Date: 1/7/2024 8:28:47 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_online_approve_Customer] @flag VARCHAR(50) = NULL
  9. ,@user VARCHAR(30) = NULL
  10. ,@customerId VARCHAR(30) = NULL
  11. ,@searchCriteria VARCHAR(30) = NULL
  12. ,@searchValue VARCHAR(50) = NULL
  13. ,@fromDate DATETIME = NULL
  14. ,@toDate DATETIME = NULL
  15. ,@cusType VARCHAR(50) = NULL
  16. ,@accountNumber VARCHAR(100) = NULL
  17. ,@agentId BIGINT = NULL
  18. ,@CustomerBankName NVARCHAR(100) = NULL
  19. ,@obpId VARCHAR(50) = NULL
  20. --grid parameters
  21. ,@pageSize VARCHAR(50) = NULL
  22. ,@pageNumber VARCHAR(50) = NULL
  23. ,@sortBy VARCHAR(50) = NULL
  24. ,@sortOrder VARCHAR(50) = NULL
  25. ,@virtualAccountNo VARCHAR(50) = NULL
  26. ,@primaryAccountNo VARCHAR(50) = NULL
  27. ,@password VARCHAR(50) = NULL
  28. ,@action CHAR(20) = NULL
  29. ,@referral VARCHAR(50) = NULL
  30. ,@verifyType VARCHAR(50) = NULL
  31. ,@customerPassword NVARCHAR(50) = NULL
  32. ,@HasDeclare VARCHAR(50) = NULL
  33. ,@agreeYn VARCHAR(50) = NULL
  34. ,@isForcedPwdChange VARCHAR(50) = NULL
  35. ,@isEmailVerified VARCHAR(50) = NULL
  36. ,@createdFrom1 VARCHAR(50) = NULL
  37. ,@mobileUser VARCHAR(50) = NULL
  38. ,@referelCode VARCHAR(50) = NULL
  39. ,@customerStatus1 VARCHAR(50) = NULL
  40. ,@mobileverifiedby VARCHAR(50) = NULL
  41. ,@mobileverifieddate VARCHAR(50) = NULL
  42. ,@mobileapprovedby VARCHAR(50) = NULL
  43. ,@mobileapproveddate VARCHAR(50) = NULL
  44. ,@mobileverificationType VARCHAR(50) = NULL
  45. ,@modifiedDate VARCHAR(50) = NULL
  46. ,@modifiedBy VARCHAR(100) = NULL
  47. ,@newData VARCHAR(300) = NULL
  48. ,@oldData VARCHAR(300) = NULL
  49. ,@isValidatedCustomer VARCHAR(5) = NULL
  50. ,@isAgreeDate DATETIME = NULL
  51. ,@verifyRemarks NVARCHAR(800) = NULL
  52. ,@ofacRemarks NVARCHAR(800) = NULL
  53. ,@status VARCHAR(500) = NULL
  54. AS
  55. SET NOCOUNT ON;
  56. SET XACT_ABORT ON;
  57. --------------------------------------------------------------------------------------
  58. -- #494 -> Added others value in approve customer screen by Leeza
  59. -- #101 -> Mobile changes - @serviceUsedFor
  60. -- #438 - added createdFrom
  61. -- #660 -> Add referral code in customer detail screen for activating mobile
  62. --Bug #681 ->Non KYC customer are appearing approve customer list
  63. -- #675 Divide the approval customer into 2 step process
  64. --#698 Create new screen to activate mobile service
  65. -- cm.agreeYn,0)= 1 for verify Customer
  66. -- Support #741 assign approve date during active mobile
  67. -- #779 added log for activate mobile @flag = 'mobile-activate-log'
  68. -- set MobileOTP expiry in case of activate mobile
  69. -- Delete mobile-user-registration if exist
  70. -- #958 - Add Asc/Desc sorting in Verify/Approve Customer From Mobile
  71. -- #1008 - Allow saving filled customer data in verify Customer from mobile
  72. -- #1030 - @flag='create-mobile-login', update isAgreeDate
  73. -- #1094 - verify pending remarks , @flag = 'approve-pending-mobile' , 'verify-mobile-user'
  74. -- #1104 - @flag = 'approve-pending' , add ofacRemarks, changes in @flag = 'approve-pending-mobile' and @flag = 'verify-mobile-user'
  75. -- added logs for delete
  76. -- #1195 changes in @flag = 'searchCriteria', @flag = 'unApprovedCustomerFromMobile', @flag = 'al' to add lawson card no in search field
  77. -- #11751 - add registered Type
  78. -- selected the customers created from agent portal as well in @flag = 'vl'
  79. -- change in @flag = 'searchCriteria' to add filterlist
  80. --------------------------------------------------------------------------------------
  81. BEGIN TRY
  82. DECLARE @table VARCHAR(MAX)
  83. ,@select_field_list VARCHAR(MAX)
  84. ,@extra_field_list VARCHAR(MAX)
  85. ,@sql_filter VARCHAR(MAX)
  86. DECLARE @email VARCHAR(200)
  87. ,@username VARCHAR(50)
  88. ,@pwd VARCHAR(50)
  89. ,@channel VARCHAR(20) = NULL
  90. DECLARE @customerStatus NVARCHAR(100)
  91. ,@createdFrom VARCHAR(5) , @bonusPoint MONEY , @rewardValue MONEY , @sourceCustomerId INT
  92. SET @toDate = @toDate + ' 23:59:59'
  93. IF @flag = 'vl' --verified list/approve pending list
  94. BEGIN
  95. SET @sortBy = 'createdDate'
  96. SET @sortOrder = 'desc'
  97. SET @table =
  98. '(
  99. SELECT SN=ROW_NUMBER() over(ORDER BY cm.customerId asc)
  100. ,customerId=cm.customerId
  101. ,email=cm.email
  102. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  103. ,dob=CONVERT(VARCHAR,cm.dob,101)
  104. ,address=cm.[address]
  105. ,nativeCountry=com.countryName
  106. ,idtype=case when cm.idtype = ''11402'' then cm.otherIdNumber else sdv.detailTitle end
  107. ,idNumber= cm.idNumber
  108. ,createdDate=CAST(cm.createdDate AS DATE)
  109. ,createdBy=cm.createdBy
  110. ,verifiedBy=cm.verifiedBy
  111. ,branchName=''''
  112. ,verifiedDate=CAST(cm.verifiedDate AS DATE)
  113. ,ipAddress=cm.ipAddress
  114. ,mobile=cm.mobile
  115. ,bankAccountNo
  116. ,bankName=bl.bankName
  117. ,case when ISNULL(cm.createdFrom, ''C'') = ''C'' THEN ''COUNTER'' WHEN cm.createdFrom = ''M'' THEN ''MOBILE'' ELSE cm.createdFrom END createdFrom
  118. FROM customerMaster cm(NOLOCK)
  119. LEFT JOIN APPLICATIONUSERS AU(NOLOCK) ON AU.USERNAME = CM.CREATEDBY
  120. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  121. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  122. LEFT JOIN vwBankLists bl (NOLOCK) ON cm.bankName = bl.rowId
  123. WHERE cm.approvedDate IS NULL
  124. --AND ISNULL(CM.CREATEDFROM, ''C'') = ''C''
  125. AND CM.CREATEDFROM IN (''C'',''O'')
  126. --AND ISNULL(CM.isVerifiedByCustomer, 0) = 1
  127. and cm.isActive = ''Y'''
  128. IF ISNULL(@fromDate, '') <> ''
  129. AND ISNULL(@toDate, '') <> ''
  130. SET @table = @table + ' AND cm.createdDate BETWEEN ''' + CAST(@fromDate AS VARCHAR) + ''' AND ''' + CAST(@toDate AS VARCHAR) + ''''
  131. SET @table = @table + ')x'
  132. SET @sql_filter = ''
  133. IF ISNULL(@searchCriteria, '') <> ''
  134. AND ISNULL(@searchValue, '') <> ''
  135. BEGIN
  136. IF @searchCriteria = 'idNumber'
  137. BEGIN
  138. --IF ISNUMERIC(@searchValue)<>1
  139. -- SET @searchValue='-1' --to ignore string value for datatype integer/customerID
  140. --SET @sql_Filter=@sql_Filter + ' AND customerId = ''' +@searchValue+''''
  141. SET @sql_Filter = @sql_Filter + ' AND REPLACE(idNumber, ''-'', '''') = ''' + REPLACE(@searchValue, '-', '') + ''''
  142. END
  143. ELSE IF @searchCriteria = 'emailId'
  144. SET @sql_Filter = @sql_Filter + ' AND email like ''' + @searchValue + '%'''
  145. ELSE IF @searchCriteria = 'customerName'
  146. SET @sql_Filter = @sql_Filter + ' AND fullName like ''' + @searchValue + '%'''
  147. ELSE IF @searchCriteria = 'mobile'
  148. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  149. ELSE IF @searchCriteria = 'membershipId'
  150. SET @sql_Filter = @sql_Filter + ' AND membershipId = ''' + @searchValue + ''''
  151. ELSE IF @searchCriteria = 'nativeCountry'
  152. SET @sql_Filter = @sql_Filter + ' AND nativeCountry = ''' + @searchValue + ''''
  153. END
  154. SET @select_field_list = '
  155. SN,customerId,email,fullName,dob,address,nativeCountry,idtype,idNumber
  156. ,createdDate,createdBy,verifiedBy,branchName,verifiedDate,bankAccountNo,bankName,createdFrom
  157. '
  158. EXEC dbo.proc_paging @table
  159. ,@sql_filter
  160. ,@select_field_list
  161. ,@extra_field_list
  162. ,@sortBy
  163. ,@sortOrder
  164. ,@pageSize
  165. ,@pageNumber
  166. RETURN
  167. END
  168. ELSE IF @flag = 'al' --approved list
  169. BEGIN
  170. IF @sortBy IS NULL
  171. SET @sortBy = 'customerId'
  172. IF @sortOrder IS NULL
  173. SET @sortOrder = 'ASC'
  174. SET @table =
  175. '(
  176. SELECT SN=ROW_NUMBER() over(ORDER BY cm.customerId asc)
  177. ,customerId=cm.customerId
  178. ,email=cm.email
  179. ,fullName= cm.fullName
  180. ,idtype=sdv.detailTitle
  181. ,idNumber=cm.idNumber
  182. ,mobile=cm.mobile
  183. ,bankName=bl.bankName
  184. ,cm.bankAccountNo
  185. ,CM.walletAccountNo
  186. ,cm.availableBalance
  187. ,cm.dob,cm.address
  188. ,country = ''South Korea''
  189. ,nativeCountry = com.CountryName
  190. ,cm.createdDate
  191. ,approvedBy=cm.approvedBy
  192. ,approvedDate=CAST(cm.approvedDate AS DATE)
  193. ,case when ISNULL(cm.createdFrom, ''C'') = ''C'' THEN ''COUNTER'' WHEN cm.createdFrom = ''M'' THEN ''MOBILE'' ELSE cm.createdFrom END createdFrom
  194. ,cm.LawsonCardNo
  195. FROM customerMaster cm(NOLOCK)
  196. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType
  197. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  198. LEFT JOIN KoreanBankList bl (NOLOCK) ON cm.bankName = bl.rowId
  199. WHERE cm.approvedDate is not null '
  200. IF ISNULL(@fromDate, '') <> ''
  201. AND ISNULL(@toDate, '') <> ''
  202. SET @table = @table + ' AND cm.approvedDate BETWEEN ''' + CAST(CAST(@fromDate AS DATE) AS VARCHAR) + ''' AND ''' + CAST(CAST(@toDate AS DATE) AS VARCHAR) + ' 23:59:59' + ''''
  203. SET @table = @table + ')x'
  204. SET @sql_filter = ''
  205. IF ISNULL(@searchCriteria, '') <> ''
  206. AND ISNULL(@searchValue, '') <> ''
  207. BEGIN
  208. IF @searchCriteria = 'idNumber'
  209. BEGIN
  210. --IF ISNUMERIC(@searchValue)<>1
  211. -- SET @searchValue='-1' --to ignore string value for datatype integer/customerID
  212. --SET @sql_Filter=@sql_Filter + ' AND customerId = ''' +@searchValue+''''
  213. SET @sql_Filter = @sql_Filter + ' AND REPLACE(idNumber, ''-'', '''') = ''' + REPLACE(@searchValue, '-', '') + ''''
  214. END
  215. ELSE IF @searchCriteria = 'emailId'
  216. SET @sql_Filter = @sql_Filter + ' AND email like ''' + @searchValue + '%'''
  217. ELSE IF @searchCriteria = 'customerName'
  218. SET @sql_Filter = @sql_Filter + ' AND fullName like ''' + @searchValue + '%'''
  219. ELSE IF @searchCriteria = 'mobile'
  220. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  221. ELSE IF @searchCriteria = 'mobile'
  222. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  223. ELSE IF @searchCriteria = 'membershipId'
  224. SET @sql_Filter = @sql_Filter + ' AND membershipId = ''' + @searchValue + ''''
  225. ELSE IF @searchCriteria = 'nativeCountry'
  226. SET @sql_Filter = @sql_Filter + ' AND nativeCountry = ''' + @searchValue + ''''
  227. END
  228. SET @select_field_list = '
  229. SN,customerId,email,fullName,idtype,idNumber,mobile,bankName,bankAccountNo,walletAccountNo,availableBalance
  230. ,dob,address,country,nativeCountry,createdDate,approvedDate,approvedBy,createdFrom,LawsonCardNo'
  231. EXEC dbo.proc_paging @table
  232. ,@sql_filter
  233. ,@select_field_list
  234. ,@extra_field_list
  235. ,@sortBy
  236. ,@sortOrder
  237. ,@pageSize
  238. ,@pageNumber
  239. RETURN
  240. END
  241. ELSE IF @flag = 'p' --pending list
  242. BEGIN
  243. IF @sortBy IS NULL
  244. SET @sortBy = 'customerId'
  245. IF @sortOrder IS NULL
  246. SET @sortOrder = 'ASC'
  247. SET @table =
  248. '(
  249. SELECT SN=ROW_NUMBER() over(ORDER BY cm.customerId asc)
  250. ,customerId=cm.customerId
  251. ,email=cm.email
  252. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  253. ,dob=CONVERT(VARCHAR,cm.dob,101)
  254. ,address=cm.[address]
  255. ,country=c.countryName
  256. ,ipAddress=isnull(cm.ipAddress,'''')
  257. ,nativeCountry=com.countryName
  258. ,idtype=sdv.detailTitle
  259. ,idNumber=cm.idNumber
  260. ,telNo=isnull(cm.telNo,'''')
  261. ,mobile=cm.mobile
  262. ,createdDate=CAST(cm.createdDate AS DATE)
  263. ,bankName=bl.bankName
  264. ,cm.bankAccountNo
  265. FROM customerMaster cm(NOLOCK)
  266. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  267. LEFT JOIN countryMaster c(NOLOCK) ON cm.country=c.countryId
  268. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  269. LEFT JOIN vwBankLists bl (NOLOCK) ON cm.bankName = bl.rowId
  270. WHERE cm.verifiedDate IS NULL'
  271. IF ISNULL(@fromDate, '') <> ''
  272. AND ISNULL(@toDate, '') <> ''
  273. SET @table = @table + ' AND cm.createdDate BETWEEN ''' + CAST(@fromDate AS VARCHAR) + ''' AND ''' + CAST(@toDate AS VARCHAR) + ''''
  274. SET @table = @table + ')x'
  275. SET @sql_filter = ''
  276. IF ISNULL(@searchCriteria, '') <> ''
  277. AND ISNULL(@searchValue, '') <> ''
  278. BEGIN
  279. IF @searchCriteria = 'idNumber'
  280. BEGIN
  281. SET @sql_Filter = @sql_Filter + ' AND REPLACE(idNumber, ''-'', '''') = ''' + REPLACE(@searchValue, '-', '') + ''''
  282. END
  283. ELSE IF @searchCriteria = 'emailId'
  284. SET @sql_Filter = @sql_Filter + ' AND email like ''' + @searchValue + '%'''
  285. ELSE IF @searchCriteria = 'customerName'
  286. SET @sql_Filter = @sql_Filter + ' AND fullName like ''' + @searchValue + '%'''
  287. ELSE IF @searchCriteria = 'mobile'
  288. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  289. ELSE IF @searchCriteria = 'membershipId'
  290. SET @sql_Filter = @sql_Filter + ' AND membershipId = ''' + @searchValue + ''''
  291. ELSE IF @searchCriteria = 'bankAccountNo'
  292. SET @sql_Filter = @sql_Filter + ' AND bankAccountNo = ''' + @searchValue + ''''
  293. ELSE IF @searchCriteria = 'nativeCountry'
  294. SET @sql_Filter = @sql_Filter + ' AND nativeCountry = ''' + @searchValue + ''''
  295. END
  296. SET @select_field_list = '
  297. SN
  298. ,customerId
  299. ,email
  300. ,fullName
  301. ,dob
  302. ,address
  303. ,country
  304. --,ipAddress
  305. ,nativeCountry
  306. ,idtype
  307. ,idNumber
  308. --,telNo
  309. ,mobile
  310. ,createdDate
  311. ,bankName
  312. ,bankAccountNo
  313. '
  314. EXEC dbo.proc_paging @table
  315. ,@sql_filter
  316. ,@select_field_list
  317. ,@extra_field_list
  318. ,@sortBy
  319. ,@sortOrder
  320. ,@pageSize
  321. ,@pageNumber
  322. RETURN
  323. END
  324. ELSE IF @flag = 'searchCriteria'
  325. BEGIN
  326. SELECT '' value
  327. ,'Select' [text]
  328. UNION ALL
  329. SELECT 'emailId'
  330. ,'Email ID'
  331. UNION ALL
  332. SELECT 'IdNumber'
  333. ,'ID - Number'
  334. UNION ALL
  335. SELECT 'nativeCountry'
  336. ,'Native Country'
  337. UNION ALL
  338. SELECT 'customerName'
  339. ,'Customer Name'
  340. UNION ALL
  341. SELECT 'mobile'
  342. ,'Mobile No'
  343. UNION ALL
  344. SELECT 'membershipId'
  345. ,'Membership ID'
  346. RETURN
  347. END
  348. ELSE IF @flag = 'ddlCustomerType'
  349. BEGIN
  350. SELECT '' value
  351. ,'Select' [text]
  352. UNION ALL
  353. SELECT 'n'
  354. ,'Newly Registered'
  355. UNION ALL
  356. SELECT 'y'
  357. ,'Existing'
  358. RETURN
  359. END
  360. ELSE IF @flag = 'verify-pending'
  361. BEGIN
  362. UPDATE dbo.customerMaster
  363. SET verifiedDate = GETDATE()
  364. ,verifiedBy = @user
  365. WHERE customerId = @customerId
  366. SELECT '0' ErrorCode
  367. ,'Customer verified successfully.' Msg
  368. ,@customerId id
  369. RETURN
  370. END
  371. ELSE IF @flag = 'create-mobile-login'
  372. BEGIN
  373. DECLARE @serviceUsedFor VARCHAR(10)
  374. ,@existingemailagent VARCHAR(50)
  375. SELECT @existingemailagent = email
  376. FROM customerMaster(NOLOCK)
  377. WHERE customerid = @customerId
  378. IF EXISTS (
  379. SELECT *
  380. FROM customerMaster(NOLOCK)
  381. WHERE CUSTOMERID = @customerId
  382. AND APPROVEDDATE IS NULL
  383. )
  384. BEGIN
  385. SELECT '1' ErrorCode
  386. ,'Customer is not approved yet, approve customer first!' Msg
  387. ,NULL
  388. RETURN
  389. END
  390. IF EXISTS (
  391. SELECT *
  392. FROM customerMaster(NOLOCK)
  393. WHERE email = @existingemailagent
  394. AND mobileApprovedDate IS NOT NULL and customerid<>@customerId
  395. )
  396. BEGIN
  397. SELECT '1' ErrorCode
  398. ,'Customer with same email already exists! Please try again with a different email.' Msg
  399. ,NULL
  400. RETURN
  401. END
  402. SELECT @email = EMAIL
  403. ,@customerId = customerId
  404. FROM CUSTOMERMASTER(NOLOCK)
  405. WHERE CUSTOMERID = @customerId
  406. AND APPROVEDDATE IS NOT NULL
  407. IF @customerId IS NULL
  408. BEGIN
  409. SELECT '1' ErrorCode
  410. ,'Customer is not approved yet, approve customer first!' Msg
  411. ,NULL
  412. RETURN
  413. END
  414. IF @email IS NULL
  415. BEGIN
  416. SELECT '1' ErrorCode
  417. ,'Email ID field is empty, please update email first!' Msg
  418. ,NULL
  419. RETURN
  420. END
  421. IF @serviceUsedFor LIKE '%M%'
  422. BEGIN
  423. SELECT '1' ErrorCode
  424. ,'Mobile user already created!' Msg
  425. ,NULL
  426. RETURN
  427. END
  428. IF EXISTS (
  429. SELECT *
  430. FROM mobile_userRegistration
  431. WHERE username = @existingemailagent
  432. AND customerId <> @customerId
  433. )
  434. BEGIN
  435. DELETE
  436. FROM mobile_userRegistration
  437. WHERE username = @existingemailagent
  438. END
  439. SELECT @username = username
  440. ,@serviceUsedFor = serviceUsedFor
  441. ,@mobileUser = mobileUser
  442. ,@referelCode = referelCode
  443. ,@customerStatus = customerstatus
  444. ,@isAgreeDate = isAgreeDate
  445. FROM customerMaster
  446. WHERE customerId = @customerId
  447. UPDATE dbo.customerMaster
  448. SET username = ISNULL(username, email)
  449. ,customerPassword = dbo.FNAEncryptString(@password)
  450. ,HasDeclare = 1
  451. ,agreeYn = 1
  452. ,isAgreeDate = GETDATE()
  453. --,isForcedPwdChange = 1
  454. --,isEmailVerified = 0
  455. --,createdFrom = 'C'
  456. ,mobileUser = 'Y'
  457. --,referelCode = @referral
  458. --,customerStatus = 'OTC'
  459. ,mobileverifiedby = @user
  460. ,mobileverifieddate = GETDATE()
  461. --,mobileverificationType = 'verified'
  462. ,mobileapprovedby = @user
  463. ,mobileapproveddate = GETDATE()
  464. ,mobileverificationType = 'approved'
  465. --,modifiedDate = GETDATE()
  466. --,modifiedBy = @user
  467. WHERE customerId = @customerId
  468. UPDATE TBL_MOBILE_OTP_REQUEST
  469. SET IS_SUCCESS = '0'
  470. ,IS_EXPIRED = '1'
  471. ,MODIFIED_DATE = GETDATE()
  472. WHERE REQUEST_FOR = 'REGISTER'
  473. AND user_id = @email
  474. SELECT '0' ErrorCode
  475. ,'Mobile login created successfully.' Msg
  476. ,@customerId id
  477. ,'Y' extra
  478. EXEC PROC_CUSTOMERMODIFYLOG @flag = 'mobile-activate-log'
  479. ,@user = @user
  480. ,@customerId = @customerId
  481. ,@username = @username
  482. ,@mobileUser = @mobileUser
  483. ,@referelCode = @referelCode
  484. ,@mobileverifiedby = @user
  485. ,@mobileverifieddate = @mobileverifieddate
  486. ,@mobileapprovedby = @user
  487. ,@mobileverificationType = @mobileverificationType
  488. ,@serviceUsedFor = @serviceUsedFor
  489. ,@customerStatus = @customerStatus
  490. ,@isAgreeDate = @isAgreeDate
  491. --SELECT '0' ErrorCode
  492. -- ,'Mobile login created successfully, please check mobile customer approve menu.' Msg
  493. -- ,@customerId id
  494. --,'approved' EXTRA2
  495. RETURN
  496. END
  497. ELSE IF @flag = 'approve-pending'
  498. BEGIN
  499. DECLARE @custIdNumber VARCHAR(50)
  500. ,@WALLET_ACC_NO VARCHAR(30)
  501. ,@fullName VARCHAR(100)
  502. DECLARE @isOfac CHAR(1)
  503. DECLARE @referalid INT;
  504. SET @isOfac = CASE
  505. WHEN ISNULL(@ofacRemarks, '') = ''
  506. THEN 'N'
  507. ELSE 'Y'
  508. END
  509. IF NOT EXISTS (
  510. SELECT *
  511. FROM CUSTOMERMASTER(NOLOCK)
  512. WHERE CUSTOMERID = @customerId
  513. AND APPROVEDDATE IS NULL
  514. )
  515. BEGIN
  516. SELECT '1' ErrorCode
  517. ,'Customer already approved or does not exists!' Msg
  518. ,NULL
  519. UPDATE dbo.customerMaster
  520. SET approvedBy = @user
  521. ,approvedDate = GETDATE()
  522. ,username = email
  523. ,mobileApprovedDate = CASE
  524. WHEN @createdFrom IN ('O','M')
  525. THEN GETDATE()
  526. ELSE NULL
  527. END
  528. ,mobileApprovedBy = CASE
  529. WHEN @createdFrom IN ('O','M')
  530. THEN @user
  531. ELSE NULL
  532. END
  533. ,ofacRemarks = @ofacRemarks
  534. ,isOfac = @isOfac
  535. ,lawsonCardNo = CASE WHEN ISNULL(lawsonCardNo,'')='' THEN 'KYC_NOW' ELSE lawsonCardNo END
  536. ,isVerifiedByCustomer=1
  537. ,verificationCode = 'COMPLETED'
  538. WHERE customerId = @customerId
  539. IF NOT EXISTS (
  540. SELECT 1
  541. FROM dbo.TBL_CUSTOMER_KYC
  542. WHERE customerId = @customerId AND kycStatus = '11044'
  543. AND isDeleted <> '1' )
  544. BEGIN
  545. INSERT INTO TBL_CUSTOMER_KYC (
  546. customerId
  547. ,kycmethod
  548. ,kycStatus
  549. ,remarks
  550. ,createdBy
  551. ,createdDate
  552. ,trackingNo
  553. ,KYC_DATE
  554. )
  555. VALUES (
  556. @customerId
  557. ,CASE WHEN @createdFrom = 'C' THEN '11048' --counter visit
  558. WHEN @createdFrom = 'M' THEN '11051' --mobile app
  559. WHEN @createdFrom = 'O' THEN '11444' --web online
  560. ELSE ''
  561. END
  562. ,'11044'
  563. ,'KYC has been completed'
  564. ,@user
  565. ,GETDATE()
  566. ,''
  567. ,GETDATE()
  568. );
  569. END
  570. IF(@referelCode IS NOT NULL)
  571. BEGIN
  572. -- DECLARE @referalid INT;
  573. SELECT @referalid=customerId FROM customerMaster WHERE membershipId = @referelCode;
  574. IF NOT EXISTS(select 'X' FROM Customer_Promotion where sourceCustomerid= @referalid and destinationcustomerid=@customerId
  575. AND CodeType='REGISTRATION')
  576. BEGIN
  577. EXEC proc_InsertRewardPoints @Flag = 'REGISTER', @CustomerId = @customerId, @ReferralId = @referalid
  578. END
  579. END
  580. RETURN
  581. END
  582. SELECT @custIdNumber = idNumber
  583. ,@fullName = ISNULL(fullName, firstName),@createdFrom = createdFrom, @referelCode = referelCode
  584. FROM dbo.customerMaster(NOLOCK)
  585. WHERE customerId = @customerId
  586. SELECT @status = ISNULL(verificationCode,'NOT_COMPLETED') FROM customerMaster WHERE customerId = @customerId
  587. print @status
  588. IF EXISTS (
  589. SELECT 'X'
  590. FROM dbo.customerMaster(NOLOCK)
  591. WHERE replace(idNumber, '-', '') = replace(@custIdNumber, '-', '')
  592. GROUP BY replace(idNumber, '-', '')
  593. HAVING count(1) > 1
  594. )
  595. BEGIN
  596. SELECT '1' ErrorCode
  597. ,'Duplicate id number found for customer' Msg
  598. ,NULL
  599. RETURN
  600. END
  601. IF EXISTS (
  602. SELECT 'X'
  603. FROM dbo.customerMaster(NOLOCK)
  604. WHERE replace(idNumber, '-', '') = replace(@custIdNumber, '-', '')
  605. AND approvedBy IS NOT NULL
  606. )
  607. BEGIN
  608. SELECT '1' ErrorCode
  609. ,'Customer with same id number already approved.' Msg
  610. ,NULL
  611. RETURN
  612. END
  613. EXEC PROC_CREATE_CUSTOMER_WALLET @CUSTOMER_ID = @customerId
  614. ,@USER = @USER
  615. --return
  616. IF(@status = 'NOT_COMPLETED')
  617. BEGIN
  618. UPDATE dbo.customerMaster
  619. SET verifiedDate = CASE WHEN verifiedDate IS NULL THEN GETDATE() ELSE verifiedDate END
  620. ,mobileverifiedby = CASE
  621. WHEN @createdFrom IN ('O','M')
  622. THEN @user
  623. ELSE NULL
  624. END
  625. ,mobileverifieddate = CASE
  626. WHEN @createdFrom IN ('O','M')
  627. THEN GETDATE()
  628. ELSE NULL
  629. END
  630. ,verifiedBy = @user
  631. ,verificationCode = 'PROCESSING'
  632. WHERE customerId = @customerId
  633. SELECT '0' ErrorCode
  634. ,'Customer verification status has been updated. Proceed to approve customer!' Msg
  635. ,@customerId id
  636. RETURN
  637. END
  638. ELSE IF(@status = 'PROCESSING')
  639. BEGIN
  640. UPDATE dbo.customerMaster
  641. SET approvedBy = @user
  642. ,approvedDate = GETDATE()
  643. ,username = email
  644. ,mobileApprovedDate = CASE
  645. WHEN @createdFrom IN ('O','M')
  646. THEN GETDATE()
  647. ELSE NULL
  648. END
  649. ,mobileApprovedBy = CASE
  650. WHEN @createdFrom IN ('O','M')
  651. THEN @user
  652. ELSE NULL
  653. END
  654. ,ofacRemarks = @ofacRemarks
  655. ,isOfac = @isOfac
  656. ,lawsonCardNo = CASE WHEN ISNULL(lawsonCardNo,'')='' THEN 'KYC_NOW' ELSE lawsonCardNo END
  657. ,isVerifiedByCustomer=1
  658. ,verificationCode = 'COMPLETED'
  659. WHERE customerId = @customerId
  660. IF NOT EXISTS (
  661. SELECT 1
  662. FROM dbo.TBL_CUSTOMER_KYC
  663. WHERE customerId = @customerId AND kycStatus = '11044'
  664. AND isDeleted <> '1' )
  665. BEGIN
  666. INSERT INTO TBL_CUSTOMER_KYC (
  667. customerId
  668. ,kycmethod
  669. ,kycStatus
  670. ,remarks
  671. ,createdBy
  672. ,createdDate
  673. ,trackingNo
  674. ,KYC_DATE
  675. )
  676. VALUES (
  677. @customerId
  678. ,CASE WHEN @createdFrom = 'C' THEN '11048' --counter visit
  679. WHEN @createdFrom = 'M' THEN '11051' --mobile app
  680. WHEN @createdFrom = 'O' THEN '11444' --web online
  681. ELSE ''
  682. END
  683. ,'11044'
  684. ,'KYC has been completed'
  685. ,@user
  686. ,GETDATE()
  687. ,''
  688. ,GETDATE()
  689. );
  690. END
  691. IF(@referelCode IS NOT NULL)
  692. BEGIN
  693. SELECT @referalid=customerId FROM customerMaster WHERE membershipId = @referelCode;
  694. IF NOT EXISTS(select 'X' FROM Customer_Promotion where sourceCustomerid= @referalid and destinationcustomerid=@customerId
  695. AND CodeType='REGISTRATION')
  696. BEGIN
  697. EXEC proc_InsertRewardPoints @Flag = 'REGISTER', @CustomerId = @customerId, @ReferralId = @referalid
  698. END
  699. END
  700. END
  701. ELSE IF(@status = 'COMPLETED' AND @createdFrom='C')
  702. BEGIN
  703. PRINT @createdFrom
  704. UPDATE dbo.customerMaster
  705. SET approvedBy = @user
  706. ,approvedDate = GETDATE()
  707. ,username = email
  708. ,ofacRemarks = @ofacRemarks
  709. ,isOfac = @isOfac
  710. ,lawsonCardNo = CASE WHEN ISNULL(lawsonCardNo,'')='' THEN 'KYC_NOW' ELSE lawsonCardNo END
  711. ,isVerifiedByCustomer=1
  712. WHERE customerId = @customerId
  713. END
  714. SELECT '0' ErrorCode
  715. ,'Customer approved successfully.' Msg
  716. ,@customerId id
  717. SELECT username = ISNULL(cm.userName, '')
  718. ,[password] = dbo.FNADecryptString(cm.customerPassword)
  719. ,[channel] = 'registration'
  720. ,[account] = ISNULL(cm.membershipId, '')
  721. ,fullName
  722. ,CustomerBankName
  723. ,cm.idType
  724. ,cm.createdFrom
  725. ,cm.ofacRemarks
  726. ,REPLACE(cm.idNumber, ' ', '') AS [idNumber]
  727. ,CONVERT(VARCHAR, cm.dob, 111) AS [dob]
  728. ,printLetter = CASE
  729. WHEN ISNULL(serviceUsedFor, 'C') LIKE '%M%'
  730. THEN 'Y'
  731. ELSE 'N'
  732. END
  733. ,email
  734. FROM dbo.customerMaster cm(NOLOCK)
  735. WHERE cm.customerId = @customerId
  736. RETURN
  737. END
  738. ELSE IF @flag = 'verify-mobile-user'
  739. BEGIN
  740. IF NOT EXISTS (
  741. SELECT *
  742. FROM CUSTOMERMASTER(NOLOCK)
  743. WHERE CUSTOMERID = @customerId
  744. AND mobileapproveddate IS NULL
  745. )
  746. BEGIN
  747. SELECT '1' ErrorCode
  748. ,'Customer already approved or does not exists!' Msg
  749. ,NULL
  750. RETURN
  751. END
  752. SELECT @customerStatus = customerStatus
  753. ,@createdFrom = createdFrom
  754. FROM customerMaster
  755. WHERE customerId = @customerId
  756. IF @verifyType = 'verify'
  757. BEGIN
  758. IF @isValidatedCustomer = 'Y'
  759. AND @verifyRemarks IS NULL
  760. BEGIN
  761. UPDATE CUSTOMERMASTER
  762. SET mobileVerifiedby = @user
  763. ,mobileVerifiedDate = Getdate()
  764. ,mobileVerificationType = 'verified'
  765. WHERE customerId = @customerId
  766. END
  767. SELECT @newData = CONCAT (
  768. ISNULL(@user, '')
  769. ,'|'
  770. ,ISNULL(CAST(Getdate() AS VARCHAR), '')
  771. ,'|'
  772. ,'Verified'
  773. ,'|'
  774. ,ISNULL(@verifyType, '')
  775. )
  776. --EXEC proc_applicationLogs @flag = 'i'
  777. -- ,@logType = 'verify-mobile-user'
  778. -- ,@tableName ='CustomerMaster'
  779. -- ,@dataId = @customerId
  780. -- ,@oldData =
  781. -- ,@newData = @newData
  782. -- ,@module = '22'
  783. -- ,@user = @user
  784. INSERT INTO applicationLogs (
  785. logType
  786. ,tableName
  787. ,dataId
  788. ,oldData
  789. ,newData
  790. ,module
  791. ,createdBy
  792. ,createdDate
  793. )
  794. VALUES (
  795. 'verify-mobile-user-existing'
  796. ,'CustomerMaster'
  797. ,@customerId
  798. ,'verify-existing'
  799. ,@newData
  800. ,'22'
  801. ,@user
  802. ,GETDATE()
  803. )
  804. SELECT '0' ErrorCode
  805. -- ,'Customer Verified Successfully.' Msg
  806. ,CASE
  807. WHEN @isValidatedCustomer = 'Y' AND @verifyRemarks IS NULL
  808. THEN 'Y'
  809. WHEN @isValidatedCustomer = 'Y' AND @verifyRemarks IS NOT NULL
  810. THEN 'R'
  811. ELSE 'N'
  812. END Msg
  813. ,@customerId id
  814. ,'Y' extra
  815. ,'verified' EXTRA2
  816. END
  817. IF @verifyType = 'approve'
  818. SET @isOfac = CASE
  819. WHEN ISNULL(@ofacRemarks, '') = ''
  820. THEN 'N'
  821. ELSE 'Y'
  822. END
  823. BEGIN
  824. UPDATE CUSTOMERMASTER
  825. SET mobileApprovedBy = @user
  826. ,mobileApprovedDate = Getdate()
  827. ,mobileVerificationType = 'approved'
  828. ,serviceUsedFor = 'CM'
  829. --,HasDeclare = 1
  830. --,agreeYn = 1
  831. -- ,isForcedPwdChange = 1
  832. --,isEmailVerified = 0
  833. ,createdFrom = 'C'
  834. ,mobileUser = 'Y'
  835. ,ofacRemarks = @ofacRemarks
  836. ,isOfac = @isOfac
  837. --,referelCode = ISNULL(@referral,referelCode)
  838. --,customerStatus = 'OTC'
  839. -- ,customerPassword= dbo.FNAEncryptString(@password)
  840. WHERE customerId = @customerId
  841. IF EXISTS (SELECT 'X' FROM Customer_Promotion P (NOLOCK) WHERE destinationCustomerId = @customerId AND codeType = 'REGISTRATION')
  842. BEGIN
  843. SELECT @sourceCustomerId = sourceCustomerId , @rewardValue = amount
  844. FROM Customer_Promotion (NOLOCK)
  845. WHERE destinationCustomerId = @customerId
  846. AND codeType = 'REGISTRATION'
  847. SELECT @bonusPoint = ISNULL(bonusPoint, 0)
  848. FROM customerMaster (NOLOCK)
  849. WHERE customerId = @sourceCustomerId
  850. UPDATE Customer_Promotion SET approvedDate = GETDATE() , [status] = 1 ,
  851. runningBalance = ISNULL(runningBalance,0) + ISNULL(amount,0)
  852. WHERE destinationCustomerId = @customerId
  853. AND codeType = 'REGISTRATION'
  854. UPDATE CUSTOMERMASTER SET bonusPoint = @bonusPoint + @rewardValue
  855. WHERE customerId = @sourceCustomerId
  856. END
  857. SELECT @newData = CONCAT (
  858. ISNULL(@user, '')
  859. ,'|'
  860. ,ISNULL(CAST(Getdate() AS VARCHAR), '')
  861. ,'|'
  862. ,'approved|CM'
  863. ,'|'
  864. ,ISNULL(@verifyType, '')
  865. )
  866. INSERT INTO applicationLogs (
  867. logType
  868. ,tableName
  869. ,dataId
  870. ,oldData
  871. ,newData
  872. ,module
  873. ,createdBy
  874. ,createdDate
  875. )
  876. VALUES (
  877. 'approve-mobile-user-existing'
  878. ,'CustomerMaster'
  879. ,@customerId
  880. ,'approve-existing'
  881. ,@newData
  882. ,'23'
  883. ,@user
  884. ,GETDATE()
  885. )
  886. SELECT '0' ErrorCode
  887. ,'Customer approved successfully.' Msg
  888. ,@customerId id
  889. ,CASE
  890. WHEN @customerStatus = 'OTC'
  891. THEN 'N'
  892. WHEN @createdFrom = 'M'
  893. THEN 'N'
  894. ELSE 'Y'
  895. END extra
  896. ,'approved' EXTRA2
  897. END
  898. SELECT username = ISNULL(cm.userName, '')
  899. ,[password] = dbo.FNADecryptString(cm.customerPassword)
  900. ,[channel] = 'registration'
  901. ,[account] = ISNULL(cm.membershipId, '')
  902. ,fullName
  903. ,CustomerBankName
  904. ,cm.idType
  905. ,cm.ofacRemarks
  906. ,REPLACE(cm.idNumber, ' ', '') AS [idNumber]
  907. ,CONVERT(VARCHAR, cm.dob, 111) AS [dob]
  908. FROM dbo.customerMaster cm(NOLOCK)
  909. WHERE cm.customerId = @customerId
  910. RETURN
  911. END
  912. ELSE IF @flag = 'approve-pending-mobile'
  913. BEGIN
  914. DECLARE @isExistingCustomer BIT
  915. ,@existingemail VARCHAR(50)
  916. DECLARE @customerStatusmobile NVARCHAR(100)
  917. ,@createdFromMobile VARCHAR(5)
  918. ,@trustDocId UNIQUEIDENTIFIER = NULL
  919. --SELECT @customerStatusmobile = customerStatus
  920. --FROM customerMaster
  921. --WHERE customerId = @customerId
  922. --SELECT @createdFromMobile = createdFrom
  923. --FROM customerMaster
  924. --WHERE customerId = @customerId
  925. SELECT @custIdNumber = idNumber
  926. ,@fullName = ISNULL(fullName, firstName)
  927. ,@isExistingCustomer = ISNULL(isExistingCustomer, 0)
  928. ,@existingemail = email
  929. ,@customerStatusmobile = customerStatus
  930. ,@createdFromMobile = createdFrom
  931. ,@trustDocId=TrustDocId
  932. FROM dbo.customerMaster(NOLOCK)
  933. WHERE customerId = @customerId
  934. IF ISNULL(@isExistingCustomer, 0) = 1
  935. BEGIN
  936. IF NOT EXISTS (
  937. SELECT *
  938. FROM CUSTOMERMASTER(NOLOCK)
  939. WHERE CUSTOMERID = @customerId
  940. AND mobileapprovedDate IS NULL
  941. )
  942. BEGIN
  943. SELECT '1' ErrorCode
  944. ,'Customer already approved or does not exists!' Msg
  945. ,NULL
  946. RETURN
  947. END
  948. IF EXISTS (
  949. SELECT *
  950. FROM CUSTOMERMASTER(NOLOCK)
  951. WHERE email = @existingemail
  952. AND mobileApprovedDate IS NOT NULL
  953. )
  954. BEGIN
  955. SELECT '1' ErrorCode
  956. ,'Customer with same email already exists! Please try again with a different email.' Msg
  957. ,NULL
  958. RETURN
  959. END
  960. IF @verifyType = 'verify'
  961. BEGIN
  962. IF @isValidatedCustomer = 'Y'
  963. AND @verifyRemarks IS NULL
  964. BEGIN
  965. UPDATE CUSTOMERMASTER
  966. SET mobileVerifiedby = @user
  967. ,mobileVerifiedDate = Getdate()
  968. ,mobileVerificationType = 'verified'
  969. WHERE customerId = @customerId
  970. END
  971. PRINT 'A';
  972. SELECT @newData = CONCAT (
  973. ISNULL(@user, '')
  974. ,'|'
  975. ,ISNULL(CAST(Getdate() AS VARCHAR), '')
  976. ,'|'
  977. ,'verified'
  978. ,'|'
  979. ,ISNULL(@verifyType, '')
  980. )
  981. INSERT INTO applicationLogs (
  982. logType
  983. ,tableName
  984. ,dataId
  985. ,oldData
  986. ,newData
  987. ,module
  988. ,createdBy
  989. ,createdDate
  990. )
  991. VALUES (
  992. 'approve-mobile-user-verify'
  993. ,'CustomerMaster'
  994. ,@customerId
  995. ,'verify-new-user'
  996. ,@newData
  997. ,'24'
  998. ,@user
  999. ,GETDATE()
  1000. )
  1001. SELECT '0' ErrorCode
  1002. --,'Customer verified successfully.' Msg
  1003. ,CASE
  1004. WHEN @isValidatedCustomer = 'Y' AND @verifyRemarks IS NULL
  1005. THEN 'Y'
  1006. WHEN @isValidatedCustomer = 'Y' AND @verifyRemarks IS NOT NULL
  1007. THEN 'R'
  1008. ELSE 'N'
  1009. END Msg
  1010. ,@customerId id
  1011. ,'Y' extra
  1012. ,'verified' EXTRA2
  1013. END
  1014. IF @verifyType = 'approve'
  1015. BEGIN
  1016. SET @isOfac = CASE
  1017. WHEN ISNULL(@ofacRemarks, '') = ''
  1018. THEN 'N'
  1019. ELSE 'Y'
  1020. END
  1021. UPDATE CUSTOMERMASTER
  1022. SET mobileApprovedBy = @user
  1023. ,mobileApprovedDate = Getdate()
  1024. ,mobileVerificationType = 'approved'
  1025. ,serviceUsedFor = 'CM'
  1026. ,referelCode = ISNULL(@referral, referelCode)
  1027. ,HasDeclare = 1
  1028. ,agreeYn = 1
  1029. ,username = ISNULL(username, email)
  1030. ,ofacRemarks = @ofacRemarks
  1031. ,isOfac = @isOfac
  1032. WHERE customerId = @customerId
  1033. IF @trustDocId IS NOT NULL
  1034. BEGIN
  1035. UPDATE trustDocCustomer SET verifiedDate=GETDATE() , verified=1 WHERE id=@trustDocId and customerId= @customerId;
  1036. END
  1037. IF EXISTS (SELECT 'X' FROM Customer_Promotion P (NOLOCK) WHERE destinationCustomerId = @customerId AND codeType = 'REGISTRATION')
  1038. BEGIN
  1039. SELECT @sourceCustomerId = sourceCustomerId , @rewardValue = amount
  1040. FROM Customer_Promotion (NOLOCK)
  1041. WHERE destinationCustomerId = @customerId
  1042. AND codeType = 'REGISTRATION'
  1043. SELECT @bonusPoint = ISNULL(bonusPoint, 0)
  1044. FROM customerMaster (NOLOCK)
  1045. WHERE customerId = @sourceCustomerId
  1046. UPDATE Customer_Promotion SET approvedDate = GETDATE() , [status] = 1 ,
  1047. runningBalance = ISNULL(runningBalance,0) + ISNULL(amount,0)
  1048. WHERE destinationCustomerId = @customerId
  1049. AND codeType = 'REGISTRATION'
  1050. UPDATE CUSTOMERMASTER SET bonusPoint = @bonusPoint + @rewardValue
  1051. WHERE customerId = @sourceCustomerId
  1052. END
  1053. SELECT @newData = CONCAT (
  1054. ISNULL(@user, '')
  1055. ,'|'
  1056. ,ISNULL(CAST(Getdate() AS VARCHAR), '')
  1057. ,'|'
  1058. ,'approved|CM'
  1059. ,'|'
  1060. ,ISNULL(@verifyType, '')
  1061. )
  1062. INSERT INTO applicationLogs (
  1063. logType
  1064. ,tableName
  1065. ,dataId
  1066. ,oldData
  1067. ,newData
  1068. ,module
  1069. ,createdBy
  1070. ,createdDate
  1071. )
  1072. VALUES (
  1073. 'approve-mobile-user'
  1074. ,'CustomerMaster'
  1075. ,@customerId
  1076. ,'approve-new-user'
  1077. ,@newData
  1078. ,'25'
  1079. ,@user
  1080. ,GETDATE()
  1081. )
  1082. SELECT '0' ErrorCode
  1083. ,'Customer approved successfully.' Msg
  1084. ,@customerId id
  1085. ,CASE
  1086. WHEN @customerStatusmobile = 'OTC'
  1087. THEN 'N'
  1088. WHEN @createdFromMobile = 'M'
  1089. THEN 'N'
  1090. ELSE 'Y'
  1091. END extra
  1092. ,'approved' EXTRA2
  1093. END
  1094. SELECT username = ISNULL(cm.userName, '')
  1095. ,[password] = dbo.FNADecryptString(cm.customerPassword)
  1096. ,[channel] = 'registration'
  1097. ,[account] = ISNULL(cm.membershipId, '')
  1098. ,fullName
  1099. ,CustomerBankName
  1100. ,cm.idType
  1101. ,cm.ofacRemarks
  1102. ,REPLACE(cm.idNumber, ' ', '') AS [idNumber]
  1103. ,CONVERT(VARCHAR, cm.dob, 111) AS [dob]
  1104. FROM dbo.customerMaster cm(NOLOCK)
  1105. WHERE cm.customerId = @customerId
  1106. RETURN
  1107. END
  1108. IF NOT EXISTS (
  1109. SELECT *
  1110. FROM CUSTOMERMASTER(NOLOCK)
  1111. WHERE CUSTOMERID = @customerId
  1112. AND mobileapprovedDate IS NULL
  1113. )
  1114. BEGIN
  1115. SELECT '1' ErrorCode
  1116. ,'Customer already approved or does not exists!' Msg
  1117. ,NULL
  1118. RETURN
  1119. END
  1120. IF EXISTS (
  1121. SELECT 'X'
  1122. FROM dbo.customerMaster(NOLOCK)
  1123. WHERE replace(idNumber, '-', '') = replace(@custIdNumber, '-', '')
  1124. GROUP BY replace(idNumber, '-', '')
  1125. HAVING count(1) > 1
  1126. )
  1127. BEGIN
  1128. SELECT '1' ErrorCode
  1129. ,'Duplicate id number found for customer' Msg
  1130. ,NULL
  1131. RETURN
  1132. END
  1133. IF EXISTS (
  1134. SELECT 'X'
  1135. FROM dbo.customerMaster(NOLOCK)
  1136. WHERE replace(idNumber, '-', '') = replace(@custIdNumber, '-', '')
  1137. AND mobileapprovedDate IS NOT NULL
  1138. AND ISNULL(@isExistingCustomer, 1) = 0
  1139. )
  1140. BEGIN
  1141. SELECT '1' ErrorCode
  1142. ,'Customer with same id number already approved.' Msg
  1143. ,NULL
  1144. RETURN
  1145. END
  1146. EXEC PROC_CREATE_CUSTOMER_WALLET @CUSTOMER_ID = @customerId
  1147. ,@USER = @USER
  1148. IF @verifyType = 'verify'
  1149. BEGIN
  1150. IF @isValidatedCustomer = 'Y' AND (@verifyRemarks IS NULL OR @verifyRemarks='')
  1151. BEGIN
  1152. UPDATE CUSTOMERMASTER
  1153. SET mobileVerifiedby = @user
  1154. ,mobileVerifiedDate = Getdate()
  1155. ,mobileVerificationType = 'verified'
  1156. --,serviceUsedFor = 'CM'
  1157. WHERE customerId = @customerId
  1158. END
  1159. INSERT INTO applicationLogs (
  1160. logType
  1161. ,tableName
  1162. ,dataId
  1163. ,oldData
  1164. ,newData
  1165. ,module
  1166. ,createdBy
  1167. ,createdDate
  1168. )
  1169. VALUES (
  1170. 'approve-mobile-user-verify'
  1171. ,'CustomerMaster'
  1172. ,@customerId
  1173. ,'verify-new-user'
  1174. ,@verifyRemarks
  1175. ,'24'
  1176. ,@user
  1177. ,GETDATE()
  1178. )
  1179. SELECT '0' ErrorCode
  1180. --,'Customer verified successfully.' Msg
  1181. ,CASE
  1182. WHEN @isValidatedCustomer = 'Y' AND @verifyRemarks IS NULL
  1183. THEN 'Y'
  1184. WHEN @isValidatedCustomer = 'Y' AND @verifyRemarks IS NOT NULL
  1185. THEN 'R'
  1186. ELSE 'N'
  1187. END Msg
  1188. ,@customerId id
  1189. ,'Y' extra
  1190. ,'verified' EXTRA2
  1191. END
  1192. IF @verifyType = 'approve'
  1193. BEGIN
  1194. SET @isOfac = CASE
  1195. WHEN ISNULL(@ofacRemarks, '') = ''
  1196. THEN 'N'
  1197. ELSE 'Y'
  1198. END
  1199. UPDATE CUSTOMERMASTER
  1200. SET mobileApprovedBy = @user
  1201. ,mobileApprovedDate = Getdate()
  1202. ,mobileVerificationType = 'approved'
  1203. ,serviceUsedFor = 'CM'
  1204. ,approvedBy = @user
  1205. ,approvedDate = GETDATE()
  1206. ,mobileUser = 'Y'
  1207. ,ofacRemarks = @ofacRemarks
  1208. ,isOfac = @isOfac
  1209. WHERE customerId = @customerId
  1210. IF @trustDocId IS NOT NULL
  1211. BEGIN
  1212. UPDATE trustDocCustomer SET verifiedDate=GETDATE() , verified=1 WHERE id=@trustDocId and customerId= @customerId;
  1213. --DECLARE @body varchar(150), @pinNo INT= DBO.FNAGetRandomTransactionPinNo(6);
  1214. -- update customerMaster set txnPin = @pinNo where customerId = @customerId and RegistrationType='EKYC';
  1215. --SET @body='Your Transaction PIN is '+ CAST( @pinNo AS varchar) +', please click notification at the top of dashboard to change it.';
  1216. -- INSERT INTO pushNotificationHistroy(customerId,body,title,createDate,imageURL,sentId,Type,isReservation,isRead,isSend,category)
  1217. -- SELECT @customerid,@body,'Txn Pin',getdate(),'',@customerId,0,0,0,0,'INFO'
  1218. END
  1219. IF EXISTS (SELECT 'X' FROM Customer_Promotion P (NOLOCK) WHERE destinationCustomerId = @customerId AND codeType = 'REGISTRATION')
  1220. BEGIN
  1221. SELECT @sourceCustomerId = sourceCustomerId , @rewardValue = amount
  1222. FROM Customer_Promotion (NOLOCK)
  1223. WHERE destinationCustomerId = @customerId
  1224. AND codeType = 'REGISTRATION'
  1225. SELECT @bonusPoint = ISNULL(bonusPoint, 0)
  1226. FROM customerMaster (NOLOCK)
  1227. WHERE customerId = @sourceCustomerId
  1228. UPDATE Customer_Promotion SET approvedDate = GETDATE() , [status] = 1 ,
  1229. runningBalance = ISNULL(runningBalance,0) + ISNULL(amount,0)
  1230. WHERE destinationCustomerId = @customerId
  1231. AND codeType = 'REGISTRATION'
  1232. UPDATE CUSTOMERMASTER SET bonusPoint = @bonusPoint + @rewardValue
  1233. WHERE customerId = @sourceCustomerId
  1234. END
  1235. SELECT '0' ErrorCode
  1236. ,'Customer approved successfully.' Msg
  1237. ,@customerId id
  1238. ,CASE
  1239. WHEN @customerStatusmobile = 'OTC'
  1240. THEN 'N'
  1241. WHEN @createdFromMobile = 'M'
  1242. THEN 'N'
  1243. ELSE 'Y'
  1244. END extra
  1245. ,'approved' EXTRA2
  1246. END
  1247. SELECT username = ISNULL(cm.userName, '')
  1248. ,[password] = dbo.FNADecryptString(cm.customerPassword)
  1249. ,[channel] = 'registration'
  1250. ,[account] = ISNULL(cm.membershipId, '')
  1251. ,fullName
  1252. ,CustomerBankName
  1253. ,cm.idType
  1254. ,REPLACE(cm.idNumber, ' ', '') AS [idNumber]
  1255. ,CONVERT(VARCHAR, cm.dob, 111) AS [dob]
  1256. FROM dbo.customerMaster cm(NOLOCK)
  1257. WHERE cm.customerId = @customerId
  1258. --For mobile broadcast notification
  1259. --EXEC ProcBroadCastMobile @Flag = 'customer-approve'
  1260. -- ,@RowId = @customerId
  1261. -- ,@ControlNo = @customerId
  1262. -- ,@CustomerId = @customerId
  1263. RETURN
  1264. END
  1265. ELSE IF @flag = 'update-obpId'
  1266. BEGIN
  1267. BEGIN TRAN
  1268. UPDATE dbo.customerMaster
  1269. SET obpId = @obpId
  1270. ,approvedDate = GETDATE()
  1271. ,approvedBy = @user
  1272. ,customerStatus = 'V'
  1273. ,verifiedBy = CASE
  1274. WHEN verifiedBy IS NULL
  1275. THEN @user
  1276. ELSE verifiedBy
  1277. END
  1278. ,verifiedDate = CASE
  1279. WHEN verifiedDate IS NULL
  1280. THEN GETDATE()
  1281. ELSE verifiedDate
  1282. END
  1283. WHERE customerId = @customerId
  1284. DECLARE @Mobile VARCHAR(20)
  1285. SELECT @virtualAccountNo = walletAccountNo
  1286. ,@CustomerBankName = firstName + '- Principle'
  1287. ,@Mobile = mobile
  1288. FROM customerMaster(NOLOCK)
  1289. WHERE customerId = @customerId
  1290. ----#### SEND NOTIFICATION TO CUSTOMER
  1291. DECLARE @SMSBody VARCHAR(90) = 'Dear ' + LEFT(@CustomerBankName, 14) + ' You are successfully registered with GME.Thank you for choosing GME.'
  1292. EXEC FastMoneyPro_Remit.dbo.proc_CallToSendSMS @FLAG = 'I'
  1293. ,@SMSBody = @SMSBody
  1294. ,@MobileNo = @Mobile
  1295. IF NOT EXISTS (
  1296. SELECT 'A'
  1297. FROM FastMoneyPro_Account.dbo.ac_master(NOLOCK)
  1298. WHERE acct_num = @virtualAccountNo
  1299. )
  1300. BEGIN
  1301. DECLARE @GL INT = 79
  1302. INSERT INTO FastMoneyPro_Account.dbo.ac_master (
  1303. acct_num
  1304. ,acct_name
  1305. ,gl_code
  1306. ,branch_id
  1307. ,acct_ownership
  1308. ,acct_rpt_code
  1309. ,acct_opn_date
  1310. ,clr_bal_amt
  1311. ,system_reserved_amt
  1312. ,lien_amt
  1313. ,utilised_amt
  1314. ,available_amt
  1315. ,created_date
  1316. ,created_by
  1317. ,company_id
  1318. )
  1319. SELECT @virtualAccountNo
  1320. ,@CustomerBankName
  1321. ,@GL
  1322. ,@customerId
  1323. ,'c'
  1324. ,'CP'
  1325. ,getdate()
  1326. ,0
  1327. ,0
  1328. ,0
  1329. ,0
  1330. ,0
  1331. ,getdate()
  1332. ,@user
  1333. ,1
  1334. END
  1335. COMMIT TRAN
  1336. SELECT '0' ErrorCode
  1337. ,'Customer Partern service account registered successfully.' Msg
  1338. ,@customerId id
  1339. END
  1340. ELSE IF @flag = 'checkVirtualNo'
  1341. BEGIN
  1342. IF NOT EXISTS (
  1343. SELECT 'X'
  1344. FROM dbo.customerMaster
  1345. WHERE walletAccountNo = @virtualAccountNo
  1346. )
  1347. SELECT '1' ErrorCode
  1348. ,'Invalid Virtual AccountNo' Msg
  1349. ,NULL id
  1350. RETURN;
  1351. END
  1352. ELSE IF @flag = 'checkPrimaryAccountNo'
  1353. BEGIN
  1354. IF NOT EXISTS (
  1355. SELECT 'X'
  1356. FROM dbo.customerMaster
  1357. WHERE bankAccountNo = @primaryAccountNo
  1358. )
  1359. SELECT '1' ErrorCode
  1360. ,'Invalid Primary AccountNo' Msg
  1361. ,NULL id
  1362. END
  1363. ELSE IF @flag = 'AuditList' --AUDITED DOC LIST
  1364. BEGIN
  1365. SET @sortBy = 'createdDate'
  1366. SET @sortOrder = 'desc'
  1367. SET @table =
  1368. '(
  1369. SELECT SN=ROW_NUMBER() over(ORDER BY cm.customerId asc)
  1370. ,customerId=cm.customerId
  1371. ,email=cm.email
  1372. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  1373. ,dob=CONVERT(VARCHAR,cm.dob,101)
  1374. ,address=cm.[address]
  1375. ,nativeCountry=com.countryName
  1376. ,idtype=sdv.detailTitle
  1377. ,idNumber=cm.idNumber
  1378. ,createdDate=CAST(cm.createdDate AS DATE)
  1379. ,verifiedBy=cm.verifiedBy
  1380. ,branchName=''''
  1381. ,verifiedDate=CAST(cm.verifiedDate AS DATE)
  1382. ,ipAddress=cm.ipAddress
  1383. ,mobile=cm.mobile
  1384. ,bankAccountNo
  1385. ,bankName=bl.bankName
  1386. ,cm.AuditBy,cm.AuditDate
  1387. FROM customerMaster cm(NOLOCK)
  1388. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  1389. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  1390. LEFT JOIN vwBankLists bl (NOLOCK) ON cm.bankName = bl.rowId
  1391. WHERE cm.verifiedDate IS NOT NULL AND cm.AuditDate IS NOT NULL'
  1392. IF ISNULL(@fromDate, '') <> ''
  1393. AND ISNULL(@toDate, '') <> ''
  1394. SET @table = @table + ' AND cm.createdDate BETWEEN ''' + CAST(@fromDate AS VARCHAR) + ''' AND ''' + CAST(@toDate AS VARCHAR) + ''''
  1395. SET @table = @table + ')x'
  1396. SET @sql_filter = ''
  1397. IF ISNULL(@searchCriteria, '') <> ''
  1398. AND ISNULL(@searchValue, '') <> ''
  1399. BEGIN
  1400. IF @searchCriteria = 'idNumber'
  1401. BEGIN
  1402. --IF ISNUMERIC(@searchValue)<>1
  1403. -- SET @searchValue='-1' --to ignore string value for datatype integer/customerID
  1404. --SET @sql_Filter=@sql_Filter + ' AND customerId = ''' +@searchValue+''''
  1405. SET @sql_Filter = @sql_Filter + ' AND REPLACE(idNumber, ''-'', '''') = ''' + REPLACE(@searchValue, '-', '') + ''''
  1406. END
  1407. ELSE IF @searchCriteria = 'emailId'
  1408. SET @sql_Filter = @sql_Filter + ' AND email like ''' + @searchValue + '%'''
  1409. ELSE IF @searchCriteria = 'customerName'
  1410. SET @sql_Filter = @sql_Filter + ' AND fullName like ''' + @searchValue + '%'''
  1411. ELSE IF @searchCriteria = 'mobile'
  1412. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  1413. ELSE IF @searchCriteria = 'walletAccountNo'
  1414. SET @sql_Filter = @sql_Filter + ' AND walletAccountNo = ''' + @searchValue + ''''
  1415. ELSE IF @searchCriteria = 'bankAccountNo'
  1416. SET @sql_Filter = @sql_Filter + ' AND bankAccountNo = ''' + @searchValue + ''''
  1417. ELSE IF @searchCriteria = 'nativeCountry'
  1418. SET @sql_Filter = @sql_Filter + ' AND nativeCountry = ''' + @searchValue + ''''
  1419. END
  1420. SET @select_field_list = '
  1421. SN,customerId,email,fullName,dob,address,nativeCountry,idtype,idNumber
  1422. ,createdDate,verifiedBy,branchName,verifiedDate,bankAccountNo,bankName,AuditBy,AuditDate
  1423. '
  1424. EXEC dbo.proc_paging @table
  1425. ,@sql_filter
  1426. ,@select_field_list
  1427. ,@extra_field_list
  1428. ,@sortBy
  1429. ,@sortOrder
  1430. ,@pageSize
  1431. ,@pageNumber
  1432. RETURN
  1433. END
  1434. ELSE IF @flag = 's-customereditedata'
  1435. BEGIN
  1436. IF @sortBy IS NULL
  1437. SET @sortBy = 'createdDate'
  1438. IF @sortOrder IS NULL
  1439. SET @sortOrder = 'DESC'
  1440. SET @table = '(
  1441. SELECT fullName
  1442. ,customerId
  1443. ,membershipId
  1444. ,mobile
  1445. ,city
  1446. ,rowId
  1447. ,createdDate
  1448. ,hasChanged = CASE WHEN approvedBy IS NULL THEN ''Y'' ELSE ''N'' END
  1449. ,modifiedBy = CASE WHEN approvedBy IS NULL THEN createdBy ELSE createdBy END
  1450. from customerMasterEditedDataMod
  1451. )x'
  1452. SET @sql_filter = ''
  1453. SET @select_field_list = 'fullName,customerId,membershipId,mobile,city,rowId,createdDate,hasChanged,modifiedBy'
  1454. EXEC dbo.proc_paging @table
  1455. ,@sql_filter
  1456. ,@select_field_list
  1457. ,@extra_field_list
  1458. ,@sortBy
  1459. ,@sortOrder
  1460. ,@pageSize
  1461. ,@pageNumber
  1462. END
  1463. ELSE IF @flag = 's-customereditedata-new'
  1464. BEGIN
  1465. IF @sortBy IS NULL
  1466. SET @sortBy = 'createdDate'
  1467. IF @sortOrder IS NULL
  1468. SET @sortOrder = 'DESC'
  1469. SET @table = '(
  1470. SELECT cm.fullName
  1471. ,cm.customerId
  1472. ,cm.membershipId
  1473. ,cm.mobile
  1474. ,cm.city
  1475. ,cmMode.rowId
  1476. ,cm.createdDate
  1477. ,hasChanged = CASE WHEN cmMode.approvedBy IS NULL THEN ''Y'' ELSE ''N'' END
  1478. ,modifiedBy = CASE WHEN cmMode.approvedBy IS NULL THEN cmMode.createdBy ELSE cmMode.createdBy END
  1479. ,case when ISNULL(cm.createdFrom, ''C'') = ''C'' THEN ''COUNTER'' WHEN cm.createdFrom = ''M'' THEN ''MOBILE'' ELSE cm.createdFrom END createdFrom
  1480. from customerMasterEditedDataMod cmMode (nolock)
  1481. INNER JOIN CUSTOMERMASTER CM (NOLOCK) ON CM.CUSTOMERID = cmMode.customerId
  1482. )x'
  1483. SET @sql_filter = ''
  1484. SET @select_field_list = 'fullName,customerId,membershipId,mobile,city,rowId,createdDate,hasChanged,modifiedBy'
  1485. EXEC dbo.proc_paging @table
  1486. ,@sql_filter
  1487. ,@select_field_list
  1488. ,@extra_field_list
  1489. ,@sortBy
  1490. ,@sortOrder
  1491. ,@pageSize
  1492. ,@pageNumber
  1493. END
  1494. ELSE IF @flag = 'approve'
  1495. BEGIN
  1496. DECLARE @firstName VARCHAR(30) = NULL
  1497. ,@middleName VARCHAR(30) = NULL
  1498. ,@lastName1 VARCHAR(100) = NULL
  1499. ,@onlineUser VARCHAR(50) = NULL
  1500. ,@customerType VARCHAR(30) = NULL
  1501. ,@country VARCHAR(30) = NULL
  1502. ,@zipCode VARCHAR(30) = NULL
  1503. ,@state VARCHAR(30) = NULL
  1504. ,@street VARCHAR(80) = NULL
  1505. ,@custCity VARCHAR(100) = NULL
  1506. ,@cityUnicode NVARCHAR(100) = NULL
  1507. ,@streetUnicode NVARCHAR(100) = NULL
  1508. ,@custGender VARCHAR(30) = NULL
  1509. ,@custNativecountry VARCHAR(30) = NULL
  1510. ,@custDOB VARCHAR(30) = NULL
  1511. ,@custEmail VARCHAR(50) = NULL
  1512. ,@custTelNo VARCHAR(30) = NULL
  1513. ,@custMobile VARCHAR(30) = NULL
  1514. ,@dob DATETIME = NULL
  1515. ,@visaStatus INT = NULL
  1516. ,@employeeBusinessType INT = NULL
  1517. ,@nameOfEmployeer VARCHAR(80) = NULL
  1518. ,@SSNNO VARCHAR(20) = NULL
  1519. ,@occupation VARCHAR(30) = NULL
  1520. ,@sourceOfFound VARCHAR(100) = NULL
  1521. ,@monthlyIncome VARCHAR(50) = NULL
  1522. ,@customerIdType VARCHAR(30) = NULL
  1523. ,@customerIdNo VARCHAR(50) = NULL
  1524. ,@custIdissueDate VARCHAR(30) = NULL
  1525. ,@custIdValidDate VARCHAR(30) = NULL
  1526. ,@remittanceAllowed BIT = NULL
  1527. ,@remarks VARCHAR(1000) = NULL
  1528. ,@companyName VARCHAR(100) = NULL
  1529. ,@registerationNo VARCHAR(30) = NULL
  1530. ,@organizationType INT = NULL
  1531. ,@dateofIncorporation DATETIME = NULL
  1532. ,@natureOfCompany INT = NULL
  1533. ,@nameOfAuthorizedPerson VARCHAR(80) = NULL
  1534. ,@position INT = NULL
  1535. SELECT @customerId = customerId
  1536. ,@customerType = customerType
  1537. ,@fullName = fullName
  1538. ,@firstName = firstName
  1539. ,@middleName = middleName
  1540. ,@lastName1 = lastName1
  1541. ,@country = country
  1542. ,@zipCode = zipCode
  1543. ,@state = STATE
  1544. ,@street = street
  1545. ,@custCity = city
  1546. ,@cityUnicode = cityUnicode
  1547. ,@streetUnicode = streetUnicode
  1548. ,@custGender = gender
  1549. ,@custNativecountry = nativeCountry
  1550. ,@custDOB = CONVERT(VARCHAR, dob, 111)
  1551. ,@custEmail = email
  1552. ,@custTelNo = telNo
  1553. ,@custMobile = mobile
  1554. ,@visaStatus = visaStatus
  1555. ,@employeeBusinessType = employeeBusinessType
  1556. ,@nameOfEmployeer = nameOfEmployeer
  1557. ,@SSNNO = SSNNO
  1558. ,@occupation = occupation
  1559. ,@sourceOfFound = sourceOfFund
  1560. ,@monthlyIncome = monthlyIncome
  1561. ,@customerIdType = idType
  1562. ,@customerIdNo = idNumber
  1563. ,@custIdissueDate = CONVERT(VARCHAR, idIssueDate, 111)
  1564. ,@custIdValidDate = CONVERT(VARCHAR, idExpiryDate, 111)
  1565. ,@remittanceAllowed = remittanceAllowed
  1566. ,@onlineUser = onlineUser
  1567. ,@remarks = remarks
  1568. ,@companyName = companyName
  1569. ,@registerationNo = registerationNo
  1570. ,@organizationType = organizationType
  1571. ,@dateofIncorporation = CONVERT(VARCHAR, dateofIncorporation, 111)
  1572. ,@natureOfCompany = natureOfCompany
  1573. ,@nameOfAuthorizedPerson = nameOfAuthorizedPerson
  1574. ,@position = position
  1575. FROM dbo.customerMasterEditedDataMod
  1576. WHERE customerId = @customerId
  1577. --LOG FOR CUSTOMER UPDATE
  1578. --SET @fullName=ISNULL(@firstName, '') + ISNULL(' '
  1579. -- + @firstName,
  1580. -- '') + ISNULL(' '
  1581. -- + @lastName1, '');
  1582. SET @onlineUser = CASE
  1583. WHEN @onlineUser = 'Y'
  1584. THEN 'True'
  1585. ELSE 'False'
  1586. END
  1587. EXEC PROC_CUSTOMERMODIFYLOG @flag = 'i-new'
  1588. ,@user = @user
  1589. ,@customerId = @customerId
  1590. ,@customerType = @customerType
  1591. ,@fullName = @fullName
  1592. ,@firstName = @firstName
  1593. ,@middleName = @middleName
  1594. ,@lastName1 = @lastName1
  1595. ,@country = @country
  1596. ,@zipCode = @zipCode
  1597. ,@state = @state
  1598. ,@street = @street
  1599. ,@custCity = @custCity
  1600. ,@cityUnicode = @cityUnicode
  1601. ,@streetUnicode = @streetUnicode
  1602. ,@custGender = @custGender
  1603. ,@custNativecountry = @custNativecountry
  1604. ,@dob = @custDOB
  1605. ,@email = @custEmail
  1606. ,@custTelNo = @custTelNo
  1607. ,@mobileNumber = @custMobile
  1608. ,@visaStatus = @visaStatus
  1609. ,@employeeBusinessType = @employeeBusinessType
  1610. ,@nameOfEmployeer = @nameOfEmployeer
  1611. ,@SSNNO = @SSNNO
  1612. ,@occupation = @occupation
  1613. ,@sourceOfFound = @sourceOfFound
  1614. ,@monthlyIncome = @monthlyIncome
  1615. ,@idType = @customerIdType
  1616. ,@idNumber = @customerIdNo
  1617. ,@issueDate = @custIdissueDate
  1618. ,@expiryDate = @custIdValidDate
  1619. ,@remittanceAllowed = @remittanceAllowed
  1620. ,@onlineUser = @onlineUser
  1621. ,@remarks = @remarks
  1622. ,
  1623. --used for customer type organisation
  1624. @companyName = @companyName
  1625. ,@registerationNo = @registerationNo
  1626. ,@organizationType = @organizationType
  1627. ,@dateofIncorporation = @dateofIncorporation
  1628. ,@natureOfCompany = @natureOfCompany
  1629. ,@nameOfAuthorizedPerson = @nameOfAuthorizedPerson
  1630. ,@position = @position
  1631. UPDATE cm
  1632. SET cm.firstName = cmm.firstName
  1633. ,cm.middleName = cmm.middleName
  1634. ,cm.lastName1 = cmm.lastName1
  1635. ,cm.country = cmm.country
  1636. ,cm.STATE = cmm.STATE
  1637. ,cm.zipCode = cmm.zipCode
  1638. ,cm.city = cmm.city
  1639. ,cm.street = cmm.street
  1640. ,cm.fullName = ISNULL(cmm.firstName, '') + ISNULL(' ' + cmm.middleName, '') + ISNULL(' ' + cmm.lastName1, '')
  1641. ,cm.email = cmm.email
  1642. ,cm.cityUnicode = cmm.cityUnicode
  1643. ,cm.streetUnicode = cmm.streetUnicode
  1644. ,cm.homePhone = cmm.homePhone
  1645. ,cm.mobile = cmm.mobile
  1646. ,cm.nativeCountry = cmm.nativeCountry
  1647. ,cm.dob = cmm.dob
  1648. ,cm.nameOfEmployeer = cmm.nameOfEmployeer
  1649. ,cm.SSNNO = cmm.SSNNO
  1650. ,cm.occupation = cmm.occupation
  1651. ,cm.idExpiryDate = cmm.idExpiryDate
  1652. ,cm.idType = cmm.idType
  1653. ,cm.idNumber = cmm.idNumber
  1654. ,cm.telNo = cmm.telNo
  1655. ,cm.gender = cmm.gender
  1656. ,cm.idIssueDate = cmm.idIssueDate
  1657. ,cm.onlineUser = cmm.onlineUser
  1658. ,cm.sourceOfFund = cmm.sourceOfFund
  1659. ,cm.visaStatus = cmm.visaStatus
  1660. ,cm.employeeBusinessType = cmm.employeeBusinessType
  1661. ,cm.remittanceAllowed = cmm.remittanceAllowed
  1662. ,cm.remarks = cmm.remarks
  1663. ,cm.organizationType = cmm.organizationType
  1664. ,cm.dateofIncorporation = cmm.dateofIncorporation
  1665. ,cm.natureOfCompany = cmm.natureOfCompany
  1666. ,cm.nameOfAuthorizedPerson = cmm.nameOfAuthorizedPerson
  1667. ,cm.monthlyIncome = cmm.monthlyIncome
  1668. ,cm.registerationNo = cmm.registerationNo
  1669. ,cm.modifiedBy = @user
  1670. ,cm.modifiedDate = GETDATE()
  1671. FROM dbo.customerMaster cm(NOLOCK)
  1672. INNER JOIN dbo.customerMasterEditedDataMod cmm(NOLOCK) ON cmm.customerId = cm.customerId
  1673. WHERE cm.customerId = @customerId
  1674. DELETE
  1675. FROM dbo.customerMasterEditedDataMod
  1676. WHERE customerId = @customerId
  1677. EXEC proc_errorHandler 0
  1678. ,'Customer Edited Data Approved Successfully'
  1679. ,@customerId
  1680. END
  1681. ELSE IF @flag = 'reject'
  1682. BEGIN
  1683. DELETE
  1684. FROM dbo.customerMasterEditedDataMod
  1685. WHERE customerId = @customerId
  1686. EXEC dbo.proc_errorHandler @errorCode = '0'
  1687. ,-- varchar(10)
  1688. @msg = 'Changes rejected successfully'
  1689. ,-- varchar(max)
  1690. @id = @customerid -- varchar(50)
  1691. END
  1692. IF @flag = 'vl-forAgent' --verified list/approve pending list
  1693. BEGIN
  1694. --DECLARE @agentid VARCHAR(10)
  1695. --SELECT @agentid = agentid FROM applicationusers WHERE username = @user
  1696. --DECLARE @branchcode VARCHAR(10)
  1697. --SELECT @branchcode = branchcode FROM agentmaster WHERE agentid = @agentid
  1698. SET @sortBy = 'createdDate'
  1699. SET @sortOrder = 'desc'
  1700. SET @table =
  1701. '(
  1702. SELECT customerId=cm.customerId
  1703. ,CM.membershipid
  1704. ,email=cm.email
  1705. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  1706. ,dob=CONVERT(VARCHAR,cm.dob,101)
  1707. ,address=cm.[address]
  1708. ,nativeCountry=com.countryName
  1709. ,idtype=case when cm.idtype = ''11402'' then cm.otherIdNumber else sdv.detailTitle end
  1710. ,idNumber= cm.idNumber
  1711. ,createdDate=CAST(cm.createdDate AS DATE)
  1712. ,createdBy=cm.createdBy
  1713. ,verifiedBy=cm.verifiedBy
  1714. ,branchName=''''
  1715. ,verifiedDate=CAST(cm.verifiedDate AS DATE)
  1716. ,ipAddress=cm.ipAddress
  1717. ,mobile=cm.mobile
  1718. ,bankAccountNo
  1719. ,bankName=bl.bankName
  1720. ,cm.agentId
  1721. FROM customerMaster cm(NOLOCK)
  1722. INNER JOIN APPLICATIONUSERS AU(NOLOCK) ON AU.USERNAME = CM.CREATEDBY
  1723. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  1724. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  1725. LEFT JOIN vwBankLists bl (NOLOCK) ON cm.bankName = bl.rowId
  1726. WHERE 1=1
  1727. --AND ISNULL(CM.isVerifiedByCustomer, 0) = 1
  1728. AND au.username <> '''
  1729. + @user + '''
  1730. AND cm.approvedDate IS NULL
  1731. AND CM.ISACTIVE = ''Y'''
  1732. IF ISNULL(@fromDate, '') <> ''
  1733. AND ISNULL(@toDate, '') <> ''
  1734. SET @table = @table + ' AND cm.createdDate BETWEEN ''' + CAST(@fromDate AS VARCHAR) + ''' AND ''' + CAST(@toDate AS VARCHAR) + ''''
  1735. SET @table = @table + ')x'
  1736. SET @sql_filter = ''
  1737. --SET @sql_Filter=@sql_Filter + ' AND substring(membershipid,1,3) = '''+@branchcode+''''
  1738. SET @sql_Filter = @sql_Filter + ' AND agentId = ' + cast(@agentId AS VARCHAR) + ''
  1739. IF ISNULL(@searchCriteria, '') <> ''
  1740. AND ISNULL(@searchValue, '') <> ''
  1741. BEGIN
  1742. IF @searchCriteria = 'idNumber'
  1743. BEGIN
  1744. --IF ISNUMERIC(@searchValue)<>1
  1745. -- SET @searchValue='-1' --to ignore string value for datatype integer/customerID
  1746. --SET @sql_Filter=@sql_Filter + ' AND customerId = ''' +@searchValue+''''
  1747. SET @sql_Filter = @sql_Filter + ' AND REPLACE(idNumber, ''-'', '''') = ''' + REPLACE(@searchValue, '-', '') + ''''
  1748. END
  1749. ELSE IF @searchCriteria = 'emailId'
  1750. SET @sql_Filter = @sql_Filter + ' AND email like ''' + @searchValue + '%'''
  1751. ELSE IF @searchCriteria = 'customerName'
  1752. SET @sql_Filter = @sql_Filter + ' AND fullName like ''' + @searchValue + '%'''
  1753. ELSE IF @searchCriteria = 'mobile'
  1754. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  1755. ELSE IF @searchCriteria = 'walletAccountNo'
  1756. SET @sql_Filter = @sql_Filter + ' AND walletAccountNo = ''' + @searchValue + ''''
  1757. ELSE IF @searchCriteria = 'bankAccountNo'
  1758. SET @sql_Filter = @sql_Filter + ' AND bankAccountNo = ''' + @searchValue + ''''
  1759. ELSE IF @searchCriteria = 'nativeCountry'
  1760. SET @sql_Filter = @sql_Filter + ' AND nativeCountry = ''' + @searchValue + ''''
  1761. END
  1762. SET @select_field_list = '
  1763. customerId,membershipid,email,fullName,dob,address,nativeCountry,idtype,idNumber
  1764. ,createdDate,createdBy,verifiedBy,branchName,verifiedDate,bankAccountNo,bankName
  1765. '
  1766. EXEC dbo.proc_paging @table
  1767. ,@sql_filter
  1768. ,@select_field_list
  1769. ,@extra_field_list
  1770. ,@sortBy
  1771. ,@sortOrder
  1772. ,@pageSize
  1773. ,@pageNumber
  1774. RETURN
  1775. END
  1776. IF @flag = 'unVerifiedCustomerFromMobile' -- unverified list/verify pending list
  1777. BEGIN
  1778. IF @sortBy IS NULL
  1779. SET @sortBy = 'createdDate'
  1780. IF @sortOrder IS NULL
  1781. SET @sortOrder = 'DESC'
  1782. SET @table =
  1783. '(
  1784. SELECT customerId=cm.customerId
  1785. ,CM.membershipid
  1786. ,cm.userName
  1787. ,email=cm.email
  1788. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  1789. ,dob=CONVERT(VARCHAR,cm.dob,101)
  1790. ,address=cm.[address]
  1791. ,nativeCountry=com.countryName
  1792. ,idtype= case when cm.idtype=''11402'' then ISNULL(sdv.detailTitle, '''') + (''-'') + ISNULL('' '' + cm.otherIdNumber, '''') else sdv.detailTitle end
  1793. ,idNumber=cm.idNumber
  1794. ,createdDate=CAST(cm.createdDate AS DATE)
  1795. ,createdBy=cm.createdBy
  1796. ,verifiedBy=cm.verifiedBy
  1797. ,branchName=''''
  1798. ,verifiedDate=CAST(cm.verifiedDate AS DATE)
  1799. ,ipAddress=cm.ipAddress
  1800. ,mobile=cm.mobile
  1801. ,bankAccountNo
  1802. ,cm.agentId
  1803. ,case when isnull(cm.isExistingCustomer,1) = 1 then ''Yes'' ELSE ''No'' End isExistingCustomer
  1804. ,createdUserFrom = ''mobile''
  1805. ,ISNULL(verifyRemarks,'''') VerifyRemarks
  1806. ,[RegistrationType] = CASE WHEN cm.RegistrationType IS NULL THEN ''MANUAL'' WHEN cm.registrationtype=''MKYC'' THEN ''MANUAL'' ELSE cm.RegistrationType END
  1807. ,[TructDocState]= dbo.FNAGetTrustDocStatus(cm.trustdocid)
  1808. FROM customerMaster cm(NOLOCK)
  1809. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  1810. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  1811. AND CM.ISACTIVE = ''Y''
  1812. AND USERNAME IS NOT NULL
  1813. AND cm.MOBILEVERIFIEDDATE IS NULL
  1814. and cm.membershipId is not null
  1815. and ISNULL(cm.serviceUsedFor, ''C'') NOT LIKE ''%M%''
  1816. and ISNULL(cm.isEmailVerified, 0) = 1
  1817. and ISNULL(cm.agreeYn,0)= 1
  1818. UNION ALL
  1819. SELECT customerId=cm.customerId
  1820. ,CM.membershipid
  1821. ,cm.userName
  1822. ,email=cm.email
  1823. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  1824. ,dob=CONVERT(VARCHAR,cm.dob,101)
  1825. ,address=cm.[address]
  1826. ,nativeCountry=com.countryName
  1827. ,idtype=sdv.detailTitle
  1828. ,idNumber=cm.idNumber
  1829. ,createdDate=CAST(cm.createdDate AS DATE)
  1830. ,createdBy=cm.createdBy
  1831. ,verifiedBy=cm.verifiedBy
  1832. ,branchName=''''
  1833. ,verifiedDate=CAST(cm.verifiedDate AS DATE)
  1834. ,ipAddress=cm.ipAddress
  1835. ,mobile=cm.mobile
  1836. ,bankAccountNo
  1837. ,cm.agentId
  1838. ,case when isnull(cm.isExistingCustomer,1) = 1 then ''Yes'' ELSE ''No'' End isExistingCustomer
  1839. ,createdUserFrom = ''core''
  1840. ,ISNULL(verifyRemarks,'''') VerifyRemarks
  1841. ,[RegistrationType] = CASE WHEN cm.RegistrationType IS NULL THEN ''MANUAL'' WHEN cm.registrationtype=''MKYC'' THEN ''MANUAL'' ELSE cm.RegistrationType END
  1842. ,[TructDocState]= dbo.FNAGetTrustDocStatus(cm.trustdocid)
  1843. FROM customerMaster cm(NOLOCK)
  1844. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  1845. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  1846. AND CM.ISACTIVE = ''Y''
  1847. AND USERNAME IS NOT NULL
  1848. AND cm.MOBILEVERIFIEDDATE IS NULL
  1849. and cm.membershipId is not null
  1850. and cm.serviceUsedFor LIKE ''%M%''
  1851. and ISNULL(cm.isEmailVerified, 0) = 0
  1852. and cm.approvedDate IS NOT NULL
  1853. '
  1854. IF ISNULL(@fromDate, '') <> ''
  1855. AND ISNULL(@toDate, '') <> ''
  1856. SET @table = @table + ' AND cm.createdDate BETWEEN ''' + CAST(@fromDate AS VARCHAR) + ''' AND ''' + CAST(@toDate AS VARCHAR) + ''''
  1857. SET @table = @table + ')x'
  1858. SET @sql_filter = ''
  1859. IF ISNULL(@searchCriteria, '') <> ''
  1860. AND ISNULL(@searchValue, '') <> ''
  1861. BEGIN
  1862. IF @searchCriteria = 'idNumber'
  1863. BEGIN
  1864. SET @sql_Filter = @sql_Filter + ' AND REPLACE(idNumber, ''-'', '''') = ''' + REPLACE(@searchValue, '-', '') + ''''
  1865. END
  1866. ELSE IF @searchCriteria = 'emailId'
  1867. SET @sql_Filter = @sql_Filter + ' AND email like ''' + @searchValue + '%'''
  1868. ELSE IF @searchCriteria = 'customerName'
  1869. SET @sql_Filter = @sql_Filter + ' AND fullName like ''' + @searchValue + '%'''
  1870. ELSE IF @searchCriteria = 'mobile'
  1871. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  1872. ELSE IF @searchCriteria = 'walletAccountNo'
  1873. SET @sql_Filter = @sql_Filter + ' AND walletAccountNo = ''' + @searchValue + ''''
  1874. ELSE IF @searchCriteria = 'bankAccountNo'
  1875. SET @sql_Filter = @sql_Filter + ' AND bankAccountNo = ''' + @searchValue + ''''
  1876. ELSE IF @searchCriteria = 'nativeCountry'
  1877. SET @sql_Filter = @sql_Filter + ' AND nativeCountry = ''' + @searchValue + ''''
  1878. END
  1879. SET @select_field_list = '
  1880. customerId,userName,isExistingCustomer,membershipid,email,fullName,dob,address,nativeCountry,idtype,idNumber
  1881. ,createdDate,createdBy,verifiedBy,branchName,verifiedDate,bankAccountNo,createdUserFrom,VerifyRemarks,RegistrationType,TructDocState
  1882. '
  1883. EXEC dbo.proc_paging @table
  1884. ,@sql_filter
  1885. ,@select_field_list
  1886. ,@extra_field_list
  1887. ,@sortBy
  1888. ,@sortOrder
  1889. ,@pageSize
  1890. ,@pageNumber
  1891. RETURN
  1892. END
  1893. IF @flag = 'unApprovedCustomerFromAgent' --verified list/approve pending list
  1894. BEGIN
  1895. SET @sortBy = 'createdDate'
  1896. SET @sortOrder = 'desc'
  1897. SET @table =
  1898. '(
  1899. SELECT customerId=cm.customerId
  1900. ,CM.membershipid
  1901. ,email=cm.email
  1902. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  1903. ,dob=CONVERT(VARCHAR,cm.dob,101)
  1904. ,address=cm.[address]
  1905. ,nativeCountry=com.countryName
  1906. ,idtype=sdv.detailTitle
  1907. ,idNumber=cm.idNumber
  1908. ,createdDate=CAST(cm.createdDate AS DATE)
  1909. ,createdBy=cm.createdBy
  1910. ,verifiedBy=cm.verifiedBy
  1911. ,branchName=''''
  1912. ,verifiedDate=CAST(cm.verifiedDate AS DATE)
  1913. ,ipAddress=cm.ipAddress
  1914. ,mobile=cm.mobile
  1915. ,bankAccountNo
  1916. ,bankName=bl.bankName
  1917. ,cm.agentId
  1918. FROM customerMaster cm(NOLOCK)
  1919. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  1920. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  1921. LEFT JOIN vwBankLists bl (NOLOCK) ON cm.bankName = bl.rowId
  1922. where cm.approvedDate IS NULL
  1923. AND CM.ISACTIVE = ''Y''
  1924. AND MEMBERSHIPID LIKE ''%AGT%''
  1925. AND CREATEDFROM = ''A''
  1926. '
  1927. IF ISNULL(@fromDate, '') <> ''
  1928. AND ISNULL(@toDate, '') <> ''
  1929. SET @table = @table + ' AND cm.createdDate BETWEEN ''' + CAST(@fromDate AS VARCHAR) + ''' AND ''' + ISNULL(CAST(@toDate AS VARCHAR), '') + ''''
  1930. SET @table = @table + ')x'
  1931. SET @sql_filter = ''
  1932. IF ISNULL(@searchCriteria, '') <> ''
  1933. AND ISNULL(@searchValue, '') <> ''
  1934. BEGIN
  1935. IF @searchCriteria = 'idNumber'
  1936. BEGIN
  1937. --IF ISNUMERIC(@searchValue)<>1
  1938. -- SET @searchValue='-1' --to ignore string value for datatype integer/customerID
  1939. --SET @sql_Filter=@sql_Filter + ' AND customerId = ''' +@searchValue+''''
  1940. SET @sql_Filter = @sql_Filter + ' AND REPLACE(idNumber, ''-'', '''') = ''' + REPLACE(@searchValue, '-', '') + ''''
  1941. END
  1942. ELSE IF @searchCriteria = 'emailId'
  1943. SET @sql_Filter = @sql_Filter + ' AND email like ''' + @searchValue + '%'''
  1944. ELSE IF @searchCriteria = 'customerName'
  1945. SET @sql_Filter = @sql_Filter + ' AND fullName like ''' + @searchValue + '%'''
  1946. ELSE IF @searchCriteria = 'mobile'
  1947. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  1948. ELSE IF @searchCriteria = 'walletAccountNo'
  1949. SET @sql_Filter = @sql_Filter + ' AND walletAccountNo = ''' + @searchValue + ''''
  1950. ELSE IF @searchCriteria = 'bankAccountNo'
  1951. SET @sql_Filter = @sql_Filter + ' AND bankAccountNo = ''' + @searchValue + ''''
  1952. ELSE IF @searchCriteria = 'nativeCountry'
  1953. SET @sql_Filter = @sql_Filter + ' AND nativeCountry = ''' + @searchValue + ''''
  1954. END
  1955. SET @select_field_list = '
  1956. customerId,membershipid,email,fullName,dob,address,nativeCountry,idtype,idNumber
  1957. ,createdDate,createdBy,verifiedBy,branchName,verifiedDate,bankAccountNo,bankName
  1958. '
  1959. EXEC dbo.proc_paging @table
  1960. ,@sql_filter
  1961. ,@select_field_list
  1962. ,@extra_field_list
  1963. ,@sortBy
  1964. ,@sortOrder
  1965. ,@pageSize
  1966. ,@pageNumber
  1967. RETURN
  1968. END
  1969. IF @flag = 'unApprovedCustomerFromMobile' --verified list/approve pending list
  1970. BEGIN
  1971. IF @sortBy IS NULL
  1972. SET @sortBy = 'createdDate'
  1973. IF @sortOrder IS NULL
  1974. SET @sortOrder = 'DESC'
  1975. SET @table =
  1976. '(
  1977. SELECT customerId=cm.customerId
  1978. ,CM.membershipid
  1979. ,cm.userName
  1980. ,email=cm.email
  1981. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  1982. ,dob=CONVERT(VARCHAR,cm.dob,101)
  1983. ,address=cm.[address]
  1984. ,nativeCountry=com.countryName
  1985. ,idtype= case when cm.idtype=''11402'' then ISNULL(sdv.detailTitle, '''') + (''-'') + ISNULL('' '' + cm.otherIdNumber, '''') else sdv.detailTitle end
  1986. ,idNumber=cm.idNumber
  1987. ,createdDate=CAST(cm.createdDate AS DATE)
  1988. ,createdBy=cm.createdBy
  1989. ,verifiedBy=cm.verifiedBy
  1990. ,branchName=''''
  1991. ,verifiedDate=CAST(cm.verifiedDate AS DATE)
  1992. ,ipAddress=cm.ipAddress
  1993. ,mobile=cm.mobile
  1994. ,bankAccountNo
  1995. ,cm.agentId
  1996. ,case when isnull(cm.isExistingCustomer,1) = 1 then ''Yes'' ELSE ''No'' End isExistingCustomer
  1997. ,createdUserFrom = ''mobile''
  1998. ,LawsonCardNo = cm.LawsonCardNo
  1999. ,[RegistrationType] = CASE WHEN cm.LawsonCardNo IS NULL THEN '''' ELSE cm.LawsonCardNo END
  2000. ,ISNULL(verificationCode,''NOT_COMPLETED'') verificationCode
  2001. FROM customerMaster cm(NOLOCK)
  2002. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  2003. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  2004. AND CM.ISACTIVE = ''Y''
  2005. AND USERNAME IS NOT NULL
  2006. AND cm.MOBILEVERIFIEDDATE IS not NULL
  2007. and cm.membershipId is not null
  2008. -- and cm.serviceUsedFor LIKE ''%M%''
  2009. and ISNULL(cm.serviceUsedFor, ''C'') NOT LIKE ''%M%''
  2010. and ISNULL(cm.isEmailVerified, 0) = 1
  2011. and cm.mobileVerificationType = ''verified''
  2012. and ISNULL(cm.agreeYn,0)= 1
  2013. and cm.hasDeclare = ''1''
  2014. and cm.agreeYn = ''1''
  2015. UNION ALL
  2016. SELECT customerId=cm.customerId
  2017. ,CM.membershipid
  2018. ,cm.userName
  2019. ,email=cm.email
  2020. ,fullName= REPLACE(ISNULL(cm.firstName, '''') + ISNULL('' '' + cm.middleName, '''') + ISNULL('' '' + cm.lastName1, ''''), '' '', '' '')
  2021. ,dob=CONVERT(VARCHAR,cm.dob,101)
  2022. ,address=cm.[address]
  2023. ,nativeCountry=com.countryName
  2024. ,idtype=sdv.detailTitle
  2025. ,idNumber=cm.idNumber
  2026. ,createdDate=CAST(cm.createdDate AS DATE)
  2027. ,createdBy=cm.createdBy
  2028. ,verifiedBy=cm.verifiedBy
  2029. ,branchName=''''
  2030. ,verifiedDate=CAST(cm.verifiedDate AS DATE)
  2031. ,ipAddress=cm.ipAddress
  2032. ,mobile=cm.mobile
  2033. ,bankAccountNo
  2034. ,cm.agentId
  2035. ,case when isnull(cm.isExistingCustomer,1) = 1 then ''Yes'' ELSE ''No'' End isExistingCustomer
  2036. ,createdUserFrom = ''core''
  2037. ,LawsonCardNo = cm.LawsonCardNo
  2038. ,[RegistrationType] = CASE WHEN cm.RegistrationType IS NULL THEN ''Manual'' ELSE cm.RegistrationType END
  2039. ,ISNULL(verificationCode,''NOT_COMPLETED'') verificationCode
  2040. FROM customerMaster cm(NOLOCK)
  2041. LEFT JOIN countryMaster com(NOLOCK) ON cm.nativeCountry=com.countryId
  2042. INNER JOIN staticDataValue sdv (NOLOCK) ON sdv.valueId=cm.idType AND sdv.typeID=1300
  2043. AND CM.ISACTIVE = ''Y''
  2044. AND USERNAME IS NOT NULL
  2045. AND cm.MOBILEVERIFIEDDATE IS NOT NULL
  2046. and cm.membershipId is not null
  2047. and cm.serviceUsedFor LIKE ''%M%''
  2048. --and ISNULL(cm.serviceUsedFor, ''C'') NOT LIKE ''%M%''
  2049. and ISNULL(cm.isEmailVerified, 0) = 0
  2050. and cm.approvedDate IS NOT NULL
  2051. and cm.mobileVerificationType = ''verified''
  2052. and ISNULL(cm.agreeYn,0)= 1'
  2053. IF ISNULL(@fromDate, '') <> ''
  2054. AND ISNULL(@toDate, '') <> ''
  2055. SET @table = @table + ' AND cm.createdDate BETWEEN ''' + CAST(@fromDate AS VARCHAR) + ''' AND ''' + CAST(@toDate AS VARCHAR) + ''''
  2056. SET @table = @table + ')x'
  2057. SET @sql_filter = ''
  2058. IF ISNULL(@searchCriteria, '') <> ''
  2059. AND ISNULL(@searchValue, '') <> ''
  2060. BEGIN
  2061. IF @searchCriteria = 'idNumber'
  2062. BEGIN
  2063. --IF ISNUMERIC(@searchValue)<>1
  2064. -- SET @searchValue='-1' --to ignore string value for datatype integer/customerID
  2065. --SET @sql_Filter=@sql_Filter + ' AND customerId = ''' +@searchValue+''''
  2066. SET @sql_Filter = @sql_Filter + ' AND REPLACE(idNumber, ''-'', '''') = ''' + REPLACE(@searchValue, '-', '') + ''''
  2067. END
  2068. ELSE IF @searchCriteria = 'emailId'
  2069. SET @sql_Filter = @sql_Filter + ' AND email like ''' + @searchValue + '%'''
  2070. ELSE IF @searchCriteria = 'customerName'
  2071. SET @sql_Filter = @sql_Filter + ' AND fullName like ''' + @searchValue + '%'''
  2072. ELSE IF @searchCriteria = 'mobile'
  2073. SET @sql_Filter = @sql_Filter + ' AND mobile = ''' + @searchValue + ''''
  2074. ELSE IF @searchCriteria = 'walletAccountNo'
  2075. SET @sql_Filter = @sql_Filter + ' AND walletAccountNo = ''' + @searchValue + ''''
  2076. ELSE IF @searchCriteria = 'bankAccountNo'
  2077. SET @sql_Filter = @sql_Filter + ' AND bankAccountNo = ''' + @searchValue + ''''
  2078. ELSE IF @searchCriteria = 'nativeCountry'
  2079. SET @sql_Filter = @sql_Filter + ' AND nativeCountry = ''' + @searchValue + ''''
  2080. ELSE IF @searchCriteria = 'LawsonCardNo'
  2081. SET @sql_Filter = @sql_Filter + ' AND LawsonCardNo = ''' + @searchValue + ''''
  2082. END
  2083. SET @select_field_list = '
  2084. customerId,userName,isExistingCustomer,membershipid,email,fullName,dob,address,nativeCountry,idtype,idNumber
  2085. ,createdDate,createdBy,verifiedBy,branchName,verifiedDate,bankAccountNo,createdUserFrom,LawsonCardNo,[RegistrationType],verificationCode
  2086. '
  2087. EXEC dbo.proc_paging @table
  2088. ,@sql_filter
  2089. ,@select_field_list
  2090. ,@extra_field_list
  2091. ,@sortBy
  2092. ,@sortOrder
  2093. ,@pageSize
  2094. ,@pageNumber
  2095. --,@action
  2096. RETURN
  2097. END
  2098. END TRY
  2099. BEGIN CATCH
  2100. IF @@TRANCOUNT > 0
  2101. ROLLBACK TRANSACTION
  2102. DECLARE @errorMessage VARCHAR(MAX)
  2103. SET @errorMessage = ERROR_MESSAGE()
  2104. EXEC proc_errorHandler 1
  2105. ,@errorMessage
  2106. ,NULL
  2107. END CATCH