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.

238 lines
10 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_complianceRpt] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_complianceRpt]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_complianceRpt] 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_complianceRpt]
  12. (
  13. @flag VARCHAR(20)=NULL
  14. ,@date VARCHAR(20)=NULL
  15. ,@rName VARCHAR(50)=NULL
  16. ,@fromDate VARCHAR(20)=NULL
  17. ,@toDate VARCHAR(20)=NULL
  18. )
  19. AS
  20. BEGIN
  21. IF @flag='rdd'
  22. BEGIN
  23. SELECT
  24. [Receiver Name] =tr.firstName+' '+ISNULL(tr.middleName,'')+' '+ISNULL(tr.lastName1,'')+' '+ISNULL(tr.lastName2,'')
  25. ,[Id Type] = ISNULL(tr.idType2,tr.idType)
  26. ,[Id Number] = ISNULL(tr.idNumber2,tr.idNumber)
  27. ,[Control No] ='<a href = "#" onclick="OpenInNewWindow('''+FastMoneyPro_remit.dbo.FNAGetURL()+'Remit/Transaction/Reports/SearchTransaction.aspx?commentFlag=N&showBankDetail=N&tranId='+CAST(rt.id AS VARCHAR)+''')">'+FastMoneyPro_remit.dbo.FNADecryptString(controlNo)+'</a>'
  28. ,[Amount] =rt.pAmt
  29. ,[Payout Agent] =am.agentName
  30. ,[Tran Status] =rt.tranStatus
  31. ,[Pay Status] =rt.payStatus
  32. FROM remitTran rt WITH(NOLOCK)
  33. INNER JOIN tranreceivers tr WITH(NOLOCK) ON rt.id=tr.tranId
  34. LEFT JOIN agentMaster am ON am.agentId=rt.pAgent
  35. WHERE rt.createdDate BETWEEN @date AND @date+' 23:59:59'
  36. AND rt.tranStatus <>'Cancel'
  37. AND rt.tranType = 'I'
  38. AND ltrim(rtrim(replace(tr.firstName+' '+ISNULL(tr.middleName,'')+' '+ISNULL(tr.lastName1,'')+' '+ISNULL(tr.lastName2,''),' ',' ')))
  39. = replace(rtrim(ltrim(@rName)),' ',' ')
  40. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  41. SELECT 'Date ' head, @date value UNION ALL
  42. SELECT 'Report By' head, 'Receiver Wise Tranaction Detail' value UNION ALL
  43. SELECT 'Receiver Name' head, @rName value
  44. SELECT 'Single Day Transaction ' title
  45. RETURN
  46. END
  47. IF (@flag='muls')
  48. BEGIN
  49. IF OBJECT_ID('tempdb..#temp4') IS NOT NULL
  50. DROP TABLE #temp4
  51. IF OBJECT_ID('tempdb..#temp5') IS NOT NULL
  52. DROP TABLE #temp5
  53. SELECT
  54. [Sender Name] ='Name: '+ts.firstName+' '+ISNULL(ts.middleName,'')+' '+ISNULL(ts.lastName1,'') + '<br/>'
  55. +ISNULL(ts.idType,'')+' :'+ISNULL(ts.idNumber,'')+'<br/>Phone: '+ISNULL(ts.homePhone,ISNULL(ts.mobile,''))
  56. ,[Receiver Name] ='Name: '+tr.firstName+' '+ISNULL(tr.middleName,'')+' '+ISNULL(tr.lastName1,'')+ '<br/>Cell: '
  57. +ISNULL(tr.mobile,'')+'<br/>Address: '+ISNULL(tr.address,'')+ISNULL(','+tr.address2,'')
  58. +'<br/>'+CASE WHEN ISNULL(tr.idType2,tr.idType) IS NULL OR ISNULL(tr.idNumber2,tr.idNumber) IS NULL THEN '' ELSE ISNULL(tr.idType2,tr.idType)+': '+ISNULL(tr.idNumber2,tr.idNumber) END
  59. ,[Control No] ='<a href = "#" onclick="OpenInNewWindow('''+FastMoneyPro_remit.dbo.FNAGetURL()+'Remit/Transaction/Reports/SearchTransaction.aspx?commentFlag=N&showBankDetail=N&tranId='+CAST(rt.id AS VARCHAR)+''')">'+FastMoneyPro_remit.dbo.FNADecryptString(controlNo)+'</a>'
  60. ,[Tran Date] = rt.createdDate
  61. ,[Sending Country] = rt.sCountry
  62. ,[Payment Method] = rt.paymentMethod --+ '-'+ dbo.decryptDb(rt.controlNo)
  63. ,[Money source] = ISNULL(rt.sourceOfFund,'Salary and Savings')
  64. ,pAmt = (rt.pAmt)
  65. ,[Payout currency] = ISNULL(rt.payoutCurr,'')
  66. ,[Payout Location] = ISNULL(rt.pBranchName,'')+'<b>('+ISNULL(ploc.districtName,'')+'</b>'
  67. ,[sName] = ts.firstName+' '+ISNULL(ts.middleName,'')+' '+ISNULL(ts.lastName1,'')+'-'+ ISNULL(ts.idNumber,'')
  68. INTO #temp4
  69. FROM remitTran rt WITH(NOLOCK)
  70. INNER JOIN tranSenders ts WITH(NOLOCK) ON rt.id=ts.tranId
  71. INNER JOIN tranreceivers tr WITH(NOLOCK) ON rt.id=tr.tranId
  72. LEFT JOIN dbo.api_districtList ploc WITH(NOLOCK) ON rt.pLocation = ploc.districtCode
  73. WHERE
  74. rt.createdDate BETWEEN @fromDate AND @toDate+' 23:59:59'
  75. AND rt.tranType = 'I'
  76. AND rt.tranStatus <>'Cancel'
  77. SELECT sName
  78. INTO #temp5
  79. FROM #temp4
  80. GROUP BY sName
  81. HAVING SUM(pAmt)> = 1000.00 ORDER BY sName
  82. SELECT [Sender Name],[Receiver Name],[Tran Date],[Control No],[Sending Country],[Payout Location]
  83. ,[Payment Method],dbo.ShowDecimal(pAmt)[Payout Amount],[Payout currency]
  84. ,a.[sName]
  85. FROM #temp4 a INNER JOIN #temp5 b ON a.sName = b.sName ORDER BY a.sName
  86. SELECT * FROM #temp5 ORDER BY sName
  87. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  88. SELECT 'From Date ' head, @fromDate value UNION ALL
  89. SELECT 'To Date ' head, @toDate value UNION ALL
  90. SELECT 'Report By' head, (SELECT CASE WHEN @flag = 'muls' THEN 'Sender Wise Multiple Tranaction' WHEN @flag ='mulr' THEN 'Receiver Wise Multiple Tranaction' END) value
  91. SELECT 'Multiple Day Transaction ' title
  92. RETURN
  93. END
  94. IF @flag='mulr'
  95. BEGIN
  96. IF OBJECT_ID('tempdb..#temp3') IS NOT NULL
  97. DROP TABLE #temp3
  98. SELECT
  99. [Receiver Name] =tr.firstName+' '+ISNULL(tr.middleName,'')+' '+ISNULL(tr.lastName1,'')+' '+ISNULL(tr.lastName2,'')
  100. ,Amount =rt.pAmt
  101. ,AmountInUSD =rt.pAmt / ISNULL(rt.pCurrCostRate,1) - ISNULL(rt.pCurrHoMargin, 0)
  102. ,Remarks =CAST(rt.createdDate AS DATE)
  103. ,rName =tr.firstName+' '+ISNULL(tr.middleName,'')+' '+ISNULL(tr.lastName1,'')+' '+ISNULL(tr.lastName2,'')
  104. ,pAmt
  105. ,txnDate=CAST(rt.createdDate AS DATE)
  106. INTO #temp3
  107. FROM remitTran rt WITH(NOLOCK)
  108. INNER JOIN tranreceivers tr WITH(NOLOCK) ON rt.id=tr.tranId
  109. WHERE rt.createdDate BETWEEN @fromDate AND @toDate+' 23:59:59'
  110. AND rt.tranType = 'I'
  111. AND rt.tranStatus <>'Cancel'
  112. SELECT [SNO] = ROW_NUMBER() OVER (ORDER BY rName ASC)
  113. ,'Receiver Name' ='<a href = "#" onclick="OpenInNewWindow(''Reports.aspx?reportName=nrb_report&flag=rdd&rName='+rName+'&type=r&date='+CAST(txnDate AS VARCHAR)+''')">'+rName+'</a>'
  114. ,'Remitance in NPR_Txn Count' =COUNT(rName)
  115. ,'Remitance in NPR_Total Amount(NPR)'=SUM(Amount)
  116. ,'Remitance in USD_Txn Count' =COUNT(rName)
  117. ,'Remitance in USD_Total Amount(USD)'=SUM(AmountInUSD)
  118. ,'Date' =txnDate
  119. FROM #temp3 GROUP BY rName,txnDate
  120. HAVING SUM(pAmt)> = 1000.00
  121. ORDER BY rName
  122. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  123. SELECT 'From Date ' head, @fromDate value UNION ALL
  124. SELECT 'To Date ' head, @toDate value UNION ALL
  125. SELECT 'Report By' head, (SELECT CASE WHEN @flag = 'muls' THEN 'Sender Wise Multiple Tranaction' WHEN @flag ='mulr' THEN 'Receiver Wise Multiple Tranaction' END) value
  126. SELECT 'Multiple Day Transaction ' title
  127. RETURN
  128. END
  129. IF @flag='r'
  130. BEGIN
  131. SELECT
  132. [Receiver Name] =tr.firstName+' '+ISNULL(tr.middleName,'')+' '+ISNULL(tr.lastName1,'')+' '+ISNULL(tr.lastName2,'')
  133. ,Amount =rt.pAmt
  134. ,AmountInUSD =rt.pAmt / ISNULL(rt.pCurrCostRate,1) - ISNULL(rt.pCurrHoMargin, 0)
  135. ,Remarks =rt.createdDate
  136. ,rName =tr.firstName+' '+ISNULL(tr.middleName,'')+' '+ISNULL(tr.lastName1,'')+' '+ISNULL(tr.lastName2,'')
  137. ,pAmt
  138. INTO #temp2
  139. FROM remitTran rt WITH(NOLOCK)
  140. INNER JOIN tranreceivers tr WITH(NOLOCK) ON rt.id=tr.tranId
  141. WHERE rt.createdDate BETWEEN @date AND @date+' 23:59:59'
  142. AND rt.tranType = 'I'
  143. AND rt.tranStatus <>'Cancel'
  144. update #temp2 set rName = REPLACE(rName,' ',' ')
  145. SELECT [SNO] = ROW_NUMBER() OVER (ORDER BY rName ASC)
  146. ,'Receiver Name' ='<a href = "#" onclick="OpenInNewWindow(''Reports.aspx?reportName=nrb_report&flag=rdd&rName='+rName+'&type=r&date='+@date+''')">'+rName+'</a>'
  147. ,'Remitance in NPR_Txn Count' =COUNT(rName)
  148. ,'Remitance in NPR_Total Amount(NPR)'=SUM(Amount)
  149. ,'Remitance in USD_Txn Count' =COUNT(rName)
  150. ,'Remitance in USD_Total Amount(USD)'=SUM(AmountInUSD)
  151. ,'Date' =@date
  152. FROM #temp2 GROUP BY rName
  153. HAVING SUM(pAmt)> = 1000.00
  154. ORDER BY rName
  155. END
  156. IF @flag='s'
  157. BEGIN
  158. IF OBJECT_ID('tempdb..#temp') IS NOT NULL
  159. DROP TABLE #temp
  160. IF OBJECT_ID('tempdb..#temp1') IS NOT NULL
  161. DROP TABLE #temp1
  162. SELECT
  163. [Sender Name] ='Name: '+rt.senderName+ '<br/>'
  164. +ISNULL(ts.idType,'')+' :'+ISNULL(ts.idNumber,'')+'<br/>Phone: '+ISNULL(ts.homePhone,ISNULL(ts.mobile,''))
  165. ,[Receiver Name] ='Name: '+rt.receiverName+ '<br/>Cell: '
  166. +ISNULL(tr.mobile,'')+'<br/>Address: '+ISNULL(tr.address,'')+ISNULL(','+tr.address2,'')
  167. +'<br/>'+CASE WHEN ISNULL(tr.idType2,tr.idType) IS NULL OR ISNULL(tr.idNumber2,tr.idNumber) IS NULL THEN '' ELSE ISNULL(tr.idType2,tr.idType)+': '+ISNULL(tr.idNumber2,tr.idNumber) END
  168. ,[Control No] ='<a href = "#" onclick="OpenInNewWindow('''+dbo.FNAGetURL()+'Remit/Transaction/Reports/SearchTransaction.aspx?tranId='+CAST(rt.id AS VARCHAR)+''')">'+ dbo.FNADecryptString(rt.controlNo) +'</a>'
  169. ,[Tran Date] = rt.createdDate
  170. ,[Sending Country] = rt.sCountry
  171. ,[Payment Method] = rt.paymentMethod
  172. ,[Money source] = ISNULL(rt.sourceOfFund,'Salary and Savings')
  173. ,[pAmt] = rt.pAmt
  174. ,[Payout currency] = ISNULL(rt.payoutCurr,'')
  175. ,[Payout Location] = ISNULL(rt.pBranchName,'')+'<b>('+ISNULL(ploc.districtName,'')+'</b>'
  176. ,[sName] = rt.senderName+'-'+ ISNULL(ts.idNumber,'')
  177. INTO #temp
  178. FROM remitTran rt WITH(NOLOCK)
  179. INNER JOIN tranSenders ts WITH(NOLOCK) ON rt.id=ts.tranId
  180. INNER JOIN tranreceivers tr WITH(NOLOCK) ON rt.id=tr.tranId
  181. LEFT JOIN dbo.api_districtList ploc WITH(NOLOCK) ON rt.pLocation = ploc.districtCode
  182. WHERE rt.createdDate BETWEEN @date AND @date+' 23:59:59'
  183. AND rt.tranType = 'I'
  184. AND tranStatus <> 'Cancel'
  185. SELECT sName
  186. INTO #temp1
  187. FROM #temp
  188. GROUP BY sName
  189. HAVING SUM(pAmt)> = 1000.00 ORDER BY sName
  190. SELECT
  191. [Sender Name],
  192. [Receiver Name],
  193. [Tran Date],
  194. [Control No],
  195. [Sending Country],
  196. [Payout Location],
  197. [Payment Method],
  198. [Payout Amount] = dbo.ShowDecimal(pAmt),
  199. [Payout currency],
  200. sName = a.[sName]
  201. FROM #temp a INNER JOIN #temp1 b ON a.sName = b.sName ORDER BY a.sName
  202. SELECT * FROM #temp1 ORDER BY sName
  203. END
  204. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  205. SELECT 'Date ' head, @date value UNION ALL
  206. SELECT 'Report By' head, (SELECT CASE WHEN @flag = 's' THEN 'Sender Wise Tranaction' WHEN @flag ='r' THEN 'Receiver Wise Tranaction' END) value
  207. SELECT 'Single Day Transaction ' title
  208. END
  209. GO