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.

100 lines
6.9 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_consolidatedRpt] 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_consolidatedRpt @flag='rpt',@user ='dipesh',@fromDate = '2014-10-10',@toDate ='2014-12-01'
  10. */
  11. CREATE proc [dbo].[proc_consolidatedRpt](
  12. @flag VARCHAR(10) = NULL
  13. ,@user VARCHAR(20) = NULL
  14. ,@fromDate VARCHAR(40) = NULL
  15. ,@toDate VARCHAR(40) = NULL
  16. )
  17. AS
  18. IF @flag='rpt'
  19. BEGIN
  20. set @toDate = @toDate+' 23:59:59'
  21. select
  22. agentId = sAgent,
  23. sendCount = count('x'),
  24. sendAmt = sum(tAmt),
  25. sendCom = sum(sAgentComm)
  26. into #send_txn_dom
  27. from remitTran rt with(nolock)
  28. inner join tranReceivers rec with(nolock) on rt.id = rec.tranId
  29. inner join agentMaster am with(nolock) on rt.sAgent = am.agentId
  30. where rt.approvedDate between @fromDate and @toDate
  31. and am.agentCountry = 'Nepal'
  32. and tranType = 'D'
  33. and rt.receiverName <> 'CM Trading Enterprises Pvt. Ltd'
  34. AND ISNULL(am.agentBlock,'U') <>'B'
  35. group by sAgent,sAgentName,am.agentGrp
  36. select
  37. agentId = pAgent,
  38. payCount = count('x'),
  39. payAmt = sum(pAmt),
  40. payCom = sum(pAgentComm)
  41. into #pay_txn_intl
  42. from remitTran rt with(nolock)
  43. inner join agentMaster am with(nolock) on rt.sAgent = am.agentId
  44. where rt.paidDate between @fromDate and @toDate
  45. and tranType ='I'
  46. AND ISNULL(am.agentBlock,'U') <>'B'
  47. group by pAgent
  48. select
  49. agentId = pAgent,
  50. payCount = count('x'),
  51. payAmt = sum(pAmt),
  52. payCom = sum(pAgentComm)
  53. into #pay_txn_dom
  54. from remitTran rt with(nolock)
  55. inner join agentMaster am with(nolock) on rt.sAgent = am.agentId
  56. where rt.paidDate between @fromDate and @toDate
  57. and tranType ='D'
  58. AND ISNULL(am.agentBlock,'U') <>'B'
  59. group by pAgent
  60. SELECT
  61. [S.N.] = ROW_NUMBER() over(order by sdv.detailTitle,am.agentName),
  62. [Agent Information_Name] = am.agentName,
  63. [Agent Information_Group] = sdv.detailTitle,
  64. [International Transaction_Paid] = isnull(ip.payCount,0),
  65. [International Transaction_Paid Amt] = isnull(ip.payAmt,0),
  66. [International Transaction_RC] = isnull(ip.payCom,0),
  67. [Domestic Transaction_Send] = isnull(ds.sendCount,0),
  68. [Domestic Transaction_Paid] = isnull(dp.payCount,0),
  69. [Domestic Transaction_Send Amt] = isnull(ds.sendAmt,0),
  70. [Domestic Transaction_Paid Amt] = isnull(dp.payAmt,0),
  71. [Domestic Transaction_SC] = isnull(ds.sendCom,0),
  72. [Domestic Transaction_RC] = isnull(dp.payCom,0),
  73. [Domestic Transaction_SC+RC] = isnull(ds.sendCom,0) + isnull(dp.payCom,0),
  74. [Total_Total TXN] = isnull(ip.payCount,0) + isnull(ds.sendCount,0) + isnull(dp.payCount,0),
  75. [Total_Total Com] = isnull(ip.payCom,0) + isnull(ds.sendCom,0) + isnull(dp.payCom,0)
  76. FROM agentMaster am
  77. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON am.agentGrp = sdv.valueId
  78. LEFT JOIN #pay_txn_intl ip ON am.agentId = ip.agentId
  79. LEFT JOIN #send_txn_dom ds ON am.agentId = ds.agentId
  80. LEFT JOIN #pay_txn_dom dp ON am.agentId = dp.agentId
  81. WHERE am.agentType = 2903
  82. and am.agentCountry ='Nepal'
  83. and am.parentId not in (5576,4641)
  84. and isnull(am.agentBlock,'U') <> 'B'
  85. order by sdv.detailTitle,am.agentName
  86. DROP TABLE #pay_txn_intl
  87. DROP TABLE #send_txn_dom
  88. DROP TABLE #pay_txn_dom
  89. SELECT '0' errorCode, 'Report has been prepared successfully.' msg, NULL id
  90. SELECT 'Date Range' head,@fromDate+'-'+@toDate VALUE
  91. SELECT 'Consolidated Report' title
  92. END
  93. GO