<?php $this->load->view('uji_analis/header_input01'); ?>
                	<table class="table table-bordered table-hover table-striped table-td-valign-middle">
                		<thead>
							<tr>
								<tr>
									<th rowspan="2" class="text-center">No Urut</th>
									<th rowspan="2" class="text-center">Nomor Sampel</th>
									<th rowspan="2" class="text-center">Kode Tabung & Erlenmeyer</th>
									<th rowspan="2" class="text-center">Berat Sampel<br/>(gram)<br/>(W)</th>
									<th rowspan="2" class="text-center">Volume Titrasi<br/>(Vs)</th>
									<th rowspan="2" class="text-center">Volume Blanko<br/>(Vb)</th>
									<th rowspan="2" class="text-center">N HCl</th>
									<th rowspan="2" class="text-center">Faktor<br>14.01 / 10</th>
									<th rowspan="2" class="text-center">Faktor Konversi N ke Protein</th>
									<th rowspan="2" class="text-center">%<br/>PK</th>
									<th rowspan="2" class="text-center">Katalis</th>
									<th rowspan="2" class="text-center">Digestor</th>
									<th rowspan="2" class="text-center">Kjeltec</th>
									<th rowspan="2" class="text-center">Buret</th>
									<th rowspan="2" class="text-center">Neraca</th>
								</tr>
							</tr>
                		</thead>
                		<tbody id="tabel_uji">
                    	<?php $z=1; foreach ($data as $key => $r) { ?>
                      		<tr id="t2_<?php echo $r['id']; ?>" class="">
                        		<td class="text-center"><?php echo $this->uri->segment(5) + $z++ ?></td>
        						<td>
        							<input type="hidden" name="nomor_batch[]" value="<?php echo $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="winput text-center kode_tabung" type="text" id="kode_tabung_erlenmeyer<?php echo $r['id']; ?>" name="kode_tabung_erlenmeyer[]" value="<?php echo ($r["kode_tabung_erlenmeyer"]) ? $r["kode_tabung_erlenmeyer"] : ($key+1); ?>">
								</td>
								<td>
									<input class="winput" type="text" onkeyup="persenPK(<?php echo $r['id']; ?>)" id="berat_sampel<?php echo $r['id']; ?>" name="berat_sampel[]" value="<?php echo $r["berat_sampel"]; ?>">
								</td>
        						<td>
									<input class="winput" type="text" onkeyup="persenPK(<?php echo $r['id']; ?>)" id="volume_titrasi<?php echo $r['id']; ?>" name="volume_titrasi[]" value="<?php echo $r["volume_titrasi"]; ?>">
								</td>
        						<td>
									<input class="winput volume_blanko" type="text" onkeyup="persenPK(<?php echo $r['id']; ?>); isi_v_blanko(<?= $r['id']; ?>)" id="volume_blanko<?php echo $r['id']; ?>" name="volume_blanko[]" value="<?php echo $r["volume_blanko"]; ?>">
								</td>
        						<td>
									<input class="winput n_hci" type="text" onkeyup="persenPK(<?php echo $r['id']; ?>); isi_hci(<?= $r['id']; ?>)" id="n_hci<?php echo $r['id']; ?>" name="n_hci[]" value="<?php echo $r["n_hci"]; ?>">
								</td>
        						<td>
									<input class="winput" type="text" onkeyup="persenPK(<?php echo $r['id']; ?>)" id="faktor_14_01<?php echo $r['id']; ?>" name="faktor_14_01[]" value="1.401" readonly>
								</td>
        						<td>
									<input class="winput" type="text" onkeyup="persenPK(<?php echo $r['id']; ?>)" id="faktor_konversi_n_kprotein<?php echo $r['id']; ?>" name="faktor_konversi_n_kprotein[]" value="6.25" readonly>
								</td>
								<td>
									<input class="winput" type="text" id="kadar_pk<?php echo $r['id']; ?>" name="kadar_pk[]" value="<?php echo $r["kadar_pk"]; ?>">
									<?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>
									<input class="winput" type="text" id="katalis<?php echo $r['id']; ?>" name="katalis[]" value="<?php echo ($r["katalis"]) ? $r["katalis"] : 'Cu'; ?>">
								</td>
								<td>
									<input class="winput" type="text" id="digestor<?php echo $r['id']; ?>" name="digestor[]" value="<?php echo ($r["digestor"]) ? $r["digestor"] : 'DT 208'; ?>">
								</td>
								<td>
									<input class="winput" type="text" id="kjeltec<?php echo $r['id']; ?>" name="kjeltec[]" value="<?php echo ($r["kjeltec"]) ? $r["kjeltec"] : 'KT 8200'; ?>">
								</td>
								<td>
									<input class="winput" type="text" id="buret<?php echo $r['id']; ?>" name="buret[]" value="<?php echo ($r["buret"]) ? $r["buret"] : 'Brand B'; ?>">
								</td>
								<td>
									<input class="winput" type="text" id="neraca<?php echo $r['id']; ?>" name="neraca[]" value="<?php echo ($r["neraca"]) ? $r["neraca"] : 'Mettler Toledo ME 204T'; ?>">
								</td>

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

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

	                	</tfoot>
                	</table>

            	</div> <!-- end panel-body -->
			</form> <!-- end form -->
			<div class="panel panel-footer">
			
			</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="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 type="text/javascript">
	function persenPK(x){
		var f = $('#berat_sampel'+x).val();
		var g = $('#volume_titrasi'+x).val();
		var h = $('#volume_blanko'+x).val();
		var i = $('#n_hci'+x).val();
		var j = $('#faktor_14_01'+x).val();
		var k = $('#faktor_konversi_n_kprotein'+x).val();

		if(f === '') f = 0;
		if(g === '') g = 0;
		if(h === '') h = 0;
		if(i === '') i = 0;
		if(j === '') j = 0;
		if(k === '') k = 0;

		var j = (parseFloat(g)-parseFloat(h))*parseFloat(i)*parseFloat(j)*parseFloat(k)/parseFloat(f);

		if(isNaN(parseFloat(j))){
				$('#kadar_pk'+x).val(0);
		}else{
			j = j.toFixed(2);
			$('#kadar_pk'+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 class=''>\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 class='winput kode_tabung' style='text-align:center;' type='text' id='kode_tabung_erlenmeyer"+c+"' name='kode_tabung_erlenmeyer[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' onkeyup='persenPK("+c+")' id='berat_sampel"+c+"' name='berat_sampel[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' onkeyup='persenPK("+c+")' id='volume_titrasi"+c+"' name='volume_titrasi[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput volume_blanko' type='text' onkeyup='persenPK("+c+");isi_v_blanko("+c+")' id='volume_blanko"+c+"' name='volume_blanko[]''>\n\
				</td>\n\
				<td>\n\
					<input class='winput n_hci' type='text' onkeyup='persenPK("+c+");isi_hci("+c+")' id='n_hci"+c+"' name='n_hci[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' onkeyup='persenPK("+c+")' id='faktor_14_01"+c+"' name='faktor_14_01[]' value='1.401' readonly>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' onkeyup='persenPK("+c+")' id='faktor_konversi_n_kprotein"+c+"' name='faktor_konversi_n_kprotein[]' value='6.25' readonly>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' id='kadar_pk"+c+"' name='kadar_pk[]'>\n\
					<br><b>KS:</b><br>\n\
					<input class='' type='text' id='c_range"+c+"' name='c_range[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' id='katalis"+c+"' value='Cu' name='katalis[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' id='digestor"+c+"' value='DT 208' name='digestor[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' id='kjeltec"+c+"' value='KT 2800' name='kjeltec[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' id='buret"+c+"' value='Brand B' name='buret[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' id='neraca"+c+"' value='Mettler Toledo ME 204T' name='neraca[]'>\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);
            var kode_tabung = $(tr[i]).find('td .kode_tabung').first().val(i+1);
        }
		
		c++;
	}

    function isi_v_blanko(x)
    {
        var volume_blanko = $("#volume_blanko"+x).val();
        $(".volume_blanko").val(volume_blanko);
    }

    function isi_hci(x)
    {
        var n_hci = $("#n_hci"+x).val();
        $(".n_hci").val(n_hci);
    }
</script>
