Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. protected function generateAverage($staff, $type)
  2. {
  3. $months = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  4. $staff = array_map(function ($row) use ($type) {
  5. if ($row['row_type'] == $type) {
  6. return $row;
  7. }
  8. }, $staff);
  9.  
  10. foreach ($staff as $key => $employee) {
  11. $months[0] += $employee['amounts'][0];
  12. $months[1] += $employee['amounts'][1];
  13. $months[2] += $employee['amounts'][2];
  14. $months[3] += $employee['amounts'][3];
  15. $months[4] += $employee['amounts'][4];
  16. $months[5] += $employee['amounts'][5];
  17. $months[6] += $employee['amounts'][6];
  18. $months[7] += $employee['amounts'][7];
  19. $months[8] += $employee['amounts'][8];
  20. $months[9] += $employee['amounts'][9];
  21. $months[10] += $employee['amounts'][10];
  22. $months[11] += $employee['amounts'][11];
  23. }
  24. $months = array_map(function ($value) use ($staff) {
  25. return $value / (count($staff) / 2);
  26. }, $months);
  27. $months[] = array_sum($months);
  28. return $months;
  29. }
  30.  
  31. array:6 [
  32. 0 => array:4 [
  33. "amounts" => array:13 [
  34. 0 => "30000.00"
  35. 1 => "30000.00"
  36. 2 => "30000.00"
  37. 3 => "30000.00"
  38. 4 => "30000.00"
  39. 5 => "30000.00"
  40. 6 => "30000.00"
  41. 7 => "30000.00"
  42. 8 => "30000.00"
  43. 9 => "30000.00"
  44. 10 => "30000.00"
  45. 11 => "30000.00"
  46. 12 => 360000.0
  47. ]
  48. "image" => "test.jpg"
  49. "row_name" => "Target"
  50. "row_type" => "target"
  51. ]
  52. ...
  53.  
  54. $data['aggregates']['Target average'] = $this->generateAverage(array_values($data['staff']), 'target');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement