<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link rel="stylesheet" type="text/css" href="../styles/Style.css">
    <script language="JavaScript" type="text/javascript" src="js/ajax.js"></script>
  <title>DETALLE DE LA PRODUCCION</title>
      
  </script>
</head>
<body>

<?php

date_default_timezone_set('UTC');

$anno=$_GET['anno'];
$mm=$_GET['mes'];
$idtp=$_GET['idtp'];
$dni=$_GET['dni'];
$idj=$_GET['idj'];
$ids=$_GET['ids'];

include("../bd/sql_variables2.php");
$con= mysqli_connect("$sql_host", "$sql_usuario", "$sql_pass","$sql_db") or die(header ("No Disponible Servidor de Base de Datos"));
mysqli_set_charset($con, 'utf8');



//pregunta por los datos del personal
$sqlaskp = "select a.p_dni as dni, b.rp_codplanilla as codplan, concat(a.p_apepat,' ',a.p_apemat,' ',a.p_nom) as nombre from tb_personal a inner join tb_regpersonal b on a.p_dni=b.p_dni where a.p_dni ='$dni' and b.rp_estado='1'";

$resultp = mysqli_query($con, $sqlaskp);
if(mysqli_num_rows($resultp)!=0){
		while ($rowp= mysqli_fetch_array($resultp)){
		        $dni= $rowp['dni'];
				$codplan= $rowp['codplan'];					
				$nombre= $rowp['nombre'];	
		}

		$cab_tabla = "<br><table align='center' class='FacetFormTABLE'>";
	    $cab_tabla = $cab_tabla."<tr><td class='FacetFieldCaptionTL'>DNI</td><td class='FacetFieldCaptionTDT'>".$dni."</td></tr>"; 
		$cab_tabla = $cab_tabla."<tr><td class='FacetFieldCaptionTL'>COD. PLANILLA</td><td class='FacetFieldCaptionTDT'>".$codplan."</td></tr>"; 
		$cab_tabla = $cab_tabla."<tr><td class='FacetFieldCaptionTL'>PERSONAL</td><td class='FacetFieldCaptionTDT'>".$nombre."</td></tr>"; 
		$cab_tabla = $cab_tabla."</table><br>";
	
		 echo $cab_tabla."<br>";
	
//produccion en las áreas
$sqlttprod="SELECT (select a_desc from tb_area where a_id=a.a_id) as area, (select act_desc from tb_actividad where act_id=a.act_id) as actividad,  (select th_desc from tb_tipohora where th_id=a.th_id) as tipohora, sum(b.h_hrs) as nrohrs, sum(a.regp_cant) as prod, a.a_id as ida, a.act_id as idact FROM `tb_regproduccion` a inner join tb_horario b on a.h_id=b.h_id inner join tb_areaservicio c on a.a_id = c.a_id WHERE a.p_dni='".$dni."' and year(a.regp_fecha)='".$anno."' and month(a.regp_fecha)='".$mm."' and c.s_id='".$ids."' and c.j_id='".$idj."' group by a.a_id, a.act_id";
//echo $sqlttprod."<br>";
$resultprod = mysqli_query($con, $sqlttprod);
if(mysqli_num_rows($resultprod)!=0){
	 
	while ($rowprod= mysqli_fetch_array($resultprod)){
		 
		 $ida = $rowprod['ida'];
		 $idact = $rowprod['idact'];
		 $det_tabla = "<br><br><table align='center' class='FacetFormTABLE'>";
	     $det_tabla = $det_tabla."<tr><td class='FacetFieldCaptionTL'  align='center' width='160'>AREA</td><td class='FacetFieldCaptionTL' align='center' width='200'>ACTIVIDAD</td><td class='FacetFieldCaptionTL' align='center' width='70'>TIPO HORA</td><td class='FacetFieldCaptionTL' align='center' width='70'>NRO HORAS</td><td class='FacetFieldCaptionTL' align='center' width='70'>NRO PAC</td></tr>"; 
	     $det_tabla = $det_tabla."<tr><td class='FacetFieldCaptionON' align='center'>".$rowprod['area']."</td><td class='FacetFieldCaptionON' align='center'>".$rowprod['actividad']."</td><td class='FacetFieldCaptionON' align='center'>".$rowprod['tipohora']."</td><td class='FacetFieldCaptionON' align='center'>".$rowprod['nrohrs']."</td><td class='FacetFieldCaptionON' align='center'>".$rowprod['prod']."</td></tr></table>";

		 echo  $det_tabla."<br>"; 
		 
		 $sqlpac = "SELECT DATE_FORMAT(a.regp_fecha,'%d/%m/%Y') as fecha1, a.regp_fecha as fecha2, (select h_horario from tb_horario where h_id = a.h_id) as turno, (select h_hrs from tb_horario where h_id = a.h_id) as nrohrs, regp_cant as nroprod, a.h_id as idh  FROM tb_regproduccion a inner join tb_areaservicio b on a.a_id = b.a_id WHERE a.p_dni='".$dni."' and year(a.regp_fecha)='".$anno."' and month(a.regp_fecha)='".$mm."' and b.s_id='".$ids."' and b.j_id='".$idj."' and a.a_id='".$ida."' and a.act_id='".$idact."' order by fecha1 asc";
		 $resultpac = mysqli_query($con, $sqlpac);
         if(mysqli_num_rows($resultpac)!=0){
		 
		            $tablapac= "<table align='center' class='FacetFormTABLE'>";
					$tablapac= $tablapac."<tr><td class='FacetFieldCaptionTL' align='center' width='90'>FECHA</td><td class='FacetFieldCaptionTL' align='center' width='80'>TURNO</td><td class='FacetFieldCaptionTL' align='center' width='60'>NRO HRS</td><td class='FacetFieldCaptionTL' align='center' width='70'>PRODUCCION</td><td class='FacetFieldCaptionTL'  align='center' width='80'>DNI PAC</td><td class='FacetFieldCaptionTL' align='center' width='220'>PACIENTE</td></tr>";
					
				while ($rowpac= mysqli_fetch_array($resultpac)){
					$nfilas = $rowpac['nroprod'];
					$fecha = $rowpac['fecha2'];
					$idh = $rowpac['idh'];
					$tablapac= $tablapac."<tr><td rowspan='".$nfilas."' class='FacetFieldCaptionON' align='center' >".$rowpac['fecha1']."</td><td rowspan='".$nfilas."' class='FacetFieldCaptionON' align='center' >".$rowpac['turno']."</td><td rowspan='".$nfilas."' class='FacetFieldCaptionON' align='center' >".$rowpac['nrohrs']."</td><td rowspan='".$nfilas."' class='FacetFieldCaptionON' align='center' >".$rowpac['nroprod']."</td>";
					
					$sql_dp = "SELECT a.pac_dni as dni, (select pac_nombre from tb_paciente where pac_dni=a.pac_dni) as paciente FROM tb_atencionpac a WHERE a.regp_fecha='".$fecha."'  and a.p_dni='".$dni."' and a.h_id='".$idh."' order by paciente asc";
					//echo $sql_dp."<br>";
					 $result_dp = mysqli_query($con, $sql_dp);
					              
						if(mysqli_num_rows($result_dp)!=0){
						while ($row_dp= mysqli_fetch_array($result_dp)){
					     $tablapac = $tablapac ."<td class='FacetFieldCaptionON' align='center' >".$row_dp['dni']."</td><td class='FacetFieldCaptionON' >".utf8_decode($row_dp['paciente'])."</td></tr>";
						}
						}
			    }
				 $tablapac= $tablapac."</table>";
				 
				echo $tablapac."<br>";
			}
		}
		 
		}

}

?>

</body>
</html>