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.

167 lines
11 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_commissionReport] 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. EXEC proc_commissionReport
  10. @flag = 'srpt'
  11. ,@user = 'bharat'
  12. ,@fromDate = '2012-1-3'
  13. ,@toDate = '2012-5-30'
  14. ,@AgentId ='9'
  15. EXEC proc_commissionReport
  16. @flag = 'drs'
  17. ,@user = 'bharat'
  18. ,@fromDate = '05/27/2012'
  19. ,@AgentId ='9'
  20. EXEC proc_commissionReport @flag = 'drs', @user = 'admin', @fromDate = '06/21/2012',
  21. @toDate = '06/21/2012', @date = '06/21/2012', @AgentId = '9', @pageNumber = '1', @pageSize = '100'
  22. EXEC proc_commissionReport @flag = 'drs', @user='bharat', @date='2012-03-09'
  23. EXEC proc_commissionReport @flag = 'srpt', @user = 'prakash', @fromDate = '2012-3-11', @toDate = '2012-3-11'
  24. */
  25. CREATE procEDURE [dbo].[proc_commissionReport]
  26. @flag VARCHAR(20)
  27. ,@user VARCHAR(30)
  28. ,@fromDate DATETIME = NULL
  29. ,@toDate DATETIME = NULL
  30. ,@date DATETIME = NULL
  31. ,@AgentId VARCHAR(30) = NULL
  32. ,@pageNumber INT = NULL
  33. ,@pageSize INT = NULL
  34. AS
  35. SET NOCOUNT ON;
  36. DECLARE @branch INT,@maxReportViewDays INT
  37. set @branch = @AgentId
  38. SET @pageNumber = ISNULL(@pageNumber,1)
  39. SET @pageSize = ISNULL(@pageSize ,100)
  40. SELECT @maxReportViewDays=ISNULL(maxReportViewDays,60) FROM applicationUsers WHERE userName = @user
  41. IF CAST(DATEDIFF(DD,@fromDate,@toDate) AS INT)>@maxReportViewDays
  42. BEGIN
  43. SELECT 'Commission Report' title
  44. EXEC proc_errorHandler '1', 'Report viewing range exceeded.', @agentId
  45. RETURN
  46. END
  47. -- if @AgentId is null
  48. --SELECT @branch = agentId FROM applicationUsers WHERE userName = @user
  49. --http://localhost:52196/SwiftSystem/Reports/Reports.aspx?reportName=comm&fromDate=2012-11-01&AgentId=&toDate=2012-11-01&reportType=srpt
  50. IF @flag = 'srpt' --Summary Report
  51. BEGIN
  52. SELECT
  53. [DATE] = CONVERT(VARCHAR, approvedDate, 101)
  54. ,dbo.GetAgentNameFromId(sBranch) [Branch Name]
  55. ,[Transaction] = 'Sent Transaction'
  56. ,[Txn Count] = '<a href="#" onclick="OpenInNewWindow('''+dbo.FNAGetURL()+'SwiftSystem/Reports/Reports.aspx?reportName=commsenddetail&date=' + CONVERT(VARCHAR, approvedDate, 101) + '&AgentId=' + CAST(sBranch AS VARCHAR) + ' '')">' + CAST(COUNT(*) AS VARCHAR) + '</a>'
  57. ,[Txn Amount] = SUM(ISNULL(cAmt, 0))
  58. ,[Commission] = SUM(ISNULL(sAgentComm, 0)) * -1
  59. FROM remitTran rt
  60. WHERE sBranch = ISNULL(@branch,sBranch)
  61. AND approvedDate BETWEEN ISNULL(@fromDate, '1900-01-01') AND ISNULL(@toDate + '23:59:59', '2100-12-31')
  62. GROUP BY CONVERT(VARCHAR, approvedDate,101),sBranch
  63. UNION ALL
  64. SELECT
  65. [DATE] = CONVERT(VARCHAR, paidDate, 101)
  66. ,dbo.GetAgentNameFromId(pBranch) [Branch Name]
  67. ,[Transaction] = 'Paid Transaction'
  68. ,[No. Of Txn] = '<a href="#" onclick="OpenInNewWindow('''+dbo.FNAGetURL()+'SwiftSystem/Reports/Reports.aspx?reportName=commpaydetail&date=' + CONVERT(VARCHAR, paidDate, 101) + '&AgentId=' + CAST(pBranch AS VARCHAR) + ''')">' + CAST(COUNT(*) AS VARCHAR) + '</a>'
  69. ,[Amount] = SUM(ISNULL(pAmt, 0)) * -1
  70. ,[Commission] = SUM(ISNULL(pAgentComm, 0)) * -1
  71. FROM remitTran rt
  72. WHERE pBranch = ISNULL(@branch,sBranch)
  73. AND paidDate BETWEEN ISNULL(@fromDate, '1900-01-01') AND ISNULL(@toDate + '23:59:59', '2100-12-31')
  74. GROUP BY CONVERT(VARCHAR, paidDate,101),pBranch
  75. ORDER BY [DATE]
  76. END
  77. ELSE IF @flag = 'drs' --Detail Report Send
  78. BEGIN
  79. set @date = cast(@date as DATE)
  80. SELECT
  81. ROW_NUMBER() OVER (ORDER BY rt.controlNo ASC) [ROWID]
  82. ,[Date] = CONVERT(VARCHAR, rt.approvedDate, 101)
  83. ,[Reference No] = dbo.FNADecryptString(rt.controlNo)
  84. ,[Sender] = ts.firstName + ISNULL( ' ' + ts.middleName, '') + ISNULL( ' ' + ts.lastName1, '') + ISNULL( ' ' + ts.lastName2, '')
  85. + ' | <a href="#" onclick="OpenInNewWindow('''+dbo.FNAGetURL()+'Remit/Transaction/ReprintVoucher/SendReceipt.aspx?controlNo=' + dbo.FNADecryptString(rt.controlNo) + ''')">Receipt</a>'
  86. ,[Collected Amount] = rt.cAmt
  87. ,[Commission] = ISNULL(rt.sAgentComm, 0) * -1
  88. INTO #COMMISSIONDETAILREPORT
  89. FROM remitTran rt
  90. LEFT JOIN tranSenders ts ON rt.id = ts.tranId
  91. WHERE sBranch = ISNULL(@branch,sBranch)
  92. AND rt.approvedDate BETWEEN ISNULL(@fromDate, '1900-01-01') AND ISNULL(@toDate + '23:59:59', '2100-12-31')
  93. ------###### COUNT RECORD FOR PAGING-----------
  94. SELECT TXNCOUNT = COUNT('A'),
  95. PAGESIZE = @pageSize ,
  96. PAGENUMBER = @pageNumber
  97. FROM #COMMISSIONDETAILREPORT
  98. SELECT [Date]
  99. ,[Reference No]
  100. ,[Sender]
  101. ,[Collected Amount]
  102. ,[Commission]
  103. FROM #COMMISSIONDETAILREPORT
  104. WHERE ROWID BETWEEN ((@pageNumber-1)*@pageSize +1) AND (@pageNumber * @pageSize)
  105. DROP TABLE #COMMISSIONDETAILREPORT
  106. END
  107. ELSE IF @flag = 'drp' --Detail Report Pay
  108. BEGIN
  109. set @date = cast(@date as DATE)
  110. SELECT
  111. [Date] = CONVERT(VARCHAR, rt.paidDate, 101)
  112. ,[Reference No] = dbo.FNADecryptString(rt.controlNo)
  113. ,[Beneficiary] = tr.firstName + ISNULL( ' ' + tr.middleName, '') + ISNULL( ' ' + tr.lastName1, '') + ISNULL( ' ' + tr.lastName2, '')
  114. ,[Pay Amount] = rt.pAmt * -1
  115. ,[Commission] = ISNULL(rt.pAgentComm, 0) * -1
  116. FROM remitTran rt
  117. LEFT JOIN tranReceivers tr ON rt.id = tr.tranId
  118. WHERE pBranch = ISNULL(@branch,sBranch)
  119. AND rt.paidDate BETWEEN ISNULL(@fromDate, '1900-01-01') AND ISNULL(@toDate + '23:59:59', '2100-12-31')
  120. END
  121. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  122. SELECT 'Agent' head, ISNULL((SELECT agentName FROM agentMaster WHERE agentId = @agentId),'All') value
  123. UNION ALL
  124. SELECT 'From Date' head, CONVERT(VARCHAR(10), @fromDate, 101) value
  125. UNION ALL
  126. SELECT 'To Date' head, CONVERT(VARCHAR(10), @toDate, 101) value
  127. SELECT 'Commission Report' title
  128. GO