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.

142 lines
10 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_domesticTransactionReport] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE proc [dbo].[proc_domesticTransactionReport]
  9. @user VARCHAR(30),
  10. @fromDate VARCHAR(50),
  11. @toDate VARCHAR(50),
  12. @flag Varchar(50),
  13. @agent VARCHAR(10) = NULL,
  14. @rptType CHAR(1) = NULL,
  15. @dateType CHAR(1) = NULL
  16. AS
  17. SET NOCOUNT ON
  18. SET @toDate = @toDate +' 23:59:59'
  19. DECLARE @sql varchar(MAX),@rptDateType varchar(MAX)
  20. IF @flag = 'TXNR' -- TRANSACTION REPORT
  21. BEGIN
  22. SET @rptDateType = CASE WHEN @dateType = 'S' THEN 'rt.createdDate'
  23. WHEN @dateType = 'P' THEN 'rt.paidDate'
  24. WHEN @dateType = 'C' THEN 'rt.cancelApprovedDate'
  25. END
  26. IF @rptType = 'D'
  27. BEGIN
  28. SET @sql ='SELECT
  29. [Date] = CONVERT(VARCHAR,'+@rptDateType+' ,101)
  30. ,[Txn Count] = ''<a href = "Reports.aspx?reportName=domtxndetail&reportType='+@rptType+'&dateType='+@dateType+'&fromDate=''+CONVERT(VARCHAR,'+@rptDateType+' ,101)+''&toDate=''+CONVERT(VARCHAR,'+@rptDateType+' ,101)+''">''+cast(count(*)as varchar)+''</a>''
  31. ,[Txn Amount] =SUM(tAmt)
  32. FROM remitTran rt WITH(NOLOCK)
  33. WHERE '+@rptDateType+' BETWEEN '''+ @FROMDATE +''' AND '''+ @TODATE +'''
  34. AND rt.tranType =''D''
  35. GROUP BY CONVERT(VARCHAR,'+@rptDateType+' ,101)'
  36. END
  37. IF @rptType = 'S'
  38. BEGIN
  39. SET @sql ='SELECT
  40. [Sending Agent] = am.agentName
  41. ,[Txn Count] = ''<a href = "Reports.aspx?reportName=domtxndetail&reportType='+@rptType+'&dateType='+@dateType+'&fromDate='+@fromDate+'&toDate='+LEFT(@toDate ,10)+'&agent=''+cast(rt.sAgent as varchar)+''">''+cast(count(*)as varchar)+''</a>''
  42. ,[Txn Amount] =SUM(tAmt)
  43. FROM remitTran rt WITH(NOLOCK)
  44. LEFT JOIN agentMaster am WITH(NOLOCK) ON AM.agentId = rt.sAgent
  45. WHERE '+@rptDateType+' BETWEEN '''+ @FROMDATE +''' AND '''+ @TODATE +'''
  46. AND rt.tranType =''D''
  47. GROUP BY rt.sAgent, am.agentName'
  48. END
  49. IF @rptType = 'R'
  50. BEGIN
  51. SET @sql ='SELECT
  52. [Reciving Agent] = am.agentName
  53. ,[Txn Count] = ''<a href = "Reports.aspx?reportName=domtxndetail&reportType='+@rptType+'&dateType='+@dateType+'&fromDate='+@fromDate+'&toDate='+LEFT(@toDate ,10)+'&agent=''+cast(rt.pAgent as varchar)+''">''+cast(count(*)as varchar)+''</a>''
  54. ,[Txn Amount] =SUM(tAmt)
  55. FROM remitTran rt WITH(NOLOCK)
  56. LEFT JOIN agentMaster am WITH(NOLOCK) ON AM.agentId = rt.pAgent
  57. WHERE '+@rptDateType+' BETWEEN '''+ @FROMDATE +''' AND '''+ @TODATE +'''
  58. AND rt.tranType =''D''
  59. GROUP BY rt.pAgent, am.agentName'
  60. END
  61. PRINT @sql
  62. EXEC(@sql)
  63. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  64. SELECT 'Date Range' head, 'From '+CONVERT(VARCHAR,@fromDate,101)+' To '+CONVERT(VARCHAR,@toDate,101) value
  65. UNION all
  66. SELECT 'Report Type' head, value = CASE WHEN @dateType ='D' THEN 'Date Wise' WHEN @dateType = 'S' THEN 'Sending Agent Wise' WHEN @dateType = 'P' THEN 'Receiving Agent Wise' END
  67. UNION all
  68. SELECT 'Date Type' head, value = CASE WHEN @dateType ='s' THEN 'Send Date' WHEN @dateType = 'P' THEN 'Paid Date' WHEN @dateType = 'C' THEN 'Cancel Date' END
  69. SELECT 'Domestic TRANSACTION REPORT' title
  70. END
  71. else if @flag = 'TXNDetail' -- TRANSACTION REPORT
  72. BEGIN
  73. if @agent=0
  74. set @agent=null
  75. select createdDate, dbo.FNADecryptString(controlNo)controlNo,cAmt, sAgentName, pAgentName,pAmt, senderName, receiverName
  76. from remitTran r with (nolock)
  77. where r.createdDate between @fromDate AND @toDate
  78. and r.tranType ='D'
  79. AND (sAgent= ISNULL(@agent,sAgent) OR ISNULL(pAgent,0)= ISNULL(@agent,ISNULL(pAgent,0)))
  80. END
  81. ELSE IF @flag = 'domtxndetail'
  82. BEGIN
  83. SET @rptDateType = CASE WHEN @dateType = 'S' THEN 'r.createdDate'
  84. WHEN @dateType = 'P' THEN 'r.paidDate'
  85. WHEN @dateType = 'C' THEN 'r.cancelApprovedDate'
  86. END
  87. IF @agent=0
  88. SET @agent=null
  89. SET @sql = 'SELECT Date = CONVERT(VARCHAR,'+@rptDateType+' ,101)
  90. ,[Control No.] = dbo.FNADecryptString(controlNo)
  91. ,[Sending Agent] = sAgentName
  92. ,[Collection Amount] = cAmt
  93. ,[Payout Agent] = pAgentName
  94. ,[Payout Amount] = pAmt
  95. ,[Sender Name] = senderName
  96. ,[Receiver Name] = receiverName
  97. FROM remitTran r WITH (NOLOCK)
  98. WHERE '+@rptDateType+' BETWEEN '''+ @fromDate +''' AND '''+ @toDate +''' AND r.tranType =''D'''
  99. IF @rptType = 'S'
  100. SET @sql = @sql +' AND sAgent='''+@agent+''''
  101. IF @rptType = 'R'
  102. SET @sql = @sql +' AND pAgent='''+@agent+''''
  103. print @sql
  104. EXEC(@sql)
  105. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  106. SELECT 'Date Range' head, 'From '+CONVERT(VARCHAR,@fromDate,101)+' To '+CONVERT(VARCHAR,@toDate,101) value
  107. UNION all
  108. SELECT 'Report Type' head, value = CASE WHEN @dateType ='D' THEN 'Date Wise' WHEN @dateType = 'S' THEN 'Sending Agent Wise' WHEN @dateType = 'P' THEN 'Receiving Agent Wise' END
  109. UNION all
  110. SELECT 'Date Type' head, value = CASE WHEN @dateType ='s' THEN 'Send Date' WHEN @dateType = 'P' THEN 'Paid Date' WHEN @dateType = 'C' THEN 'Cancel Date' END
  111. SELECT 'DOMESTIC TRANSACTION REPORT -DETAIL' title
  112. END
  113. GO