@extends('layouts.front.masterapp')
@section('title', 'Lembar Instrument Monitoring')
@section('content')
<section class="row">
    <div class="col-md-6">
        <div class="card">
            <div class="card-body px-3 py-4-5">
                <div class="row">
                    <div class="col-md-6">
                        <h6 class="text-muted font-semibold">Filter Lembar Instrument Monitoring</h6>
                        <div class="card-header">
                        <form action="{{ route('lembar_instrument_monitoring.index') }}" method="PATCH" enctype="multipart/form-data">
                        {{ csrf_field() }}
                        <div class="col-md-12 col-12">
                                <div class="form-group">
                                    <label for="last-name-column">Instrument</label>
                                    <select class="form-control" name="instrument">
                                            <option></option>
                                            @foreach ($instrument as $item)
                                            <option value="{{ $item->id }}" {{ isset($filter_instrument) ? ($filter_instrument == $item->id ? 'selected' : '') : '' }}>{{ $item->instrument }}</option>
                                            @endforeach
                                        </select>
                                </div>
                            </div>
            
                            <div class="col-md-12 col-12">
                                <div class="form-group">
                                    <label for="last-name-column">Tahun</label>
                                    <select class="form-control" name="tahun">
                                            <option></option>
                                            @foreach ($tahun as $item)
                                            <option value="{{ $item->tahun }}" {{ isset($filter_tahun) ? ($filter_tahun == $item->tahun ? 'selected' : '') : '' }}>{{ $item->tahun }}</option>
                                            @endforeach
                                        </select>
                                </div>
                            </div>

                            <button type="submit" class="btn btn-success">Filter</button>
                        </form>

                    </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    @if(!empty($filter_tahun && $filter_instrument))
    <div class="col-md-6">
        <div class="card">
            <div class="card-body px-3 py-4-5">
                <div class="row">
                    <div class="col-md-6">
                        <h6 class="text-muted font-semibold">Print Lembar Instrument Monitoring</h6>
                        <div class="card-header">
             
                        <form action="{{ route('cetak_pdf') }}" method="post" enctype="multipart/form-data" target="_blank">
                        {{ csrf_field() }}
                            <div class="col-md-12 col-12">
                                <div class="form-group">
                                    <label for="last-name-column">No. Dokumen</label>
                                    <input type="text"  name="no_dokumen" class="form-control" required>
                                    <input type="hidden"  name="filter_tahun" value="{{$filter_tahun}}" class="form-control">
                                    <input type="hidden"  name="filter_instrument" value="{{$filter_instrument}}"  class="form-control">
                                </div>
                            </div>
                            <div class="col-md-12 col-12">
                                <div class="form-group">
                                    <label for="last-name-column">Revisi</label>
                                    <input type="text" name="revisi" class="form-control" required>
                                </div>
                            </div>
                            <div class="col-md-12 col-12">
                                <div class="form-group">
                                    <label for="last-name-column">Tanggal Terbit</label>
                                    <input type="date"  name="tanggal_terbit" class="form-control" required>
                                </div>
                            </div>
            
                            <button type="submit" class="btn btn-success">Print</button>
                        </form>

                    </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    @endif
</section>


