@extends(('layouts/compact_menu'))
{{-- Page title --}}
@section('title')
    Dashboard
    @parent
@stop
{{-- page level styles --}}
@section('header_styles')
    <link type="text/css" rel="stylesheet" href="{{asset('vendors/chartist/css/chartist.min.css')}}" />
    <link type="text/css" rel="stylesheet" href="{{asset('vendors/circliful/css/jquery.circliful.css')}}">
    <link type="text/css" rel="stylesheet" href="{{asset('css/pages/index.css')}}">

    <style type="text/css">
        .bold{
            font-weight: bold;
        }
    </style>
@stop
@section('content')

    <header class="head">
        <div class="main-bar">
            <div class="row no-gutters">
                <div class="col-6">
                    <h4 class="m-t-5">
                        <i class="fa fa-home"></i>
                        Dashboard
                    </h4>
                </div>
            </div>
        </div>
    </header>
    <div class="outer">
        <div class="inner bg-container">
            <div class="clearfix"></div>

            @include('flash::message')

            <div class="clearfix"></div>
            @if(!is_running_job())
            <div class="row widget_countup">
                <div class="col-md-12 p-d-15 col-sm-12">
                    <div id="top_widget1">
                        <a href="{{route('import-command')}}" class="btn btn-primary">Import Data</a>
                    </div>
                </div>
            </div>
            @endif
            <div class="row ">
                <div class="col">
                    <div class="card">
                        <div class="card-header bg-white">
                            <span class="card-title">Global Snapshot</span>
                            
                        </div>
                        <div class="card-body">
                           <form>
                                <div class="form-group row form_inline_inputs_bot">
                                    
                                    <div class="col-lg-3" style="margin-top: 10px;">
                                        <select class="form-control chzn-select" name="level_select" id="level_select">
                                            @foreach($levels as $l)
                                            <option value="{{$l->id}}">{{$l->label}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </form>
                            <div class="table-responsive m-t-20">
                                <table class="table table-stripped table-bordered" id="global_table">
                                    <thead>
                                        <tr>
                                            <th width="50%"></th>
                                            <th width="50%">TOTAL</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row m-t-35">
                <div class="col">
                    <div class="card">
                        <div class="card-header bg-white">
                            <span class="card-title">Workload</span>
                            
                        </div>
                        <div class="card-body">
                           <form>
                                <div class="form-group row form_inline_inputs_bot">
                                    
                                    <div class="col-lg-3" style="margin-top: 10px;">
                                        <select class="form-control chzn-select" name="level_select_workload" id="level_select_workload">
                                            @foreach($levels_workload as $l)
                                            <option value="{{$l->id}}">{{$l->label}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </form>
                            <div class="table-responsive m-t-20">
                                <table class="table table-stripped table-bordered" id="workload_table">
                                    <thead>
                                        <tr>
                                            <th width="50%">Boards</th>
                                            <th width="50%">TOTAL</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row m-t-35">
                <div class="col">
                    <div class="card">
                        <div class="card-header bg-white">
                            <span class="card-title">Exception</span>
                            
                        </div>
                        <div class="card-body">
                           <form>
                                <div class="form-group row form_inline_inputs_bot">
                                    <div class="col-lg-3" style="margin-top: 10px;">
                                        <select class="form-control chzn-select" name="board_select_exception" id="board_select_exception">
                                            @foreach($boards as $b)
                                            <option value="{{$b->id}}">{{$b->name}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-lg-3" style="margin-top: 10px;">
                                        <select class="form-control chzn-select" name="level_select_exception" id="level_select_exception">
                                            @foreach($levels_exception as $l)
                                            <option value="{{$l->id}}">{{$l->label}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </form>
                            <div class="table-responsive m-t-20">
                                <table class="table table-stripped table-bordered" id="exception_table">
                                    <thead>
                                        <tr>
                                            <th width="50%">Job No.</th>
                                            <th width="25%">Exceed Estimate 10%</th>
                                            <th width="25%">Assigned User</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@stop
@section('footer_scripts')
    <!--  plugin scripts -->
    <script type="text/javascript" src="{{asset('vendors/countUp.js/js/countUp.min.js')}}"></script>
    <script type="text/javascript" src="{{asset('vendors/flip/js/jquery.flip.min.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/pluginjs/jquery.sparkline.js')}}"></script>
    <script type="text/javascript" src="{{asset('vendors/chartist/js/chartist.min.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/pluginjs/chartist-tooltip.js')}}"></script>
    <script type="text/javascript" src="{{asset('vendors/swiper/js/swiper.min.js')}}"></script>
    <script type="text/javascript" src="{{asset('vendors/circliful/js/jquery.circliful.js')}}"></script>
    <script type="text/javascript" src="{{asset('vendors/flotchart/js/jquery.flot.js')}}" ></script>
    <script type="text/javascript" src="{{asset('vendors/flotchart/js/jquery.flot.resize.js')}}"></script>
    <!--end of plugin scripts-->

    <script type="text/javascript" src="{{asset('vendors/datatables/js/jquery.dataTables.js')}}"></script>
<script type="text/javascript" src="{{asset('js/pluginjs/dataTables.tableTools.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/dataTables.colReorder.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/dataTables.bootstrap4.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/dataTables.buttons.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/dataTables.responsive.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/responsive.bootstrap4.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/dataTables.rowReorder.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/buttons.colVis.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/buttons.html5.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/buttons.bootstrap.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/buttons.print.min.js')}}"></script>
<script type="text/javascript" src="{{asset('vendors/datatables/js/dataTables.scroller.min.js')}}"></script>
<!-- end of plugin scripts -->
<!--Page level scripts-->
<script type="text/javascript" src="{{asset('js/pages/simple_datatables.js')}}"></script>

<script type="text/javascript" src="{{asset('js/pages/index.js')}}"></script>
    <script type="text/javascript">
    $(document).ready(function() {

        var table = $('#global_table').DataTable({
            processing: true,
            serverSide: true,
            "bPaginate": false,
            "bFilter": false,
            "bInfo": false,
            "ordering": false,
            ajax: {
                    url: '{{ route("get_global_data") }}',
                    type: "POST",
                    data: function (d) {
                        d._token = "{{ csrf_token() }}"
                        d.level_select = $("#level_select").val();
                    }
                },
            columns: [
                { data: 'name', name: 'name' },
                { data: 'total', name: 'total' },
            ],
            'columnDefs': [
               {
                    "targets": 1,
                    "className": "text-center bold",
               }
             ]
            }); 

        load_datatable();

        $("#level_select").on("change", function(){
            load_datatable();
        })


        function load_datatable()
        {
           table.ajax.reload();
        }


        //Workload

        var table_workload = $('#workload_table').DataTable({
            processing: true,
            serverSide: true,
            "bPaginate": false,
            "bFilter": false,
            "bInfo": false,
            "ordering": false,
            ajax: {
                    url: '{{ route("get_workload_data") }}',
                    type: "POST",
                    data: function (d) {
                        d._token = "{{ csrf_token() }}"
                        d.level_select = $("#level_select_workload").val();
                    },
                    "dataSrc": function (json) {
                      var return_data = new Array();
                      for(var i=0;i< json.data.length; i++){
                        var total_str = "";
                        total_str += json.data[i].total['task']+'&nbsp;&nbsp;&nbsp;';
                        total_str += json.data[i].total['et']+'&nbsp;&nbsp;&nbsp;';
                        total_str += json.data[i].total['lt']+'&nbsp;&nbsp;&nbsp;';
                        return_data.push({
                          'name': json.data[i].name,
                          'total'  :  total_str,
                        })
                      }
                      return return_data;
                    },
                },
            columns: [
                { data: 'name', name: 'name' },
                { data: 'total', name: 'total' },
            ],
            'columnDefs': [
               {
                    "targets": 1,
                    "className": "text-center bold",
               }
             ]
            }); 

        load_datatable_workload();

        $("#level_select_workload").on("change", function(){
            load_datatable_workload();
        })


        function load_datatable_workload()
        {
           table_workload.ajax.reload();
        }

        //Exception

        var table_exception = $('#exception_table').DataTable({
            processing: true,
            serverSide: true,
            "bPaginate": false,
            "bFilter": false,
            "bInfo": false,
            "ordering": false,
            ajax: {
                    url: '{{ route("get_exception_data_d") }}',
                    type: "POST",
                    data: function (d) {
                        d._token = "{{ csrf_token() }}"
                        d.level_select = $("#level_select_exception").val();
                        d.board = $("#board_select_exception").val();
                    }
                },
            columns: [
                { data: 'name', name: 'name' },
                { data: 'exceed_estimate', name: 'exceed_estimate' },
                { data: 'assigned_user', name: 'assigned_user' },
            ],
            'columnDefs': [
               {
                    "targets": 1,
                    "className": "text-center bold",
               },
               {
                    "targets": 2,
                    "className": "text-center",
               }
             ]
            }); 

        load_datatable_exception();

        $("#level_select_exception").on("change", function(){
            load_datatable_exception();
        })

        $("#board_select_exception").on("change", function(){
            load_datatable_exception();
        })


        function load_datatable_exception()
        {
           table_exception.ajax.reload();
        }

        
    })
</script>
@stop
