<!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']."_invoices";
$invoice_query = "SELECT * FROM $table_name2 WHERE invoice_date > '".$start."' AND invoice_date < '".$end."' AND mworks IS NULL ORDER BY job_card_no DESC ";
$invoice_result = mySQL_query($invoice_query);
$invoice_num = mysql_num_rows($invoice_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">Invoiced jobs</label></td>
              <td width="253">&nbsp;</td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
        </div>
       
        <div class="page_middle_frame">
        

<?php
$page='invoice_report_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": [[ 2, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 6},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
 
        <table width="678"  id="scroll_table" class="data_display" >
           
           <thead>
            <tr>
              <th width="66" >Job card </th>
              <th >Invoice no</th>
              <th >Invoice date</th>
              <th >Invoice amount</th>
              <th >Customer</th>
              <th >Project</th>
              <th >&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;
$a7tot=0;
while ($i<$invoice_num) {
	$a1 = mysql_result($invoice_result, $i, "job_card_no");
	
	     $a2 = mysql_result($invoice_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='';
		 }
	$a4 = mysql_result($invoice_result, $i, "invoice_no");
	$a5 = mysql_result($invoice_result, $i, "invoice_date");
	$a7 = mysql_result($invoice_result, $i, "invoice_amount");
	$a8 = mysql_result($invoice_result, $i, "invoiced_by");
	
	
	$table_name = $_SESSION['db_prefix']."_compiled_jobs";
	$project_query = "SELECT project, project_no, project_place, project_area FROM $table_name WHERE job_card_no = '".$a1."' ";
	$project_result = mySQL_query($project_query);
	$a6 = mysql_result($project_result, 0, "project");
	$a12 = mysql_result($project_result, 0, "project_no");
	$a13 = mysql_result($project_result, 0, "project_place");
	$a14 = mysql_result($project_result, 0, "project_area");
	
	
	
	$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>";
	
	$invoiceTT ="<table id=table_tool_tip width=250 ><tr><td  width=100>Invoice no:</td><td width=150>".$a4."</td></tr><tr><td>Invoice date::</td><td>".date("d-m-Y", strtotime($a5))."</td></tr><tr><td>Invoice amount:</td><td>P ".number_format($a7, 2, '.', ',')."</td></tr><tr><td>Invoiced by</td><td>".$a8."</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>";
	
		
	$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="left"><a href="inspection_report.php?job_card_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $jobTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td width="78" align="left"><a href="invoice_report.php?invoice_no=<?php echo $a4 ?>&job_card_no=<?php echo $a1 ?> " onMouseover="ddrivetip('<?php echo $invoiceTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $a4 ?></a></td>
              <td width="96" align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td width="96" align="right"><?php echo number_format($a7, 2, '.', ',') ?>&nbsp;</td>
              <td width="136" 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="96" align="left"><a href=" " onMouseOver="ddrivetip('<?php echo $projectTT?>', 250)"; onMouseOut="hideddrivetip()"><?php echo $a6 ?></a></td>
              <td width="41" align="left"><?php echo $a5?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td colspan="8"; 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>