<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--reference to main.css removed-->
<?php
include('../include/session.php');
?>

<?php
$job_card_no=$_GET['job_card_no'];
$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$job_result = mySQL_query($job_query);
////$job_card_no = mysql_result($job_result, 0, "job_card_no");
$cust_id = mysql_result($job_result, 0, "cust_id");
$quote_note = mysql_result($job_result, 0, "quote_note");
$value = mysql_result($job_result, 0, "value");
$order_date = mysql_result($job_result, 0, "date");
$del_date = mysql_result($job_result, 0, "del_date");
$end_date = mysql_result($job_result, 0, "end_date");
$project_description = mysql_result($job_result, 0, "project_description");

$project_no = mysql_result($job_result, 0, "project_no");
$project_place = mysql_result($job_result, 0, "project_place");
$project_area = mysql_result($job_result, 0, "project_area");
$deliver_date = mysql_result($job_result, 0, "del_date");


$table_name = $_SESSION['db_prefix']."_mworks_jobs";
$status_query = "SELECT captured, compiled, invoiced, completed FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$status_result = mySQL_query($status_query);
$captured = mysql_result($status_result, 0, "captured");
$compiled = mysql_result($status_result, 0, "compiled");
$invoiced = mysql_result($status_result, 0, "invoiced");
$completed = mysql_result($status_result, 0, "completed");


if ($completed=='yes') {
	   	$table_name = $_SESSION['db_prefix']."_mworks_order_job_lines_done";
}
else {
		$table_name = $_SESSION['db_prefix']."_mworks_order_job_lines";
}

$line_query = "SELECT *  FROM $table_name WHERE  job_card_no =  '".$job_card_no."' ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

$line2_query = "SELECT *  FROM $table_name WHERE  job_card_no =  '".$job_card_no."' AND store_item_id IS NULL";
$line2_result = mySQL_query($line2_query);
$line2_num = mysql_num_rows($line2_result);

$table_name = $_SESSION['db_prefix']."_mworks_job_components";
$line3_query = "SELECT * FROM $table_name WHERE job_card_no = '".$job_card_no."' "; 
$line3_result = mySQL_query($line3_query);
$line3_num = mysql_num_rows($line3_result);

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

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>

</head>

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

if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");
?>
<div class="main_frame">
  <div class="page_head_frame">
          <table width="650" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="553"><label class="label_page_head">M-works job card</label></td>
              <td width="97"><label class="label_quote_no"><?php echo $job_card_no;  ?></label>
              <?php if (($captured=='yes') AND ($compiled=='') AND ($completed=='') ) { ?> <img src="../images/round_red.png" width="12" height="12"><?php } ?>
              <?php if (($captured=='yes') AND ($compiled=='yes') AND ($completed=='') ) { ?> <img src="../images/round_orange.png" width="12" height="12"><?php } ?>
              <?php if (($captured=='yes') AND ($completed=='yes') ) { ?> <img src="../images/round_green.png" width="12" height="12"><?php } ?></td>
            </tr>
          </table>
          </div>
          <div class="page_middle_frame">
<div class="page_inside_frame">
<?php 
include('../include/customer_block.php');
?>
</div>    
<div class="page_inside_frame">
<table width="650" id="table_details_display">
    <tr>
      <td align="left" valign="top">Project:</td>
      <td align="left" valign="top"><?php  echo $project_description;  ?></td>
      <td align="left" valign="top"><?php echo 'Job card no:'; ?></td>
      <td align="left" valign="top"><?php echo $job_card_no;  ?></td>
    </tr>
    <tr>
      <td align="left" valign="top"><?php  echo 'Order date:';?></td>
      <td width="131" align="left" valign="top"><?php  echo date("d-m-Y", strtotime($order_date));  ?></td>
      <td width="101" align="left" valign="top"><?php  echo 'Job value'; ?></td>
      <td width="277" align="left" valign="top"><?php   echo number_format($value, 2, '.', ','); ?></td>
    </tr>
    <tr>
      <td align="left" valign="top">Project period:</td>
      <td colspan="3" align="left" valign="top">from: <?php echo date("d-m-Y", strtotime($deliver_date));  ?> to: <?php echo date("d-m-Y", strtotime($end_date));  ?> </td>
      </tr>
    <tr>
      <td width="121" align="left" valign="top">Project place:</td>
      <td colspan="3" align="left" valign="top"><?php echo $project_no?>&nbsp;&nbsp;<?php echo $project_area?>&nbsp;&nbsp;<?php echo $project_place?></td>
      </tr>
    <tr>
      <td align="left" valign="top">Notes:</td>
      <td colspan="3" align="left" valign="top"><?php echo $quote_note ?></td>
    </tr>
  </table>
