<?php if(!empty($is_grafik)) { ?>
<script src="<?php echo base_url();?>/assets/plugins/chart-js/Chart.min.js"></script>
<script src="<?php echo base_url();?>/assets/plugins/chart-js/chartjs-plugin-datalabels.min.js"></script>
<script src="<?php echo base_url();?>/assets/plugins/gritter/js/jquery.gritter.js"></script>
<script src="<?php echo base_url();?>/assets/js/page-index-v3.demo.min.js"></script>
<?php } ?>
<?php if(!empty($is_grafik)) { ?>
<div class="panel panel-grey">
<div class="panel no-rounded-corner bg-default text-white wrapper m-b-0">
<div class="chartjs-size-monitor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: hidden; pointer-events: none; visibility: hidden; z-index: -1;">
<div class="chartjs-size-monitor-expand" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;">
<div style="position:absolute;width:1000000px;height:1000000px;left:0;top:0">
</div></div><div class="chartjs-size-monitor-shrink" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:200%;height:200%;left:0; top:0"></div></div></div>
                            <!-- end btn-group -->
                            <!-- begin title -->
                            <h4 class=" m-t-0 m-b-10">
                                <i class="fa fa-snowflake-o text-success-light"></i> Grafik Deret Standar Fosfor
                                <small class="text-muted m-l-5"><?php echo date('Y'); ?></small>
                            </h4>
                            <!-- end title -->
                            <!-- begin chart -->
                        <canvas id="line-chart" style="display: block; width: 500px; height: 166px;" height="166" width="500"></canvas>
                        </div>
                        <div class="col-sm-12" style="margin-left: 40px;">
                          <h4>Rumus Persamaan</h4>
                          <label> y = <?php echo $grafik[0]['slope'].'x '.(strpos('|'.$grafik[0]['intercept'], '-')  == false ? '+' : '').$grafik[0]['intercept']; ?></label>
                          <br>
                          <label> r = <?php echo round($grafik[0]['d_range'], 4);?></label>
                        </div>
</div>
<?php } ?>

