<!--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
$cust_id = $_GET['cust_id'];
$cust_query_line = '=';
include('../include/period_select_date.php');

$table_name = $_SESSION['db_prefix']."_customer";
    $position_query = "SELECT cust_id, comp_name, name_2 FROM $table_name ORDER BY comp_name ASC";
	$arrId3 = array ();
	$arrName3 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$k = 0;
	while ($k < $position_num) {
		$arrId3[$k] = mysql_result($position_result, $k, "cust_id");
		$arrName3[$k] = mysql_result($position_result, $k, "comp_name").', '.mysql_result($position_result, $k, "name_2");
		$k++;
	}
	}

if ($cust_id!=0) {

$table_name2 = $_SESSION['db_prefix']."_customer";
$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
$customer_result = mySQL_query($customer_query);
$customer_num = mysql_num_rows($customer_result);	
$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
}
else {
	$cust_id = 0;
	$cust_name = 'All';
	$cust_query_line = '>';
}

$table_name1 = $_SESSION['db_prefix']."_tile_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";
$table_name3 = $_SESSION['db_prefix']."_list_tiles";	 	
$tiles_display_query = "
SELECT 
item_type,
SUM(quantity) AS summed_quantity
FROM(
SELECT 
$table_name2.item_type,
SUM($table_name1.quantity) AS quantity 
FROM 
$table_name1, $table_name2
WHERE 
$table_name2.store_item_id = $table_name1.store_item_id
AND
$table_name1.cust_id ".$cust_query_line." '".$cust_id."'
AND
$table_name1.branch = 'Gaborone' 
AND
$table_name1.order_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."'
AND $table_name2.subCategory = 'Tiles' 
GROUP BY $table_name2.item_type

UNION ALL

SELECT $table_name3.item_type, $table_name3.quantity
FROM $table_name3
)
C
GROUP BY item_type
";
$tiles_display_result = execsql($tiles_display_query);
$tiles_display_num = mysql_num_rows($tiles_display_result);

$table_name1 = $_SESSION['db_prefix']."_tile_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";
$table_name3 = $_SESSION['db_prefix']."_list_accessories";	 	
$acc_display_query = "
SELECT 
item_type,
SUM(quantity) AS summed_quantity
FROM(
SELECT 
$table_name2.item_type,
SUM($table_name1.quantity) AS quantity 
FROM 
$table_name1, $table_name2
WHERE 
$table_name2.store_item_id = $table_name1.store_item_id
AND
$table_name1.cust_id ".$cust_query_line." '".$cust_id."'
AND
$table_name1.branch = 'Gaborone' 
AND
$table_name1.order_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."'
AND $table_name2.subCategory = 'Accessories' 
GROUP BY $table_name2.item_type

UNION ALL

SELECT 
$table_name3.item_type, 
$table_name3.quantity
FROM $table_name3
)
C
GROUP BY item_type
";

