<!doctype html>
<html lang="en" class="h-100">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Zeitenauswertung</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css">
    <!-- JQuery -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
    
    <!-- Bootstrap -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
   
    <link rel="stylesheet" href="{{url('/css/bootstrap/bootstrap.dialogs.css')}}">
    <script src="{{url('/js/bootstrap.dialogs.js')}}"></script>
    
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    
    <script src="{{url('/js/x-editable.js')}}"></script>
    
    <script src="{{url('js/hwplus.js?1')}}"></script>
    
    <style type="text/css">
    
        
        
    </style>
    
    <script>
    
    </script>
    
    </head> 

    <body class="h-100 ">
    
        <div id="spinner" class="spinner spinner-border d-none" role="status">
            <span class="sr-only">Loading...</span>
        </div>
    
        <div class="container h-100" >
        
        
        <div class="btn-group mt-2 mb-2" role="group">
            <button type="button" class="btn btn-secondary" onclick="window.location='854e5746f03aaac88bb0e294185f2f14f168af43'"><i class="bi bi-files"></i></button>
            <button type="button" class="btn btn-secondary" onclick="window.location='9fc66b7e47269b60348557814c297de4cb2d8d12'"><i class="bi bi-file-bar-graph"></i></button>
        </div>
        
        
            @php 
                if(!request('month')) request()->merge(['month'=> date('m'), 'year' => date('Y')]); 
            @endphp
        
            Monat: <select id="month" onchange="window.location = '6ca633a39a30db63099945dda453f32ed976b44a?month=' + this.value + '&year=' + $('#year').val()">
                <option value="1" @php if(1 == request('month')) echo "selected"; @endphp>1</option>
                <option value="2" @php if(2 == request('month')) echo "selected"; @endphp>2</option>
                <option value="3" @php if(3 == request('month')) echo "selected"; @endphp>3</option>
                <option value="4" @php if(4 == request('month')) echo "selected"; @endphp>4</option>
                <option value="5" @php if(5 == request('month')) echo "selected"; @endphp>5</option>
                <option value="6" @php if(6 == request('month')) echo "selected"; @endphp>6</option>
                <option value="7" @php if(7 == request('month')) echo "selected"; @endphp>7</option>
                <option value="8" @php if(8 == request('month')) echo "selected"; @endphp>8</option>
                <option value="9" @php if(9 == request('month')) echo "selected"; @endphp>9</option>
                <option value="10" @php if(10 == request('month')) echo "selected"; @endphp>10</option>
                <option value="11" @php if(11 == request('month')) echo "selected"; @endphp>11</option>
                <option value="12" @php if(12 == request('month')) echo "selected"; @endphp>12</option>               
            </select>
            Jahr: <select name="year" id="year">
                <option value="2023">2023</option>
            </select>
            <div id="barchart_material" style="width: 900px; height: 500px;"></div>
        
        </div>
        
        

    
        <script type="text/javascript">

        google.charts.load('current', {'packages':['bar']});

        google.charts.setOnLoadCallback(drawChart);



        function drawChart() {
        
            @php
                $users = [];
                $staff = \App\Models\PHPXPress\HwplusStaff::get();
                foreach($staff->pluck('descriptor')->toArray() AS $user) $users[] = "'".$user."'";
            @endphp
            

            var data = google.visualization.arrayToDataTable([['Datum', @php echo implode(',', $users); @endphp], 
            
            @php
            
                $hours = DB::table('hwplus_manhours')
                ->select(DB::raw("SUM(Replace(workinghours, ',', '.')) AS workinghours, date_format(date, '%e') AS date, _staff"))
                ->whereRaw("MONTH(date) = " . request('month'))
                ->whereRaw("YEAR(date) = " . request('year'))
                ->groupBy('date')
                ->groupBy('_staff')
                ->get();
            
                // SELECT SUM(Replace(workinghours, ',', '.')), date_format(date, "%e"),_staff FROM `hwplus_manhours`  WHERE MONTH(date) = MONTH(now()) and YEAR(date) = YEAR(now()) group By date, _staff
            
                $d1 = date_create(request('year').'-'.request('month').'-01'); //current month/year
                $d2 = date_create($d1->format('Y-m-t')); //get last date of the month

                $days = date_diff($d1,$d2);

                $days_arr = [];
                $d = 1;
                do{
                    echo "[".$d.",";
                    foreach($staff AS $user) {
                        if($whs = $hours->where('date', $d)->where('_staff', $user->getKey())->first()) echo $whs->workinghours; else echo 0; echo ",";
                    }
                    echo "], ";
                    
                    $d++;
                }while ($d <= $days->days+1);

            @endphp
            
            
            ]);

    

            var options = {

            chart: {

                title: 'Arbeitszeiten',

                subtitle: '',

            },

            };

    

            var chart = new google.charts.Bar(document.getElementById('barchart_material'));

    

            chart.draw(data, google.charts.Bar.convertOptions(options));

        }
 
        </script>
    
    </body>
</html>
