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.

96 lines
7.3 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_agentExRateReport] 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. IF EXISTS (SELECT 'x' FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[proc_agentExRateReport]') AND TYPE IN (N'P', N'PC'))
  10. DROP PROCEDURE [dbo].proc_agentExRateReport
  11. GO
  12. */
  13. /*
  14. proc_spExRate @flag = 's', @user = 'admin', @sortBy = 'exRateTreasuryId', @sortOrder = 'ASC', @pageSize = '10', @pageNumber = '1'
  15. */
  16. CREATE proc [dbo].[proc_agentExRateReport]
  17. @flag VARCHAR(50) = NULL
  18. ,@user VARCHAR(30)
  19. ,@branch INT = NULL
  20. ,@agent INT = NULL
  21. ,@country INT = NULL
  22. ,@sortBy VARCHAR(50) = NULL
  23. ,@sortOrder VARCHAR(5) = NULL
  24. ,@pageSize INT = NULL
  25. ,@pageNumber INT = NULL
  26. AS
  27. SET NOCOUNT ON
  28. SET XACT_ABORT ON
  29. BEGIN TRY
  30. IF @flag = 'exRateToday' --Exchange Rate Today
  31. BEGIN
  32. SELECT
  33. pCountryName = pcm.countryName
  34. ,pCountryCode = pcm.countryCode
  35. ,pAgentName = ISNULL(pam.agentName, '[Anywhere]')
  36. ,ert.pCurrency
  37. ,customerRate = ISNULL(ert.crossRateOperation, ert.customerRate) + ISNULL(erbw.premium, ert.premium)
  38. ,lastModifiedDate = COALESCE(erbw.modifiedDate, ert.modifiedDate, ert.createdDate)
  39. FROM exRateTreasury ert WITH(NOLOCK)
  40. LEFT JOIN exRateBranchWise erbw WITH(NOLOCK) ON ert.exRateTreasuryId = erbw.exRateTreasuryId AND erbw.cBranch = @branch AND ISNULL(erbw.isActive, 'N') = 'Y'
  41. INNER JOIN countryMaster pcm WITH(NOLOCK) ON ert.pCountry = pcm.countryId
  42. LEFT JOIN agentMaster pam WITH(NOLOCK) ON ert.pAgent = pam.agentId
  43. WHERE cCountry = @country AND cAgent = @agent AND ISNULL(ert.isActive, 'N') = 'Y'
  44. ORDER BY pCountryName, pAgentName
  45. /*
  46. SELECT
  47. pCountryName = pcm.countryName
  48. ,pCountryCode = pcm.countryCode
  49. ,pAgent
  50. ,pAgentName = ISNULL(pam.agentName, '[All]')
  51. ,ert.pCurrency
  52. ,customerRate = ISNULL(ert.crossRateOperation, ert.customerRate) + ISNULL(erbw.premium, ert.premium)
  53. ,lastModifiedDate = COALESCE(erbw.modifiedDate, ert.modifiedDate, ert.createdDate)
  54. INTO #exRateTemp
  55. FROM exRateTreasury ert WITH(NOLOCK)
  56. LEFT JOIN exRateBranchWise erbw WITH(NOLOCK) ON ert.exRateTreasuryId = erbw.exRateTreasuryId AND erbw.cBranch = @branch
  57. INNER JOIN countryMaster pcm WITH(NOLOCK) ON ert.pCountry = pcm.countryId
  58. LEFT JOIN agentMaster pam WITH(NOLOCK) ON ert.pAgent = pam.agentId
  59. WHERE cCountry = @country AND cAgent = @agent AND ISNULL(ert.isActive, 'N') = 'Y'
  60. ORDER BY pCountryName, pAgentName
  61. SELECT pCountryName, pCountryCode, pAgentId, pAgentName, pCurrency, customerRate, lastModifiedDate FROM
  62. (
  63. SELECT
  64. pCountryName = agentCountry
  65. ,pCountryCode = cm.countryCode
  66. ,pAgentId = agentId
  67. ,pAgentName = agentName
  68. ,pCurrency = ert.pCurrency
  69. ,customerRate = ert.customerRate
  70. ,lastModifiedDate = ert.lastModifiedDate
  71. FROM #exRateTemp ert
  72. INNER JOIN agentMaster am ON ert.pCountryName = am.agentCountry AND ert.pAgent IS NULL AND am.agentType = 2903
  73. INNER JOIN countryMaster cm ON am.agentCountry = cm.countryName
  74. WHERE am.agentId NOT IN (SELECT ISNULL(pAgent, 0) FROM #exRateTemp)
  75. UNION ALL
  76. SELECT * FROM #exRateTemp WHERE pAgent IS NOT NULL
  77. )x ORDER BY pCountryName, pAgentName
  78. */
  79. END
  80. END TRY
  81. BEGIN CATCH
  82. IF @@TRANCOUNT > 0
  83. ROLLBACK TRANSACTION
  84. DECLARE @errorMessage VARCHAR(MAX)
  85. SET @errorMessage = ERROR_MESSAGE()
  86. EXEC proc_errorHandler 1, @errorMessage, NULL
  87. END CATCH
  88. GO