<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Radstone Phakalane Distributor sales</title>
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico">
<?php 
include('../include/session.php');

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

if ($permission_num==1) {  
	
$report_year = $_POST['report_year_select'];
$report_type = $_POST['report_type'];
$line_num = $_POST['line_num_text'];


if ($report_type==1) {
$report_cat = 'Tiles and Accessories';
$table_name = $_SESSION['db_prefix']."_order_lines";
$total_query = "SELECT order_date, SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' GROUP BY EXTRACT(month FROM order_date) ";
$total_result = mySQL_query($total_query);
$total_num = mysql_num_rows($total_result);
}

if ($report_type==2) {
$report_cat = 'Tiles';
$table_name = $_SESSION['db_prefix']."_order_lines";
$total_query = "SELECT order_date, SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND sub_category = 'Tiles'  GROUP BY EXTRACT(month FROM order_date) ";
$total_result = mySQL_query($total_query);
$total_num = mysql_num_rows($total_result);
}

if ($report_type==3) {
$report_cat = 'Accessories';
$table_name = $_SESSION['db_prefix']."_order_lines";
$total_query = "SELECT order_date, SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND sub_category = 'Accessories'  GROUP BY EXTRACT(month FROM order_date) ";
$total_result = mySQL_query($total_query);
$total_num = mysql_num_rows($total_result);
}

$table_name = $_SESSION['db_prefix']."_order_lines";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$double_roman_query = "SELECT SUM($table_name.quantity) AS total_quantity FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND $table_name.store_item_id = $table_name2.store_item_id AND $table_name2.item_type = 'Double Roman'  GROUP BY EXTRACT(month FROM order_date) ";
$double_roman_result = mySQL_query($double_roman_query);
$double_roman_num = mysql_num_rows($double_roman_result);


$table_name = $_SESSION['db_prefix']."_order_lines";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$slate_query = "SELECT SUM($table_name.quantity) AS total_quantity FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND $table_name.store_item_id = $table_name2.store_item_id AND $table_name2.item_type = 'Slate'  GROUP BY EXTRACT(month FROM order_date) ";
$slate_result = mySQL_query($slate_query);
$slate_num = mysql_num_rows($slate_result);


$table_name = $_SESSION['db_prefix']."_order_lines";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$venetian_query = "SELECT SUM($table_name.quantity) AS total_quantity FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND $table_name.store_item_id = $table_name2.store_item_id AND $table_name2.item_type = 'Venetian'  GROUP BY EXTRACT(month FROM order_date) ";
$venetian_result = mySQL_query($venetian_query);
$venetian_num = mysql_num_rows($venetian_result);

$table_name = $_SESSION['db_prefix']."_order_lines";
$accessories_query = "SELECT SUM(quantity) AS total_quantity FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND sub_category = 'Accessories'  GROUP BY EXTRACT(month FROM order_date) ";
$accessories_result = mySQL_query($accessories_query);
$accessories_num = mysql_num_rows($accessories_result);


?>
<!--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" />
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></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.barRenderer.js"></script>
<script type="text/javascript" src="../jscript/jqplot.categoryAxisRenderer.js"></script>
<script type="text/javascript" src="../jscript/jqplot.pointLabels.js"></script>
<script type="text/javascript" src="../jscript/jqplot.donutRenderer.js"></script>
<link rel="stylesheet" type="text/css" href="../css/jquery.jqplot.css" />
       
</head>

<body style="width:auto; margin-left:20px;" onUnload="<?php $z=0; while ($z<30) { $_SESSION['cust_id'.$z]=''; $z++; } ?>">

<div>
 
<div>
    <label class="label_page_head">Radstone Phakalane Distributor sales </label>
</div>

<div>

 
<label class="label_std">Reporting on: <?php echo $report_cat ?> &nbsp;&nbsp;&nbsp;Report year: <?php echo $report_year ?> </label>    
 

<div style="width:auto; overflow:scroll;"><br>
<table id="table_list">
<thead>
  <tr>
    <td align="center">Month</td>
    <td align="center">Total<br>Sales</td>
    <?php	
	$columns = 0;
	$k=0;
	while ($k<$line_num) {
	
	if(isset($_POST['cust_checkbox'.$k])) { 
	  		$cust_id = $_POST['cust_id_text'.$k];
			 
			
				$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");
 				}
			
			${'column_cust_id'.$columns} = $cust_id;
			
			$columns = $columns + 1;
					  	
	?>
    <td align="center"><?php echo $cust_name ?></td>
    <td align="center">in %</td>
    <?php
	$k++;
	}
	else {
		$k++;
	}
	
	}
	?>
  </tr>