<?php $this->load->view('uji_analis/header_input01'); ?>

                	<table class="table table-bordered table-hover table-striped table-td-valign-middle">
                		<thead>
							<tr>
								<th class="text-center">No.</th>
								<th class="text-center">Nomor Sampel</th>
								<th class="text-center">Kode krusibel porselen</th>
								<th class="text-center">Berat Sampel (gram)</th>
								<th class="text-center">V Indukan (mL)</th>
								<th class="text-center">V Labu (mL)</th>
								<th class="text-center">V Pipet (mL)</th>
								<th class="text-center">Abs</th>
								<th class="text-center">Intercept (a)</th>
								<th class="text-center">Slope (b)</th>
								<th class="text-center">Konsentrasi Sampel (ppm)</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']; ?>">
	                        	<td class="text-center"><?= $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_krusibel_porselen<?= $r['id']; ?>" name="kode_krusibel_porselen[]" value="<?= ($r["kode_krusibel_porselen"]) ? $r["kode_krusibel_porselen"] : $r["abu_kb"]; ?>">
								</td>
		                        <td>
									<input class="winput" type="text" onkeyup="persenP(<?= $r['id']; ?>)" id="berat_sampel<?= $r['id']; ?>" name="berat_sampel[]" value="<?= ($r["berat_sampel"]) ? $r["berat_sampel"] : $r["abu_bs"]; ?>">
								</td>
								<td>
									<input class="winput" type="text" onkeyup="persenP(<?= $r['id']; ?>)" id="v_indukan<?= $r['id']; ?>" name="v_indukan[]" value="250">
								</td>
		                        <td>
									<input class="winput" type="text" onkeyup="persenP(<?= $r['id']; ?>)" id="v_labu<?= $r['id']; ?>" name="v_labu[]" value="25">
								</td>
		                        <td>
									<input class="winput" type="text" onkeyup="persenP(<?= $r['id']; ?>)" id="v_pipet<?= $r['id']; ?>" name="v_pipet[]" value="<?= $r["v_pipet"]; ?>">
								</td>
		                        <td>
									<input class="winput" type="text" onkeyup="persenP(<?= $r['id']; ?>)" id="abs<?= $r['id']; ?>" name="abs[]" value="<?= $r["abs"]; ?>">
								</td>
		                        <td>
									<input class="winput" type="text" onkeyup="persenP(<?= $r['id']; ?>)" id="intercept<?= $r['id']; ?>" name="intercept[]" value="<?= (!empty($intercept)) ? $intercept : $r['intercept']; ?>">
								</td>
		                        <td>
									<input class="winput" type="text" onkeyup="persenP(<?= $r['id']; ?>)" id="slope<?= $r['id']; ?>" name="slope[]" value="<?= (!empty($slope)) ? $slope : $r['slope']; ?>">
								</td>
		                        <td>
									<input class="winput" type="text" onkeyup="persenP(<?= $r['id']; ?>)" id="konsentrasi_sampel<?= $r['id']; ?>" name="konsentrasi_sampel[]" value="<?= $r["konsentrasi_sampel"]; ?>">
								</td>
		                        <td colspan="2">
									<input class="winput" type="text" id="kadar_p<?= $r['id'] ?>" name="kadar_p[]" value="<?= $r["kadar_p"]; ?>">
									<?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>

								<!-- ===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 -->
			<div class="panel panel-footer bg-white">
				<div>
					<h5>Keterangan</h5>
					<table>
						<tr>
							<td>1</td>
							<td>Tanggal pembuatan Larutan Molybdovanadate</td>
							<td>:</td>
							<td>
								<div style="width:250px;" class="input-group">
									<input style="width:50px;" onchange="klik_tgl('ket_1');" type="date" id="ket_1" value="<?= get_str_date($data[0]['ket_1']); ?>" name="ket_1[]">
									<input class="" id="c_ket_1" class="" value="<?= get_str_date2($data[0]['ket_1']); ?>" readonly>
								</div>
							</td>
						</tr>
						<tr>
							<td>2</td>
							<td>Tanggal pembuatan Larutan Standar Fosfor 2000 ppm</td>
							<td>:</td>
							<td>
								<div style="width:250px;" class="input-group">
									<input style="width:50px;" onchange="klik_tgl('ket_2');" type="date" id="ket_2" value="<?= get_str_date($data[0]['ket_1']); ?>" name="ket_2[]">
									<input class="" id="c_ket_2" class="" value="<?= get_str_date2($data[0]['ket_1']); ?>" readonly>
								</div>
							</td>
						</tr>
						<tr>
							<td>3</td>
							<td><input class="winput" type="text" id="ket_3" name="ket_3[]" value="<?= $data[0]['ket_3']; ?>"></td>
							<td></td>
							<td>
							</td>
						</tr>
					</table>
				</div>
			</form>
		  </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 type="text/javascript">
	function persenP(x){
		var g = $('#v_indukan'+x).val();
		var h = $('#v_labu'+x).val();
		var f = $('#berat_sampel'+x).val();
		var i = $('#v_pipet'+x).val();

		var j = $('#abs'+x).val();
		var k = $('#intercept'+x).val();
		var l = $('#slope'+x).val();

		if(j === '') j = 0;
		if(k === '') k = 0;
		if(l === '') l = 0;

		var m = (parseFloat(j)-parseFloat(k))/parseFloat(l);

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

		if(g === '') g = 0;
		if(h === '') h = 0;
		if(f === '') f = 0;
		if(m === '') m = 0;
		if(i === '') i = 0;
		
		console.log(g);
		console.log(h);
		console.log(f);
		console.log(i);
		console.log(j);
		console.log(k);
		console.log(l);
		console.log(m);
		console.log(d);

		var z = (parseFloat(g)*parseFloat(h)*parseFloat(m))/(parseFloat(f)*parseFloat(i)*10000);

        console.log(z);

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

        console.log($('#kadar_p'+x).val());
	}

	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' type='text' id='kode_krusibel_porselen"+c+"' name='kode_krusibel_porselen[]' >\n\
			</td>\n\
		    <td>\n\
				<input class='winput' type='text' onkeyup='persenP("+c+")' id='berat_sampel"+c+"' name='berat_sampel[]' >\n\
			</td>\n\
			<td>\n\
				<input class='winput' type='text' onkeyup='persenP("+c+")' id='v_indukan"+c+"' name='v_indukan[]' value='250' >\n\
			</td>\n\
		    <td>\n\
				<input class='winput' type='text' onkeyup='persenP("+c+")' id='v_labu"+c+"' name='v_labu[]' value='25' >\n\
			</td>\n\
		    <td>\n\
				<input class='winput' type='text' onkeyup='persenP("+c+")' id='v_pipet"+c+"' name='v_pipet[]' >\n\
			</td>\n\
		    <td>\n\
				<input class='winput' type='text' onkeyup='persenP("+c+")' id='abs"+c+"' name='abs[]' >\n\
			</td>\n\
		    <td>\n\
				<input class='winput' type='text' onkeyup='persenP("+c+")' id='intercept"+c+"' name='intercept[]' value='<?= (!empty($intercept)) ? $intercept : $r['intercept']; ?>'>\n\
			</td>\n\
		    <td>\n\
				<input class='winput' type='text' onkeyup='persenP("+c+")' id='slope"+c+"' name='slope[]' value='<?= (!empty($slope)) ? $slope : $r['slope']; ?>'>\n\
			</td>\n\
		    <td>\n\
				<input class='winput' type='text' onkeyup='persenP("+c+")' id='konsentrasi_sampel"+c+"' name='konsentrasi_sampel[]'>\n\
			</td>\n\
		    <td colspan='2'>\n\
				<input class='winput' type='text' id='kadar_p"+c+"' name='kadar_p[]' value='<?= $r['kadar_p']; ?>'>\n\
				<span style='font-size:10px;' class='text-center'><b>KS:</b></span>\n\
				<input class='' 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\
			<!-- ========================================= -->\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>


