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.

114 lines
9.6 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_intlAgentMigration] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. /*
  9. SELECT * FROM intlAgents
  10. EXEC proc_intlAgentMigration @flag = 'i'
  11. EXEC proc_intlAgentMigration @flag = 'approve'
  12. */
  13. CREATE PROCEDURE [dbo].[proc_intlAgentMigration]
  14. @flag VARCHAR(20) = NULL
  15. AS
  16. DECLARE @result TABLE(errorCode INT, msg VARCHAR(200), id INT)
  17. DECLARE @tempIntlBranchList TABLE(rowId INT IDENTITY(1,1), companyName VARCHAR(255), agentCode VARCHAR(10), agent_branch_code VARCHAR(10), branch VARCHAR(200), country VARCHAR(200),
  18. [address] VARCHAR(255), city VARCHAR(200), telephone VARCHAR(200), fax VARCHAR(200), isHeadOffice VARCHAR(100), contactPerson VARCHAR(200))
  19. IF @flag = 'i'
  20. BEGIN
  21. DECLARE @parentId INT, @agentCountryId INT, @agentType INT, @agentRole CHAR(1), @isSettlingAgent CHAR(1)
  22. DECLARE @rowId INT, @agentName VARCHAR(255), @agentCode VARCHAR(10), @agent_branch_code VARCHAR(10), @branch VARCHAR(200), @country VARCHAR(200),
  23. @agentAddress VARCHAR(255), @agentCity VARCHAR(200), @telephone VARCHAR(200), @fax VARCHAR(200), @isHeadOffice VARCHAR(100), @contactPerson VARCHAR(200)
  24. INSERT INTO @tempIntlBranchList
  25. SELECT * FROM intlAgents
  26. SELECT @agentRole = 'B'
  27. WHILE EXISTS(SELECT 'X' FROM @tempIntlBranchList)
  28. BEGIN
  29. SELECT TOP 1
  30. @rowId = rowId, @agentName = companyName, @agentCode = agentCode, @agent_branch_code = agent_branch_code, @branch = branch, @country = country
  31. ,@agentAddress = [address], @agentCity = city, @telephone = telephone, @fax = fax, @isHeadOffice = isHeadOffice, @contactPerson = contactPerson
  32. FROM @tempIntlBranchList
  33. SELECT @agentCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @country
  34. IF NOT EXISTS(SELECT 'X' FROM agentMaster WITH(NOLOCK) WHERE mapCodeInt = @agentCode)
  35. BEGIN
  36. SELECT @parentId = 4641, @agentType = 2903, @isSettlingAgent = 'Y'
  37. EXEC proc_agentMasterMigration @flag = 'i', @user = 'admin', @agentId = null, @parentId = @parentId, @agentName = @agentName, @agentAddress = @agentAddress
  38. , @agentCity = @agentCity, @agentCountryId = @agentCountryId, @agentCountry = @country, @agentPhone1 = @telephone
  39. , @agentFax1 = @fax
  40. , @agentRole = @agentRole, @agentType = @agentType
  41. , @isSettlingAgent = @isSettlingAgent
  42. , @mapCodeInt = @agentCode
  43. END
  44. SET @agentType = 2904
  45. SET @isSettlingAgent = 'N'
  46. SELECT @parentId = agentId FROM agentMaster WITH(NOLOCK) WHERE mapCodeInt = @agentCode
  47. SELECT @agentName = companyName + ISNULL(' - ' + branch, '') FROM @tempIntlBranchList WHERE rowId = @rowId
  48. EXEC proc_agentMasterMigration @flag = 'i', @user = 'admin', @agentId = null, @parentId = @parentId, @agentName = @agentName, @agentAddress = @agentAddress
  49. , @agentCity = @agentCity, @agentCountryId = @agentCountryId, @agentCountry = @country, @agentPhone1 = @telephone
  50. , @agentFax1 = @fax
  51. , @agentRole = @agentRole, @agentType = @agentType
  52. , @isSettlingAgent = @isSettlingAgent
  53. , @mapCodeInt = @agent_branch_code
  54. DELETE FROM @tempIntlBranchList WHERE rowId = @rowId
  55. SELECT
  56. @agentName = NULL, @agentCode = NULL, @agent_branch_code = NULL, @branch = NULL, @country = NULL
  57. ,@agentAddress = NULL, @agentCity = NULL, @telephone = NULL, @fax = NULL, @isHeadOffice = NULL, @contactPerson = NULL
  58. END
  59. END
  60. ELSE IF @flag = 'approve'
  61. BEGIN
  62. DECLARE @agentIds TABLE(rowId INT IDENTITY(1,1), agentId INT, mapCodeInt VARCHAR(8))
  63. DECLARE @totalRows INT, @count INT, @agentId INT, @mapCodeInt VARCHAR(10)
  64. INSERT @agentIds
  65. SELECT agentId, mapCodeInt FROM agentMaster WHERE approvedBy IS NULL
  66. SELECT @totalRows = COUNT(*) FROM @agentIds
  67. SET @count = 1
  68. WHILE (@count <= @totalRows)
  69. BEGIN
  70. SELECT @agentId = agentId, @mapCodeInt = mapCodeInt FROM @agentIds WHERE rowId = @count
  71. EXEC proc_agentMaster @flag = 'approve', @user = 'imeadmin', @agentId = @agentId
  72. SET @count = @count + 1
  73. END
  74. END
  75. ELSE IF @flag = 'otherInfo'
  76. BEGIN
  77. SELECT * FROM intlAgentsInfo
  78. SELECT * FROM agentContactPerson
  79. UPDATE am SET
  80. am.agentAddress = iai.[address]
  81. ,am.agentPhone1 = iai.phone1
  82. ,am.agentPhone2 = iai.phone2
  83. ,am.agentFax1 = iai.fax
  84. ,am.agentEmail1 = iai.email
  85. ,am.joinedDate = iai.dateofjoin
  86. FROM agentMaster am
  87. INNER JOIN intlAgentsInfo iai ON am.mapCodeInt = iai.agentCode
  88. /*
  89. INSERT INTO agentContactPerson(agentId, name, country, address, phone, mobile1, fax, email, post, isPrimary, createdBy, createdDate)
  90. SELECT am.agentId, iai.contactname1, cm.countryId, am.agentAddress, iai.phone1, iai.phone2, iai.fax, iai.email, iai.post1, 'Y', 'admin', GETDATE()
  91. FROM agentMaster am
  92. INNER JOIN intlAgentsInfo iai ON am.mapCodeInt = iai.agentCode
  93. LEFT JOIN countryMaster cm ON cm.countryName = iai.country
  94. */
  95. END
  96. GO