<?session_start();
$fi=$_GET["fechaini"];
$ff=$_GET["fechafin"];
require("../conectar.php");
require("funciones.php");?>
<html>
<head>
<title>Tipo de renta</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>
<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>
<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>
</head>
<body>
<center>
<table class="ocupacion">
<tr><td colspan="5"><h1>Tipo de renta</h1></td></tr>
<tr>
<th>Concepto</th>
<th>Cantidad</th>
<th>Ingreso MXN</th>
<th>Ingreso USD</th>
<th>Ingresos Totales(MXN)</th>
</tr>
<?
$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;			
}
$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>
</center>
<br>

<br>
<?
$va=$cadena;
$val=str_replace("^", "'", $va); 
?>
<script type="text/javascript">				
var chart;			
$(document).ready(function() {
				chart = new Highcharts.Chart({
				chart: {
				renderTo: 'container4',
				plotBackgroundColor: null,
						plotBorderWidth: null,
						plotShadow: false
						},
						title: {
						text: 'Tipo de renta'
						},
						tooltip: {
						formatter: function() {
						return '<b>'+ this.point.name +'</b>: '+ this.y +' ';
						}
						},
						plotOptions: {
						pie: {
						allowPointSelect: true,
						cursor: 'pointer',
						dataLabels: {
						enabled: true,
						color: '#000000',
						connectorColor: '#000000',
						formatter: function() {
						return '<b>'+ this.point.name +'</b>: '+ this.y +'';
						}
						},
						showInLegend: true
						}
						},
						series: [{
						type: 'pie',
						<?echo $val;?>
						}]
						});
						});
</script>
<div id="container4" style="width: 700px; height: 300px; margin: 0 auto"></div>
</body>
</html>
