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.

1400 lines
64 KiB

1 year ago
1 year ago
12 months ago
12 months ago
1 year ago
10 months ago
10 months ago
11 months ago
1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[mobile_proc_customerMaster_V2] Script Date: 12/13/2023 10:18:24 AM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[mobile_proc_customerMaster_V2] (
  9. @flag VARCHAR(20)
  10. ,@username VARCHAR(100) = NULL
  11. ,@type VARCHAR(100) = NULL
  12. ,@sourceOfFund VARCHAR(100) = NULL
  13. ,@monthlyIncome VARCHAR(100) = NULL
  14. ,@businessType VARCHAR(100) = NULL
  15. ,@mobile VARCHAR(100) = NULL
  16. ,@email VARCHAR(100) = NULL
  17. ,@additionalAddress NVARCHAR(100) = NULL
  18. ,@idType VARCHAR(100) = NULL
  19. ,@idTypeNumber VARCHAR(100) = NULL
  20. ,@idIssuingCountry VARCHAR(5) = NULL
  21. ,@idStartDate VARCHAR(20) = NULL
  22. ,@idEndDate VARCHAR(20) = NULL
  23. ,@additionalIdType VARCHAR(100) = NULL
  24. ,@idFront VARCHAR(100) = NULL
  25. ,@idBack VARCHAR(100) = NULL
  26. ,@occupation VARCHAR(100) = NULL
  27. ,@idSide VARCHAR(100) = NULL
  28. ,@additionalId VARCHAR(100) = NULL
  29. ,@additionalIdBack VARCHAR(100) = NULL
  30. ,@facePicture VARCHAR(100) = NULL
  31. ,@currentPin VARCHAR(20) = NULL
  32. ,@NewPassword VARCHAR(50) = NULL
  33. ,@newPin VARCHAR(20) = NULL
  34. ,@currentPassword VARCHAR(50) = NULL
  35. ,@confirmNewPin VARCHAR(20) = NULL
  36. ,@ConfirmNewPassword VARCHAR(50) = NULL
  37. ,@employeerName VARCHAR(100) = NULL
  38. ,@visaStatus VARCHAR(50) = NULL
  39. ,@occupationOther VARCHAR(150) = NULL
  40. ,@otherIdType VARCHAR(150) = NULL
  41. ,@otherOccupation VARCHAR(150) = NULL
  42. ,@otherSourceOfFund VARCHAR(150) = NULL
  43. ,@purposeOfRegistration INT = NULL
  44. ,@SettingType VARCHAR(30) = NULL
  45. ,@customerPassword NVARCHAR(20) = NULL
  46. ,@token VARCHAR(MAX) = NULL
  47. ,@idTypeOther VARCHAR(150) = NULL
  48. ,@code NVARCHAR(50) = NULL
  49. ,@amount MONEY = NULL
  50. ,@rType VARCHAR(20) = NULL
  51. ,@trustDocId UNIQUEIDENTIFIER = NULL
  52. )
  53. AS
  54. ;
  55. ------------------------------------------------------------------------------------------------------------
  56. -- Task #225 - Create Token For Bioemtric - flag = 'update-settings' , insert for mobiletoken
  57. -- #101 , #361 - Mobile changes for multi lingual
  58. -- #387 - Force Reset Pin , @flag= 'c-pin'
  59. -- #205 - add param @idTypeOther
  60. -- otherIdNumber set value with Other ID (Please Specify)
  61. -- #495 changed parameter for occupationOther
  62. --Bug #763 Wrong Message display in case of change Pin & Password
  63. -- store montly income in salaryRange for existing customer
  64. -- #1030 , @flag = 'agree' , added isAgreeDate
  65. --Bug #1065 missing Missing ForcePinChangeDate
  66. -- #946 -> duplicate mobile number validation in @flag = 'i' for new customer registration from mobile
  67. -- #1003 -> Reward Points , @flag = 'i' , 'i-existing'
  68. ------------------------------------------------------------------------------------------------------------
  69. SET NOCOUNT ON;
  70. SET XACT_ABORT ON;
  71. BEGIN
  72. SET DATEFORMAT dmy;
  73. DECLARE @customerId BIGINT
  74. ,@cust BIGINT
  75. ,@errorMsg VARCHAR(MAX)
  76. ,@sourceCustomerId INT
  77. ,@rewardAmount MONEY
  78. ,@runningBalance MONEY
  79. ,@totalDrAmount MONEY
  80. ,@totalCrAmount MONEY
  81. ,@trustDocIdold UNIQUEIDENTIFIER ;
  82. SELECT @customerId = customerId, @trustDocIdold=trustdocid
  83. FROM customerMaster WITH (NOLOCK)
  84. WHERE username = @userName
  85. IF @flag = 'id-update'
  86. BEGIN
  87. SELECT @customerId = customerId
  88. FROM CUSTOMERMASTER(NOLOCK)
  89. WHERE USERNAME = @username
  90. IF ISNULL(@idFront, '') <> ''
  91. INSERT INTO customerDocumentTmp (
  92. customerId
  93. ,fileName
  94. ,createdBy
  95. ,createdDate
  96. ,documentType
  97. )
  98. SELECT @customerId
  99. ,@idFront
  100. ,@username
  101. ,GETDATE()
  102. ,11394
  103. IF ISNULL(@idBack, '') <> ''
  104. INSERT INTO customerDocumentTmp (
  105. customerId
  106. ,fileName
  107. ,createdBy
  108. ,createdDate
  109. ,documentType
  110. )
  111. SELECT @customerId
  112. ,@idBack
  113. ,@username
  114. ,GETDATE()
  115. ,11395
  116. EXEC proc_errorHandler 0
  117. ,'Document uploaded successfully!'
  118. ,@userName
  119. RETURN
  120. END
  121. ELSE IF @flag = 'update-settings'
  122. BEGIN
  123. IF NOT EXISTS (
  124. SELECT *
  125. FROM customerMaster(NOLOCK)
  126. WHERE USERNAME = @username
  127. )
  128. OR NOT EXISTS (
  129. SELECT *
  130. FROM mobile_userRegistration(NOLOCK)
  131. WHERE USERNAME = @username
  132. )
  133. BEGIN
  134. EXEC proc_errorHandler 1
  135. ,'Invalid customer data!'
  136. ,@userName
  137. RETURN
  138. END
  139. IF @SettingType NOT IN ('FINGER_PRINT_LOGIN')
  140. BEGIN
  141. EXEC proc_errorHandler 2
  142. ,'Invalid data!'
  143. ,@userName
  144. RETURN
  145. END
  146. IF @type NOT IN (
  147. 'True'
  148. ,'False'
  149. )
  150. BEGIN
  151. EXEC proc_errorHandler 2
  152. ,'Invalid data!'
  153. ,@userName
  154. RETURN
  155. END
  156. IF NOT EXISTS (
  157. SELECT *
  158. FROM customerMaster
  159. WHERE customerPassword = dbo.FNAEncryptString(@customerPassword)
  160. AND username = @username
  161. )
  162. BEGIN
  163. EXEC proc_errorHandler 3
  164. ,'Invalid Username/Password.'
  165. ,@userName
  166. RETURN
  167. END
  168. --IF @type = 'True'
  169. --BEGIN
  170. -- IF EXISTS(SELECT TOP 1 * FROM mobile_userRegistration (NOLOCK) WHERE USERNAME = @username AND isbiometricLogin = 1)
  171. -- BEGIN
  172. -- SELECT @errorMsg = @SettingType + ' is already enabled'
  173. -- EXEC proc_errorHandler 1, @errorMsg ,''
  174. -- RETURN
  175. -- END
  176. --END
  177. --IF @type = 'False'
  178. --BEGIN
  179. -- IF EXISTS(SELECT TOP 1 * FROM mobile_userRegistration (NOLOCK) WHERE USERNAME = @username AND isbiometricLogin = 0)
  180. -- BEGIN
  181. -- SELECT @errorMsg = @SettingType + ' is already disabled'
  182. -- EXEC proc_errorHandler 1, @errorMsg ,''
  183. -- RETURN
  184. -- END
  185. --END
  186. UPDATE mr
  187. SET BiometricLoginType = @SettingType
  188. ,IsBiometricLogin = CASE
  189. WHEN @type = 'True'
  190. THEN 1
  191. ELSE 0
  192. END
  193. FROM mobile_userRegistration mr
  194. INNER JOIN customerMaster cm WITH (NOLOCK) ON mr.username = cm.email
  195. WHERE mr.username = @username
  196. UPDATE MobileToken
  197. SET activeStatus = 'N'
  198. WHERE userName = @username
  199. IF @type = 'True'
  200. BEGIN
  201. INSERT INTO MobileToken (
  202. username
  203. ,activeStatus
  204. ,token
  205. ,loginType
  206. ,createdOn
  207. )
  208. SELECT @userName
  209. ,'Y'
  210. ,@token
  211. ,@SettingType
  212. ,GETDATE()
  213. EXEC proc_errorHandler 0
  214. ,'Settings updated successfully!'
  215. ,@token
  216. RETURN
  217. END
  218. EXEC proc_errorHandler 0
  219. ,'Settings updated successfully!'
  220. ,''
  221. RETURN
  222. END
  223. ELSE IF @flag = 'c-pin-pwd'
  224. BEGIN
  225. IF ISNULL(@newPin, 'A') <> ISNULL(@confirmNewPin, 'B')
  226. BEGIN
  227. EXEC proc_errorHandler 1
  228. ,'New pin and Confirm pin are not same!'
  229. ,@userName
  230. RETURN
  231. END
  232. IF ISNULL(@NewPassword, 'A') <> ISNULL(@ConfirmNewPassword, 'B')
  233. BEGIN
  234. EXEC proc_errorHandler 2
  235. ,'New password and Confirm password are not same!'
  236. ,@userName
  237. RETURN
  238. END
  239. IF DBO.FNAencryptstring(@currentPassword) = DBO.FNAencryptstring(@NewPassword)
  240. BEGIN
  241. EXEC proc_errorHandler 6
  242. ,'New Password can not be same as your old password, Please try again!'
  243. ,@userName
  244. RETURN;
  245. END
  246. IF DBO.FNAencryptstring(@currentPin) = DBO.FNAencryptstring(@newPin)
  247. BEGIN
  248. EXEC proc_errorHandler 7
  249. ,'New pin can not be same as your old pin, Please try again!'
  250. ,@userName
  251. RETURN;
  252. END
  253. IF NOT EXISTS (
  254. SELECT 'A'
  255. FROM customerMaster(NOLOCK)
  256. WHERE username = @username
  257. )
  258. BEGIN
  259. EXEC proc_errorHandler 3
  260. ,'Invalid customer found!'
  261. ,@userName
  262. RETURN
  263. END
  264. IF NOT EXISTS (
  265. SELECT 'A'
  266. FROM customerMaster(NOLOCK)
  267. WHERE username = @username
  268. AND txnPin = @currentPin
  269. )
  270. BEGIN
  271. EXEC proc_errorHandler 4
  272. ,'Invalid pin number!'
  273. ,@userName
  274. RETURN
  275. END
  276. IF NOT EXISTS (
  277. SELECT 'A'
  278. FROM customerMaster(NOLOCK)
  279. WHERE username = @username
  280. AND customerPassword = dbo.FNAEncryptString(@currentPassword)
  281. )
  282. BEGIN
  283. EXEC proc_errorHandler 5
  284. ,'Invalid password!'
  285. ,@userName
  286. RETURN
  287. END
  288. UPDATE customerMaster
  289. SET txnPin = @newPin
  290. ,customerPassword = dbo.FNAEncryptString(@NewPassword)
  291. ,isForcedPwdChange = 0
  292. WHERE username = @username
  293. UPDATE mobile_userRegistration
  294. SET isForcePassChange = 0
  295. ,forcePassChangeDate = GETDATE()
  296. ,isForcePinChange = 0
  297. ,ForcePinChangeDate = GETDATE()
  298. WHERE username = @username
  299. EXEC proc_errorHandler 0
  300. ,'You have successfully changed your pin and password'
  301. ,@username
  302. RETURN
  303. END
  304. ELSE IF @flag = 'c-pin'
  305. BEGIN
  306. IF ISNULL(@newPin, 'A') <> ISNULL(@confirmNewPin, 'B')
  307. BEGIN
  308. EXEC proc_errorHandler 1
  309. ,'New pin and Confirm pin are not same!'
  310. ,@userName
  311. RETURN
  312. END
  313. IF EXISTS (
  314. SELECT 'A'
  315. FROM customerMaster(NOLOCK)
  316. WHERE username = @username
  317. AND @currentPin = @newPin
  318. )
  319. BEGIN
  320. EXEC proc_errorHandler 2
  321. ,'Old pin and new pin cannot be same!'
  322. ,@userName
  323. RETURN
  324. END
  325. IF NOT EXISTS (
  326. SELECT 'A'
  327. FROM customerMaster(NOLOCK)
  328. WHERE username = @username
  329. )
  330. BEGIN
  331. EXEC proc_errorHandler 3
  332. ,'Invalid customer found!'
  333. ,@userName
  334. RETURN
  335. END
  336. if @currentPin IS NOT NULL
  337. BEGIN
  338. IF NOT EXISTS (
  339. SELECT 'A'
  340. FROM customerMaster(NOLOCK)
  341. WHERE username = @username
  342. AND txnPin = @currentPin
  343. )
  344. BEGIN
  345. EXEC proc_errorHandler 4
  346. ,'Invalid pin number!'
  347. ,@userName
  348. RETURN
  349. END
  350. UPDATE customerMaster
  351. SET txnPin = @newPin
  352. ,isForcedPwdChange = 0
  353. WHERE username = @username
  354. AND txnPin = @currentPin
  355. UPDATE mobile_userRegistration
  356. SET isForcePinChange = 0
  357. ,ForcePinChangeDate = GETDATE()
  358. WHERE username = @username
  359. END
  360. ELSE
  361. BEGIN
  362. UPDATE customerMaster
  363. SET txnPin = @newPin
  364. ,isForcedPwdChange = 0
  365. WHERE username = @username
  366. AND RegistrationType='EKYC'
  367. UPDATE mobile_userRegistration
  368. SET isForcePinChange = 0
  369. ,ForcePinChangeDate = GETDATE()
  370. ,ekycPinUpdated=1
  371. WHERE username = @username
  372. END
  373. EXEC proc_errorHandler 0
  374. ,'You have successfully changed your pin'
  375. ,@userName
  376. RETURN
  377. END
  378. ELSE IF @flag = 'i'
  379. BEGIN
  380. -- IF @idType IS NULL
  381. -- AND @otherIdType IS NOT NULL /*ANDROID */
  382. -- BEGIN
  383. -- SET @idType = 11402
  384. -- SET @idTypeOther = @otherIdType
  385. -- END
  386. -- ELSE IF @idType IS NOT NULL AND @rType='EKYC'
  387. -- BEGIN
  388. -- IF @idType='FOREIGNER' OR @idType='RESIDENCE'
  389. -- BEGIN
  390. -- SET @idType='11168' --Residence Card
  391. -- END
  392. -- ELSE IF @idType='JAPANESE' OR @idType='RESIDENT' OR @idType='DRIVING_LICENSE' /*EKYC */
  393. -- BEGIN
  394. -- SET @idType='11079' --Driver License
  395. -- END
  396. -- END
  397. -- ELSE IF @idType IS NOT NULL /*IOS */
  398. -- BEGIN
  399. -- IF NOT EXISTS (
  400. -- SELECT *
  401. -- FROM StaticDataValue(NOLOCK)
  402. -- WHERE typeID = 1300
  403. -- AND isActive = 'Y'
  404. -- AND CAST(valueid AS VARCHAR) = @idType
  405. -- )
  406. -- BEGIN
  407. -- IF @idType='FOREIGNER' OR @idType='RESIDENCE' /*EKYC */
  408. -- BEGIN
  409. -- SET @idType='11168' --Residence Card
  410. -- END
  411. -- ELSE IF @idType='JAPANESE' OR @idType='RESIDENT' OR @idType='DRIVING_LICENSE' /*EKYC */
  412. -- BEGIN
  413. -- SET @idType='11079' --Driver License
  414. -- END
  415. -- ELSE
  416. -- BEGIN
  417. -- SET @idTypeOther = @idType
  418. -- SELECT @idType = valueId
  419. -- FROM StaticDataValue(NOLOCK)
  420. -- WHERE typeID = 1300
  421. -- AND isActive = 'Y'
  422. -- AND detailTitle = 'Other ID (Please Specify)'
  423. -- END
  424. -- END
  425. -- END
  426. DECLARE @fcmid VARCHAR(250), @deviceType VARCHAR(100)
  427. PRINT @idType;
  428. IF @occupation IS NULL
  429. AND @otherOccupation IS NOT NULL /*ANDROID */
  430. BEGIN
  431. SET @occupation = 11383
  432. SET @occupationOther = @otherOccupation
  433. END
  434. ELSE IF @occupation IS NOT NULL /*IOS */
  435. BEGIN
  436. IF NOT EXISTS (
  437. SELECT *
  438. FROM StaticDataValue(NOLOCK)
  439. WHERE typeID = 2000
  440. AND isActive = 'Y'
  441. AND CAST(valueid AS VARCHAR) = @occupation
  442. )
  443. BEGIN
  444. SET @occupationOther = @occupation
  445. SELECT @occupation = valueId
  446. FROM StaticDataValue(NOLOCK)
  447. WHERE typeID = 2000
  448. AND isActive = 'Y'
  449. AND detailTitle = 'Other (Please specify)'
  450. END
  451. END
  452. IF EXISTS (
  453. SELECT TOP 1 'A'
  454. FROM customerMaster(NOLOCK)
  455. WHERE username = @userName
  456. )
  457. AND EXISTS (
  458. SELECT TOP 1 'A'
  459. FROM customerMasterTemp(NOLOCK)
  460. WHERE username = @userName
  461. )
  462. BEGIN
  463. EXEC proc_errorHandler 1
  464. ,'Username already taken, please select new username!'
  465. ,@userName
  466. RETURN
  467. END
  468. --DECLARE @mobileWithCode VARCHAR(20)
  469. --SELECT @mobileWithCode = CONCAT('+81',@mobile)
  470. IF EXISTS (
  471. SELECT 'X'
  472. FROM customerMaster WITH (NOLOCK)
  473. WHERE mobile = @mobile
  474. AND ISNULL(onlineUser, 'N') = 'Y'
  475. AND isnull(isDeleted, 'N') = 'N'
  476. AND customerId <> @customerId
  477. )
  478. BEGIN
  479. SELECT @errorMsg = 'Customer with mobile number ' + @mobile + ' already exists.'
  480. --EXEC proc_errorHandler 2, @errorMsg, @customerId --, @mobile
  481. SELECT 2 ErrorCode
  482. ,@errorMsg Msg
  483. ,@customerId Id
  484. ,@mobile Extra
  485. RETURN
  486. END
  487. --alter table customerMasterTemp add documentType varchar(20)
  488. BEGIN TRANSACTION
  489. SELECT @CODE = REFERELCODE
  490. FROM CustomerMasterTemp(NOLOCK)
  491. WHERE email = @username
  492. IF @type IN (
  493. '0'
  494. ,'1'
  495. )
  496. BEGIN
  497. IF EXISTS (
  498. SELECT 'X'
  499. FROM dbo.customerMasterTemp(NOLOCK)
  500. WHERE username = @userName
  501. )
  502. BEGIN
  503. UPDATE dbo.customerMasterTemp
  504. SET occupation = ISNULL(@occupation, occupation)
  505. ,monthlyIncome = ISNULL(@monthlyIncome, monthlyIncome)
  506. ,employeeBusinessType = ISNULL(@businessType, employeeBusinessType)
  507. ,mobile = ISNULL(@mobile, mobile)
  508. --,ADDITIONALADDRESS = ISNULL(@additionalAddress, ADDITIONALADDRESS)
  509. ,idType = ISNULL(@idType, idType)
  510. ,documentType = ISNULL(@additionalIdType, documentType)
  511. ,nameOfEmployeer = ISNULL(@employeerName, nameOfEmployeer)
  512. ,otherIdNumber = @otherIdType
  513. ,occupationOther = @otherOccupation
  514. ,purposeOfRegistration = ISNULL(@purposeOfRegistration, purposeOfRegistration)
  515. ,idNumber = ISNULL(@idTypeNumber, idNumber)
  516. ,idExpiryDate = ISNULL(@idEndDate, idExpiryDate)
  517. ,idIssueDate = ISNULL(@idStartDate, idIssueDate)
  518. ,idIssueCountry=ISNULL(@idIssuingCountry, idIssueCountry)
  519. WHERE username = @userName
  520. INSERT INTO dbo.customerMaster (
  521. fullName
  522. ,firstName
  523. ,middleName
  524. ,lastName1
  525. ,mobile
  526. ,gender
  527. ,dob
  528. ,occupation
  529. ,nativeCountry
  530. ,country
  531. ,bankName
  532. ,bankAccountNo
  533. ,idType
  534. ,idNumber
  535. ,homePhone
  536. ,idIssueDate
  537. ,idExpiryDate
  538. ,verifyDoc1
  539. ,verifyDoc2
  540. ,verifyDoc3
  541. ,SelfieDoc
  542. ,referelCode
  543. ,createdBy
  544. ,createdDate
  545. ,isActive
  546. ,onlineUser
  547. ,customerPassword
  548. ,[address]
  549. ,city
  550. ,state2
  551. ,customerType
  552. ,ADDITIONALADDRESS
  553. ,monthlyIncome
  554. ,organizationType
  555. ,username
  556. ,anotherIdType
  557. ,employeeBusinessType
  558. ,documentType
  559. ,remittanceallowed
  560. ,txnPin
  561. ,nameOfEmployeer
  562. ,isExistingCustomer
  563. ,HasDeclare
  564. ,createdFrom
  565. ,occupationOther
  566. ,purposeOfRegistration
  567. ,email
  568. ,customerEmail
  569. ,otherIdNumber
  570. ,isEmailVerified
  571. ,mobileUser
  572. ,RegistrationType
  573. ,TrustDocId
  574. ,MEMBERSHIPID
  575. ,idIssueCountry
  576. --,postalCode
  577. ,zipCode
  578. ,mobileVerificationType
  579. ,mobileverifieddate
  580. ,mobileverifiedby
  581. ,LawsonCardNo
  582. )
  583. SELECT fullName
  584. ,CMT.firstName
  585. ,CMT.middleName
  586. ,cmt.lastName1
  587. ,mobile
  588. ,gender
  589. ,CASE ISDATE(dob) WHEN 1 THEN dob ELSE '' END
  590. ,CMT.occupation
  591. ,nativeCountry
  592. ,233
  593. ,bankName
  594. ,bankAccountNo
  595. ,idType
  596. ,@idTypeNumber
  597. ,CMT.homePhone
  598. , convert(varchar, @idStartDate, 101)
  599. , convert(varchar, @idEndDate, 101)
  600. ,verifyDoc1
  601. ,verifyDoc2
  602. ,verifyDoc3
  603. ,CMT.selfie
  604. ,CMT.referelCode
  605. ,CMT.createdBy
  606. ,createdDate
  607. ,'Y'
  608. ,'Y'
  609. ,customerPassword
  610. ,[address]
  611. ,city
  612. ,state2
  613. ,4700
  614. ,ADDITIONALADDRESS
  615. ,monthlyIncome
  616. ,organizationType
  617. ,username
  618. ,anotherIdType
  619. ,employeeBusinessType
  620. ,documentType
  621. ,1
  622. ,NULL
  623. ,nameOfEmployeer
  624. ,0
  625. ,0
  626. ,'M'
  627. ,@otherOccupation
  628. ,@purposeOfRegistration
  629. ,email
  630. ,customerEmail
  631. ,@idTypeOther
  632. ,isEmailVerified
  633. ,mobileUser
  634. ,@rType
  635. ,@trustDocId
  636. ,MEMBERSHIPID
  637. ,ISNULL(@idIssuingCountry, idIssueCountry)
  638. --,postalCode
  639. ,zipcode
  640. ,'verified'
  641. ,GETDATE()
  642. ,'system'
  643. ,RegistrationType
  644. FROM dbo.CustomerMasterTemp AS CMT(NOLOCK)
  645. WHERE CMT.username = @userName
  646. SET @cust = @@IDENTITY
  647. UPDATE dbo.mobile_userRegistration
  648. SET customerId = @cust
  649. WHERE username = @userName
  650. DELETE
  651. FROM customerMasterTemp
  652. WHERE username = @userName
  653. END
  654. ELSE
  655. BEGIN
  656. IF EXISTS (
  657. SELECT 'x'
  658. FROM dbo.customerMaster(NOLOCK)
  659. WHERE username = @userName
  660. )
  661. BEGIN
  662. UPDATE dbo.customerMaster
  663. SET occupation = ISNULL(@occupation, occupation)
  664. ,monthlyIncome = ISNULL(@monthlyIncome, monthlyIncome)
  665. ,employeeBusinessType = ISNULL(@businessType, employeeBusinessType)
  666. ,mobile = ISNULL(@mobile, mobile)
  667. ,ADDITIONALADDRESS = ISNULL(@additionalAddress, ADDITIONALADDRESS)
  668. ,idType = ISNULL(@idType, idType)
  669. ,documentType = ISNULL(@additionalIdType, documentType)
  670. ,nameOfEmployeer = ISNULL(@employeerName, nameOfEmployeer)
  671. ,otherIdNumber = @idTypeOther
  672. ,--@otherIdType,
  673. occupationOther = @occupationOther
  674. ,--@otherOccupation
  675. purposeOfRegistration = ISNULL(@purposeOfRegistration, purposeOfRegistration)
  676. --,RegistrationType= @rType
  677. ,TrustDocId= ISNULL(@trustDocId,TrustDocId)
  678. ,idIssueDate= ISNULL(@idStartDate,idIssueDate)
  679. ,IdNumber= ISNULL(@idTypeNumber,IdNumber)
  680. ,idExpiryDate= ISNULL(@idEndDate,idExpiryDate)
  681. ,idIssueCountry= ISNULL(@idIssuingCountry,idIssueCountry)
  682. ,mobileVerificationType =ISNULL(mobileVerificationType,'Verified')
  683. ,mobileverifieddate=ISNULL(mobileverifieddate,GETDATE())
  684. ,mobileverifiedby=ISNULL(mobileverifiedby,'system')
  685. WHERE username = @userName
  686. END
  687. END
  688. END
  689. IF @type = '1' AND ISNULL(@rType,'MANUAL') <> 'EKYC'
  690. BEGIN
  691. IF ISNULL(@idFront, '') <> ''
  692. INSERT INTO customerDocument (
  693. customerId
  694. ,fileName
  695. ,fileDescription
  696. ,createdBy
  697. ,createdDate
  698. ,documentType
  699. ,isOnlineDoc
  700. )
  701. SELECT ISNULL(@customerId, @cust)
  702. ,@idFront
  703. ,'idFrontCustUpload'
  704. ,@userName
  705. ,GETDATE()
  706. ,11394
  707. ,'Y'
  708. IF ISNULL(@idBack, '') <> ''
  709. INSERT INTO customerDocument (
  710. customerId
  711. ,fileName
  712. ,fileDescription
  713. ,createdBy
  714. ,createdDate
  715. ,documentType
  716. ,isOnlineDoc
  717. )
  718. SELECT ISNULL(@customerId, @cust)
  719. ,@idBack
  720. ,'idBackCustUpload'
  721. ,@userName
  722. ,GETDATE()
  723. ,11395
  724. ,'Y'
  725. IF ISNULL(@idSide, '') <> ''
  726. INSERT INTO customerDocument (
  727. customerId
  728. ,fileName
  729. ,fileDescription
  730. ,createdBy
  731. ,createdDate
  732. ,documentType
  733. ,isOnlineDoc
  734. )
  735. SELECT ISNULL(@customerId, @cust)
  736. ,@idSide
  737. ,'idSideCustUpload'
  738. ,@userName
  739. ,GETDATE()
  740. ,11388
  741. ,'Y'
  742. IF ISNULL(@additionalId, '') <> ''
  743. INSERT INTO customerDocument (
  744. customerId
  745. ,fileName
  746. ,fileDescription
  747. ,createdBy
  748. ,createdDate
  749. ,documentType
  750. ,isOnlineDoc
  751. )
  752. SELECT ISNULL(@customerId, @cust)
  753. ,@additionalId
  754. ,'additionalIdCustUpload'
  755. ,@userName
  756. ,GETDATE()
  757. ,11396
  758. ,'Y'
  759. IF ISNULL(@additionalIdBack, '') <> ''
  760. INSERT INTO customerDocument (
  761. customerId
  762. ,fileName
  763. ,fileDescription
  764. ,createdBy
  765. ,createdDate
  766. ,documentType
  767. ,isOnlineDoc
  768. )
  769. SELECT ISNULL(@customerId, @cust)
  770. ,@additionalIdBack
  771. ,'additionalIdBackCustUpload'
  772. ,@userName
  773. ,GETDATE()
  774. ,11397
  775. ,'Y'
  776. IF ISNULL(@facePicture, '') <> ''
  777. INSERT INTO customerDocument (
  778. customerId
  779. ,fileName
  780. ,fileDescription
  781. ,createdBy
  782. ,createdDate
  783. ,documentType
  784. ,isOnlineDoc
  785. )
  786. SELECT ISNULL(@customerId, @cust)
  787. ,@facePicture
  788. ,'SelfieCustUpload' --'facePictureCustUpload'
  789. ,@userName
  790. ,GETDATE()
  791. ,'11440'--11443 --Face Picture
  792. ,'Y'
  793. UPDATE dbo.customerMaster
  794. SET HasDeclare = 1,
  795. --verificationCode='PROCESSING',
  796. modifiedDate=GETDATE()
  797. WHERE customerId = @customerId
  798. END
  799. ELSE IF @type in ('0','1') AND @rType= 'EKYC'
  800. BEGIN
  801. UPDATE dbo.customerMaster
  802. SET HasDeclare = 1
  803. WHERE customerId = @customerId
  804. END
  805. SELECT @fcmid = deviceid
  806. ,@deviceType = deviceType
  807. ,@cust = customerId
  808. FROM mobile_userRegistration
  809. WHERE username = @username
  810. COMMIT TRANSACTION
  811. IF @@TRANCOUNT = 0
  812. BEGIN
  813. print @fcmid
  814. print @deviceType
  815. SELECT 0 AS ERRORCODE
  816. ,'KYC Submitted successfully' AS MSG
  817. ,@userName AS ID
  818. ,@cust AS EXTRA
  819. ,@fcmid AS Extra2
  820. ,@deviceType AS Extra3
  821. RETURN
  822. END
  823. EXEC proc_errorHandler 1
  824. ,'Failed to Submit KYC'
  825. ,@userName
  826. RETURN
  827. END
  828. ELSE IF @flag = 'i-existing'
  829. BEGIN
  830. IF NOT EXISTS (
  831. SELECT TOP 1 'A'
  832. FROM customerMaster(NOLOCK)
  833. WHERE username = @userName
  834. )
  835. BEGIN
  836. EXEC proc_errorHandler 1
  837. ,'Invalid user supplied!'
  838. ,@userName
  839. RETURN
  840. END
  841. --IF EXISTS(SELECT 'X' FROM customerMaster with (nolock)
  842. -- WHERE mobile = @mobile
  843. -- and ISNULL(onlineUser, 'N')='Y'
  844. -- AND isnull(isDeleted,'N')='N'
  845. -- AND customerId <> @customerId)
  846. --BEGIN
  847. -- SELECT @errorMsg = 'Customer with mobile number ' + @mobile + ' already exist.'
  848. -- EXEC proc_errorHandler 1, @errorMsg, @customerId
  849. -- RETURN
  850. --END
  851. IF @idType IS NULL
  852. AND @otherIdType IS NOT NULL /*ANDROID */
  853. BEGIN
  854. SET @idType = 11402
  855. SET @idTypeOther = @otherIdType
  856. END
  857. ELSE IF @idType IS NOT NULL /*IOS */
  858. BEGIN
  859. IF NOT EXISTS (
  860. SELECT *
  861. FROM StaticDataValue(NOLOCK)
  862. WHERE typeID = 1300
  863. AND isActive = 'Y'
  864. AND CAST(valueid AS VARCHAR) = @idType
  865. )
  866. BEGIN
  867. SET @idTypeOther = @idType
  868. SELECT @idType = valueId
  869. FROM StaticDataValue(NOLOCK)
  870. WHERE typeID = 1300
  871. AND isActive = 'Y'
  872. AND detailTitle = 'Other ID (Please Specify)'
  873. END
  874. END
  875. IF @occupation IS NULL
  876. AND @otherOccupation IS NOT NULL /*ANDROID */
  877. BEGIN
  878. SET @occupation = 11383
  879. SET @occupationOther = @otherOccupation
  880. END
  881. ELSE IF @occupation IS NOT NULL /*IOS */
  882. BEGIN
  883. IF NOT EXISTS (
  884. SELECT *
  885. FROM StaticDataValue(NOLOCK)
  886. WHERE typeID = 2000
  887. AND isActive = 'Y'
  888. AND CAST(valueid AS VARCHAR) = @occupation
  889. )
  890. BEGIN
  891. SET @occupationOther = @occupation
  892. SELECT @occupation = valueId
  893. FROM StaticDataValue(NOLOCK)
  894. WHERE typeID = 2000
  895. AND isActive = 'Y'
  896. AND detailTitle = 'Other (Please specify)'
  897. END
  898. END
  899. --alter table customerMasterTemp add documentType varchar(20)
  900. BEGIN TRANSACTION
  901. -- IF @code like 'IC%'
  902. IF @type IN (
  903. '0'
  904. ,'1'
  905. )
  906. BEGIN
  907. SELECT @CODE = REFERELCODE
  908. FROM customerMasterTemp(NOLOCK)
  909. WHERE email = @username
  910. IF EXISTS (
  911. SELECT 'X'
  912. FROM dbo.customerMasterTemp(NOLOCK)
  913. WHERE username = @userName
  914. )
  915. BEGIN
  916. UPDATE dbo.customerMasterTemp
  917. SET occupation = ISNULL(@occupation, occupation)
  918. ,monthlyIncome = ISNULL(@monthlyIncome, monthlyIncome)
  919. ,employeeBusinessType = ISNULL(@businessType, employeeBusinessType)
  920. ,mobile = ISNULL(@mobile, mobile)
  921. ,ADDITIONALADDRESS = ISNULL(@additionalAddress, ADDITIONALADDRESS)
  922. ,idType = ISNULL(@idType, idType)
  923. ,documentType = ISNULL(@additionalIdType, documentType)
  924. ,nameOfEmployeer = ISNULL(@employeerName, nameOfEmployeer)
  925. ,otherIdNumber = @otherIdType
  926. ,occupationOther = @otherOccupation
  927. ,purposeOfRegistration = ISNULL(@purposeOfRegistration, purposeOfRegistration)
  928. ,salaryRange = ISNULL(@monthlyIncome, monthlyIncome)
  929. WHERE username = @userName
  930. INSERT INTO dbo.customerMaster (
  931. fullName
  932. ,firstName
  933. ,mobile
  934. ,gender
  935. ,dob
  936. ,occupation
  937. ,nativeCountry
  938. ,country
  939. ,bankName
  940. ,bankAccountNo
  941. ,idType
  942. ,idNumber
  943. ,homePhone
  944. ,idIssueDate
  945. ,idExpiryDate
  946. ,verifyDoc1
  947. ,verifyDoc2
  948. ,verifyDoc3
  949. ,SelfieDoc
  950. ,referelCode
  951. ,createdBy
  952. ,createdDate
  953. ,isActive
  954. ,onlineUser
  955. ,customerPassword
  956. ,[address]
  957. ,city
  958. ,state2
  959. ,customerType
  960. ,ADDITIONALADDRESS
  961. ,monthlyIncome
  962. ,organizationType
  963. ,username
  964. ,anotherIdType
  965. ,employeeBusinessType
  966. ,documentType
  967. ,remittanceallowed
  968. ,txnPin
  969. ,nameOfEmployeer
  970. ,visaStatus
  971. ,occupationOther
  972. ,purposeOfRegistration
  973. ,mobileUser
  974. ,salaryRange
  975. )
  976. SELECT fullName
  977. ,CMT.firstName
  978. ,mobile
  979. ,gender
  980. ,dob
  981. ,CMT.occupation
  982. ,nativeCountry
  983. ,113
  984. ,bankName
  985. ,bankAccountNo
  986. ,idType
  987. ,idNumber
  988. ,CMT.homePhone
  989. ,CMT.idIssueDate
  990. ,idExpiryDate
  991. ,verifyDoc1
  992. ,verifyDoc2
  993. ,verifyDoc3
  994. ,CMT.selfie
  995. ,CMT.referelCode
  996. ,CMT.createdBy
  997. ,createdDate
  998. ,'Y'
  999. ,'Y'
  1000. ,customerPassword
  1001. ,[address]
  1002. ,city
  1003. ,state2
  1004. ,4700
  1005. ,ADDITIONALADDRESS
  1006. ,monthlyIncome
  1007. ,organizationType
  1008. ,username
  1009. ,anotherIdType
  1010. ,employeeBusinessType
  1011. ,documentType
  1012. ,1
  1013. ,NULL
  1014. ,nameOfEmployeer
  1015. ,visaStatus
  1016. ,@occupationOther
  1017. ,@purposeOfRegistration
  1018. ,mobileUser
  1019. ,monthlyIncome
  1020. FROM dbo.CustomerMasterTemp AS CMT(NOLOCK)
  1021. WHERE CMT.username = @userName
  1022. SET @cust = @@IDENTITY
  1023. UPDATE dbo.mobile_userRegistration
  1024. SET customerId = @cust
  1025. WHERE username = @userName
  1026. DELETE
  1027. FROM customerMasterTemp
  1028. WHERE username = @userName
  1029. IF EXISTS (
  1030. SELECT 'X'
  1031. FROM customerMaster(NOLOCK)
  1032. WHERE membershipId = @code
  1033. )
  1034. BEGIN
  1035. IF EXISTS (
  1036. SELECT 'X'
  1037. FROM dbo.customerMaster(NOLOCK)
  1038. WHERE username = @userName
  1039. )
  1040. BEGIN
  1041. SELECT @customerId = customerId
  1042. FROM CustomerMaster(NOLOCK)
  1043. WHERE email = @username
  1044. END
  1045. SELECT @sourceCustomerId = customerId
  1046. FROM customerMaster(NOLOCK)
  1047. WHERE membershipId = @code
  1048. IF NOT EXISTS (
  1049. SELECT 'X'
  1050. FROM customerMaster(NOLOCK) cm
  1051. LEFT JOIN IntroducerCommissionSetup(NOLOCK) ics ON ics.IntroducerId = cm.customerId
  1052. WHERE ics.IntroducerId = @sourceCustomerId
  1053. )
  1054. BEGIN
  1055. IF NOT EXISTS (
  1056. SELECT 'X'
  1057. FROM Customer_Promotion(NOLOCK)
  1058. WHERE sourceCustomerId = @sourceCustomerId
  1059. AND destinationCustomerId = @customerId
  1060. )
  1061. BEGIN
  1062. SELECT @rewardAmount = ISNULL(detailDesc, 100)
  1063. FROM staticDataValue(NOLOCK)
  1064. WHERE valueId = '11435'
  1065. AND typeId = 8106
  1066. AND isActive = 'Y'
  1067. SELECT @totalDrAmount = SUM(ISNULL(amount, 0))
  1068. FROM Customer_Promotion CP(NOLOCK)
  1069. WHERE sourceCustomerId = @sourceCustomerId
  1070. AND tranType = 'DR'
  1071. AND [status] = 1
  1072. SELECT @totalCrAmount = SUM(ISNULL(amount, 0))
  1073. FROM Customer_Promotion CP(NOLOCK)
  1074. WHERE sourceCustomerId = @sourceCustomerId
  1075. AND tranType = 'CR'
  1076. AND [status] = 1
  1077. SELECT @runningBalance = ISNULL(@totalCrAmount, 0) - ISNULL(@totalDrAmount, 0) + ISNULL(@rewardAmount, 0)
  1078. INSERT INTO Customer_Promotion (
  1079. sourceCustomerId
  1080. ,destinationCustomerId
  1081. ,code
  1082. ,codeType
  1083. ,referenceId
  1084. ,rewardType
  1085. ,amount
  1086. ,createdDate
  1087. ,[status]
  1088. ,approvedDate
  1089. ,tranType
  1090. ,runningBalance
  1091. )
  1092. SELECT @sourceCustomerId
  1093. ,@customerId
  1094. ,@code
  1095. ,'REGISTRATION'
  1096. ,@userName
  1097. ,'REFER_EARN'
  1098. ,@rewardAmount
  1099. ,GETDATE()
  1100. ,0
  1101. ,NULL
  1102. ,'CR'
  1103. ,@runningBalance
  1104. END
  1105. END
  1106. END
  1107. END
  1108. ELSE
  1109. BEGIN
  1110. SELECT @customerId = customerId
  1111. FROM customerMaster WITH (NOLOCK)
  1112. WHERE username = @userName
  1113. SELECT @CODE = REFERELCODE
  1114. FROM customerMaster(NOLOCK)
  1115. WHERE email = @username
  1116. IF EXISTS (
  1117. SELECT 'x'
  1118. FROM dbo.customerMaster(NOLOCK)
  1119. WHERE username = @userName
  1120. )
  1121. BEGIN
  1122. UPDATE dbo.customerMaster
  1123. SET occupation = ISNULL(@occupation, occupation)
  1124. ,monthlyIncome = ISNULL(@monthlyIncome, monthlyIncome)
  1125. ,employeeBusinessType = ISNULL(@businessType, employeeBusinessType)
  1126. ,mobile = ISNULL(@mobile, mobile)
  1127. ,ADDITIONALADDRESS = ISNULL(@additionalAddress, ADDITIONALADDRESS)
  1128. ,idType = ISNULL(@idType, idType)
  1129. ,documentType = ISNULL(@additionalIdType, documentType)
  1130. ,nameOfEmployeer = ISNULL(@employeerName, nameOfEmployeer)
  1131. ,visaStatus = ISNULL(@visaStatus, visaStatus)
  1132. ,otherIdNumber = @otherIdType
  1133. ,occupationOther = @otherOccupation
  1134. ,purposeOfRegistration = ISNULL(@purposeOfRegistration, purposeOfRegistration)
  1135. ,salaryRange = ISNULL(@monthlyIncome, monthlyIncome)
  1136. WHERE username = @userName
  1137. END
  1138. END
  1139. END
  1140. IF @type = '1'
  1141. BEGIN
  1142. IF ISNULL(@idFront, '') <> ''
  1143. INSERT INTO customerDocument (
  1144. customerId
  1145. ,fileName
  1146. ,fileDescription
  1147. ,createdBy
  1148. ,createdDate
  1149. ,documentType
  1150. ,isOnlineDoc
  1151. ,IDType
  1152. )
  1153. SELECT ISNULL(@customerId, @cust)
  1154. ,@idFront
  1155. ,'idFrontCustUpload'
  1156. ,@userName
  1157. ,GETDATE()
  1158. ,11394
  1159. ,'Y'
  1160. ,@idType
  1161. IF ISNULL(@idBack, '') <> ''
  1162. INSERT INTO customerDocument (
  1163. customerId
  1164. ,fileName
  1165. ,fileDescription
  1166. ,createdBy
  1167. ,createdDate
  1168. ,documentType
  1169. ,isOnlineDoc
  1170. ,IDType
  1171. )
  1172. SELECT ISNULL(@customerId, @cust)
  1173. ,@idBack
  1174. ,'idBackCustUpload'
  1175. ,@userName
  1176. ,GETDATE()
  1177. ,11395
  1178. ,'Y'
  1179. ,@idType
  1180. IF ISNULL(@idSide, '') <> ''
  1181. INSERT INTO customerDocument (
  1182. customerId
  1183. ,fileName
  1184. ,fileDescription
  1185. ,createdBy
  1186. ,createdDate
  1187. ,documentType
  1188. ,isOnlineDoc
  1189. )
  1190. SELECT ISNULL(@customerId, @cust)
  1191. ,@idSide
  1192. ,'idSideCustUpload'
  1193. ,@userName
  1194. ,GETDATE()
  1195. ,11388
  1196. ,'Y'
  1197. IF ISNULL(@additionalId, '') <> ''
  1198. INSERT INTO customerDocument (
  1199. customerId
  1200. ,fileName
  1201. ,fileDescription
  1202. ,createdBy
  1203. ,createdDate
  1204. ,documentType
  1205. ,isOnlineDoc
  1206. ,IDType
  1207. )
  1208. SELECT ISNULL(@customerId, @cust)
  1209. ,@additionalId
  1210. ,'additionalIdCustUpload'
  1211. ,@userName
  1212. ,GETDATE()
  1213. ,11396
  1214. ,'Y'
  1215. ,@additionalIdType
  1216. IF ISNULL(@additionalIdBack, '') <> ''
  1217. INSERT INTO customerDocument (
  1218. customerId
  1219. ,fileName
  1220. ,fileDescription
  1221. ,createdBy
  1222. ,createdDate
  1223. ,documentType
  1224. ,isOnlineDoc
  1225. ,IDType
  1226. )
  1227. SELECT ISNULL(@customerId, @cust)
  1228. ,@additionalIdBack
  1229. ,'additionalIdBackCustUpload'
  1230. ,@userName
  1231. ,GETDATE()
  1232. ,11397
  1233. ,'Y'
  1234. ,@additionalIdType
  1235. IF ISNULL(@facePicture, '') <> ''
  1236. INSERT INTO customerDocument (
  1237. customerId
  1238. ,fileName
  1239. ,fileDescription
  1240. ,createdBy
  1241. ,createdDate
  1242. ,documentType
  1243. ,isOnlineDoc
  1244. ,isProfilePic
  1245. )
  1246. SELECT ISNULL(@customerId, @cust)
  1247. ,@facePicture
  1248. ,'SelfieCustUpload'
  1249. ,@userName
  1250. ,GETDATE()
  1251. ,11440 --Face Picture
  1252. ,'Y'
  1253. ,'1'
  1254. UPDATE dbo.customerMaster
  1255. SET HasDeclare = 1
  1256. WHERE customerId = @customerId
  1257. END
  1258. COMMIT TRANSACTION
  1259. IF @@TRANCOUNT = 0
  1260. BEGIN
  1261. SELECT 0 AS ERRORCODE
  1262. ,'KYC Submitted successfully' AS MSG
  1263. ,@userName AS ID
  1264. ,@cust AS EXTRA
  1265. RETURN
  1266. END
  1267. EXEC proc_errorHandler 2
  1268. ,'Failed to Submit KYC'
  1269. ,@userName
  1270. RETURN
  1271. END
  1272. END