<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/glassware/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', 'Nama Alat', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['nama'] : '');
                         echo toi_input('nama', $var, 'text', null, 'Nama Alat');
                     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', 'Merk', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['merk'] : '');
                         echo toi_input('merk', $var, 'text', null, 'Merk');
                     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');
										 if(!empty($edit)){
											 echo div_form('start', 'Tambah', 4, 7, '*');
	                         $var = (!empty($edit) ? '' : '');
	                         echo toi_input('tambah', $var, 'text', 'tambah', 'Tambah', 'onkeyup=tambahGlassware();');
	                     echo div_form('end');

										 }
                     echo div_form('start', 'Jumlah', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['jumlah'] : '');
                         echo toi_input('jumlah', $var, 'text', 'jumlah', 'Jumlah');
                     echo div_form('end');
										 if(!empty($edit)){
											 echo div_form('start', 'Operasional', 4, 7, '*');
	                         $var = (!empty($edit) ? $edit['rusak'] : '');
	                         echo toi_input('rusak', $var, 'text', 'rusak', 'Operasional', 'onkeyup=sisaGlassware();');
	                     echo div_form('end');
											 echo div_form('start', 'Sisa', 4, 7, '*');
	                         $var = (!empty($edit) ? $edit['sisa'] : '');
	                         echo toi_input('sisa', $var, 'text', 'sisa', 'Sisa', 'readonly');
	                     echo div_form('end');
										 }
                     echo div_form('start', 'Satuan', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['satuan'] : '');
                         echo toi_input('satuan', $var, 'text', null, 'Satuan');
                     echo div_form('end');
                     echo div_form('start', 'Keterangan', 4, 7, '*');
                         $var = (!empty($edit) ? $edit['keterangan'] : '');
                         echo toi_input('keterangan', $var, 'text', null, 'Keterangan');
                     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 tambahGlassware(){
        var g = $('.tambah').val();
				var i = $('.jumlah').val();

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

        var j = parseFloat(g)+parseFloat(i);

        if(isNaN(parseFloat(j))){
            $('.jumlah').val(0);
        }else{
						$('.jumlah').val(j);
        }
    }

		function sisaGlassware(){
        var h = $('.rusak').val();
				var i = $('.jumlah').val();
				var rusak = 0;
				<?php if(isset($edit['rusak'])) { ?>
					rusak = '<?php $edit['rusak']; ?>';
				<?php } ?>

        if(h === '') h = 0;
				if(i === '') i = 0;

				var k = parseFloat(i)-parseFloat(h);

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