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



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

$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
	$job_query = "SELECT * FROM $table_name WHERE invoiced='yes' AND completed IS NULL ORDER BY maintenance_card_no DESC";
	$job_result = execsql($job_query);
	$job_num = mysql_num_rows($job_result);


?>
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<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 = "Maintenance-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/maintenance_sidebar.php");
?>

<div class="main_frame" >
  <div class="page_head_frame">
        <table width="600" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Maintenance</label></td>
            <td align="right">&nbsp;</td>
          </tr>
        </table>
  </div><br />
<div class="scroll_frame_long" style="height:450px; width:700px;">
  <table width="680" id="table_list" class="sortable-onload-1r rowstyle-alt no-arrow "  >
    <thead>
      <tr>
        <th width="87" align="center">Maintenance<br>
card</th>
        <th width="115" align="left" class="sortable-date-dmy">Project</th>
        <th width="58" align="center" class="sortable-date-dmy">Start<br>
          Date</th>
        <th width="134" align="left" class="sortable-text">Customer</th>
        <th width="101" align="center" >Open<br>
          Maintenance<br>
          card</th>
        <th width="87" align="center" >Close<br>
Maintenance<br>
card</th>
        <th width="66" align="center" >Complete</th>
        </tr>
    </thead>
    <tbody>
      <?php
$i = 0;
$amount=0;
	while ($i < $job_num) {
		$b0 = mysql_result($job_result, $i, "maintenance_no");
		$b0a = mysql_result($job_result, $i, "maintenance_card_no");
		$b1 = mysql_result($job_result, $i, "cust_id");
		 $table_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, name_2, title, account_type, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$b1."' ";
		 $customer_result = mySQL_query($customer_query);
		 $customer_num = mysql_num_rows($customer_result);
		 if ($customer_num!=0) {
         $type = mysql_result($customer_result, 0, "account_type");
			if ($type=="corporate") { 
				$a2a = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$a2a = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}	
		 $a2b = mysql_result($customer_result, 0, "bag_box");
		 $a2c = mysql_result($customer_result, 0, "box_no");
		 $a2d = mysql_result($customer_result, 0, "postal_place");
		 $a2e = mysql_result($customer_result, 0, "phone");
		 $a2f = mysql_result($customer_result, 0, "contact_1");
		 $a3 = mysql_result($customer_result, 0, "status");
		 }
		 
		 
		 
		 
		 
				
		$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
		$project_query = "SELECT start_date, project, project_no, project_place, project_description FROM $table_name WHERE maintenance_no = '".$b0."'  ";
		$project_result = mySQL_query($project_query);
		$b2 = mysql_result($project_result, 0, "start_date"); 
		$project = mysql_result($project_result, 0, "project"); 
		$b9 = mysql_result($project_result, 0, "project_no");
		$b10 = mysql_result($project_result, 0, "project_place");
		$b11 = mysql_result($project_result, 0, "project_description");
		$b13 = mysql_result($job_result, $i, "value");
		
  		$b20 = mysql_result($job_result, $i, "quotation");
		$b21 = mysql_result($job_result, $i, "invoiced");
		$b22 = mysql_result($job_result, $i, "card_opened");
		$b23 = mysql_result($job_result, $i, "card_closed");
		$b24 = mysql_result($job_result, $i, "completed");


				
		$jobTT ="<table id=table_tool_tip width=300 ><tr><td  width=100>Job no:</td><td width=175>".$b0a." (".$b0.")</td></tr><tr><td valign=top>Project no /place:</td><td>".$b9."&nbsp;".$b10."</td></tr><tr><td>Project:</td><td>".$project."</td></tr><tr><td>Project description:</td><td>".$b11."</td></tr><tr><td>Job value:</td><td>P ".$b13." </td></tr><tr><td>Date:</td><td>".date("d-m-Y", strtotime($b2))."</td></tr></table><br><b>Click for details</b>";

		$customerTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";
?>
      <tr class="alt">
        <td align="center" style="padding-left:0px;"><a href="maintenance_card.php?maintenance_card_no=<?php echo $b0a?>" onMouseOver="ddrivetip('<?php echo $jobTT?>', 300)"; onMouseOut="hideddrivetip()" target="_parent"><?php echo $b0a;?></a></td>
        <td><span style="padding-left:0px;"><a href="maintenance_card.php?maintenance_card_no=<?php echo $b0a?>" onMouseOver="ddrivetip('<?php echo $jobTT?>', 300)"; onMouseOut="hideddrivetip()" target="_parent"><?php echo $project;?></a></span></td>
        <td><?php  if ($b2!='') {echo date("d-m-Y", strtotime($b2));}?></td>
        <td align="left" ><a href="../sales/customer_details.php?cust_id=<?php echo $b1?>" onmouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a2a?></a></td>
        <td align="center"><?php 
		 if ($b21=='yes') {
		 if ($b22=='yes') {?>
          <a href="maintenance_card.php?maintenance_card_no=<?php echo $b0a?>" onmouseover="ddrivetip('Maintenance card opened', 150)"; onmouseout="hideddrivetip()"><img src="../images/round_green.png" alt="" width="12" height="12"></a>
          <?php }?>
          <?php if ($b22=='') {?>
          <a href="maintenance_compileJobWiz0.php?maintenance_no=<?php echo $b0?>" onmouseover="ddrivetip('Click to open maintenance card', 150)"; onmouseout="hideddrivetip()"><img src="../images/round_red.png" alt="" width="12" height="12"></a>
          <?php }
		 }?>
        </td>
        <td align="center"><?php 
		
		if ($b22=='yes') {
			if ($b23=='yes') {?>
          <a href="closed_maintenance_card.php?maintenance_card_no=<?php echo $b0a?>" onmouseover="ddrivetip('Maintenance card closed', 150)"; onmouseout="hideddrivetip()"><img src="../images/round_green.png" alt="" width="12" height="12"></a>
          <?php }?>
          <?php if ($b23=='') {?>
          <a href="maintenance_closeJobWiz0.php?maintenance_card_no=<?php echo $b0a?>" onmouseover="ddrivetip('Click to close maintenance card', 150)"; onmouseout="hideddrivetip()"><img src="../images/round_red.png" alt="" width="12" height="12"></a>
          <?php } ?>
          <?php }
		  ?></td>
        <td align="center"><?php 
		  if (($b23=='yes')) {
		  if ($b24=='yes') {?>
          <a href="../orders/invoice_report_list.php?date=" onmouseover="ddrivetip('Job completed', 150)"; onmouseout="hideddrivetip()"><img src="../images/round_green.png" alt="" width="12" height="12"></a>
          <?php }
		else{ ?>
          <a href="maintenance_completeJobWiz0.php?maintenance_card_no=<?php echo $b0a?>" onmouseover="ddrivetip('Click to complete maintenance job', 175)"; onmouseout="hideddrivetip()"><img src="../images/round_red.png" alt="" width="12" height="12"></a>
          <?php }
		  }?></td>
        </tr>
      <?php
    $i++;
		
	}?>
    </tbody>
  </table>
</div>    
  
</div>
</body>



<?php } else {
$_SESSION['denied_return'] = $_SESSION['location'];	
include ("../navigation/maintenance_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>

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