<style type="text/css">
	.width-td{width: 100px;}
</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>
              <a href="<?php echo site_url('sampel/pengajuan') ?>" class="btn btn-primary m-b-5"><span class="fa fa-arrow-left"></span> Kembali</a>
              <?php if($id_status == 10) : ?>
              <a target='_blank' href="<?php echo site_url('download_dok/cetak_lhp?id_uji='.$id_uji.'&status='.$id_status); ?>" class="btn btn-primary m-b-5">Cetak LHP</a>
              <?php endif; ?>
							<hr>
            </div>
            <div class="panel panel-body table-responsive">
                <?php $p_uji = parameter_uji_lhu_lhp($data); ?>
                <form action="<?= site_url('sampel/pengajuan/save_lhp/'.$id_uji.'/'.$id_status); ?>" method="post">
                <table class="table table-bordered">
                    <thead>
                		<tr>
	                		<th rowspan="2" class="text-center">No.</th>
	                		<th rowspan="2" class="text-center">No. Uji</th>
	                		<th rowspan="2" class="text-center">Jenis/Asal Sampel</th>
                            <?php foreach($p_uji as $pkey => $p) : ?>
                                <?php if($p['nama_uji'] != '') : ?>
                                    <th colspan="2" class="text-center"><?= 'Kadar '.$p['label']. ' (%)'; ?></th>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </tr>
                        <tr>
                            <?php foreach($p_uji as $pkey => $p) : ?>
                                <?php if($p['nama_uji'] != '') : ?>
                                    <th class="text-center">Sampel</th>
                                    <th class="text-center">SNI(Maks)</th>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </tr>
                    </thead>   
                    <tbpdy>
                        <?php
                            $data_lhp = $this->m_dok->get_data_lhp($data[0]['id_uji']);
                        ?>
                        <?php //tampil_array($data); ?>
                        <?php $i = 1; foreach ($data as $rkey => $r) : ?>
                            <tr>
                                <td class="text-center"><?php echo $this->uri->segment(4) + $i++ ?></td>
                                <td class="text-center">
                                    <input type='hidden' name="id_sampel[]" value="<?= $r['id']; ?>">
                                    <?= $r['nomor_sampel']; ?>
                                </td>

                                <!-- <td><textarea style="width:99%; height: 90px;; text-align:center;" readonly class="width-td" type="" name=""><?php echo $r['jenis_sampel']."/\n".$r['asal_sampel'] ?></textarea></td> -->
                                <td class="text-center"><?php echo "<b>".$r['jenis_sampel']."</b>/<br>".$r['asal_sampel'] ?></td>
                                <?php foreach($p_uji as $pkey => $p) : ?>
                                    <?php if($p['nama_uji'] != '') : ?>
                                        <?php
                                            if(!in_array($data_lhp[$rkey][$p['nama_uji']], ['', null, 0])){
                                                $r['l_'.$p['nama_uji']] = $data_lhp[$rkey][$p['nama_uji']];
                                                $r[$p['nama_uji']] = $data_lhp[$rkey]['sni_'.$p['nama_uji']];
                                            }else{
                                                $r['l_'.$p['nama_uji']] = $data[$rkey][$p['nama_uji']];

                                                $nama_uji = $p['nama_uji'];
                                                if($nama_uji == 'af'){
                                                    $nama_uji = 'aflatoksin';
                                                }
                                                $r[$p['nama_uji']] = $data[$rkey][$nama_uji];
                                            }
                                        ?>
                                        <td class="text-center"><input class="width-td" name="<?= $p['nama_uji']; ?>[]" value="<?= $r['l_'.$p['nama_uji']]; ?>"></td>
                                        <td class="text-center"><input class="width-td" name="<?= 'sni_'.$p['nama_uji']; ?>[]" value="<?= $r[$p['nama_uji']]; ?>"></td>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            </tr>
                            
                        <?php endforeach; ?>
                            <tr>
								<td></td>
								<th colspan="2" class="text-center">Metode</th>
                                <?php $tfield=[]; foreach($p_uji as $pkey => $p) : ?>
                                    <?php if($p['nama_uji'] != '') : ?>
                                        <?php $tfield[] = $pkey; ?>
                                        <td colspan="2">
                                            <!-- <textarea style='width:99%;' readonly><?= $this->m_master->getMetodeUji($p['id'])[0]['detail']; ?>
                                            </textarea>  -->
                                            <?= $this->m_master->getMetodeUji($p['id'])[0]['detail']; ?>
                                        </td>
                                    <?php endif; ?>
                                <?php endforeach; ?>
							</tr>
                            <tr>
                                <td colspan="3"></td>
                                <td colspan="<?= count($tfield)*2; ?>"><button type="submit" class="btn btn-primary">Simpan Data LHP</button></td>
                            </tr>
                    </tbpdy>
                </table>
                </form>

            </div>
            <div class="panel panel-footer">
            <?php if($id_status == '9'){ ?>
							<a href="<?php echo site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/10'); ?>" class="btn btn-primary btn-md">Buat Draft</a>
						<?php } ?>
            <?php if($id_status == '10'){ ?>
							<a href="<?php echo site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/11'); ?>" class="btn btn-primary btn-md">ACC LHP</a>
							<a href="<?php echo site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/9'); ?>" class="btn btn-warning btn-md">Kembalikan ke Penerima Sampel</a>
						<?php } ?>
            </div>

        </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="<?php //echo site_url('sampel/pengajuan/siapkan_sampel?id_uji='.$id_uji.'&status=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>
