				<?php $this->load->view('uji_analis/header_input01'); ?>
					<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">Kode Krusibel</th>
								<th rowspan="2" class="text-center">Berat Krusibel (gram) W<sub>2</sub></th>
								<th rowspan="2" class="text-center">Berat Sampel (gram) W</th>
								<th rowspan="2" class="text-center">Berat&nbsp;Sampel + Sampel setelah&nbsp;Furnace <br>(gram)<br>W<sub>1</sub></th>
								<th rowspan="2" class="text-center">Kadar Abu (%)</th>
								<th colspan="2" class="text-center">Lanjut Uji</th>
								<th rowspan="2" class="text-center">Keterangan</th>
							</tr>
							<tr>
								<th class="text-center">Ca</th>
								<th class="text-center">P</th>
							</tr>
						</thead>
						<tbody id="tabel_uji">
						<?php $z=1; foreach ($data as $r) { ?>
							<tr id="t2_<?= $r['id']; ?>" class="">
								<td class="text-center"><?= $this->uri->segment(5) + $z++ ?></td>
								<td>
									<input type="hidden" name="nomor_batch[]" value="<?= $nomor_batch; ?>">
									<?php if(!empty($is_edit)) : ?>
										<input type='hidden' name='id[]' value="<?= $r['id']; ?>">
									<?php endif; ?>
									<?php if($r["id_sampel"] == 0 ) : ?>
										<input class="wth-form text-center" id="kontrol_sampel" name="kontrol_sampel[]" placeholder="Kontrol Sampel" value="<?= val_ks($r["kontrol_sampel"]); ?>">
									<?php else : ?>
										<input type="hidden" name="kontrol_sampel[]" value="<?= ($r['kontrol_sampel'] ? $r['kontrol_sampel'] : 0) ?>">
										<?= $r["nomor_sampel"]; ?>
									<?php endif; ?>
								</td>
								<td>
									<input class="text-center" id="kode_krusebel<?= $r['id']; ?>" name="kode_krusebel[]" value="<?= $r["kode_krusebel"]; ?>">
								</td>
								<td>
									<input type="text" onkeyup="persenAbu(<?= $r['id']; ?>)" id="berat_krusebel<?= $r['id']; ?>" name="berat_krusebel[]" value="<?= $r["berat_krusebel"]; ?>">
								</td>
								<td>
									<input type="text" onkeyup="persenAbu(<?= $r['id']; ?>)" id="berat_sampel<?= $r['id']; ?>" name="berat_sampel[]" value="<?= $r["berat_sampel"]; ?>">
								</td>
								<td>
									<input type="text" onkeyup="persenAbu(<?= $r['id']; ?>)" id="bksf<?= $r['id']; ?>" name="bksf[]" value="<?= $r["bksf"]; ?>">
								</td>
								<td>
									<input type="text" id="kadar_abu<?= $r['id']; ?>" name="kadar_abu[]" value="<?= $r["kadar_abu"]; ?>">
									<?php if(!empty($is_edit) && $r['id_sampel'] == 0) : ?>
										<br><b>KS:</b><br>
										<input type='text' id="c_range<?= $r['id']; ?>" name='c_range[]' value="<?= $r['c_range']; ?>">
									<?php elseif($r['id_sampel'] != 0) : ?>
										<input type="hidden" name='c_range[]'>
									<?php else : ?>
										<input type="hidden" name='c_range[]'>
									<?php endif; ?>
								</td>
								<td>
                                    <?php                     
                                        $is_ca = $this->m_analis->cek_parameter([6,13], $r['id']);
                                        if(!is_null($is_ca)){
                                            $lanjut_uji_ca = 1;
                                            $c_lanjut_uji_ca = '√';
                                        }else{
                                            $lanjut_uji_ca = 0;
                                            $c_lanjut_uji_ca = '-';
                                        }
                                        echo $c_lanjut_uji_ca;
                                    ?>
									<input type="hidden" id="lanjut_uji_ca<?= $r['id']; ?>" name="lanjut_uji_ca[]" value="<?= $lanjut_uji_ca; ?>">
								</td>
								<td>
                                    <?php                     
                                        $is_p = $this->m_analis->cek_parameter([7], $r['id']);
                                        if(!is_null($is_p)){
                                            $lanjut_uji_p = 1;
                                            $c_lanjut_uji_p = '√';
                                        }else{
                                            $lanjut_uji_p = 0;
                                            $c_lanjut_uji_p = '-';
                                        }
                                        echo $c_lanjut_uji_p;
                                    ?>
									<input type="hidden" id="lanjut_uji_p<?= $r['id']; ?>" name="lanjut_uji_p[]" value="<?= $lanjut_uji_p; ?>">
								</td>
								<td>
									<input type="text" id="keterangan<?= $r['id']; ?>" name="keterangan[]" value="<?= $r["keterangan"]; ?>">
								</td>

								<!-- ===ID SAMPEL (SYARAT MUTLAK HARUS ADA)=== -->
								<input type="hidden" id="id_sampel<?= $r['id']; ?>" name="id_sampel[]" value="<?= $r["id_sampel"]; ?>">
								<!-- ========================================= -->

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

						</tfoot>
					</table>

				</div> <!-- end panel-body -->
			</form> <!-- end form -->
			<div class="panel panel-footer">
				<!-- code -->
			</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="javascript:;" 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 persenAbu(x){
		var g = $('#berat_krusebel'+x).val();
		var h = $('#berat_sampel'+x).val();
		var i = $('#bksf'+x).val();

		if(g === '') g = 0;
		if(h === '') h = 0;
		if(i === '') i = 0;
		
		console.log(g);
		console.log(h);
		console.log(i);
		var j = (parseFloat(i)-parseFloat(g))/parseFloat(h)*100;
		console.log(j);
		if(isNaN(parseFloat(j))){
			$('#kadar_abu'+x).val(0);
		}else{
			j = j.toFixed(2);
			$('#kadar_abu'+x).val(j);
		}
	}

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

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

	var c = 10000000;

	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 id='t2_<?= $r['id']; ?>' > \n\
				<td class='text-center'></td> \n\
				<td>\n\
					<?php if(!empty($is_edit)) : ?>\n\
						<input type=hidden name='id[]' value='0'>\n\
					<?php endif; ?>\n\
					<input type='hidden' name='nomor_batch[]' value='<?= $nomor_batch; ?>'>\n\
					<input class='wth-form' type='text' id='kontrol_sampel' name='kontrol_sampel[]' placeholder='Kontrol Sampel'>\n\
				</td>\n\
				<td>\n\
					<input type='text' id='kode_krusebel"+c+"' name='kode_krusebel[]' >\n\
				</td>\n\
				<td>\n\
					<input type='text' onkeyup='persenAbu("+c+")' id='berat_krusebel"+c+"' name='berat_krusebel[]'>\n\
				</td>\n\
				<td>\n\
					<input type='text' onkeyup='persenAbu("+c+")' id='berat_sampel"+c+"' name='berat_sampel[]'>\n\
				</td>\n\
				<td>\n\
					<input type='text' onkeyup='persenAbu("+c+")' id='bksf"+c+"' name='bksf[]'>\n\
				</td>\n\
				<td>\n\
					<input type='text' id='kadar_abu"+c+"' name='kadar_abu[]'>\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\
				<td>\n\
					<input type='text' id='lanjut_uji_ca"+c+"' name='lanjut_uji_ca[]'>\n\
				</td>\n\
				<td>\n\
					<input type='text' id='lanjut_uji_p"+c+"' name='lanjut_uji_p[]'>\n\
				</td>\n\
				<td>\n\
					<input type='text' id='keterangan"+c+"' name='keterangan[]'>\n\
				</td>\n\
		\n\
				<!-- ===ID SAMPEL (SYARAT MUTLAK HARUS ADA)=== -->\n\
				<input type='hidden' id='id_sampel"+c+"' name='id_sampel[]'>\n\
				<!-- ========================================= -->\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>
