<style type="text/css">
    .rtable > thead > tr > th {
	    vertical-align: middle;
	    text-align: center;
    }
</style>
<?php 
    if(empty($data)) : 
        $data[0] = null;
    endif;
?>
<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>
                
                <?= select_parameter(); ?>

                <hr>

            </div>
            <div class="panel panel-body table-responsive">
                    <div class="row mb-3" style="font-weight: bold;">
                        <div class="col-sm-12">
                            <a href="<?= site_url('penyiapan_uji'); ?>" class="btn btn-primary">Kembali</a>
                        </div>
                    </div>
                    <table class="table table-bordered table-hover table-striped table-td-valign-middle">
                        <thead class="text-midle">
                            <tr class="grey">
                                <th rowspan="3" class="text-center">No.</th>
                                <th rowspan="3" class="text-center"><?= padding_nbsp('Aksi', 10) ?></th>
                                <th colspan="2" class="text-center">Waktu</th>
                                <th rowspan="3" class="text-center">Nomor Sampel</th>
                                <th rowspan="3" class="text-center">Bentuk/Jenis Sampel</th>
                                <th colspan="4" class="text-center">Kondisi Sampel</th>
                                <th colspan="5" class="text-center">Jenis Sampel</th>
                                <th rowspan="3" class="text-center">Jenis Grinder</th>
                                <th rowspan="3" class="text-center">Keterangan</th>
                            </tr>
                            <tr class="grey">
                                <th rowspan="2" class="text-center">Pukul&nbsp;Mulai</th>
                                <th rowspan="2" class="text-center">Pukul&nbsp;Selesai</th>
                                <th rowspan="2" class="text-center">Cair</th>
                                <th colspan="3" class="text-center">Padat</th>
                                <th colspan="3" class="text-center">Arsip</th>
                                <th colspan="2" class="text-center">Kerja</th>
                            </tr>
                            <tr class="grey">
                                <th class="text-center">Basah</th>
                                <th class="text-center">Lembab</th>
                                <th class="text-center">Kering</th>
                                <th class="text-center">Cair</th>
                                <th class="text-center">Tanpa Dioven</th>
                                <th class="text-center">Dioven</th>
                                <th class="text-center">Selain Uji Aflatoksin</th>
                                <th class="text-center">Uji Aflatoksin</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $i = 1; foreach($batch as $bkey => $b) : ?>
                            <form method="post" action="<?= site_url('sampel/pengajuan/create_penyiapan_sampel'); ?>">
                                <?php $data = $this->m_disposisi->riwayat_penyiapan($b['nomor_batch']); ?>
                                <tr>
                                    <td rowspan="<?= count($data); ?>" class="text-center"><?= $this->uri->segment(4) + $i++; ?></td>
                                    <td rowspan="<?= count($data); ?>" class="text-center">
                                    <div>
                                        <?php
                                            if($data[0]['is_acc'] == 1){
                                                $title = 'Siapkan Ulang';
                                                $disabled = '';
                                                $btn = 'danger';
                                                $btn2 = 'danger';
                                            }else{
                                                $title = 'Sukses';
                                                $disabled = 'disabled';
                                                $btn = 'success';
                                                $btn2 =  'primary';
                                            }
                                        ?>
                                        <button type="submit" class="btn btn-<?= $btn; ?> btn-sm mt-1" <?= $disabled; ?> title="<?= $title; ?>">
                                            <?php if($data[0]['is_acc'] == 1) : ?>
                                                <i class="fas fa-edit fa-lg"></i>
                                            <?php else : ?>
                                                <i class="far fa-check-circle fa-lg"></i>
                                            <?php endif; ?>
                                        </button>
                                        <button type="button" class="btn btn-<?= $btn2; ?> btn-sm mt-1" title="Tanggal Penyiapan: <?= get_str_date2($data[0]['tanggal_penyiapan']); ?>, Jenis Sampel: <?= ucwords($data[0]['jenis_sampel']); ?>" name="is_acc" value="1"><i class="fas fa-info-circle fa-lg"  data-toggle="modal" data-target="#exampleModal"></i></button>
                                    </div>

                                    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                            <div class="modal-header">
                                                <h5 class="modal-title" id="exampleModalLabel">Masukkan Keterangan Koreksi</h5>
                                            </div>
                                            <div class="modal-body">
                                                <?= $data[0]['ket_koreksi']; ?>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Close</button>
                                            </div>
                                            </div>
                                        </div>
                                    </div>
                                    </td>
                                <?php foreach($data as $rkey => $r) : ?>
                                    <input type="hidden" name="check_penyiapan[]" value="<?= $r['id_sampel']; ?>">
                                    <?php if($rkey != 0) : ?>
                                        <tr>
                                    <?php endif; ?>
                                        <td><?= date('H:i', strtotime($r['pukul_mulai'])); ?></td>
                                        <td><?= date('H:i', strtotime($r['pukul_selesai'])); ?></td>
                                        <td><?= $r['nomor_sampel'] ?></td>
                                        <td><?= $r['bentuk_jenis'] ?></td>
                                        <td class="text-center"><?= $r['id_bentuk_sampel'] === '1' ? '√' : '-';?></td>
                                        <td class="text-center"><?= strpos($r['id_bentuk_sampel'], '2') !== false ? '√' : '-';?></td>
                                        <td class="text-center"><?= strpos($r['id_bentuk_sampel'], '3') !== false ? '√' : '-';?></td>
                                        <td class="text-center"><?= strpos($r['id_bentuk_sampel'], '4') !== false ? '√' : '-';?></td>
                                        <td class="text-center"><?= (strpos($r['id_penanganan_arsip'], '"1"') != false) ? '√' : '-';?></td>
                                        <td class="text-center"><?= (strpos($r['id_penanganan_arsip'], '"2"') != false) ? '√' : '-';?></td>
                                        <td class="text-center"><?= (strpos($r['id_penanganan_arsip'], '"3"') != false) ? '√' : '-';?></td>
                                        <td class="text-center"><?= $r['id_penanganan_kerja'] === '5' ? '√' : '-';?></td>
                                        <td class="text-center"><?= $r['id_penanganan_kerja'] === '6' ? '√' : '-';?></td>
                                        <td class="text-center"><?= $r['nama_grinder'];?></td>
                                        <td><?= $r['keterangan'] ?></td>
                                    </tr>
                                <?php endforeach; ?>
                            </form>
                            <?php endforeach; ?>
                        </tbody>
                        <tfoot>

                        </tfoot>
                    </table>
            </div>
            <?php if(!empty($id_status) && in_array((int)$id_status, array(4))) { ?>
            <div class="panel panel-footer">
            	<a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/5') ?>" class="btn btn-success">Siapkan Sampel</a>
            	<a href="#modal-alert" class="btn btn-danger" data-toggle="modal">Batalkan</a>
            </div>
            <?php }else if(!empty($id_status) && in_array((int)$id_status, array(5))){ ?>
            <div class="panel panel-footer">
                <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/6') ?>" class="btn btn-primary">Verifikasi</a>
                <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/4') ?>" class="btn btn-danger">Kembalikan ke Penyiapan Sampel</a>
            </div>
            <?php } ?>
        </div>
        <!-- end panel -->
    </div>
</div>

<div class="modal fade" id="modal-alert" style="display: none;" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="alert alert-danger m-b-0">
                    <p><b>Peringatan:</b> Apakah anda yakin akan membatalkan penyiapan sampel ini?</p>
                </div>
            </div>
            <div class="modal-footer">
                <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/0') ?>" 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>
            </div>
        </div>
    </div>
</div>