</thead>
<?php 
$i=0;
while ($i<$total_num) {
	$order_month =  mysql_result($total_result, $i, "order_date");
	$order_month = date("F", strtotime($order_month));
	$all_total = mysql_result($total_result, $i, "total_quantity");
	$month_no = date("m", strtotime($order_month));
?>	  
  <tr>
    <td><?php echo $order_month ?></td>
    <td align="right"><?php echo $all_total ?></td>
    <?php
	
	
	$k=0;
	while ($k<$columns) {
	
	$cust_id = ${'column_cust_id'.$k};	
	$_SESSION['cust_id'.$k] = $cust_id;
	$month_period = $month_no;
	
	
if ($report_type==1) {
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$cust_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND EXTRACT(month FROM order_date) = '".$month_period."' AND cust_id = '".$cust_id."'  GROUP BY EXTRACT(month FROM order_date) ";
	
	$cust_total_result = mySQL_query($cust_total_query);
	$cust_total_num = mysql_num_rows($cust_total_result);
	if ($cust_total_num>0) {
	$cust_total = mysql_result($cust_total_result, 0, "total_quantity");
	}
	else {
    $cust_total = 0;
	}
	$perc = ($cust_total / $all_total) * 100;
}

if ($report_type==2) {
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$cust_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND EXTRACT(month FROM order_date) = '".$month_period."' AND cust_id = '".$cust_id."' AND sub_category = 'Tiles'  GROUP BY EXTRACT(month FROM order_date) ";
	$cust_total_result = mySQL_query($cust_total_query);
	$cust_total_num = mysql_num_rows($cust_total_result);
	if ($cust_total_num>0) {
	$cust_total = mysql_result($cust_total_result, 0, "total_quantity");
	}
	else {
    $cust_total = 0;
	}
	$perc = ($cust_total / $all_total) * 100;
}

if ($report_type==3) {
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$cust_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND EXTRACT(month FROM order_date) = '".$month_period."' AND cust_id = '".$cust_id."' AND sub_category = 'Accessories'  GROUP BY EXTRACT(month FROM order_date) ";
	$cust_total_result = mySQL_query($cust_total_query);
	$cust_total_num = mysql_num_rows($cust_total_result);
	if ($cust_total_num>0) {
	$cust_total = mysql_result($cust_total_result, 0, "total_quantity");
	}
	else {
    $cust_total = 0;
	}
	$perc = ($cust_total / $all_total) * 100;
}


//===================popup balloon

	$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");
 			}
			
	$double_roman_quantity = mysql_result($double_roman_result, $i, "total_quantity");
	$slate_quantity = mysql_result($slate_result, $i, "total_quantity");
	$venetian_quantity = mysql_result($venetian_result, $i, "total_quantity");
	$accessories_quantity = mysql_result($accessories_result, $i, "total_quantity");
	
$table_name = $_SESSION['db_prefix']."_order_lines";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$cust_double_roman_query = "SELECT SUM($table_name.quantity) AS total_quantity FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND $table_name.store_item_id = $table_name2.store_item_id AND $table_name2.item_type = 'Double Roman' AND $table_name.cust_id = '".$cust_id."' AND EXTRACT(month FROM order_date) = '".$month_no."' ";
$cust_double_roman_result = mySQL_query($cust_double_roman_query);
$cust_double_roman_num = mysql_num_rows($cust_double_roman_result);
if ($cust_double_roman_num > 0) {
$cust_double_roman = mysql_result($cust_double_roman_result, 0, "total_quantity");
}
else {
$cust_double_roman = 0;
}
$cust_double_roman_perc = number_format(($cust_double_roman / $double_roman_quantity) * 100, 2, '.', ',');

$table_name = $_SESSION['db_prefix']."_order_lines";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$cust_slate_query = "SELECT SUM($table_name.quantity) AS total_quantity FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND $table_name.store_item_id = $table_name2.store_item_id AND $table_name2.item_type = 'Slate' AND $table_name.cust_id = '".$cust_id."'  AND EXTRACT(month FROM order_date) = '".$month_no."' ";
$cust_slate_result = mySQL_query($cust_slate_query);
$cust_slate_num = mysql_num_rows($cust_slate_result);
if ($cust_slate_num > 0) {
$cust_slate = mysql_result($cust_slate_result, 0, "total_quantity");
}
else {
$cust_slate = 0;
}
$cust_slate_perc = number_format(($cust_slate / $slate_quantity) * 100, 2, '.', ',');

$table_name = $_SESSION['db_prefix']."_order_lines";
$table_name2 = $_SESSION['db_prefix']."_store_items";
$cust_venetian_query = "SELECT SUM($table_name.quantity) AS total_quantity FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND $table_name.store_item_id = $table_name2.store_item_id AND $table_name2.item_type = 'Venetian' AND $table_name.cust_id = '".$cust_id."'  AND EXTRACT(month FROM order_date) = '".$month_no."' ";
$cust_venetian_result = mySQL_query($cust_venetian_query);
$cust_venetian_num = mysql_num_rows($cust_venetian_result);
if ($cust_venetian_num > 0) {
$cust_venetian = mysql_result($cust_venetian_result, 0, "total_quantity");
}
else {
$cust_venetian = 0;
}
$cust_venetian_perc = number_format(($cust_venetian / $venetian_quantity) * 100, 2, '.', ',');

$table_name = $_SESSION['db_prefix']."_order_lines";
$cust_accessories_query = "SELECT SUM(quantity) AS total_quantity FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND sub_category = 'Accessories' AND $table_name.cust_id = '".$cust_id."'  AND EXTRACT(month FROM order_date) = '".$month_no."' ";
$cust_accessories_result = mySQL_query($cust_accessories_query);
$cust_accessories_num = mysql_num_rows($cust_accessories_result);
if ($cust_accessories_num > 0) {
$cust_accessories = mysql_result($cust_accessories_result, 0, "total_quantity");
}
else {
$cust_accessories = 0;
}
$cust_accessories_perc = number_format(($cust_accessories / $accessories_quantity) * 100, 2, '.', ',');
			
$customerTT_line1 = $cust_name.'<br>';	
$customerTT_line2 = '<table><tr><td width=100px; align=center;>&nbsp;</td><td width=50px; align=center;>DR</td><td width=50px; align=center;>SL</td><td width=50px; align=center;>VN</td><td width=50px; align=center;>Acc</td></tr><tr><td>Total Sales</td><td align=right;>'.$double_roman_quantity.'</td><td align=right;>'.$slate_quantity.'</td><td align=right;>'.$venetian_quantity.'</td><td align=right;>'.$accessories_quantity.'</td></tr><tr><td>Customer Sales</td><td align=right;>'.$cust_double_roman.'</td><td align=right;>'.$cust_slate.'</td><td align=right;>'.$cust_venetian.'</td><td align=right;>'.$cust_accessories.'</td></tr><tr><td>Customer %</td><td>'.$cust_double_roman_perc.'</td><td>'.$cust_slate_perc.'</td><td>'.$cust_venetian_perc.'</td><td>'.$cust_accessories_perc.'</td></tr></table>';
$customerTT = $customerTT_line1.$customerTT_line2;


	
	?>
    <td align="right"><a href=" " onMouseover="ddrivetip('<?php echo $customerTT ?>', 350)"; onMouseout="hideddrivetip()"> <?php echo $cust_total ?> </a></td>
    <td align="right"><?php echo number_format($perc, 1, '.', ',') ?></td>
    <?php
	$k++;
	}
	?>
		
  </tr>