<section class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body px-3 py-4-5">
                <div class="row">
                @if (\Session::has('success'))
                        <div class="alert alert-success">
                            <ul>
                                <center>{!! \Session::get('success') !!}</center>
                            </ul>
                        </div>
                @endif


                <div class="col-md-12">
                        <h5 class="text-muted font-semibold">
                            <center>LEMBAR @if(!empty($instrumentdetail)) {{$instrumentdetail->instrument}}@endif - TAHUN @if(!empty($filter_tahun)) {{$filter_tahun}}@endif</center>
                        </h5>
              
                <br><br>
                @foreach ($sub_instrument as $data)   
                <h6>{{ $data->sub_instrument }} </h6>             
                    <div class="table-responsive">
                            <table class="table table-striped mb-0">
                            <thead>
                                <th>No. Pernyataan</th>
								<th colspan="{{count($fakultas)}}"><center>{{ $data->jenis_input->detail }}</center></th>
                               
                            </thead>
							<thead>
                                <th>&nbsp;</th>
								@foreach ($fakultas as $dataa)
                                <th>{{$dataa->fakultas}}</th>
                                @endforeach
 
                            </thead>
                            <tbody>
                              
                               
                                <form action="{{ route('lembar_instrument_monitoring.store')}}" method="POST" enctype="multipart/form-data">
                                 @csrf
                                   
                                    <input type="hidden"  value="{{$data->id}}" name="id_sub_instrument" class="form-control">
                                    @php $no = 1; @endphp
                                   
                                    @foreach($pernyataan_instrument as $item)
                                    @if($data->id == $item->id_sub_instrument) 
                                    
                                    <tr>
                                        <td>{{ $no++ }}. {{ $item->pernyataan_instrument }} </td>
                                        
                                        @for ($i = 1; $i <= count($fakultas) ; $i++)
                                        <td>
                                        
                                        <input type="{{ $data->jenis_input->html }}"  
                                        name="jumlah_pernyataan_instrument[]"class="form-control" 
                                        value="{{ isset($arr_hasil[$item->id][''][$i][$filter_tahun]) ? $arr_hasil[$item->id][''][$i][$filter_tahun]->jumlah : '' }}">

                                        <input type="hidden"  value="{{$item->id}}" name="id_pernyataan_instrument[]" class="form-control">

                                       
                                        <input type="hidden"  value="{{$filter_tahun}}" name="tahun" class="form-control">
                                        <input type="hidden"  value="{{$i}}" name="id_fakultas[]" class="form-control">
                                        <input type="hidden"  value="@if(!empty($hasil_instrument)){{$hasil_instrument->id}}@endif" name="id[]" class="form-control">
                                        
                                        </td>
                                        @endfor
                                        
                                    </tr>
                                    @foreach($sub_pernyataan_instrument as $value)

                                    @if($item->id == $value->id_pernyataan_instrument) 
                                    <tr>
                                        <td>{{ $value->sub_peryataan }}</td>
                                        @for ($a = 1; $a <= count($fakultas) ; $a++)
                                        <td>
                                        <!-- @php
                                            $hasil_subinstrument = App\Models\Hasil_Instrument::
                                                                    where('id_pernyataan_instrument',$item->id)
                                                                    ->where('id_sub_pernyataan_instrument',$value->id)
                                                                    ->where('id_fakultas',$a)
                                                                    ->where('tahun',$filter_tahun)
                                                                    ->first();
                                                    
                                        @endphp     -->
                                       
                                                <!-- <input type="{{ $data->jenis_input->html }}"  
                                                name="jumlah_sub_peryataan[{{$item->id}}][{{$value->id}}][{{$a}}]"class="form-control" value="@if(!empty($hasil_subinstrument)){{$hasil_subinstrument->jumlah}}@endif"> -->

                                                <input type="{{ $data->jenis_input->html }}"  
                                                name="jumlah_sub_peryataan[{{$item->id}}][{{$value->id}}][{{$a}}]"class="form-control" value="{{ isset($arr_hasil[$item->id][$value->id][$a][$filter_tahun]) ? $arr_hasil[$item->id][$value->id][$a][$filter_tahun]->jumlah : '' }}">

                                                <input type="hidden"  value="@if(!empty($hasil_subinstrument)){{$hasil_subinstrument->id}}@endif" name="id_subhasil[]" class="form-control">

                                        </td>
                                        @endfor
                                        
                                       
                                    </tr>
                                    @endif
                                    @endforeach

                                    
                                    @endif
                                    @endforeach
                                    <tr>
                                    
                                        <td><strong>Jumlah</strong></td>
                                        @for ($b = 1; $b <= count($fakultas) ; $b++)
                                       
                                       
									    <td><center><strong>{{ isset($arr_hasil_total[$data->id][$b][$filter_tahun]) ? $arr_hasil_total[$data->id][$b][$filter_tahun]->total : '' }}</strong></center></td>

									    @endfor          
                                             
                                    </tr>

                                    <tr>
                                        <td>
                                           &nbsp;
                                        </td>
                                        <td colspan="{{count($fakultas)}}">
                                            <div class="col-12 d-flex justify-content-end">
                                                <button type="submit" class="btn btn-success me-1 mb-1">Simpan</button>             
                                            </div>
                                          
                                        </td>     
                                    </tr>
                                    
                                    </form>
                               
                                
                            </tbody>
                        </table>
                       
                    </div>
                    @endforeach
                      
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
@endsection
@push('js')
{{-- <script src="{{URL::to('template/assets/js/ckeditor.js')}}"></script> --}}
<script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/classic/ckeditor.js"></script>
<script>
    function remove(element){
        $(element).remove();
    }
    function edit(url, title){
        var token = "{{ csrf_token() }}";
        $('#edit-form').modal('toggle');
        $('#edit-form-body').html('Loading...');
        $('#modal-edit-label').html(title);
        var request = $.ajax({
            url : url,
            type : "GET",
            dataType : "html",
            data : {_token: token},
            success: function(data){
                $('#edit-form-body').html(data);
            }
        })
    }



    function destroy(url){
        Swal.fire({
        title: 'Apakah Anda Yakin?',
        text: "Anda akan menghapus data ini!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Ya'
        }).then((result) => {
            if (result.isConfirmed) {
                var token = "{{ csrf_token() }}";
                var request = $.ajax({
                    url : url,
                    type : "DELETE",
                    dataType : "html",
                    data : {_token: token, _method: 'PUT'},
                    success: function(data){
                        Swal.fire({
                            position: 'top-end',
                            icon: 'success',
                            title: 'Berhasil menghapus data',
                            showConfirmButton: false,
                            timer: 1500
                        });
                        location.reload();
                },
                error: function(data){
                    Swal.fire({
                        position: 'top-end',
                        icon: 'error',
                        title: 'Gagal menghapus data',
                        showConfirmButton: false,
                        timer: 1500
                    })
                }
            })
            }
        })
    }



      function destroy(url){
        Swal.fire({
        title: 'Apakah Anda Yakin?',
        text: "Anda akan menghapus data ini!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Ya'
        }).then((result) => {
            if (result.isConfirmed) {
                var token = "{{ csrf_token() }}";
                var request = $.ajax({
                    url : url,
                    type : "DELETE",
                    dataType : "html",
                    data : {_token: token, _method: 'PUT'},
                    success: function(data){
                        Swal.fire({
                            position: 'top-end',
                            icon: 'success',
                            title: 'Berhasil menghapus data',
                            showConfirmButton: false,
                            timer: 1500
                        });
                        location.reload();
                },
                error: function(data){
                    Swal.fire({
                        position: 'top-end',
                        icon: 'error',
                        title: 'Gagal menghapus data',
                        showConfirmButton: false,
                        timer: 1500
                    })
                }
            })
            }
        })
    }



    


</script>
@endpush
