public function getResults()
 {
     $input = Request::createFromGlobals();
     $steps = Step::where('step_flow', $_SESSION['user_flow'])->get();
     foreach ($steps as $step) {
         $records = Reclamo::with(['ef_request.dates' => function ($query) use($step) {
             return $query->whereDateFlow($step->step_flow)->whereDateStep($step->step_id);
         }]);
         $records = $this->applyFilters($records);
         $records = $records->get();
         $subtotalArray = ['work' => 0, 'non-work' => 0, 'total' => 0];
         $dateCount = 0;
         foreach ($records as $record) {
             foreach ($record->ef_request->dates as $date) {
                 $date_end = $date->date_end ? $date->date_end : date('Y-m-d H:i:s');
                 $timeArray = TimeController::getHours($date->date_start, $date_end);
                 $subtotalArray['work'] += $timeArray['work'];
                 $subtotalArray['non-work'] += $timeArray['non-work'];
                 $subtotalArray['total'] += $timeArray['total'];
                 $dateCount++;
             }
         }
         if ($dateCount > 0) {
             $subtotalArray['work'] = $subtotalArray['work'] / $dateCount;
             $subtotalArray['non-work'] = $subtotalArray['non-work'] / $dateCount;
             $subtotalArray['total'] = $subtotalArray['total'] / $dateCount;
         }
         $step->elapsed_time = $subtotalArray;
     }
     return $steps;
 }
 public function getResults()
 {
     $input = Request::createFromGlobals();
     $records = [];
     $steps = Step::where('step_flow', $_SESSION['user_flow'])->get();
     $reclamos = Reclamo::with('ef_request.dates');
     $reclamos = $this->applyFilters($reclamos);
     $reclamos = $reclamos->get();
     foreach ($reclamos as $reclamo) {
         $record = ['reclamo' => $reclamo->ef_request->request_inner_id, 'times' => [], 'total' => 0];
         // Iterate steps and load times/totals
         foreach ($steps as $step) {
             $step_time = 0;
             $dates = $reclamo->ef_request->dates->filter(function ($date) use($step) {
                 return $date->date_step == $step->step_id;
             });
             foreach ($dates as $date) {
                 $timeArray = TimeController::getHours($date->date_start, $date->date_end);
                 if ($input->duration == 'calendar') {
                     $step_time += $timeArray['total'] / 24;
                 } else {
                     $step_time += $timeArray['work'] / 8;
                 }
             }
             $stepArray = ['name' => $step->step_name, 'time' => number_format($step_time, 2)];
             $record['times'][] = $stepArray;
         }
         // Add totals
         foreach ($record['times'] as $time) {
             $record['total'] += $time['time'];
         }
         $records[] = $record;
     }
     return compact('records', 'steps');
 }