<?session_start();
$fi=$_GET["fechaini"];
$ff=$_GET["fechafin"];
require("../conectar.php");
require("funciones.php");?>
<!doctype html>
<html>
<head><title>Ingresos por concepto</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" border="1">
  <tr><td colspan="4"><h1>INGRESOS X CONCEPTO</h1></td></tr>
  <tr>
    <td>Concepto </td>
    <td>No. de Clientes</td>
    <td>Cantidad en dolares</td>
   <td>Cantidad en pesos</td>
  </tr>
  <?
    $sql="SELECT concepto, count( DISTINCT id_concepto) as con from pagos  where(fecha between '$fi' and '$ff') and valadmon='s' group by concepto ";  
	$query=mysql_query($sql);
	$mayor=0;
 	while($pago=mysql_fetch_array($query))
		{
		 $x++;
		 $concepto=$pago["concepto"];
		 $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
		 $color = '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
 ?><tr>
 <input name="ultimon" type="hidden" id="ultimon" >
    <td>
    <input name="concepto<?echo$x?>" type="hidden" id="concepto<?echo$x?>" value="<?echo$concepto;?>" ><? if($concepto=="DEPOSITO"){echo"DEPOSITOS EN GARANTIA";}elseif($concepto=="IMPUESTOS"){echo$concepto."(IVA)";}else{echo$concepto;}?></td>
	<input name="color<?echo$x?>" type="hidden" id="color<?echo$x?>" value="<?echo$color;?>" >
    <td><? $totalclientes=$totalclientes+$pago["con"]; if($mayor<$pago["con"])$mayor=$pago["con"];?>
    <input name="cliente<?echo$x?>"  type="hidden" id="cliente<?echo$x?>" value="<?echo$pago["con"];?>"><font color="blue"><a onclick="clientelist('<?echo"p.concepto=/$concepto/"?>','<?echo$fi?>','<?echo$ff?>','<?echo$x?>');" ><?echo$pago["con"]?></a></font>
	<div id="clientelist<?echo$x;?>" > </div></td>
    <td>
	<?$sql="SELECT sum(monto) as monto, sum(monto*divisa) as montoconv from pagos  where (fecha between '$fi' and '$ff') and tipo_moneda='USD' and concepto='$concepto' and valadmon='s' group by concepto ";  
	$query1=mysql_query($sql); 
	$montous=mysql_fetch_array($query1);
	echo moneda($montous["monto"]);
	$totaldolarp=$totaldolarp+($montous["montoconv"]);
	$totaldolar=$totaldolar+$montous["monto"];?></td>
    <td><?$sql="SELECT sum(monto) as monto from pagos  where (fecha between '$fi' and '$ff') and tipo_moneda='MXN' and concepto='$concepto' and valadmon='s' group by concepto ";  
	$query1=mysql_query($sql); 	$montopes=mysql_fetch_array($query1);
	echo moneda($montopes["monto"]);	$totalpesos=$totalpesos+$montopes["monto"];
	?></td>
  </tr>
  <?
   if($montous['monto']==""){$usd="0";}else{$usd=$montous['monto'];}
    $tipos=array('CLIENTES','USD','MXN');
	$conc=$conc.",^$concepto^";
	$totgg3=$totgg3.",^$concepto^";
    $val=$val.",".$pago["con"];
	$vali=$vali.",".$pago['con'];
	$valiusd=$valiusd.",".$usd;
	$valimxn=$valimxn.",".round($montopes['monto'],2);
	$lc=strlen($val);
	$lc=$lc-1;
	$val=substr($val,-$lc);
	$totg=",{name:^$concepto^,data:[$val]}";
	$totgg=$totgg.$totg;
	$val="";
  }
    $ltg=strlen($totgg);
	$ltg=$ltg-1;
    $datacl=substr($totgg,-$ltg);
    $ltg3=strlen($conc);
	$ltg3=$ltg3-1;
    $conc3=substr($conc,-$ltg3);	
	$lc2=strlen($vali);
	$lc2=$lc2-1;
	$vali=substr($vali,-$lc2);
	$lc3=strlen($valiusd);
	$lc3=$lc3-1;
	$valiusd=substr($valiusd,-$lc3);
	$lc4=strlen($valimxn);
	$lc4=$lc4-1;
	$valimxn=substr($valimxn,-$lc4);
	$graficausdpesos="{name:^Clientes^,data:[$vali]},{name:^USD^,data:[$valiusd]},{name:^MXN^,data:[$valimxn]}";
	?>

  <tr>

    <td>Total</td>

    <td><?$mayor=$mayor+5;?>

    <!--<input name="total" type="text" id="total" value="<?echo $mayor;?>" readonly></td>-->
	<input name="total" type="text" id="total" value="<?echo $totalclientes;?>" readonly></td>
    <td><?echo moneda($totaldolar);?></td>

    <td><?echo moneda($totalpesos);?></td>

    <input name="ancho" type="hidden" id="ancho" value="<?echo$x;?>" >

  </tr>
  <tr>
    <th></th>
    <th></th>
    <th>Gran total</th>
    <th><?echo moneda($totalpesos+$totaldolarp);?></th>

    <input name="ancho" type="hidden" id="ancho" value="<?echo$x;?>" >

  </tr>
  <tr><th colspan="4">&nbsp;</th></tr>
  <!--<tr>
  <th colspan="4">  
  <a href="graficas/xconcepto.php?val=<?echo $datacl?>" 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 X CONCEPTO</font></div></a>
    <a href="graficas/xconceptousdpesos.php?val=<?echo$graficausdpesos;?>&nom=<?echo$conc3;?>" 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 X CONCEPTO CLIENTES/USD/MXN</font></div></a>
	</th>
  </tr>-->
  <? 
  $va=$datacl;
  $val=str_replace("^", "'", $va);
  ?>
