calculateModel.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. class calculateModel extends Staple_Model
  3. {
  4. private $db;
  5. function __construct()
  6. {
  7. $this->db = Staple_DB::get();
  8. }
  9. function nearestQuarterHour($time)
  10. {
  11. //$time = strtotime($time);
  12. $round = 15*60;
  13. $rounded = round($time/$round)*$round;
  14. return date("g:i A", $rounded);
  15. }
  16. function timeToDecimal($time)
  17. {
  18. $timeArr = explode(':', $time);
  19. $hours = $timeArr[0]*1;
  20. $minutes = $timeArr[1]/60;
  21. $dec = $hours + $minutes;
  22. if($dec > 0)
  23. {
  24. return round($dec,2);
  25. }
  26. else
  27. {
  28. return 0;
  29. }
  30. }
  31. function calculatedTotals($uid,$startDate,$endDate)
  32. {
  33. $sql = "SELECT ROUND((TIME_TO_SEC(SEC_TO_TIME(SUM(outTime - inTime)-SUM(lessTime*60)))/3600)*4)/4 AS 'totalTime' FROM timeEntries WHERE inTime >= $startDate AND outTime <= $endDate AND userId = $uid";
  34. if($this->db->query($sql)->num_rows > 0)
  35. {
  36. $query = $this->db->query($sql);
  37. $result = $query->fetch_assoc();
  38. return round($result['totalTime'],2);
  39. }
  40. else
  41. {
  42. return 0;
  43. }
  44. }
  45. }