<?session_start();
$fi=$_GET["fechaini"];
$ff=$_GET["fechafin"];
require("../conectar.php");
require("funciones.php");?>
<!doctype html>
<html>
<head><title>Reporte de medios</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>		
<script type="text/javascript" src="js/highcharts.js"></script>			
<script type="text/javascript" src="js/modules/exporting.js"></script>
<script type="text/javascript" src="js/themes/gray.js"></script>
<script>
function clientelist(con,fi,ff,x)
{ 
c=1;
e="";
//while(document.getElementById("clientelist"+c)){if(c!=x){ $("#clientelist"+c).html("");} c++;}
$.post("clientelistaff.php",{ id:x,con:con,fi:fi,ff:ff},function(data,status){
$("#clientelist"+x).html(data);
});
}
</script>
		<link rel="stylesheet" type="text/css" href="css/estiloorg.css" />
	<style type="text/css">
        p.ps{ font-size:9px;height:7px; }
	.ps:hover{ font-size:10px; background:#487f1a;}	
	
.ocupacion {
	-webkit-box-shadow: 5px 5px #000000;
	box-shadow: 5px 5px #000000;
	font-family: Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", serif;
}

.ocupacion td {
	text-align: center;
	border-collapse: separate;
	background-color: #E6E6E6;
	color: #000000;
	border-top: thin solid #000000;
	border-bottom: thin solid #000000;
	border-left:thin solid #000000;
	border-right:thin solid #000000;
}
.ocupacion tr th {
	text-align: center;
	border-collapse: separate;
	background-color: #000000;
	border-left:thin solid #ffffff;
	border-top: thin solid #000000;
	border-bottom: thin solid #000000;
	border-right:thin solid #ffffff;
}
.ocupacion input {
	background-color: #E6E6E6;
	border-style: none;
	text-align: center;
	color: #000000;
	width:60px;
}


.ocupacion2 {
	-webkit-box-shadow: 5px 5px #000000;
	box-shadow: 5px 5px #000000;
	font-family: Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", serif;
}

.ocupacion2 td {
	text-align: right;
	border-collapse: separate;
	background-color: #E6E6E6;
	color: #000000;
	border-top: thin solid #000000;
	border-bottom: thin solid #000000;
	border-left:thin solid #000000;
	border-right:thin solid #000000;
}
.ocupacion2 tr th {
	text-align: center;
	border-collapse: separate;
	background-color: #000000;
	border-left:thin solid #ffffff;
	border-top: thin solid #000000;
	border-bottom: thin solid #000000;
	border-right:thin solid #ffffff;
}
.ocupacion2 input {
	background-color: #E6E6E6;
	border-style: none;
	text-align: center;
	color: #000000;
	width:60px;
}

               a{text-decoration:none;outline:none;}
               .boton{margin-left:2px;margin-right:2px;float:left;width:100px;height:30px;background: url(images/bkbtn.png) no-repeat;color:#000;font-weight:bold;font-size:10px;text-align:center;text:decoration:none !important;}
               .boton:hover{background-position: left bottom;}
               .boton .d{position:relative;margin:auto;top:8px;font-size:9px;}
               .boton .db{position:relative;margin:auto;top:5px;font-size:9px;}
               .boton .n{position:relative;margin:auto;top:8px;}
	</style>
</head>
<body>
<center>
<table class="ocupacion">
  <tr><td colspan="3"><h1>Motivo de viaje</h1></td></tr>
  <tr>
    <th>Motivo de viaje </th>
    <th>No. de Clientes</th>
    <th>porcentaje</th>
  </tr>
  <?
   $totalclientes=0;$x=0;$porq=0;
   /*$sql="SELECT  c.id_concepto FROM conceptos as c 
     INNER JOIN pagos as p ON p.id_concepto=c.id_concepto 
   where(p.fecha between '$fi' and '$ff') group by p.id_concepto ";  */
   	
	$query=mysql_query($sql);
	/*while($rentas=mysql_fetch_array($query)){$ren.="'".$rentas["id_concepto"]."',";}*/
	$ren.="'0'";  
	$sql="SELECT  c.motivo_viaje as mv,count(c.id_cliente) as con from clientes as c 
    INNER JOIN  renta as r ON c.id_cliente=r.id_cliente 
	where r.fecha between '$fi' and '$ff' group by c.motivo_viaje";  
	$query=mysql_query($sql);
	while($medio=mysql_fetch_array($query))
		{
		$totalclientes=$medio["con"]+$totalclientes;
		}
	$query=mysql_query($sql);
		while($medio=mysql_fetch_array($query))
		{
		$x++;
		if($medio["mv"]==""){$m="NO CAPTURADO";}
		else{$m=$medio["mv"];}
 ?><tr>
    <td>
    <input name="medio<?echo$x?>" type="hidden" id="medio<?echo$x?>" value="<?echo$m;?>" ><?echo htmlentities($m);?></td>

    <td>
    <input name="cliente<?echo$x?>" type="text" id="cliente<?echo$x?>" value="<?echo$medio["con"];?>" readonly></td>
    <td>
	<input name="porcliente<?echo$x?>" type="text" id="porcliente<?echo$x?>" value="<?echo porcentaje($por=($medio["con"]/$totalclientes)*100);?>" readonly></td>
  </tr>
  <? 
  $porq=$porq+$por;
  $totsubmedio=$medio["con"];
  $viaje=$viaje.",^$m^";
  $totviaje=$totviaje.",".$totsubmedio;
  }
 $sub=strlen($viaje);
 $sub=$sub-1;
 $viaje=substr($viaje,-$sub);
 $tsb=strlen($totviaje);
 $tsb=$tsb-1;
 $totviaje=substr($totviaje,-$tsb);
  ?>
  <tr>
    <td>Total</td>
    <td><?echo ($totalclientes);?></td>
    <td><?echo porcentaje($porq);?></td>
  </tr>
  <!--<tr><td colspan="4"><a href="graficas/gsubmedios.php?datos=<?echo$totviaje;?>&fpago=<?echo$pais;?>" target="_blank" onclick="window.open(this.href ,this.target,'toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,top=0,left=0,width=1170,height=550');return false;"><div class="boton"><font class="db">GRAFICA MEDIOS</font></div></a></td></tr>-->

<br>

<br>
<?
 $me=$viaje;
 $meses=str_replace("^", "'", $me);
 $data=$totviaje;
?>
		<script type="text/javascript">
		
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container16',
						defaultSeriesType: 'column',
						marginRight: 200,
						marginBottom: 50
					},
					title: {
						text: 'MOTIVO DE VIAJE',
						x: -20 //center
					},
					subtitle: {
						text: 'Mexico en Renta',
						x: -20
					},
					xAxis: {
						categories: [<?echo $meses?>]
					},
					yAxis: {
						title: {
							text: 'TOTAL'
						},labels: {
								formatter: function() {
									return Math.round(this.value);
								}},
						plotLines: [{
							value: 0,
							width: 1,
							color: '#808080'
						}]
					},
					tooltip: {
						formatter: function() {
				                return '<b>'+ this.series.name +'</b><br/>'+
								this.x +': '+ this.y +'';
						}
					},
					 plotOptions: {
						column: {
							dataLabels: {
								enabled: true
							}
						}
					}
					,
					legend: {
						layout: 'vertical',
						align: 'right',
						verticalAlign: 'top',
						x: -10,
						y: 100,
						borderWidth: 0
					},
					series:[{name: 'MOTIVO DE VIAJE',
						data: [<?echo $data;?>]	
						}]
				});
				
				
			});
				
		</script>
		<tr>
		<td colspan="4"><div id="container16" style="width: 700px; height: 300px; margin: 0 auto"></div></td>
		</tr>
		</table>
