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

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

$date = $_GET['date'];

$table_name2 = $_SESSION['db_prefix']."_maintenance_jobs";
$job_query = "SELECT maintenance_card_no, cust_id, date, start_date, project, project_no, project_area, project_place, completed, card_opened FROM $table_name2 WHERE card_opened = 'yes'  AND date >= '".$start."' AND date <= '".$end."'  ORDER BY maintenance_card_no DESC ";
$job_result = mySQL_query($job_query);
$job_num = mysql_num_rows($job_result);	

?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.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="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="385"><label class="label_page_head">Maintenance costing job cards</label></td>
              <td width="253">&nbsp;</td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
        </div>
       
        <div class="page_middle_frame">
        

<?php
$page='maintenance_costing_job_list.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>

<div class="page_inside_frame">        
      
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "485px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 6},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
 
        <table width="602"  id="scroll_table" class="data_display" >
           
           <thead>
            <tr>
              <th width="20" >&nbsp;</th>
              <th width="92" >Maintenance card </th>
              <th >Date</th>
              <th >Customer</th>
              <th >Project</th>
              <th >Start date</th>
              <th >&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;
$a7tot=0;
while ($i<$job_num) {
	$a1 = mysql_result($job_result, $i, "maintenance_card_no");
	
	     $a2 = mysql_result($job_result, $i, "cust_id");
		 if ($a2!='0') {
	     $table_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, name_2, title, status, account_type, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$a2."' ";
		 $customer_result = mySQL_query($customer_query);
         $type = mysql_result($customer_result, 0, "account_type");
			if ($a1=="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");
		 } 
		 else {
			 $a2a='';
		 }
		 		

	$a5 = mysql_result($job_result, $i, "date");
	$a6 = mysql_result($job_result, $i, "project");
	
	$a9 = mysql_result($job_result, $i, "start_date");
	
	
	$a12 = mysql_result($job_result, $i, "project_no");
	$a13 = mysql_result($job_result, $i, "project_place");
	$a14 = mysql_result($job_result, $i, "project_area");
	
	
	$card_opened = mysql_result($job_result, $i, "card_opened");
	$completed = mysql_result($job_result, $i, "completed");
	
	$quoteTT = "Click for details";
	
	$jobTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Maintenance card:</td><td width=175>".$a1."</td></tr><tr><td  width=75>Project:</td><td width=175>".$a6."</td></tr><tr><td>Project place:</td><td>".$a12."</td></tr><tr><td>&nbsp;</td><td>".$a14."</td></tr><tr><td>&nbsp;</td><td>".$a13."</td></tr></table><br><b>Click for details</b>";
	
	$projectTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Project:</td><td width=175>".$a6."</td></tr><tr><td>Project place:</td><td>".$a12."</td></tr><tr><td>&nbsp;</td><td>".$a14."</td></tr><tr><td>&nbsp;</td><td>".$a13."</td></tr></table>";
	
	//$productsTT ="<img src=../images/view.png  width=20 height=16><table id=table_tool_tip width=250 ><tr><td  width=75>Products quoted:</td><td width=175>".$line_text."</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>
              <td  style="padding-left:0px;" align="center">
              <?php if (($card_opened=='yes') AND ($completed='') ) { ?> <a href=" " onMouseover="ddrivetip('Job not started yet.', 100)"; onMouseout="hideddrivetip()"> <img src="../images/round_red.png" width="12" height="12">  </a><?php } ?>
              
              <?php if (($card_opened=='yes') AND ($completed='yes') ) { ?> <a href=" " onMouseover="ddrivetip('Job completed.', 100)"; onMouseout="hideddrivetip()"> <img src="../images/round_green.png" width="12" height="12">  </a> <?php } ?>
              </td>
              <td  style="padding-left:0px;" align="left"><a href="maintenance_costing_job_card.php?maintenance_card_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $jobTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td width="78" align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td width="121" align="left"><a href="../sales/customer_details.php?cust_id=<?php echo $a2 ?>" onMouseOver="ddrivetip('<?php echo $customerTT?>', 250)"; onMouseOut="hideddrivetip()"><?php echo $a2a ?></a></td>
              <td width="151" align="left"><a href=" " onMouseover="ddrivetip('<?php echo $projectTT?>', 250)"; onMouseout="hideddrivetip()"><?php echo $a6 ?>   </a></td>
              <td width="85" align="left"><?php echo date("d-m-Y", strtotime($a9)) ?>&nbsp;</td>
              <td width="23" align="left"><?php echo $a5?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
            </tfoot>
          </table>
          
        </div>
  
 </div> 
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else {
$_SESSION['denied_return'] = "maintenance/maintenance_main.php";	
include ("../navigation/maintenance_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>