<?php namespace App\Http\Controllers;

use App\Business\EmployeeStatistics;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Util\IntervalTime;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;

class StatisticsController extends Controller
{

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        return view('statistics.index');
    }


    public function statisticLogInPerMonth(Request $request)
    {
       $emp=new EmployeeStatistics();

        //$date = new Carbon($request->get('date'));
        $id = $request->get('id');
        /* $begin =  $request->get('begin');
         $end = $request->get('end');
         $step = $request->get('step');*/
        $date = Carbon::now();
        $stats = [[]];

        $m = 00;
        $h = 7;
        $intervals = [];
        for ($i = 0; $i < 6; $i++) {
            $intervals[$i] = new IntervalTime();
            $intervals[$i]->setYear($date->year);
            $intervals[$i]->setMonth($date->month);
            if ($i % 2 == 0) {
                $h = $h + 1;
                $intervals[$i]->setHour($h);
                $intervals[$i]->setInf(00);
                $intervals[$i]->setSup(30);
            } else {
                $intervals[$i]->setInf(30);
                $intervals[$i]->setSup(59);
            }
        }
        $stats = [
            ['8h00 - 8h30', 8/*$emp->logInByInterval($id,$intervals[0])*/],
            ['8h30 - 9h00', 2],
            ['9h00 - 9h30', 2],
            ['9h30 - 10h00', 2],
            ['10h00 - 10h30', 7]
        ];
        return Response::json(compact('stats'));

    }

    public function statisticLogOutPerMonth(Request $request)
    {

        //$date = new Carbon($request->get('date'));
        $id = $request->get('id');
        /* $begin =  $request->get('begin');
         $end = $request->get('end');
         $step = $request->get('step');*/
        $date = Carbon::now();
        $stats = [[]];

        $m = 00;
        $h = 15;
        $intervals = [];
        for ($i = 0; $i < 6; $i++) {
            $intervals[$i] = new IntervalTime();
            $intervals[$i]->setYear($date->year);
            $intervals[$i]->setMonth($date->month);
            if ($i % 2 == 0) {
                $h = $h + 1;
                $intervals[$i]->setHour($h);
                $intervals[$i]->setInf(00);
                $intervals[$i]->setSup(30);
            } else {
                $intervals[$i]->setInf(30);
                $intervals[$i]->setSup(59);
            }
            $stats = [
                ['16h00 - 16h30', 11],
                ['16h30 - 17h00', 2],
                ['17h00 - 17h30', 2],
                ['17h30 - 18h00', 2],
                ['18h00 - 18h30', 7]
            ];
            return Response::json(compact('stats'));

        }


    }
}
