<?php session_start();
//Refrescar Automaticamente la pagina..
    
    $self = $_SERVER['PHP_SELF']; //Obtenemos la página en la que nos encontramos
	header("refresh:3600; url=$self"); //Refrescamos cada 300 segundos
	require ("conexion.php");
	$today = date("Y-m-d");
	//$sql = mysqli_query($enlace,"SELECT usuario_nombre FROM usuarios");//Este es el script SQL que necesitas para jalar el ultimo registro
	$Perfil=$_SESSION['Perfil'];
	if (isset($_SESSION['usuario_nombre'])) {	
		  if ($Perfil==1 or $Perfil==2){
?>

<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8" />
<title>Indicadores Remanufactura y Pintura</title>
</head> 

<h1>Resumen de Indicadores de Gestion Sobre Pintura y remanufacturados al dia <?php echo $today; ?></h1>
<p><a href="index.php">&lt;&lt; Regresar</a></p>
<table border='1' align='left'>
<caption><h2><B>Cantidad de Pedidos</B></h2></caption>
	<?php
		//Invocamos el archivo de conexión
		//Cantidad de Pedidos
		echo "<tr>";
		//Registros Totales
			echo "<td>";
				echo "<table border='1' align='left'>";
					echo "<tr>";
						echo "<td>";
							$result1 = mysqli_query($enlace, "SELECT COUNT(*) as TotalRegistros FROM unicuadro");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Registros Totales</b></td>";
								echo "</tr>";
								while ($row = mysqli_fetch_array($result1)){
									echo "<tr>";
										echo "<td>".$row['TotalRegistros']."</td>";
									echo "</tr>";
									}
							echo "</table>";
						echo "</td>";
		//Ordenes Cumplidas
						echo "<td>";
							$result2 = mysqli_query($enlace, "SELECT COUNT(pedido) as Cumplidas FROM unicuadro where Fecha_EA_Almacen<=Fecha_EA_Pintura");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Ordenes Cumplidas</b></td>";
								echo "</tr>";
							while ($row = mysqli_fetch_array($result2)){
								echo "<tr>";
								echo "<td>".$row['Cumplidas']."</td>";
								echo "</tr>";
									}
							echo "</table>";
						echo "</td>";
		//Ordenes En Proceso
						echo "<td>";
							$result4 = mysqli_query($enlace, "SELECT COUNT(Pedido) as Proceso FROM unicuadro where isnull(Fecha_EA_Almacen) and Fecha_EA_Pintura>'$today'");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Ordenes En Proceso</b></td>";
								echo "</tr>";
							while ($row = mysqli_fetch_array($result4)){
								echo "<tr>";
									echo "<td>".$row['Proceso']."</td>";
								echo "</tr>";
									}
							echo "</table>";

						echo "</td>";
		//Ordenes no Cumplidas
						echo "<td>";
							$result3 = mysqli_query($enlace, "SELECT COUNT(Pedido) as NoCumplidas FROM unicuadro where Fecha_EA_Pintura<=Fecha_EA_Almacen");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Ordenes no Cumplidas</b></td>";
								echo "</tr>";
							while ($row = mysqli_fetch_array($result3)){
								echo "<tr>";
									echo "<td>".$row['NoCumplidas']."</td>";
								echo "</tr>";
								}
							echo "</table>";

						echo "</td>";
		//Ordenes Vencidas
						echo "<td>";
							$result4 = mysqli_query($enlace, "SELECT COUNT(Pedido) as vencidas FROM unicuadro where isnull(Fecha_EA_Almacen) and Fecha_EA_Pintura<'$today'");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Ordenes Vencidas</b></td>";
								echo "</tr>";
							while ($row = mysqli_fetch_array($result4)){
								echo "<tr>";
									echo "<td>".$row['vencidas']."</td>";
								echo "</tr>";
								}
							echo "</table>";
						echo "</td>";
		//Ordenes no Asignadas
						echo "<td>";
							$result5 = mysqli_query($enlace, "SELECT COUNT(Pedido) as NoAsignadas FROM unicuadro where isnull(Fecha_EA_Pintura) ");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Ordenes no Asignadas</b></td>";
								echo "</tr>";
							while ($row = mysqli_fetch_array($result5)){
								echo "<tr>";
									echo "<td>".$row['NoAsignadas']."</td>";
								echo "</tr>";
								}
							echo "</table>";
					echo "</tr>";
				echo "</table>";		
			echo "</td>";
		echo "</tr>";
	?>
</table>

<br>
<br>

<table border='1' align='left'>	
<caption><h2>Relacion de Pedidos </h2> </caption>
	<?php

				
	echo "<tr>";
		echo "<td>";
			echo "<table border='1' align='left'>";
				echo "<tr>";
					echo "<td>";
						$result1 = mysqli_query($enlace, "SELECT pedido FROM unicuadro order by pedido desc");
							echo "<table border='1' align='left'>";
							echo "<tr bgcolor='#CCCCCC'>";
								echo "<td><b><a href='unicuadro.php'>Pedidos Totales</a></b></td>";
							echo "</tr>";
							while ($row = mysqli_fetch_array($result1)){
								echo "<tr>";
									echo "<td>".$row['pedido']."</td>";
								echo "</tr>";
								}
							echo "</table>";
					echo "</td>";
					echo "<td>";
						$result2 = mysqli_query($enlace, "SELECT pedido FROM unicuadro where Fecha_EA_Pintura>=Fecha_EA_Almacen order by pedido desc");
							echo "<table border='1' align='Center'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Pedidos Cumplidos</b></td>";
								echo "</tr>";
							while ($row = mysqli_fetch_array($result2)){
								echo "<tr>";
									echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
								echo "</tr>";
								}
							echo "</table>";
					echo "</td>";
					echo "<td>";
						$result4 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where isnull(Fecha_EA_Almacen) and Fecha_EA_Pintura>'$today' order by pedido desc");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Pedidos En Proceso</b></td>";
								echo "</tr>";
							while ($row = mysqli_fetch_array($result4)){
								echo "<tr>";
									echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
								echo "</tr>";
								}
							echo "</table>";
					echo "</td>";
					echo "<td>";
						$result3 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where Fecha_EA_Pintura<Fecha_EA_Almacen order by pedido desc");
						echo "<table border='1' align='left'>";
							echo "<tr bgcolor='#CCCCCC'>";
							echo "<td><b>Pedidos no Cumplidas</b></td>";
							echo "</tr>";
								while ($row = mysqli_fetch_array($result3)){
									echo "<tr>";
										echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
									echo "</tr>";
								}
						echo "</table>";
					echo "</td>";
					echo "<td>";
						$result4 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where isnull(Fecha_EA_Almacen) and Fecha_EA_Pintura<'$today' order by pedido desc");
						echo "<table border='1' align='left'>";
							echo "<tr bgcolor='#CCCCCC'>";
							echo "<td><b>Pedidos Vencidos</b></td>";
							echo "</tr>";
								while ($row = mysqli_fetch_array($result4)){
								echo "<tr>";
									echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
								echo "</tr>";
								}	
						echo "</table>";
					echo "</td>";
					echo "<td>";
						$result5 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where isnull(Fecha_EA_Pintura) order by pedido desc");
						echo "<table border='1' align='left'>";
							echo "<tr bgcolor='#CCCCCC'>";
								echo "<td><b>Pedidos no Asignados</b></td>";
							echo "</tr>";
								while ($row = mysqli_fetch_array($result5)){
								echo "<tr>";
									echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
								echo "</tr>";
								}
						echo "</table>";
					echo "</td>";
				echo "</tr>";
			echo "</table>";		
		echo "</td>";
	echo "</tr>";
?>
</table>	

<table border='1' align='left'>	
<caption><h2>Pedidos Pintura</h2> </caption>

<?php
	
			//Pedidos Pintura
				//Tabla3
	echo "<tr>";
		echo "<td>";
			echo "<table border='1' align='left'>";
				echo "<tr>";
					echo "<td>";
						$result1 = mysqli_query($enlace, "SELECT pedido FROM unicuadro where Responsable = 'Pintura' order by pedido desc");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Pedidos Pintura</b></td>";
								echo "</tr>";
								while ($row = mysqli_fetch_array($result1)){
								echo "<tr>";
									echo "<td>".$row['pedido']."</td>";
								echo "</tr>";
									}
							echo "</table>";
					echo "</td>";
					echo "<td>";
						$result2 = mysqli_query($enlace, "SELECT pedido FROM unicuadro where Fecha_EA_Pintura>=Fecha_EA_Almacen and Responsable = 'Pintura' order by pedido desc");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Cumple Pintura</b></td>";
								echo "</tr>";
								while ($row = mysqli_fetch_array($result2)){
									echo "<tr>";
										echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
									echo "</tr>";
									}
							echo "</table>";
					echo "</td>";
					echo "<td>";
						$result4 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where isnull(Fecha_EA_Almacen) and Fecha_EA_Pintura>'$today' and Responsable = 'Pintura' order by pedido desc");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>En Proceso Pintura</b></td>";
								echo "</tr>";
								while ($row = mysqli_fetch_array($result4)){
									echo "<tr>";
										echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
									echo "</tr>";
									}
							echo "</table>";
					echo "</td>";
					echo "<td>";
						$result3 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where Fecha_EA_Pintura<Fecha_EA_Almacen and Responsable = 'Pintura' order by pedido desc");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>No Cumplidas Pintura</b></td>";
								echo "</tr>";
								while ($row = mysqli_fetch_array($result3)){
									echo "<tr>";
										echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
									echo "</tr>";
									}
							echo "</table>";
					echo "</td>";
					echo "<td>";
						$result4 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where isnull(Fecha_EA_Almacen) and Fecha_EA_Pintura<'$today' and Responsable = 'Pintura' order by pedido desc");
							echo "<table border='1' align='left'>";
								echo "<tr bgcolor='#CCCCCC'>";
									echo "<td><b>Vencidos Pintura</b></td>";
								echo "</tr>";
								while ($row = mysqli_fetch_array($result4)){
									echo "<tr>";
										echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
									echo "</tr>";
									}	
							echo "</table>";
					echo "</td>";
				echo "</tr>";
			echo "</table>";		
		echo "</td>";
	echo "</tr>";


?>
</table>


<table border='1' align='left'>	
<caption><h2>Pedidos Remanufactura</h2> </caption>

<?php
	echo "<tr>";
		echo "<td>";
			echo "<table border='1' align='left'>";
//Fila4
echo "<tr>";
echo "<td>";
//Pedidos Pintura
	$result1 = mysqli_query($enlace, "SELECT pedido FROM unicuadro where Responsable = 'Remanufactura' order by pedido desc");
	echo "<table border='1' align='left'>";
		echo "<tr bgcolor='#CCCCCC'>";
		echo "<td><b>Pedidos Remanufactura</b></td>";
		echo "</tr>";
		while ($row = mysqli_fetch_array($result1)){
			echo "<tr>";
			echo "<td>".$row['pedido']."</td>";
			echo "</tr>";
		}
	echo "</table>";

echo "</td>";
//Pedidos Cumplidos
echo "<td>";
	$result2 = mysqli_query($enlace, "SELECT pedido FROM unicuadro where Fecha_EA_Pintura>=Fecha_EA_Almacen and Responsable = 'Remanufactura' order by pedido desc");
	echo "<table border='1' align='left'>";
		echo "<tr bgcolor='#CCCCCC'>";
		echo "<td><b>Cumple Remanufactura</b></td>";
		echo "</tr>";
		while ($row = mysqli_fetch_array($result2)){
			echo "<tr>";
			echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
			echo "</tr>";
		}
	echo "</table>";
echo "</td>";

echo "<td>";
	$result4 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where isnull(Fecha_EA_Almacen) and Fecha_EA_Pintura>'$today' and Responsable = 'Remanufactura' order by pedido desc");
	echo "<table border='1' align='left'>";
		echo "<tr bgcolor='#CCCCCC'>";
		echo "<td><b>En Proceso Remanufactura</b></td>";
		echo "</tr>";
		while ($row = mysqli_fetch_array($result4)){
			echo "<tr>";
			echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
			echo "</tr>";
		}
	echo "</table>";

echo "</td>";
echo "<td>";
	$result3 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where Fecha_EA_Pintura<Fecha_EA_Almacen and Responsable = 'Remanufactura' order by pedido desc");
	echo "<table border='1' align='left'>";
		echo "<tr bgcolor='#CCCCCC'>";
		echo "<td><b>No Cumplidas Remanufactura</b></td>";
		echo "</tr>";
		while ($row = mysqli_fetch_array($result3)){
			echo "<tr>";
			echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
			echo "</tr>";
		}
	echo "</table>";

echo "</td>";
echo "<td>";
	$result4 = mysqli_query($enlace, "SELECT Pedido FROM unicuadro where isnull(Fecha_EA_Almacen) and Fecha_EA_Pintura<'$today' and Responsable = 'Remanufactura' order by pedido desc");
	echo "<table border='1' align='left'>";
	echo "<tr bgcolor='#CCCCCC'>";
	echo "<td><b>Vencidos Remanufactura</b></td>";
	echo "</tr>";
	while ($row = mysqli_fetch_array($result4)){
		echo "<tr>";
		echo "<td><a href='UnicuadroSeleccion.php?Pedido=".$row['pedido']."'>".$row['pedido']."</td>";
		echo "</tr>";
	}	
	echo "</table>";
echo "</td>";

			echo "</table>";		
		echo "</td>";
	echo "</tr>";


// mysqli_close() es el evivalente a mysql_close() sirve para finalizar la conexión.
mysqli_close($enlace);


$FECHAOLD=$_SESSION['UltimoIngreso'];
$HORA=date('Y-n-j H:i:s');

$tiempo=(strtotime($HORA) - strtotime($FECHAOLD));

if($tiempo>=600){
	session_destroy();
	echo '<script language=javascript> alert ("su session a sido caducada por su seguridad, por favor ingrese nuevamente.") self.location="index.php"</script>';
	}else{
	$_SESSION['UltimoIngreso']=$HORA;
	}
?>
</table>


</html>

<?php
}else{
        echo 'El usuario no tiene los permisos suficientes para acceder a la web';
         mysqli_close($enlace); //Cerramos la conexion a la db
    }
}
else{
echo 'El usuario no tiene acceso a esta pagina web comuniquese con el administrador del sistema';
 mysqli_close($enlace); //Cerramos la conexion a la db
}
?>