ahmedrahil786

Daily signups, With card_upload info

Jul 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. ### link to access dashboard : https://docs.google.com/spreadsheets/d/1FGq9PXBEcT9UKh1sTsAcy4N36cJV6lqqHDR0CL2ZWzY/edit#gid=275227634
  2.  
  3. set @start := '2019-1-1';
  4.  
  5. select
  6. A.date,
  7. D.signups,
  8. C.DocUploaded,
  9. C.DocApproved,
  10. C.rejected,
  11. F.paymentupload,
  12. F.cardupload,
  13. F.grabpay,
  14. A.TotalMFTs,
  15. A.mft_21,
  16. B.ActiveMembers,
  17. B.Bookings,
  18. round(E.Net_Rev,2) as Net_rev,
  19. round(E.gross_rev,2) as gross_rev,
  20. round(E.Coupon_Rev,2) as Coupon_Rev,
  21. round((E.Coupon_Rev/E.gross_rev)*100,2) as Coupon_Rate,
  22. CAST((A.TOtalMFTs/B.ActiveMembers)*100 AS DECIMAL(18,2)) as MFT_DAUPct
  23. from (select
  24. date(c.created_at + interval '8' hour) as date,
  25. count(distinct case when c.kind = 'subscriptionFee' and str_to_date(m.birthday, '%Y%m%d') >= NOW() - interval '21' year then c.member_id end) as mft_21,
  26. count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as TotalMFTs
  27. from charges c
  28. join members m
  29. on m.id = c.member_id
  30. left outer join member_appendixes ma
  31. on ma.id = m.id
  32. where c.created_at + interval '8' hour >= @start
  33. #and c.created_at + interval '8' hour <= '2018-5-2 00:00
  34. and m.imaginary = 'normal'
  35. group by 1) A
  36. join (
  37. select
  38. date(r.return_at + interval '8' hour) as date,
  39. count(distinct case when r.state NOT IN ('canceled', 'fail') then r.member_id end) as ActiveMembers,
  40. count(distinct case when r.state = 'completed' then r.id end) as Bookings,
  41. count(distinct case when r.state NOT IN ('canceled', 'fail') then r.id end) as NonCancelledBookings,
  42. count(distinct case when r.state = 'fail' then r.id end) as FailedBookings,
  43. count(distinct case when r.state = 'fail' then r.member_id end) as UniqueFailedsids,
  44. sum(case when p.state = 'normal' and p.paid_type = 'card' then p.amount end) as NetRev,
  45. sum(case when p.state = 'normal' then p.amount end) as GrossRev
  46. from reservations r
  47. join members m
  48. on m.id = r.member_id and m.email not like '%socar.my%' and m.imaginary = 'normal'
  49. join payments p
  50. on p.reservation_id = r.id
  51. where r.return_at + interval '8' hour >= @start
  52. and p.state = 'normal'
  53. group by 1
  54. order by 1 asc) B
  55. on B.date = A.date
  56.  
  57. join (select
  58. Date(dl.created_at + interval '8' hour) as Date,
  59. count(distinct case when dl.state not like 'noInput' then dl.member_id end) DocUploaded,
  60. count(distinct case when dl.state = 'approved' then dl.member_id end) DocApproved,
  61. count(distinct case when dl.state = 'reject' then dl.member_id end) rejected,
  62. count(distinct case when dl.gender = 'man' then dl.member_id end) MaleApproved,
  63. count(distinct case when dl.gender = 'woman' then dl.member_id end) FemaleApproved
  64. from driver_licenses dl
  65. join members m on m.id = dl.member_id
  66. where dl.created_at + interval '8' hour >= @start
  67. and m.imaginary = 'normal'
  68. group by 1) C
  69. on C.Date = A.Date
  70. join
  71. (select date(pm.created_at + interval '8' hour) as date,
  72. count(distinct case when pm.state = 'approved' then pm.member_id end) paymentupload,
  73. count(distinct case when pm.state = 'approved' and pm.provider in ('braintree','dummymethod','mcp') then pm.member_id end) cardupload,
  74. count(distinct case when pm.state = 'approved' and pm.provider in ('grabpay') then pm.member_id end) grabpay
  75. from payment_methods pm
  76. where pm.created_at + interval '8' hour >= @start
  77. group by 1) F
  78. on F.date = A.date
  79.  
  80. join
  81.  
  82. (select
  83. Date(m.created_at + interval '8' hour) as Date,
  84. count(distinct m.id) as signups
  85. from members m
  86. left outer join reservations r on
  87. r.member_id = m.id
  88. where m.created_at + interval '8' hour >= @start
  89. and m.imaginary = 'normal'
  90. group by 1 ) D
  91. on D.Date = A.Date
  92.  
  93. Join
  94.  
  95. (select
  96. A.date as date,
  97. A.rev as gross_rev,
  98. B.coupon as Coupon_Rev,
  99. A.rev - B.coupon as Net_Rev
  100. from
  101. (select
  102. date(r.return_at + interval '8' hour) as date,
  103. sum(c.amount) as rev
  104. from charges c
  105. join reservations r
  106. on c.reservation_id = r.id
  107. where c.state = 'normal' and c.kind IN ('rent' , 'oneway', 'd2d', 'mileage')
  108. group by 1) A
  109. join
  110. (select
  111. date(r.return_at + interval '8' hour) as date,
  112. IFNULL(sum(p.amount),0) as coupon
  113. from payments p
  114. join reservations r on p.reservation_id = r.id
  115. where p.state = 'normal' and p.paid_type = 'coupon'
  116. group by 1) B
  117. on A.date = B.date) E
  118. on E.date = A.date
  119.  
  120. group by 1
  121. order by 1 desc
  122. ;
Advertisement
Add Comment
Please, Sign In to add comment