<?php
ob_start();
session_start();
require '../../../conexion.php';
require_once('../../../include/sesiones.php');
require "../../php_qr/qrlib.php";    
require_once('../../../php_electronica/api.php');
require_once dirname(__FILE__).'../../vendor/autoload.php';

use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;

$nom_id=$_GET['nom_id'];
$query=mysqli_query($con,"SELECT *  FROM dian_nomina where nom_id='$nom_id' and empresa='$empresa' ");
$roww=mysqli_fetch_array($query);

$nom_prefijo=$roww['nom_prefijo']; 
$nom_numero=$roww['nom_numero']; 
//$observaciones=$roww['observaciones'];
$nom_emp_id=$roww['nom_emp_id'];
$dir=mysqli_query($con,"SELECT * FROM empleados where emp_id='$nom_emp_id'") or die(mysqli_error($con)); 
$dire=mysqli_fetch_array($dir);
$emp_correo=$dire['emp_correo']; 


try 
{
    ob_start();
    include(dirname('__FILE__').'/nomina/nomina.php');
    $content = ob_get_clean();

    $html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', 0);
    $html2pdf->pdf->SetDisplayMode('fullpage');
    $html2pdf->writeHTML($content);

    $pdfdoc = $html2pdf->Output('', 'S');
    $base64 = chunk_split(base64_encode($pdfdoc));
} 
catch (Html2PdfException $e) 
{
    $html2pdf->clean();
    $formatter = new ExceptionFormatter($e);
    $formatter->getHtmlMessage();
}


$json = array(
            "prefix"                        =>  $nom_prefijo,
            "consecutive"                   =>  $nom_numero,
            "email"                         =>  $emp_correo,
            "base64graphicrepresentation"   =>  $base64
);

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "{$configuration->base_url}ubl2.1/send-email-document-payroll",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>json_encode($json),
 
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'accept: application/json',
    "Authorization: Bearer {$configuration->token}"
  ),
));

$response = curl_exec($curl);
curl_close($curl);
$book=json_decode($response, true);
echo "<div class='alert alert-info alert-dismissable'<H2>"; echo $message=$book['message']; echo "</div>";

?>