<!--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";
$receive_query = "SELECT order_no,  cust_id, order_date, receive_date, direct, status, branch FROM $table_name2 WHERE branch = 'Gaborone' AND order_date BETWEEN '".$start."' AND '".$end."' AND (( status = 'received' OR status = 'part received' OR status = 'part delivered') OR (status <> 'delivered' AND direct = 'yes')) GROUP BY order_no ORDER BY order_date DESC ";
$receive_result = mySQL_query($receive_query);
$receive_num = mysql_num_rows($receive_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_deliver_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": [[ 2, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
                             	{"bSortable": true},
								{"iDataSort": 9},
								{"bSortable": true},
								{"iDataSort": 7},
								{"iDataSort": 8},
								{"bSortable": true},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
       
        
   
         <?php
$page='tile_deliver_list.php';
$reference_name='branch';
$reference='Gaborone';
$reference_name_2='';
$reference_2='';
include('../include/period_select_block_2.php');
?>
     
       
        
        
          <div align="right">
            <label class="label_end"><img src="../images/round_orange.png" width="8" height="8" />: part delivered / 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 >Branch</th>
              <th >Order Date</th>
              <th >Receive Date</th>
              <th >Name</th>
              <th >&nbsp;</th>
              <th>&nbsp;</th>
              <th>&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;

$a7tot=0;
$price=0;
while ($i<$receive_num) {
	$a1 = mysql_result($receive_result, $i, "order_no");
		
	     $a2 = mysql_result($receive_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($receive_result, $i, "direct");
	$a5 = mysql_result($receive_result, $i, "order_date");
	$a6 = mysql_result($receive_result, $i, "receive_date");
	$a7 = '';
	$a11 = mysql_result($receive_result, $i, "status");
		
	$a14 = mysql_result($receive_result, $i, "branch");
	
	
	$table_name = $_SESSION['db_prefix']."_tile_receive_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);
	
	$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>";

$table_name = $_SESSION['db_prefix']."_tile_order_lines";
	$line_query = "SELECT  store_item_id, quantity, rec_quantity, del_quantity  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_text2="";
	$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");
		$rec_quantity = mysql_result($line_result, $l, "rec_quantity");
		$del_quantity = mysql_result($line_result, $l, "del_quantity");
		
		
		$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_text2 = $line_text2."<tr><td>".$store_item_name."</td><td>".$quantity."</td><td>".$rec_quantity."</td><td>".$del_quantity."</td></tr>";
	   $l++;
	}

	
	$table_name = $_SESSION['db_prefix']."_quotation_notes";
	$notes_query = "SELECT  note_date, note_text, seller   FROM $table_name WHERE quote_number = '".$a1."' ORDER BY line_id DESC";
	$notes_result = mySQL_query($notes_query);
	$notes_num = mysql_num_rows($notes_result);
	$notes_text='';
	$m=0;
	while ($m<$notes_num) {
		$notes1 = date("d-m-Y", strtotime(mysql_result($notes_result, $m, "note_date")))." ".mysql_result($notes_result, $m, "seller").": ";
		$notes2 = mysql_result($notes_result, $m, "note_text");
		$notes_text=$notes_text.'<tr><td valign=top>'.$notes1.'</td><td valign=top>'.$notes2.'</td><tr>';
		$m++;
	}
	
if ($a4='yes') {
	$deliver_text = 'Direct delivery by Radstone';
}
else {
	$deliver_text = 'Delivery by Vertex';
}

if ($_SESSION['userbranch']=='Gaborone') {
	$branch_text = 'Click to deliver.';
}
else {
	$branch_text = '<font color=red>Delivery can only be made if you are logged in as Gaborone user.</font>';
}

$orderTT ="<b>".$deliver_text."</b><br><table id=table_tool_tip width=400 ><tr><td>Item</td><td>Ordered</td><td>Received</td><td>Delivered</td></tr>".$line_text2."</table><br><table><tr><td>Notes:</td><td></td></tr>".$notes_text."</table><br><b>".$branch_text."</b>";

	
	?>
            <tr>
              <td align="left">
                <?php if (($a11=="part delivered") OR ($a11=="part received") OR ($a11=="received")) { ?>
                <img src="../images/round_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;">
              <?php if ($_SESSION['userbranch']=='Gaborone') { ?>
              <a href="deliver_tilesWiz0.php?order_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $orderTT?>', 410)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a>
              <?php } else { ?>
              <a href="" onmouseover="ddrivetip('<?php echo $orderTT?>', 410)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a>
              <?php } ?>
              </td>
              <td ><?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="../sales/customer_details.php?cust_id=<?php echo $a2 ?>" onmouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a2a ?></a></td>
              <td align="left"><?php echo $a5 ?></td>
              <td  align="left"><?php echo $a6 ?>&nbsp;</td>
              <td  align="left"><?php echo $a1 ?>&nbsp;</td>
            </tr>
            <?php
  $i++;
}
?>
            
          </table>
 
 </div>
 </li>
        <li>
          <input type="radio" name="tabs" id="tab2">
          <label  class="tab" for="tab2"><a class="tabs" href="tile_deliver_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_deliver_list.php?branch=Combined&date=">Combined</a></label>
           
 <div id="tab-content3" class="tab-content animated fadeIn">
 
          </div>
        </li>
</ul>
 
  </div>


 