<?php
$i++;
}
?>
<tfoot>
<tr>
    <td>&nbsp;</td>
    <?php
	if ($report_type==1) {
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$full_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' ";
	$full_total_result = mySQL_query($full_total_query);
	$full_total = mysql_result($full_total_result, 0, "total_quantity");
	}
	
	if ($report_type==2) {
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$full_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND sub_category = 'Tiles' ";
	$full_total_result = mySQL_query($full_total_query);
	$full_total = mysql_result($full_total_result, 0, "total_quantity");
	}
	
	if ($report_type==3) {
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$full_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND sub_category = 'Accessories' ";
	$full_total_result = mySQL_query($full_total_query);
	$full_total = mysql_result($full_total_result, 0, "total_quantity");
	}
	?>
    <td align="right"><?php echo $full_total ?></td>
    <?php
	$k=0;
	while ($k<$columns) {
		$cust_id = ${'column_cust_id'.$k};
	
	if ($report_type==1) {	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$cust_full_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND cust_id = '".$cust_id."' ";
	$cust_full_total_result = mySQL_query($cust_full_total_query);
	$cust_full_total = mysql_result($cust_full_total_result, 0, "total_quantity");
	}
	
	if ($report_type==2) {	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$cust_full_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND cust_id = '".$cust_id."'  AND sub_category = 'Tiles' ";
	$cust_full_total_result = mySQL_query($cust_full_total_query);
	$cust_full_total = mysql_result($cust_full_total_result, 0, "total_quantity");
	}
	
	if ($report_type==3) {	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$cust_full_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND cust_id = '".$cust_id."'  AND sub_category = 'Accessories' ";
	$cust_full_total_result = mySQL_query($cust_full_total_query);
	$cust_full_total = mysql_result($cust_full_total_result, 0, "total_quantity");
	}
	
	$perc_full_total = ($cust_full_total / $full_total) * 100;
	?>
    <td align="right"><?php echo $cust_full_total ?></td>
    <td align="right"><?php echo number_format($perc_full_total, 1, '.', ',') ?></td>
    <?php
	$k++;
	}
	?>
  </tr>
