ahmedrahil786

Tracking different types of charges - Insurance as well

Nov 7th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. ######## weekly Revenue Related Info
  2.  
  3. set @startDate = "2019-11-01 00:00:00";
  4.  
  5. select
  6. rm.date as date,
  7. rm.resv as resv,
  8. sum(rm.nr) as netrevenues,
  9. sum(rm.rent) as rental,
  10. sum(rm.d2d) as d2d,
  11. sum(rm.insurance) as insurance,
  12. sum(rm.mileage) as mileage,
  13. sum(rm.paid_coupon) as Coupon
  14.  
  15. from
  16. (select
  17. Date(r.return_at + interval '8' hour) as date,
  18. count(r.id) as resv,
  19. sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','d2d','oneway','mileage')),0)) as rent,
  20. sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('d2d')),0)) as d2d,
  21. sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('oneway')),0)) as oneway,
  22. sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('mileage')),0)) as mileage,
  23. sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('subscriptionFee')),0)) as subscriptionFee,
  24. sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('insurance')),0)) as insurance,
  25. sum(ifnull((select sum(amount) from payments where state='normal' and r.id=reservation_id and paid_type='coupon'),0)) as paid_coupon,
  26. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','oneway','d2d','mileage')),0)- ifnull((select sum(amount) from payments where state='normal' and reservation_id=r.id and paid_type ='coupon'),0)),2) as nr
  27. from reservations r, members m
  28.  
  29. where r.member_id=m.id
  30. and m.imaginary in ('normal','sofam')
  31. and r.state = 'completed'
  32. and convert_tz(r.return_at, '+0:00','+8:00') >= @startdate
  33. group by 1
  34. ) rm
  35. group by rm.date
  36. order by 1 desc ;
Advertisement
Add Comment
Please, Sign In to add comment