<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
include('../include/session.php');

$job_card_no = $_GET['job_card_no'];
$quote='no';
$table_name = $_SESSION['db_prefix']."_mworks_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$job_result = mySQL_query($job_query);
$cust_id = mysql_result($job_result, 0, "cust_id");	

$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}

$table_name = $_SESSION['db_prefix']."_mworks_jobs";
$production_query = "SELECT * FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$production_result = mySQL_query($production_query);
$entry_date = mysql_result($production_result, 0, "entry_date");
	

$table_name = $_SESSION['db_prefix']."_mworks_production_report";
$inspection_query = "SELECT *  FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$inspection_result = mySQL_query($inspection_query);
$inspected_by = mysql_result($inspection_result, 0, "inspected_by");
$production_date = mysql_result($inspection_result, 0, "production_date");
$job_approved = mysql_result($inspection_result, 0, "job_approved");

$table_name = $_SESSION['db_prefix']."_mworks_job_components";
$component_query = "SELECT component, quantity, produced_quantity, notes FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$component_result = mySQL_query($component_query);
$component_num = mysql_num_rows($component_result);

?>


<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />


</head>
<body>
<?php
include ("../navigation/header.php");
$page_name = "Orders-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");
?>
<div class="main_frame" style="height:auto;">
  <div class="page_head_frame">
      <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="472"><label class="label_page_head">Production report:</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2">&nbsp;&nbsp;&nbsp; <?php echo $name ?></label></td>
            <td width="208">Job card no.:<label style="font-size:24px; color:#209949;"><?php echo $job_card_no ?></label></td>
            </tr>
        </table>
      </div>
<div class="page_middle_frame">
<div class="page_inside_frame">
<?php 
		include ('../include/customer_block.php');
		echo '<br>';
		include ('../include/job_block.php')
		?>
</div>        
<div class="page_inside_frame">
  <table width="649" id="table_details_display">
    <tr>
      <td width="122">Item</td>
      <td width="239">Notes</td>
      <td width="116" align="center">Ordered qty</td>
      <td width="152" align="center">Produced qty</td>
      </tr>
    <?php 
  $i=0;
  while ($i<$component_num) {
	  $component = mysql_result($component_result, $i, "component");
	  $quantity = mysql_result($component_result, $i, "quantity");
	  $produced_quantity = mysql_result($component_result, $i, "produced_quantity");
	  if ($produced_quantity=='') {$produced_quantity=0;}
	  $notes = mysql_result($component_result, $i, "notes");
	  $balance =$quantity-$produced_quantity;
	  
	?>
    <tr>
      <td><?php echo $component ?></td>
      <td><?php echo $notes ?></td>
      <td align="center"><?php echo $quantity ?></td>
      <td align="center"><?php echo $produced_quantity ?></td>
      <?php
	$i++;
  }
	?>
      
    </tr>
  </table>
</div> 
<div class="page_inside_frame">
      <table width="649" id="table_details_display">
  <tr>
    <td width="265" valign="top">Job was inspected by:</td>
    <td width="372"><?php echo $inspected_by?>
      </td>
  </tr>
  <tr>
    <td valign="top">Production date:</td>
    <td><?php echo date("d-m-Y", strtotime($production_date))?></td>
  </tr>
        </table>
   <br>

    <table width="649" id="table_details_display">
  <tr>
    <td width="265">Job approved?</td>
    <td width="372"><?php echo $job_approved ?></td>
  </tr>
</table>
</div>
</div>       
 </div>

<?php include ('../navigation/side_bar.php'); ?>
</div>
</body>
<?php } else {
$_SESSION['denied_return'] = "production/production_main.php";	
include ("../navigation/production_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
	</body>
<?php }
?>
</html>