<style type="text/css">
    .table > thead > tr > th {
        vertical-align: middle;
        text-align: center;
    }
</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="btn-group" role="group" aria-label="Group Button Penyiapan Sampel">
                    <a href="<?php echo site_url('permitaan_uji') ?>" class="btn btn-primary m-b-5">
                        <span class="fa fa-arrow-left"></span> Kembali
                    </a>
                    <a href="<?= site_url('penyiapan_uji/'.$id_uji.'/'.$id_status); ?>" class="btn btn-warning m-b-5">Penyiapan Sampel</a>
                    <a href="<?= site_url('pelayuan_sampel/'.$id_uji.'/'.$id_status) ?>" class="btn btn-warning m-b-5 active">
                        Pelayuan Sampel
                    </a>
                </div>
                <hr>

            </div>
            <div class="panel panel-body table-responsive">
                <form method="post" action="<?= site_url('sampel/pelayuan_sampel/update_pelayuan'); ?>">
                    <button type="submit" class="btn btn-primary mb-2">Simpan Pelayuan</button>
                    <table class="table table-bordered table-striped">
                        <thead class="text-center">
                            <tr class="grey">
                                <th rowspan="2">No</th>
                                <th rowspan="2">Nomor Sampel</th>
                                <th colspan="2">Tgl&nbsp;dan&nbsp;Pukul sebelum&nbsp;Masuk&nbsp;Oven</th>
                                <th rowspan="2">Berat&nbsp;Segar (gram)</th>
                                <th colspan="2">Tgl&nbsp;dan&nbsp;Pukul setelah&nbsp;Keluar&nbsp;Oven</th>
                                <th rowspan="2">Berat Kering (gram)</th>
                                <th rowspan="2">Kadar&nbsp;Air&nbsp;1 (%)</th>
                                <th rowspan="2">Pelaksana</th>
                                <th rowspan="2">Keterangan</th>
                            </tr>
                            <tr class="grey">
                                <th>Tanggal</th>
                                <th>Pukul</th>
                                <th>Tanggal</th>
                                <th>Pukul</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $i=1; foreach($data as $r) {?>
                                <input name="id_sampel[]" type="hidden" value="<?= $r['id_sampel']; ?>">
                                <tr>
                                    <td><?php echo $this->uri->segment(4)+$i++; ?></td>
                                    <td>
                                        <input class="text-center" name="nomor_sampel[]" value="<?php echo ($r['nomor_sampel']); ?>">
                                    </td>
                                    <td><?= toi_date_input('tgl_pukul_sebelum_dioven[]', $r['tgl_pukul_sebelum_dioven']); ?></td>
                                    <td><?= toi_time_input('tgl_pukul_sebelum_dioven[]', $r['tgl_pukul_sebelum_dioven']); ?></td>
                                    <td>
                                        <input onkeyup="persenAir(<?= $r['id_sampel']; ?>)" class="text-center berat_segar<?= $r['id_sampel']; ?>" name="berat_segar[]" value="<?= $r['berat_segar']; ?>">
                                    </td>
                                    <td><?= toi_date_input('tgl_pukul_setelah_dioven[]', $r['tgl_pukul_setelah_dioven']); ?></td>
                                    <td><?= toi_time_input('tgl_pukul_setelah_dioven[]', $r['tgl_pukul_setelah_dioven']); ?></td>
                                    <td>
                                        <input onkeyup="persenAir(<?= $r['id_sampel']; ?>)" class="text-center berat_kering<?= $r['id_sampel']; ?>" name="berat_kering[]" value="<?= $r['berat_kering']; ?>">
                                    </td>
                                    <td><input class="text-center kadar_air<?= $r['id_sampel']; ?>" name="kadar_air[]" value="<?= $r['kadar_air']; ?>"></td>
                                    <td><input class="text-center" name="nama_pelaksana[]" value="<?= $r['nama_pelaksana']; ?>"></td>
                                    <td><input class="text-center" name="keterangan[]" value="<?= $r['keterangan']; ?>"></td>
                                </tr>
                            <?php } ?>
                        </tbody>
                    </table>
                </form>
            </div>
            <div class="panel panel-footer">

            </div>
        </div>

    </div>
</div>

<script type="text/javascript">
    function persenAir(x){
        var f = $('.berat_segar'+x).val();
        var g = $('.berat_kering'+x).val();

        if(f === '') f = 0;
        if(g === '') g = 0;

        var i = (parseFloat(f)-parseFloat(g))/parseFloat(f)*100;

        if(isNaN(parseFloat(i))){
                $('.kadar_air').val(0);
        }else{
            $('.kadar_air'+x).val(parseFloat(i.toFixed(2)));
        }
    }
</script>