</tfoot>
</table>
</div>
<div align="right" style="margin-top:5px; margin-right:10px;">
<a href="distribution1_csv_export.php?report_year_select=<?php echo $report_year ?>&report_type=<?php echo $report_type ?>&line_num_text=<?php echo $columns ?>" ><input name="export2_button" type="button" value="CSV Export" class="imagebutton"></a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="distributor_ordered_report_print1.php?report_year_select=<?php echo $report_year ?>&report_type=<?php echo $report_type ?>&line_num_text=<?php echo $columns ?>" target="_blank"><input name="print1_button" type="button" value="Print" class="imagebutton"></a>
</div>

<div style="width:700px;"><br>
<label class="label_std"><label class="label_std">Tile and Accessories distribution on distributor orders <?php echo $report_year ?></label> 
<table id="table_list" width="500" >
<thead>
  <tr>
    <td align="center">Month</td>
    <td align="center">Total</td>
    <td align="center">Double Roman</td>
    <td align="center">in %</td>
    <td align="center">Slate</td>
    <td align="center">in %</td>
    <td align="center">Venetian</td>
    <td align="center">in %</td>
    <td align="center">Accessories</td>
    <td align="center">in %</td>
    </tr>
</thead>
<?php 
$p=0;
while ($p<$total_num) {
	$order_month =  mysql_result($total_result, $p, "order_date");
	$order_month = date("F", strtotime($order_month));
	$all_total = mysql_result($total_result, $p, "total_quantity");
	$month_no = date("m", strtotime($order_month));
	
	$double_roman_quantity = mysql_result($double_roman_result, $p, "total_quantity");
	$slate_quantity = mysql_result($slate_result, $p, "total_quantity");
	$venetian_quantity = mysql_result($venetian_result, $p, "total_quantity");
	$accessories_quantity = mysql_result($accessories_result, $p, "total_quantity");
	
	$double_roman_perc = ($double_roman_quantity / $all_total) * 100;
	$slate_perc = ($slate_quantity / $all_total) * 100;
	$venetian_perc = ($venetian_quantity / $all_total) * 100;
	$accessories_perc = ($accessories_quantity / $all_total) * 100;
	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$full_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' ";
	$full_total_result = mySQL_query($full_total_query);
	$full_total = mysql_result($full_total_result, 0, "total_quantity");
	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$table_name2 = $_SESSION['db_prefix']."_store_items";
	$double_roman_total_query = "SELECT SUM($table_name.quantity) AS total_quantity  FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND $table_name.store_item_id = $table_name2.store_item_id AND item_type = 'Double Roman' ";
	$double_roman_total_result = mySQL_query($double_roman_total_query);
	$double_roman_total = mysql_result($double_roman_total_result, 0, "total_quantity");
	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$table_name2 = $_SESSION['db_prefix']."_store_items";
	$slate_total_query = "SELECT SUM($table_name.quantity) AS total_quantity  FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND $table_name.store_item_id = $table_name2.store_item_id AND item_type = 'Slate' ";
	$slate_total_result = mySQL_query($slate_total_query);
	$slate_total = mysql_result($slate_total_result, 0, "total_quantity");
	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$table_name2 = $_SESSION['db_prefix']."_store_items";
	$venetian_total_query = "SELECT SUM($table_name.quantity) AS total_quantity  FROM $table_name, $table_name2 WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."' AND $table_name.store_item_id = $table_name2.store_item_id AND item_type = 'Venetian' ";
	$venetian_total_result = mySQL_query($venetian_total_query);
	$venetian_total = mysql_result($venetian_total_result, 0, "total_quantity");
	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$accessories_total_query = "SELECT SUM(quantity) AS total_quantity  FROM $table_name WHERE EXTRACT(YEAR FROM order_date) = '".$report_year."'  AND sub_category = 'Accessories' ";
	$accessories_total_result = mySQL_query($accessories_total_query);
	$accessories_total = mysql_result($accessories_total_result, 0, "total_quantity");
	
	$double_roman_full_perc = ($double_roman_total / $full_total) * 100;
	$slate_full_perc = ($slate_total / $full_total) * 100;
	$venetian_full_perc = ($venetian_total / $full_total) * 100;
	$accessories_full_perc = ($accessories_total / $full_total) * 100;
?>	    
  <tr>
    <td><?php echo $order_month ?></td>
    <td align="right"><?php echo $all_total ?></td>
    <td align="right"><?php echo $double_roman_quantity ?></td>
    <td align="right"><?php echo number_format($double_roman_perc, 1, '.', ',') ?></td>
    <td align="right"><?php echo $slate_quantity ?></td>
    <td align="right"><?php echo number_format($slate_perc, 1, '.', ',') ?></td>
    <td align="right"><?php echo $venetian_quantity ?></td>
    <td align="right"><?php echo number_format($venetian_perc, 1, '.', ',') ?></td>
    <td align="right"><?php echo $accessories_quantity ?></td>
    <td align="right"><?php echo number_format($accessories_perc, 1, '.', ',') ?></td>
  </tr>
<?php
$p++;
}
?>  
<tfoot>
	<tr>
    <td>&nbsp;</td>
    <td align="right"><?php echo $full_total ?> </td>
    <td align="right"><?php echo $double_roman_total ?></td>
    <td align="right"><?php echo number_format($double_roman_full_perc, 1, '.', ',') ?></td>
    <td align="right"><?php echo $slate_total ?></td>
    <td align="right"><?php echo number_format($slate_full_perc, 1, '.', ',') ?></td>
    <td align="right"><?php echo $venetian_total ?></td>
    <td align="right"><?php echo number_format($venetian_full_perc, 1, '.', ',') ?></td>
    <td align="right"><?php echo $accessories_total ?></td>
    <td align="right"><?php echo number_format($accessories_full_perc, 1, '.', ',') ?></td>
  </tr>
