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


$ch4 = curl_init('http://200.24.13.60/~program1/power-time-api/public/informeturno'); //create a new cURL resource
$payload4 = json_encode(array(
'id_sucursal' => $_POST["txtSucursal"], 
'id_departamento' => $_POST["txtDepartamento"] 
));
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);

$personaHTML = "";				
foreach ($array4[0] as $row) {
	$personaHTML .= "<tr>";				
	$personaHTML .= "<td>".$row->rut."</td>";		
	$personaHTML .= "<td>".STRTOUPPER($row->nombre ." ".$row->apellido) ."</td>";	
	$personaHTML .= "<td>".STRTOUPPER($row->sucursal) ."</td>";	
	$personaHTML .= "<td>".STRTOUPPER($row->departamento) ."</td>";	
	$personaHTML .= "<td>".STRTOUPPER($row->turno) ."</td>";		
	$personaHTML .= "</tr>";		
}
 		 

curl_close($ch4); 	

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

$ch4 = curl_init('http://200.24.13.60/~program1/power-time-api/public/informeturnocantidad'); //create a new cURL resource
$payload4 = json_encode(array(
'id_sucursal' => $_POST["txtSucursal"], 
'id_departamento' => $_POST["txtDepartamento"] 
));
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);

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

curl_close($ch4); 	
				
$html = '
<style>
body{
	font-size:10px;
}
h3{
	font-size:20px;
	display:inline;
}
h4{
	font-size:14px;
	display:inline;	
}
.tbl-marcaje th {
  color: #000000;
  background-color: #CCCCCC;
  border:solid 1px #000000;
}
.tbl-marcaje 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>					
	</tr>
	<tr>		
		<td width="70%"><b>RUT :</b> 70.983.600-5</td>				
	</tr>	
</table><br />
<center><h3>Informe De Turnos</h3></center>
<br /> 
<h4>Listado de Trabajadores:</h4>
<table class="tbl-marcaje" width="100%">
	<tr>
		<th><b>RUT </b></th>			
		<th><b>TRABAJADOR </b></th>
		<th><b>SUCURSAL </b></th>	
		<th><b>DEPARTAMENTO </b></th>	
		<th><b>TURNO </b></th>			
	</tr>
	'.$personaHTML.'			
</table>  
<br /> 
<br /> 
<h4>Total de Trabajadores por Turno:</h4>
<table class="tbl-marcaje" width="100%">
	<tr>
		<th><b>TURNO </b></th>		 	
		<th><b>TOTAL </b></th>			
	</tr>
	'.$cantidadHTML.'			
</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);

?>
