<?php
//ini_set('display_error',1);
date_default_timezone_set('America/Lima');
session_start();
if($_SESSION["sistema"]!= "1"){ header("location: ../login/index.php"); exit();}

require_once ("../../config/Cado.php");
require_once ("../formatos/formato.php");
require_once ("../formatos/fechas.php");
require_once ("../grafica/cGrafica.php");
$oGrafica = new cGrafica();

// echo $_post['top'];
if($_POST['mes']!=""){
	$te  =  nombre_mes($_POST['mes']).', '.$_POST['anio'];
	$fec1 = '01-'.$_POST['mes'].'-'.$_POST['anio'];
	$fec2 = '31-'.$_POST['mes'].'-'.$_POST['anio'];
}else{
	$te  =  $_POST['anio'];
	$fec1 = '01-01-'.$_POST['anio'];
	$fec2 = '31-12-'.$_POST['anio'];
}

?>
<style type="text/css">
select{
	cursor:pointer;
}

</style>

<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
	
	<div class="row">

	
	<div id="ventas_topproducto" class="col-lg-6 col-sm-6 col-xs-12" style="height:400px;" ></div>
	
	<div id="compras_topproducto" class="col-lg-6 col-sm-6 col-xs-12" style="height:400px;" ></div>


	</div>
	
</div>

<script type="text/javascript">



	$(function() {


Highcharts.chart('ventas_topproducto', {
    chart: {
        type: 'variablepie'
    },
    title: {
        text: 'Top <?php echo $_POST["top"]; ?> productos mas vendidos en <?php echo $te;?>'
    },
    tooltip: {
        headerFormat: '',
        pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {point.name}</b><br/>' +
            'Cantidad (Vendidos): <b>{point.y}</b><br/>'
    },
    series: [{
        minPointSize: 10,
        innerSize: '20%',
        zMin: 0,
        name: 'countries',
        data: [
			<?php 		
			$dts=$oGrafica->filtroTopProductoVendidos('',fecha_mysql($fec1),fecha_mysql($fec2),$_POST['top']);
			while($dt = mysqli_fetch_array($dts)){
				$z = ($dt["can"] * $_POST['top'])/10;
			?>	
			{
			name :'<?php echo $dt["pronom"]." | ".$dt["marnom"]; ?>', 
			y:<?php echo $dt["can"]; ?>,
			z: <?php echo $z; ?>
			},
			<?php
			}		
			?>
		]
    }]
});
	
	
	
	
Highcharts.chart('compras_topproducto', {
    chart: {
        type: 'variablepie'
    },
    title: {
        text: 'Top <?php echo $_POST["top"]; ?> productos mas comprados en <?php echo $te;?>'
    },
    tooltip: {
        headerFormat: '',
        pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {point.name}</b><br/>' +
            'Cantidad (Comprados): <b>{point.y}</b><br/>'
    },
    series: [{
        minPointSize: 10,
        innerSize: '20%',
        zMin: 0,
        name: 'countries',
        data: [
			<?php 		
			$dts=$oGrafica->filtroTopProductoCompras('',fecha_mysql($fec1),fecha_mysql($fec2),$_POST['top']);
			while($dt = mysqli_fetch_array($dts)){
				$z = ($dt["can"] * $_POST['top'])/10;
			?>	
			{
			name :'<?php echo $dt["pronom"]." | ".$dt["marnom"]; ?>', 
			y:<?php echo $dt["can"]; ?>,
			z: <?php echo $z; ?>
			},
			<?php
			}		
			?>
		]
    }]
});
	

	
	}); 

</script>
