<!--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_name2 = $_SESSION['db_prefix']."_tile_orders";
$order_query = "SELECT order_no,  cust_id, order_date, receive_date, direct, status, value, branch, pallets, order_book_no FROM $table_name2 WHERE branch = 'Gaborone' AND order_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."' ORDER BY order_date DESC ";
$order_result = mySQL_query($order_query);
$order_num = mysql_num_rows($order_result);	

?>

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

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

<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": "420px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 4, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
                             	{"bSortable": true},
								{"iDataSort": 11},
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 9},
								{"iDataSort": 10},
								{"bSortable": true},
								{"iDataSort": 12},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
       
        
 
         <?php
$page='tile_order_list.php';
$reference_name='branch';
$reference='Gaborone';
$reference_name_2='';
$reference_2='';
include('../include/period_select_block_2.php');
?>       </form>
       
        
        
          <div align="right">
            <label class="label_end"><img src="../images/round_green.png" width="8" height="8" />: Delivered&nbsp;&nbsp;<img src="../images/round_orange.png" width="8" height="8" />:Received&nbsp;&nbsp;<img src="../images/round_red.png" width="8" height="8" />:On order&nbsp;&nbsp;<img src="../images/right_arrow_green.png" width="8" height="8" />:Direct delivery</label>
          </div>
          <table width="445" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th align="center" >&nbsp;</th>
              <th style="border-right-style:hidden;">&nbsp;</th>
              <th >Order no</th>
              <th >Book order no</th>
              <th >Branch</th>
              <th >Order Date</th>
              <th >Receive Date</th>
              <th >Name</th>
              <th >Value</th>
              <th >&nbsp;</th>
              <th>&nbsp;</th>
              <th>&nbsp;</th>
              <th>&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;

$a7tot=0;
$price=0;
while ($i<$order_num) {
	$a1 = mysql_result($order_result, $i, "order_no");
		
	     $a2 = mysql_result($order_result, $i, "cust_id");
	     $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);
		 $customer_num = mysql_num_rows($customer_result);
		 if ($customer_num!=0) {
         $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");
		 
		 }
	
	$a4 = mysql_result($order_result, $i, "direct");
	$a5 = mysql_result($order_result, $i, "order_date");
	$a6 = mysql_result($order_result, $i, "receive_date");
	$a7 = mysql_result($order_result, $i, "value");
	$a8 = mysql_result($order_result, $i, "order_book_no");
	$a11 = mysql_result($order_result, $i, "status");
	$a14 = mysql_result($order_result, $i, "branch");
	$a15 = mysql_result($order_result, $i, "pallets");
	$a7tot = $a7tot + $a7;
	
	$table_name = $_SESSION['db_prefix']."_tile_order_lines";
	$line_query = "SELECT  store_item_id, quantity, purchase_price   FROM $table_name WHERE order_no = '".$a1."' ";
	$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++;
	}
	
	$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>";

	
	$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 width="30" align="left">
                <?php if ($a11=="delivered") { ?>
                <img src="../images/round_green.png" width="12" height="12"  />
                <?php } ?>
                <?php if ($a11=="received") { ?>
                <img src="../images/round_orange.png" width="12" height="12"  />
                <?php } ?>
                <?php if ($a11=="part received") { ?>
                <img src="../images/round_red_orange.png" width="12" height="12"  />
                <?php } ?>
                <?php if ($a11=="on order") { ?>
                <img src="../images/round_red.png" width="12" height="12"   />
                <?php } ?>
                <?php if ($a4=="yes") { ?>
                <img src="../images/right_arrow_green.png" width="12" height="12"   />
                <?php } ?></td>
              <td align="right" style="border-right-style:hidden; padding-right:0px" >O</td>
              <td align="left"  style="padding-left:0px;"><a href="tile_order_display.php?order_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $orderTT?>', 450)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td align="left"><?php echo $a8 ?></td>
              <td align="left"><?php echo $a14 ?></td>
              <td align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td align="left"><?php  if ($a6!='0000-00-00') { echo date("d-m-Y", strtotime($a6));}?></td>
              <td align="left"><a href="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="right"><?php echo number_format($a7, 2, '.', ',') ?></td>
              <td align="left"><?php echo $a5 ?></td>
              <td align="left"><?php echo $a6 ?></td>
              <td align="left"><?php echo $a1 ?></td>
              <td align="left"><?php echo $a7 ?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td colspan="8" align="right" valign="bottom">Total:</td>
                <td align="right" valign="bottom"><?php echo number_format($a7tot, 2, '.', ',') ?></td>
                <td >&nbsp;</td>
                <td >&nbsp;</td>
                <td >&nbsp;</td>
                <td >&nbsp;</td>
              </tr>
            </tfoot>
          </table>
 
 </div>
 </li>
        <li>
          <input type="radio" name="tabs" id="tab2">
          <label  class="tab" for="tab2"><a class="tabs" href="tile_order_list.php?branch=Francistown&date=">Francistown</a></label>
<div id="tab-content2" class="tab-content animated fadeIn">
</div>
        </li>
        <li>
          <input type="radio" name="tabs" id="tab3">
          <label class="tab"for="tab3"><a class="tabs" href="tile_order_list.php?branch=Combined&date=">Combined</a></label>
           
 <div id="tab-content3" class="tab-content animated fadeIn">
 
          </div>
        </li>
</ul>
 
  </div>


 

