<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<link href="../css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/tabs.css" />

<!--jscript-->
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

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

$table_name = $_SESSION['db_prefix']."_pallets";	 	
	$display_query = "SELECT order_no, quantity, ret_quantity FROM $table_name WHERE del_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."'";
	
		$display_result = execsql($display_query);
		$i = 0;
		$display_num = mysql_num_rows($display_result);

?>

<div class="page_middle_frame" style="height:690px;"> 

<ul class="tabs">
      <li>
          <input type="radio" name="tabs" id="tab1">
          <label class="tab" for="tab1"><a class="tabs" href="outstanding_pallets_list.php?branch=Gaborone&date=">Gaborone</a></label>
<div id="tab-content1" class="tab-content animated fadeIn" style="height:630px;">  

 </div>
 </li>
        <li>
          <input type="radio" name="tabs" id="tab2">
          <label  class="tab" for="tab2"><a class="tabs" href="outstanding_pallets_list.php?branch=Francistown&date=">Francistown</a></label>
<div id="tab-content2" class="tab-content animated fadeIn" style="height:630px;">

</div>
        </li>
        <li>
          <input type="radio" checked  name="tabs" id="tab3">
          <label class="tab"for="tab3"><a class="tabs" href="outstanding_pallets_list.php?branch=Combined&date=">Combined</a></label>           
 <div id="tab-content3" class="tab-content animated fadeIn" style="height:630px;">

<?php
$page='outstanding_pallets_list.php';
$reference_name='branch';
$reference='Combined';
include('../include/period_select_block_small.php');
?>  


<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": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                             	{"iDataSort": 3},
								{"bVisible": false},
								{"iDataSort": 5},
								{"bVisible": false},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
       
   
          
          <table width="662" id="scroll_table" class="data_display"  >
	<thead>
		<tr>
		  <th width="63">Order no</th>
          <th width="34">&nbsp;</th>
		  <th width="34">Delivery date</th>
          <th width="34">&nbsp;</th>
		  <th width="200">Customer</th>
          <th width="34">&nbsp;</th>
		  <th align="center" width="70">Qty delivered</th>
          <th align="center" width="70">Qty returned</th>
          <th align="center" width="70" >Qty outstanding</th>
		</tr>
	</thead>
	<tbody>
  <?php
    $b9=0;
	$line_text="";
	$total_quantity = '';
	$total_ret_quantity = '';
	$total_balance = '';
	$i=0;
	while($i < $display_num){
		 $b1 = mysql_result($display_result, $i, "order_no");
		 	$table_name = $_SESSION['db_prefix']."_tile_orders";
			$order_query = "SELECT cust_id, order_date, pallets FROM $table_name WHERE order_no = '".$b1."'  ";
			$order_result = mySQL_query($order_query);
			$b2 = mysql_result($order_result, 0, "order_date");
		    $a2 = mysql_result($order_result, 0, "cust_id");
			$a15 = mysql_result($order_result, 0, "pallets");
			
			$table_name = $_SESSION['db_prefix']."_customer";
			$customer_query = "SELECT status, account_type, comp_name, name_2, title, bag_box, box_no, postal_place, phone, cell_1  FROM $table_name WHERE cust_id = '".$a2."' ";
			$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");
				$a2aa = 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, "cell_1");
			$a2g = mysql_result($customer_result, 0, "status");
			$a2h="";
			}
			else {
			$a2a='';
			}
			
		 $b4 = mysql_result($display_result, $i, "quantity");
		 $b5 = mysql_result($display_result, $i, "ret_quantity");
		 $b6 = $b4-$b5;	
		 
	$balance = $b4 - $b5;
	$total_quantity = $total_quantity + $b4;
	$total_ret_quantity = $total_ret_quantity + $b5;
	$total_balance = $total_quantity - $total_ret_quantity;	 
		 
	$table_name = $_SESSION['db_prefix']."_tile_order_lines";
	$line_query = "SELECT  store_item_id, quantity, purchase_price   FROM $table_name WHERE order_no = '".$b1."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
		
	$l=0;
	$total=0;
	$line_text="";
	$products=mysql_result($line_result, 0, "store_item_id");
		
	while($l<$line_num) {
		$store_item_id = mysql_result($line_result, $l, "store_item_id");
		$quantity = mysql_result($line_result, $l, "quantity");
		$price = mysql_result($line_result, $l, "purchase_price");
	
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
		$name_result = mySQL_query($name_query);
		$store_item_name = mysql_result($name_result, 0, "item_name");
		$sub_total =  $quantity * $price;
		$total = $total + $sub_total;
			  
	   	$line_text = $line_text."<tr><td>".$store_item_name."</td><td>".$quantity."</td><td align=right>".number_format($price, 2, '.', ',')."</td><td align=right>".number_format($sub_total, 2, '.', ',')."</td></tr>";
	   $l++;
	}
		 
		 $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>";
		 
		 $orderTT ="<table id=table_tool_tip width=450 ><tr><td>Item</td><td>Quantity</td><td align=center>Price</td><td align=center>Total</td></tr>".$line_text."<tr><td>Estimated pallets: ".$a15."</td><td>&nbsp;</td><td align=center>&nbsp;</td><td align=center>&nbsp;</td></tr></table><br><b>Click for details</b>";			
		?>
		<tr >
		  <td ><a href="../sales/tile_order_display.php?order_no=<?php echo $b1 ?> " onmouseover="ddrivetip('<?php echo $orderTT?>', 450)"; onmouseout="hideddrivetip()"><?php echo $b1 ?></a></td>
          <td ><?php echo $b1 ?></td>
		  <td ><?php echo date("d-m-Y", strtotime($b2)) ?></td>
          <td ><?php echo $b2 ?></td>
		  <td ><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 ><?php echo $a2aa ?></td>
			<td align="center"><?php echo $b4?></td>
			<td align="center"><?php echo $b5?></td>
			<td align="center"><?php echo $b6?></td>
		</tr>
        
		<?php
		$i++;
		  
	}
	
	?>
	</tbody>

<tfoot>
<tr>
    <td colspan="6" align="right">Totals: &nbsp;</td>
    <td align="center"><?php echo $total_quantity ?></td>
    <td align="center"><?php echo $total_ret_quantity ?></td>
    <td align="center"><?php echo $total_balance ?></td>
</tr>
  </tfoot>	
</table>
 


 
          </div>
        </li>
</ul>
 
  </div>


 

