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.

63 lines
2.0 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[PROC_PayingAgentSettlementReport] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[PROC_PayingAgentSettlementReport]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[PROC_PayingAgentSettlementReport] 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_PayingAgentSettlementReport]
  12. @fdate varchar(10)
  13. ,@toDate varchar(20)
  14. ,@flag varchar(10)
  15. ,@user varchar(50)
  16. ,@agentId INT = null
  17. AS
  18. SET NOCOUNT ON
  19. --select @fdate='2017-10-10',@toDate='2017-10-13'
  20. set @toDate = @toDate +' 23:59:59'
  21. if @flag = 's'
  22. begin
  23. select pAgentName 'Paying Agent' ,cnt [Count]
  24. ,'Average NPR Rate' = pCurrCostRate/cnt,tAmt 'Principal KRW',pAmt 'Principal NPR'
  25. ,principalUSD 'Principal USD',commUSD 'Comm USD' from (
  26. select pAgentName,cnt = count('a'),pCurrCostRate = sum(pCurrCostRate),tAmt=sum(tAmt),pAmt = sum(pAmt)
  27. ,'principalUSD' = sum(pAmt/pCurrCostRate) ,'commUSD' = sum(sAgentComm/pCurrCostRate)
  28. from remittran(nolock)
  29. where createdDate between @fdate and @toDate
  30. AND pAgent = ISNULL(@agentId,pAgent)
  31. GROUP BY pAgentName
  32. )x
  33. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  34. SELECT 'From Date ' head,@fdate value
  35. UNION ALL
  36. SELECT 'To Date ' head,@toDate value
  37. SELECT 'Paying Agent Settlement Report Summary' title
  38. end
  39. else if @flag = 'detail1'
  40. begin
  41. select pAgentName 'Paying Agent',controlno = dbo.FNADecryptString(controlNo),'USD-NPR' = pCurrCostRate,'Principal KRW' = tAmt,
  42. 'Principal NPR' = pAmt,'Comm KRW' = sAgentComm,'Principal USD' = pAmt/pCurrCostRate,'Comm USD'=sAgentComm/pCurrCostRate
  43. ,'USD-KRW'=sCurrCostRate
  44. from remittran(nolock)
  45. where createdDate between @fdate and @toDate
  46. AND ISNULL(pAgent, 1056) = ISNULL(@agentId,1056)
  47. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  48. SELECT 'From Date ' head,@fdate value
  49. UNION ALL
  50. SELECT 'To Date ' head,@toDate value
  51. SELECT 'Paying Agent Settlement Report Summary' title
  52. end
  53. GO