<style type="text/css">
    /* table{
        border: 0.3px solid grey;
    } */
    th {
        border: 0.1px solid #bec3c6;
        border-bottom: 2px solid #bec3c6;
    }
    td {
        border: 0.1px solid #ebeced;
    }

    .table > thead > tr > th {
        vertical-align: middle;
        text-align: center;
    }

    th {
        padding : 1px 10px 1px 10px;
    }

    td {
        padding : 1px 10px 1px 10px;
    }

    /* tbody {
    display:block;
    height:300px;
    overflow-y:scroll;
}
thead, tbody tr {
    display:table;
    width:200%;
    table-layout:fixed;
} */

thead {
    table-layout:fixed;
    display:inline-block;
    width:2250px;
    background-color: #ebeced;
}
tbody {
    display:inline-block;
    height:400px;
    overflow-y:scroll;
    width:2250px;
}


</style>
<div class="row">
<!-- begin col-8 -->
<div class="col-sm-12">
    <!-- begin panel -->
    <div class="panel panel-grey">
        <div class="panel-heading">
            <div class="panel-heading-btn">
                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-grey" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-grey" data-click="panel-remove"><i class="fa fa-times"></i></a>
            </div>
            <div class="row">
            <div>
                <?= select_parameter(); ?>
            </div>
            <div style="margin-left:5px;">
                <button class="btn btn-primary" id="bt_cari1" onclick="cari1();">
                <span class="fa fa-search"></span> Pencarian
                </button>
                <button class="btn btn-primary" id="bt_cari2" onclick="cari2();">
                <span class="fa fa-search"></span> Pencarian
                </button>
            </div>
            </div>
            <hr>
            <?php $this->load->view('pengajuan/filter_disposisi'); ?>

        </div>

        <div class="panel panel-body table-responsive">
            <table class="table-fixed" id="my_table">
                <thead>
                <tr>
                    <th style="width:25px;" rowspan="3" class="text-center">No.</th>
                    <th style="width:100px;" rowspan="3" class="text-center">Aksi</th>
                    <th style="width:150px;" rowspan="3" class="text-center">Status</th>
                    <th style="width:100px;" rowspan="3" class="text-center">Nomor Sampel</th>
                    <th colspan="2" rowspan="2" class="text-center">Kualitas</th>
                    <th style="width:100px;" rowspan="3" class="text-center">Kemasan</th>
                    <th colspan="3" rowspan="2" class="text-center">Penanganan&nbsp;Sampel</th>
                    <th colspan="3" rowspan="2" class="text-center">Berat&nbsp;(gram)</th>
                    <th colspan="12" class="text-center">Parameter Uji</th>
                    <th colspan="6" class="text-center">Penyimpanan Sampel</th>
                    <th style="width:150px;" rowspan="3" class="text-center">Keterangan</th>
                </tr>
                <tr>
                    <th colspan="5" class="text-center">Proksimat</th>
                    <th colspan="2" class="text-center"></th>
                    <th style="width:30px;" rowspan="2" class="text-center">TDN</th>
                    <th colspan="2" class="text-center"></th>
                    <th colspan="2" class="text-center"></th>
                    <th colspan="3" class="text-center">Sampel Kerja</th>
                    <th colspan="3" class="text-center">Sampel Arsip</th>
                </tr>
                <tr>
                    <th style="width:50px;" class="text-center">Baik</th>
                    <th style="width:50px;" class="text-center">Tidak Baik</th>
                    <th style="width:30px;" class="text-center">B</th>
                    <th style="width:30px;" class="text-center">L</th>
                    <th style="width:30px;" class="text-center">K</th>
                    <th style="width:30px;" class="text-center">B</th>
                    <th style="width:30px;" class="text-center">K</th>
                    <th style="width:30px;" class="text-center">KA1</th>
                    <th style="width:30px;" class="text-center">Air</th>
                    <th style="width:30px;" class="text-center">Abu</th>
                    <th style="width:30px;" class="text-center">PK</th>
                    <th style="width:30px;" class="text-center">LK</th>
                    <th style="width:30px;" class="text-center">SK</th>
                    <th style="width:30px;" class="text-center">Ca</th>
                    <th style="width:30px;" class="text-center">P</th>
                    <th style="width:30px;" class="text-center">Ur</th>
                    <th style="width:30px;" class="text-center">Af</th>
                    <th style="width:30px;" class="text-center">NDF</th>
                    <th style="width:50px;" class="text-center">MBM</th>
                    <th style="width:30px;" class="text-center">Fz</th>
                    <th style="width:30px;" class="text-center">Rf</th>
                    <th style="width:50px;" class="text-center">R.AC</th>
                    <th style="width:30px;" class="text-center">Fz</th>
                    <th style="width:30px;" class="text-center">Rf</th>
                    <th style="width:50px;" class="text-center">R.AC</th>
                </tr>
                </thead>
                <tbody>
                    <?php
                        $id = array();
                        $i=0;
                        foreach($data as $r){
                        $id[$i] = $r['id'];
                        $i++;
                        }
                        $id = array_unique($id);
                        $row = array();

                        foreach($id as $k){
                        $row[$k]['id']= array();
                        $row[$k]['id_status']= array();
                        $row[$k]['status_sampel']= array();
                        $row[$k]['keterangan']= array();
                        $row[$k]['detail']= array();
                        foreach($data as $r){
                            if($r['id'] == $k){
                            $row[$k]['id'][] = $r['id'];
                            $row[$k]['id_status'][] = $r['id_status'];
                            $row[$k]['status_sampel'][] = $r['status_sampel'];
                            $row[$k]['keterangan'][] = $r['keterangan'];
                            $row[$k]['detail'][] = $r['detail'];
                            $row[$k]['data_sampel'][] = $r;
                            }
                        }
                        }
                    ?>
                    <?php $z = 1; foreach($row as $r){ ?>
                        <tr>
                        <?php $tr = false; ?>
                        <td style="width:25px;" class="text-center" <?= 'rowspan="' . count($r['id']) . '"' ?>>
                            <?= $this->uri->segment(4) + $z++ ?>
                        </td>
                        <td style="width:100px;" <?= 'rowspan="' . count($r['id']) . '"' ?>>
                            <div class="btn-group m-b-5 m-r-5">
                            <a href="javascript:;" class="btn btn-inverse">Aksi</a>
                            <a href="javascript:;" data-toggle="dropdown" class="btn btn-grey dropdown-toggle" aria-expanded="false">
                                <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu pull-right" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(70px, 32px, 0px);">
                                <li>
                                    <a target="_blank" href="<?= site_url('download_dok/download_disposisi?id_uji='.$r['id'][0]) ?>">Download Disposisi</a>
                                </li>

                                <?php if((int)$r['id_status'][0] == 11) { ?>
                                    <?php if(in_array($idGroup, array('1','4'))) { ?>
                                        <li>
                                            <a target='_blank' href="<?= site_url('download_dok/cetak_lhp?id='.$r['id'][0].'&status='.$r['id_status'][0]) ?>" class="">Cetak LHP</a>
                                        </li>
                                        <!-- <li>
                                            <a target='_blank' href="<?= site_url('download_dok/download_lhp_af?id='.$r['id'][0].'&status='.$r['id_status'][0]) ?>" class="">Cetak LHP Aflatoksin</a>
                                        </li>
                                        <li>
                                            <a target='_blank' href="<?= site_url('download_dok/download_lhp_tdn?id='.$r['id'][0].'&status='.$r['id_status'][0]) ?>" class="">Cetak LHP TDN</a>
                                        </li> -->
                                        <li>
                                            <a href="<?= site_url('sampel/asam_amino?id_uji='.$r['id'][0].'&id_status='.$r['id_status'][0]) ?>" class="">Asam Amino</a>
                                        </li>
                                        <li>
                                            <a href="#modal-alert3-<?= $r['id'][0] ?>" data-toggle="modal">Download Sertifikat</a>
                                        </li>
                                    <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 10) { ?>
                                <?php if(in_array($idGroup, array('1','9', '2'))) { ?>
                                <li>
                                    <a href="<?= site_url('lhp/'.$r['id'][0].'/'.$r['id_status'][0]) ?>">ACC LHP</a>
                                </li>
                                <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 9) { ?>
                                <?php if(in_array($idGroup, array('1','4'))) { ?>
                                <li>
                                    <a href="<?= site_url('lhp/'.$r['id'][0].'/'.$r['id_status'][0]) ?>">Buat Draft LHP</a>
                                </li>
                                <li>
                                    <a target="_blank" href="<?= site_url('download_dok/download_lhu?id_uji='.$r['id'][0].'&status='.$r['id_status'][0]) ?>">Download LHU</a>
                                </li>
                                <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 8) { ?>
                                <?php if(in_array($idGroup, array('1','2'))) { ?>
                                <li>
                                    <a href="<?= site_url('lhu/'.$r['id'][0].'/'.$r['id_status'][0]) ?>">ACC LHU</a>
                                </li>
                                <li>
                                    <a target="_blank" href="<?= site_url('download_dok/download_lhu?id_uji='.$r['id'][0].'&status='.$r['id_status'][0]) ?>">Download LHU</a>
                                </li>
                                <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 7) { ?>
                                <?php if(in_array($idGroup, array('1','5'))) { ?>
                                <li>
                                    <a href="<?= site_url('sampel/pengajuan/verifikasi_penyelia/'.$r['id'][0].'/'.$r['id_status'][0]) ?>">
                                    Verifikasi Penyelia
                                    </a>
                                </li>
                                <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 6) { ?>
                                <?php if(in_array($idGroup, array('1','3'))) { ?>
                                <li>
                                    <a href="<?= site_url('uji_analis/'.$r['id'][0].'/'.$r['id_status'][0]) ?>">Cek Uji Analis</a>
                                </li>
                                <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 5) { ?>
                                <?php if(in_array($idGroup, array('1','5'))) { ?>
                                <!-- <li>
                                    <a target="_blank" href="https://view.officeapps.live.com/op/view.aspx?src=<?php //echo base_url('template/Penyiapan-Sampel.doc') ?>">Download Penyiapan Sampel</a>
                                </li> -->
                                <li>
                                    <a href="<?= site_url('penyiapan_uji/'.$r['id'][0].'/'.$r['id_status'][0]) ?>">Cek Penyiapan Uji Sampel</a>
                                </li>
                                <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 4) { ?>
                                <?php if(in_array($idGroup, array('1','8'))) { ?>
                                <!-- <li>
                                    <a href="<?= site_url('penyiapan_uji/'.$r['id'][0].'/'.$r['id_status'][0]); ?>">Penyiapan Uji</a>
                                </li> -->
                                <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 3) { ?>
                                <?php if(in_array($idGroup, array('1','7'))) { ?>
                                <li>
                                    <a href="#modal-alert-<?= $r['id'][0] ?>" data-toggle="modal">Verifikasi Deputi MT</a>
                                </li>
                                <?php } ?>
                                <?php } ?>

                                <?php if((int)$r['id_status'][0] == 2) { ?>
                                <?php if(in_array($idGroup, array('1','2'))) { ?>
                                <li>
                                    <a href="#modal-alert-mt<?= $r['id'][0] ?>" data-toggle="modal">Kembalikan ke Penerima Sampel</a>
                                </li>
                                <?php } ?>
                                <?php } ?>
                            </ul>
                            </div>
                        </td>
                        <td style="width:150px;" class="text-center" <?= 'rowspan="' . count($r['id']) . '"' ?>>
                            <?= str_replace('Status','',$r['status_sampel'][0]).'<br>['. str_replace(' ', '&nbsp;', $r['detail'][0]).']'; ?>
                            <?= isset($r['keterangan'][0]) && in_array($r['status_sampel'][0], ['Status I', 'Status II', 'Status III']) ? '<br>'.$r['keterangan'][0] : '' ?>
                        </td>

                        <?php foreach ($r['data_sampel'] as $s) {?>

                        <?php if ($tr) { ?>
                            <tr>
                        <?php }$tr = true ?>
                        <td style="width:100px;" class="text-center"><?= $s['nomor_sampel']?></td>
                        <td style="width:50px;" class="text-center"><?= $s['kualitas']=='Baik' ?'√':'-'?></td>
                        <td style="width:50px;" class="text-center"><?= $s['kualitas']=='Tidak Baik' ?'√':'-'?></td>
                        <td style="width:100px;"><?= $s['kemasan'] ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['jenis_penanganan']=='Basah'?'√':'-' ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['jenis_penanganan']=='Lembab'?'√':'-' ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['jenis_penanganan']=='Kering'?'√':'-' ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['jenis_berat']=='Basah'?$s['berat_sampel']:'-' ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['jenis_berat']=='Kering'?$s['berat_sampel']:'-' ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['jenis_berat']=='Kadar Air 1'?$s['berat_sampel']:'-' ?></td>
                        <?php
                            $parameter_uji = json_decode($s['jenis_pengujian']);
                        ?>

                        <td style="width:30px;" class="text-center"><?= (in_array(1, $parameter_uji) || in_array(6, $parameter_uji)) ? '√' : '-'; // AIR ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(2, $parameter_uji) || in_array(6, $parameter_uji)) ? '√' : '-'; // ABU ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(5, $parameter_uji) || in_array(6, $parameter_uji)) ? '√' : '-'; // PK ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(3, $parameter_uji) || in_array(6, $parameter_uji)) ? '√' : '-'; // LK ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(4, $parameter_uji) || in_array(6, $parameter_uji)) ? '√' : '-'; //SK ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(6, $parameter_uji) || in_array(13, $parameter_uji)) ? '√' : '-'; // CA ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(7, $parameter_uji)) ? '√' : '-'; // p ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(8, $parameter_uji)) ? '√' : '-'; // TDN  ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(9, $parameter_uji)) ? '√' : '-'; // UR ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(10, $parameter_uji)) ? '√' : '-'; //  AF ?></td>
                        <td style="width:30px;" class="text-center"><?= (in_array(11, $parameter_uji)) ? '√' : '-'//  ANDF?></td>
                        <td style="width:50px;" class="text-center"><?= (in_array(12, $parameter_uji)) ? '√' : '-' // MBM ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['sampel_kerja']=='1'?'√':'-' ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['sampel_kerja']=='2'?'√':'-' ?></td>
                        <td style="width:50px;" class="text-center"><?= $s['sampel_kerja']=='3'?'√':'-' ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['sampel_arsip']=='1'?'√':'-' ?></td>
                        <td style="width:30px;" class="text-center"><?= $s['sampel_arsip']=='2'?'√':'-' ?></td>
                        <td style="width:50px;" class="text-center"><?= $s['sampel_arsip']=='3'?'√':'-' ?></td>
                        <td style="width:150px;"><?= $s['jenis_klasifikasi'] ?></td>
                        </tr>
                        <?php } ?>

                        <div class="modal fade" id="modal-alert-mt<?= $r['id'][0] ?>" style="display: none;" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-body">
                                    <div class="alert alert-info m-b-0">
                                        <p>
                                            <b>Peringatan:</b>
                                            <p>Apakah anda yakin akan mengembalikan sampel ini ke penerima Sampel?</p>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$r['id'][0].'/1') ?>" class="btn width-100 btn-sm btn-primary">Ya</a>
                                    <a href="javascript:;" class="btn width-100 btn-sm btn-danger" data-dismiss="modal">Batal</a>
                                </div>
                            </div>
                        </div>
                    </div>

                        <div class="modal fade" id="modal-alert-<?= $r['id'][0] ?>" style="display: none;" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-body">
                                    <div class="alert alert-info m-b-0">
                                        <p>
                                            <b>Peringatan:</b>
                                            <p>Apakah anda yakin akan memverifikasi penyiapan sampel ini?</p>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$r['id'][0].'/4') ?>" class="btn width-100 btn-sm btn-primary">Ya</a>
                                    <!-- <a href="javascript:;" class="btn width-100 btn-sm btn-danger" data-dismiss="modal">Tidak</a> -->
                                    <a href="#modal-alert2-<?= $r['id'][0] ?>" class="btn width-100 btn-sm btn-danger" data-toggle="modal">Tidak</a>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="modal fade" id="modal-alert2-<?= $r['id'][0] ?>" style="display: none;" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <form action="<?= site_url("sampel/pengajuan/tolak_deputi") ?>" method="post">
                                <div class="modal-body">
                                    <div class="alert alert-info m-b-0">
                                        <b>Masukkan Alasan:</b>
                                        <input type="hidden" name="id_uji2" value="<?= $r['id'][0]; ?>">
                                        <textarea class="form-control" name="keterangan"></textarea>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="submit" class="btn btn-info btn-sm">Simpan Alasan</button>
                                    <a href="javascript:;" class="btn width-100 btn-sm btn-danger" data-dismiss="modal">Batal</a>
                                </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="modal fade" id="modal-alert3-<?= $r['id'][0] ?>" style="display: none;" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                <h5 class="modal-title">Download Sertifikat</h5>
                                </div>
                                <div class="modal-body">
                                <div class="row">
                                    <div class="col-sm-2 text-center">
                                    <label>No. Sampel</label>
                                    </div>
                                    <div class="col-sm-2 text-center">
                                    <label>Sertifikat</label>
                                    </div>
                                </div>
                                <?php foreach($r['data_sampel'] as $d) { ?>
                                    <div class="row" style="margin-bottom:3px;">
                                    <div class="col-sm-2 text-center">
                                        <?= $d['id_sampel']; ?>
                                    </div>
                                    <div class="col-sm-2 text-center">
                                        <a target="_blank" href="<?= site_url('download_dok/download_sertifikat?id='.$d['id_sampel']) ?>" class="btn btn-primary btn-xs">Download</a>
                                    </div>
                                    </div>
                                <?php } ?>
                                </div> 
                            </div>
                        </div>
                    </div>
                    <?php } ?>
                </tbody>
            </table>
        </div>
        <div class="row">
            <div class="col-sm-12" style="margin-top: 10px;">
                <?php if($link_paging){?>
                    <ul class="pagination pagination-sm no-margin">
                        <?= $link_paging; ?>
                    </ul>
                <?php } ?>
            </div>
        </div>
    </div>
    <!-- end panel -->
</div>
</div>

<script> //JS UNTUK ANALIS DAN DISPOSISI FILTER
    $("#edit_analis, #cetak_analis, #tb_cari, #bt_cari2").hide();

    <?php if(!empty($filter) && $filter['filter_cari']) {?>
    $('#tb_cari').show();
    <?php } ?>

    function onEdit(){
        $('#form_edit_analis').submit();
    }

    function onCheck(x) {
        if($('#id_check'+x).is(':checked')){
                $("#edit_analis, #cetak_analis").show();
        }else{
            $("#edit_analis, #cetak_analis").hide();
        }
    }

    function cari1(){
        $("#bt_cari2").show();
        $("#bt_cari1").hide();

        $("#tb_cari").show();
    }

    function cari2(){
        $("#bt_cari2").hide();
        $("#bt_cari1").show();

        $("#tb_cari").hide();
    }
</script>
