<?php 
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php');

?>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() 
{
    var data = google.visualization.arrayToDataTable([
    ['Task', 'Hours per Day'],
<?php 
    $fecha=date('y-m-d');
    $fecha1 = date('Y-m-d',strtotime('-1 month',strtotime($fecha)));
    $sql=mysqli_query($con, "SELECT *, sum(k.kar_cantidad_r) as can from kardex_ventas k, articulos a 
        WHERE  kar_fecha BETWEEN '$fecha1' AND '$fecha' and k.kar_art_id=a.art_id and a.art_tipo='articulo' and k.empresa='$empresa' group by k.kar_art_id order by can desc limit 10 ");
    while ($row=mysqli_fetch_array($sql))
    {
        $kar_art_id=$row['kar_art_id'];
        $total=$row['can'];
        $sql1=mysqli_query($con, "SELECT * from  articulos where art_id='$kar_art_id' ");
        $cos=mysqli_fetch_array($sql1);
        $art_nombre=$cos['art_nombre'];
?>   

    ['<?php echo $art_nombre; ?>', <?php echo $total; ?>],
         

<?php }  ?>
    ]);

    var options = {
        title: 'Lo mas vendido (Ultimo mes)',
    };
    var chart = new google.visualization.PieChart(document.getElementById('piechart'));
        chart.draw(data, options);
}
</script>
<div class="col-md-5">
    <div class="widget stacked">
        <div class="widget-content">
            <div id="piechart" style="height: 330px;"></div>
        </div> <!-- /widget-content -->
    </div> <!-- /widget -->   
</div> <!-- /.span6 -->
   