<?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>Northern Production - User</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">รายงาน </h3>

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

											
											</div>

											<div class="widget-body">
											  <?php

 
 $Cli_date1 = $_REQUEST['Cli_date1'];
 //SELECT * FROM `pd_history` WHERE `sent_date` BETWEEN '2023-08-08 00:00:00.000000' AND '2023-08-08 23:59:59.000000'
 $Cli_date11 = $Cli_date1." 00:00:00.000000";
$Cli_date2 = $_REQUEST['Cli_date2'];
$Cli_date22= $Cli_date2." 23:59:59.000000";


$strSQL = "SELECT * FROM pd_po,pd_posub,pd_job,pd_history ,pd_dep 
WHERE pd_po.id_po =pd_posub.id_po 
and pd_posub.id_posub=pd_job.id_posub 
and pd_job.job_pdid=pd_history.job_pdid 
and pd_history.id_dep=pd_dep.id_dep 
and sent_date  BETWEEN '$Cli_date11' AND '$Cli_date22'
order by pd_history.pdh_id,pd_history.job_pdid asc";

$objQuery = mysqli_query($con,$strSQL);  
$i=1;
?>
			<table width="100%" class="table table-striped table-bordered table-hover" id="dynamic-table">
				<thead>
					<tr>
					 <th width='5%' bgcolor="#E0E0E0" class="center">ลำดับ</th>
					 <th width="9%" bgcolor="#E0E0E0" class="hidden-480">เลขที่ใบผลิต</th>
					 <th width="2%" bgcolor="#E0E0E0" class="center">รอบ</th>
					 <th width="24%" bgcolor="#E0E0E0" class="center">Item</th>
					 <th width='5%' bgcolor="#E0E0E0" class="hidden-480">จำนวน</th>
					 <th width='6%' bgcolor="#E0E0E0" class="hidden-480">จำนวนดี</th>
					 <th width='6%' bgcolor="#E0E0E0" class="hidden-480">จำนวนเสีย</th>
					 <th width='10%' bgcolor="#E0E0E0" class="hidden-480">แผนก</th>
					 <th width='10%' bgcolor="#E0E0E0" class="hidden-480">แผนกที่ส่งต่อ</th>
					 <th width='13%' bgcolor="#E0E0E0" class="hidden-480">วันที่ส่ง</th>
					</tr>
                   </thead>     				
				   	<?php
					while($objResult = mysqli_fetch_array($objQuery)){
					?>
				<tbody>	
					<tr>
					  <td align="center"><?=$i++; ?></td>
					  <td ><?=$objResult['job_pdid']; ?></td>
					  <td align="center"><?=$objResult['job_round']; ?></td>
					  <td ><?=$objResult['id_item']." - ".$objResult['name_item']; ?></td>
					  <td><?=$objResult['part_qty']." ".$objResult['part_unit']; ?></td>
					  <td><?=$objResult['part_qty']." ".$objResult['part_unit']; ?></td>
					  <td><?php echo "0 ".$objResult['part_unit']; ?></td>
					  <td><?php
					   $strSQL2 = "SELECT * FROM pd_dep where id_dep='$objResult[id_dep]'";
					   $objQuery2 = mysqli_query($con,$strSQL2); 
					   $objResult2 = mysqli_fetch_array($objQuery2);
					 
					  ?><font size="-2" ><?php echo $objResult2['name_dep']; ?></font></td>
					  <td ><?php

					   $strSQL3 = "SELECT * FROM pd_dep where id_dep='$objResult[sent_to]'";
					   $objQuery3 = mysqli_query($con,$strSQL3); 
					   $objResult3 = mysqli_fetch_array($objQuery3);

					  ?><font size="-2" ><?php echo $objResult3['name_dep']; ?></font>

                      </td>
					  <td><?php
					   $date = new DateTime($objResult['sent_date']); // ตรงนี้คือรูปแบบเดิมที่มีในฐานข้อมูล 
                    echo $date->format('d-m-Y H:i:s');
					  ?></td>
					  </tr>
			   <?php
				}
				?>
				<tr>
					  <td bgcolor="#E4E4E4">&nbsp;</td>
					  <td bgcolor="#E4E4E4" class="hidden-480"><strong>ผลิตงานทั้งหมด :</strong></td>
					  <td bgcolor="#E4E4E4" >&nbsp;</td>
					  <td bgcolor="#E4E4E4" ><strong>
					    <?php

					  $strSQLc = "SELECT Count(pd_po.id_po) 
					  FROM pd_po,pd_posub,pd_job,pd_history ,pd_dep 
					  WHERE pd_po.id_po =pd_posub.id_po 
					  and pd_posub.id_posub=pd_job.id_posub 
					  and pd_job.job_pdid=pd_history.job_pdid 
					  and pd_history.id_dep=pd_dep.id_dep 
					  and sent_date  BETWEEN '$Cli_date11' AND '$Cli_date22'
					  order by pd_history.pdh_id asc
						";
						$objQueryc = mysqli_query($con,$strSQLc); 
						$objResultc = mysqli_fetch_array($objQueryc);
					  echo $objResultc['Count(pd_po.id_po)']."  งาน";?> 
					    
					    </strong></td>
					  <td bgcolor="#E4E4E4" class="hidden-480"><strong>จำนวนทั้งหมด :</strong></td>
					  <td bgcolor="#E4E4E4" class="hidden-480"><strong>
					    <?php
					  
					  $strSQLa = "SELECT sum(pd_history.job_qty) 
					 FROM pd_po,pd_posub,pd_job,pd_history ,pd_dep 
					 WHERE pd_po.id_po =pd_posub.id_po 
					 and pd_posub.id_posub=pd_job.id_posub 
					 and pd_job.job_pdid=pd_history.job_pdid 
					 and pd_history.id_dep=pd_dep.id_dep 
					 and sent_date  BETWEEN '$Cli_date11' AND '$Cli_date22'
					 order by pd_history.pdh_id asc
						";
						$objQuerya = mysqli_query($con,$strSQLa); 
						$objResulta = mysqli_fetch_array($objQuerya);
					  echo $objResulta['sum(pd_history.job_qty)']."  ชิ้น";?>
					  </strong></td>
					  <td bgcolor="#E4E4E4" class="hidden-480">&nbsp;</td>
					  <td bgcolor="#E4E4E4" class="hidden-480">&nbsp;</td>
					  <td bgcolor="#E4E4E4" class="hidden-480">&nbsp;</td>
					  <td bgcolor="#E4E4E4" class="hidden-480">&nbsp;</td>
					  </tr>
				</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>
