<?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>

<div class="panel panel-lime">
<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 Urea
                                <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;">
                          <?php //var_dump($grafik) ?>
                          <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 endif; ?>

<?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">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_<?= $r['id']; ?>" class="">
                        		<td class="text-center"><?= $this->uri->segment(5) + $z++ ?></td>
        						<td class="text-center">
        							<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" type="text" onkeyup="persenUr(<?= $r['id']; ?>)" id="abs_standart<?= $r['id']; ?>" name="abs_standart[]" value="<?= $r["abs_standart"]; ?>">
								</td>
								<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?= $r['id']; ?>)" id="abs_sampel<?= $r['id']; ?>" name="abs_sampel[]" value="<?= $r["abs_sampel"]; ?>">
								</td>
								<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?= $r['id']; ?>)" id="sampel_yang_ditimbang<?= $r['id']; ?>" name="sampel_yang_ditimbang[]" value="<?= $r["sampel_yang_ditimbang"]; ?>">
								</td>
								<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?= $r['id']; ?>)" id="volume_larutan_induk<?= $r['id']; ?>" name="volume_larutan_induk[]" value="500">
								</td>
								<td>
									<input class="winput text-center" type="text" onkeyup="persenUr(<?= $r['id']; ?>)" id="volume_alikuot_sampel<?= $r['id']; ?>" name="volume_alikuot_sampel[]" value="5">
								</td>
								<td>
									<input class="winput text-center" type="text" id="mg_sampel_dalam_alikuot<?= $r['id']; ?>" name="mg_sampel_dalam_alikuot[]" value="<?= $r["mg_sampel_dalam_alikuot"]; ?>">
								</td>
								<td>
									<input class="winput text-center" type="text" id="kadar_ur<?= $r['id']; ?>" name="kadar_ur[]" value="<?= $r["kadar_ur"]; ?>">
									<?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>
                        <img src="<?= 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:250px;" onchange="klik_tgl('ket_0');" type="text" id="ket_0" name="ket_0[]" value="<?= $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:250px;" class="input-group">
                                        <input style="width:50px;" onchange="klik_tgl('ket_1');" value="<?= ($data[0]['ket_1']) ? date('Y-m-d', $data[0]['ket_1']) : null; ?>"  type="date" id="ket_1" name="ket_1[]">
                                        <input class="" id="c_ket_1" class="" value="<?= get_str_date2(($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:250px;" class="input-group">
                                        <input style="width:50px;" onchange="klik_tgl('ket_2');" value="<?= ($data[0]['ket_2']) ? date('Y-m-d', $data[0]['ket_2']) : null; ?>" type="date" id="ket_2" name="ket_2[]">
                                        <input class="" id="c_ket_2" class="" value="<?= get_str_date2(($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:250px;" class="input-group">
                                        <input style="width:50px;" onchange="klik_tgl('ket_3');" value="<?= ($data[0]['ket_3']) ? date('Y-m-d', $data[0]['ket_3']) : null; ?>"  type="date" id="ket_3" name="ket_3[]">
                                        <input class="" id="c_ket_3" class="" value="<?= get_str_date2(($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:250px;" class="input-group">
                                        <input style="width:50px;" onchange="klik_tgl('ket_4');"  type="date" id="ket_4" value="<?= ($data[0]['ket_4']) ? date('Y-m-d', $data[0]['ket_4']) : null; ?>" name="ket_4[]">
                                        <input class="" id="c_ket_4" class="" value="<?= get_str_date2(($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:250px;" class="input-group">
                                        <input style="width:50px;" onchange="klik_tgl('ket_5');"  type="date" id="ket_5" value="<?= ($data[0]['ket_5']) ? date('Y-m-d', $data[0]['ket_5']) : null; ?>" name="ket_5[]">
                                        <input class="" id="c_ket_5" class="" value="<?= get_str_date2(($data[0]['ket_5'] ? $data[0]['ket_5'] : '')); ?>" readonly>
                                    </div>
                                </td>
                            </tr>
                        </table>

                    </div>
                </div> <!-- end panel-footer -->
            </form> <!-- end form -->
        </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'><?= $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 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\
				<!-- ========================================= -->\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[] = (round($r['deret_std_urea'], 1)).'d';}?>
<?php $b=array(); foreach($grafik as $r) {$b[] = $r['abs'];}?>
<?php 
  $n = '';
  $d = array();
  for($i=0;$i< 35 ;$i++){
    $v = $i*0.1-1.2;
    $v = (strlen($v)>10?'0':$v).'d';
    $d[] = $v;

    if(in_array($v, $a)) {
      for($c=0;$c<count($a);$c++) {
        if($v == $a[$c]) {
          if($b[$c] == 0){
            $n .= 'null,';
          }else{
            $n .= $b[$c].',';  
          }  
        }
      }
    } else {
      $n .= 'null,';
    }
  }

?>


<script>
new Chart(document.getElementById("line-chart"), {
  type: 'line',
  data: {
    labels: [<?php for ($i = 0; $i < 35 ; $i++) {
    $v = $i*0.1-1.2;
    echo (strlen($v)>10?'0':$v).',';
}?>],
    datasets: [{
        data: [<?php echo $n; ?>],
        label: '',//"Data Uji Sampel",
        borderColor: "#00e6e6",
        backgroundColor: "rgba(0, 0, 0, 0)",
        fill: true
      }
    ]
  },
  options: {
    spanGaps: true,
    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: {
                min: 0.000,
                max: 2.100,

                // forces step size to be 5 units
                stepSize: 0.200
            },
          display: true,
          scaleLabel: {
              display: true,
              labelString: ''//'Bulan'
          }
                }],
            yAxes: [{
            display: true,
            scaleLabel: {
              display: true,
              labelString: ''//'Jumlah Sampel'
            },
            ticks: {
              min: .000,
              max: 1.300,

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