<!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']."_compiled_jobs";
$job_query = "SELECT job_card_no, cust_id, date, del_date, forman, project, project_no, project_area, project_place, captured, compiled, invoiced FROM $table_name2 WHERE captured = 'yes' AND date >= '".$start."' AND date <= '".$end."' ORDER BY job_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 = "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="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="385"><label class="label_page_head">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='compiled_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": 8},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
 
        <table width="678"  id="scroll_table" class="data_display" >
           
           <thead>
            <tr>
              <th width="28" >&nbsp;</th>
              <th width="75" >Job card </th>
              <th >Date</th>
              <th >Customer</th>
              <th >Project</th>
              <th >Foreman</th>
              <th >Delivery/install</th>
              <th >&nbsp;</th>
              <th >&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;
$a7tot=0;
while ($i<$job_num) {
	$a1 = mysql_result($job_result, $i, "job_card_no");
	
	     $a2 = mysql_result($job_result, $i, "cust_id");
		 if ($a2!='0') {
	     $table_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$a2."' ";
		 
         $customer_result = mySQL_query($customer_query);
         $a2a = 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");
	$a7 = mysql_result($job_result, $i, "forman");
	
	if ($a7!='') {	
	$table_name2 = $_SESSION['db_prefix']."_employee";
	$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$a7."' ";
	$employee_result = mySQL_query($employee_query);
	$employee_num = mysql_num_rows($employee_result);	
	$a7a = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name");
	}
	else {
		$a7a='';
	}
	
	$a9 = mysql_result($job_result, $i, "del_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");
	
	$captured = mysql_result($job_result, $i, "captured");
	$compiled = mysql_result($job_result, $i, "compiled");
	$invoiced = mysql_result($job_result, $i, "invoiced");
	
	$quoteTT = "Click for details";
	
	$jobTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Job 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 (($captured=='yes') AND ($compiled=='') AND ($invoiced=='') ) { ?> <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 (($captured=='yes') AND ($compiled=='yes') AND ($invoiced=='') ) { ?> <a href=" " onMouseover="ddrivetip('Job in progress.', 100)"; onMouseout="hideddrivetip()"> <img src="../images/round_orange.png" width="12" height="12">  </a><?php } ?>
              <?php if (($captured=='yes') AND ($compiled=='yes') AND ($invoiced=='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="job_card.php?job_card_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $jobTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td width="62" align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td width="104" 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="80" align="left"><a href=" " onMouseover="ddrivetip('<?php echo $projectTT?>', 250)"; onMouseout="hideddrivetip()"><?php echo $a6 ?>   </a></td>
              <td width="103" align="left"><?php echo $a7a ?></td>
              <td width="109" align="left"><?php if ($a9!='') { echo date("d-m-Y", strtotime($a9));} ?></td>
              <td width="39" align="center"><a href="job_card_history.php?job_card_no=<?php echo $a1 ?>" onMouseover="ddrivetip('Click for job history', 150)"; onMouseout="hideddrivetip()"><img src="../images/history_icon.png" width="16" height="17"> </a></td>
              <td width="38" align="left"><?php echo $a5?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td colspan="10"; height="5">&nbsp;</td>
              
              </tr>
            </tfoot>
          </table>
          
        </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">
</body>
<?php }
?>
</html>