</center>
</body>
</html>
<!--		<br>
		
		<br>
<table class="ocupacion" align="center">
 <tr>	
    <th colspan="4">CLIENTES QUE NO RENTARON</th>
      </tr>
  <tr>
    <th>Medio </th>
    <th>Submedio </th>
    <th>No. de Clientes</th>
    <th>porcentaje</th>
  </tr>
  <?
 /*$totalclientes=0;$x=0;$porq=0;
  $sql="SELECT  (Select subcanal from submedio where idsubmedio=r.submedio) as descripcion , (Select canal from medio where id=r.medio) as canal,  count(r.id_renta) as con from renta as r 
  INNER JOIN conceptos as c ON c.id_renta=r.id_renta 
  where(c.dia_inicio between '$fi' and '$ff') and c.status_renta IN('','LIBRE')  group by descripcion ";  
	$query=mysql_query($sql);
	while($medio=mysql_fetch_array($query))
		{
		$totalclientes=$medio["con"]+$totalclientes;
		}
	$query=mysql_query($sql);
		while($medio=mysql_fetch_array($query))
		{
		$x++;
		if($medio["canal"]==""){$m="NO CAPTURADO";}
		else{$m=$medio["canal"];}
		if($medio["descripcion"]==""){$d="NO CAPTURADO";}
		else{$d=$medio["descripcion"];}*/
 ?><tr>
    <td>
    <input name="medio<?echo$x?>" type="hidden" id="medio<?echo$x?>" value="<?echo$m;?>" ><?echo$m?></td>
	 <td>
    <input name="submedio<?echo$x?>" type="hidden" id="submedio<?echo$x?>" value="<?echo$d;?>" ><?echo$d?></td>
    <td>
    <input name="cliente<?echo$x?>" type="text" id="cliente<?echo$x?>" value="<?echo$medio["con"];?>" readonly></td>
    <td>
	<input name="porcliente<?echo$x?>" type="text" id="porcliente<?echo$x?>" value="<?echo porcentaje($porcen=$por=($medio["con"]/$totalclientes)*100);?>" readonly></td>
  </tr>
  <?
  /*$porq=$porcen+$porq;
  }*/?>
  <tr>
    <td></td>
    <td>Total</td>
    <td><?echo ($totalclientes);?></td>
    <td><?echo porcentaje($porq);?></td>
  </tr>
</table>-->