<?php
require_once ('../librerias/dompdf/autoload.inc.php');
use Dompdf\Dompdf;

$url2 = 'http://200.24.13.60/~program1/power-time-api/public/obtenerpersona';
$ch2 = curl_init($url2); //create a new cURL resource
$payload2 = json_encode(array('id' => $_POST["txtId_persona"]));
curl_setopt($ch2, CURLOPT_POSTFIELDS, $payload2);//attach encoded JSON string to the POST fields
curl_setopt($ch2, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); //set the content type to application/json
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); //return response instead of outputting
$result2 = curl_exec($ch2); //execute the POST request
$array2 = json_decode($result2);

$nombrePersona = $array2[0]->nombre ." ". $array2[0]->apellido;
$rut = $array2[0]->rut;
curl_close($ch2);

/***************************************************/

$ch3 = curl_init('http://200.24.13.60/~program1/power-time-api/public/obtenercargoasignado'); //create a new cURL resource
$payload3 = json_encode(array('id_persona' => $_POST["txtId_persona"]));
curl_setopt($ch3, CURLOPT_POSTFIELDS, $payload3);//attach encoded JSON string to the POST fields
curl_setopt($ch3, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); //set the content type to application/json
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true); //return response instead of outputting
$result3 = curl_exec($ch3); //execute the POST request
$array3 = json_decode($result3);

 
$cargo = $array3[0]->descripcion;			

curl_close($ch3); 	

/***********************************************************************/

$ch4 = curl_init('http://200.24.13.60/~program1/power-time-api/public/obtenerdepartamentoasignado'); //create a new cURL resource
$payload4 = json_encode(array('id_persona' => $_POST["txtId_persona"]));
curl_setopt($ch4, CURLOPT_POSTFIELDS, $payload4);//attach encoded JSON string to the POST fields
curl_setopt($ch4, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); //set the content type to application/json
curl_setopt($ch4, CURLOPT_RETURNTRANSFER, true); //return response instead of outputting
$result4 = curl_exec($ch4); //execute the POST request
$array4 = json_decode($result4);

$cargoHTML = "";				
foreach ($array4[0] as $row) {
	$cargoHTML .= "<tr>";			
	$cargoHTML .= "<td>".STRTOUPPER($row->sucursal) ."</td>";		
	$cargoHTML .= "<td>".STRTOUPPER($row->descripcion) ."</td>";		
	$cargoHTML .= "</tr>";		
}
 		 

curl_close($ch4); 	
			
/***************************************************/


$ch4 = curl_init('http://200.24.13.60/~program1/power-time-api/public/turnopersona'); //create a new cURL resource
$payload4 = json_encode(array('id_persona' => $_POST["txtId_persona"]));
curl_setopt($ch4, CURLOPT_POSTFIELDS, $payload4);//attach encoded JSON string to the POST fields
curl_setopt($ch4, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); //set the content type to application/json
curl_setopt($ch4, CURLOPT_RETURNTRANSFER, true); //return response instead of outputting
$result4 = curl_exec($ch4); //execute the POST request
$array4 = json_decode($result4);

$turnoHTML = "";				
foreach ($array4[0] as $row) {
	$turnoHTML .= "<tr>";			
	$turnoHTML .= "<td>".STRTOUPPER($row->descripcion) ."</td>";		
	$turnoHTML .= "</tr>";		
}
 		 

curl_close($ch4); 	
			
/***************************************************/


$ch4 = curl_init('http://200.24.13.60/~program1/power-time-api/public/informehoraextratrabajador'); //create a new cURL resource
$payload4 = json_encode(array(
'id_persona' => $_POST["txtId_persona"],
'fecha_inicio' => $_POST["txtFecha_inicio_permiso"],
'fecha_termino' => $_POST["txtFecha_termino_permiso"]
));
curl_setopt($ch4, CURLOPT_POSTFIELDS, $payload4);//attach encoded JSON string to the POST fields
curl_setopt($ch4, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); //set the content type to application/json
curl_setopt($ch4, CURLOPT_RETURNTRANSFER, true); //return response instead of outputting
$result4 = curl_exec($ch4); //execute the POST request
$array4 = json_decode($result4);

$permisoHTML = "";				
foreach ($array4[0] as $row) {
	$permisoHTML .= "<tr>";			
	$permisoHTML .= "<td>".$row->fecha ."</td>";	
	$permisoHTML .= "<td>".$row->cantidad ."</td>";			
	$permisoHTML .= "</tr>";		
}
 		 

curl_close($ch4); 	
			
/***************************************************/
				
$html = '
<style>
body{
	font-size:10px;
}
h3{
	font-size:20px;
	display:inline;
}
h4{
	font-size:14px;
	display:inline;	
}
#folio{
	border: solid 3px #000000;
	text-align:center;
	padding: 10px;
}
.tbl-marcaje{
	text-align: center;
}
.tbl-marcaje th {
  color: #000000;
  background-color: #CCCCCC;
  border:solid 1px #000000;
}
.tbl-marcaje td {
	border:solid 1px #000000;
}
.tbl-marcaje2{
	text-align: left;
}
.tbl-marcaje2 th {
  color: #000000;
  background-color: #CCCCCC;
  border:solid 1px #000000;
}
.tbl-marcaje2 td {
	border:solid 1px #000000;
}	
</style>
<div>
	<img style="max-height:50px;" src="../img/002.png" />
</div> 
<table width="100%">
	<tr>
		<td width="70%"><b>COMPA&Ntilde;IA :</b> CORP MUNICIPAL PARA EL DESARROLLO SOCIAL</td>	
	    <td><b>PERIODO DESDE :</b> '. $_POST["txtFecha_inicio_permiso"] .'</td>			
	</tr>
	<tr>		
		<td width="70%"><b>RUT :</b> 70.983.600-5</td>	
	<td><b>PERIODO HASTA :</b> '. $_POST["txtFecha_termino_permiso"] .'</td>			
	</tr>	
</table><br /> 

		
<center><h3>Reporte Horas Extra Trabajador</h3></center>
<br /> 	
<h4>Trabajador:</h4>
<table class="tbl-marcaje" width="100%">
	<tr>
		<th width="30%"><b>RUT </b></th>
		<th><b>NOMBRE </b></th>	
		<th><b>CARGO </b></th>			
	</tr>
	<tr>
		<td>'.$rut.'</td>		
		<td>'.$nombrePersona.'</td>	
		<td>'.$cargo.'</td>			
	</tr>			
</table>  
<br /> 	
<h4>Informaci&oacute;n de Turno Laboral:</h4>
<table class="tbl-marcaje" width="30%">
	<tr>
		<th><b>TURNO </b></th>			
	</tr>
	'.$turnoHTML.'		
		
</table>  
<br /> 	
<h4>Sucursal / Departamento:</h4> 
<table class="tbl-marcaje" width="100%">
	<tr>
		<th width="30%"><b>SUCURSAL </b></th>
		<th><b>DEPARTAMENTO </b></th>			
	</tr>
	'.$cargoHTML.'		
		
</table>   
<br /> 	
<h4>Listado de Horas Extras Trabajador:</h4>
<table class="tbl-marcaje" width="100%">
	<tr>
		<th><b>FECHA </b></th>
		<th><b>CANTIDAD </b></th>	
		
	</tr>
	'.$permisoHTML.'		
		
</table>  


';

$pdf = new DOMPDF();
$pdf->set_paper("A4", "portrait");
$pdf->load_html(utf8_encode($html));
$pdf->render();
$pdf->stream("marcajes.pdf", array("Attachment" => false));
exit(0);

?>
