@extends('layouts.master')

@section('content')
<!-- DataTables -->
<link rel="stylesheet" href="{{ asset('/assets/') }}/css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/switch/rcswitcher.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/pnotify.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/sweetalert.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/sweet-alert-animations.css">
<div class="panel panel-default" style="min-height: 500px">
    <!-- Default panel contents -->
    <div class="panel-heading"></div>
        <header class="panel-heading" style="height:50px;">
            <div class="pull-left">
                {{$title}}
            </div>
            <div>
                 {{-- @if(\Auth::user()->utype==1)
                    <a href="{{ url('admin/grade_structure/add') }}" class="btn btn-sm btn-info pull-right"><i class="fa fa-plus"></i> Add Grade Structure</a> <br><br>
                @endif --}}
            </div>
        </header>
    <div class="panel-body">
        @foreach($grade as $data)
        <div class="col-md-4">
          <div class="box" style="border: 1px solid #d4d4d4;background: #f0f0f0;">
            <div class="box-header with-border" style="text-align: center !important">
              <h4 class="tex-center">{{$data->name}}</h4>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table class="table table-bordered">
                <tbody>
                    <?php $newhead=array();$newgrade=array(); $total=0; ?>
                    @foreach($data->gradehead as $row)
                    <tr>
                      <td>{{$row->head->name}}</td>
                      <td  class="text-right">{{ number_format($row->amount,2) }}</td>
                      <?php  $total = $total + $row->amount; ?>
                    </tr>
                    <?php
                            $newhead[] = $row->head_id;
                            $newgrade[] = $row->grade_id;
                    ?>
                    @endforeach
                    @if(in_array($data->id,$newgrade))
                        @foreach($heads as $head)
                            @if(!in_array($head->id,$newhead))
                                <tr>
                                  <td>{{$head->name}}</td>
                                  <td  class="text-right">0</td>
                                </tr>
                            @endif
                        @endforeach
                    @else
                        @foreach($heads as $head)
                            <tr>
                              <td>{{$head->name}}</td>
                              <td  class="text-right">0</td>
                            </tr>   
                        @endforeach
                    @endif
                    <tr>
                      <td colspan="2" class="text-right">Total : &nbsp; {{ number_format($total,2) }}</td>
                    </tr>

                </tbody>
              </table><br/>
              <a href="{{ url('admin/grade_structure/edit/'.$data->id) }}" class="btn btn-sm btn-info pull-right"><i class="fa fa-edit"></i> Update</a> <br><br>
            </div>
          </div>
        </div>
        @endforeach
        <div class="clearfix"></div>
        
    </div>

</div>


<div class="modal fade" id="modalPreview">
    <div class="modal-dialog" style='width: 70%;'>
    
    </div>
</div>
<div id"statusmsg">
    
</div>
@stop

@section('style')
<style>
    .modal-dialog {
      width: 70% !important;
      height: 70% !important;
    }

    .modal-content {
      height: auto;
      min-height: 70% !important;
      border-radius: 0;
    }
</style>
@stop

@section('script')
<script src="{{ asset('/assets/') }}/js/jquery.dataTables.min.js"></script>
<script src="{{ asset('/assets/') }}/js/dataTables.bootstrap.min.js"></script>
<script src="{{ asset('/assets/') }}/switch/rcswitcher.js"></script>
<script src="{{ asset('/assets/') }}/alert/sweetalert.min.js"></script>
<script src="{{ asset('/assets/') }}/alert/pnotify.js"></script>
<script src="{{ asset('/assets/') }}/alert/notify.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();
    $("input[type='checkbox']").rcSwitcher();
});

$(document).ready(function() {
    $('body').on('hidden.bs.modal', '.modal', function () {
      $(this).removeData('bs.modal');
    });
    var table=$("#example").DataTable({
         "searching": true,
         "lengthChange": true,
         "ordering": true,
         stateSave: true       
    });

    $("input[type='checkbox']").rcSwitcher().on({'toggle.rcSwitcher': function( e, dataObj, changeType ){
            var id = $(this).data('id');
            var urll="{{ url('admin/grade_structure/status') }}/"+id;
            var msg_success = 'Status Updated Successfully.';
            var msg_error = 'Something went wrong!';
            $.ajax({
                url:urll,
                success: function(data){
                  notify('success',msg_success);                       
                },
                error: function (data) {
                    notify('error',msg_error);
                }
            });
        }
    });
});
</script>
@stop
@if(Session::has('msg'))
    <div class="alert alert-success center-block msg_alt" >
        <a class="close" data-dismiss="alert" href="#">&times;</a>
        <strong><i class="fa fa-check"></i></strong>&nbsp;
    {{Session::get('msg')}}
    </div>
@endif