<table class="ocupacion">
<tr>
<th>Concepto</th>
<th>Cantidad</th>
<th>Ingreso MXN</th>
<th>Ingreso USD</th>
<th>Ingresos Totales(MXN)</th>
</tr>
<?
require("../conectar.php");
$fi=$_GET["fechaini"];
$ff=$_GET["fechafin"];
$concepto=0;$x=0;$cantidad=0;$pes=0;$usds=0;$total=0;$pestot=0;$usdtot=0;
$sql="SELECT p.concepto,count( DISTINCT p.id_concepto) as cant, sum(p.monto) as mon, sum(p.monto*p.divisa) as moncon, p.tipo_moneda 
FROM conceptos as c 
INNER JOIN pagos as p ON p.id_concepto=c.id_concepto 
WHERE p.concepto IN('RENTA','SEGUIMIENTO') AND (p.fecha BETWEEN '$fi' AND '$ff') AND p.valadmon='s'  GROUP BY p.concepto,tipo_moneda";
$query=mysql_query($sql);
while($usd=mysql_fetch_array($query))
{
if($concepto!=$usd["concepto"])
		{ 
		$x++;?>
		<tr>
		<td><?echo $concepto;?><input type="hidden" name="concepto<?echo$x?>" id="concepto<?echo$x?>" value="<?echo$concepto?>" ></td>
		<td><input type="hidden" name="cantidad<?echo$x?>" id="cantidad<?echo$x?>" value="<?echo$cantidad?>" ><font color="blue"><a onclick="clientelist('<?echo"p.concepto =/$concepto/ ";?>','<?echo$fi?>','<?echo$ff?>','<?echo"tipo".$x;?>');" ><?echo ($cantidad);?></a></font>
	<div id="clientelist<?echo"tipo".$x;?>" > </div></td>
		<td><?echo moneda($pes);?><input type="hidden" name="pes<?echo$x?>" id="pes<?echo$x?>" value="<?echo$pes?>" ></td>
		<td><?echo moneda($usds);?><input type="hidden" name="usds<?echo$x?>" id="usds<?echo$x?>" value="<?echo$usds?>" ></td>
		<td><?echo moneda($total)?><input type="hidden" name="total<?echo$x?>" id="total<?echo$x?>" value="<?echo$total?>" ></td>
		</tr>
			<?
			$ca=$cantidad;
			$con=$concepto;
			$totalt=$totalt+$total;
			$usdtot=$usds+$usdtot;
			$pestot=$pes+$pestot;
			$cantidad=0;$pes=0;$usds=0;$total=0;$concepto=$usd["concepto"];
			$val="[^".$con."^,".$ca."],";
			$tot="name:^$con^,data:[$val";
		}
if($concepto==0)$concepto=$usd["concepto"];
if($usd["tipo_moneda"]=="USD"){$usds=$usd["mon"]+$usds;$total=$total+$usd["moncon"]; } 
if($usd["tipo_moneda"]=="MXN"){$pes=$usd["mon"]+$pes;$total=$total+$usd["mon"]; } 
$cantidad=$cantidad+$usd["cant"];
$cantidadt=$cantidadt+$usd["cant"];

			$val2="[^".$concepto."^,".$cantidad."]]";
            $tot2=$tot.$val2;			
}
echo$cadena=$tot2;
$totalt=$totalt+$total;
$usdtot=$usds+$usdtot;
			$pestot=$pes+$pestot;
?>
<tr><?$x++;?>
		<td><?echo$concepto;?><input type="hidden" name="concepto<?echo$x?>" id="concepto<?echo$x?>" value="<?echo$concepto?>" ></td>
		<td><input type="hidden" name="cantidad<?echo$x?>" id="cantidad<?echo$x?>" value="<?echo$cantidad?>" ><font color="blue"><a onclick="clientelist('<?echo"p.concepto =/$concepto/ ";?>','<?echo$fi?>','<?echo$ff?>','<?echo"tipo".$x?>');" ><?echo ($cantidad);?></a></font>
	<div id="clientelist<?echo"tipo".$x;?>" > </div></td>
		<td><?echo moneda($pes);?><input type="hidden" name="pes<?echo$x?>" id="pes<?echo$x?>" value="<?echo$pes?>" ></td>
		<td><?echo moneda($usds);?><input type="hidden" name="usds<?echo$x?>" id="usds<?echo$x?>" value="<?echo$usds?>" ></td>
		<td><?echo moneda($total)?><input type="hidden" name="total<?echo$x?>" id="total<?echo$x?>" value="<?echo$total?>" ></td>
</tr>
<tr>
<td>Total</td>
<td><?echo ($cantidadt);?><input type="hidden" name="cantidadt" id="cantidadt" value="<?echo$cantidadt?>" ></td>
<td><?echo moneda($pestot);?><input type="hidden" name="pestot" id="pestot" value="<?echo$pestot?>" ></td>
<td><?echo moneda($usdtot);?><input type="hidden" name="usdtot" id="usdtot" value="<?echo$usdtot?>" ></td>
<th title="Gran total"><?echo moneda($totalt);?><input type="hidden" name="totalt" id="totalt" value="<?echo$totalt?>" ></th>
</tr>
<tr><th colspan="5">&nbsp;</th></tr>
<tr><th colspan="5"><a href="graficas/tiporenta.php?val=<?echo $cadena?>" 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 TIPO DE RENTA</font></div></a></th></tr>
</table>