<?php if(!empty($is_grafik)) : ?>
<?php $a=array(); foreach($grafik as $r) {$a[] = $r['deret_std_p'];}?>
<?php $b=array(); foreach($grafik as $r) {$b[] = $r['abs'];}?>
<?php 
  $n = '';
  for($i=0;$i<=(int)(end($a)+2);$i+=2){
    if(in_array($i,$a)){
      for($c=0;$c<count($a);$c++){
        if($i == $a[$c]){
          $n .= $b[$c].',';
        }
      }
    }else {
      $n .= 'null,';
    }
  }
?>

<script>
new Chart(document.getElementById("line-chart"), {
  type: 'line',
  data: {
    labels: [<?php for($i=0; $i<=(int)(end($a)+2);$i+=2) {echo $i.',';}?>],
    datasets: [{
        data: [<?php echo $n; ?>],
        label: '',//"Data Uji Sampel",
    borderColor: "#00e6e6",
        fill: true
      }
    ]
  },
  options: {
    elements: {
      line: {
          tension: 0
      }
    },
  	legend: { display: false },
    title: {
      display: false,
    //   text: 'World population per region (in millions)'
    },
    plugins: {
      datalabels: {
          anchor :'end',
          align :'top',
      }
    },
    scales: {
        xAxes: [{
            ticks: {
                autoSkip: false,
                //maxRotation: 90
            },
					display: true,
					scaleLabel: {
							display: true,
							labelString: ''//'Bulan'
					}
                }],
                yAxes: [{
						display: true,
						scaleLabel: {
							display: true,
							labelString: ''//'Jumlah Sampel'
						},
						ticks: {
							min: 0.000,
							max: 1.000,

							// forces step size to be 5 units
							stepSize: 0.200
						}
					}]
      }
  }
});
</script>
<?php endif; ?>
