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.

254 lines
14 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_creditDetailReport] 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_creditDetailReport
  10. @flag = 'b'
  11. ,@user = 'admin'
  12. ,@fromDate = '2010-01-01'
  13. ,@toDate = '2014-12-31'
  14. */
  15. CREATE procEDURE [dbo].[proc_creditDetailReport]
  16. @flag VARCHAR(20)
  17. ,@user VARCHAR(30)
  18. ,@issuedDateFrom DATETIME = NULL
  19. ,@issuedDateTo DATETIME = NULL
  20. ,@validDateFrom DATETIME = NULL
  21. ,@validDateTo DATETIME = NULL
  22. ,@followUpDateFrom DATETIME = NULL
  23. ,@followUpDateTo DATETIME = NULL
  24. ,@sAgent INT = NULL
  25. ,@country INT = NULL
  26. ,@agentId INT = NULL
  27. AS
  28. DECLARE
  29. @sql VARCHAR(MAX)
  30. ,@table VARCHAR(MAX)
  31. ,@selectList VARCHAR(MAX)
  32. --Filters 2
  33. IF @flag = 'b' -- Bank Guarantee
  34. BEGIN
  35. SET @sql = ''
  36. IF @agentId IS NOT NULL
  37. SET @sql = @sql + ' AND main.agentId = ' + CAST(@agentId AS VARCHAR) + ''
  38. IF @issuedDateFrom IS NOT NULL
  39. SET @sql = @sql + ' AND main.issuedDate >= ''' + @issuedDateFrom + ''''
  40. IF @issuedDateTo IS NOT NULL
  41. SET @sql = @sql + ' AND main.issuedDate <= ''' + @issuedDateTo + ' 23:59:59'''
  42. IF @validDateFrom IS NOT NULL
  43. SET @sql = @sql + ' AND main.validDate >= ''' + @validDateFrom + ''''
  44. IF @validDateTo IS NOT NULL
  45. SET @sql = @sql + ' AND main.validDate <= ''' + @validDateTo + ' 23:59:59'''
  46. IF @followUpDateFrom IS NOT NULL
  47. SET @sql = @sql + ' AND main.followUpDate >= ''' + @followUpDateFrom + ''''
  48. IF @followUpDateTo IS NOT NULL
  49. SET @sql = @sql + ' AND main.followUpDate <= ''' + @followUpDateTo + ' 23:59:59'''
  50. SET @table = '
  51. SELECT
  52. [Agent Name] = am.agentName
  53. ,[Guarantee No] = main.guaranteeNo
  54. ,[Amount] = main.amount
  55. ,[Currency] = curr.currencyCode
  56. ,[Bank Name] = main.bankName
  57. ,[Issued Date] = main.issuedDate
  58. ,[Expiry Date] = main.expiryDate
  59. ,[FollowUp Date] = main.followUpDate
  60. FROM bankGuarantee main
  61. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  62. LEFT JOIN currencyMaster curr WITH(NOLOCK) ON main.currency = curr.currencyId
  63. WHERE 1 = 1
  64. '
  65. SET @sql = 'SELECT * FROM ('
  66. + @table
  67. + @sql
  68. +
  69. ' ) x '
  70. PRINT @table
  71. EXEC (@sql)
  72. END
  73. ELSE IF @flag = 'm'
  74. BEGIN
  75. SET @sql = ''
  76. IF @agentId IS NOT NULL
  77. SET @sql = @sql + ' AND main.agentId = ' + CAST(@agentId AS VARCHAR) + ''
  78. IF @issuedDateFrom IS NOT NULL
  79. SET @sql = @sql + ' AND main.valuationDate >= ''' + @issuedDateFrom + ''''
  80. IF @issuedDateTo IS NOT NULL
  81. SET @sql = @sql + ' AND main.valuationDate <= ''' + @issuedDateTo + ' 23:59:59'''
  82. SET @table = '
  83. SELECT
  84. [Agent Name] = am.agentName
  85. ,[Registration Office] = main.regOffice
  86. ,[Registration No] = main.mortgageRegNo
  87. ,[ValuationAmount] = main.valuationAmount
  88. ,[Currency] = curr.currencyCode
  89. ,[Valuator] = main.valuator
  90. ,[Mortgage Date] = main.valuationDate
  91. ,[Property Type] = pt.detailTitle
  92. ,[Plot No] = main.plotNo
  93. ,[Ownner] = main.owner
  94. FROM mortgage main
  95. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  96. LEFT JOIN currencyMaster curr WITH(NOLOCK) ON main.currency = curr.currencyId
  97. LEFT JOIN staticDataValue pt WITH(NOLOCK) ON main.propertyType = pt.valueId
  98. WHERE 1 = 1
  99. '
  100. SET @sql = 'SELECT * FROM ('
  101. + @table
  102. + @sql
  103. +
  104. ' ) x '
  105. PRINT @table
  106. EXEC (@sql)
  107. END
  108. ELSE IF @flag = 'c'
  109. BEGIN
  110. SET @sql = ''
  111. IF @agentId IS NOT NULL
  112. SET @sql = @sql + ' AND main.agentId = ' + CAST(@agentId AS VARCHAR) + ''
  113. IF @issuedDateFrom IS NOT NULL
  114. SET @sql = @sql + ' AND main.depositedDate >= ''' + @issuedDateFrom + ''''
  115. IF @issuedDateTo IS NOT NULL
  116. SET @sql = @sql + ' AND main.depositedDate <= ''' + @issuedDateTo + ' 23:59:59'''
  117. SET @table = '
  118. SELECT
  119. [Agent Name] = am.agentName
  120. ,[Deposit Account No] = main.depositAcNo
  121. ,[Cash Deposit] = main.cashDeposit
  122. ,[Currency] = curr.currencyCode
  123. ,[Deposited Date] = main.depositedDate
  124. FROM cashSecurity main
  125. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  126. LEFT JOIN currencyMaster curr WITH(NOLOCK) ON main.currency = curr.currencyId
  127. WHERE 1 = 1
  128. '
  129. SET @sql = 'SELECT * FROM ('
  130. + @table
  131. + @sql
  132. +
  133. ' ) x '
  134. PRINT @table
  135. EXEC (@sql)
  136. END
  137. ELSE IF @flag = 'f'
  138. BEGIN
  139. SET @sql = ''
  140. IF @agentId IS NOT NULL
  141. SET @sql = @sql + ' AND main.agentId = ' + CAST(@agentId AS VARCHAR) + ''
  142. IF @issuedDateFrom IS NOT NULL
  143. SET @sql = @sql + ' AND main.issuedDate >= ''' + @issuedDateFrom + ''''
  144. IF @issuedDateTo IS NOT NULL
  145. SET @sql = @sql + ' AND main.issuedDate <= ''' + @issuedDateTo + ' 23:59:59'''
  146. IF @validDateFrom IS NOT NULL
  147. SET @sql = @sql + ' AND main.validDate >= ''' + @validDateFrom + ''''
  148. IF @validDateTo IS NOT NULL
  149. SET @sql = @sql + ' AND main.validDate <= ''' + @validDateTo + ' 23:59:59'''
  150. IF @followUpDateFrom IS NOT NULL
  151. SET @sql = @sql + ' AND main.followUpDate >= ''' + @followUpDateFrom + ''''
  152. IF @followUpDateTo IS NOT NULL
  153. SET @sql = @sql + ' AND main.followUpDate <= ''' + @followUpDateTo + ' 23:59:59'''
  154. SET @table = '
  155. SELECT
  156. [Agent Name] = am.agentName
  157. ,[Fixed Deposit No] = main.fixedDepositNo
  158. ,[Amount] = main.amount
  159. ,[Currency] = curr.currencyCode
  160. ,[Bank Name] = main.bankName
  161. ,[Issued Date] = main.issuedDate
  162. ,[Expiry Date] = main.expiryDate
  163. ,[FollowUp Date] = main.followUpDate
  164. FROM fixedDeposit main
  165. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  166. LEFT JOIN currencyMaster curr WITH(NOLOCK) ON main.currency = curr.currencyId
  167. WHERE 1 = 1
  168. '
  169. SET @sql = 'SELECT * FROM ('
  170. + @table
  171. + @sql
  172. +
  173. ' ) x '
  174. PRINT @table
  175. EXEC (@sql)
  176. END
  177. ELSE IF @flag = 'l'
  178. BEGIN
  179. SET @sql = ''
  180. IF @agentId IS NOT NULL
  181. SET @sql = @sql + ' AND main.agentId = ' + CAST(@agentId AS VARCHAR) + ''
  182. IF @validDateFrom IS NOT NULL
  183. SET @sql = @sql + ' AND main.expiryDate >= ''' + @validDateFrom + ''''
  184. IF @validDateTo IS NOT NULL
  185. SET @sql = @sql + ' AND main.expiryDate <= ''' + @validDateTo + ' 23:59:59'''
  186. SET @table = '
  187. SELECT
  188. [Agent Name] = am.agentName
  189. ,[Limit Amount] = main.limitAmt
  190. ,[Per Top Up Amount] = main.perTopUpAmt
  191. ,[Max Limit Amount] = main.maxLimitAmt
  192. ,[Currency] = curr.currencyCode
  193. ,[Expiry Date] = main.expiryDate
  194. FROM creditLimit main
  195. LEFT JOIN agentMaster am WITH(NOLOCK) ON main.agentId = am.agentId
  196. LEFT JOIN currencyMaster curr WITH(NOLOCK) ON main.currency = curr.currencyId
  197. WHERE 1 = 1
  198. '
  199. SET @sql = 'SELECT * FROM ('
  200. + @table
  201. + @sql
  202. +
  203. ' ) x '
  204. PRINT @table
  205. EXEC (@sql)
  206. END
  207. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  208. SELECT '' head, '' value from (select 0 id ) x where id <> 0
  209. SELECT 'Credit Detail Report' title
  210. GO