<table class="ocupacion">
  <tr>	
    <th colspan="4">CLIENTES QUE RENTARON</th>
      </tr>
  <tr>
    <th>Medio </th>
    <th>Submedio </th>
    <th>No. de Clientes</th>
    <th>porcentaje</th>
  </tr>
  <?
   $totalclientes=0;$x=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') and p.concepto IN('RENTA','SEGUIMIENTO') group by p.id_concepto ";  
   	
	$query=mysql_query($sql);
	while($rentas=mysql_fetch_array($query)){$ren.="'".$rentas["id_concepto"]."',";}
	$ren.="'0'";  
	$sql="SELECT  (Select subcanal from submedio where idsubmedio=r.submedio) as descripcion , (Select canal from medio where id=r.medio) as canal, count(c.id_renta) as con from  conceptos as c 
    INNER JOIN  renta as r ON c.id_renta=r.id_renta 
	where c.id_concepto IN($ren)  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"];}		//echo $d;
 ?><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($por=($medio["con"]/$totalclientes)*100);?>" readonly></td>
  </tr>
  <? 
  $porq=$porq+$por;
  $totsubmedio=$medio["con"];
  $smedio=$smedio.",^$d^";
  $totsub=$totsub.",".$totsubmedio;
  }
 $sub=strlen($smedio);
 $sub=$sub-1;
 $smedio=substr($smedio,-$sub);
 $tsb=strlen($totsub);
 $tsb=$tsb-1;
 $totsub=substr($totsub,-$tsb);
  ?>
  <tr>
    <td></td>
    <td>Total</td>
    <td><?echo ($totalclientes);?></td>
    <td><?echo porcentaje($porq);?></td>
  </tr>
  <tr><td colspan="4"><a href="graficas/gsubmedios.php?datos=<?echo$totsub;?>&fpago=<?echo$smedio;?>" 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>
</table>
<br>
<table class="ocupacion">
 <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>