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.

248 lines
19 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_customerEnrollmentRpt] 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_customerEnrollmentRpt] @flag = 'main', @user = 'admin', @fromDate = '2013-11-01',
  10. @toDate = '2013-11-17', @memId = null, @pageNumber = '1', @pageSize = '100'
  11. */
  12. CREATE procEDURE [dbo].[proc_customerEnrollmentRpt]
  13. @flag VARCHAR(20),
  14. @fromDate VARCHAR(20) = NULL,
  15. @toDate VARCHAR(30) = NULL,
  16. @memId VARCHAR(50) = NULL,
  17. @agentId VARCHAR(30) = NULL,
  18. @branchId VARCHAR(30) = NULL,
  19. @pageNumber INT = NULL,
  20. @pageSize INT = NULL,
  21. @user VARCHAR(50) = NULL
  22. AS
  23. SET NOCOUNT ON;
  24. SET ANSI_NULLS ON;
  25. declare @sql varchar(max),@url varchar(max)
  26. IF @flag='main'
  27. BEGIN
  28. SET @url='"Reports.aspx?reportName=20164400&flag=main-customer&fromDate='+@fromDate+'&toDate='+@toDate+'&agent=''+ISNULL(cast(a.agentId as varchar),'''')+''&memId='+ISNULL(@memId,'')+'"'
  29. set @sql = 'select
  30. [SN] = row_number() over(order by b.agentName)
  31. ,[Agent] = ''<span class = "link" onclick = ViewAMLDDLReport('+@url+');>'' + b.agentName + ''</span>''
  32. ,[No of Customer] = count(''x'')
  33. from customerMaster a with(nolock)
  34. inner join agentMaster b with(nolock) on a.agentId = b.agentId'
  35. set @sql = @sql+ ' where a.createdDate between '''+@fromDate+''' and '''+@toDate+' 23:59:59'''
  36. if @agentId is not null and @branchId is null
  37. set @sql = @sql+ ' and a.agentId = '''+@agentId+''''
  38. if @branchId is not null
  39. set @sql = @sql+ ' and a.agentId = '''+@branchId+''''
  40. if @memId is not null
  41. set @sql = @sql+ ' and a.membershipId = '''+@memId+''''
  42. set @sql = @sql+ ' group by b.agentName,a.agentId'
  43. print(@sql)
  44. exec(@sql)
  45. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  46. SELECT 'Agent' head, case when @agentId is null then 'All' else (select agentName from agentMaster with(nolock) where agentId = @agentId) end value
  47. union all
  48. SELECT 'Branch' head, case when @branchId is null then 'All' else (select agentName from agentMaster with(nolock) where agentId = @branchId) end value
  49. union all
  50. SELECT 'From Date' head, @fromDate value
  51. union all
  52. SELECT 'To Date' head, @toDate value
  53. union all
  54. SELECT 'Membeship ID' head, @memId value
  55. SELECT 'Customer Enrollment Report' title
  56. END
  57. IF @flag='main-customer'
  58. BEGIN
  59. SET @url='"Reports.aspx?reportName=customerrpt&fromDate='+@fromDate+'&toDate='+@toDate+'&memId=''+ISNULL(cast(a.membershipId as varchar),'''')+''"'
  60. set @sql = 'select
  61. [Membership Id] = ''<span class = "link" onclick = ViewAMLDDLReport('+@url+');>'' + a.membershipId + ''</span>''
  62. ,[Customer Name] = ISNULL('' '' + a.firstName, '''') + ISNULL('' '' + a.middleName, '''') + ISNULL('' '' + a.lastName, '''')
  63. ,[County] = pCountry
  64. ,[Zone] = pZone
  65. ,[District] = pDistrict
  66. ,[VDC/MNC] = pMunicipality
  67. ,[Mobile] = mobile
  68. ,[Email] = email
  69. ,[Occupation] = occupation
  70. ,[Date Of Birth] = dobEng
  71. ,[Created By] = createdBy
  72. ,[Created Date] = createdDate
  73. ,[Approved By] = approvedBy
  74. ,[Approved Date] = approvedDate
  75. from customerMaster a with(nolock)'
  76. set @sql = @sql+ ' where a.createdDate between '''+@fromDate+''' and '''+@toDate+' 23:59:59'''
  77. if @agentId is not null and @branchId is null
  78. set @sql = @sql+ ' and a.agentId = '''+@agentId+''''
  79. if @branchId is not null
  80. set @sql = @sql+ ' and a.agentId = '''+@branchId+''''
  81. if @memId is not null
  82. set @sql = @sql+ ' and a.membershipId = '''+@memId+''''
  83. set @sql = @sql+ ' order by a.createdDate desc'
  84. exec(@sql)
  85. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  86. SELECT 'Agent' head, case when @agentId is null then 'All' else (select agentName from agentMaster with(nolock) where agentId = @agentId) end value
  87. union all
  88. SELECT 'Branch' head, case when @branchId is null then 'All' else (select agentName from agentMaster with(nolock) where agentId = @branchId) end value
  89. union all
  90. SELECT 'From Date' head, @fromDate value
  91. union all
  92. SELECT 'To Date' head, @toDate value
  93. union all
  94. SELECT 'Membeship ID' head, @memId value
  95. SELECT 'Customer Enrollment Report' title
  96. END
  97. IF @FLAG='main-detail'
  98. BEGIN
  99. --send transaction
  100. select
  101. [S.N.] = row_number()over(order by rt.id)
  102. ,[Control No] = dbo.fnadecryptstring(rt.controlNo)
  103. ,[Agent] = sBranchName
  104. ,[Payment Method] = paymentMethod
  105. ,[Payout Amount] = pAmt
  106. ,[Tran Status] = tranStatus
  107. ,[TXN Date] = createdDate
  108. ,[Paid Date] = paidDate
  109. ,[Rec. Agent] = pAgentName
  110. ,[Sender_Name] = isnull(sen.firstName,'')+' '+isnull(sen.middleName,'')+' '+isnull(sen.lastname1,'')+' '+isnull(sen.lastname2,'')
  111. ,[Sender_Id Type] = sen.idType
  112. ,[Sender_Id Number] = sen.idNUmber
  113. ,[Receiver_Name] = isnull(rec.firstName,'')+' '+isnull(rec.middleName,'')+' '+isnull(rec.lastname1,'')+' '+isnull(rec.lastname2,'')
  114. ,[Receiver_Id Type] = sen.idType
  115. ,[Receiver_Id Number] = sen.idNUmber
  116. ,[Transaction Type] = 'Send'
  117. from remitTran rt with(nolock)
  118. inner join tranSenders sen with(nolock) on rt.id = sen.tranId
  119. inner join tranReceivers rec with(nolock) on rt.id = rec.tranId
  120. where sen.membershipId = @memId
  121. and rt.createddate between @fromDate and @toDate+' 23:59:59'
  122. union all
  123. --receiver transaction
  124. select
  125. [S.N.] = row_number()over(order by rt.id)
  126. ,[Control No] = dbo.fnadecryptstring(rt.controlNo)
  127. ,[Agent] = sBranchName
  128. ,[Payment Type] = paymentMethod
  129. ,[Payout Amount] = pAmt
  130. ,[Tran Status] = tranStatus
  131. ,[TXN Date] = createdDate
  132. ,[Paid Date] = paidDate
  133. ,[Rec. Agent] = pAgentName
  134. ,[Sender_Name] = isnull(sen.firstName,'')+' '+isnull(sen.middleName,'')+' '+isnull(sen.lastname1,'')+' '+isnull(sen.lastname2,'')
  135. ,[Sender_Id Type] = sen.idType
  136. ,[Sender_Id Number] = sen.idNUmber
  137. ,[Receiver_Name] = isnull(rec.firstName,'')+' '+isnull(rec.middleName,'')+' '+isnull(rec.lastname1,'')+' '+isnull(rec.lastname2,'')
  138. ,[Receiver_Id Type] = sen.idType
  139. ,[Receiver_Id Number] = sen.idNUmber
  140. ,[Transaction Type] = 'Receive'
  141. from remitTran rt with(nolock)
  142. inner join tranReceivers rec with(nolock) on rt.id = rec.tranId
  143. inner join tranSenders sen with(nolock) on rt.id = sen.tranId
  144. where sen.membershipId = @memId
  145. and rt.paidDate between @fromDate and @toDate+' 23:59:59'
  146. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  147. SELECT 'From Date' head,@FROMDATE value
  148. UNION ALL
  149. SELECT 'To Date' head,@TODATE value
  150. UNION ALL
  151. SELECT 'Membeship ID' head,@memId value
  152. SELECT 'Customer Enrollment Report' title
  153. END
  154. IF @FLAG='detail'
  155. BEGIN
  156. --send transaction
  157. select
  158. [S.N.] = row_number()over(order by rt.id)
  159. ,[Control No] = dbo.fnadecryptstring(rt.controlNo)
  160. ,[Agent] = sBranchName
  161. ,[Payment Method] = paymentMethod
  162. ,[Payout Amount] = pAmt
  163. ,[Tran Status] = tranStatus
  164. ,[TXN Date] = createdDate
  165. ,[Paid Date] = paidDate
  166. ,[Rec. Agent] = pAgentName
  167. ,[Sender_Name] = isnull(sen.firstName,'')+' '+isnull(sen.middleName,'')+' '+isnull(sen.lastname1,'')+' '+isnull(sen.lastname2,'')
  168. ,[Sender_Id Type] = sen.idType
  169. ,[Sender_Id Number] = sen.idNUmber
  170. ,[Receiver_Name] = isnull(rec.firstName,'')+' '+isnull(rec.middleName,'')+' '+isnull(rec.lastname1,'')+' '+isnull(rec.lastname2,'')
  171. ,[Receiver_Id Type] = sen.idType
  172. ,[Receiver_Id Number] = sen.idNUmber
  173. ,[Transaction Type] = 'Send'
  174. from remitTran rt with(nolock)
  175. inner join tranSenders sen with(nolock) on rt.id = sen.tranId
  176. inner join tranReceivers rec with(nolock) on rt.id = rec.tranId
  177. where sen.membershipId = @memId
  178. and rt.createddate between @fromDate and @toDate+' 23:59:59'
  179. union all
  180. --receiver transaction
  181. select
  182. [S.N.] = row_number()over(order by rt.id)
  183. ,[Control No] = dbo.fnadecryptstring(rt.controlNo)
  184. ,[Agent] = sBranchName
  185. ,[Payment Type] = paymentMethod
  186. ,[Payout Amount] = pAmt
  187. ,[Tran Status] = tranStatus
  188. ,[TXN Date] = createdDate
  189. ,[Paid Date] = paidDate
  190. ,[Rec. Agent] = pAgentName
  191. ,[Sender_Name] = isnull(sen.firstName,'')+' '+isnull(sen.middleName,'')+' '+isnull(sen.lastname1,'')+' '+isnull(sen.lastname2,'')
  192. ,[Sender_Id Type] = sen.idType
  193. ,[Sender_Id Number] = sen.idNUmber
  194. ,[Receiver_Name] = isnull(rec.firstName,'')+' '+isnull(rec.middleName,'')+' '+isnull(rec.lastname1,'')+' '+isnull(rec.lastname2,'')
  195. ,[Receiver_Id Type] = sen.idType
  196. ,[Receiver_Id Number] = sen.idNUmber
  197. ,[Transaction Type] = 'Receive'
  198. from remitTran rt with(nolock)
  199. inner join tranReceivers rec with(nolock) on rt.id = rec.tranId
  200. inner join tranSenders sen with(nolock) on rt.id = sen.tranId
  201. where sen.membershipId = @memId
  202. and rt.paidDate between @fromDate and @toDate+' 23:59:59'
  203. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  204. SELECT 'From Date' head,@FROMDATE value
  205. UNION ALL
  206. SELECT 'To Date' head,@TODATE value
  207. UNION ALL
  208. SELECT 'Membeship ID' head,@memId value
  209. SELECT 'Customer Enrollment Report' title
  210. END
  211. GO