<?php 
ob_start();
session_start();
require_once("../conn/conn.php");
include('../utility/chksession.php');
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>Invoice - Ace Admin</title>

		<meta name="description" content="" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="../assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="../assets/font-awesome/4.5.0/css/font-awesome.min.css" />

		<!-- page specific plugin styles -->

		<!-- text fonts -->
		<link rel="stylesheet" href="../assets/css/fonts.googleapis.com.css" />

		<!-- ace styles -->
		<link rel="stylesheet" href="../assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />

		<!--[if lte IE 9]>
			<link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
		<![endif]-->
		<link rel="stylesheet" href="../assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="../assets/css/ace-rtl.min.css" />

		<!--[if lte IE 9]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->
		<script src="../assets/js/ace-extra.min.js"></script>

		<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->

		<!--[if lte IE 8]>
		<script src="assets/js/html5shiv.min.js"></script>
		<script src="assets/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body class="no-skin">
		
		<div class="main-container ace-save-state" id="main-container">
			<script type="text/javascript">
				try{ace.settings.loadState('main-container')}catch(e){}
			</script>


			<div class="main-content">
				<div class="main-content-inner">
					
					<div class="page-content">
						<div class="ace-settings-container" id="ace-settings-container">
							

							<div class="ace-settings-box clearfix" id="ace-settings-box">
								<div class="pull-left width-50">
									<div class="ace-settings-item">
										<div class="pull-left">
											<select id="skin-colorpicker" class="hide">
												<option data-skin="no-skin" value="#438EB9">#438EB9</option>
												<option data-skin="skin-1" value="#222A2D">#222A2D</option>
												<option data-skin="skin-2" value="#C6487E">#C6487E</option>
												<option data-skin="skin-3" value="#D0D0D0">#D0D0D0</option>
											</select>
										</div>
										<span>&nbsp; Choose Skin</span>
									</div>

									<div class="ace-settings-item">
										<input type="checkbox" class="ace ace-checkbox-2 ace-save-state" id="ace-settings-navbar" autocomplete="off" />
										<label class="lbl" for="ace-settings-navbar"> Fixed Navbar</label>
									</div>

									<div class="ace-settings-item">
										<input type="checkbox" class="ace ace-checkbox-2 ace-save-state" id="ace-settings-sidebar" autocomplete="off" />
										<label class="lbl" for="ace-settings-sidebar"> Fixed Sidebar</label>
									</div>

									<div class="ace-settings-item">
										<input type="checkbox" class="ace ace-checkbox-2 ace-save-state" id="ace-settings-breadcrumbs" autocomplete="off" />
										<label class="lbl" for="ace-settings-breadcrumbs"> Fixed Breadcrumbs</label>
									</div>

									<div class="ace-settings-item">
										<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-rtl" autocomplete="off" />
										<label class="lbl" for="ace-settings-rtl"> Right To Left (rtl)</label>
									</div>

									<div class="ace-settings-item">
										<input type="checkbox" class="ace ace-checkbox-2 ace-save-state" id="ace-settings-add-container" autocomplete="off" />
										<label class="lbl" for="ace-settings-add-container">
											Inside
											<b>.container</b>
										</label>
									</div>
								</div><!-- /.pull-left -->

								<div class="pull-left width-50">
									<div class="ace-settings-item">
										<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-hover" autocomplete="off" />
										<label class="lbl" for="ace-settings-hover"> Submenu on Hover</label>
									</div>

									<div class="ace-settings-item">
										<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-compact" autocomplete="off" />
										<label class="lbl" for="ace-settings-compact"> Compact Sidebar</label>
									</div>

									<div class="ace-settings-item">
										<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-highlight" autocomplete="off" />
										<label class="lbl" for="ace-settings-highlight"> Alt. Active Item</label>
									</div>
								</div><!-- /.pull-left -->
							</div><!-- /.ace-settings-box -->
						</div><!-- /.ace-settings-container -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="space-6"></div>

								<div class="row">
									<div class="col-sm-10 col-sm-offset-1">
										<div class="widget-box transparent">
											<div class="widget-header widget-header-large">
												<h3 class="widget-title grey lighter">
                                                แบบฟอร์มสรุปการชิม IN/JUST IN/OUT Test
												</h3>

												<div class="widget-toolbar no-border invoice-info">
													<span>หมายเลขเอกสาร :</span>
													<span>FM-QA-SS-003</span>

													<br />
													<span>แก้ไขครั้งที่ : </span>
													<span>00/2017</span>

                                                    <br />
													<span>วันที่มีผลบังคับใช้ : </span>
													<span>01/08/2017</span>
												</div>

											
											</div>

											<div class="widget-body">
									
                                                <?php
										//$io_code = $_REQUEST['io_code'];
									    //echo $io_code;

										//$strSQL = "SELECT * FROM qc_inout where io_code = '22980631JD' ";
										//$objQuery = mysqli_query($con,$strSQL);  

										$strSQL = "SELECT * FROM qc_inout";
										$objQuery = mysqli_query($con,$strSQL);  
										
										

											?>
														<table class="table table-striped table-bordered">
															<thead>
																<tr>
																	<th class="center">วันที่</th>
																	<th>ตัวอย่างที่ทดลอง </th>
																	<th class="hidden-xs">Code</th>
                                                                    <th class="hidden-480">Reference</th>
																	<th class="hidden-480">Appearance</th>
																	<th>1</th>
																	<th>2</th>
																	<th>3</th>
																	<th>4</th>
																	<th>5</th>
																	<th>6</th>
																	<th>สรุปผล</th>
																	<th>จัดเตรียมโดย</th>
                                                                    <th>หมายเหตุ</th>
																</tr>
															</thead>

															<tbody>
                                                            <?php
													while($objResult = mysqli_fetch_array($objQuery)){


														$strSQL1 = "SELECT * FROM qc_inout, qc_inoutresult 
														where qc_inout.io_code=qc_inoutresult.io_code
														and qc_inout.io_code='$objResult[io_code]'
														LIMIT 0,1";
														$objQuery1 = mysqli_query($con,$strSQL1);  
														$objResult1 = mysqli_fetch_array($objQuery1);

														$strSQL2 = "SELECT * FROM qc_inout, qc_inoutresult 
														where qc_inout.io_code=qc_inoutresult.io_code
														and qc_inout.io_code='$objResult[io_code]'
														LIMIT 1,1";
														$objQuery2 = mysqli_query($con,$strSQL2);  
														$objResult2 = mysqli_fetch_array($objQuery2);

														$strSQL3 = "SELECT * FROM qc_inout, qc_inoutresult 
														where qc_inout.io_code=qc_inoutresult.io_code
														and qc_inout.io_code='$objResult[io_code]'
														LIMIT 2,1";
														$objQuery3 = mysqli_query($con,$strSQL3);  
														$objResult3 = mysqli_fetch_array($objQuery3);

														$strSQL4 = "SELECT * FROM qc_inout, qc_inoutresult 
														where qc_inout.io_code=qc_inoutresult.io_code
														and qc_inout.io_code='$objResult[io_code]'
														LIMIT 3,1";
														$objQuery4 = mysqli_query($con,$strSQL4);  
														$objResult4 = mysqli_fetch_array($objQuery4);

														$strSQL5 = "SELECT * FROM qc_inout, qc_inoutresult 
														where qc_inout.io_code=qc_inoutresult.io_code
														and qc_inout.io_code='$objResult[io_code]'
														LIMIT 4,1";
														$objQuery5 = mysqli_query($con,$strSQL5);  
														$objResult5 = mysqli_fetch_array($objQuery5);

														$strSQL6 = "SELECT * FROM qc_inout, qc_inoutresult 
														where qc_inout.io_code=qc_inoutresult.io_code
														and qc_inout.io_code='$objResult[io_code]'
														LIMIT 5,1";
														$objQuery6 = mysqli_query($con,$strSQL6);  
														$objResult6 = mysqli_fetch_array($objQuery6);


														//คำนวน count
														$strSQLa = "SELECT COUNT(ior_r3)
														FROM `qc_inoutresult` 
														where io_code='$objResult[io_code]'";
														$objQuerya = mysqli_query($con,$strSQLa);  
														$objResulta = mysqli_fetch_array($objQuerya);

														$counttotal = $objResulta['COUNT(ior_r3)'];
														$counttotala=$counttotal*3;


														$strSQLb = "SELECT COUNT(ior_r3)
														FROM `qc_inoutresult` 
														where ior_r3='OUT'
														and io_code='$objResult[io_code]'";
														$objQueryb = mysqli_query($con,$strSQLb);  
														$objResultb = mysqli_fetch_array($objQueryb);
														
														$countout = $objResultb['COUNT(ior_r3)']*3;

														$strSQLc = "SELECT COUNT(ior_r3)
														FROM `qc_inoutresult` 
														where ior_r3='Just IN'
														and io_code='$objResult[io_code]'";
														$objQueryc = mysqli_query($con,$strSQLc);  
														$objResultc = mysqli_fetch_array($objQueryc);
														
														$countjustin = $objResultc['COUNT(ior_r3)']*0.5;




													?>
																<tr>
																	<td class="center"><?=$objResult['io_date'];  ?></td>
																	<td><?=$objResult['io_name']; ?></td>
																	<td class="hidden-xs"><?=$objResult['io_code']; ?></td>
																	<td class="hidden-480"><?=$objResult['io_ref']; ?></td>
																	<td class="hidden-480"><?php //echo "1".$objResult2['ior_r3'];
																		if(isset($objResult1['ior_r1'])) 
																		{
																			if($objResult1['ior_r1']=='OUT'){
																				echo "ไม่ผ่าน";
																			}elseif($objResult1['ior_r1']=='IN'){
 
																				echo "ผ่าน";
																			}
																		}else{

																			echo "-";
																		}
																	?></td>
                                                                    <td><?php //echo "1".$objResult2['ior_r3'];
																		if(isset($objResult1['ior_r3'])) 
																		{
																			echo $objResult1['ior_r3'];
																		}else{

																			echo "-";
																		}
																	?></td>
																	<td><?php //echo "2".$objResult3['ior_r3']; 
																		if(isset($objResult2['ior_r3'])) 
																		{
																			echo $objResult2['ior_r3'];
																		}else{

																			echo "-";
																		}
																	?></td>
																	<td><?php //echo "3".$objResult4['ior_r3'];								
																		if(isset($objResult3['ior_r3'])) 
																		{
																			echo $objResult3['ior_r3'];
																		}else{

																			echo "-";
																		}
																	 ?></td>
																	<td><?php //echo "4".$objResult5['ior_r3']; 
																		if(isset($objResult4['ior_r3'])) 
																		{
																			echo $objResult4['ior_r3'];
																		}else{
																	
																			echo "-";
																		}
																	?></td>
																	<td><?php //echo "5".$objResult6['ior_r3']; 
																		if(isset($objResult5['ior_r3'])) 
																		{
																			echo $objResult5['ior_r3'];
																		}else{
																	
																			echo "-";
																		}
																	?></td>
																	<td><?php //echo "6".$objResult7['ior_r3'];
																		if(isset($objResult6['ior_r3'])) 
																		{
																			echo $objResult6['ior_r3'];
																		}else{
																	
																			echo "-";
																		} 
																	?></td>
																	<td><?php 
																	if($counttotal=='6'){

																	//echo '6';

																	if($countout!=0 && $countjustin!=0 && $counttotala!= 0){

																		$defect = ($countout+$countjustin)/$counttotala;

																		$per = (1-$defect)*100;
	
																			//echo round($per,2)." %"; 
																			
																			if($per >= '80'){
	
																				echo "ผ่าน";
																			}else{
																				echo "ไม่ผ่าน";
																			}
																	}else{


																	}

																	}elseif($counttotal=='4'){


																		//echo '4';
																		$defect = $countout/$counttotala;

																		$per = (1-$defect)*100;
	
																			//echo round($per,2)." %"; 
																			
																			if($per >= '80'){
	
																				echo "ผ่าน";
																			}else{
																				echo "ไม่ผ่าน";
																			}

																		}else{


																	}
																	
																	
																		?>
																	</td>
																	<td><?php echo $objResult['io_recorder'] ?></td>
                                                                    <td><?php //echo isset($objResult1['ior_note']); 
																	if(isset($objResult1['ior_note'])) 
																	{
																		echo $objResult1['ior_note']." ";
																	}else{
																
																		echo "";
																	}
																	if(isset($objResult2['ior_note'])) 
																	{
																		echo $objResult2['ior_note']." ";
																	}else{
																
																		echo "";
																	}
																	if(isset($objResult3['ior_note'])) 
																	{
																		echo $objResult3['ior_note']." ";
																	}else{
																
																		echo "";
																	}
																	if(isset($objResult4['ior_note'])) 
																	{
																		echo $objResult4['ior_note']." ";
																	}else{
																
																		echo "";
																	}
																	if(isset($objResult5['ior_note'])) 
																	{
																		echo $objResult5['ior_note']." ";
																	}else{
																
																		echo "";
																	}
																	if(isset($objResult6['ior_note'])) 
																	{
																		echo $objResult6['ior_note']." ";
																	}else{
																
																		echo "";
																	}
																	?></td>
																</tr>
                                                        <?php
                                                            }

                                                        ?>
															</tbody>
														</table>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>

								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->


			<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
			</a>
		</div><!-- /.main-container -->

		<!-- basic scripts -->

		<!--[if !IE]> -->
		<script src="../assets/js/jquery-2.1.4.min.js"></script>

		<!-- <![endif]-->

		<!--[if IE]>
<script src="assets/js/jquery-1.11.3.min.js"></script>
<![endif]-->
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="../assets/js/bootstrap.min.js"></script>

		<!-- page specific plugin scripts -->

		<!-- ace scripts -->
		<script src="../assets/js/ace-elements.min.js"></script>
		<script src="../assets/js/ace.min.js"></script>

		<!-- inline scripts related to this page -->
	</body>
</html>
