<?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 Crucible Filter</th>
								<th rowspan="2" class="text-center">Berat Kode Crucible Filter Kosong</th>
								<th rowspan="2" class="text-center">Berat Sampel<br/>(W)</th>
								<th rowspan="2" class="text-center">
									Berat Crucible Filter dab Sampel Setelah Oven<br/>(W<sub>2</sub>)
								</th>
								<th rowspan="2" class="text-center">
									Berat Crucible Filter dab Sampel Setelah Tanur<br/>(W<sub>1</sub>)
								</th>
								<th rowspan="2" class="text-center">% Serat Kasar</th>
								<th rowspan="2" class="text-center">Kode Fibertec</th>
								<th rowspan="2" class="text-center">Jenis Oven</th>
								<th rowspan="2" class="text-center">Jenis Furnace</th>
								<th rowspan="2" class="text-center">Ket</th>
							</tr>
                		</thead>
                		<tbody id="tabel_uji">
                    	<?php $z=1; foreach ($data as $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" type="text" id="kode_crucible_filter<?php echo $r['id']; ?>" name="kode_crucible_filter[]" value="<?php echo $r["kode_crucible_filter"]; ?>">
								</td>
								<td>
									<input class="winput" type="text" id="berat_crucible_filter_kosong<?php echo $r['id']; ?>" name="berat_crucible_filter_kosong[]" value="<?php echo $r["berat_crucible_filter_kosong"]; ?>">
								</td>
        						<td>
									<input class="winput" type="text" onkeyup="persenSK(<?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="persenSK(<?php echo $r['id']; ?>)" id="bcfso<?php echo $r['id']; ?>" name="bcfso[]" value="<?php echo $r["bcfso"]; ?>">
								</td>
        						<td>
									<input class="winput" type="text" onkeyup="persenSK(<?php echo $r['id']; ?>)" id="bcfst<?php echo $r['id']; ?>" name="bcfst[]" value="<?php echo $r["bcfst"]; ?>">
								</td>
        						<td>
									<input class="winput" type="text" id="kadar_sk<?php echo $r['id']; ?>" name="kadar_sk[]" value="<?php echo $r["kadar_sk"]; ?>">
									<?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>
                                    <select id="kode_fibertio<?php echo $r['id']; ?>" name="kode_fibertio[]">
                                        <option value="">Pilih salah satu</option>
                                        <?php foreach($kode_fibertec as $au) : ?>
                                            <option <?= ($r['kode_fibertio'] == $au['nama_alat']) ? 'selected' : '';?> value="<?php echo $au['nama_alat'] ?>"><?php echo $au['nama_alat']; ?></option>
                                        <?php endforeach; ?>
                                    </select>
								</td>
								<td>
                                    <select id="jenis_oven<?php echo $r['id']; ?>" name="jenis_oven[]">
                                        <option value="">Pilih salah satu</option>
                                        <?php foreach($oven as $au) : ?>
                                            <option <?= ($r['jenis_oven'] == $au['nama_alat']) ? 'selected' : '';?> value="<?php echo $au['nama_alat'] ?>"><?php echo $au['nama_alat']; ?></option>
                                        <?php endforeach; ?>
                                    </select>
								</td>
								<td>
                                    <select id="jenis_furnace<?php echo $r['id']; ?>" name="jenis_furnace[]">
                                        <option value="">Pilih salah satu</option>
                                        <?php foreach($furnace as $au) : ?>
                                            <option <?= ($r['jenis_furnace'] == $au['nama_alat']) ? 'selected' : '';?> value="<?php echo $au['nama_alat'] ?>"><?php echo $au['nama_alat']; ?></option>
                                        <?php endforeach; ?>
                                    </select>
								</td>
								<td>
									<input class="winput" type="text" id="keterangan<?php echo $r['id']; ?>" name="keterangan[]" value="<?php echo $r["keterangan"]; ?>">
								</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>
			</form>
			<div class="panel panel-footer">
			
			</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 type="text/javascript">
	function persenSK(x){
		var h = $('#bcfso'+x).val();
		var i = $('#bcfst'+x).val();
		var g = $('#berat_sampel'+x).val();

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

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

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

	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\
					<?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' type='text' id='kode_crucible_filter"+c+"' name='kode_crucible_filter[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' id='berat_crucible_filter_kosong"+c+"' name='berat_crucible_filter_kosong[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' onkeyup='persenSK("+c+")' id='berat_sampel"+c+"' name='berat_sampel[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' onkeyup='persenSK("+c+")' id='bcfso"+c+"' name='bcfso[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' onkeyup='persenSK("+c+")' id='bcfst"+c+"' name='bcfst[]'>\n\
				</td>\n\
				<td>\n\
					<input class='winput' type='text' id='kadar_sk"+c+"' name='kadar_sk[]'>\n\
					<br><b>KS:</b><br>\n\
					<input class='' type='text' id='c_range"+c+"' name='c_range[]'>\n\
				</td>\n\
				<td>\n\
                    <select id='kode_fibertio"+c+"' name='kode_fibertio[]'>\n\
                        <option value=''>Pilih salah satu</option>\n\
                        <?php foreach($kode_fibertec as $au) : ?>\n\
                            <option value='<?= $au['nama_alat']?>'><?= $au['nama_alat']?></option>\n\
                        <?php endforeach; ?>\n\
                    </select>\n\
				</td>\n\
				<td>\n\
                    <select id='jenis_oven"+c+"' name='jenis_oven[]'>\n\
                        <option value=''>Pilih salah satu</option>\n\
                        <?php foreach($oven as $au) : ?>\n\
                            <option value='<?= $au['nama_alat']?>'><?= $au['nama_alat']?></option>\n\
                        <?php endforeach; ?>\n\
                    </select>\n\
				</td>\n\
				<td>\n\
                    <select id='jenis_furnace"+c+"' name='jenis_furnace[]'>\n\
                        <option value=''>Pilih salah satu</option>\n\
                        <?php foreach($furnace as $au) : ?>\n\
                            <option value='<?= $au['nama_alat']?>'><?= $au['nama_alat']?></option>\n\
                        <?php endforeach; ?>\n\
                    </select>\n\
				</td>\n\
				<td>\n\
					<input class='winput' 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>
