<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
include ("../navigation/header.php");

$page_name = "Sales-main";
include ("../navigation/access.php");

if ($permission_num==1) {

include ("../navigation/sales_sidebar.php");
	
		
?>
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css">

<!--jscript-->
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

<?php
include('../include/period_select_date.php');
$store_item_id = $_GET['store_item_id'];


$table_name2 = $_SESSION['db_prefix']."_tile_order_lines";
$order_query = "SELECT store_item_id, order_no, order_date, cust_id, quantity, price, purchase_price, branch FROM $table_name2 WHERE store_item_id = '".$store_item_id."' AND order_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."'  ";
$order_result = mySQL_query($order_query);
$order_num = mysql_num_rows($order_result);	

$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);
$item_name = mysql_result($name_result, 0, "item_name");

$table_caption = 'Orders with '.$item_name;

?>

 
       
</head>

<body>

<div class="main_frame">
 
<div class="page_head_frame">
    <label class="label_page_head">Tile sales reports</label>
</div>

<div class="page_middle_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": "420px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 2, "asc" ]],
					"aoColumns": [
								
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 9},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 10},
								{"iDataSort": 11},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
       
        
 
         <?php
$page='tile_sales_list.php';
$reference_name='branch';
$reference='Gaborone';
$reference_name_2='store_item_id';
$reference_2= $store_item_id;
include('../include/period_select_block_2.php');
?>       </form>
       
        
        
          <div style="margin-top:120px;">

          <label class="label_std"><font size="+2"><?php echo $table_caption ?></font></label> 
          </div>
          <table width="445" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th >Order no</th>
              <th >Branch</th>
              <th >Order date</th>
              <th >Customer</th>
              <th >Quantity</th>
              <th >Purchase<br />price</th>
              <th >Sales<br />price</th>
              <th >Total<br />purchase</th>
              <th >Total<br />sales</th>
              
              <th>&nbsp;</th>
              <th>&nbsp;</th>
              <th>&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;

$a9_total=0;
$a10_total=0;
$price=0;

while ($i<$order_num) {
	$a1 = mysql_result($order_result, $i, "order_no");
	$a2 = mysql_result($order_result, $i, "branch");
	$a3 = mysql_result($order_result, $i, "order_date");
	$a4 = mysql_result($order_result, $i, "cust_id");
	
	$table_name2 = $_SESSION['db_prefix']."_customer";
				$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$a4."' ";
				$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");
 				}
	
	$a6 = mysql_result($order_result, $i, "quantity");
	
	$a9 = mysql_result($order_result, $i, "purchase_price");
	$a10 = mysql_result($order_result, $i, "price");
	
	$a9_sub = $a9 * $a6;
	$a9_total = $a9_total + $a9_sub;
	$a10_sub = $a10 * $a6;
	$a10_total = $a10_total + $a10_sub;
	
	
	//$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 align="left"  style="padding-left:0px;"><a href=" " onMouseover="ddrivetip('', 450)"; onMouseout="hideddrivetip()"> <?php echo $a1 ?>  </a></td>
              <td align="left"><?php echo $a2 ?></td>
              <td align="left"><?php echo date("d-m-Y", strtotime($a3)) ?></td>
              <td align="left"><?php echo $cust_name ?></td>
              <td align="right"><?php echo $a6 ?></td>
              <td align="right"><?php echo $a9 ?></td>
              <td align="right"><?php echo $a10 ?></td>
              <td align="right"><?php echo number_format($a9_sub, 2, '.', ',') ?></td>
              <td width="80" align="right"><?php echo number_format($a10_sub, 2, '.', ',') ?></td>
              
              <td align="left"><?php echo $a3 ?></td>
              <td align="left"><?php echo $a9_sub ?></td>
              <td align="left"><?php echo $a10_sub ?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td colspan="7" align="right" valign="bottom">Total:</td>
                <td align="right" valign="bottom"><?php echo number_format($a9_total, 2, '.', ',') ?></td>
                <td align="right" valign="bottom"><?php echo number_format($a10_total, 2, '.', ',') ?></td>
                <td >&nbsp;</td>
                <td >&nbsp;</td>
                <td >&nbsp;</td>
               
              </tr>
            </tfoot>
          </table>

</div>
</div> 

<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "sales/sales_main.php?date=&branch=";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>