</tfoot>
</table>

<br><br>
<div align="right" style="margin-top:5px; margin-right:10px;">
<a href="distribution2_csv_export.php?report_year_select=<?php echo $report_year ?>&report_type=<?php echo $report_type ?>" ><input name="export2_button" type="button" value="CSV Export" class="imagebutton"></a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="distributor_ordered_report_print2.php?report_year_select=<?php echo $report_year ?>&report_type=<?php echo $report_type ?>" target="_blank"><input name="print2_button" type="button" value="Print" class="imagebutton"></a>

</div>

<div>
<label class="label_std">Product distribution on distributor orders  <?php echo $report_year ?></label> 
  <div id="pie1" style="height:200px;width:300px; "></div>
<script>
$(document).ready(function(){
    var plot1 = $.jqplot('pie1', [[
	['DR',<?php echo $double_roman_total ?>],
	['SL',<?php echo $slate_total ?>],
	['VN',<?php echo $venetian_total ?>],
	['Acc',<?php echo $accessories_total ?>],
	
	]], {
        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>

<label class="label_std">Month product distribution on distributor orders <?php echo $report_year ?></label><br>
<div id="chart2" style="width:auto;"></div>
<script>
$(document).ready(function(){

        var s1 = [<?php $p=0; while ($p<$total_num) { echo mysql_result($double_roman_result, $p, "total_quantity").','; $p++;  } ?>];
        var s2 = [<?php $p=0; while ($p<$total_num) { echo mysql_result($slate_result, $p, "total_quantity").','; $p++;  } ?>];
		var s3 = [<?php $p=0; while ($p<$total_num) { echo mysql_result($venetian_result, $p, "total_quantity").','; $p++;  } ?>];
		var s4 = [<?php $p=0; while ($p<$total_num) { echo mysql_result($accessories_result, $p, "total_quantity").','; $p++;  } ?>];
		
		var ticks = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
         
        plot2 = $.jqplot('chart2', [s1, s2, s3, s4], {
            seriesDefaults: {
                renderer:$.jqplot.BarRenderer,
                pointLabels: { show: true }
            },
            axes: {
                xaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer,
                    ticks: ticks
                }
            }
        });
     
        $('#chart2').bind('jqplotDataHighlight', 
            function (ev, seriesIndex, pointIndex, data) {
                $('#info2').html(' month,quantity: '+data);
            }
        );
             
        $('#chart2').bind('jqplotDataUnhighlight', 
            function (ev) {
                $('#info2').html('Move mouse over bar');
            }
        );
    });
</script>
<div><span>Moused Over: </span><span id="info2">Nothing</span></div>
</div>

</div>
</div>
</div> 

</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php 
    $_SESSION['denied_return'] = "store/store_main.php?date=";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>

