<?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">
					
				<div class="page-content">
						<!-- /.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">รายงาน Date Planner</h3>

												<div class="widget-toolbar no-border invoice-info"></div>

											
											</div>

											<div class="widget-body">
											  <?php
											  
											  $Cli_date1 = $_REQUEST['Cli_date1'];
											  $Cli_date2 = $_REQUEST['Cli_date2'];
											  
						

echo "ข้อมูลการวางแผนระหว่างวันที่ ".$Cli_date1." - ".$Cli_date2."</p>";



//$strSQL = "SELECT * FROM `pd_po` WHERE `order_date` BETWEEN '$Cli_date1' AND '$Cli_date2'";
$strSQL = "SELECT * FROM pd_po,pd_posub,pd_dep
 where pd_po.id_po=pd_posub.id_po 
 and  pd_posub.id_dep=pd_dep.id_dep
 and `date_plan` BETWEEN '$Cli_date1' AND '$Cli_date2'
 order by pd_posub.id_dep ASC,pd_posub.date_plan ASC,pd_posub.id_item ASC
";

$objQuery = mysqli_query($con,$strSQL);  
$i=1;

?>
											  <table class="table table-striped table-bordered table-hover" id="dynamic-table">
											    <thead>
											      <tr>
											        <th width="47" class="center">ลำดับ</th>
											        <th width="84" >หมายเลข PO</th>
											        <th width="100">วันที่จัดส่ง</th>
											        <th width="194">Item</th>
											        <th width="57">Qty Order</th>
											        <th width="140">วันที่วางแผนผลิต</th>
											        <th width="104">เลขที่ใบผลิต</th>
											        <th width="60">รอบ : ขั้นตอน</th>
											        <th width="94">Qty Of Step</th>
											        <th width="92">สถานะ</th>
											        <th width='150'>ผู้รับผิดชอบเริ่มต้น</th>
											        <th width='123'>สถานะ</th>
										          </tr>
										        </thead>
											    <tbody>
											      <?php
													
													

												    	while($objResult = mysqli_fetch_array($objQuery)){
															
								
															
												    	    ?>
											      <tr>
											        <td class="center"><?=$i++;?></td>
											        <td><?=$objResult['no_po']; ?></td>
											        <td><?php
														 $date1 = new DateTime($objResult['delivery_date']); // ตรงนี้คือรูปแบบเดิมที่มีในฐานข้อมูล 
                       									 echo $date1->format('d-m-Y');
														
														 ?></td>
											        <td><?=$objResult['id_item']." - ".$objResult['name_item']; ?></td>
											        <td><?=$objResult['part_qty']." ".$objResult['part_unit']; ?></td>
											        <td><?php	
														if($objResult['date_plan']=='0000-00-00'){
						   ?>
											          <font color="#FF0000"><b><?php echo '0000-00-00';?></b></font>
											          <?php
					  }else
					  {
						  
						  $date2 = new DateTime($objResult['date_plan']); // ตรงนี้คือรูปแบบเดิมที่มีในฐานข้อมูล 
                       		echo $date2->format('d-m-Y'); 
					  }?></td>
											        <td><?php
														    
														    $strSQL1 = "SELECT * FROM pd_posub,pd_job where pd_posub.id_posub=pd_job.id_posub and pd_posub.id_posub='$objResult[id_posub]'";
														    $objQuery1 = mysqli_query($con,$strSQL1);
														    $objResult1 = mysqli_fetch_array($objQuery1);
															
															
														
																echo $objResult1['job_pdid'];
															
														
														    ?></td>
											        <td><?php
                                                        //เช็ครอบ
														
														    $strSQL2 = "SELECT MAX(job_round) FROM pd_job,pd_jobver 
															where pd_job.id_posub=pd_jobver.id_posub 
															and pd_job.id_posub='$objResult[id_posub]'
															";
														    $objQuery2 = mysqli_query($con,$strSQL2);
														    $objResult2 = mysqli_fetch_array($objQuery2);
															
															
															$strSQL3 = "SELECT MAX(pd_ver.job_round) FROM pd_jobver,pd_ver 
															where pd_jobver.id_posub=pd_ver.id_posub 
															and pd_jobver.id_posub='$objResult[id_posub]'
															";
														    $objQuery3 = mysqli_query($con,$strSQL3);
														    $objResult3 = mysqli_fetch_array($objQuery3);
															
															$strSQL4 = "SELECT * FROM pd_jobver,pd_ver 
															where pd_jobver.id_posub=pd_ver.id_posub 
															and pd_jobver.id_posub='$objResult[id_posub]'
														";
														    $objQuery4 = mysqli_query($con,$strSQL4);
														    $objResult4 = mysqli_fetch_array($objQuery4);
															
														$ver = $objResult3['MAX(pd_ver.job_round)'];
														$work = $objResult2['MAX(job_round)'];
														$job_step=$objResult4['job_step'];
														
														if($objResult1['job_pdid']==''){
															//echo 'work='.$work ;
															//echo 'VER='.$ver ; 
															//ไม่ให้ใส่ ขั้นตอน
														}else{
															//echo 'work='.$work ;
															//echo 'VER='.$ver ;
														
																echo $ver." : ".$job_step; ;	
														
														}

														
														?></td>
											        <td><?php
												  
												  	$strSQL5 = "SELECT SUM(job_qty) FROM `pd_jobsub` 
													where id_posub='$objResult[id_posub]'
													
													and job_round='$ver'";
													$objQuery5 = mysqli_query($con,$strSQL5);
													$objResult5 = mysqli_fetch_array($objQuery5);
													
													
													$strSQL4 = "SELECT * FROM `pd_jobver` 
															where id_posub='$objResult[id_posub]'
															
															and job_round='$ver';
															";
														    $objQuery4 = mysqli_query($con,$strSQL4);
														    $objResult4 = mysqli_fetch_array($objQuery4);
															
															$totalstep =$objResult['part_qty']*$objResult4['job_step'];
															$sumstep =  $objResult5['SUM(job_qty)'];
														if($objResult5['SUM(job_qty)']==0){
															echo $totalstep." : 0 ".$objResult['part_unit'];
														}else{
															echo $totalstep." : ".$objResult5['SUM(job_qty)']." ".$objResult['part_unit'];
														}
													
													
												
												 
												  ?></td>
											        <td class="hidden-480"><?//$objResult['part_status']; ?>
											          <?php // จำนวน * ขั้นตอน
                                                       
														 if($sumstep==""){
															 $pertatol='0';
															 
														 }else{
															 $pertatol=number_format(($sumstep/$totalstep)*100, 2 );
															
															 
														 }
														 
														
                                                    if($pertatol>='100%'){
															?>
											          <div class="progress pos-rel" data-percent="<?=$pertatol;?>%">
											          <div class="progress-bar progress-bar-success" style="width:<?=$pertatol;?>%;"></div>
											          <?php
															
															}else{
															?>
											          <div class="progress pos-rel" data-percent="<?=$pertatol;?>%">
											          <div class="progress-bar progress-bar-warning " style="width:<?=$pertatol;?>%;"></div>
										            <?php	
																
															}

														?></td>
											        <td><?=$objResult['name_dep']; ?></td>
											        <td><?php //$objResult['part_status']; ?>
											          <?php 
						
						if($objResult['part_status']=='ดำเนินการเรียบร้อย'){
							
							?>
											          <font color="#008000"><B><?php echo $objResult['part_status'];?></B></font>
											          <?
							
						}else{
							echo $objResult['part_status'];
							
						}
						
						?></td>
										          </tr>
											    
											      <?php	
														
														}
	
													?>
										        </tbody>
										      </table>
											</div>
									  </div>
								  </div>
							  </div>
						  </div>
				  </div>

				  <!-- PAGE CONTENT ENDS -->
				</div><!-- /.col -->
						</div><!-- /.row -->
  </div><!-- /.page-content -->
			</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><!-- /.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>
