<!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 = mysql_result($job_result, 0, "project");

$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");
$forman = mysql_result($job_result, 0, "forman");
if ($forman!='') {
	$table_name2 = $_SESSION['db_prefix']."_employee";
	$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$forman."' ";
	$employee_result = mySQL_query($employee_query);
	$employee_num = mysql_num_rows($employee_result);	
	$forman_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
}
else {
    $forman_name='';
	}


$captured = mysql_result($job_result, 0, "captured");
$compiled = mysql_result($job_result, 0, "compiled");
$invoiced = mysql_result($job_result, 0, "invoiced");
$completed = mysql_result($job_result, 0, "completed");



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

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

$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_name4 = $_SESSION['db_prefix']."_survey_orders";
$survey_query = "SELECT * FROM $table_name4 WHERE job_card_no = '".$job_card_no."' ";
$survey_result = mySQL_query($survey_query);
$survey_num = mysql_num_rows($survey_result);
if ($survey_num>0) {
$result_1 = mysql_result($survey_result, 0, "result_1");
$result_2 = mysql_result($survey_result, 0, "result_2");
$result_3 = mysql_result($survey_result, 0, "result_3");
$result_4 = mysql_result($survey_result, 0, "result_4");

$survey_perc = (($result_1+$result_2+$result_3+$result_4)/8)*100;
}
else {
	$survey_perc = '';
}

$table_name = $_SESSION['db_prefix']."_order_history";	
$notes_query = "SELECT  *   FROM $table_name WHERE job_card_number = '".$job_card_no."' ORDER BY line_id DESC ";
$notes_result = mySQL_query($notes_query);
$notes_num = mysql_num_rows($notes_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>
<script language="JavaScript" src="../jscript/tablesort.js"  type="text/javascript"></script> 

</head>

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

if ($permission_num==1) {
	include ("../navigation/orders_sidebar.php");
?>
<div class="main_frame">
  <div class="page_head_frame">
          <table width="650" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="473"><label class="label_page_head">Job card history for&nbsp;<?php echo $job_card_no.'&nbsp;&nbsp;'.$cust_name ?></label></td>
              <td width="80" align="center">Survey result:<br>
               <b> <?php  if ($survey_perc>='0') { ?> <a href="survey_job_report.php?job_card_no=<?php echo $job_card_no ?>" onMouseover="ddrivetip('Click to view report', 150)"; onMouseout="hideddrivetip()"><?php echo number_format($survey_perc, 0, '.', ',').'%'; ?> </a><?php } else { echo '--';} ?></b></td>
              <td width="97" align="center"><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 ($compiled=='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;  ?></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">Foreman:</td>
      <td align="left" valign="top"><?php echo $forman_name ?></td>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</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"><?php if ($deliver_date!='') {?>from: <?php echo date("d-m-Y", strtotime($deliver_date));  ?> to: <?php echo date("d-m-Y", strtotime($end_date));  ?><?php } ?> </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">
History:
<table width="650" id="table_details_display">
  <tr>
    <td width="81" height="25">Date:</td>
    <td width="86">&nbsp;Entry by:</td>
    <td width="475">Note:&nbsp;</td>
  </tr>
  <?php
			   $i=0;
			   while ($i<$notes_num) {
				   $c1 = mysql_result($notes_result, $i, "note_date");  
				   $c2 = mysql_result($notes_result, $i, "note_text");  
				   $c3 = mysql_result($notes_result, $i, "user_name"); 
				   ?>
  <tr>
    <td height="25"><?php echo date("d-m-Y", strtotime($c1))?></td>
    <td><?php echo $c3 ?></td>
    <td><?php echo $c2 ?></td>
  </tr>
  <?php 
				  $i++;
			   }?>
</table>
</div>  
   
</div>  
</div>

</div>

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

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

</html>