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.

1391 lines
64 KiB

10 months ago
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: 11/28/2023 12:26:08 PM ******/
  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. PRINT @idType;
  427. IF @occupation IS NULL
  428. AND @otherOccupation IS NOT NULL /*ANDROID */
  429. BEGIN
  430. SET @occupation = 11383
  431. SET @occupationOther = @otherOccupation
  432. END
  433. ELSE IF @occupation IS NOT NULL /*IOS */
  434. BEGIN
  435. IF NOT EXISTS (
  436. SELECT *
  437. FROM StaticDataValue(NOLOCK)
  438. WHERE typeID = 2000
  439. AND isActive = 'Y'
  440. AND CAST(valueid AS VARCHAR) = @occupation
  441. )
  442. BEGIN
  443. SET @occupationOther = @occupation
  444. SELECT @occupation = valueId
  445. FROM StaticDataValue(NOLOCK)
  446. WHERE typeID = 2000
  447. AND isActive = 'Y'
  448. AND detailTitle = 'Other (Please specify)'
  449. END
  450. END
  451. IF EXISTS (
  452. SELECT TOP 1 'A'
  453. FROM customerMaster(NOLOCK)
  454. WHERE username = @userName
  455. )
  456. AND EXISTS (
  457. SELECT TOP 1 'A'
  458. FROM customerMasterTemp(NOLOCK)
  459. WHERE username = @userName
  460. )
  461. BEGIN
  462. EXEC proc_errorHandler 1
  463. ,'Username already taken, please select new username!'
  464. ,@userName
  465. RETURN
  466. END
  467. --DECLARE @mobileWithCode VARCHAR(20)
  468. --SELECT @mobileWithCode = CONCAT('+81',@mobile)
  469. IF EXISTS (
  470. SELECT 'X'
  471. FROM customerMaster WITH (NOLOCK)
  472. WHERE mobile = @mobile
  473. AND ISNULL(onlineUser, 'N') = 'Y'
  474. AND isnull(isDeleted, 'N') = 'N'
  475. AND customerId <> @customerId
  476. )
  477. BEGIN
  478. SELECT @errorMsg = 'Customer with mobile number ' + @mobile + ' already exists.'
  479. --EXEC proc_errorHandler 2, @errorMsg, @customerId --, @mobile
  480. SELECT 2 ErrorCode
  481. ,@errorMsg Msg
  482. ,@customerId Id
  483. ,@mobile Extra
  484. RETURN
  485. END
  486. --alter table customerMasterTemp add documentType varchar(20)
  487. BEGIN TRANSACTION
  488. SELECT @CODE = REFERELCODE
  489. FROM CustomerMasterTemp(NOLOCK)
  490. WHERE email = @username
  491. IF @type IN (
  492. '0'
  493. ,'1'
  494. )
  495. BEGIN
  496. IF EXISTS (
  497. SELECT 'X'
  498. FROM dbo.customerMasterTemp(NOLOCK)
  499. WHERE username = @userName
  500. )
  501. BEGIN
  502. UPDATE dbo.customerMasterTemp
  503. SET occupation = ISNULL(@occupation, occupation)
  504. ,monthlyIncome = ISNULL(@monthlyIncome, monthlyIncome)
  505. ,employeeBusinessType = ISNULL(@businessType, employeeBusinessType)
  506. ,mobile = ISNULL(@mobile, mobile)
  507. --,ADDITIONALADDRESS = ISNULL(@additionalAddress, ADDITIONALADDRESS)
  508. ,idType = ISNULL(@idType, idType)
  509. ,documentType = ISNULL(@additionalIdType, documentType)
  510. ,nameOfEmployeer = ISNULL(@employeerName, nameOfEmployeer)
  511. ,otherIdNumber = @otherIdType
  512. ,occupationOther = @otherOccupation
  513. ,purposeOfRegistration = ISNULL(@purposeOfRegistration, purposeOfRegistration)
  514. ,idNumber = ISNULL(@idTypeNumber, idNumber)
  515. ,idExpiryDate = ISNULL(@idEndDate, idExpiryDate)
  516. ,idIssueDate = ISNULL(@idStartDate, idIssueDate)
  517. ,idIssueCountry=ISNULL(@idIssuingCountry, idIssueCountry)
  518. WHERE username = @userName
  519. INSERT INTO dbo.customerMaster (
  520. fullName
  521. ,firstName
  522. ,middleName
  523. ,lastName1
  524. ,mobile
  525. ,gender
  526. ,dob
  527. ,occupation
  528. ,nativeCountry
  529. ,country
  530. ,bankName
  531. ,bankAccountNo
  532. ,idType
  533. ,idNumber
  534. ,homePhone
  535. ,idIssueDate
  536. ,idExpiryDate
  537. ,verifyDoc1
  538. ,verifyDoc2
  539. ,verifyDoc3
  540. ,SelfieDoc
  541. ,referelCode
  542. ,createdBy
  543. ,createdDate
  544. ,isActive
  545. ,onlineUser
  546. ,customerPassword
  547. ,[address]
  548. ,city
  549. ,state2
  550. ,customerType
  551. ,ADDITIONALADDRESS
  552. ,monthlyIncome
  553. ,organizationType
  554. ,username
  555. ,anotherIdType
  556. ,employeeBusinessType
  557. ,documentType
  558. ,remittanceallowed
  559. ,txnPin
  560. ,nameOfEmployeer
  561. ,isExistingCustomer
  562. ,HasDeclare
  563. ,createdFrom
  564. ,occupationOther
  565. ,purposeOfRegistration
  566. ,email
  567. ,customerEmail
  568. ,otherIdNumber
  569. ,isEmailVerified
  570. ,mobileUser
  571. ,RegistrationType
  572. ,TrustDocId
  573. ,MEMBERSHIPID
  574. ,idIssueCountry
  575. --,postalCode
  576. ,zipCode
  577. ,mobileVerificationType
  578. ,mobileverifieddate
  579. ,mobileverifiedby
  580. ,LawsonCardNo
  581. )
  582. SELECT fullName
  583. ,CMT.firstName
  584. ,CMT.middleName
  585. ,cmt.lastName1
  586. ,mobile
  587. ,gender
  588. ,CASE ISDATE(dob) WHEN 1 THEN dob ELSE '' END
  589. ,CMT.occupation
  590. ,nativeCountry
  591. ,233
  592. ,bankName
  593. ,bankAccountNo
  594. ,idType
  595. ,@idTypeNumber
  596. ,CMT.homePhone
  597. , convert(varchar, @idStartDate, 101)
  598. , convert(varchar, @idEndDate, 101)
  599. ,verifyDoc1
  600. ,verifyDoc2
  601. ,verifyDoc3
  602. ,CMT.selfie
  603. ,CMT.referelCode
  604. ,CMT.createdBy
  605. ,createdDate
  606. ,'Y'
  607. ,'Y'
  608. ,customerPassword
  609. ,[address]
  610. ,city
  611. ,state2
  612. ,4700
  613. ,ADDITIONALADDRESS
  614. ,monthlyIncome
  615. ,organizationType
  616. ,username
  617. ,anotherIdType
  618. ,employeeBusinessType
  619. ,documentType
  620. ,1
  621. ,NULL
  622. ,nameOfEmployeer
  623. ,0
  624. ,0
  625. ,'M'
  626. ,@otherOccupation
  627. ,@purposeOfRegistration
  628. ,email
  629. ,customerEmail
  630. ,@idTypeOther
  631. ,isEmailVerified
  632. ,mobileUser
  633. ,@rType
  634. ,@trustDocId
  635. ,MEMBERSHIPID
  636. ,ISNULL(@idIssuingCountry, idIssueCountry)
  637. --,postalCode
  638. ,zipcode
  639. ,'verified'
  640. ,GETDATE()
  641. ,'system'
  642. ,RegistrationType
  643. FROM dbo.CustomerMasterTemp AS CMT(NOLOCK)
  644. WHERE CMT.username = @userName
  645. SET @cust = @@IDENTITY
  646. UPDATE dbo.mobile_userRegistration
  647. SET customerId = @cust
  648. WHERE username = @userName
  649. DELETE
  650. FROM customerMasterTemp
  651. WHERE username = @userName
  652. END
  653. ELSE
  654. BEGIN
  655. IF EXISTS (
  656. SELECT 'x'
  657. FROM dbo.customerMaster(NOLOCK)
  658. WHERE username = @userName
  659. )
  660. BEGIN
  661. UPDATE dbo.customerMaster
  662. SET occupation = ISNULL(@occupation, occupation)
  663. ,monthlyIncome = ISNULL(@monthlyIncome, monthlyIncome)
  664. ,employeeBusinessType = ISNULL(@businessType, employeeBusinessType)
  665. ,mobile = ISNULL(@mobile, mobile)
  666. ,ADDITIONALADDRESS = ISNULL(@additionalAddress, ADDITIONALADDRESS)
  667. ,idType = ISNULL(@idType, idType)
  668. ,documentType = ISNULL(@additionalIdType, documentType)
  669. ,nameOfEmployeer = ISNULL(@employeerName, nameOfEmployeer)
  670. ,otherIdNumber = @idTypeOther
  671. ,--@otherIdType,
  672. occupationOther = @occupationOther
  673. ,--@otherOccupation
  674. purposeOfRegistration = ISNULL(@purposeOfRegistration, purposeOfRegistration)
  675. --,RegistrationType= @rType
  676. ,TrustDocId= ISNULL(@trustDocId,TrustDocId)
  677. ,idIssueDate= ISNULL(@idStartDate,idIssueDate)
  678. ,IdNumber= ISNULL(@idTypeNumber,IdNumber)
  679. ,idExpiryDate= ISNULL(@idEndDate,idExpiryDate)
  680. ,idIssueCountry= ISNULL(@idIssuingCountry,idIssueCountry)
  681. ,mobileVerificationType =ISNULL(mobileVerificationType,'Verified')
  682. ,mobileverifieddate=ISNULL(mobileverifieddate,GETDATE())
  683. ,mobileverifiedby=ISNULL(mobileverifiedby,'system')
  684. WHERE username = @userName
  685. END
  686. END
  687. END
  688. IF @type = '1' AND ISNULL(@rType,'MANUAL') <> 'EKYC'
  689. BEGIN
  690. IF ISNULL(@idFront, '') <> ''
  691. INSERT INTO customerDocument (
  692. customerId
  693. ,fileName
  694. ,fileDescription
  695. ,createdBy
  696. ,createdDate
  697. ,documentType
  698. ,isOnlineDoc
  699. )
  700. SELECT ISNULL(@customerId, @cust)
  701. ,@idFront
  702. ,'idFrontCustUpload'
  703. ,@userName
  704. ,GETDATE()
  705. ,11394
  706. ,'Y'
  707. IF ISNULL(@idBack, '') <> ''
  708. INSERT INTO customerDocument (
  709. customerId
  710. ,fileName
  711. ,fileDescription
  712. ,createdBy
  713. ,createdDate
  714. ,documentType
  715. ,isOnlineDoc
  716. )
  717. SELECT ISNULL(@customerId, @cust)
  718. ,@idBack
  719. ,'idBackCustUpload'
  720. ,@userName
  721. ,GETDATE()
  722. ,11395
  723. ,'Y'
  724. IF ISNULL(@idSide, '') <> ''
  725. INSERT INTO customerDocument (
  726. customerId
  727. ,fileName
  728. ,fileDescription
  729. ,createdBy
  730. ,createdDate
  731. ,documentType
  732. ,isOnlineDoc
  733. )
  734. SELECT ISNULL(@customerId, @cust)
  735. ,@idSide
  736. ,'idSideCustUpload'
  737. ,@userName
  738. ,GETDATE()
  739. ,11388
  740. ,'Y'
  741. IF ISNULL(@additionalId, '') <> ''
  742. INSERT INTO customerDocument (
  743. customerId
  744. ,fileName
  745. ,fileDescription
  746. ,createdBy
  747. ,createdDate
  748. ,documentType
  749. ,isOnlineDoc
  750. )
  751. SELECT ISNULL(@customerId, @cust)
  752. ,@additionalId
  753. ,'additionalIdCustUpload'
  754. ,@userName
  755. ,GETDATE()
  756. ,11396
  757. ,'Y'
  758. IF ISNULL(@additionalIdBack, '') <> ''
  759. INSERT INTO customerDocument (
  760. customerId
  761. ,fileName
  762. ,fileDescription
  763. ,createdBy
  764. ,createdDate
  765. ,documentType
  766. ,isOnlineDoc
  767. )
  768. SELECT ISNULL(@customerId, @cust)
  769. ,@additionalIdBack
  770. ,'additionalIdBackCustUpload'
  771. ,@userName
  772. ,GETDATE()
  773. ,11397
  774. ,'Y'
  775. IF ISNULL(@facePicture, '') <> ''
  776. INSERT INTO customerDocument (
  777. customerId
  778. ,fileName
  779. ,fileDescription
  780. ,createdBy
  781. ,createdDate
  782. ,documentType
  783. ,isOnlineDoc
  784. )
  785. SELECT ISNULL(@customerId, @cust)
  786. ,@facePicture
  787. ,'SelfieCustUpload' --'facePictureCustUpload'
  788. ,@userName
  789. ,GETDATE()
  790. ,'11440'--11443 --Face Picture
  791. ,'Y'
  792. UPDATE dbo.customerMaster
  793. SET HasDeclare = 1,
  794. --verificationCode='PROCESSING',
  795. modifiedDate=GETDATE()
  796. WHERE customerId = @customerId
  797. END
  798. ELSE IF @type in ('0','1') AND @rType= 'EKYC'
  799. BEGIN
  800. UPDATE dbo.customerMaster
  801. SET HasDeclare = 1
  802. WHERE customerId = @customerId
  803. END
  804. COMMIT TRANSACTION
  805. IF @@TRANCOUNT = 0
  806. BEGIN
  807. SELECT 0 AS ERRORCODE
  808. ,'KYC Submitted successfully' AS MSG
  809. ,@userName AS ID
  810. ,@cust AS EXTRA
  811. RETURN
  812. END
  813. EXEC proc_errorHandler 1
  814. ,'Failed to Submit KYC'
  815. ,@userName
  816. RETURN
  817. END
  818. ELSE IF @flag = 'i-existing'
  819. BEGIN
  820. IF NOT EXISTS (
  821. SELECT TOP 1 'A'
  822. FROM customerMaster(NOLOCK)
  823. WHERE username = @userName
  824. )
  825. BEGIN
  826. EXEC proc_errorHandler 1
  827. ,'Invalid user supplied!'
  828. ,@userName
  829. RETURN
  830. END
  831. --IF EXISTS(SELECT 'X' FROM customerMaster with (nolock)
  832. -- WHERE mobile = @mobile
  833. -- and ISNULL(onlineUser, 'N')='Y'
  834. -- AND isnull(isDeleted,'N')='N'
  835. -- AND customerId <> @customerId)
  836. --BEGIN
  837. -- SELECT @errorMsg = 'Customer with mobile number ' + @mobile + ' already exist.'
  838. -- EXEC proc_errorHandler 1, @errorMsg, @customerId
  839. -- RETURN
  840. --END
  841. IF @idType IS NULL
  842. AND @otherIdType IS NOT NULL /*ANDROID */
  843. BEGIN
  844. SET @idType = 11402
  845. SET @idTypeOther = @otherIdType
  846. END
  847. ELSE IF @idType IS NOT NULL /*IOS */
  848. BEGIN
  849. IF NOT EXISTS (
  850. SELECT *
  851. FROM StaticDataValue(NOLOCK)
  852. WHERE typeID = 1300
  853. AND isActive = 'Y'
  854. AND CAST(valueid AS VARCHAR) = @idType
  855. )
  856. BEGIN
  857. SET @idTypeOther = @idType
  858. SELECT @idType = valueId
  859. FROM StaticDataValue(NOLOCK)
  860. WHERE typeID = 1300
  861. AND isActive = 'Y'
  862. AND detailTitle = 'Other ID (Please Specify)'
  863. END
  864. END
  865. IF @occupation IS NULL
  866. AND @otherOccupation IS NOT NULL /*ANDROID */
  867. BEGIN
  868. SET @occupation = 11383
  869. SET @occupationOther = @otherOccupation
  870. END
  871. ELSE IF @occupation IS NOT NULL /*IOS */
  872. BEGIN
  873. IF NOT EXISTS (
  874. SELECT *
  875. FROM StaticDataValue(NOLOCK)
  876. WHERE typeID = 2000
  877. AND isActive = 'Y'
  878. AND CAST(valueid AS VARCHAR) = @occupation
  879. )
  880. BEGIN
  881. SET @occupationOther = @occupation
  882. SELECT @occupation = valueId
  883. FROM StaticDataValue(NOLOCK)
  884. WHERE typeID = 2000
  885. AND isActive = 'Y'
  886. AND detailTitle = 'Other (Please specify)'
  887. END
  888. END
  889. --alter table customerMasterTemp add documentType varchar(20)
  890. BEGIN TRANSACTION
  891. -- IF @code like 'IC%'
  892. IF @type IN (
  893. '0'
  894. ,'1'
  895. )
  896. BEGIN
  897. SELECT @CODE = REFERELCODE
  898. FROM customerMasterTemp(NOLOCK)
  899. WHERE email = @username
  900. IF EXISTS (
  901. SELECT 'X'
  902. FROM dbo.customerMasterTemp(NOLOCK)
  903. WHERE username = @userName
  904. )
  905. BEGIN
  906. UPDATE dbo.customerMasterTemp
  907. SET occupation = ISNULL(@occupation, occupation)
  908. ,monthlyIncome = ISNULL(@monthlyIncome, monthlyIncome)
  909. ,employeeBusinessType = ISNULL(@businessType, employeeBusinessType)
  910. ,mobile = ISNULL(@mobile, mobile)
  911. ,ADDITIONALADDRESS = ISNULL(@additionalAddress, ADDITIONALADDRESS)
  912. ,idType = ISNULL(@idType, idType)
  913. ,documentType = ISNULL(@additionalIdType, documentType)
  914. ,nameOfEmployeer = ISNULL(@employeerName, nameOfEmployeer)
  915. ,otherIdNumber = @otherIdType
  916. ,occupationOther = @otherOccupation
  917. ,purposeOfRegistration = ISNULL(@purposeOfRegistration, purposeOfRegistration)
  918. ,salaryRange = ISNULL(@monthlyIncome, monthlyIncome)
  919. WHERE username = @userName
  920. INSERT INTO dbo.customerMaster (
  921. fullName
  922. ,firstName
  923. ,mobile
  924. ,gender
  925. ,dob
  926. ,occupation
  927. ,nativeCountry
  928. ,country
  929. ,bankName
  930. ,bankAccountNo
  931. ,idType
  932. ,idNumber
  933. ,homePhone
  934. ,idIssueDate
  935. ,idExpiryDate
  936. ,verifyDoc1
  937. ,verifyDoc2
  938. ,verifyDoc3
  939. ,SelfieDoc
  940. ,referelCode
  941. ,createdBy
  942. ,createdDate
  943. ,isActive
  944. ,onlineUser
  945. ,customerPassword
  946. ,[address]
  947. ,city
  948. ,state2
  949. ,customerType
  950. ,ADDITIONALADDRESS
  951. ,monthlyIncome
  952. ,organizationType
  953. ,username
  954. ,anotherIdType
  955. ,employeeBusinessType
  956. ,documentType
  957. ,remittanceallowed
  958. ,txnPin
  959. ,nameOfEmployeer
  960. ,visaStatus
  961. ,occupationOther
  962. ,purposeOfRegistration
  963. ,mobileUser
  964. ,salaryRange
  965. )
  966. SELECT fullName
  967. ,CMT.firstName
  968. ,mobile
  969. ,gender
  970. ,dob
  971. ,CMT.occupation
  972. ,nativeCountry
  973. ,113
  974. ,bankName
  975. ,bankAccountNo
  976. ,idType
  977. ,idNumber
  978. ,CMT.homePhone
  979. ,CMT.idIssueDate
  980. ,idExpiryDate
  981. ,verifyDoc1
  982. ,verifyDoc2
  983. ,verifyDoc3
  984. ,CMT.selfie
  985. ,CMT.referelCode
  986. ,CMT.createdBy
  987. ,createdDate
  988. ,'Y'
  989. ,'Y'
  990. ,customerPassword
  991. ,[address]
  992. ,city
  993. ,state2
  994. ,4700
  995. ,ADDITIONALADDRESS
  996. ,monthlyIncome
  997. ,organizationType
  998. ,username
  999. ,anotherIdType
  1000. ,employeeBusinessType
  1001. ,documentType
  1002. ,1
  1003. ,NULL
  1004. ,nameOfEmployeer
  1005. ,visaStatus
  1006. ,@occupationOther
  1007. ,@purposeOfRegistration
  1008. ,mobileUser
  1009. ,monthlyIncome
  1010. FROM dbo.CustomerMasterTemp AS CMT(NOLOCK)
  1011. WHERE CMT.username = @userName
  1012. SET @cust = @@IDENTITY
  1013. UPDATE dbo.mobile_userRegistration
  1014. SET customerId = @cust
  1015. WHERE username = @userName
  1016. DELETE
  1017. FROM customerMasterTemp
  1018. WHERE username = @userName
  1019. IF EXISTS (
  1020. SELECT 'X'
  1021. FROM customerMaster(NOLOCK)
  1022. WHERE membershipId = @code
  1023. )
  1024. BEGIN
  1025. IF EXISTS (
  1026. SELECT 'X'
  1027. FROM dbo.customerMaster(NOLOCK)
  1028. WHERE username = @userName
  1029. )
  1030. BEGIN
  1031. SELECT @customerId = customerId
  1032. FROM CustomerMaster(NOLOCK)
  1033. WHERE email = @username
  1034. END
  1035. SELECT @sourceCustomerId = customerId
  1036. FROM customerMaster(NOLOCK)
  1037. WHERE membershipId = @code
  1038. IF NOT EXISTS (
  1039. SELECT 'X'
  1040. FROM customerMaster(NOLOCK) cm
  1041. LEFT JOIN IntroducerCommissionSetup(NOLOCK) ics ON ics.IntroducerId = cm.customerId
  1042. WHERE ics.IntroducerId = @sourceCustomerId
  1043. )
  1044. BEGIN
  1045. IF NOT EXISTS (
  1046. SELECT 'X'
  1047. FROM Customer_Promotion(NOLOCK)
  1048. WHERE sourceCustomerId = @sourceCustomerId
  1049. AND destinationCustomerId = @customerId
  1050. )
  1051. BEGIN
  1052. SELECT @rewardAmount = ISNULL(detailDesc, 100)
  1053. FROM staticDataValue(NOLOCK)
  1054. WHERE valueId = '11435'
  1055. AND typeId = 8106
  1056. AND isActive = 'Y'
  1057. SELECT @totalDrAmount = SUM(ISNULL(amount, 0))
  1058. FROM Customer_Promotion CP(NOLOCK)
  1059. WHERE sourceCustomerId = @sourceCustomerId
  1060. AND tranType = 'DR'
  1061. AND [status] = 1
  1062. SELECT @totalCrAmount = SUM(ISNULL(amount, 0))
  1063. FROM Customer_Promotion CP(NOLOCK)
  1064. WHERE sourceCustomerId = @sourceCustomerId
  1065. AND tranType = 'CR'
  1066. AND [status] = 1
  1067. SELECT @runningBalance = ISNULL(@totalCrAmount, 0) - ISNULL(@totalDrAmount, 0) + ISNULL(@rewardAmount, 0)
  1068. INSERT INTO Customer_Promotion (
  1069. sourceCustomerId
  1070. ,destinationCustomerId
  1071. ,code
  1072. ,codeType
  1073. ,referenceId
  1074. ,rewardType
  1075. ,amount
  1076. ,createdDate
  1077. ,[status]
  1078. ,approvedDate
  1079. ,tranType
  1080. ,runningBalance
  1081. )
  1082. SELECT @sourceCustomerId
  1083. ,@customerId
  1084. ,@code
  1085. ,'REGISTRATION'
  1086. ,@userName
  1087. ,'REFER_EARN'
  1088. ,@rewardAmount
  1089. ,GETDATE()
  1090. ,0
  1091. ,NULL
  1092. ,'CR'
  1093. ,@runningBalance
  1094. END
  1095. END
  1096. END
  1097. END
  1098. ELSE
  1099. BEGIN
  1100. SELECT @customerId = customerId
  1101. FROM customerMaster WITH (NOLOCK)
  1102. WHERE username = @userName
  1103. SELECT @CODE = REFERELCODE
  1104. FROM customerMaster(NOLOCK)
  1105. WHERE email = @username
  1106. IF EXISTS (
  1107. SELECT 'x'
  1108. FROM dbo.customerMaster(NOLOCK)
  1109. WHERE username = @userName
  1110. )
  1111. BEGIN
  1112. UPDATE dbo.customerMaster
  1113. SET occupation = ISNULL(@occupation, occupation)
  1114. ,monthlyIncome = ISNULL(@monthlyIncome, monthlyIncome)
  1115. ,employeeBusinessType = ISNULL(@businessType, employeeBusinessType)
  1116. ,mobile = ISNULL(@mobile, mobile)
  1117. ,ADDITIONALADDRESS = ISNULL(@additionalAddress, ADDITIONALADDRESS)
  1118. ,idType = ISNULL(@idType, idType)
  1119. ,documentType = ISNULL(@additionalIdType, documentType)
  1120. ,nameOfEmployeer = ISNULL(@employeerName, nameOfEmployeer)
  1121. ,visaStatus = ISNULL(@visaStatus, visaStatus)
  1122. ,otherIdNumber = @otherIdType
  1123. ,occupationOther = @otherOccupation
  1124. ,purposeOfRegistration = ISNULL(@purposeOfRegistration, purposeOfRegistration)
  1125. ,salaryRange = ISNULL(@monthlyIncome, monthlyIncome)
  1126. WHERE username = @userName
  1127. END
  1128. END
  1129. END
  1130. IF @type = '1'
  1131. BEGIN
  1132. IF ISNULL(@idFront, '') <> ''
  1133. INSERT INTO customerDocument (
  1134. customerId
  1135. ,fileName
  1136. ,fileDescription
  1137. ,createdBy
  1138. ,createdDate
  1139. ,documentType
  1140. ,isOnlineDoc
  1141. ,IDType
  1142. )
  1143. SELECT ISNULL(@customerId, @cust)
  1144. ,@idFront
  1145. ,'idFrontCustUpload'
  1146. ,@userName
  1147. ,GETDATE()
  1148. ,11394
  1149. ,'Y'
  1150. ,@idType
  1151. IF ISNULL(@idBack, '') <> ''
  1152. INSERT INTO customerDocument (
  1153. customerId
  1154. ,fileName
  1155. ,fileDescription
  1156. ,createdBy
  1157. ,createdDate
  1158. ,documentType
  1159. ,isOnlineDoc
  1160. ,IDType
  1161. )
  1162. SELECT ISNULL(@customerId, @cust)
  1163. ,@idBack
  1164. ,'idBackCustUpload'
  1165. ,@userName
  1166. ,GETDATE()
  1167. ,11395
  1168. ,'Y'
  1169. ,@idType
  1170. IF ISNULL(@idSide, '') <> ''
  1171. INSERT INTO customerDocument (
  1172. customerId
  1173. ,fileName
  1174. ,fileDescription
  1175. ,createdBy
  1176. ,createdDate
  1177. ,documentType
  1178. ,isOnlineDoc
  1179. )
  1180. SELECT ISNULL(@customerId, @cust)
  1181. ,@idSide
  1182. ,'idSideCustUpload'
  1183. ,@userName
  1184. ,GETDATE()
  1185. ,11388
  1186. ,'Y'
  1187. IF ISNULL(@additionalId, '') <> ''
  1188. INSERT INTO customerDocument (
  1189. customerId
  1190. ,fileName
  1191. ,fileDescription
  1192. ,createdBy
  1193. ,createdDate
  1194. ,documentType
  1195. ,isOnlineDoc
  1196. ,IDType
  1197. )
  1198. SELECT ISNULL(@customerId, @cust)
  1199. ,@additionalId
  1200. ,'additionalIdCustUpload'
  1201. ,@userName
  1202. ,GETDATE()
  1203. ,11396
  1204. ,'Y'
  1205. ,@additionalIdType
  1206. IF ISNULL(@additionalIdBack, '') <> ''
  1207. INSERT INTO customerDocument (
  1208. customerId
  1209. ,fileName
  1210. ,fileDescription
  1211. ,createdBy
  1212. ,createdDate
  1213. ,documentType
  1214. ,isOnlineDoc
  1215. ,IDType
  1216. )
  1217. SELECT ISNULL(@customerId, @cust)
  1218. ,@additionalIdBack
  1219. ,'additionalIdBackCustUpload'
  1220. ,@userName
  1221. ,GETDATE()
  1222. ,11397
  1223. ,'Y'
  1224. ,@additionalIdType
  1225. IF ISNULL(@facePicture, '') <> ''
  1226. INSERT INTO customerDocument (
  1227. customerId
  1228. ,fileName
  1229. ,fileDescription
  1230. ,createdBy
  1231. ,createdDate
  1232. ,documentType
  1233. ,isOnlineDoc
  1234. ,isProfilePic
  1235. )
  1236. SELECT ISNULL(@customerId, @cust)
  1237. ,@facePicture
  1238. ,'SelfieCustUpload'
  1239. ,@userName
  1240. ,GETDATE()
  1241. ,11440 --Face Picture
  1242. ,'Y'
  1243. ,'1'
  1244. UPDATE dbo.customerMaster
  1245. SET HasDeclare = 1
  1246. WHERE customerId = @customerId
  1247. END
  1248. COMMIT TRANSACTION
  1249. IF @@TRANCOUNT = 0
  1250. BEGIN
  1251. SELECT 0 AS ERRORCODE
  1252. ,'KYC Submitted successfully' AS MSG
  1253. ,@userName AS ID
  1254. ,@cust AS EXTRA
  1255. RETURN
  1256. END
  1257. EXEC proc_errorHandler 2
  1258. ,'Failed to Submit KYC'
  1259. ,@userName
  1260. RETURN
  1261. END
  1262. END