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.

139 lines
10 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_PaidTranListInt] 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 procEDURE [dbo].[proc_PaidTranListInt]
  9. @Sagent INT = NULL
  10. ,@payAgent INT = NULL
  11. ,@PBranch INT = NULL
  12. ,@orderBy VARCHAR(50) = NULL
  13. ,@fromDate DATETIME
  14. ,@toDate DATETIME
  15. ,@FLAG CHAR(1)
  16. ,@rCountry VARCHAR(50) = NULL
  17. ,@pageSize INT = NULL
  18. ,@pageNumber INT = NULL
  19. ,@user VARCHAR(50)
  20. AS
  21. SET NOCOUNT ON;
  22. SET @TODATE = @TODATE + ' 23:59:59'
  23. DECLARE @REPORTHEAD VARCHAR(200),@maxReportViewDays int
  24. ----DECLARE @Sagent INT,@payAgent INT,@PBranch INT,@orderBy VARCHAR(50),@fromDate DATETIME,@toDate DATETIME,@FLAG CHAR(1)
  25. ----SELECT @Sagent = NULL,@payAgent=NULL,@PBranch=NULL,@fromDate='2012-10-12',@toDate='2012-11-21',@FLAG='D'
  26. SET @pageSize = ISNULL(@pageSize,500)
  27. SET @pageNumber = ISNULL(@pageNumber,1)
  28. SELECT @maxReportViewDays=ISNULL(maxReportViewDays,60) FROM applicationUsers WHERE userName = @user
  29. IF CAST(DATEDIFF(DD,@fromDate,@toDate) AS INT)>@maxReportViewDays
  30. BEGIN
  31. SELECT 'Paid Transaction Report List' title
  32. EXEC proc_errorHandler '1', 'Report viewing range exceeded.', 0
  33. RETURN
  34. END
  35. IF @FLAG='S'
  36. BEGIN
  37. SET @REPORTHEAD = 'Paid Transaction Summary List'
  38. SELECT DISTINCT LO.districtName+''+pAgentName [HEAD] FROM (
  39. SELECT
  40. pLocation,pAgentName
  41. FROM remittran
  42. WHERE sCountry<>'Nepal'
  43. AND pCountry = @rCountry
  44. AND paidDate BETWEEN @fromDate AND @toDate
  45. AND ISNULL(sAgent,0) = ISNULL(@Sagent,ISNULL(sAgent,0))
  46. AND ISNULL(pBranch,0)=ISNULL(@PBranch,ISNULL(pBranch,0))
  47. AND ISNULL(pAgent,0) = isnull(@payAgent,ISNULL(pAgent,0))
  48. GROUP BY pLocation,pAgentName,sBranchName
  49. )X
  50. INNER JOIN api_districtlist LO ON LO.ROWID = X.PLOCATION
  51. SELECT LO.districtName+''+pAgentName [HEAD],sBranchName ,TRN Nos,PAMT [Payout Amt],PCOMM [Comm Agent] FROM (
  52. SELECT
  53. pLocation,pAgentName,sBranchName,COUNT(*) TRN,SUM(pAmt) PAMT,SUM(pagentComm) PCOMM
  54. FROM remittran
  55. WHERE sCountry<>'Nepal'
  56. AND pCountry = @rCountry
  57. AND paidDate BETWEEN @fromDate AND @toDate
  58. AND ISNULL(sAgent,0) = ISNULL(@Sagent,ISNULL(sAgent,0))
  59. AND ISNULL(pBranch,0)=ISNULL(@PBranch,ISNULL(pBranch,0))
  60. AND ISNULL(pAgent,0) = isnull(@payAgent,ISNULL(pAgent,0))
  61. GROUP BY pLocation,pAgentName,sBranchName
  62. )X
  63. INNER JOIN api_districtlist LO ON LO.ROWID = X.PLOCATION
  64. END
  65. IF @FLAG='D'
  66. BEGIN
  67. SET @REPORTHEAD = 'Paid Transaction Detail List'
  68. SELECT DISTINCT LO.districtName+''+pAgentName [Payout By]
  69. FROM (
  70. SELECT
  71. pLocation,pAgentName
  72. FROM remittran RT
  73. INNER JOIN tranreceivers R ON RT.ID = R.tranId
  74. INNER JOIN transenders S ON RT.ID = S.TRANID
  75. WHERE sCountry<>'Nepal'
  76. AND pCountry = @rCountry
  77. AND paidDate BETWEEN @fromDate AND @toDate
  78. AND ISNULL(sAgent,0) = ISNULL(@Sagent,ISNULL(sAgent,0))
  79. AND ISNULL(pBranch,0)=ISNULL(@PBranch,ISNULL(pBranch,0))
  80. AND ISNULL(rt.pAgent,0) = isnull(@payAgent,ISNULL(rt.pAgent,0))
  81. )X
  82. INNER JOIN api_districtlist LO ON LO.ROWID = X.PLOCATION
  83. SELECT LO.districtName+''+pAgentName [HEAD]
  84. --,trnno+'<BR>'+sender [Sender]
  85. ,[Sender] =trnno+'<BR>'+ '<a href = "#" onclick="OpenInNewWindow('''+DBO.FNAGetURL()+'Remit/Transaction/Reports/SearchTransaction.aspx?commentFlag=N&showBankDetail=Y&tranId='+CAST(ID AS VARCHAR)+''')">'+CAST(sender AS VARCHAR)+'</a>'
  86. ,Receiver
  87. ,CAST(approvedDateLocal AS VARCHAR)+'(S:'+approvedBy+')'+'<BR>'+CONVERT(VARCHAR,paidDate,101) [Local DOT/Paid Date]
  88. ,CAST(sAmt AS VARCHAR)+' '+sCurr [Send Amt],PAMT [Receive Amt] ,sBranchName [Generated By]
  89. FROM (
  90. SELECT
  91. rt.id,pLocation,pAgentName,sBranchName,PAMT,dbo.FNADecryptString(controlNo) [trnno],paidDate,approvedDateLocal,approvedBy
  92. ,tAmt sAmt,collCurr sCurr,R.firstname+' ' +ISNULL(R.middleName,' ')+' '+isnull(R.lastName1,ISNULL(R.lastName2,' ')) [receiver]
  93. ,S.firstname +' '+ISNULL(S.middleName,' ')+' '+isnull(S.lastName1,ISNULL(S.lastName2,' ')) [sender]
  94. FROM remittran RT
  95. INNER JOIN tranreceivers R ON RT.ID = R.tranId
  96. INNER JOIN transenders S ON RT.ID = S.TRANID
  97. WHERE sCountry<>'Nepal'
  98. AND pCountry = @rCountry
  99. AND paidDate BETWEEN @fromDate AND @toDate
  100. AND ISNULL(sAgent,0) = ISNULL(@Sagent,ISNULL(sAgent,0))
  101. AND ISNULL(pBranch,0)=ISNULL(@PBranch,ISNULL(pBranch,0))
  102. AND ISNULL(rt.pAgent,0) = isnull(@payAgent,ISNULL(rt.pAgent,0))
  103. )X
  104. INNER JOIN api_districtlist LO ON LO.ROWID = X.PLOCATION
  105. END
  106. EXEC proc_errorHandler '0', 'Report has been prepared successfully.',0
  107. SELECT 'From Date' head, CONVERT(VARCHAR, @fromDate, 101) value
  108. UNION ALL
  109. SELECT 'To Date' head, CONVERT(VARCHAR, @toDate, 101)+'<br>' value
  110. UNION ALL
  111. SELECT 'Sending Agent' head, ISNULL((SELECT agentName FROM agentMaster WHERE agentId = @sagent),'All')+'<br>' value
  112. UNION ALL
  113. SELECT 'Payout Agent' head, ISNULL((SELECT agentName FROM agentMaster WHERE agentId = @payAgent),'All')+'<br>' value
  114. UNION ALL
  115. SELECT 'Payout Branch' head, ISNULL((SELECT agentName FROM agentMaster WHERE agentId = @PBranch),'All') value
  116. SELECT @REPORTHEAD title
  117. GO