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

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

if ($permission_num==1) {

include ("../navigation/store_sidebar.php");
		
?>
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/tabs.css" />
<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> 



<script type="text/javascript" src="../jscript/jquery.jqplot.js"></script>
<script type="text/javascript" src="../jscript/jqplot.pieRenderer.js"></script>
<script type="text/javascript" src="../jscript/jqplot.donutRenderer.js"></script>
<link rel="stylesheet" type="text/css" href="../css/jquery.jqplot.css" />

<?php
$show = $_GET['show'];
$cust_id = $_GET['cust_id'];
$item_type = $_GET['item_type'];
$list_item_type = $_GET['item_type'];
$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 = '>';
}

//calculation tiles per customer
$table_name1 = $_SESSION['db_prefix']."_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";
$table_name3 = $_SESSION['db_prefix']."_list_tiles";
if ($cust_id==0) {	 	
$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.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."' )
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
";
}
else {
$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_id."'
AND
($table_name1.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."' )
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);


//calculation total tiles per tile
$table_name1 = $_SESSION['db_prefix']."_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";
$table_name3 = $_SESSION['db_prefix']."_list_tiles";	 	
$total_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.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."' )
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
";
$total_tiles_display_result = execsql($total_tiles_display_query);
$total_tiles_display_num = mysql_num_rows($total_tiles_display_result);


//calculation accessories per customer
$table_name1 = $_SESSION['db_prefix']."_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";
$table_name3 = $_SESSION['db_prefix']."_list_accessories";	 	
if ($cust_id==0) {
$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.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."'
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
";
}
else {
$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_id."'
AND
$table_name1.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."'
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);


//calculation total accessories
$table_name1 = $_SESSION['db_prefix']."_order_lines";	
$table_name2 = $_SESSION['db_prefix']."_store_items";
$table_name3 = $_SESSION['db_prefix']."_list_accessories";	 	
$total_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.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."'
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
";
$total_acc_display_result = execsql($total_acc_display_query);
$total_acc_display_num = mysql_num_rows($total_acc_display_result);

if ($show==1) {
//order summary
if ($cust_id!=0) {
$table_name1 = $_SESSION['db_prefix']."_order_lines";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$order_summary_query = "
SELECT $table_name2.item_type, $table_name1.order_reference, $table_name1.cust_id, $table_name1.order_no, $table_name1.quantity, $table_name1.order_date 
FROM $table_name1, $table_name2 
WHERE $table_name2.store_item_id = $table_name1.store_item_id 
AND $table_name1.cust_id = '".$cust_id."'
AND ($table_name1.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."' ) 
AND $table_name2.item_type = '".$item_type."' 
";
$order_summary_result = execsql($order_summary_query);
$order_summary_num = mysql_num_rows($order_summary_result);
}
else {
$table_name1 = $_SESSION['db_prefix']."_order_lines";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$order_summary_query = "
SELECT $table_name2.item_type, $table_name1.order_reference, $table_name1.cust_id,  $table_name1.order_no, $table_name1.quantity, $table_name1.order_date 
FROM $table_name1, $table_name2 
WHERE $table_name2.store_item_id = $table_name1.store_item_id 
AND ($table_name1.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."' ) 
AND $table_name2.item_type = '".$item_type."' 
";
$order_summary_result = execsql($order_summary_query);
$order_summary_num = mysql_num_rows($order_summary_result);
	
}



}

?>

  
</head>

<body>

<div class="main_frame">
 
  <div class="page_head_frame">
    <label class="label_page_head">Product sales</label></div>
<div class="page_middle_frame">

<?php
$page='sales_products.php';
$reference_name='show';
$reference=$show;
$reference_name_2='cust_id';
$reference_2=$cust_id;
$reference_name_3='item_type';
$reference_3=$item_type;
include('../include/period_select_block_small.php');
?>
<div class="page_inside_frame">
<form name="form1" id="form1"  action="" method="get">
Select customer:&nbsp;&nbsp;
<select name="comp_name_select" class="select300"  onchange="window.location.href= this.form.comp_name_select.options[this.form.comp_name_select.selectedIndex].value">
           <?php echo "<option value=sales_products.php?date=3&start_date=".$start."&end_date=".$end."&cust_id=0&show=0&item_type=>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?date=3&show=0&item_type=All&start_date=".$start."&end_date=".$end."&cust_id=".$arrId3[$k].">".$arrName3[$k]."</option>";
			
	}
?>
</select>
</form>
</div>
<br />
<br />

<form name="form2" id="form2"  action="" method="get">
<div class="page_inside_frame">
<div style="float:left; min-height:210px;">
Customer sales on total sales
  <table width="341" id="table_details_display"  >
	<thead>
		<tr>
		  <th width="115">Tiles</th>
          <th width="66" align="center">Sales<br>
            Quantity</th>
          <th width="71" align="center">Total Sales</th>
          <th width="69" align="center">% of<br>
Total Sales</th>
          </tr>
	</thead>
	<tbody>
  <?php
   	$i=0;
	$b4_tot=0;
	$b5_tot=0;
	$b6_tot=0;
	while($i < $tiles_display_num){
		 $b1 = mysql_result($tiles_display_result, $i, "item_type");
		 $b4 = mysql_result($tiles_display_result, $i, "summed_quantity");
		 if ($b4=='') {$b4='0';}
		 
		 $b5 = mysql_result($total_tiles_display_result, $i, "summed_quantity");
		 if ($b5=='') {$b5='0';}
		 
		 if (($b4!=0)||($b5!=0)) {
		        $b6 = $b4/$b5*100;
		 }
		 else {
			 $b6='0';
		 }
		 
		 $table_name = $_SESSION['db_prefix']."_list_tiles";
		 $tile_type_query = "SELECT item_type  FROM $table_name ";
		 $tile_type_result = mySQL_query($tile_type_query);
		 $tile_type_num = mysql_num_rows($tile_type_result);
		 $k=0;
		 while ($k<$tile_type_num) {
		    $item_type = mysql_result($tile_type_result, $k, "item_type");
			if ($item_type==$b1) {
			${'tile_type'.$k} = $item_type;
			${'tile_quantity'.$k} = $b4 ;
			}
			$k++;
			}
			
			
$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']."_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 
FROM 
$table_name1, $table_name2
WHERE 
$table_name2.store_item_id = $table_name1.store_item_id
AND
$table_name1.cust_id = '".$cust_id."'
AND
$table_name2.item_type = '".$b1."'
AND
$table_name1.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."'
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']."_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 

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_name2.item_type = '".$b1."'
AND
$table_name1.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."'
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 align="right" ><?php if ($cust_id!=0) { ?><a href="sales_products.php?cust_id=<?php echo $cust_id ?>&show=1&item_type=<?php echo $b1 ?>&&date=1&date1=<?php echo $start ?>&date2=<?php echo $end?>" onMouseOver="ddrivetip('Click for order breakdown', 125)"; onMouseOut="hideddrivetip()"><?php echo number_format($b4, 0, '.', ',') ?></a><?php } else { ?> <a href="sales_products.php?cust_id=0&show=1&item_type=<?php echo $b1 ?>&&date=1&date1=<?php echo $start ?>&date2=<?php echo $end?>" onMouseOver="ddrivetip('Click for order breakdown', 125)"; onMouseOut="hideddrivetip()"><?php echo number_format($b4, 0, '.', ',') ?></a> <?php  }?><?php $b4_tot = $b4_tot + $b4 ?></td>
          <td align="right" ><?php echo number_format($b5, 0, '.', ','); ?><?php $b5_tot = $b5_tot + $b5 ?></td>
          <td align="center" ><?php echo number_format($b6, 2, '.', ','); ?>
         <?php if (($b4_tot!=0)||($b5_tot!=0)) {
		        $b6_tot = $b4_tot/$b5_tot*100;
		 }
		 else {
			 $b6_tot='0';
		 }
		 ?></td>
          </tr>
		<?php
		$i++;
}
?>

<tr style="border-top-style:double;">
       	  <td >Total:</td>
       	  <td align="right" ><?php echo number_format($b4_tot, 0, '.', ',') ?></td>
       	  <td align="right" ><?php echo number_format($b5_tot, 0, '.', ',') ?></td>
       	  <td align="center" ><?php echo number_format($b6_tot, 2, '.', ',') ?></td>
     	  </tr>
        
	</tbody>

</table>
</div>
<div style="float:right">
Customer sales distribution
<div id="pie1" style="height:200px;width:300px; "></div>
<script>
$(document).ready(function(){
    var plot1 = $.jqplot('pie1', [[
	<?php
	$k=0;
	while ($k<$tile_type_num) { ?>
	['<?php echo ${"tile_type".$k} ?>',<?php echo ${"tile_quantity".$k} ?>],
	<?php 
	$k++;
	}
	?>
	]], {
        gridPadding: {top:0, bottom:38, left:0, right:0},
        seriesDefaults:{
            renderer:$.jqplot.PieRenderer, 
            trendline:{ show:true }, 
            rendererOptions: { padding: 8, showDataLabels: true }
        },
        legend:{
            show:true, 
            placement: 'inside', 
            rendererOptions: {
                numberRows: 1
            }, 
            location:'s',
            marginTop: '15px'
        }       
    });
});
</script>
</div>

<br />
<div style="float:left; min-height:210px;">
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<table width="340" id="table_details_display"class="sortable-onload-0r rowstyle-alt no-arrow "  >
	<thead>
		<tr>
		  <th width="115" class="sortable-text">Accessories</th>
          <th width="66" align="center" class="sortable-numeric">Sales<br>
            Quantity</th>
          <th width="66" align="center">Total Sales</th>
          <th width="73" align="center">% of<br>
            Total Sales</th>
        </tr>
	</thead>
	<tbody>
  <?php
   	$i=0;
	$b4_tot=0;
	$b5_tot=0;
	$b6_tot=0;
	while($i < $acc_display_num){
		 $b1 = mysql_result($acc_display_result, $i, "item_type");
		 $b4 = mysql_result($acc_display_result, $i, "summed_quantity");
		 if ($b4=='') {$b4='0';}
		 
		 $b5 = mysql_result($total_acc_display_result, $i, "summed_quantity");
		 if ($b5=='') {$b5='0';}
		 
		 if (($b4!=0)||($b5!=0)) {
		        $b6 = $b4/$b5*100;
		 }
		 else {
			 $b6='0';
		 }
		 
		 $table_name = $_SESSION['db_prefix']."_list_accessories";
		 $acc_type_query = "SELECT item_type, item_code  FROM $table_name ";
		 $acc_type_result = mySQL_query($acc_type_query);
		 $acc_type_num = mysql_num_rows($acc_type_result);
		 $m=0;
		 while ($m<$acc_type_num) {
			$item_type = mysql_result($acc_type_result, $m, "item_type"); 
		    $item_code = mysql_result($acc_type_result, $m, "item_code");
			if ($item_type==$b1) {
			${'acc_code'.$m} = $item_code;
			${'acc_quantity'.$m} = $b4 ;
			}
			$m++;
			}
		 
		 
$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']."_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 
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_name2.item_type = '".$b1."'
AND
$table_name1.order_date >= '".$start."' AND $table_name1.order_date <= '".$end."'
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=250 ><tr><td>Color</td><td>Quantity</td></tr>".$color_line_text."</table>";			
		?>
		<tr >
		  <td ><a href="" onmouseover="ddrivetip('<?php echo $color_quantityTT ?>', 250)"; onmouseout="hideddrivetip()"><?php echo $b1 ?></a></td>
          <td align="right" ><?php if ($cust_id!=0) { ?><a href="sales_products.php?cust_id=<?php echo $cust_id ?>&show=1&item_type=<?php echo $b1 ?>&&date=1&date1=<?php echo $start ?>&date2=<?php echo $end?>" onMouseOver="ddrivetip('Click for order breakdown', 125)"; onMouseOut="hideddrivetip()"><?php echo number_format($b4, 0, '.', ',') ?></a><?php } else { ?> <a href="sales_products.php?cust_id=0&show=1&item_type=<?php echo $b1 ?>&&date=1&date1=<?php echo $start ?>&date2=<?php echo $end?>" onMouseOver="ddrivetip('Click for order breakdown', 125)"; onMouseOut="hideddrivetip()"><?php echo number_format($b4, 0, '.', ',') ?></a> <?php  }?>
            <?php $b4_tot = $b4_tot + $b4 ?></td>
          <td align="right" ><?php echo number_format($b5, 0, '.', ','); ?>
            <?php $b5_tot = $b5_tot + $b5 ?></td>
          <td align="center" ><?php echo number_format($b6, 2, '.', ','); ?>
            <?php if (($b4_tot!=0)||($b5_tot!=0)) {
		        $b6_tot = $b4_tot/$b5_tot*100;
		 }
		 else {
			 $b6_tot='0';
		 }
		 ?></td>
          
		</tr>
		<?php
		$i++;
	}
?>

<tr style="border-top-style:double;">
       	  <td >Total:</td>
       	  <td align="right" ><?php echo number_format($b4_tot, 0, '.', ',') ?></td>
       	  <td align="right" ><?php echo number_format($b5_tot, 0, '.', ',') ?></td>
       	  <td align="center" ><?php echo number_format($b6_tot, 2, '.', ',') ?></td>
     	  </tr>
         
	</tbody>

</table>
</div>
<div style="float:right">
<div id="pie2" style="height:200px;width:300px; "></div>
<script>
$(document).ready(function(){
    var plot2 = $.jqplot('pie2', [[
	<?php
	$m=0;
	while ($m<$acc_type_num) { ?>
	['<?php echo ${"acc_code".$m} ?>',<?php echo ${"acc_quantity".$m} ?>],
	<?php 
	$m++;
	}
	?>
	]], {
        gridPadding: {top:0, bottom:38, left:0, right:0},
        seriesDefaults:{
            renderer:$.jqplot.PieRenderer, 
            trendline:{ show:true }, 
            rendererOptions: { padding: 8, showDataLabels: true }
        },
        legend:{
            show:true, 
            placement: 'inside', 
            rendererOptions: {
                numberRows: 1
            }, 
            location:'s',
            marginTop: '15px'
        }       
    });
});
</script>
</div>

</div>

</form>

<?php if ($show==1) { ?>
<div class="page_inside_frame">
<table width="479" id="table_details_display">
  <tr>
    <td colspan="4">Order summary for <?php echo $list_item_type ?> ordered by <?php echo $cust_name ?>  </td>
    </tr> 
  <tr>
    <td width="90">Order no</td>
    <td width="81">Date</td>
    <td width="231">Customer</td>
    <td width="57">Quantity</td>
  </tr>
  <?php
  $i=0;
  $tot_quantity=0;
  while ($i<$order_summary_num) {
	  $order_no = mysql_result($order_summary_result, $i, "order_no");
	  $order_reference = mysql_result($order_summary_result, $i, "order_reference");
	  $order_date = mysql_result($order_summary_result, $i, "order_date");
	  $quantity = mysql_result($order_summary_result, $i, "quantity");
	  $cust_id = mysql_result($order_summary_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 ='".$cust_id."' ";
				$customer_result = mySQL_query($customer_query);
				$customer_num = mysql_num_rows($customer_result);	
				$account_type = mysql_result($customer_result, 0, "account_type");
				$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				
	  ?>
  <tr>
    <td><a href="order.php?order_reference=<?php echo $order_reference ?>" onMouseover="ddrivetip('Click for order details.', 120)"; onMouseout="hideddrivetip()"><?php echo $order_no ?></a></td>
    <td><?php echo date("d-m-Y", strtotime($order_date)) ?></td>
    <td><a href="account_details.php?cust_id=<?php echo $cust_id ?>" onMouseover="ddrivetip('Click for customer details', 150)"; onMouseout="hideddrivetip()"><?php echo $cust_name ?></a></td>
    <td align="right"><?php echo number_format($quantity, 0, '.', ',') ?><?php $tot_quantity = $tot_quantity + $quantity ?></td>
  </tr>
  <?php
  $i++;
  }
  ?>
  <tr>
    <td colspan="3" align="right">Total:&nbsp;&nbsp;</td>
    <td align="right"><?php echo number_format($tot_quantity, 0, '.', ',') ?></td>
  </tr>
</table>
</div>
<?php } ?>
 </div>
 </div>
 </div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "store/store_main.php?date=";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>

