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.

231 lines
8.0 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_CancelReport_Admin] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_CancelReport_Admin]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_CancelReport_Admin] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. CREATE PROCEDURE [dbo].[proc_CancelReport_Admin]
  12. @user VARCHAR(50),
  13. @sCountry VARCHAR(50) = NULL,
  14. @sAgent VARCHAR(50) = NULL,
  15. @sBranch VARCHAR(50) = NULL,
  16. @pCountry VARCHAR(50) = NULL,
  17. @rAgent VARCHAR(50) = NULL,
  18. @fromDate VARCHAR(10) ,
  19. @toDate VARCHAR(20) ,
  20. @cancelType VARCHAR(50) = NULL,
  21. @pageSize INT = 100,
  22. @pageNumber INT = 1
  23. AS
  24. SET NOCOUNT ON;
  25. DECLARE @SQL VARCHAR(MAX)
  26. IF(DATEDIFF(D,@fromDate,@toDate))>31
  27. BEGIN
  28. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  29. EXEC proc_errorHandler '1', '<font color="red"><b>Report can view only 31 days</b></font>', NULL
  30. RETURN;
  31. END
  32. If OBJECT_ID('tempdb..#TempResult') is not null
  33. DROP TABLE #TempResult
  34. CREATE TABLE #TempResult(
  35. [Sending_Country] VARCHAR(50)
  36. ,[Sending_Agent] VARCHAR(200)
  37. ,[Sending_Branch] VARCHAR(200)
  38. ,[BRN] VARCHAR(200)
  39. ,[Sender/Receiver] VARCHAR(300)
  40. ,[Receiving_Country] VARCHAR(50)
  41. ,[Receiving_Agent] VARCHAR(200)
  42. ,[TXN Date] VARCHAR(50)
  43. ,[Deposit Amt] MONEY
  44. ,[Payout Amt] MONEY
  45. ,[Cancel Request_User] VARCHAR(50)
  46. ,[Cancel Request_Date] VARCHAR(50)
  47. ,[Cancel Approve_User] VARCHAR(50)
  48. ,[Cancel Approve_Date] VARCHAR(50)
  49. ,[Cancel Refund_User] VARCHAR(50)
  50. ,[Cancel Refund_Date] VARCHAR(50)
  51. ,[Cancel Reason] VARCHAR(500)
  52. ,[Txn<br/>Generated By] VARCHAR(50)
  53. )
  54. SET @SQL='
  55. INSERT INTO #TempResult
  56. SELECT * FROM (
  57. SELECT
  58. [Sending_Country] = ISNULL(sCountry,''-'')
  59. ,[Sending_Agent] = ISNULL(sAgentName,''-'')
  60. ,[Sending_Branch] = ISNULL(sBranchName,''-'')
  61. ,[BRN] = ''<a href = "#" onclick="ViewTranDetail(''+CAST(RT.id AS VARCHAR)+'')">''+dbo.FNADecryptString(RT.controlNo) +''</a>''
  62. ,[Sender/Receiver] = rt.senderName+''/''+rt.receiverName
  63. ,[Receiving_Country] = RT.pCountry
  64. ,[Receiving_Agent] = RT.pAgentName
  65. ,[TXN Date] = RT.createdDate
  66. ,[Deposit Amt] = RT.cAmt
  67. ,[Payout Amt] = RT.pAmt
  68. ,[Cancel Request_User] = RT.cancelRequestBy
  69. ,[Cancel Request_Date] = RT.cancelRequestDate
  70. ,[Cancel Approve_User] = RT.cancelApprovedBy
  71. ,[Cancel Approve_Date] = RT.cancelApprovedDate
  72. ,[Cancel Refund_User] = RC.teller
  73. ,[Cancel Refund_Date] = RC.refundDate
  74. ,[Cancel Reason] = ISNULL(''Request :''+RC.cancelReason,'''')+''<br/>''+ISNULL(''Approve :''+RC.approvedRemarks,'''')
  75. ,[Txn<br/>Generated By] = RT.createdBy
  76. FROM remitTran RT WITH (NOLOCK)
  77. LEFT JOIN tranCancelrequest RC WITH (NOLOCK) ON RT.controlNo=RC.controlNo
  78. WHERE ISNULL(RC.cancelStatus, '''') <> ''Rejected'' '
  79. IF @sCountry IS NOT NULL
  80. SET @SQL = @SQL +' AND RT.sCountry = '''+@sCountry+''''
  81. IF @sAgent IS NOT NULL
  82. SET @SQL = @SQL +' AND RT.sAgent = '''+@sAgent+''''
  83. IF @sBranch IS NOT NULL
  84. SET @SQL = @SQL +' AND RT.sBranch =''' +CAST(@sBranch AS VARCHAR)+ ''''
  85. IF @pCountry IS NOT NULL AND @pCountry<>'ALL'
  86. SET @SQL = @SQL +' AND RT.pCountry ='''+@pCountry+''''
  87. IF @rAgent IS NOT NULL
  88. SET @SQL = @SQL +' AND RT.pAgent ='''+@rAgent+''''
  89. -->> Report Type
  90. IF @cancelType IS NULL
  91. SET @SQL = @SQL +' AND RT.cancelApprovedDate BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59'' and ISNULL(RC.cancelStatus, '''') <> ''CancelRequest'' '
  92. IF @cancelType ='denied'
  93. SET @SQL = @SQL +' AND 1=2 '
  94. IF @cancelType ='Approved'
  95. SET @SQL = @SQL +' AND RT.cancelApprovedDate BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59'' and ISNULL(RC.cancelStatus, '''') not in (''CancelRequest,Rejected'') '
  96. IF @cancelType ='Refunded'
  97. SET @SQL = @SQL +' AND RC.refundDate BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59'' and RC.cancelStatus = ''Refunded'' '
  98. IF @cancelType ='RefundPending'
  99. SET @SQL = @SQL +' AND RT.cancelApprovedDate BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59''
  100. and RC.cancelStatus = ''Approved'' and RC.tranStatus in (''Payment'',''Paid'',''Post'') and RT.sAgent = 13410 '
  101. IF @cancelType ='PaidCancel'
  102. SET @SQL = @SQL +' AND RT.cancelApprovedDate BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59'' and RT.payStatus = ''Paid'''
  103. IF @cancelType ='PostCancel'
  104. SET @SQL = @SQL +' AND RT.cancelApprovedDate BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59'' and RT.payStatus = ''Post'''
  105. IF @cancelType ='Rejected'
  106. SET @SQL = @SQL +' AND RC.approvedDate BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59'' and RC.tranStatus = ''Rejected'''
  107. IF @cancelType ='denied' OR @cancelType IS NULL
  108. BEGIN
  109. SET @SQL=@SQL + '
  110. UNION ALL
  111. SELECT
  112. [Sending_Country] = ISNULL(RT.sCountry,''-'')
  113. ,[Sending_Agent] = ISNULL(RT.sAgentName,''-'')
  114. ,[Sending_Branch] = ISNULL(RT.sBranchName,''-'')
  115. ,[BRN] = ''<a href = "#" onclick="ViewCancelTxnByControlNo(''+CAST(dbo.FNADecryptString(RT.controlNo) AS VARCHAR)+'')">''+dbo.FNADecryptString(RT.controlNo) +''</a>''
  116. ,[Sender/Receiver] = rt.senderName+''/''+rt.receiverName
  117. ,[Receiving_Country] = RT.pCountry
  118. ,[Receiving_Agent] = RT.pAgentName
  119. ,[TXN Date] = RT.createdDate
  120. ,[Deposit Amt] = RT.cAmt
  121. ,[Payout Amt] = RT.pAmt
  122. ,[Cancel Request_User] = RT.cancelRequestBy
  123. ,[Cancel Request_Date] = RT.cancelRequestDate
  124. ,[Cancel Approve_User] = RT.cancelApprovedBy
  125. ,[Cancel Approve_Date] = RT.cancelApprovedDate
  126. ,[Cancel Refund_User] = RC.teller
  127. ,[Cancel Refund_Date] = RC.refundDate
  128. ,[Cancel Reason] = ISNULL(''Request :''+RC.cancelReason,'''')+''<br/>''+ISNULL(''Approve :''+RC.approvedRemarks,'''')
  129. ,[Txn Generated By] = RT.createdBy
  130. FROM cancelTranHistory RT WITH (NOLOCK)
  131. LEFT JOIN tranCancelrequest RC WITH (NOLOCK) ON RT.controlNo=RC.controlNo
  132. WHERE RC.cancelStatus <> ''Rejected'' and cancelapprovedDate BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59'''
  133. IF @sCountry IS NOT NULL
  134. SET @SQL = @SQL +' AND RT.sCountry = '''+@sCountry+''''
  135. IF @sAgent IS NOT NULL
  136. SET @SQL = @SQL +' AND RT.sAgent = '''+@sAgent+''''
  137. IF @sBranch IS NOT NULL
  138. SET @SQL = @SQL +' AND RT.sBranch =''' +CAST(@sBranch AS VARCHAR)+ ''''
  139. IF @pCountry IS NOT NULL AND @pCountry<>'ALL'
  140. SET @SQL = @SQL +' AND RT.pCountry ='''+@pCountry+''''
  141. IF @rAgent IS NOT NULL
  142. SET @SQL = @SQL +' AND RT.pAgent ='''+@rAgent+''''
  143. END
  144. SET @SQL = @SQL +')x'
  145. PRINT @SQL
  146. EXEC(@SQL)
  147. ALTER TABLE #TempResult ADD rowId INT IDENTITY(1,1)
  148. SELECT
  149. COUNT(*) AS TXNCOUNT
  150. ,@pageSize PAGESIZE
  151. ,@pageNumber PAGENUMBER
  152. FROM #TempResult
  153. SELECT
  154. rowId [S.N.]
  155. ,[Sending_Country]
  156. ,[Sending_Agent]
  157. ,[Sending_Branch]
  158. ,[BRN]
  159. ,[Sender/Receiver]
  160. ,[Receiving_Country]
  161. ,[Receiving_Agent]
  162. ,[TXN Date]
  163. ,[Deposit Amt]
  164. ,[Payout Amt]
  165. ,[Cancel Reason]
  166. ,[Cancel Request_User]
  167. ,[Cancel Request_Date]
  168. ,[Cancel Approve_User]
  169. ,[Cancel Approve_Date]
  170. ,[Cancel Refund_User]
  171. ,[Cancel Refund_Date]
  172. ,[Txn<br/>Generated By]
  173. FROM #TempResult
  174. WHERE rowId BETWEEN CAST(((@pageNumber - 1) * @pageSize + 1) AS VARCHAR) AND CAST(@pageNumber * @pageSize AS VARCHAR)
  175. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  176. SELECT 'Sending Country' head,isnull(@sCountry,'All') VALUE
  177. UNION ALL
  178. SELECT 'Receiving Country' head,isnull(@pCountry,'All') VALUE
  179. UNION ALL
  180. SELECT 'Sending Agent' head,isnull(@sAgent,'All') VALUE
  181. UNION ALL
  182. SELECT 'Receiving Agent' head,isnull(@rAgent,'All') VALUE
  183. UNION ALL
  184. SELECT 'Branch' head,case when @sBranch is null then 'All' else (SELECT agentName FROM agentMaster WITH(NOLOCK) WHERE agentid=@sBranch) end VALUE
  185. UNION ALL
  186. SELECT '<br/>From Date' head,@fromDate value
  187. UNION ALL
  188. SELECT 'To Date' head, @toDate
  189. UNION ALL
  190. SELECT 'Cancel Type' head, ISNULL(UPPER(@cancelType),'All')
  191. SELECT 'Cancel Transaction Report' title
  192. GO