财务查询存储过程.sql 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --------------------------------------------------------------------------------------------------------
  2. alter proc Query_Finance
  3. @OrderCount int output, --1.当天订单数; --
  4. @ReceiptCount int output, --2.当天收款次数; --
  5. @Oreder1 int output, --3.当天订单预约收款; --
  6. @Oreder2 int output, --4.当天订单补款; --
  7. @Oreder3 int output, --5.当天订单后期补款; --
  8. @Oreder4 int output, --6.当天订单使用储值卡消费金额; --
  9. @OtherReceipts int output, --7.当天其他收入; --
  10. @Payout int output, --8.当天支出; --
  11. @OtherSalary int output, --9.当天其他二销; --
  12. @MemberReceipts int output, --A.当天会员收入; --
  13. @GrossReceipts int output, --B.当天总收入; --总收入要扣除储值卡消费的;
  14. @NetReceipt int output --C.当天纯收入; --;
  15. as
  16. begin
  17. --1.获得当天的订单数目;
  18. select @OrderCount = count(distinct id) from dindanbukuan where 0=datediff(day,date,getdate())
  19. --2.当天收款次数;
  20. select @ReceiptCount = count(id) from dindanbukuan where 0=datediff(day,date,getdate())
  21. --3.当天订单预约收款;
  22. select @Oreder1 = sum(convert(int,money)) from dindanbukuan where 0=datediff(day,date,getdate()) and bz='预约收款'
  23. --4.当天订单补款;
  24. select @Oreder2 = sum(convert(int,money)) from dindanbukuan where 0=datediff(day,date,getdate()) and bz='预约补款'
  25. --5.当天订单后期补款;
  26. select @Oreder3 = sum(convert(int,money)) from dindanbukuan where 0=datediff(day,date,getdate()) and bz not in('预约收款','预约补款')
  27. --6.当天订单使用储值卡消费金额;
  28. select @Oreder4 = sum(convert(int,money)) from dindanbukuan where 0=datediff(day,date,getdate()) and paytype = '储值卡扣款'
  29. --7.当天其他收入;
  30. select @OtherReceipts = sum(convert(float,money)) from singleincome where 0=datediff(day,dat,getdate()) and sale2type is null
  31. --8.当天支出;
  32. select @Payout = sum(convert(float,money)) from gudingfeiyong where 0=datediff(day,dat,getdate())
  33. --9.当天其他二销;
  34. select @OtherSalary = sum(convert(float,money)) from singleincomemoneyview where 0=datediff(day,date,getdate())
  35. --10.当天会员收入;
  36. select @MemberReceipts = sum(convert(float,money)) from memberview where 0=datediff(day,date,getdate())
  37. --11.当天的总收入;
  38. set @GrossReceipts = 0
  39. if @Oreder1 is not null
  40. begin
  41. set @GrossReceipts = @GrossReceipts + @Oreder1
  42. end
  43. if @Oreder2 is not null
  44. begin
  45. set @GrossReceipts = @GrossReceipts + @Oreder2
  46. end
  47. if @Oreder3 is not null
  48. begin
  49. set @GrossReceipts = @GrossReceipts + @Oreder3
  50. end
  51. if @Oreder4 is not null
  52. begin
  53. set @GrossReceipts = @GrossReceipts - @Oreder4
  54. end
  55. if @OtherReceipts is not null
  56. begin
  57. set @GrossReceipts = @GrossReceipts + @OtherReceipts
  58. end
  59. if @OtherSalary is not null
  60. begin
  61. set @GrossReceipts = @GrossReceipts + @OtherSalary
  62. end
  63. --12.当天的纯收入;
  64. set @NetReceipt = (@GrossReceipts - @Payout)
  65. end