<?session_start();
$fi=$_GET["fechaini"];
$ff=$_GET["fechafin"];
require("../conectar.php");
require("funciones.php");?>
<!doctype html>
<html>
<head>
<title>Ingreso por dia</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="ocupacion2">
<tr><td colspan="3"><h1>Ingreso por dia</h1></td></tr>
<tr>
<th>Dia</th>
<th>Ingreso en Pesos</th>
<th>Ingreso en Dolares</th>
</tr>
<?
function fechacorta($f)
{
list($anio,$mes,$dia)=explode("-",$f);
$me=array("","ENE","FEB","MAR","ABR","MAY","JUN","JUL","AGO","SEP","OCT","NOV","DIC");
$mes++;$mes--;
$return=$me["$mes"]."-".$dia;
return($return);
}
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;
function dias($fecha_i,$fecha_f)
{
	$dias	= (strtotime($fecha_i)-strtotime($fecha_f))/86400;
	$dias 	= abs($dias); $dias = floor($dias);		
	return $dias;
}


$fechainc=$fi;
$numerodias=dias($fi,$ff);
for($x=0;$x<=$numerodias;$x++)
{

$sql="SELECT p.fecha, 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='$fechainc') AND p.valadmon='s' GROUP BY tipo_moneda, p.fecha order by fecha ASC";
$query=mysql_query($sql);
$pes=0;$usds=0;$concepto=$fechainc;
while($usd=mysql_fetch_array($query))
{

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"]; } 
			$usdtot=$usds+$usdtot;
			$pestot=$pes+$pestot;
}?>
		<tr>
	<td><font align="right"><?echo fechacorta($concepto);?><input type="hidden" name="concepto<?echo$x?>" id="concepto<?echo$x?>" value="<?echo$concepto?>" ></td>
	<td><font align="right"><?echo moneda($pes);?><input type="hidden" name="pes<?echo$x?>" id="pes<?echo$x?>" value="<?echo$pes?>" ></td>
	<td><font align="right"><?echo moneda($usds);?><input type="hidden" name="usds<?echo$x?>" id="usds<?echo$x?>" value="<?echo$usds?>" ></td>
		</tr>
			<?$dias=$dias.",^".fechacorta($concepto)."^";$usdxd=$usdxd.",".$usds;$pesosxd=$pesosxd.",".$pes;
			$rr=strtotime ( '+1 day' , strtotime ( $fechainc ) ) ;
			$fechainc = date ( 'Y-m-d' , $rr );
			}
			
			$d=strlen($dias);$d=$d-1;$d=substr($dias,-$d);$ixd=strlen($usdxd);$ixd=$ixd-1;$ingresoxdiausd=substr($usdxd,-$ixd);$ixdusd=strlen($pesosxd);$ixdusd=$ixdusd-1;$ingresoxdiamxn=substr($pesosxd,-$ixdusd);$ingxd="{name:^INGRESOS USD^,data:[$ingresoxdiausd]},{name:^INGRESOS MXN^,data:[$ingresoxdiamxn]}";
?>
<tr>
<td><!--Total--></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>
</tr>
<tr>
<th>Gran Total</th>
<th><?echo "MXN ".moneda($total);?><input type="hidden" name="pestot" id="pestot" value="<?echo$total?>" ></td>
<td></td>
</tr>
<!--<tr><td colspan="3"><a href="graficas/ingresoxdia.php?val=<?echo$ingxd;?>&dia=<?echo$d;?>" 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 INGRESO X DIA</font></div></a></td></tr>-->
</table>
</center>
<?
 $va=$ingxd;
 $me=$d;
 $val=str_replace("^", "'", $va);
 $meses=str_replace("^", "'", $me);
?>
<br>

<br>
		<script type="text/javascript">
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container6',
						defaultSeriesType: 'line',
						marginRight: 200,
						marginBottom: 50
					},
					title: {
						text: 'INGRESOS X DIA',
						x: -20 //center
					},
					subtitle: {
						text: 'Mexico en renta',
						x: -20
					},
					xAxis: {
						categories: [<?echo $meses;?>]
					},
					yAxis: {
						title: {
							text: 'Cantidad'
						},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: {
						line: {
							dataLabels: {
								enabled: true
							}
						}
					}
					,
					legend: {
						layout: 'vertical',
						align: 'right',
						verticalAlign: 'top',
						x: -10,
						y: 100,
						borderWidth: 1
					},
					series: [<?echo $val;?>],
				});
				
				
			});
				
		</script>
		<div id="container6" style="width: 1000px; height: 300px; margin: 0 auto"></div>
</body>
</html>		