<?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>Nortern Production - 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">
					<!-- /.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
										
											$Cli_date1 = $_POST['Cli_date1'];
											$Cli_date2 = $_POST['Cli_date2'];
											$Item_id = $_POST['Item_id'];
											$Cli_code = $_POST['Cli_code'];
		
											//echo $Cli_date1.$Cli_date2.$Item_id.$Cli_code;
											?></br><?	
										
											echo "วันที่  "."$Cli_date1"." - "."$Cli_date2";
											?></br><?		
											?></br><?								
										
											if($Cli_date1 != "" && $Cli_date2 !="" && $Item_id!="NULL" && $Cli_code!=""){
												//echo "1 วันที่1".$Cli_date1."วันที่2".$Cli_date2."item".$Item_id."code".$Cli_code;
												
												$strSQL = "SELECT * FROM qc_checklistitem 
												WHERE Cli_date BETWEEN '$Cli_date1' AND '$Cli_date2'
												AND Item_id='$Item_id'
												AND Cli_code='$Cli_code'";
												$objQuery = mysqli_query($con,$strSQL);  
										
										

											?>
														<table class="table table-striped table-bordered" width='100%'>
															<thead>
																<tr>
																  <th rowspan="2%" class="center">วันที่</th>
																  <th rowspan="2">ตัวอย่างที่ทดลอง </th>
																  <th rowspan="2" class="hidden-xs">Code</th>
																  <th rowspan="10%" class="hidden-480">Reference</th>
																  <th colspan="6">Sensory</th>
																  <th rowspan="2">ผล</th>
																  <th rowspan="2">สรุปผล</th>
																  <th rowspan="2">จัดเตรียมโดย</th>
																  <th rowspan="2">ผู้ตรวจสอบ</th>
																  <th rowspan="2">หมายเหตุ</th>
															  </tr>
																<tr>
																  <th width="65">1</th>
																	<th width="95">2</th>
																	<th width="95">3</th>
																	<th width="95">4</th>
																	<th width="95">5</th>
																	<th width="100">6</th>
																</tr>
															</thead>

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

                                                        $strSQL1 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 0,1;";
														$objQuery1 = mysqli_query($con,$strSQL1);  
														$objResult1 = mysqli_fetch_array($objQuery1);

                                                        $strSQL2 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 1,1;";
														$objQuery2 = mysqli_query($con,$strSQL2);  
														$objResult2 = mysqli_fetch_array($objQuery2);

                                                        $strSQL3 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 2,1;";
														$objQuery3 = mysqli_query($con,$strSQL3);  
														$objResult3 = mysqli_fetch_array($objQuery3);

                                                        $strSQL4 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 3,1;";
														$objQuery4 = mysqli_query($con,$strSQL4);  
														$objResult4 = mysqli_fetch_array($objQuery4);

                                                        $strSQL5 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 4,1;";
														$objQuery5 = mysqli_query($con,$strSQL5);  
														$objResult5 = mysqli_fetch_array($objQuery5);

                                                        $strSQL6 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 5,1;";
														$objQuery6 = mysqli_query($con,$strSQL6);  
														$objResult6 = mysqli_fetch_array($objQuery6);


													?>
																<tr>
																	<td width="150" class="center"><?=$objResult['Cli_date'];  ?></td>
																	
																	<td width="200"><?=$objResult['Item_id']." - ".$objResult['Item_name']; ?></td>
                                                                    <td width="100"><?=$objResult['Cli_code']; ?></td>
                                                                    <td width="69"><?=$objResult['Cli_ref']; ?></td>
  
                                                                    <td><?php //echo $objResult1['result'];
                                                                    
                                                                    if(isset($objResult1['result'])) 
																	{echo $objResult1['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult2['result'])) 
																	{echo $objResult2['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php
                                                                    if(isset($objResult3['result'])) 
																	{echo $objResult3['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult4['result'])) 
																	{echo $objResult4['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult5['result'])) 
																	{echo $objResult5['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult6['result'])) 
																	{echo $objResult6['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td align="center" width="70"><?php 

																	//คำนวน count
																	$strSQLa = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQuerya = mysqli_query($con,$strSQLa);  
																	$objResulta = mysqli_fetch_array($objQuerya);

																	$counttotal = $objResulta['COUNT(result)'];
																	$counttotala=$counttotal*3;
																	//echo $counttotal;


																	$strSQLb = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='OUT'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryb = mysqli_query($con,$strSQLb);  
																	$objResultb = mysqli_fetch_array($objQueryb);
																	
																	$countout = $objResultb['COUNT(result)']*3;
																//	echo $countout;

																	$strSQLc = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='Just IN'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryc = mysqli_query($con,$strSQLc);  
																	$objResultc = mysqli_fetch_array($objQueryc);
																	
																	$countjustin = $objResultc['COUNT(result)']*0.5;
																	//echo $countjustin;



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

															*/
																	if($counttotal=='6'){

																	//echo '6';

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

																		$per = (1-$defect)*100;
	
																			echo round($per,2)." % "; 
																			
																			if($per >= '80'){
	
																				//echo "ผ่าน";
																			}else{
																				//echo "ไม่ผ่าน";
																			}
																	}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 width="70" align="center"><?php 

																	//คำนวน count
																	$strSQLa = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQuerya = mysqli_query($con,$strSQLa);  
																	$objResulta = mysqli_fetch_array($objQuerya);

																	$counttotal = $objResulta['COUNT(result)'];
																	$counttotala=$counttotal*3;
																	//echo $counttotal;


																	$strSQLb = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='OUT'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryb = mysqli_query($con,$strSQLb);  
																	$objResultb = mysqli_fetch_array($objQueryb);
																	
																	$countout = $objResultb['COUNT(result)']*3;
																//	echo $countout;

																	$strSQLc = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='Just IN'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryc = mysqli_query($con,$strSQLc);  
																	$objResultc = mysqli_fetch_array($objQueryc);
																	
																	$countjustin = $objResultc['COUNT(result)']*0.5;
																	//echo $countjustin;



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

															*/
																	if($counttotal=='6'){

																	//echo '6';

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

																		$per = (1-$defect)*100;
	
																			//echo round($per,2)." % "; 
																			
																			if($per >= '80'){
	
																				echo "ผ่าน";
																			}else{
																				echo "ไม่ผ่าน";
																			}
																	}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 width="100"><?php echo $objResult['Cli_record'] ?></td>
                                                                    <td width="74"><?php echo $objResult['Cli_checker'] ?></td>
                                                                    <td width="70"><?php echo $objResult['Cli_note']; 
                                                                    
																	?></td>
																</tr>
                                                        <?php
                                                            }

                                                        ?>
															</tbody>
														</table>
												
												<?
												
											}else if($Cli_date1 != "" && $Cli_date2 !="" && $Item_id=="NULL" && $Cli_code!=""){
												//echo "2 วันที่1".$Cli_date1."วันที่2".$Cli_date2."item".$Item_id."code".$Cli_code;
												
												$strSQL = "SELECT * FROM qc_checklistitem 
												WHERE Cli_date BETWEEN '$Cli_date1' AND '$Cli_date2'
												AND Cli_code='$Cli_code';";
												$objQuery = mysqli_query($con,$strSQL);  
										
										

											?>
														<table class="table table-striped table-bordered" width='100%'>
															<thead>
																<tr>
																  <th rowspan="2%" class="center">วันที่</th>
																  <th rowspan="2">ตัวอย่างที่ทดลอง </th>
																  <th rowspan="2" class="hidden-xs">Code</th>
																  <th rowspan="10%" class="hidden-480">Reference</th>
																  <th colspan="6">Sensory</th>
																  <th rowspan="2">ผล</th>
																  <th rowspan="2">สรุปผล</th>
																  <th rowspan="2">จัดเตรียมโดย</th>
																  <th rowspan="2">ผู้ตรวจสอบ</th>
																  <th rowspan="2">หมายเหตุ</th>
															  </tr>
																<tr>
																  <th width="65">1</th>
																	<th width="95">2</th>
																	<th width="95">3</th>
																	<th width="95">4</th>
																	<th width="95">5</th>
																	<th width="100">6</th>
																</tr>
															</thead>

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

                                                        $strSQL1 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 0,1;";
														$objQuery1 = mysqli_query($con,$strSQL1);  
														$objResult1 = mysqli_fetch_array($objQuery1);

                                                        $strSQL2 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 1,1;";
														$objQuery2 = mysqli_query($con,$strSQL2);  
														$objResult2 = mysqli_fetch_array($objQuery2);

                                                        $strSQL3 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 2,1;";
														$objQuery3 = mysqli_query($con,$strSQL3);  
														$objResult3 = mysqli_fetch_array($objQuery3);

                                                        $strSQL4 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 3,1;";
														$objQuery4 = mysqli_query($con,$strSQL4);  
														$objResult4 = mysqli_fetch_array($objQuery4);

                                                        $strSQL5 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 4,1;";
														$objQuery5 = mysqli_query($con,$strSQL5);  
														$objResult5 = mysqli_fetch_array($objQuery5);

                                                        $strSQL6 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 5,1;";
														$objQuery6 = mysqli_query($con,$strSQL6);  
														$objResult6 = mysqli_fetch_array($objQuery6);


													?>
																<tr>
																	<td width="150" class="center"><?=$objResult['Cli_date'];  ?></td>
																	
																	<td width="200"><?=$objResult['Item_id']." - ".$objResult['Item_name']; ?></td>
                                                                    <td width="100"><?=$objResult['Cli_code']; ?></td>
                                                                    <td width="69"><?=$objResult['Cli_ref']; ?></td>
  
                                                                    <td><?php //echo $objResult1['result'];
                                                                    
                                                                    if(isset($objResult1['result'])) 
																	{echo $objResult1['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult2['result'])) 
																	{echo $objResult2['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php
                                                                    if(isset($objResult3['result'])) 
																	{echo $objResult3['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult4['result'])) 
																	{echo $objResult4['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult5['result'])) 
																	{echo $objResult5['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult6['result'])) 
																	{echo $objResult6['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td align="center" width="70"><?php 

																	//คำนวน count
																	$strSQLa = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQuerya = mysqli_query($con,$strSQLa);  
																	$objResulta = mysqli_fetch_array($objQuerya);

																	$counttotal = $objResulta['COUNT(result)'];
																	$counttotala=$counttotal*3;
																	//echo $counttotal;


																	$strSQLb = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='OUT'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryb = mysqli_query($con,$strSQLb);  
																	$objResultb = mysqli_fetch_array($objQueryb);
																	
																	$countout = $objResultb['COUNT(result)']*3;
																//	echo $countout;

																	$strSQLc = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='Just IN'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryc = mysqli_query($con,$strSQLc);  
																	$objResultc = mysqli_fetch_array($objQueryc);
																	
																	$countjustin = $objResultc['COUNT(result)']*0.5;
																	//echo $countjustin;



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

															*/
																	if($counttotal=='6'){

																	//echo '6';

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

																		$per = (1-$defect)*100;
	
																			echo round($per,2)." % "; 
																			
																			if($per >= '80'){
	
																				//echo "ผ่าน";
																			}else{
																				//echo "ไม่ผ่าน";
																			}
																	}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 width="70" align="center"><?php 

																	//คำนวน count
																	$strSQLa = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQuerya = mysqli_query($con,$strSQLa);  
																	$objResulta = mysqli_fetch_array($objQuerya);

																	$counttotal = $objResulta['COUNT(result)'];
																	$counttotala=$counttotal*3;
																	//echo $counttotal;


																	$strSQLb = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='OUT'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryb = mysqli_query($con,$strSQLb);  
																	$objResultb = mysqli_fetch_array($objQueryb);
																	
																	$countout = $objResultb['COUNT(result)']*3;
																//	echo $countout;

																	$strSQLc = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='Just IN'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryc = mysqli_query($con,$strSQLc);  
																	$objResultc = mysqli_fetch_array($objQueryc);
																	
																	$countjustin = $objResultc['COUNT(result)']*0.5;
																	//echo $countjustin;



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

															*/
																	if($counttotal=='6'){

																	//echo '6';

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

																		$per = (1-$defect)*100;
	
																			//echo round($per,2)." % "; 
																			
																			if($per >= '80'){
	
																				echo "ผ่าน";
																			}else{
																				echo "ไม่ผ่าน";
																			}
																	}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 width="100"><?php echo $objResult['Cli_record'] ?></td>
                                                                    <td width="74"><?php echo $objResult['Cli_checker'] ?></td>
                                                                    <td width="70"><?php echo $objResult['Cli_note']; 
                                                                    
																	?></td>
																</tr>
                                                        <?php
                                                            }

                                                        ?>
															</tbody>
														</table>
												
												<?
												
												
											}else if($Cli_date1 != "" && $Cli_date2 !="" && $Item_id!="NULL" && $Cli_code==""){
													//echo "3 วันที่1".$Cli_date1."วันที่2".$Cli_date2."item".$Item_id."code".$Cli_code;
													$strSQL = "SELECT * FROM qc_checklistitem 
												WHERE Cli_date BETWEEN '$Cli_date1' AND '$Cli_date2'
												AND Item_id='$Item_id'";
												$objQuery = mysqli_query($con,$strSQL);  
										
										

											?>
														<table class="table table-striped table-bordered" width='100%'>
															<thead>
																<tr>
																  <th rowspan="2%" class="center">วันที่</th>
																  <th rowspan="2">ตัวอย่างที่ทดลอง </th>
																  <th rowspan="2" class="hidden-xs">Code</th>
																  <th rowspan="10%" class="hidden-480">Reference</th>
																  <th colspan="6">Sensory</th>
																  <th rowspan="2">ผล</th>
																  <th rowspan="2">สรุปผล</th>
																  <th rowspan="2">จัดเตรียมโดย</th>
																  <th rowspan="2">ผู้ตรวจสอบ</th>
																  <th rowspan="2">หมายเหตุ</th>
															  </tr>
																<tr>
																  <th width="65">1</th>
																	<th width="95">2</th>
																	<th width="95">3</th>
																	<th width="95">4</th>
																	<th width="95">5</th>
																	<th width="100">6</th>
																</tr>
															</thead>

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

                                                        $strSQL1 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 0,1;";
														$objQuery1 = mysqli_query($con,$strSQL1);  
														$objResult1 = mysqli_fetch_array($objQuery1);

                                                        $strSQL2 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 1,1;";
														$objQuery2 = mysqli_query($con,$strSQL2);  
														$objResult2 = mysqli_fetch_array($objQuery2);

                                                        $strSQL3 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 2,1;";
														$objQuery3 = mysqli_query($con,$strSQL3);  
														$objResult3 = mysqli_fetch_array($objQuery3);

                                                        $strSQL4 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 3,1;";
														$objQuery4 = mysqli_query($con,$strSQL4);  
														$objResult4 = mysqli_fetch_array($objQuery4);

                                                        $strSQL5 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 4,1;";
														$objQuery5 = mysqli_query($con,$strSQL5);  
														$objResult5 = mysqli_fetch_array($objQuery5);

                                                        $strSQL6 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 5,1;";
														$objQuery6 = mysqli_query($con,$strSQL6);  
														$objResult6 = mysqli_fetch_array($objQuery6);


													?>
																<tr>
																	<td width="150" class="center"><?=$objResult['Cli_date'];  ?></td>
																	
																	<td width="200"><?=$objResult['Item_id']." - ".$objResult['Item_name']; ?></td>
                                                                    <td width="100"><?=$objResult['Cli_code']; ?></td>
                                                                    <td width="69"><?=$objResult['Cli_ref']; ?></td>
  
                                                                    <td><?php //echo $objResult1['result'];
                                                                    
                                                                    if(isset($objResult1['result'])) 
																	{echo $objResult1['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult2['result'])) 
																	{echo $objResult2['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php
                                                                    if(isset($objResult3['result'])) 
																	{echo $objResult3['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult4['result'])) 
																	{echo $objResult4['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult5['result'])) 
																	{echo $objResult5['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult6['result'])) 
																	{echo $objResult6['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td align="center" width="70"><?php 

																	//คำนวน count
																	$strSQLa = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQuerya = mysqli_query($con,$strSQLa);  
																	$objResulta = mysqli_fetch_array($objQuerya);

																	$counttotal = $objResulta['COUNT(result)'];
																	$counttotala=$counttotal*3;
																	//echo $counttotal;


																	$strSQLb = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='OUT'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryb = mysqli_query($con,$strSQLb);  
																	$objResultb = mysqli_fetch_array($objQueryb);
																	
																	$countout = $objResultb['COUNT(result)']*3;
																//	echo $countout;

																	$strSQLc = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='Just IN'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryc = mysqli_query($con,$strSQLc);  
																	$objResultc = mysqli_fetch_array($objQueryc);
																	
																	$countjustin = $objResultc['COUNT(result)']*0.5;
																	//echo $countjustin;



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

															*/
																	if($counttotal=='6'){

																	//echo '6';

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

																		$per = (1-$defect)*100;
	
																			echo round($per,2)." % "; 
																			
																			if($per >= '80'){
	
																				//echo "ผ่าน";
																			}else{
																				//echo "ไม่ผ่าน";
																			}
																	}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 width="70" align="center"><?php 

																	//คำนวน count
																	$strSQLa = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQuerya = mysqli_query($con,$strSQLa);  
																	$objResulta = mysqli_fetch_array($objQuerya);

																	$counttotal = $objResulta['COUNT(result)'];
																	$counttotala=$counttotal*3;
																	//echo $counttotal;


																	$strSQLb = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='OUT'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryb = mysqli_query($con,$strSQLb);  
																	$objResultb = mysqli_fetch_array($objQueryb);
																	
																	$countout = $objResultb['COUNT(result)']*3;
																//	echo $countout;

																	$strSQLc = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='Just IN'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryc = mysqli_query($con,$strSQLc);  
																	$objResultc = mysqli_fetch_array($objQueryc);
																	
																	$countjustin = $objResultc['COUNT(result)']*0.5;
																	//echo $countjustin;



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

															*/
																	if($counttotal=='6'){

																	//echo '6';

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

																		$per = (1-$defect)*100;
	
																			//echo round($per,2)." % "; 
																			
																			if($per >= '80'){
	
																				echo "ผ่าน";
																			}else{
																				echo "ไม่ผ่าน";
																			}
																	}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 width="100"><?php echo $objResult['Cli_record'] ?></td>
                                                                    <td width="74"><?php echo $objResult['Cli_checker'] ?></td>
                                                                    <td width="70"><?php echo $objResult['Cli_note']; 
                                                                    
																	?></td>
																</tr>
                                                        <?php
                                                            }

                                                        ?>
															</tbody>
														</table>
												
												<?
												
											}else if($Cli_date1 != "" && $Cli_date2 !="" && $Item_id=="NULL" && $Cli_code==""){
												//echo "4 วันที่1".$Cli_date1."วันที่2".$Cli_date2."item".$Item_id."code".$Cli_code;
												$strSQL = "SELECT * FROM qc_checklistitem 
												WHERE Cli_date BETWEEN '$Cli_date1' AND '$Cli_date2'";
												$objQuery = mysqli_query($con,$strSQL);  
										
										

											?>
														<table class="table table-striped table-bordered" width='100%'>
															<thead>
																<tr>
																  <th rowspan="2%" class="center">วันที่</th>
																  <th rowspan="2">ตัวอย่างที่ทดลอง </th>
																  <th rowspan="2" class="hidden-xs">Code</th>
																  <th rowspan="10%" class="hidden-480">Reference</th>
																  <th colspan="6">Sensory</th>
																  <th rowspan="2">ผล</th>
																  <th rowspan="2">สรุปผล</th>
																  <th rowspan="2">จัดเตรียมโดย</th>
																  <th rowspan="2">ผู้ตรวจสอบ</th>
																  <th rowspan="2">หมายเหตุ</th>
															  </tr>
																<tr>
																  <th width="65">1</th>
																	<th width="95">2</th>
																	<th width="95">3</th>
																	<th width="95">4</th>
																	<th width="95">5</th>
																	<th width="100">6</th>
																</tr>
															</thead>

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

                                                        $strSQL1 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 0,1;";
														$objQuery1 = mysqli_query($con,$strSQL1);  
														$objResult1 = mysqli_fetch_array($objQuery1);

                                                        $strSQL2 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 1,1;";
														$objQuery2 = mysqli_query($con,$strSQL2);  
														$objResult2 = mysqli_fetch_array($objQuery2);

                                                        $strSQL3 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 2,1;";
														$objQuery3 = mysqli_query($con,$strSQL3);  
														$objResult3 = mysqli_fetch_array($objQuery3);

                                                        $strSQL4 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 3,1;";
														$objQuery4 = mysqli_query($con,$strSQL4);  
														$objResult4 = mysqli_fetch_array($objQuery4);

                                                        $strSQL5 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 4,1;";
														$objQuery5 = mysqli_query($con,$strSQL5);  
														$objResult5 = mysqli_fetch_array($objQuery5);

                                                        $strSQL6 = "SELECT * FROM qc_resultinout,qc_resultinsub
                                                        where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                        and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                         and qc_resultinout.per_id=qc_resultinsub.per_id
                                                        and qc_resultinsub.Topic_id='T003'
                                                        and qc_resultinout.Item_id='$objResult[Item_id]'
                                                        and qc_resultinout.Cli_code='$objResult[Cli_code]'
                                                        LIMIT 5,1;";
														$objQuery6 = mysqli_query($con,$strSQL6);  
														$objResult6 = mysqli_fetch_array($objQuery6);


													?>
																<tr>
																	<td width="150" class="center"><?=$objResult['Cli_date'];  ?></td>
																	
																	<td width="200"><?=$objResult['Item_id']." - ".$objResult['Item_name']; ?></td>
                                                                    <td width="100"><?=$objResult['Cli_code']; ?></td>
                                                                    <td width="69"><?=$objResult['Cli_ref']; ?></td>
  
                                                                    <td><?php //echo $objResult1['result'];
                                                                    
                                                                    if(isset($objResult1['result'])) 
																	{echo $objResult1['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult2['result'])) 
																	{echo $objResult2['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php
                                                                    if(isset($objResult3['result'])) 
																	{echo $objResult3['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult4['result'])) 
																	{echo $objResult4['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult5['result'])) 
																	{echo $objResult5['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td><?php 
                                                                    if(isset($objResult6['result'])) 
																	{echo $objResult6['result']." ";}
                                                                    else{echo "";}
                                                                    ?></td>
																	<td align="center" width="70"><?php 

																	//คำนวน count
																	$strSQLa = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQuerya = mysqli_query($con,$strSQLa);  
																	$objResulta = mysqli_fetch_array($objQuerya);

																	$counttotal = $objResulta['COUNT(result)'];
																	$counttotala=$counttotal*3;
																	//echo $counttotal;


																	$strSQLb = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='OUT'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryb = mysqli_query($con,$strSQLb);  
																	$objResultb = mysqli_fetch_array($objQueryb);
																	
																	$countout = $objResultb['COUNT(result)']*3;
																//	echo $countout;

																	$strSQLc = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='Just IN'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryc = mysqli_query($con,$strSQLc);  
																	$objResultc = mysqli_fetch_array($objQueryc);
																	
																	$countjustin = $objResultc['COUNT(result)']*0.5;
																	//echo $countjustin;



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

															*/
																	if($counttotal=='6'){

																	//echo '6';

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

																		$per = (1-$defect)*100;
	
																			echo round($per,2)." % "; 
																			
																			if($per >= '80'){
	
																				//echo "ผ่าน";
																			}else{
																				//echo "ไม่ผ่าน";
																			}
																	}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 width="70" align="center"><?php 

																	//คำนวน count
																	$strSQLa = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQuerya = mysqli_query($con,$strSQLa);  
																	$objResulta = mysqli_fetch_array($objQuerya);

																	$counttotal = $objResulta['COUNT(result)'];
																	$counttotala=$counttotal*3;
																	//echo $counttotal;


																	$strSQLb = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='OUT'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryb = mysqli_query($con,$strSQLb);  
																	$objResultb = mysqli_fetch_array($objQueryb);
																	
																	$countout = $objResultb['COUNT(result)']*3;
																//	echo $countout;

																	$strSQLc = "SELECT COUNT(result) FROM qc_resultinout,qc_resultinsub
                                                                    where qc_resultinout.Item_id=qc_resultinsub.Item_id
                                                                    and qc_resultinout.Cli_code=qc_resultinsub.Cli_code
                                                                    and qc_resultinout.per_id=qc_resultinsub.per_id
                                                                    and qc_resultinsub.Topic_id='T003'
																	and qc_resultinsub.result='Just IN'
																	and qc_resultinout.Item_id='$objResult[Item_id]'
																	and qc_resultinout.Cli_code='$objResult[Cli_code]'";
																	$objQueryc = mysqli_query($con,$strSQLc);  
																	$objResultc = mysqli_fetch_array($objQueryc);
																	
																	$countjustin = $objResultc['COUNT(result)']*0.5;
																	//echo $countjustin;



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

															*/
																	if($counttotal=='6'){

																	//echo '6';

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

																		$per = (1-$defect)*100;
	
																			//echo round($per,2)." % "; 
																			
																			if($per >= '80'){
	
																				echo "ผ่าน";
																			}else{
																				echo "ไม่ผ่าน";
																			}
																	}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 width="100"><?php echo $objResult['Cli_record'] ?></td>
                                                                    <td width="74"><?php echo $objResult['Cli_checker'] ?></td>
                                                                    <td width="70"><?php echo $objResult['Cli_note']; 
                                                                    
																	?></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>