</div>  

<div class="page_inside_frame">
Job components:
<table width="650" id="table_display">
        <?php
		
	  $i=0;
		while ($i<$line3_num) {
	       $component = mysql_result($line3_result, $i, "component");
		   $notes = mysql_result($line3_result, $i, "notes");
		   $quantity = mysql_result($line3_result, $i, "quantity");
		   
	  
		?>
  <tr>
    <td width="295"><?php echo $component ?></td>
    <td width="219"><?php echo $notes ?></td>
    <td width="120" align="center"><?php echo $quantity ?></td>
    </tr>
  <?php 
  $i++;
  }
  ?>
</table>


<br>
Store items used:
<table width="650" id="table_display" >
          <tr>
            <td height="26" colspan="2" align="left" valign="top">Item</td>
            <td width="109" align="left" valign="top">Group</td>
            <td width="36" align="center" valign="top">Unit</td>
            <td width="96" align="center" valign="top">Quantity<br>
            ordered</td>
            <td width="86" align="center" valign="top">Quantity<br>
              supplied</td>
            <td width="80" align="center" valign="top">Remarks</td>
        </tr>
          <?php
				$i=0;
				$sub_total_2=0;
				while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "order_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 
					 if ( ($a1>0) AND ($a1<100000)) {
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory, register FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
						$register = mysql_result($item_result, 0, "register");
					 }
					 if ($a1>100000) {
					 $table_name = $_SESSION['db_prefix']."_store_items_special";
						$item_query = "SELECT item_name FROM $table_name WHERE special_store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = '';
						$a4a = 'Special order';
						$register = '';
					 }
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "delivered");
					 $a5 = mysql_result($line_result, $i, "store_reg_id");
					 
					  if ($a1==0) {
					   $a1a = mysql_result($line_result, $i, "item_name");
					   $a3 = '';
					   $a3a='';
					   $a4a = 'To order';
					   $a7='';
					 }
					$a8 = mysql_result($line_result, $i, "misc");
					
					if ($register=='yes') {
					$table_name = $_SESSION['db_prefix']."_store_register";
					$register_query = "SELECT serial_number  FROM $table_name WHERE store_register_id = '".$a5."' ";
					
					$register_result = mySQL_query($register_query);
					$register_num = mysql_num_rows($register_result);
					if ($register_num!=0) {
					$serial = mysql_result($register_result, 0, "serial_number");
					}
					else {
						$serial = '';
					}
					}
					 
				 ?>
          <tr>
            <td colspan="2" valign="top"><?php echo $a1a ?>
            <?php if ($register=='yes') { echo 'serial no: '.$serial ; }?></td>
            <td valign="top"><?php echo $a4a ?></td>
            <td align="center" valign="top"><?php echo $a3a ?></td>
            <td align="center" valign="top"><?php if (($a2!='') AND ($a2!='0.00')) { if ($a3a!='no') {echo number_format($a2, 2, '.', ',');} else { echo number_format($a2, 0, '.', ','); }} ?></td>
            <td align="center" valign="top"><?php if (($a3!='') AND ($a3!='0.00'))  { if ($a3a!='no') {echo number_format($a3, 2, '.', ',');} else { echo number_format($a3, 0, '.', ','); }} ?></td>
            <td align="center" valign="top"><?php echo $a8 ?></td>
        </tr>
          <?php 
			  $i++;
				 }
				 ?>
          <tr>
            <td colspan="2" align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="right" valign="top">&nbsp;</td>
        </tr>
      </table>
        <br>
<br>
<a href="m_job_card_print.php?job_card_no=<?php echo $job_card_no?>" target="_blank"><input name="print_button" type="button" class="imagebutton" value="Print job card" ></a>
</div>      



   
</div>  
</div>
<?php include ('../navigation/side_bar.php'); ?>


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