<?php




	include "../../plugin/SVGGraph/SVGGraph.php";
	
	
	
	
	
	
	
	//====================================================product distribution==============================================================
	
				
				
		
		
	
	//device library:
	$query_device="select * from t_".$key_table_prefix."_device ";
	$result_device = mysqli_query($dbconn,$query_device);
	while($line_device = mysqli_fetch_array($result_device,MYSQLI_ASSOC))
	{
		
		$device_data[$line_device["dev_android_id"]]=$line_device["dev_name"];
	}
	
	
	
	
	
	
	
	
	
	
	echo "<div class='data_display_content' style='padding:20px;float:left;width:350px;left-align:center;'>";
	
	
			echo "<font size=3 style='padding:15px;color:#000;'><b> Sales Distribution by Product</b></font>";
			
			
			
			$query="select 
					
					sum(ivi_quantity) as ivi_quantity,
					sum(ivi_discount_total) as ivi_discount_total,
					sum(ivi_total_amount) as ivi_total_amount,
					
					ivi_product_code, ivi_product_name
					
					
					from t_".$key_table_prefix."_invoice_header h, t_".$key_table_prefix."_invoice_item i 
					where ivh_doc_no = ivi_doc_no
					and h.device_id = i.device_id 
					and ivh_status = 'POSTED'
					
					
					
					
					
					
					group by  ivi_product_code, ivi_product_name
					order by ivi_total_amount desc
					
					
					";		
			$result = mysqli_query($dbconn,$query);
			while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
			{
				$chart_value_product[$line["ivi_product_code"]]=$line["ivi_total_amount"];
			}
			
			$settings = array(
			'back_colour' => '#fff',   'stroke_colour' => '',
			'back_stroke_width' => 0,  'back_stroke_colour' => '#eee',
			'pad_right' => 20,         'pad_left' => 20,
			'link_base' => '/',        'link_target' => '_top',
			'show_labels' => true,     'show_label_amount' => true,
			'label_font' => 'Arial', 'label_font_size' => '11',
			'label_colour' => '#fff', 
			'sort' => false
			);
			
			$values = array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45,
			'Lard' => 35);
			
			$colours = array('#ccf','#699','#93c','#996','#f39','#0f3','#339');
			$colours = array('#F03434','#22A7F0','#90C695','#2C3E50','#913D88','#F39C12','#DB0A5B');
			$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php',
			'Me' => 'svggraph.php');
			
			$graph = new SVGGraph(300, 300, $settings);
			$graph->colours = $colours;
			
			$graph->Values($chart_value_product);
			$graph->Links($links);
			$graph->Render('DonutGraph');
	
	echo "</div>";
	
	
	
	
	
	
	
	
	echo "<div class='data_display_content' style='padding:20px;float:left;width:350px;left-align:center;'>";
	
			echo "<font size=3 style='padding:15px;color:#000;'><b> Sales Distribution by Branch</b></font>";
			
			
			$query="select 
					
					sum(ivi_quantity) as ivi_quantity,
					sum(ivi_discount_total) as ivi_discount_total,
					sum(ivi_total_amount) as ivi_total_amount,
					
					h.device_id as device
					
					
					from t_".$key_table_prefix."_invoice_header h, t_".$key_table_prefix."_invoice_item i 
					where ivh_doc_no = ivi_doc_no
					and h.device_id = i.device_id 
					and ivh_status = 'POSTED'
					
					
					
					
					
					
					group by  device
					order by ivi_total_amount desc
					
					
					";		
			$result = mysqli_query($dbconn,$query);
			while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
			{
				$chart_value_device[$device_data[$line["device"]]]=$line["ivi_total_amount"];
			}
			
				
				
				
			$settings = array(
			'back_colour' => '#fff',   'stroke_colour' => '',
			'back_stroke_width' => 0,  'back_stroke_colour' => '#eee',
			'pad_right' => 20,         'pad_left' => 20,
			'link_base' => '/',        'link_target' => '_top',
			'show_labels' => true,     'show_label_amount' => true,
			'label_font' => 'Arial', 'label_font_size' => '11',
			'label_colour' => '#fff', 
			'sort' => false
			);
			
			$values = array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45,
			'Lard' => 35);
			
			$colours = array('#F03434','#22A7F0','#90C695','#2C3E50','#913D88','#F39C12','#DB0A5B');
			$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php',
			'Me' => 'svggraph.php');
			
			$graph = new SVGGraph(300, 300, $settings);
			$graph->colours = $colours;
			
			$graph->Values($chart_value_device);
			$graph->Links($links);
			$graph->Render('DonutGraph');
			
	echo "</div>";
	
	
	
	
	
	
	
	
	
	
	
	echo "<div class='data_display_content' style='padding:20px;float:left;width:350px;left-align:center;'>";
	
			echo "<font size=3 style='padding:15px;color:#000;'><b> Sales Distribution by Week`s Day</b></font>";
		
		unset($chart_value_weekday);
			
			$query="select 
					
					
					sum(ivi_total_amount) as ivi_total_amount,
					
					DATE_FORMAT(h.created_date,'%a') as sales_day,
					DATE_FORMAT(h.created_date,'%w') as sales_day_w
					
					from t_".$key_table_prefix."_invoice_header h, t_".$key_table_prefix."_invoice_item i 
					where ivh_doc_no = ivi_doc_no
					and h.device_id = i.device_id 
					and ivh_status = 'POSTED'
					
					
					
					
					
					
					group by sales_day
					order by  sales_day_w desc
					
					
					";		
			$result = mysqli_query($dbconn,$query);
			while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
			{
				
				$chart_value_weekday[$line["sales_day"]] = $line["ivi_total_amount"];
					
				
			}
			
			
				
		unset($settings);
			
			$settings = array(
		  'back_colour'       => '#fff',    'stroke_colour'      => '#000',
		  'back_stroke_width' => 0,         'back_stroke_colour' => '#eee',
		  'axis_colour'       => '#333',    'axis_overlap'       => 2,
		  'axis_font'         => 'Arial', 'axis_font_size'     => 10,
		  'grid_colour'       => '#BDC3C7',    'label_colour'       => '#000',
		  'pad_right'         => 0,        'pad_left'           => 0,
		  'link_base'         => '/',       'link_target'        => '_top',
		  'fill_under'        => true,
		  'marker_size'       => 0,
		  'marker_type'       => array('dot', 'cross'),
		  'marker_colour'     => array('#2574A9', 'red')
		);
		 
		$values = array(
		 array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45, 'Lard' => 35),
		 array('Dough' => 20, 'Ray' => 30, 'Me' => 20, 'So' => 15, 'Far' => 25, 'Lard' => 35,
		  'Tea' => 45)
		);
		 unset($colours);
		$colours = array('#0ED2F7', '#B2FEFA');
		$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php',
		  'Me' => 'svggraph.php');
		 
		$graph = new SVGGraph(300, 300, $settings);
		$graph->colours = $colours;
		 
		$graph->Values($chart_value_weekday);
		$graph->Links($links);
		$graph->Render('MultiRadarGraph');
			
			
			
	echo "</div>";
	
	
	
	
	
	
	
	echo "<br>&nbsp;<br>&nbsp;";
	echo "<br>&nbsp;<br>&nbsp;";
	echo "<br>&nbsp;<br>&nbsp;";
	
	    echo "</section>";
	
	









	/*
	$graph = new SVGGraph(640, 480);
 $graph->colours = array('#E74C3C','#1ABC9C','#3498DB');
 $graph->Values(100, 200, 150);
 $graph->Links('/Tom/', '/Dick/', '/Harry/');
 $graph->Render('BarGraph');
	
	
	
	
 $settings = array(
'back_colour' => '#ECF0F1',   'stroke_colour' => '',
'back_stroke_width' => 0,  'back_stroke_colour' => '#eee',
'pad_right' => 20,         'pad_left' => 20,
'link_base' => '/',        'link_target' => '_top',
'show_labels' => true,     'show_label_amount' => true,
'label_font' => 'Arial', 'label_font_size' => '11',
'label_colour' => '#fff', 
'sort' => false
);

$values = array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45,
'Lard' => 35);

$colours = array('#ccf','#699','#93c','#996','#f39','#0f3','#339');
$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php',
'Me' => 'svggraph.php');

$graph = new SVGGraph(300, 200, $settings);
$graph->colours = $colours;

$graph->Values($values);
$graph->Links($links);
$graph->Render('DonutGraph');
	
	
	
	
	
	
$settings = array(
'back_colour' => '#eee',  'stroke_colour' => '',
'back_stroke_width' => 0, 'back_stroke_colour' => '#eee',
'axis_colour' => '#333',  'axis_overlap' => 2,
'axis_font' => 'Georgia', 'axis_font_size' => 10,
'grid_colour' => '#666',  'label_colour' => '#000',
'pad_right' => 20,        'pad_left' => 20,
'link_base' => '/',       'link_target' => '_top',
'project_angle' => 45,    'minimum_grid_spacing' => 20
);

$values = array(
array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45, 'Lard' => 35),
array('Dough' => 20, 'Ray' => 30, 'Me' => 20, 'So' => 15, 'Far' => 25, 'Lard' => 35,
'Tea' => 45)
);

$colours = array(array('#74ebd5','#74ebd5'), array('#BE93C5','#7BC6CC'));
$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php',
'Me' => 'svggraph.php');

$graph = new SVGGraph(300, 200, $settings);
$graph->colours = $colours;

$graph->Values($values);
$graph->Links($links);
$graph->Render('Bar3DGraph');




$settings = array(
  'back_colour'       => '#eee',    'stroke_colour'      => '#000',
  'back_stroke_width' => 0,         'back_stroke_colour' => '#eee',
  'axis_colour'       => '#333',    'axis_overlap'       => 2,
  'axis_font'         => 'Georgia', 'axis_font_size'     => 10,
  'grid_colour'       => '#666',    'label_colour'       => '#000',
  'pad_right'         => 20,        'pad_left'           => 20,
  'link_base'         => '/',       'link_target'        => '_top',
  'fill_under'        => true,
  'marker_size'       => 3,
  'marker_type'       => array('x', 'cross'),
  'marker_colour'     => array('blue', 'red')
);
 
$values = array(
 array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45, 'Lard' => 35),
 array('Dough' => 20, 'Ray' => 30, 'Me' => 20, 'So' => 15, 'Far' => 25, 'Lard' => 35,
  'Tea' => 45)
);
 
$colours = array(array('red', 'yellow'), array('blue', 'white'));
$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php',
  'Me' => 'svggraph.php');
  
  
  
  
  
 
$graph = new SVGGraph(300, 200, $settings);
$graph->colours = $colours;
 
$graph->Values($values);
$graph->Links($links);
$graph->Render('MultiRadarGraph');
	
	*/
	
	
	
?>