$acc_display_result = execsql($acc_display_query);
$acc_display_num = mysql_num_rows($acc_display_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="sales_products.php?branch=Gaborone&date=&cust_id=0">Gaborone</a></label>
<div id="tab-content1" class="tab-content animated fadeIn" style="height:630px;">  

<?php
$page='sales_products.php';
$reference_name='branch';
$reference='Gaborone';
$reference_name_2='cust_id';
$reference_2=$cust_id;
include('../include/period_select_block_small.php');
?>
<div class="page_inside_frame">
<form action="" method="get">
Select customer:&nbsp;&nbsp;
<select name="comp_name_select" class="select200"  onchange="window.location.href= this.form.comp_name_select.options[this.form.comp_name_select.selectedIndex].value"> >
           <?php echo "<option value=sales_products.php?branch=Gaborone&date=&cust_id=0>All</option>"; ?>
            <option value="<?php echo $cust_id ?>" selected><?php echo $cust_name ?></option>
            <?php
        	for ($k = 0; $k < count($arrId3); $k++) {
    		echo "<option value=sales_products.php?branch=Gaborone&date=&cust_id=".$arrId3[$k].">" . $arrName3[$k] . "</option>";
			
	}
?>
</select>
</form>
</div>
<br />
<br />
<div class="page_inside_frame">
<table width="640" id="table_details_display"  >
	<thead>
		<tr>
		  <th width="200">Tiles</th>
          <th width="200">Sales Quantity</th>
          <th width="100">&nbsp;</th>
        </tr>
	</thead>
	<tbody>
  <?php
   	$i=0;
	while($i < $tiles_display_num){
		 $b1 = mysql_result($tiles_display_result, $i, "item_type");
		 $b4 = mysql_result($tiles_display_result, $i, "summed_quantity");
		 $b5 = '';
		 
			
$table_name = $_SESSION['db_prefix']."_list_colors";
$color_query = "SELECT item_name FROM $table_name ";
$color_result = mySQL_query($color_query);
$color_num = mysql_num_rows($color_result);

$color_line_text = '';
$color_line2_text = '';
$k=0;
while ($k<$color_num) {
$color = mysql_result($color_result, $k, "item_name");

$table_name1 = $_SESSION['db_prefix']."_tile_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";	 	
$color_qty_query = "SELECT 
$table_name2.store_item_id, 
$table_name2.item_type,
SUM($table_name1.quantity) AS summed_quantity, 
$table_name1.branch 
FROM 
$table_name1, $table_name2
WHERE 
$table_name2.store_item_id = $table_name1.store_item_id
AND
$table_name1.cust_id ".$cust_query_line." '".$cust_id."'
AND
$table_name1.branch = 'Gaborone' 
AND
$table_name2.item_type = '".$b1."'
AND
$table_name1.order_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."'
AND 
$table_name2.subCategory = 'Tiles'
AND 
$table_name2.item_color = '".$color."'
AND
$table_name2.item_antique = '' 
GROUP BY $table_name2.item_type";


$color_qty_result = execsql($color_qty_query);
$color_qty_num = mysql_num_rows($color_qty_result);
if ($color_qty_num!=0) {
$color_quantity = mysql_result($color_qty_result, 0, "summed_quantity");
$antique = '';
}
else {
$color_quantity=0;
}

$color_line_text = $color_line_text."<tr><td>".$color."</td><td>".$color_quantity."</td></tr>";

$table_name1 = $_SESSION['db_prefix']."_tile_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";	 	
$color_qty_query = "SELECT 
$table_name2.store_item_id, 
$table_name2.item_type,
$table_name2.item_antique,
SUM($table_name1.quantity) AS summed_quantity, 
$table_name1.branch 
FROM 
$table_name1, $table_name2
WHERE 
$table_name2.store_item_id = $table_name1.store_item_id
AND
$table_name1.cust_id ".$cust_query_line." '".$cust_id."'
AND
$table_name1.branch = 'Gaborone' 
AND
$table_name2.item_type = '".$b1."'
AND
$table_name1.order_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."'
AND 
$table_name2.subCategory = 'Tiles'
AND 
$table_name2.item_color = '".$color."'
AND
$table_name2.item_antique = 'Antique' 
GROUP BY $table_name2.item_type";
$color_qty_result = execsql($color_qty_query);
$color_qty_num = mysql_num_rows($color_qty_result);
if ($color_qty_num!=0) {
$color_quantity2 = mysql_result($color_qty_result, 0, "summed_quantity");
$antique = mysql_result($color_qty_result, 0, "item_antique");
}
else {
$color_quantity2=0;
}
  
$color_line2_text = $color_line2_text."<tr><td>".$color." antique</td><td>".$color_quantity2."</td></tr>";

$k++;
}
	 
$color_quantityTT ="<table id=table_tool_tip width=250 ><tr><td>".$b1." Color</td><td>Quantity</td></tr>".$color_line_text.$color_line2_text."</table>";			
		?>
        
       	<tr >
		  <td ><a href="" onmouseover="ddrivetip('<?php echo $color_quantityTT ?>', 250)"; onmouseout="hideddrivetip()"><?php echo $b1 ?></a></td>
          <td ><?php echo $b4 ?></td>
          <td ><?php echo $b5 ?></td>
		</tr>
               
		<?php
		$i++;
		  
	}
	
	?>
	</tbody>

</table>
<br />
<br />
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<table width="640" id="table_details_display"class="sortable-onload-0r rowstyle-alt no-arrow "  >
	<thead>
		<tr>
		  <th width="200" class="sortable-text">Accessories</th>
          <th width="200" class="sortable-numeric">Sales Quantity</th>
          <th width="100">&nbsp;</th>
        </tr>
	</thead>
	<tbody>
  <?php
   	$i=0;
	while($i < $acc_display_num){
		 $b1 = mysql_result($acc_display_result, $i, "item_type");
		 $b4 = mysql_result($acc_display_result, $i, "summed_quantity");
		 $b5 = '';
$table_name = $_SESSION['db_prefix']."_list_colors";
$color_query = "SELECT item_name FROM $table_name ";
$color_result = mySQL_query($color_query);
$color_num = mysql_num_rows($color_result);

$color_line_text = '';
$k=0;
while ($k<$color_num) {
$color = mysql_result($color_result, $k, "item_name");

$table_name1 = $_SESSION['db_prefix']."_tile_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";	 	
$color_qty_query = "SELECT 
$table_name2.store_item_id, 
$table_name2.item_type,
SUM($table_name1.quantity) AS summed_quantity, 
$table_name1.branch 
FROM 
$table_name1, $table_name2
WHERE 
$table_name2.store_item_id = $table_name1.store_item_id
AND
$table_name1.cust_id ".$cust_query_line." '".$cust_id."'
AND
$table_name1.branch = 'Gaborone' 
AND
$table_name2.item_type = '".$b1."'
AND
$table_name1.order_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."'
AND 
$table_name2.subCategory = 'Accessories'
AND 
$table_name2.item_color = '".$color."'  
GROUP BY $table_name2.item_type";

$color_qty_result = execsql($color_qty_query);
$color_qty_num = mysql_num_rows($color_qty_result);
if ($color_qty_num!=0) {
$color_quantity = mysql_result($color_qty_result, 0, "summed_quantity");
}
else {
$color_quantity=0;
}
 
$color_line_text = $color_line_text."<tr><td>".$color."</td><td>".$color_quantity."</td></tr>";

$k++;
}
	 
$color_quantityTT ="<table id=table_tool_tip width=450 ><tr><td>Color</td><td>Quantity</td></tr>".$color_line_text."</table>";			
		?>
		<tr >
		  <td ><a href="" onmouseover="ddrivetip('<?php echo $color_quantityTT ?>', 450)"; onmouseout="hideddrivetip()"><?php echo $b1 ?></a></td>
          <td ><?php echo $b4 ?></td>
          <td ><?php echo $b5 ?></td>
          
		</tr>
        
		<?php
		$i++;
		  
	}
	
	?>
	</tbody>

</table>
 </div>
 </div>
 </li>
        <li>
          <input type="radio" name="tabs" id="tab2">
          <label  class="tab" for="tab2"><a class="tabs" href="sales_products.php?branch=Francistown&date=&cust_id=0">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="sales_products.php?branch=Combined&date=&cust_id=0">Combined</a></label>
           
 <div id="tab-content3" class="tab-content animated fadeIn">
 
          </div>
        </li>
</ul>
 
  </div>


 

