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.

112 lines
4.1 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_KJDepositReport] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_KJDepositReport]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_KJDepositReport] 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 proc [dbo].[proc_KJDepositReport]
  12. @flag varchar(10),
  13. @startDate varchar(10),
  14. @endDate varchar(20),
  15. @user varchar(40),
  16. @searchType varchar(30) = null,
  17. @searchValue varchar(150) = null
  18. as
  19. set nocount on
  20. if @flag = 's'
  21. begin
  22. select [Bank Name] = k.BankName,[Sum Amount] = sum(d.amount),[No of Txn] = count(1)
  23. from TblVirtualBankDepositDetail d(nolock)
  24. LEFT join KoreanBankList k on k.bankCode = d.institution
  25. where d.logDate between @startDate and @endDate+' 23:59:59'
  26. group by k.BankName
  27. end
  28. if @flag = 'd'
  29. begin
  30. select [Bank Name] =k.BankName,[Received On] = d.receivedOn
  31. ,[Customer Name] = CASE WHEN d.customerName ='Nnull' THEN D.depositor ELSE d.customerName END
  32. ,[Primary Ac No] = d.no,[Virtual Ac No] = d.virtualAccountNo,[Amount] = d.amount
  33. from TblVirtualBankDepositDetail d(nolock)
  34. LEFT join KoreanBankList k on k.bankCode = d.institution
  35. where d.logDate between @startDate and @endDate+' 23:59:59'
  36. end
  37. if @flag = 'statement'
  38. begin
  39. DECLARE @customerId BIGINT
  40. DECLARE @table TABLE (customerId BIGINT, email VARCHAR(150))
  41. if @searchValue is not null
  42. begin
  43. DECLARE @sql VARCHAR(150) = 'SELECT customerId, email FROM customerMaster CM (NOLOCK) WHERE 1 = 1 '
  44. DECLARE @sqlFilter VARCHAR(200) = ''
  45. IF ISNULL(@searchValue,'')<>'' AND ISNULL(@searchType,'')<>''
  46. BEGIN
  47. IF @searchType='idNumber'
  48. BEGIN
  49. --IF ISNUMERIC(@searchValue)<>1
  50. -- SET @searchValue='-1' --to ignore string value for datatype integer/customerID
  51. --SET @sql_Filter=@sql_Filter + ' AND customerId = ''' +@searchValue+''''
  52. SET @sqlFilter=@sqlFilter + ' AND REPLACE(idNumber, ''-'', '''') = ''' +REPLACE(@searchValue, '-', '')+''''
  53. END
  54. ELSE IF @searchType='emailId'
  55. SET @sqlFilter=@sqlFilter + ' AND email like ''' +@searchValue+'%'''
  56. ELSE IF @searchType='customerName'
  57. SET @sqlFilter=@sqlFilter + ' AND fullName like ''' +@searchValue+'%'''
  58. ELSE IF @searchType='mobile'
  59. SET @sqlFilter=@sqlFilter + ' AND mobile = ''' +@searchValue+''''
  60. ELSE IF @searchType='walletAccountNo'
  61. SET @sqlFilter=@sqlFilter + ' AND walletAccountNo = ''' +@searchValue+''''
  62. ELSE IF @searchType='bankAccountNo'
  63. SET @sqlFilter=@sqlFilter + ' AND bankAccountNo = ''' +@searchValue+''''
  64. END
  65. INSERT INTO @table(customerId, email)
  66. EXEC(@sql+@sqlFilter)
  67. end
  68. select sum(amount) amount,virtualAccountNo,c.email,(c.availableBalance) availableBalance ,c.FullName
  69. into #temp
  70. from TblVirtualBankDepositDetail t(nolock)
  71. inner join customermaster c(nolock) on c.walletAccountNo = t.virtualAccountNo
  72. WHERE T.logDate between @startDate and @endDate+' 23:59:59'
  73. group by virtualAccountNo,c.email,c.availableBalance,c.FullName
  74. select createdBy,sum(camt) camt into #txn
  75. from remittran(nolock) where tranStatus <> 'cancel'
  76. AND createdDate between @startDate and @endDate+' 23:59:59'
  77. group by createdBy
  78. if @searchValue is not null
  79. begin
  80. select FullName,t.email,T.virtualAccountNo,sum(t.amount)'Deposited Amount', sum(camt) 'Send Amount',sum(t.amount-camt) 'Available Balance'
  81. ,(t.availableBalance) 'Balance Seen In System'
  82. from #temp t
  83. left join #txn x on x.createdBy = t.email
  84. inner join @table tmp on tmp.email = t.email
  85. group by t.email,T.virtualAccountNo,t.availableBalance,FullName
  86. end
  87. else
  88. begin
  89. select FullName,t.email,T.virtualAccountNo,sum(t.amount)'Deposited Amount', sum(camt) 'Send Amount',sum(t.amount-camt) 'Available Balance'
  90. ,(t.availableBalance) 'Balance Seen In System'
  91. from #temp t
  92. left join #txn x on t.email = x.createdBy
  93. group by t.email,T.virtualAccountNo,t.availableBalance,FullName
  94. --having sum(t.amount-x.camt-T.availableBalance) >0
  95. --having sum(t.amount-camt) <> (t.availableBalance)
  96. end
  97. end
  98. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  99. SELECT 'From Date ' head,@startDate value union all
  100. SELECT 'To Date ' head,@endDate value
  101. SELECT 'Bank Deposit Report' title
  102. GO