<style type="text/css">
	.width-td{width: 100px;}
	.myselect-container {
    position:relative;
    height:10px;
    width:100px;
    /*for contain our absoulte select tag */
	}
	.myselect-container select {
	    position:absolute;
	    /*for put our list on other tag */
	}
</style>

<style type="text/css">
  .table > thead > tr > th {
     vertical-align: middle;
     text-align: center;
  }
  .table > tbody > tr > td {
     vertical-align: middle;
     text-align: center;
  }
</style>

<?php 
	$jam_mulai = strpos($data[0]['mulai_uji'], '00:00:00') == false ? date('H', strtotime($data[0]['mulai_uji'])) : date('H'); 
	$menit_mulai = strpos($data[0]['mulai_uji'], '00:00:00') == false ? date('H', strtotime($data[0]['mulai_uji'])) : date('i');
	$jam_selesai = strpos($data[0]['selesai_uji'], '00:00:00') == false ? date('H', strtotime($data[0]['selesai_uji'])) : date('H'); 
	$menit_selesai = strpos($data[0]['selesai_uji'], '00:00:00') == false ? date('H', strtotime($data[0]['selesai_uji'])) : date('i');
?>

<div class="row">
    <!-- begin col-8 -->
    <div class="col-sm-12">
        <!-- begin panel -->
        <form method="post" id="form_edit" action="">
	        <div class="panel panel-inverse">
	            <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>

              		<?php echo menu_parameter('ur', true, ($method == 'edit' ? null : $url_batch)); ?>
					<button type="button" onclick="save_analis();" class="btn btn-warning">Simpan</button>
					<hr>

					<table class="table">
						<tr>
							<th>Terbitan/Revisi</th>
							<td>:</td>
							<th><input class="" style="width:207px;" name='terbitan_revisi_ke[]' value="<?php echo ($data[0]['terbitan_revisi_ke'] ? $data[0]['terbitan_revisi_ke'] : '') ?>"></th>

							<th>Tanggal Revisi</th>
							<td>:</td>
							<th>
								<div style="width:220px;" class="input-group">
									<input style="width:50px;" class="mulai_uji" onchange="klik_tgl('tanggal_revisi');" type="date" id="tanggal_revisi" name="tanggal_revisi[]" value="<?php echo $data[0]['tanggal_revisi']; ?>">
									<input class="" id="c_tanggal_revisi" value="<?php echo toi_date03($data[0]['tanggal_revisi']); ?>" readonly>
								</div>
							</th>

							<th style="width:100px;"></th>
						</tr>
						<tr>
							<th>Tanggal Terbitan</th>
							<td>:</td>
							<th>
								<div style="width:220px;" class="input-group">
									<input style="width:50px;" class="mulai_uji" onchange="klik_tgl('tanggal_terbitan');" type="date" id="tanggal_terbitan" name="tanggal_terbitan[]" value="<?php echo ($data[0]['tanggal_terbitan'] ? $data[0]['tanggal_terbitan'] : date('Y-m-d')); ?>">
									<input class="" id="c_tanggal_terbitan" class="" value="<?php echo toi_date03(($data[0]['tanggal_terbitan'] ? $data[0]['tanggal_terbitan'] : date('Y-m-d'))); ?>" readonly>
								</div>
							</th>
							<th></th> <th></th> <th></th>
							<th style="width:100px;"></th>
						</tr>
						<tr>
							<th>Tanggal Pengujian</th>
							<td>:</td>
							<td>
								<div style="width:220px;" class="input-group">
									<input style="width:50px;" class="mulai_uji" onchange="klik_tgl('mulai_uji')" type="date" id="mulai_uji" name="mulai_uji[]" value="<?php echo ( $data[0]['mulai_uji'] ? explode(' ', $data[0]['mulai_uji'])[0] : date('Y-m-d')); ?>">
									<input class="" id="c_mulai_uji" value="<?php echo toi_date03(( $data[0]['mulai_uji'] ? explode(' ', $data[0]['mulai_uji'])[0] : date('Y-m-d'))); ?>" readonly>
								</div>
							</td>

							<th>Suhu (ᵒC)</th>
							<td>:</td>
							<th><input class="" style="width:207px;" name='suhu[]' value="<?php echo $data[0]['suhu'] ?>"></th>

							<th></th>
						</tr>
						<tr>
							
							<th>Pukul Mulai Pengujian</th>
							<td>:</td>
							<td class="input-group">
								<select style="width:103px;" onfocus='this.size=5;' onblur='this.size=1;' onchange='this.size=1; this.blur();' name="jam_selesai[]">
									<?php for($x=0; $x<24; $x++) {  $x = strlen($x) < 2 ? '0'.$x : $x; ?>
										<option <?php echo $jam_mulai == $x ? 'selected' : ''; ?> value="<?php echo $x;?>"><?php echo $x; ?></option>
									<?php } ?>
								</select> :
								<select style="width:103px;" onfocus='this.size=5;' onblur='this.size=1;' onchange='this.size=1; this.blur();' name="menit_selesai[]">
									<?php for($x=0; $x<60; $x++) {  $x = strlen($x) < 2 ? '0'.$x : $x; ?>
										<option <?php echo $menit_mulai == $x ? 'selected' : ''; ?> value="<?php echo $x;?>"><?php echo $x; ?></option>
									<?php } ?>
								</select>
							</td>
							<th>RH (%)</th>
							<td>:</td>
							<th><input class="" style="width:207px;" name='rh[]' value="<?php echo $data[0]['rh'] ?>"></th>

							<th></th>
						</tr>

						<tr>
							<th>Pukul Selesai Pengujian</th>
							<td>:</td>
							<td class="input-group">
								<select style="width:103px;" onfocus='this.size=5;' onblur='this.size=1;' onchange='this.size=1; this.blur();' name="jam_mulai[]">
									<?php for($x=0; $x<24; $x++) {  $x = strlen($x) < 2 ? '0'.$x : $x; ?>
										<option <?php echo $jam_selesai == $x ? 'selected' : ''; ?> value="<?php echo $x;?>"><?php echo $x; ?></option>
									<?php } ?>
								</select> :
								<select style="width:103px;" onfocus='this.size=5;' onblur='this.size=1;' onchange='this.size=1; this.blur();' name="menit_mulai[]">
									<?php for($x=0; $x<60; $x++) {  $x = strlen($x) < 2 ? '0'.$x : $x; ?>
										<option <?php echo $menit_selesai == $x ? 'selected' : ''; ?> value="<?php echo $x;?>"><?php echo $x; ?></option>
									<?php } ?>
								</select>
							</td>
							
							<th>Metode Uji</th>
							<th>:</th>
							<td>
								<textarea class="" style="width: 207px; float: left;" name="metode_uji[]"><?php echo $data[0]['metode_uji'] ? $data[0]['metode_uji'] : 'AOAC 2012 Bab 4 Butir 4.3.02 Metode 967.07'; ?>
								</textarea>
							</td>
							<th></th>
						</tr>
					</table>
            	</div>

            	<div class="panel panel-body table-responsive">
            		<button class="btn btn-primary" type="button" onclick="add_kontrol_sampel()">
						Tambah Kontrol Sampel
					</button>
					<label><input type="radio" id="t1" name="letak[]" value="t1_">Sebelum</label>
					<label><input type="radio" id="t3" name="letak[]" value="t3_">Sesudah</label>
					<select id="letak_id" name="letak_id[]">
						<option disable>Pilih sampel</option>
						<?php foreach($data as $d) { ?>
							<?php if(!is_null($d['id_sampel'])) { ?>
								<option value="<?php echo $d['id_sampel']; ?>"><?php echo $d['id_sampel']; ?></option>
							<?php } ?>
						<?php } ?>
					</select>
					<hr> 

                	<table class="table table-bordered table-hover table-striped table-td-valign-middle">
                		<thead>
							<tr>
						  		<th rowspan="2" class="text-center">No Urut</th>
						  		<th rowspan="2" class="text-center">No Sampel</th>
								<th rowspan="2" class="text-center">Abs Standar</th>
								<th rowspan="2" class="text-center">Abs Sampel</th>
								<th rowspan="2" class="text-center">sampel yang ditimbang (mg)</th>
								<th rowspan="2" class="text-center">Volume Larutan Induk (mL)</th>
								<th rowspan="2" class="text-center">Volume aliquot sampel (mL)</th>
								<th rowspan="2" class="text-center">mg sampel dalam aliquot</th>
								<th rowspan="2" class="text-center">% Urea</th>
					  		</tr>
                		</thead>
                		<tbody id="tabel_uji">
                    	<?php $z=1; foreach ($data as $r) { ?>
                      		<tr id="t2_<?php echo $r['id_sampel']; ?>" class="">
                        		<td class="text-center"><?php echo $this->uri->segment(5) + $z++ ?></td>
        						<td class="text-center">
        							<input type="hidden" name="nomor_batch[]" value="<?php echo $r['nomor_batch'] ?>">
									<input type="hidden" name="kontrol_sampel2[]" value="<?php echo $r['kontrol_sampel'] ?>">
									<?php
									if(is_null($r["id_sampel"])){ ?>
										<input class="text-center" type="text" onkeyup="persenCa(<?php echo $r['kontrol_sampel'] ?>)" id="kontrol_sampel" name="kontrol_sampel[]" placeholder="Kontrol Sampel" value="<?php echo $r["kontrol_sampel"]; ?>">
									<?php } else{?>
										<input type="hidden" name="kontrol_sampel[]" value="<?php echo ($r['kontrol_sampel'] ? $r['kontrol_sampel'] : 0) ?>">
										<?php echo nomor_id($r["id_sampel"]);
									} 
									?>
								</td>
        						<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?php echo $r['id_sampel'] ?>)" id="abs_standart<?php echo $r['id_sampel'] ?>" name="abs_standart[]" value="<?php echo $r["abs_standart"]; ?>">
								</td>
								<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?php echo $r['id_sampel'] ?>)" id="abs_sampel<?php echo $r['id_sampel'] ?>" name="abs_sampel[]" value="<?php echo $r["abs_sampel"]; ?>">
								</td>
								<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?php echo $r['id_sampel'] ?>)" id="sampel_yang_ditimbang<?php echo $r['id_sampel'] ?>" name="sampel_yang_ditimbang[]" value="<?php echo $r["sampel_yang_ditimbang"]; ?>">
								</td>
								<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?php echo $r['id_sampel'] ?>)" id="volume_larutan_induk<?php echo $r['id_sampel'] ?>" name="volume_larutan_induk[]" value="500">
								</td>
								<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?php echo $r['id_sampel'] ?>)" id="volume_alikuot_sampel<?php echo $r['id_sampel'] ?>" name="volume_alikuot_sampel[]" value="5">
								</td>
								<td>
									<input class="winput text-center" type="text" id="mg_sampel_dalam_alikuot<?php echo $r['id_sampel'] ?>" name="mg_sampel_dalam_alikuot[]" value="<?php echo $r["mg_sampel_dalam_alikuot"]; ?>">
								</td>
								<td>
									<input class="winput text-center" type="text" id="kadar_ur<?php echo $r['id_sampel'] ?>" name="kadar_ur[]" value="<?php echo $r["kadar_ur"]; ?>">
									<?php if(!is_null($r['id_sampel'])) { ?>
										<input type="hidden" name='c_range[]'>
									<?php } else { ?>
										<span style='font-size:10px;' class='text-center'><b>KS:</b></span>
										<input class='wth-form text-center ' type='text' name='c_range[]' value="<?php echo $r['c_range'] ?>">
									<?php } ?>
								</td>
					
								<!-- ===ID SAMPEL (SYARAT MUTLAK HARUS ADA)=== -->
								<input type="hidden" id="id_sampel<?php echo $r['id_sampel'] ?>" name="id_sampel[]" value="<?php echo $r["id_sampel"]; ?>">
								<?php if(!empty($method)) { ?>
									<?php if(in_array($method, array('batch_sampel', 'kontrol_sampel'))) { ?>
										<input type="hidden" name="method_batch[]" value="<?php echo $method; ?>">
									<?php } ?>
									<?php if(in_array($method, array('kontrol_sampel'))) { ?>
										<input type="hidden" name="nomor_batch[]" value="<?php echo $nomor_batch;?>">
									<?php } ?>
								<?php } ?>
								<!-- ========================================= -->

                      		</tr>
	                    <?php } ?>
	                	</tbody>
	                	<tfoot>

	                	</tfoot>
	                </table>
            	</div> <!-- end panel-body -->
			</form> <!-- end form -->
			<div class="panel panel-footer bg-white">
				<div>
					<img src="<?php echo base_url("assets/img/formula/formula_urea.jpg");?>">
				</div>
				<div>
					<h5>Keterangan</h5>
					<table>
						<tr>
							<td>1</td>
							<td colspan="3">
								Hasil pengujian nomor
								<input style="width:220px;" onchange="klik_tgl('ket_0');" type="text" id="ket_0" name="ket_0[]" value="<?php echo $data[0]['ket_0']; ?>">
								 < LOQ (0,73 %) hasil pengujian disimpulkan ND (Non Detection)</td>
								
							</td>
						</tr>
						<tr>
							<td>2</td>
							<td width="380px">Tanggal pembuatan Larutan Zn(CH3COO)2*2H2O</td>
							<td>:</td>
							<td>
								<div style="width:220px;" class="input-group">
									<input style="width:50px;" onchange="klik_tgl('ket_1');" type="date" id="ket_1" name="ket_1[]">
									<input class="" id="c_ket_1" class="" value="<?php echo toi_date03(($data[0]['ket_1'] ? $data[0]['ket_1'] : '')); ?>" readonly>
								</div>
							</td>
						</tr>
						<tr>
							<td>3</td>
							<td>Tanggal pembuatan Larutan K4[Fe(CN)6]*3H2O</td>
							<td>:</td>
							<td>
								<div style="width:220px;" class="input-group">
									<input style="width:50px;" onchange="klik_tgl('ket_2');" type="date" id="ket_2" name="ket_2[]">
									<input class="" id="c_ket_2" class="" value="<?php echo toi_date03(($data[0]['ket_2'] ? $data[0]['ket_2'] : '')); ?>" readonly>
								</div>
							</td>
						</tr>
						<tr>
							<td>4</td>
							<td>Tanggal pembuatan Larutan Buffer</td>
							<td>:</td>
							<td>
								<div style="width:220px;" class="input-group">
									<input style="width:50px;" onchange="klik_tgl('ket_3');" type="date" id="ket_3" name="ket_3[]">
									<input class="" id="c_ket_3" class="" value="<?php echo toi_date03(($data[0]['ket_3'] ? $data[0]['ket_3'] : '')); ?>" readonly>
								</div>
							</td>
						</tr>
						<tr>
							<td>5</td>
							<td>Tanggal pembuatan Larutan Standar Urea</td>
							<td>:</td>
							<td>
								<div style="width:220px;" class="input-group">
									<input style="width:50px;" onchange="klik_tgl('ket_4');" type="date" id="ket_4" name="ket_4[]">
									<input class="" id="c_ket_4" class="" value="<?php echo toi_date03(($data[0]['ket_4'] ? $data[0]['ket_4'] : '')); ?>" readonly>
								</div>	
							</td>
						</tr>
						<tr>
							<td>6</td>
							<td>Tanggal pembuatan Larutan p-Dimethylaminobenzaldehyde</td>
							<td>:</td>
							<td>
								<div style="width:220px;" class="input-group">
									<input style="width:50px;" onchange="klik_tgl('ket_5');" type="date" id="ket_5" name="ket_5[]">
									<input class="" id="c_ket_5" class="" value="<?php echo toi_date03(($data[0]['ket_5'] ? $data[0]['ket_5'] : '')); ?>" readonly>
								</div>
							</td>
						</tr>
					</table>

				</div>
			</div> <!-- end panel-footer -->
        </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 persenUr(x){
		var f = $('#sampel_yang_ditimbang'+x).val();
		var g = $('#volume_larutan_induk'+x).val();
		var h = $('#volume_alikuot_sampel'+x).val();
		var e = $('#abs_sampel'+x).val();
		var d = $('#abs_standart'+x).val();

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

		var j = parseFloat(h)*parseFloat(f)/parseFloat(g);
		var o = (1*parseFloat(e)*100)/(d*j);

      if(isNaN(parseFloat(j))){
          $('#mg_sampel_dalam_alikuot'+x).val(0);
      }else{
          j = j.toFixed(3);
          $('#mg_sampel_dalam_alikuot'+x).val(j);
      }

			if(isNaN(parseFloat(o))){
          $('#kadar_ur'+x).val(0);
      }else{
          o = o.toFixed(2);
          $('#kadar_ur'+x).val(o);
      }
    }

	function removeTd() {
		$('.mulai_uji').removeAttr('td');
	}

	function save_analis(){
		$('#form_edit').submit();
	}

	var c = 1000000;

	function add_kontrol_sampel(){
		var t1 = $("#t1").val();
		var t3 = $("#t3").val();
		var letak_id = $("#letak_id").val();
		var t = 0;

		var cek = "\n\
			<tr class=''>\n\
	    		<td class='text-center'><?php echo $this->uri->segment(5) + $z++ ?></td>\n\
				<td>\n\
					<input type='hidden' name='nomor_batch[]' value='<?php echo $data[0]['nomor_batch'] ?>'>\n\
					<input type='hidden' name='kontrol_sampel2[]'>\n\
					<input class='winput text-center' type='text' id='kontrol_sampel' name='kontrol_sampel[]' placeholder='Kontrol Sampel'>\n\
				</td>\n\
				<td>\n\
					<input class='winput text-center' type='text' onkeyup='persenUr("+c+")' id='abs_standart"+c+"' name='abs_standart[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput text-center' type='text' onkeyup='persenUr("+c+")' id='abs_sampel"+c+"' name='abs_sampel[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput text-center' type='text' onkeyup='persenUr("+c+")' id='sampel_yang_ditimbang"+c+"' name='sampel_yang_ditimbang[]''>\n\
				</td>\n\
				<td>\n\
					<input class='winput text-center' type='text' onkeyup='persenUr("+c+")' id='volume_larutan_induk"+c+"' name='volume_larutan_induk[]' value='500'>\n\
				</td>\n\
				<td>\n\
					<input class='winput text-center' type='text' onkeyup='persenUr("+c+")' id='volume_alikuot_sampel"+c+"' name='volume_alikuot_sampel[]' value='5'>\n\
				</td>\n\
				<td>\n\
					<input class='winput text-center' type='text' id='mg_sampel_dalam_alikuot"+c+"' name='mg_sampel_dalam_alikuot[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput text-center' type='text' id='kadar_ur"+c+"' name='kadar_ur[]'>\n\
					<span style='font-size:10px;' class='text-center'><b>KS:</b></span>\n\
					<input type='text' id='c_range"+c+"' name='c_range[]'>\n\
				</td>\n\
	\n\
				<!-- ===ID SAMPEL (SYARAT MUTLAK HARUS ADA)=== -->\n\
				<input type='hidden' id='id_sampel"+c+"' name='id_sampel[]'>\n\
				<?php if(!empty($method)) { ?>
					<?php if(in_array($method, array('batch_sampel', 'kontrol_sampel'))) { ?>
						<input type='hidden' name='method_batch[]' value='<?php echo $method; ?>'>\n\
					<?php } ?>
					<?php if(in_array($method, array('kontrol_sampel'))) { ?>
						<input type='hidden' name='nomor_batch[]' value='<?php echo $nomor_batch; ?>'>\n\
					<?php } ?>
				<?php } ?>
				<!-- ========================================= -->\n\
	\n\
	  		</tr>";
  		
		if ($("#t1").prop("checked")) {
			t = t1;
			$("#t2_"+letak_id).before(cek);
		}
		if ($("#t3").prop("checked")) {
			t = t3;
			$("#t2_"+letak_id).after(cek);
		}

		var tr = $('#tabel_uji tr');
        for (var i = 0; i < tr.length; i++) {
            var td = $(tr[i]).find('td').first().text(i+1);
        }
		
		c++;

	}
</script>
