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.

1552 lines
43 KiB

11 months ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[mobile_proc_customerMaster] Script Date: 11/8/2023 8:07:54 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. --EXEC [mobile_proc_customerMaster] @flag='refresh-customer-info',@userName='android-demo-jme@yopmail.com'
  9. ALTER PROCEDURE [dbo].[mobile_proc_customerMaster] @flag VARCHAR(30)
  10. ,@userName VARCHAR(100) = NULL
  11. ,@firstName VARCHAR(50) = NULL
  12. ,@middleName VARCHAR(50) = NULL
  13. ,@lastName VARCHAR(50) = NULL
  14. ,@nickName VARCHAR(100) = NULL
  15. ,@mobileNumber VARCHAR(30) = NULL
  16. ,@email VARCHAR(100) = NULL
  17. ,@gender VARCHAR(15) = NULL
  18. ,@dateOfBirth DATETIME = NULL
  19. ,@nativeCountry VARCHAR(100) = NULL
  20. ,@country VARCHAR(100) = NULL
  21. ,@address VARCHAR(150) = NULL
  22. ,@city VARCHAR(50) = NULL
  23. ,@province VARCHAR(50) = NULL
  24. ,@occupation VARCHAR(100) = NULL
  25. ,@primaryBankName VARCHAR(200) = NULL
  26. ,@primaryAccountNumber VARCHAR(100) = NULL
  27. ,@verificationIdType VARCHAR(50) = NULL
  28. ,@verificationIdNumber VARCHAR(50) = NULL
  29. ,@issueDate DATETIME = NULL
  30. ,@expiryDate DATETIME = NULL
  31. ,@regIdcardFrontUrl VARCHAR(200) = NULL
  32. ,@regIdcardBackUrl VARCHAR(200) = NULL
  33. ,@passbookUrl VARCHAR(200) = NULL
  34. ,@passportUrl VARCHAR(200) = NULL
  35. ,@selfieUrl VARCHAR(300) = NULL
  36. -- CDD parameters
  37. ,@cddCode VARCHAR(100) = NULL
  38. ,@sourceOfFund VARCHAR(500) = NULL
  39. ,@referralCode VARCHAR(100) = NULL
  40. ,@sourceCustomerId INT = NULL
  41. ,@appVersion VARCHAR(100) = NULL
  42. ,@phoneBrand VARCHAR(100) = NULL
  43. ,@phoneOS VARCHAR(100) = NULL
  44. ,@fcmId VARCHAR(MAX) = NULL
  45. ,@osVersion VARCHAR(100) = NULL
  46. ,@fullName VARCHAR(200) = NULL
  47. ,@passportNumber VARCHAR(100) = NULL
  48. ,@anotherIDType VARCHAR(20) = NULL
  49. ,@anotherIDNumber VARCHAR(20) = NULL
  50. ,@branch VARCHAR(20) = NULL
  51. ,@type INT = NULL
  52. ,@url VARCHAR(200) = NULL
  53. ,@userId INT = NULL
  54. ,@fileType VARCHAR(25) = NULL
  55. ,@fileName VARCHAR(200) = NULL
  56. AS
  57. SET NOCOUNT ON;
  58. SET XACT_ABORT ON;
  59. BEGIN TRY
  60. ------------------------------------------------------------------------------------------------------------
  61. -- select column [mobile_userRegistration].isForcePassChange
  62. -- #387 - Added parameter @IsForcePinChangeMob
  63. -- #101 - Mobile Changes
  64. -- #647 - change pin and password for existing customer from mobile reg
  65. -- #659 change in @flag='refresh-customer-info' for full name
  66. -- #1069 in @flag = 'refresh-customer-info' for id expiry date and status
  67. --#lawson card
  68. -- #1135 _ Notification count
  69. -- #1003 - Reward Points , @flag = 'get-invite-details'
  70. -- #1298 - changes in reward points response
  71. -- #1309 - Changes in @flag = 'get-invite-details' and @flag='get-reward-fee'
  72. -- #1594 - @flag = 'get-loyalty-points'
  73. -- #1601 - Push 500 reward points to customers , @flag = 'get-loyalty-points'
  74. -- Trust doc -- add ResidenceType, IsNFC
  75. -- #18600 added new @flag = 'get-payment-method' for exrate
  76. -- #19922 change in flag= 'get-invite-details' to retrieve membershipId and available reward points
  77. ------------------------------------------------------------------------------------------------------------
  78. DECLARE @errorMsg VARCHAR(MAX)
  79. ,@customerId BIGINT
  80. ,@yearlyLimit MONEY = '3500000.00'
  81. ,@totalSend MONEY
  82. ,@totalSendText VARCHAR(200)
  83. ,@YearStart DATE
  84. ,@YearEnd DATETIME
  85. ,@cust BIGINT = NULL;
  86. DECLARE @IsActive CHAR(1)
  87. DECLARE @redirectTo VARCHAR(100) = ''
  88. SET @country = '118';
  89. SET @firstName = UPPER(@firstName)
  90. SET @middleName = UPPER(@middleName)
  91. SET @lastName = UPPER(@lastName)
  92. SET @fullName = @firstName + ISNULL(' ' + @middleName, '') + ISNULL(' ' + @lastName, '')
  93. IF @flag = 'i'
  94. BEGIN
  95. --SELECT @customerId = customerId FROM customerMasterTemp with (nolock)
  96. --WHERE email = @username OR mobile = @username
  97. --CHECK FOR customer IN temp table
  98. SELECT @customerId = customerId
  99. FROM customerMasterTemp WITH (NOLOCK)
  100. WHERE username = @userName
  101. IF @customerId IS NULL
  102. BEGIN
  103. IF EXISTS (
  104. SELECT TOP 1 'A'
  105. FROM customerMaster(NOLOCK)
  106. WHERE userName = @userName
  107. )
  108. BEGIN
  109. SELECT @errorMsg = 'It looks like you are already registered in JME system!'
  110. EXEC proc_errorHandler 1
  111. ,@errorMsg
  112. ,@userName
  113. RETURN
  114. END
  115. END
  116. SELECT @email = @userName
  117. BEGIN TRANSACTION
  118. UPDATE dbo.customerMasterTemp
  119. SET firstName = @fullName
  120. ,fullName = @fullName
  121. ,nickName = @nickName
  122. ,mobile = @mobileNumber
  123. ,homePhone = @verificationIdNumber
  124. ,
  125. --email=@email,
  126. gender = CASE
  127. WHEN UPPER(@gender) = 'M'
  128. THEN '97'
  129. WHEN UPPER(@gender) = 'F'
  130. THEN '98'
  131. ELSE '99'
  132. END
  133. ,
  134. --dob=@dateOfBirth,
  135. nativeCountry = @nativeCountry
  136. ,country = @country
  137. ,[address] = @address
  138. ,city = @province
  139. ,state2 = @province
  140. ,occupation = @occupation
  141. ,bankName = @primaryBankName
  142. ,bankAccountNo = @primaryAccountNumber
  143. ,idNumber = @verificationIdNumber
  144. ,idType = @verificationIdType
  145. ,idIssueDate = @issueDate
  146. ,createdDate = GETDATE()
  147. ,sourceOfFund = CASE
  148. WHEN @sourceOfFund IS NOT NULL
  149. THEN (
  150. SELECT sd.detailTitle
  151. FROM dbo.staticDataValue sd(NOLOCK)
  152. WHERE sd.valueId = @sourceOfFund
  153. )
  154. ELSE sourceOfFund
  155. END
  156. ,idExpiryDate = @expiryDate
  157. ,verifyDoc1 = @regIdcardFrontUrl
  158. ,verifyDoc2 = @regIdcardBackUrl
  159. ,verifyDoc3 = @passbookUrl
  160. ,verifyDoc4 = @passportUrl
  161. ,selfie = @selfieUrl
  162. ,referelCode = @referralCode
  163. WHERE userName = @username
  164. INSERT INTO dbo.customerMaster (
  165. fullName
  166. ,firstName
  167. ,mobile
  168. ,email
  169. ,gender
  170. ,dob
  171. ,occupation
  172. ,nativeCountry
  173. ,country
  174. ,bankName
  175. ,bankAccountNo
  176. ,idType
  177. ,idNumber
  178. ,homePhone
  179. ,idIssueDate
  180. ,idExpiryDate
  181. ,sourceOfFund
  182. ,verifyDoc1
  183. ,verifyDoc2
  184. ,verifyDoc3
  185. ,SelfieDoc
  186. ,referelCode
  187. ,createdBy
  188. ,createdDate
  189. ,isActive
  190. ,onlineUser
  191. ,customerPassword
  192. ,[address]
  193. ,city
  194. ,state2
  195. ,customerType
  196. ,agreeYn
  197. )
  198. SELECT fullName
  199. ,CMT.firstName
  200. ,mobile
  201. ,email
  202. ,gender
  203. ,dob
  204. ,CMT.occupation
  205. ,nativeCountry
  206. ,country
  207. ,bankName
  208. ,bankAccountNo
  209. ,idType
  210. ,idNumber
  211. ,CMT.homePhone
  212. ,CMT.idIssueDate
  213. ,idExpiryDate
  214. ,sourceOfFund
  215. ,verifyDoc1
  216. ,verifyDoc2
  217. ,verifyDoc3
  218. ,CMT.selfie
  219. ,CMT.referelCode
  220. ,CMT.createdBy
  221. ,GETDATE()
  222. ,'Y'
  223. ,'Y'
  224. ,customerPassword
  225. ,[address]
  226. ,state2
  227. ,state2
  228. ,4701
  229. ,CMT.agreeYn
  230. FROM dbo.CustomerMasterTemp AS CMT(NOLOCK)
  231. WHERE CMT.customerId = @customerId
  232. SET @cust = @@IDENTITY
  233. UPDATE dbo.mobile_userRegistration
  234. SET customerId = @cust
  235. WHERE username = @username
  236. DELETE
  237. FROM customerMasterTemp
  238. WHERE username = @username
  239. COMMIT TRANSACTION
  240. IF @@TRANCOUNT = 0
  241. BEGIN
  242. SELECT 0 AS ERRORCODE
  243. ,'KYC Submitted successfully' AS MSG
  244. ,@userName AS ID
  245. ,@cust AS EXTRA
  246. --SELECT
  247. -- errorCode='0'
  248. -- ,userId=@userName
  249. -- ,firstName=ISNULL(cm.firstName, '')
  250. -- ,middleName=ISNULL(cm.middleName, '')
  251. -- ,lastName=ISNULL(cm.lastName1,'')
  252. -- ,fullname=ISNULL(cm.firstName, '') + ISNULL(' ' + cm.middleName, '') + ISNULL(' ' + cm.lastName1, '')
  253. -- ,mobileNumber=ISNULL(mobile,'')
  254. -- ,email=ISNULL(email,'')
  255. -- ,gender=ISNULL(sv.detailTitle,'')
  256. -- ,dateOfBirth=CONVERT(VARCHAR(10),dob,120)
  257. -- ,nativeCountry=ISNULL(com1.countryName,'')
  258. -- ,country=ISNULL(com.countryName,'')
  259. -- ,address=ISNULL(address,'')
  260. -- ,city=ISNULL(city,'')
  261. -- ,province=ISNULL(cm.state2,'')
  262. -- ,provinceId= cm.state2
  263. -- ,occupation=ISNULL(sdv.detailTitle,'')
  264. -- ,primaryBankName=ISNULL(bl.BankName,'')
  265. -- ,primaryAccountNumber=ISNULL(cm.bankAccountNo,'')
  266. -- ,verificationIdType=ISNULL(dv.detailTitle,'')
  267. -- ,verificationIdNumber=ISNULL(cm.idNumber,'')
  268. -- ,issueDate=CONVERT(VARCHAR(10),cm.idIssueDate,120)
  269. -- ,expiryDate=CONVERT(VARCHAR(10),cm.idExpiryDate,120)
  270. -- ,sourceOfFund=ISNULL(cm.sourceOfFund,'')
  271. -- ,regIdcardFrontUrl=ISNULL(cm.verifyDoc1,'')
  272. -- ,regIdcardBackUrl=ISNULL(cm.verifyDoc2,'')
  273. -- ,passbookUrl=ISNULL(cm.verifyDoc3,'')
  274. -- ,selfieUrl=ISNULL(cm.SelfieDoc,'')
  275. -- ,passportUrl=''
  276. --FROM dbo.customerMaster cm WITH(NOLOCK)
  277. --LEFT JOIN dbo.vwBankLists bl WITH(NOLOCK)ON cm.bankName=bl.rowId
  278. --LEFT JOIN dbo.staticDataValue sdv WITH(NOLOCK)ON cm.occupation=sdv.valueId
  279. --LEFT JOIN dbo.staticDataValue sv WITH(NOLOCK)ON cm.gender=sv.valueId
  280. --LEFT JOIN dbo.countryMaster com WITH(NOLOCK)ON cm.country=com.countryId
  281. --LEFT JOIN dbo.countryMaster com1 WITH(NOLOCK)ON cm.nativeCountry=com1.countryId
  282. --LEFT JOIN dbo.staticDataValue dv WITH(NOLOCK)ON cm.idType=dv.valueId
  283. --WHERE customerId=@cust
  284. RETURN
  285. END
  286. EXEC proc_errorHandler 1
  287. ,'Failed to Submit KYC'
  288. ,@userName
  289. -- SELECT errorCode='1'
  290. --,userId=''
  291. --,firstName=''
  292. --,middleName=''
  293. --,lastName=''
  294. --,fullname=''
  295. --,mobileNumber=''
  296. --,email=''
  297. --,gender=''
  298. --,dateOfBirth=''
  299. --,nativeCountry=''
  300. --,country=''
  301. --,address=''
  302. --,city=''
  303. --,province=''
  304. --,provinceId=''
  305. --,occupation=''
  306. --,primaryBankName=''
  307. --,primaryAccountNumber=''
  308. --,verificationIdType=''
  309. --,verificationIdNumber=''
  310. --,issueDate=''
  311. --,expiryDate=''
  312. --,sourceOfFund=''
  313. --,regIdcardFrontUrl=''
  314. --,regIdcardBackUrl=''
  315. --,passbookUrl=''
  316. --,passportUrl=''
  317. --,selfieUrl=''
  318. RETURN
  319. END
  320. IF @flag = 'i-V2'
  321. BEGIN
  322. --CHECK FOR customer IN temp table
  323. SELECT @customerId = customerId
  324. FROM customerMasterTemp WITH (NOLOCK)
  325. WHERE username = @userName
  326. --PRINT @userName
  327. --PRINT @customerId
  328. IF @customerId IS NULL
  329. BEGIN
  330. IF EXISTS (
  331. SELECT TOP 1 'A'
  332. FROM customerMaster(NOLOCK)
  333. WHERE EMAIL = @userName
  334. )
  335. BEGIN
  336. SELECT @errorMsg = 'It looks like you are already registered in JME system!'
  337. EXEC proc_errorHandler 1
  338. ,@errorMsg
  339. ,@userName
  340. RETURN
  341. END
  342. END
  343. BEGIN TRANSACTION
  344. UPDATE dbo.customerMasterTemp
  345. SET firstName = @fullName
  346. ,fullName = @fullName
  347. ,nickName = @nickName
  348. ,homePhone = @verificationIdNumber
  349. ,email = @userName
  350. ,customerEmail = @email
  351. ,gender = CASE
  352. WHEN UPPER(@gender) = 'M'
  353. THEN '97'
  354. WHEN UPPER(@gender) = 'F'
  355. THEN '98'
  356. ELSE '99'
  357. END
  358. ,dob = @dateOfBirth
  359. ,country = @country
  360. ,[address] = @address
  361. ,city = @city
  362. ,state2 = @province
  363. ,occupation = @occupation
  364. ,bankName = @primaryBankName
  365. ,bankAccountNo = @primaryAccountNumber
  366. ,idNumber = @verificationIdNumber
  367. ,idType = @verificationIdType
  368. ,idIssueDate = @issueDate
  369. ,createdDate = GETDATE()
  370. ,sourceOfFund = CASE
  371. WHEN @sourceOfFund IS NOT NULL
  372. THEN (
  373. SELECT TOP 1 sd.detailTitle
  374. FROM dbo.staticDataValue sd(NOLOCK)
  375. WHERE sd.valueId = @sourceOfFund
  376. )
  377. ELSE sourceOfFund
  378. END
  379. ,idExpiryDate = @expiryDate
  380. ,verifyDoc1 = @regIdcardFrontUrl
  381. ,verifyDoc2 = @regIdcardBackUrl
  382. ,verifyDoc3 = @passbookUrl
  383. ,verifyDoc4 = @passportUrl
  384. ,selfie = @selfieUrl
  385. ,referelCode = @referralCode
  386. WHERE customerId = @customerId
  387. INSERT INTO dbo.customerMaster (
  388. fullName
  389. ,firstName
  390. ,mobile
  391. ,email
  392. ,customerEmail
  393. ,gender
  394. ,dob
  395. ,occupation
  396. ,nativeCountry
  397. ,country
  398. ,bankName
  399. ,bankAccountNo
  400. ,idType
  401. ,idNumber
  402. ,homePhone
  403. ,idIssueDate
  404. ,idExpiryDate
  405. ,sourceOfFund
  406. ,verifyDoc1
  407. ,verifyDoc2
  408. ,verifyDoc3
  409. ,SelfieDoc
  410. ,referelCode
  411. ,createdBy
  412. ,createdDate
  413. ,isActive
  414. ,onlineUser
  415. ,customerPassword
  416. ,[address]
  417. ,city
  418. ,state2
  419. ,customerType
  420. )
  421. SELECT fullName
  422. ,CMT.firstName
  423. ,mobile
  424. ,email
  425. ,customerEmail
  426. ,gender
  427. ,dob
  428. ,CMT.occupation
  429. ,nativeCountry
  430. ,country
  431. ,bankName
  432. ,bankAccountNo
  433. ,idType
  434. ,idNumber
  435. ,CMT.homePhone
  436. ,CMT.idIssueDate
  437. ,idExpiryDate
  438. ,sourceOfFund
  439. ,verifyDoc1
  440. ,verifyDoc2
  441. ,verifyDoc3
  442. ,CMT.selfie
  443. ,CMT.referelCode
  444. ,CMT.createdBy
  445. ,GETDATE()
  446. ,'Y'
  447. ,'Y'
  448. ,customerPassword
  449. ,[address]
  450. ,city
  451. ,state2
  452. ,4701
  453. FROM dbo.CustomerMasterTemp AS CMT(NOLOCK)
  454. WHERE CMT.customerId = @customerId
  455. SET @cust = @@IDENTITY
  456. UPDATE dbo.mobile_userRegistration
  457. SET customerId = @cust
  458. WHERE username = @username
  459. DELETE
  460. FROM customerMasterTemp
  461. WHERE username = @username
  462. COMMIT TRANSACTION
  463. IF @@TRANCOUNT = 0
  464. BEGIN
  465. SELECT 0 AS ERRORCODE
  466. ,'KYC Submitted successfully' AS MSG
  467. ,@userName AS ID
  468. ,@cust AS EXTRA
  469. RETURN
  470. END
  471. EXEC proc_errorHandler 1
  472. ,'Failed to Submit KYC'
  473. ,@userName
  474. RETURN
  475. END
  476. IF @flag = 'u'
  477. BEGIN
  478. IF (YEAR(GETDATE()) - YEAR(@dateOfBirth) < 16)
  479. BEGIN
  480. EXEC proc_errorHandler 1
  481. ,'Customer Not Eligible'
  482. ,@userName
  483. RETURN
  484. END
  485. ----OR cm.mobile=@userName not aplicable
  486. IF NOT EXISTS (
  487. SELECT TOP 1 'x'
  488. FROM dbo.customerMaster(NOLOCK) cm
  489. WHERE cm.email = @userName
  490. )
  491. BEGIN
  492. SELECT @errorMsg = 'Customer with userId ' + @userName + ' does not exists.'
  493. EXEC proc_errorHandler 1
  494. ,@errorMsg
  495. ,@userName
  496. RETURN
  497. END
  498. SELECT @customerId = cm.customerId
  499. FROM dbo.customerMaster(NOLOCK) cm
  500. WHERE cm.email = @userName
  501. --OR cm.mobile=@userName
  502. BEGIN TRANSACTION
  503. UPDATE dbo.customerMaster
  504. SET firstName = ISNULL(@fullName, fullName)
  505. ,fullName = ISNULL(@fullName, fullName)
  506. ,
  507. ----nickName=ISNULL(@nickName,nickName),
  508. mobile = ISNULL(@mobileNumber, mobile)
  509. ,email = ISNULL(@email, email)
  510. ,gender = ISNULL(@gender, gender)
  511. ,dob = ISNULL(@dateOfBirth, dob)
  512. ,nativeCountry = ISNULL(@nativeCountry, nativeCountry)
  513. ,country = ISNULL(@country, country)
  514. ,[address] = ISNULL(@address, [address])
  515. ,city = ISNULL(@city, city)
  516. ,state2 = CASE
  517. WHEN @province IS NOT NULL
  518. THEN (
  519. SELECT TOP 1 cim.cityName
  520. FROM dbo.CityMaster cim(NOLOCK)
  521. WHERE cim.cityId = @province
  522. )
  523. ELSE state2
  524. END
  525. ,occupation = ISNULL(@occupation, occupation)
  526. ,bankName = ISNULL(@primaryBankName, bankName)
  527. ,bankAccountNo = ISNULL(@primaryAccountNumber, bankAccountNo)
  528. ,idNumber = ISNULL(@verificationIdNumber, idNumber)
  529. ,idType = ISNULL(@verificationIdType, idType)
  530. ,idIssueDate = ISNULL(@issueDate, idIssueDate)
  531. ,sourceOfFund = CASE
  532. WHEN @sourceOfFund IS NOT NULL
  533. THEN (
  534. SELECT TOP 1 sd.detailTitle
  535. FROM dbo.staticDataValue sd(NOLOCK)
  536. WHERE sd.valueId = @sourceOfFund
  537. )
  538. ELSE sourceOfFund
  539. END
  540. ,idExpiryDate = ISNULL(@expiryDate, idExpiryDate)
  541. ,verifyDoc1 = ISNULL(@regIdcardFrontUrl, verifyDoc1)
  542. ,verifyDoc2 = ISNULL(@regIdcardBackUrl, verifyDoc2)
  543. ,verifyDoc3 = ISNULL(@passbookUrl, verifyDoc3)
  544. ,SelfieDoc = ISNULL(@selfieUrl, SelfieDoc)
  545. FROM customermaster(NOLOCK) cust
  546. WHERE cust.customerId = @customerId
  547. IF @@TRANCOUNT > 0
  548. COMMIT TRANSACTION
  549. SELECT errorCode = '0'
  550. ,userId = @userName
  551. ,firstName = ISNULL(cm.firstName, '')
  552. ,middleName = ISNULL(cm.middleName, '')
  553. ,lastName = ISNULL(cm.lastName1, '')
  554. ,fullname = ISNULL(cm.firstName, '') + ISNULL(' ' + cm.middleName, '') + ISNULL(' ' + cm.lastName1, '')
  555. ,nickName = ''
  556. ,mobileNumber = ISNULL(mobile, '')
  557. ,email = ISNULL(email, '')
  558. ,gender = ISNULL(sv.detailTitle, '')
  559. ,dateOfBirth = CONVERT(VARCHAR(10), dob, 120)
  560. ,nativeCountry = ISNULL(com1.countryName, '')
  561. ,country = ISNULL(com.countryName, '')
  562. ,[address] = ISNULL([address], '')
  563. ,city = ISNULL(city, '')
  564. ,province = ISNULL(cm.state2, '')
  565. ,provinceId = ISNULL(cim.cityId, '')
  566. ,occupation = ISNULL(sdv.detailTitle, '')
  567. ,primaryBankName = 'Fast Remit Bank' --bl.BankName
  568. ,primaryAccountNumber = ISNULL(cm.bankAccountNo, '')
  569. ,verificationIdType = ISNULL(dv.detailTitle, '')
  570. ,verificationIdNumber = ISNULL(cm.idNumber, '')
  571. ,issueDate = CONVERT(VARCHAR(10), cm.idIssueDate, 120)
  572. ,expiryDate = CONVERT(VARCHAR(10), cm.idExpiryDate, 120)
  573. ,sourceOfFund = ISNULL(cm.sourceOfFund, '')
  574. ,regIdcardFrontUrl = ISNULL(cm.verifyDoc1, '')
  575. ,regIdcardBackUrl = ISNULL(cm.verifyDoc2, '')
  576. ,passbookUrl = ISNULL(cm.verifyDoc3, '')
  577. ,passportUrl = ''
  578. ,selfieUrl = ISNULL(cm.SelfieDoc, '')
  579. FROM (
  580. SELECT TOP 1 *
  581. FROM dbo.customerMaster(NOLOCK) cm
  582. WHERE cm.customerId = @customerId
  583. ) cm
  584. LEFT JOIN dbo.vwBankLists(NOLOCK) bl ON cm.bankName = bl.bankCode
  585. LEFT JOIN mobile_userRegistration(NOLOCK) v ON cm.customerId = v.customerId
  586. LEFT JOIN dbo.staticDataValue(NOLOCK) sdv ON cm.occupation = sdv.valueId
  587. LEFT JOIN dbo.staticDataValue(NOLOCK) sv ON cm.gender = sv.valueId
  588. LEFT JOIN dbo.countryMaster(NOLOCK) com ON cm.country = com.countryId
  589. LEFT JOIN dbo.staticDataValue(NOLOCK) dv ON cm.idType = dv.valueId
  590. LEFT JOIN dbo.countryMaster(NOLOCK) com1 ON cm.nativeCountry = com1.countryId
  591. LEFT JOIN dbo.CityMaster cim(NOLOCK) ON LTRIM(RTRIM(cim.cityName)) = LTRIM(RTRIM(cm.state2))
  592. --WHERE cm.customerId = @customerId
  593. RETURN
  594. END
  595. IF @flag = 's'
  596. BEGIN
  597. IF NOT EXISTS (
  598. SELECT TOP 1 'x'
  599. FROM dbo.customerMaster(NOLOCK) cm
  600. WHERE cm.email = @userName
  601. OR cm.mobile = @userName
  602. )
  603. BEGIN
  604. SELECT @errorMsg = 'Customer with userId ' + @userName + ' does not exists.'
  605. EXEC proc_errorHandler 1
  606. ,@errorMsg
  607. ,@userName
  608. RETURN
  609. END
  610. SELECT @customerId = cm.customerId
  611. FROM dbo.customerMaster(NOLOCK) cm
  612. WHERE cm.email = @userName
  613. OR cm.mobile = @userName
  614. SELECT errorCode = '0'
  615. ,userId = @userName
  616. ,firstName = ISNULL(cm.firstName, '')
  617. ,middleName = ''
  618. ,lastName = ''
  619. ,fullname = ISNULL(cm.fullName, '')
  620. ,nickName = ''
  621. ,mobileNumber = ISNULL(mobile, '')
  622. ,email = ISNULL(email, '')
  623. ,gender = ISNULL(sv.detailTitle, '')
  624. ,dateOfBirth = CONVERT(VARCHAR(10), dob, 120)
  625. ,nativeCountry = ISNULL(com1.countryName, '')
  626. ,country = 'South Korea'
  627. ,address = ISNULL(address, '')
  628. ,city = ISNULL(city, '')
  629. ,province = ISNULL(cm.state2, '')
  630. ,provinceId = ISNULL(cim.cityId, '')
  631. ,occupation = ISNULL(sdv.detailTitle, '')
  632. ,primaryBankName = 'Fast Remit Bank' --ISNULL(bl.BankName,'')
  633. ,primaryAccountNumber = ISNULL(cm.bankAccountNo, '')
  634. ,verificationIdType = ISNULL(dv.detailTitle, '')
  635. ,verificationIdNumber = ISNULL(cm.idNumber, '')
  636. ,issueDate = CONVERT(VARCHAR(10), cm.idIssueDate, 120)
  637. ,expiryDate = CONVERT(VARCHAR(10), cm.idExpiryDate, 120)
  638. ,sourceOfFund = ISNULL(cm.sourceOfFund, '')
  639. ,regIdcardFrontUrl = ISNULL(cm.verifyDoc1, '')
  640. ,regIdcardBackUrl = ISNULL(cm.verifyDoc2, '')
  641. ,passbookUrl = ISNULL(cm.verifyDoc3, '')
  642. ,selfieUrl = ISNULL(cm.SelfieDoc, '')
  643. FROM (
  644. SELECT TOP 1 *
  645. FROM dbo.customerMaster cm WITH (NOLOCK)
  646. WHERE customerId = @customerId
  647. ) cm
  648. LEFT JOIN dbo.vwBankLists bl WITH (NOLOCK) ON cm.bankName = bl.bankCode
  649. LEFT JOIN dbo.staticDataValue sdv WITH (NOLOCK) ON cm.occupation = sdv.valueId
  650. LEFT JOIN dbo.staticDataValue sv WITH (NOLOCK) ON cm.gender = sv.valueId
  651. LEFT JOIN dbo.countryMaster com1 WITH (NOLOCK) ON cm.nativeCountry = com1.countryId
  652. LEFT JOIN dbo.staticDataValue dv WITH (NOLOCK) ON cm.idType = dv.valueId
  653. LEFT JOIN dbo.CityMaster cim(NOLOCK) ON cim.cityName = cm.state2
  654. --WHERE customerId=@customerId
  655. RETURN
  656. END
  657. IF @flag = 'getUser' --customer due deligience(static data values)
  658. BEGIN
  659. -- OR cm.mobile=@userName USE IN FUTURE
  660. IF EXISTS (
  661. SELECT TOP 1 'x'
  662. FROM dbo.customerMaster(NOLOCK) cm
  663. WHERE cm.email = @userName
  664. )
  665. BEGIN
  666. --DECLARE @yearlyLimit VARCHAR(100)=''
  667. --DECLARE @YearStart DATE, @YearEnd DATETIME
  668. SELECT @YearStart = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)
  669. ,@YearEnd = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1) + ' 23:59:59'
  670. --deCLARE @CUSTID BIGINT
  671. SELECT @customerId = customerId
  672. FROM dbo.customerMaster(NOLOCK) cm
  673. WHERE cm.email = @userName
  674. --OR cm.mobile=@userName USE IN FUTURE
  675. SELECT @totalSend = SUM(ROUND(R.tAmt / (R.sCurrCostRate + R.sCurrHoMargin), 2, 0))
  676. FROM REMITTRAN R(NOLOCK)
  677. INNER JOIN TRANSENDERS T(NOLOCK) ON T.TRANID = R.ID
  678. AND T.CUSTOMERID = @customerId
  679. AND R.TRANSTATUS <> 'Cancel'
  680. AND R.approvedDate BETWEEN @YearStart
  681. AND @YearEnd
  682. SELECT @yearlyLimit = amount
  683. FROM dbo.csDetail CD(NOLOCK)
  684. INNER JOIN csMaster CM(NOLOCK) ON CM.csMasterId = CD.csMasterId
  685. AND CD.period = 365
  686. AND CD.condition = 4600
  687. AND ISNULL(CD.isActive, 'Y') = 'Y'
  688. AND ISNULL(CD.isDeleted, 'N') = 'N'
  689. AND ISNULL(CD.isEnable, 'Y') = 'Y'
  690. AND ISNULL(CM.isActive, 'Y') = 'Y'
  691. AND ISNULL(CM.isDeleted, 'N') = 'N'
  692. SET @yearlyLimit = (@yearlyLimit - ISNULL(@totalSend, 0))
  693. SELECT @customerId = cm.customerId
  694. FROM dbo.customerMaster(NOLOCK) cm
  695. WHERE cm.email = @userName
  696. --OR cm.mobile=@userName ## not applicable
  697. SELECT errorCode = '0'
  698. ,userId = @userName
  699. ,firstName = ISNULL(cm.firstName, '')
  700. ,middleName = ISNULL(cm.middleName, '')
  701. ,lastName = ISNULL(cm.lastName1, '')
  702. ,nickName = ''
  703. ,email = ISNULL(cm.email, '')
  704. ,mobileNumber = ISNULL(cm.mobile, '')
  705. ,verificationCode = ISNULL(ur.OTP, '')
  706. ,VerificationCodeExpiryDate = ''
  707. ,createdDate = CONVERT(VARCHAR(10), ur.createdDate, 120)
  708. ,userRoles = ''
  709. ,rewardPoint = CAST(ISNULL(cm.bonusPoint, 0) AS DECIMAL)
  710. ,isActive = CASE
  711. WHEN ISNULL(cm.isActive, 'Y') = 'Y'
  712. THEN 1
  713. ELSE 0
  714. END
  715. ,hasKYC = CASE
  716. WHEN ISNULL(cm.createdDate, '') <> ''
  717. THEN 1
  718. ELSE 0
  719. END
  720. ,isVerified = CASE
  721. WHEN cm.approvedDate IS NOT NULL
  722. THEN 1
  723. ELSE 0
  724. END
  725. ,forgetCode = ISNULL(ur.passRecoveryCode, '')
  726. ,ForgetCodeExpiryDate = ''
  727. ,primaryBankName = 'Fast Remit Bank' --CASE WHEN cm.customerType='11048' THEN N'WSB (050)' ELSE 'Kwangju Bank (034)' END
  728. ,walletNumber = ISNULL(cm.walletAccountNo, '')
  729. ,availableBalance = @yearlyLimit -- CAST([dbo].FNAGetCustomerACBal(@userName) AS DECIMAL) --change this with yearly limit after fix in mobile
  730. ,dpUrl = ''
  731. ,ISNULL(ur.cmRegistrationId, '') cmRegistrationId
  732. ,yearlyLimit = FORMAT(@yearlyLimit, '0,00') --@yearlyLimit
  733. FROM (
  734. SELECT TOP 1 *
  735. FROM dbo.customerMaster cm WITH (NOLOCK)
  736. WHERE customerId = @customerId
  737. ) cm
  738. LEFT JOIN dbo.mobile_userRegistration(NOLOCK) ur ON ur.customerId = cm.customerId
  739. LEFT JOIN dbo.vwBankLists bl WITH (NOLOCK) ON bl.bankCode = cm.bankName
  740. --WHERE cm.customerId=@customerId
  741. RETURN
  742. END
  743. ELSE
  744. BEGIN
  745. SELECT @errorMsg = 'Customer with userId ' + @userName + ' does not exists.'
  746. EXEC proc_errorHandler 1
  747. ,@errorMsg
  748. ,@userName
  749. RETURN
  750. END
  751. END
  752. IF @flag = 'refresh-customer-info'
  753. BEGIN
  754. DECLARE @isExistingCustomer BIT
  755. ,@hasUpdatedDefaultCredentials INT
  756. ,@createdFrom CHAR(1)
  757. ,@isForcedPwdChange INT
  758. ,@isForcePassChangeMob INT
  759. ,@isForcePinChangeMob INT
  760. ,@registrationType VARCHAR(100)
  761. DECLARE @notificationCount INT = 0
  762. ,@showInviteCode VARCHAR(1) = 'Y'
  763. --SELECT @yearlyLimit = amount
  764. --FROM dbo.csDetail CD(NOLOCK)
  765. --INNER JOIN csMaster CM(NOLOCK) ON CM.csMasterId = CD.csMasterId
  766. -- AND CD.period = 365
  767. -- AND CD.condition = 4600
  768. -- AND ISNULL(CD.isActive, 'Y') = 'Y'
  769. -- AND ISNULL(CD.isDeleted, 'N') = 'N'
  770. -- AND ISNULL(CD.isEnable, 'Y') = 'Y'
  771. -- AND ISNULL(CM.isActive, 'Y') = 'Y'
  772. -- AND ISNULL(CM.isDeleted, 'N') = 'N'
  773. PRINT 'A';
  774. IF EXISTS (
  775. SELECT TOP 1 'A'
  776. FROM CustomerMasterTemp(NOLOCK)
  777. WHERE username = @userName
  778. AND isActive = 'Y'
  779. )
  780. BEGIN
  781. SET @isExistingCustomer = 1
  782. IF EXISTS (
  783. SELECT *
  784. FROM CustomerMasterTemp CT(NOLOCK)
  785. WHERE username = @userName
  786. AND OldCustomerId IS NULL
  787. )
  788. BEGIN
  789. SET @isExistingCustomer = 0
  790. END
  791. UPDATE mobile_userRegistration
  792. SET appVersion = @appVersion
  793. ,phoneBrand = @phoneBrand
  794. ,phoneOS = @phoneOS
  795. ,deviceId = ISNULL(@fcmId, deviceId)
  796. ,osVersion = @osVersion
  797. WHERE customerId = (
  798. SELECT TOP 1 customerId
  799. FROM CustomerMasterTemp(NOLOCK)
  800. WHERE username = @userName
  801. AND isActive = 'Y'
  802. )
  803. SELECT '0' ErrorCode
  804. ,@userName userId
  805. ,cust.customerId SenderId
  806. ,ISNULL(cust.fullName, @userName) firstName
  807. ,ISNULL(cust.email, '') email
  808. ,ISNULL(cust.customerEmail, '') AS customerEmail
  809. ,ISNULL(cust.mobile, '') phone
  810. ,CONVERT(VARCHAR(10), cust.dob, 120) dob
  811. --,cust.idType AS idType
  812. --,cust.idNumber AS idNumber
  813. ,'' AS countryCode
  814. ,CAST(ISNULL(cust.bonusPoint, 0) AS DECIMAL) rewardPoint
  815. ,CASE
  816. WHEN ISNULL(cust.isActive, 'N') = 'Y'
  817. THEN 1
  818. ELSE 0
  819. END active
  820. ,KYC=0
  821. ,verified=0
  822. ,'' walletNumber
  823. ,0 availableBalance
  824. ,'Fast Remit Bank' primaryBankName
  825. ,ISNULL(dpUrl, '') dpUrl
  826. ,ISNULL(ur.cmRegistrationId, '') cmRegistrationId
  827. ,ISNULL(co.countryName, '') country
  828. ,'' city
  829. ,'' [address]
  830. ,'' [province]
  831. ,'' [provinceId]
  832. ,CASE
  833. WHEN cust.referelCode IS NOT NULL
  834. THEN 1
  835. ELSE 0
  836. END isReferred
  837. ,'' sourceId
  838. ,yearlyLimit = FORMAT(@yearlyLimit, '0,00')
  839. ,PennyTestStatus = '2'
  840. ,'' accessTokenRegTime
  841. ,'' accessTokenExpTime
  842. ,redirectTo = ISNULL(cust.registrationType,'EKYC')
  843. ,cust.membershipId AS referelCode
  844. , 'true' agreeYn
  845. ,isExistingCustomer = @isExistingCustomer
  846. ,hasUpdatedDefaultCredentials = '2'
  847. ,hasVerifiedOTP = CASE
  848. WHEN ISNULL(isEmailVerified, 0) = 0
  849. THEN 'False'
  850. ELSE 'True'
  851. END
  852. ,IsBiometricLogin = 0
  853. ,BiometricLoginType = ''
  854. ,@notificationCount notificationCount
  855. ,CONVERT(VARCHAR(10), cust.idExpiryDate, 121) IDExpiryDate
  856. ,CASE
  857. WHEN GETDATE() > cust.idExpiryDate
  858. THEN 'Expired'
  859. ELSE 'Valid'
  860. END idStatus
  861. ,showInviteCode = ISNULL(@showInviteCode, 'N')
  862. ,RewardPoints = 0
  863. ,ISNULL(ur.ResidenceType, 'FOREIGNER') ResidenceType
  864. ,ISNULL(ur.UseNFC, 'Y') UseNFC
  865. ,cust.SelfieDoc
  866. ,KycVerified= 0
  867. ,KycStatus= ISNULL(verificationCode,'NOT_COMPLETED')
  868. ,KycStatusMsg= CASE verificationCode WHEN 'NOT_COMPLETED'
  869. THEN 'Not Completed' WHEN 'PROCESSING' THEN 'ID Document Submission is in Processing'
  870. WHEN 'COMPLETED' THEN 'KYC Completed' ELSE 'NOT COMPLETED' END
  871. FROM (
  872. SELECT TOP 1 *
  873. FROM CustomerMasterTemp(NOLOCK) cust
  874. WHERE cust.username = @userName
  875. ) cust
  876. LEFT JOIN mobile_userRegistration(NOLOCK) ur ON cust.customerId = ur.customerId
  877. LEFT JOIN countryMaster co(NOLOCK) ON cust.country = co.countryId
  878. LEFT JOIN dbo.CityMaster cm(NOLOCK) ON cust.state2 = cm.cityName
  879. WHERE ur.username = @userName
  880. RETURN
  881. END
  882. DECLARE @customerStatus VARCHAR(5)
  883. ,@ekycPinUpdated BIT
  884. ,@deviceType VARCHAR(20)
  885. SELECT @customerId = cm.customerId
  886. ,@IsActive = isActive
  887. ,@createdFrom = ISNULL(createdFrom, 'O')
  888. ,@isForcedPwdChange = ISNULL(isForcedPwdChange, 2)
  889. ,@isExistingCustomer = ISNULL(isexistingcustomer, 0)
  890. ,@isForcePassChangeMob = ISNULL(ur.isForcePassChange, 0)
  891. ,@isForcePinChangeMob = ISNULL(ur.isForcePinChange, 0)
  892. ,@registrationType = ISNULL(cm.registrationType, '')
  893. ,@customerStatus = cm.customerStatus
  894. ,@ekycPinUpdated = ISNULL(ur.ekycPinUpdated, 0)
  895. ,@deviceType = ur.DeviceType
  896. FROM dbo.customerMaster(NOLOCK) cm
  897. INNER JOIN mobile_userRegistration(NOLOCK) ur ON cm.customerId = ur.customerId
  898. WHERE cm.username = @userName
  899. PRINT @customerId;
  900. --notification count
  901. SELECT @notificationCount = count(*)
  902. FROM pushNotificationHistroy
  903. WHERE isRead = 0
  904. AND type = 0
  905. AND customerId = @customerId
  906. DECLARE @rewardPoints INT = 0;
  907. SET @rewardPoints = CAST(DBO.FNA_GET_AVAILABLE_BALANCE_POINTS(@customerId) AS INT);
  908. -- IF EXISTS (
  909. -- SELECT 'x'
  910. -- FROM IntroducerCommissionSetup
  911. -- WHERE IntroducerId = @customerId
  912. -- )
  913. -- BEGIN
  914. -- SET @showInviteCode = 'N'
  915. -- END
  916. --SELECT @customerStatus = customerstatus
  917. --FROM customerMaster
  918. --WHERE customerid = @customerId
  919. --IF @isForcedPwdChange <> 0
  920. --BEGIN
  921. -- IF @createdFrom = 'C'
  922. -- AND @customerStatus = 'OTC'
  923. -- SET @hasUpdatedDefaultCredentials = 2
  924. -- IF @createdFrom = 'C'
  925. -- AND @customerStatus IS NULL
  926. -- SET @hasUpdatedDefaultCredentials = 0
  927. -- IF @createdFrom = 'M'
  928. -- AND @isExistingCustomer = 1
  929. -- SET @hasUpdatedDefaultCredentials = 0
  930. -- IF @createdFrom = 'M'
  931. -- AND @isExistingCustomer = 0
  932. -- SET @hasUpdatedDefaultCredentials = 1 --change Pin
  933. -- IF @createdFrom = 'A'
  934. -- SET @hasUpdatedDefaultCredentials = 2 --change pin & password
  935. -- IF @createdFrom = 'O'
  936. -- SET @hasUpdatedDefaultCredentials = 0
  937. --END
  938. --ELSE
  939. -- SET @hasUpdatedDefaultCredentials = 0
  940. --IF (
  941. -- @hasUpdatedDefaultCredentials = 0
  942. -- AND @isForcePassChangeMob = 1
  943. -- )
  944. --BEGIN
  945. -- SET @hasUpdatedDefaultCredentials = 3 -- change password only
  946. --END
  947. --ELSE IF (
  948. -- @hasUpdatedDefaultCredentials = 0
  949. -- AND @isForcePinChangeMob = 1
  950. -- )
  951. --BEGIN
  952. -- SET @hasUpdatedDefaultCredentials = 4 -- change pin only
  953. --END
  954. --ELSE
  955. --BEGIN
  956. -- IF @createdFrom = 'M'
  957. -- AND @isExistingCustomer = 0
  958. -- AND ISNULL(@registrationType, '') = 'EKYC'
  959. -- AND @ekycPinUpdated = 0 --AND ISNULL(@deviceType,'IOS')<>'Android'
  960. -- SET @hasUpdatedDefaultCredentials = 5 --change Pin
  961. --END
  962. --OR cm.mobile=@userName future use
  963. DECLARE @hasPennyTestDone VARCHAR(1) = '0'
  964. SELECT @hasPennyTestDone = '1'
  965. IF @customerId IS NULL
  966. BEGIN
  967. EXEC proc_errorHandler 1
  968. ,'Unauthorized access found, Please contact JME support'
  969. ,@userName
  970. RETURN
  971. END
  972. --IF EXISTS (
  973. -- SELECT TOP 1 'x'
  974. -- FROM dbo.customerMaster(NOLOCK)
  975. -- WHERE approvedDate < '2018-12-19'
  976. -- AND customerId = @customerId
  977. -- )
  978. --BEGIN
  979. -- SET @hasPennyTestDone = '2'
  980. --END
  981. SET @hasPennyTestDone = '2'
  982. IF ISNULL(@IsActive, 'N') <> 'Y'
  983. BEGIN
  984. EXEC proc_errorHandler 1
  985. ,'Your account has blocked, Please contact JME support'
  986. ,@userName
  987. RETURN
  988. END
  989. SELECT @YearStart = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)
  990. ,@YearEnd = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1) + ' 23:59:59'
  991. --SELECT @totalSend = SUM(R.tAmt) --SUM(ROUND(R.tAmt/(R.sCurrCostRate+R.sCurrHoMargin), 2, 0))
  992. --FROM REMITTRAN R(NOLOCK)
  993. --INNER JOIN TRANSENDERS T(NOLOCK) ON T.TRANID = R.ID
  994. -- AND T.CUSTOMERID = @customerId
  995. -- AND R.TRANSTATUS <> 'Cancel'
  996. -- AND R.approvedDate BETWEEN @YearStart
  997. -- AND @YearEnd
  998. SET @yearlyLimit = (@yearlyLimit - ISNULL(@totalSend, 0))
  999. UPDATE mobile_userRegistration
  1000. SET appVersion = @appVersion
  1001. ,phoneBrand = @phoneBrand
  1002. ,phoneOS = @phoneOS
  1003. ,deviceId = ISNULL(@fcmId, deviceId)
  1004. ,osVersion = @osVersion
  1005. WHERE customerId = @customerId
  1006. SELECT '0' ErrorCode
  1007. ,@userName userId
  1008. ,cust.customerId SenderId
  1009. ,ISNULL(cust.fullName, '') firstName
  1010. ,ISNULL(cust.email, '') email
  1011. ,ISNULL(cust.customerEmail, '') AS customerEmail
  1012. ,ISNULL(cust.mobile, '') phone
  1013. ,CONVERT(VARCHAR(10), cust.dob, 120) dob
  1014. --,cust.idType AS idType
  1015. --,cust.idNumber AS idNumber
  1016. ,cm1.countryCode AS countryCode
  1017. ,CAST(ISNULL(@rewardPoints, 0) AS DECIMAL) rewardPoint
  1018. ,CASE
  1019. WHEN ISNULL(cust.isActive, 'N') = 'Y'
  1020. THEN 1
  1021. ELSE 0
  1022. END active
  1023. ,CASE lawsoncardno WHEN 'KYC_LATER' THEN 1 ELSE ISNULL(HasDeclare, 0) END kyc
  1024. ,CASE
  1025. WHEN ISNULL(HasDeclare, 0) =0 THEN 0
  1026. WHEN ISNULL(mobileApprovedDate,mobileVerifiedDate) IS NOT NULL
  1027. THEN 1
  1028. ELSE 0
  1029. END verified
  1030. ,walletAccountNo walletNumber
  1031. ,0 availableBalance
  1032. --,ISNULL(bl.BankName,'') primaryBankName
  1033. ,cust.username
  1034. ,primaryBankName = 'Fast Remit Bank' --CASE WHEN cust.customerType='11048' THEN N'저축은행 (050)' ELSE 'Kwangju Bank (034)' END
  1035. ,'' dpUrl
  1036. ,ISNULL(ur.cmRegistrationId, '') cmRegistrationId
  1037. ,ISNULL(co.countryName, '') country
  1038. ,ISNULL(cust.city, '') city
  1039. ,ISNULL(cust.[address], '') [address]
  1040. ,ISNULL(cust.state2, '') [province]
  1041. ,ISNULL(cm.cityId, '') [provinceId]
  1042. ,CASE
  1043. WHEN cust.referelCode IS NOT NULL
  1044. THEN 1
  1045. ELSE 0
  1046. END isReferred
  1047. ,ISNULL(sdv.valueId, '') sourceId
  1048. ,yearlyLimit = FORMAT(@yearlyLimit, '0,00')
  1049. ,PennyTestStatus = @hasPennyTestDone -----0 not started, 1 requested , 2 completed
  1050. ,kcm.accessTokenRegTime
  1051. ,kcm.accessTokenExpTime
  1052. ,redirectTo = ISNULL(cust.RegistrationType, 'EKYC') --@redirectTo
  1053. ,cust.membershipId AS referelCode
  1054. ,agreeYn = CASE lawsoncardno WHEN 'KYC_LATER' THEN 'true' ELSE ISNULL(cust.agreeYn, 'false') END
  1055. ,isExistingCustomer = ISNULL(isExistingCustomer, 1)
  1056. ,hasUpdatedDefaultCredentials = ISNULL(@hasUpdatedDefaultCredentials, 0)
  1057. ,hasVerifiedOTP = ISNULL(isEmailVerified, 0)
  1058. ,IsBiometricLogin = ISNULL(IsBiometricLogin, 0)
  1059. ,BiometricLoginType = ISNULL(BiometricLoginType, '')
  1060. --,CASE ur.isForcePassChange WHEN '1' THEN 'Y' ELSE 'N' END IsForcedPwdChange
  1061. ,@notificationCount notificationCount
  1062. ,CONVERT(VARCHAR(10), cust.idExpiryDate, 121) IDExpiryDate
  1063. ,CASE
  1064. WHEN GETDATE() > cust.idExpiryDate
  1065. THEN 'Expired'
  1066. ELSE 'Valid'
  1067. END idStatus
  1068. ,showInviteCode = ISNULL(@showInviteCode, 'N')
  1069. ,RewardPoints = ISNULL(@rewardPoints, 0)
  1070. ,ISNULL(ur.ResidenceType, 'FOREIGNER') ResidenceType
  1071. ,ISNULL(ur.UseNFC, 'Y') UseNFC
  1072. ,REPLACE(cust.SelfieDoc, '\\', '/') SelfieDoc
  1073. ,KycVerified= ISNULL(isVerifiedByCustomer,0)
  1074. ,KycStatus= ISNULL(verificationCode,'NOT_COMPLETED')
  1075. ,KycStatusMsg= CASE verificationCode WHEN 'NOT_COMPLETED'
  1076. THEN 'Not Completed' WHEN 'PROCESSING' THEN 'ID Document Submission is in Processing'
  1077. WHEN 'COMPLETED' THEN 'KYC Completed' ELSE 'NOT COMPLETED' END
  1078. FROM (
  1079. SELECT TOP 1 *
  1080. FROM customerMaster(NOLOCK) cust
  1081. WHERE cust.customerId = @customerId
  1082. ) cust
  1083. LEFT JOIN dbo.countryMaster AS CM1 ON cm1.countryId = cust.nativeCountry
  1084. LEFT JOIN mobile_userRegistration(NOLOCK) ur ON cust.customerId = ur.customerId
  1085. LEFT JOIN dbo.vwBankLists(NOLOCK) bl ON cust.bankName = bl.rowId
  1086. LEFT JOIN countryMaster co(NOLOCK) ON cust.country = co.countryId
  1087. LEFT JOIN staticDatavalue sdv(NOLOCK) ON cust.sourceOfFund = sdv.detailTitle
  1088. AND sdv.typeID = '3900'
  1089. AND ISNULL(sdv.IS_DELETE, 'N') = 'N'
  1090. LEFT JOIN dbo.CityMaster cm(NOLOCK) ON cust.state2 = cm.cityName
  1091. LEFT JOIN dbo.KFTC_CUSTOMER_MASTER(NOLOCK) kcm ON cust.customerId = kcm.customerId
  1092. WHERE cust.customerId = @customerId AND ISNULL(sdv.IS_DELETE,'N')='N'
  1093. RETURN
  1094. END
  1095. IF @flag = 'get-invite-details'
  1096. BEGIN
  1097. -- PRINT @sourceCustomerId;
  1098. DECLARE @totalCustomerCount INT
  1099. ,@registrationMoney MONEY
  1100. ,@transactionMoney MONEY
  1101. IF EXISTS (
  1102. SELECT 'X'
  1103. FROM CustomerMaster(NOLOCK)
  1104. WHERE CUSTOMERID = @sourceCustomerId
  1105. )
  1106. BEGIN
  1107. IF OBJECT_ID('tempdb..#Reward') IS NOT NULL
  1108. DROP TABLE #Reward
  1109. CREATE TABLE #Reward (
  1110. DESTINATION_CUSTOMERID INT
  1111. ,REWARD_TYPE VARCHAR(50)
  1112. ,REWARD_AMOUNT INT
  1113. ,CUSTOMER_NAME VARCHAR(200)
  1114. ,CREATED_DATE VARCHAR(10)
  1115. ,REWARD_POINTS VARCHAR(100)
  1116. ,REFERRAL_CODE VARCHAR(200)
  1117. )
  1118. INSERT INTO #Reward (
  1119. DESTINATION_CUSTOMERID
  1120. ,REWARD_TYPE
  1121. ,REWARD_AMOUNT
  1122. ,CREATED_DATE
  1123. ,REWARD_POINTS
  1124. ,REFERRAL_CODE
  1125. )
  1126. SELECT destinationCustomerId
  1127. ,CASE
  1128. WHEN codeType = 'REGISTRATION'
  1129. THEN 'Successful Registration'
  1130. WHEN codeType = 'FIRST_TXN'
  1131. THEN 'First Transaction Done'
  1132. WHEN codeType = 'REDEEM'
  1133. THEN 'Points Used'
  1134. WHEN codeType = 'MULTI_TXN'
  1135. THEN 'JME Reward - Multi Transaction'
  1136. END
  1137. ,CASE
  1138. WHEN trantype = 'DR'
  1139. THEN - CAST(ISNULL(AMOUNT, 0) AS INT)
  1140. ELSE CAST(ISNULL(AMOUNT, 0) AS INT)
  1141. END
  1142. ,CONVERT(VARCHAR(10), cp.createdDate, 121)
  1143. ,CAST(dbo.[FNA_GET_AVAILABLE_BALANCE_POINTS](@sourceCustomerId) AS INT) AS [rewardMoney]
  1144. --,(SELECT membershipId FROM customerMaster WHERE customerId = @sourceCustomerId) AS [referralCode]
  1145. , ISNULL((SELECT membershipId FROM customerMaster WHERE customerId = @sourceCustomerId), '') AS referralCode
  1146. FROM Customer_Promotion CP(NOLOCK)
  1147. WHERE sourceCustomerId = @sourceCustomerId
  1148. AND [STATUS] = 1
  1149. UPDATE R
  1150. SET CUSTOMER_NAME = ISNULL(fullName, '')
  1151. FROM #Reward R
  1152. INNER JOIN customerMaster CM(NOLOCK) ON R.DESTINATION_CUSTOMERID = customerId
  1153. SELECT @totalCustomerCount = COUNT(destinationCustomerId)
  1154. FROM Customer_Promotion CP(NOLOCK)
  1155. WHERE 1 = 1
  1156. AND sourceCustomerId = @sourceCustomerId
  1157. AND codeType = 'REGISTRATION'
  1158. AND [status] = '1'
  1159. --SELECT @registrationMoney = ISNULL(SUM(amount), 0)
  1160. --FROM Customer_Promotion CP(NOLOCK)
  1161. --WHERE 1 = 1
  1162. -- AND sourceCustomerId = @sourceCustomerId
  1163. -- AND rewardType = 'REGISTRATION'
  1164. -- AND [status] = '1'
  1165. -- AND tranType = 'CR'
  1166. --SELECT @transactionMoney = ISNULL(SUM(amount), 0)
  1167. --FROM Customer_Promotion CP(NOLOCK)
  1168. --WHERE 1 = 1
  1169. -- AND sourceCustomerId = @sourceCustomerId
  1170. -- AND rewardType = 'TRANSACTION'
  1171. -- -- AND [status] = '1' Total
  1172. -- AND tranType = 'CR'
  1173. -- select * from customer_promotion
  1174. SELECT DISTINCT @totalCustomerCount AS [totalReferral]
  1175. ,CAST(dbo.[FNA_GET_AVAILABLE_BALANCE_POINTS](@sourceCustomerId) AS INT) AS [rewardMoney]
  1176. --,(isnull(@registrationMoney, 0) + isnull(@transactionMoney, 0)) AS [rewardMoney]
  1177. ,cm.membershipId AS [inviteCode]
  1178. --,'Earned ' + CAST(@registrationMoney AS VARCHAR) + ' JPY for Regisration. ' + CAST(@transactionMoney AS VARCHAR) + ' for first Txn' AS [inviteMessage]
  1179. ,customerId AS sourceCustomerId
  1180. FROM CUSTOMERMASTER CM(NOLOCK)
  1181. LEFT JOIN Customer_Promotion CP(NOLOCK) ON CM.customerId = CP.sourceCustomerId
  1182. WHERE 1 = 1
  1183. AND CM.customerId = @sourceCustomerId
  1184. SELECT *
  1185. FROM #Reward
  1186. SELECT @totalCustomerCount = COUNT(destinationCustomerId)
  1187. FROM Customer_Promotion CP(NOLOCK)
  1188. WHERE 1 = 1
  1189. AND sourceCustomerId = @sourceCustomerId
  1190. AND codeType = 'REGISTRATION'
  1191. AND [status] = '1'
  1192. --SELECT @registrationMoney = ISNULL(SUM(amount), 0)
  1193. --FROM Customer_Promotion CP(NOLOCK)
  1194. --WHERE 1 = 1
  1195. -- AND sourceCustomerId = @sourceCustomerId
  1196. -- AND rewardType = 'REGISTRATION'
  1197. -- AND [status] = '1'
  1198. -- AND tranType = 'CR'
  1199. --SELECT @transactionMoney = ISNULL(SUM(amount), 0)
  1200. --FROM Customer_Promotion CP(NOLOCK)
  1201. --WHERE 1 = 1
  1202. -- AND sourceCustomerId = @sourceCustomerId
  1203. -- AND rewardType = 'TRANSACTION'
  1204. -- -- AND [status] = '1' Total
  1205. -- AND tranType = 'CR'
  1206. -- select * from customer_promotion
  1207. SELECT DISTINCT @totalCustomerCount AS [totalReferral]
  1208. ,CAST(dbo.[FNA_GET_AVAILABLE_BALANCE_POINTS](@sourceCustomerId) AS INT) AS [rewardMoney]
  1209. --,(isnull(@registrationMoney, 0) + isnull(@transactionMoney, 0)) AS [rewardMoney]
  1210. ,cm.membershipId AS [inviteCode]
  1211. --,'Earned ' + CAST(@registrationMoney AS VARCHAR) + ' JPY for Regisration. ' + CAST(@transactionMoney AS VARCHAR) + ' for first Txn' AS [inviteMessage]
  1212. ,customerId AS sourceCustomerId
  1213. FROM CUSTOMERMASTER CM(NOLOCK)
  1214. LEFT JOIN Customer_Promotion CP(NOLOCK) ON CM.customerId = CP.sourceCustomerId
  1215. WHERE 1 = 1
  1216. AND CM.customerId = @sourceCustomerId
  1217. END
  1218. ELSE
  1219. BEGIN
  1220. SELECT @errorMsg = 'Customer does not exists.'
  1221. EXEC proc_errorHandler 1
  1222. ,@errorMsg
  1223. ,@sourceCustomerId
  1224. RETURN
  1225. END
  1226. END
  1227. IF @flag = 'get-reward-fee'
  1228. BEGIN
  1229. DECLARE @showRewardPoints CHAR(1) = 'N'
  1230. IF EXISTS (
  1231. SELECT 'x'
  1232. FROM Customer_Promotion(NOLOCK)
  1233. WHERE sourceCustomerId = @sourceCustomerId
  1234. )
  1235. BEGIN
  1236. SET @showRewardPoints = 'Y'
  1237. END
  1238. SELECT CAST(DBO.FNA_GET_AVAILABLE_BALANCE_POINTS(@sourceCustomerId) AS INT) AS [point]
  1239. ,showRewardPoint = ISNULL(@showRewardPoints, 'N')
  1240. END
  1241. IF @flag = 'get-loyalty-points'
  1242. BEGIN
  1243. DECLARE @tranCount INT = 0;
  1244. DECLARE @enable CHAR(1) = 'Y';
  1245. DECLARE @totalCount INT
  1246. ,@isFreeSc CHAR(1) = 'N'
  1247. EXEC PROC_Customer_Loyalty @flag = 'get-tranCount'
  1248. ,@customerId = @sourceCustomerId
  1249. ,@tranCount = @tranCount OUT
  1250. SELECT @totalCount = (
  1251. SELECT TOP 1 txnCount
  1252. FROM schemeSetup(NOLOCK)
  1253. WHERE isActive = 'Y'
  1254. ORDER BY createdDate DESC
  1255. )
  1256. IF @tranCount >= @totalCount
  1257. BEGIN
  1258. SET @isFreeSc = 'Y'
  1259. END
  1260. IF @totalCount IS NULL
  1261. BEGIN
  1262. SET @totalCount = 5
  1263. SET @enable = 'N';
  1264. END
  1265. SELECT ISNULL(@tranCount, 0) AS tranCount
  1266. ,ISNULL(@totalCount, 0) AS totalCount
  1267. ,@isFreeSc AS isFreeSc
  1268. ,requiredCount = CASE
  1269. WHEN (ISNULL(@totalCount, 0) - ISNULL(@tranCount, 0)) > 0
  1270. THEN (ISNULL(@totalCount, 0) - ISNULL(@tranCount, 0))
  1271. ELSE 0
  1272. END
  1273. ,@enable IsActive
  1274. END
  1275. IF @flag = 'save-profile'
  1276. BEGIN
  1277. DECLARE @fileDescription VARCHAR(10) = NULL
  1278. SET @fileDescription = 'Selfie'
  1279. SELECT @customerId = customerId FROM customerMaster (NOLOCK) WHERE username = @userName
  1280. IF EXISTS (SELECT TOP 1 1 FROM customerDocument (NOLOCK) WHERE customerId = @customerId AND fileDescription = @fileDescription)
  1281. BEGIN
  1282. UPDATE customerDocument SET fileName = @fileName , fileType = @filetype , modifiedBy = @userName , modifiedDate = GETDATE()
  1283. WHERE customerId = @customerId and fileDescription = @fileDescription
  1284. END
  1285. ELSE
  1286. BEGIN
  1287. INSERT INTO customerDocument (
  1288. customerId
  1289. ,[fileName]
  1290. ,fileDescription
  1291. ,fileType
  1292. ,createdBy
  1293. ,createdDate
  1294. ,approvedBy
  1295. ,approvedDate
  1296. ,isProfilePic
  1297. ,documentType
  1298. )
  1299. SELECT
  1300. @customerId
  1301. ,@fileName
  1302. ,@fileDescription
  1303. ,@fileType
  1304. ,@userName
  1305. ,GETDATE()
  1306. ,@userName
  1307. ,GETDATE()
  1308. ,'1'
  1309. ,'11440' -- Customer Selfie
  1310. END
  1311. IF EXISTS (
  1312. SELECT TOP 1 1
  1313. FROM customerMaster(NOLOCK)
  1314. WHERE username = @username
  1315. )
  1316. BEGIN
  1317. UPDATE customerMaster
  1318. SET SelfieDoc = @url
  1319. WHERE username = @username
  1320. SELECT '0' ErrorCode
  1321. ,'Customer profile updated successfully' Msg
  1322. ,@username Id
  1323. ,@fileName Extra
  1324. END
  1325. ELSE
  1326. BEGIN
  1327. SELECT '1' ErrorCode
  1328. ,'Username not found.' Msg
  1329. ,@username Id
  1330. RETURN
  1331. END
  1332. END
  1333. IF @flag = 'get-membershipId'
  1334. BEGIN
  1335. --IF EXISTS (
  1336. -- SELECT TOP 1 1
  1337. -- FROM customerMaster(NOLOCK)
  1338. -- WHERE customerid = @customerId
  1339. -- )
  1340. --BEGIN
  1341. SELECT membershipId,CONVERT(VARCHAR(10), createdDate,121) createdDate
  1342. FROM customerMaster
  1343. WHERE customerId = @userId
  1344. -- RETURN ;
  1345. --END
  1346. --SELECT NULL membershipId
  1347. END
  1348. IF @flag = 'get-ResidenceType'
  1349. BEGIN
  1350. select CASE WHEN ResidenceType='RESIDENCE' THEN 'RESIDENT' WHEN ( (ResidenceType ='0' OR ResidenceType IS NULL) AND idType='11168' ) THEN 'FOREIGNER'
  1351. WHEN ( (ResidenceType ='0' OR ResidenceType IS NULL) AND idType='11079' ) THEN 'RESIDENT'
  1352. ELSE ISNULL(ResidenceType,'') END ResidenceType , idType FROM mobile_userRegistration mu inner join
  1353. customerMaster cm on mu.customerId= cm.customerId
  1354. WHERE cm.username = @userName
  1355. UNION ALL
  1356. select CASE WHEN ResidenceType='RESIDENCE' THEN 'RESIDENT' WHEN ( (ResidenceType ='0' OR ResidenceType IS NULL) AND idType='11168' ) THEN 'FOREIGNER'
  1357. WHEN ( (ResidenceType ='0' OR ResidenceType IS NULL) AND idType='11079' ) THEN 'RESIDENT'
  1358. ELSE ISNULL(ResidenceType,'') END ResidenceType , idType FROM mobile_userRegistration mu inner join
  1359. CustomerMasterTemp cm on mu.customerId= cm.customerId
  1360. WHERE cm.username = @userName
  1361. -- RETURN ;
  1362. --END
  1363. --SELECT NULL membershipId
  1364. END
  1365. IF @flag = 'get-payment-method'
  1366. BEGIN
  1367. SELECT CAST(detailDesc AS DECIMAL(7,2) ) detailDesc ,
  1368. REPLACE(REPLACE(detailTitle, CHAR(13), ''), CHAR(10), '') detailTitle , CASE detailTitle WHEN 'ONLINE' THEN 'Online Banking(Best Rate)' WHEN 'DEBIT_CARD' THEN 'DEBIT CARD' ELSE 'E-Banking (Good rate)' END AS DisplayText
  1369. FROM staticDataValue WHERE typeId = '8109'
  1370. RETURN
  1371. END
  1372. IF @flag = 'get-profile-details'
  1373. BEGIN
  1374. SELECT TOP 1 cmt.firstName
  1375. ,fullName
  1376. ,gender = CASE
  1377. WHEN gender = 97
  1378. THEN 'Male'
  1379. WHEN gender = 98
  1380. THEN 'Female'
  1381. ELSE 'OTHERS'
  1382. END
  1383. ,CONVERT(VARCHAR(10), dob, 120) AS dob
  1384. ,email AS email
  1385. ,city
  1386. ,address
  1387. ,ADDITIONALADDRESS
  1388. ,nativeCountry = cm.countryName
  1389. ,idNumber AS passportNumber
  1390. ,CONVERT(VARCHAR(10), idIssueDate, 120) AS passportIssueDate
  1391. ,CONVERT(VARCHAR(10), idExpiryDate, 120) AS passportExpiryDate
  1392. ,idIssueCountry
  1393. ,mobile
  1394. ,referelCode
  1395. ,customerId AS userId
  1396. ,zipCode
  1397. FROM dbo.customerMaster(NOLOCK) cmt
  1398. LEFT JOIN dbo.countryMaster(NOLOCK) cm ON cm.countryId = cmt.nativeCountry
  1399. WHERE username = @email
  1400. RETURN
  1401. END
  1402. END TRY
  1403. BEGIN CATCH
  1404. IF @@TRANCOUNT > 0
  1405. ROLLBACK TRANSACTION
  1406. DECLARE @errorMessage VARCHAR(MAX)
  1407. SET @errorMessage = ERROR_MESSAGE()
  1408. SELECT '1' ErrorCode
  1409. ,@errorMessage Msg
  1410. ,NULL ID
  1411. END CATCH
  1412. GO