<?php
require_once ('../clases/jpgraph/jpgraph.php');
require_once ('../clases/jpgraph/jpgraph_odo.php');
include('../clases/clase.conexion.php');
include('../funciones/variables.php');
include('../funciones/funciones.php');
$var = VarServer("MYSQLI");
$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
$varAno = (isset($_GET[anio]) && $_GET[anio]<>"")?$_GET[anio]:date("Y");
$varMes = (isset($_GET[mes]) && $_GET[mes]<>"")?$_GET[mes]:date("m");
 
$sql = "CALL spQuery_Avance_Ventas_Empresa('".$varAno."','".$varMes."');";
$obj->AbrirConexion();
$rs = $obj->Query($sql);
$obj->CerrarConexion();
$acaptions = NULL;
$NumReg = $obj->NumFilas($rs);
// Create a new odometer graph (width=250, height=200 pixels)
$graph = new OdoGraph(700,200*$NumReg);
$graph->title->Set('INDICADOR DE VENTAS POR EMPRESA');
$graph->title->SetFont(FF_ARIAL,FS_BOLD,14);
$graph->subtitle->Set('PERIODO : '.MesNombreLargo($varMes).' - '.$varAno);
$graph->subtitle->SetFont(FF_ARIAL,FS_BOLD,10);
$odo = array();

$i = 0;
$varArrayReal = array();
$varArrayTend = array();
while($fila = $obj->FetchArray($rs)) {
		$varTitu = substr($fila["EMPRESA"],0,45);
		$varTitu.= "\nVenta : ".number_format($fila["VENTA"],2,".",",");
		$varTitu.= "\nMeta : ".number_format($fila["META"],2,".",",");
		$odo[$i] =new Odometer();
		$odo[$i]->needle->Set($fila["PORC_VENTA"]);
		$odo[$i]->label->Set(number_format($fila["PORC_VENTA"],2,".",",")."%");
		$odo[$i]->label->SetFont(FF_FONT2,FS_BOLD);
		$odo[$i]->caption->SetFont(FF_FONT1,FS_NORMAL);
		$odo[$i]->caption->Set($varTitu);
		$odo[$i]->AddIndication(0,40,'red');
		$odo[$i]->AddIndication(40,60,'orange');
		$odo[$i]->AddIndication(60,80,'yellow');
		$odo[$i]->AddIndication(80,90,'green:0.7');
		$odo[$i]->AddIndication(90,100,'green:0.9');		
		$varArrayReal[$i] = $odo[$i];
		
		$varTitu = substr($fila["EMPRESA"],0,45);
		$varTitu.= "\nTendencia : ".number_format($fila["TENDENCIA"],2,".",",");
		$varTitu.= "\nMeta : ".number_format($fila["META"],2,".",",");
		$odo[$i] =new Odometer();
		$odo[$i]->SetColor("lightyellow");
		$odo[$i]->needle->Set($fila["PORC_TENDENCIA"]);
		$odo[$i]->label->Set(number_format($fila["PORC_TENDENCIA"],2,".",",")."%");
		$odo[$i]->label->SetFont(FF_FONT2,FS_BOLD);
		$odo[$i]->caption->SetFont(FF_FONT1,FS_NORMAL);
		$odo[$i]->caption->Set($varTitu);
		$odo[$i]->AddIndication(0,40,'red');
		$odo[$i]->AddIndication(40,60,'orange');
		$odo[$i]->AddIndication(60,80,'yellow');
		$odo[$i]->AddIndication(80,90,'green:0.7');
		$odo[$i]->AddIndication(90,100,'green:0.9');		
		$varArrayTend[$i] = $odo[$i];
		$i++;
	}

$ver1 = new LayoutVert( $varArrayReal);
$ver2 = new LayoutVert( $varArrayTend);
$row1 = new LayoutHor(array($ver1,$ver2) );
// Add the odometer to the graph
$graph->Add($row1);

// ... and finally stroke and stream the image back to the browser
$graph->Stroke();
?>