<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('inventaris/bahan_habis_pakai/index') ?>" class="btn btn-primary"><span class="fa fa-arrow-left"></span> Kembali</a>
							<hr>

            </div>
            <div class="panel panel-body table-responsive">
                <div class="col-sm-10">
                    <form class="form-horizontal" method="post" name="" action="">
                    <?php
                    // echo div_form('start', 'Nomor Sampel', 4, 7, '*');
                    //     echo toi_input(null, nomor_id($id_bahan), 'text', null, 'Nomor Sampel');
                    //     echo toi_input('id_sampel', $id_bahan, 'hidden', null);
                    //     $var = (!empty($edit) ? '1' : '');
                    //     echo toi_input('is_edit', $var, 'hidden', null);
                    // echo div_form('end');

                    echo div_form('start', 'Nama Barang', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['nama_barang'] : '');
                         echo toi_input('nama_barang', $var, 'text', null, 'Nama Barang');
                     echo div_form('end');
                     echo div_form('start', 'Bulan', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['bulan'] : ''); ?>
                         <select class="form-control default-select2" name="bulan">
                           <option></option>
                           <?php for($i=1;$i<=12;$i++){ ?>
                             <option <?php echo $var == $i ? 'selected' : ''; ?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
                           <?php } ?>
                         </select>
                     <?php echo div_form('end');
                     echo div_form('start', 'Tahun', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['tahun'] : '');
                         echo toi_input('tahun', $var, 'text', null, 'Tahun');
                     echo div_form('end');
                     echo div_form('start', 'Merek', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['merk'] : '');
                         echo toi_input('merk', $var, 'text', null, 'Merek');
                     echo div_form('end');
                     echo div_form('start', 'Spesifikasi', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['spesifikasi'] : '');
                         echo toi_input('spesifikasi', $var, 'text', null, 'Spesifikasi');
                     echo div_form('end');
                     echo div_form('start', 'Jumlah Stok', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['jumlah_stok'] : '');
												 $sisa_bahan = (!empty($edit) ? 'onkeyup=sisaBahan();' : null);
                         echo toi_input('jumlah_stok', $var, 'text', 'jumlah_stok', 'Jumlah Stok', $sisa_bahan);
                     echo div_form('end');
									 if(!empty($edit)){
										 echo div_form('start', null, 4, 7, null);
										 		echo "Total Pengambilan = ". $total_pengambilan;
										 echo div_form('end');
                     echo div_form('start', 'Jumlah Pengambilan', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['jumlah_pengambilan'] : '');
                         echo toi_input('jumlah_pengambilan', null, 'text', 'jumlah_pengambilan', 'Jumlah Pengambilan', $sisa_bahan);
                     echo div_form('end');
                     echo div_form('start', 'Sisa Stok', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['sisa_stok'] : '');
                         echo toi_input('sisa_stok', $var, 'text', 'sisa_stok', 'Sisa Stok');
                     echo div_form('end');
									 }else{?>
										 <input type="hidden" class="jumlah_pengambilan" value="0" name="jumlah_pengambilan">
										 <input type="hidden" class="sisa_stok" name="sisa_stok">
									 <?php }
                     echo div_form('start', 'Satuan Barang', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['satuan_barang'] : '');
                         echo toi_input('satuan_barang', $var, 'text', null, 'Satuan Barang');
                     echo div_form('end');
                    ?>

                     <?php echo div_form('start', null, 4, 7); ?>
                        <button type="submit" class="btn btn-md btn-success">Simpan</button>
                        <button type="reset" class="btn btn-md btn-warning">Reset</button>
                        <a onclick="goBack();" class="btn btn-md btn-danger">Batal</a>
                    <?php echo div_form('end'); ?>
                    </form>
                </div>
            </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>

<script>
    function sisaBahan(){
        var g = $('.jumlah_stok').val();
        var h = $('.jumlah_pengambilan').val();
				var total_ambil = 0;

				<?php if(!empty($total_pengambilan)){ ?>
					total_ambil = <?php echo $total_pengambilan; ?>
				<?php } ?>

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

        var j = parseFloat(g)-(parseFloat(h)+parseFloat(total_ambil));

        if(isNaN(parseFloat(j))){
            $('.sisa_stok').val(0);
        }else{
            $('.sisa_stok').val(j);
        }
    }
</script>