</table>
<center>
<script>
		<!-- 2. Add the JavaScript to initialize the chart on document ready -->		
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container',
						defaultSeriesType: 'column',
						marginRight: 200,
						marginBottom: 50
					},
					title: {
						text: 'Ingresos x concepto',
						x: -20 //center
					},
					subtitle: {
						text: 'Mexico en Renta',
						x: -20
					},
					xAxis: {
						categories: ['Totales']
					},
					yAxis: {
						title: {
							text: 'Numero de clientes'
						},
						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: 1
					},
					series: [<?echo $val;?>]
				});
				
				
			});
</script>
<br>

<br>
<center><div id="container" style="width: 700px; height: 300px;"></div></center>
<br>

<br>
<?$val=$graficausdpesos;
$nom=$conc3;
 $conl=str_replace("^", "'", $nom);
 $val=str_replace("^", "'", $val);
?>
		<script type="text/javascript">
		
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container2',
						defaultSeriesType: 'column',
					},
					title: {
						text: 'INGRESOS X CONCEPTO CLIENTES/USD/MXN'
					},
					subtitle: {
						text: 'Mexico en Renta'
					},
					xAxis: {
						categories: [<?echo $conl;?>],
						labels: {
						rotation: -45,
						align: 'right',
						style: {
							fontSize: '12px',
							fontFamily: 'Verdana, sans-serif'
						}
						}
					},
					yAxis: {
						 labels: {
								formatter: function() {
									return Math.round(this.value);
								}},
						title: {
							text: 'Cantidad'
						}
					},
					tooltip: {
					 headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                     pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                    '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
                     footerFormat: '</table>',
                     shared: true,
                     useHTML: true
					},
					plotOptions: {
						column: {
							pointPadding: 0.2,
							borderWidth: 0,
							dataLabels: {
							enabled: true
							}
						}
					},
				        series: [<?echo $val;?>]
				});
				
				
			});
				
		</script>
<center><div id="container2" style="width: 700px; height: 300px;"></div></center>
</body>
</html>