<?php

namespace App\Http\Controllers;
use App\Path;
use App\Car;
use GuzzleHttp\Client;
use Illuminate\Http\Request;

class AttendanceController extends Controller
{
    private $docker_ip="http://192.168.5.150:8086";

    public function atten(Request $request)
    {


        $query = Path::all();
        $main=Car::all();
        $client = new \GuzzleHttp\Client();
        $res = $client->get($this->docker_ip."/query?db=test&q=select%20*%20from%20people");
        $response = json_decode($res->getBody()->__toString(), true);



        $people_count=count($response['results'][0]['series'][0]['values']);
        $result_content=array();
        // dd($response[0]['Ports']);
        for($i=0;$i<$people_count;$i++){
            $dbname=$response['results'][0]['series'][0]['name'];
            $come_back=$response['results'][0]['series'][0]['values'][$i][1];
            $go_out=$response['results'][0]['series'][0]['values'][$i][2];
            $name=$response['results'][0]['series'][0]['values'][$i][3];
            $off_work=$response['results'][0]['series'][0]['values'][$i][4];
            $on_work=$response['results'][0]['series'][0]['values'][$i][5];
            // $array = Arr::add('Id',$response[$i]['Id']);
            array_push($result_content,['Names'=>$dbname,'come_back'=>$come_back,'go_out'=>$go_out,
            'name'=>$name,'off_work'=>$off_work,
            'on_work'=>$on_work]);
        }
        return View('index',['page' => 'attendance','result'=>$query,'iresult'=>$main,'content'=>$result_content,'navbar_li'=>'layouts.navbar_li','title'=>'tt']);
        
    }
        public function attend(Request $request)
                {
                    $start=$request->input('start_time');
                    $end=$request->input('end_time');
                    $start=strtotime("$start,now");
                    $end=strtotime("$end,now");
                    
                    return $start.$end;

                    echo $time;

                
                
                // dd($result_content);
                }

}
