<div class="row">
    <!-- begin col-8 -->
    <div class="col-sm-12">
        <!-- begin panel -->
        <div class="panel panel-grey">
            <div class="panel-heading">
                <?php $this->load->view('pendaftaran/filter_permintaan_uji');?>
                <hr>
                <a href="<?= site_url('set_data_uji'); ?>" class="btn btn-primary">Tambah Data</a>
            </div>
            
            <div class="panel panel-body">
                <div class="table-responsive">
                    <table class="table table-hover table-bordered table-striped">
                        <thead class="grey">
                            <tr>
                                <th class="text-center">No.</th>
                                <th class="text-center">Aksi</th>
                                <th colspan="2" class="text-center">Status Disposisi</th>
                                <th class="text-center">Nomor Permintaan Uji</th>
                                <th class="text-center">Jenis&nbsp;Layanan</th>
                                <th class="text-center">Registrasi Laboratorium</th>
                                <th class="text-center">Tanggal&nbsp;Pukul Pengambilan</th>
                                <th class="text-center">Tanggal&nbsp;Pukul Registrasi</th>
                                <th class="text-center">Perkiraan&nbsp;Estimasi Selesai LHP</th>
                                <th class="text-center">Tanggal&nbsp;Pukul Mulai Uji</th>
                                <th class="text-center">Tanggal&nbsp;Pukul Terbit LHU</th>
                                <th class="text-center">Tanggal&nbsp;Pukul Terbit LHP</th>
                                <th class="text-center">Tanggal&nbsp;Surat</th>
                                <th class="text-center">Nomor&nbsp;Surat</th>
                                <th class="text-center">Instansi/Perusahaan<br>/Umum</th>
                                <th class="text-center">Alamat</th>
                                <th class="text-center">Keterangan</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $i=1; foreach($data as $r) { ?>
                            <?php
                                $bctr='';
                                $ttitle = '';
                                if(date('Y-m-d H:i:s') >= date('Y-m-d H:i:s', strtotime('-2 days', $r['perkiraan_estimasi_selesai_lhp']))){
                                    $ttitle = 'Data dalam pengerjaan';
                                    $bctr = 'warning';
                                }

                                if(date('Y-m-d H:i:s') > date('Y-m-d H:i:s', $r['perkiraan_estimasi_selesai_lhp']) || is_null($r['perkiraan_estimasi_selesai_lhp'])) {
                                    $ttitle = 'Data sudah melewati masa estimasi';
                                    $bctr = 'danger';
                                }

                                if((int)$r['id_status'] >= 11) {
                                    $ttitle = 'Data selesai pengerjaan';
                                    $bctr = 'success';
                                }
                            ?>
                            <tr>
                                <td class='text-center'><?= $this->uri->segment(2) + $i++ ?></td>
                                <td>
                                    <?php $countSampel = count($this->m_pendaftaran->getSampel($r['id'])); ?>
                                    <?= aksi_button('start') ?>
                                        <?php if(!in_array($r['id_status'], ['1','2']) && in_array($id_group, ['1','2','4'])) { ?>
                                            <li>
                                                <a target="_blank" href="<?= site_url('download_ttpp/'.$r['id_ttpp'].'/'.$r['id_status']) ?>">
                                                    Download TTPP
                                                </a>
                                            </li>
                                            <li>
                                                <a target="_blank" href="<?= site_url('download_npps/'.$r['id'].'/'.$r['id_status']) ?>">
                                                    Download NPPS
                                                </a>
                                            </li>
                                            <li>
                                                <a target="_blank" href="<?= site_url('download_npps_vp/'.$r['id'].'/'.$r['id_status']) ?>">
                                                    Download NPPS Via Pos
                                                </a>
                                            </li>
                                            <?php if($r['id_layanan'] == 3) : ?>
                                                <li>
                                                    <a target="_blank" href="<?= site_url('download_kelengkapan_administrasi/'.$r['id'].'/'.$r['id_status']) ?>">
                                                        Download Kelengkapan Administrasi
                                                    </a>
                                                </li>
                                                <li>
                                                    <a target="_blank" href="<?= site_url('download_kelengkapan_administrasi_vp/'.$r['id'].'/'.$r['id_status']) ?>">
                                                        Download Kelengkapan Administrasi Via Pos
                                                    </a>
                                                </li>
                                            <?php endif; ?>
                                        <?php } ?>
                                        <?php if(in_array($r['id_status'], ['1']) && in_array($id_group, ['1', '4'])) { ?>
                                            <?php if($countSampel != 0 && in_array($id_group, array('1','4'))) { ?>
                                                <li>
                                                    <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$r['id'].'/2/1') ?>">
                                                        Kirim ke MT
                                                    </a>
                                                </li>
                                            <?php } ?>
                                        <?php } ?>
                                        <?php if(in_array($r['id_status'], ['2']) && in_array($id_group, ['1', '2'])) { ?>
                                            <?php if($countSampel != 0 && in_array($id_group, array('1','2'))) { ?>
                                                <li>
                                                    <a href="<?= site_url('permintaan_uji/verifikasi/'.$r['id']) ?>">
                                                        Verifikasi
                                                    </a>
                                                </li>
                                            <?php } ?>
                                        <?php } ?>
                                        <li>
                                            <a href="<?= site_url('permintaan_uji/sampel/'.$r['id']) ?>">
                                                Daftar Sampel
                                            </a>
                                        </li>
                                        <?php if((int)$r['id_status'] < 3) : ?>
                                            <li>
                                                <a href="<?= site_url('set_data_uji/'.$r['id']); ?>">
                                                    Edit Data Uji
                                                </a>
                                            </li>
                                            <li>
                                                <?php
                                                    $id_ttpp = $r['id'];
                                                    if(!is_null($r['id_ttpp']) && $r['id_ttpp'] != '') :
                                                        $id_ttpp = $r['id_ttpp'];
                                                    endif;
                                                ?>
                                                <a href="<?= site_url('set_data_uji?id_ttpp='.$id_ttpp); ?>">
                                                    Tambah Uji Satu TTPP
                                                </a>
                                            </li>
                                        <?php endif; ?>
                                        <?php if($r['id_status'] == 11) : ?>
                                            <hr>
                                            <li>
                                                <a href="<?= site_url('sampel/pendaftaran/sampel_sudah_diterima/'.$r['id'].'/1'); ?>">
                                                    LHP Rilis
                                                </a>
                                            </li>
                                            <li>
                                                <a href="<?= site_url('sampel/pendaftaran/sampel_sudah_diterima/'.$r['id'].'/2'); ?>">
                                                    LHP Lanjutan
                                                </a>
                                            </li>
                                            <hr>
                                        <?php endif; ?>
                                        <li>
                                            <a href="<?= site_url('sampel/pendaftaran/delete_uji/'.$r['id']); ?>">
                                                Hapus
                                            </a>
                                        </li>
                                    <?= aksi_button('end') ?>
                                </td>
                                <td><button class="btn btn-xs <?= 'btn-'.$bctr; ?>" title="<?= $ttitle; ?>">O</button></td>
                                <td class='text-center'>
                                    <?= str_replace('','',$r['status_sampel']).'<br>['. str_replace(' ', '&nbsp;', $r['detail_status']).']'; ?>
                                    <?= ($r['is_receive'] == 1 && $r['id_status'] == 1) ? '<br><span class="text-success">Sampel sudah Diterima</span>' : ''; ?>
                                    <?= (isset($r['note_verifikasi']) && $r['id_status'] == 1) ? '<br> <span class="text-danger"><b>Ditolak:</b> '.$r['note_verifikasi'] : '</span>'; ?>
                                    <?= (isset($r['note_verifikasi']) && $r['id_status'] == 1) ? '<br><span class="text-danger">Ubah&nbsp;data&nbsp;permintaan&nbsp;uji&nbsp;dan sampel untuk pengajuan ulang!</span>' : ''; ?>
                                    <?= ($r['is_receive'] == 1 && $r['id_status'] == 13) ? '<br><span class="text-success">LHP&nbsp;Rilis</span>' : ''; ?>
                                    <?= ($r['is_receive'] == 2 && $r['id_status'] == 13) ? '<br><span class="text-success">LHP&nbsp;Lanjutan</span>' : ''; ?>
                                </td>
                                <td>
                                    <?= $r['nomor_uji']; ?>
                                </td>
                                <td><?= $r['jenis_layanan'] ?></td>
                                <td><?= $r['registrasi_laboratorium'] ?></td>
                                <td><?= indo_datetime($r['tgl_pukul_pengambilan']); ?></td>
                                <td><?= indo_datetime($r['tgl_pukul_registrasi'], 'time'); ?></td>
                                <td><?= indo_datetime($r['perkiraan_estimasi_selesai_lhp'], 'time'); ?></td>
                                <td><?= indo_datetime($r['tgl_pukul_mulai_uji'], 'time'); ?></td>
                                <td><?= indo_datetime($r['tgl_pukul_terbit_lhu'], 'time'); ?></td>
                                <td><?= indo_datetime($r['tgl_pukul_terbit_lhp'], 'time'); ?></td>
                                <td><?= indo_datetime($r['tgl_surat']); ?></td>
                                <td><?= $r['nomor_surat'] ?></td>
                                <td><?= $r['instansi_umum'] ?></td>
                                <td><?= str_replace(' ', '&nbsp;', $r['alamat']); ?></td>
                                <td><?= $r['keterangan'] ?></td>
                            </tr>
                            <?php } ?>
                        </tbody>
                    </table>
                </div>
                <div class="btn-group">
                    <?= $link_paging; ?>
                </div>
            </div>
        </div>
    </div>
</div>
