<?php 

// incluye autocargador 
require_once("dompdf/dompdf_config.inc.php");

require_once "controlador/examenes.controlador.php";
require_once "modelo/examenes.modelo.php";

$codigoConsultaMedica = 1;
$tipoFicha = 0;
$numeroReceta = 2;
$codigoDoctor = 1;

$noConsulta = $_GET['noConsulta'];
$noOrden = $_GET['noOrden'];
/*
//$productos = ControladorProductos::ctrMostrarRecetas('tra_receta_medica',$consulta,$tipoFicha,$noReceta,'tra_rm_correlativo');
//$laboratorios = ControladorProductos::ctrMostrarRecetas();
$paciente = ControladorProductos::ctrMostrarPaciente('cfg_cliente',$paciente);
$medico = ControladorProductos::ctrMostrarMedico('tra_consulta_medica',$consulta);

$laboratorios = ControladorProductos::ctrMostrarLaboratorio('examenes_complementarios','LABORATORIOS_CLINICOS',$consulta,$noExamen);

*/
$contenidoHtml.='
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Orden de Trabajo</title>
  <script type="text/php">

if ( isset($pdf) ) {

  $font = Font_Metrics::get_font("sans-serif");
  $size = 6;
  $color = array(0,0,0);
  $text_height = Font_Metrics::get_font_height($font, $size);

  $foot = $pdf->open_object();
  
  $w = $pdf->get_width();
  $h = $pdf->get_height();

  // Draw a line along the bottom
  $y = $h - 2.5 * $text_height - 24;
  $pdf->line(16, $y, $w - 16, $y, array(0,0,0), 1);

  $y += $text_height;

  // Add the job number
  $text = "PBX 2229-7900 Whatsapp: 3167-7994";
  $pdf->text(16, $y, $text, $font, $size, $color);

  $pdf->close_object();
  $pdf->add_object($foot, "all");

  
  if ( !"2004-11-18 17:19:38" ) {
    // Add an initals box if the document has not already been approved
  
    global $initials;
    $initials = $pdf->open_object();
    
    $text = "Initials:";
    $width = Font_Metrics::get_text_width($text, $font, $size);
    $pdf->text($w - 16 - $width - 38, $y, $text, $font, $size, $color);
    $pdf->rectangle($w - 16 - 36, $y - 2, 36, $text_height + 4, array(0.5,0.5,0.5), 0.5);
    
        $pdf->close_object();
    $pdf->add_object($initials);

  } else {

    // Mark the document as a duplicate if has been approved
    /*$watermark = $pdf->open_object();
    $pdf->text(110, $h - 240, "DUPLICATE", Font_Metrics::get_font("verdana", "bold"),
               110, array(0.5, 0.5, 0.5), 0, 0, -52);*/

    $text = "https://therapysportsguate.org";
    $width = Font_Metrics::get_text_width($text, $font, $size);
    $pdf->text($w - 16 - $width, $y, $text, $font, $size, $color);
    
    $pdf->close_object();
    $pdf->add_object($watermark, "all");
  }

  $text = "Pagina {PAGE_NUM} de {PAGE_COUNT}";  
  $width = Font_Metrics::get_text_width("Página 1 of 2", $font, $size);

  $pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
  
}
</script>
<style>
  label{
    font-weight: bolder !important;
  }
  .borde{
    border:1px dashed #3178bc !important;
  }
</style>
</head>
<body>';
$check = '<div style="width: 13px; height: 13px;border: 1px solid #3f3f3f;background-color: #ffffff; margin: auto"></div>';

$contenidoHtml.='
  <table style="width: 100%">
    <tr>
      <th width="100%" align="center"><!--<img src="http://localhost:8888/generacionPDF/receta/logo-250.png">--></th>
    </tr>
  </table>

  <table style="border:1px dashed #3178bc !important; width: 100% !important;">
  <tr>
      <td class="label"><label>Orden de Trabajo No.:</label> 2</td>
      <td></td>
    </tr>
    <tr>
      <td class="label"><label>Nombre Paciente:</label> Marcos González</td>
      <td class="label"><label>Fecha nacimiento:</label> 29/11/1985</td>
    </tr>
    <tr>
      <td class="label"><label>Correo:</label> marcos@hotmail.com</td>
      <td class="label"><label>Edad:</label> 36 años</td>
    </tr>
    <!--<tr>
      <td class="bold" style="width: 11%"><label>Nombre Paciente:</label></td>
      <td class="field" style="width: 20%">Marcos González</td>
      <td class="label" style="width: 11%">Fecha nacimiento:</td>
      <td class="field" style="width: 9%">29/11/1985</td>
      <td class="label" style="width: 6%">Correo:</td>
      <td class="field" style="width: 17%">marcos@hotmail.com</td>
      <td class="label" style="width: 6%">Edad:</td>
      <td class="field" style="width: 11%">36 años</td>
    </tr>-->
  </table>
  <br><br>
  <table style="border: 0.5px dashed #3178bc !important; width: 100% !important;">
    <tr>
      <td class="borde" align="center"><strong>Tipo de Servicio</strong></td>
      <td class="borde" align="center"><strong>Servicio</strong></td>
      <td class="borde" align="center"><strong>Checkout</strong></td>
      <td class="borde" align="right"><strong>Monto</strong></td>
    </tr>
    <tr>
      <td class="borde">Consulta</td>
      <td class="borde">Medicina General</td>
      <td class="borde">'.$check.'</td>
      <td class="borde" align="right">Q125</td>
    </tr>
    <tr>
      <td class="borde">Laboratorio</td>
      <td class="borde">Hematología</td>
      <td class="borde">'.$check.'</td>
      <td class="borde" align="right">Q195</td>
    </tr>
    <tr>
      <td class="borde">Consulta</td>
      <td class="borde">Consulta Familiar</td>
      <td class="borde">'.$check.'</td>
      <td class="borde" align="right">Q190</td>
    </tr>
    <tr>
      <td class="borde">Laboratorio</td>
      <td class="borde">Química Glucosa Ayunas</td>
      <td class="borde">'.$check.'</td>
      <td class="borde" align="right">Q290</td>
    </tr>
    <tr>
      <td class="borde">Laboratorio</td>
      <td class="borde">Química Glucosa 2hpp</td>
      <td class="borde">'.$check.'</td>
      <td class="borde" align="right">Q250</td>
    </tr>
    <tr>
      <td class="borde">Laboratorio</td>
      <td class="borde">E.... TGP</td>
      <td class="borde">'.$check.'</td>
      <td class="borde" align="right">Q150</td>
    </tr>
    <tr>
      <td colspan="3"><br></td>
    </tr>
    <tr>
      <td colspan="2" class="borde"></td>
      <td class="borde"><strong>Copago</strong></td>
      <td class="borde" align="right">Q300</td>
    </tr>
    <tr>
      <td colspan="2" class="borde"></td>
      <td class="borde"><strong>Total Paciente</strong></td>
      <td class="borde" align="right">Q300</td>
    </tr>
    <tr>
      <td colspan="2" class="borde"></td>
      <td class="borde"><strong>Total Cliente</strong></td>
      <td class="borde" align="right">Q900</td>
    </tr>
    <tr>
      <td colspan="2" class="borde"></td>
      <td class="borde"><strong>Total General</strong></td>
      <td class="borde" align="right">Q1200</td>
    </tr>
  </table>

</body>
</html>
';

$contenidoHtml=utf8_decode($contenidoHtml);
$dompdf= new DOMPDF();
ob_start();
/*$file=file_get_contents('http://localhost:8888/generacionPDF/receta.php?consulta=4&tipoFicha=0&noReceta=1&paciente=1');
$dompdf->load_html($file)*/
$dompdf->load_html($contenidoHtml);
ini_set("memory_limit", "128M");
$dompdf->set_paper("a4", 'portrait');//portrait   landscape
$dompdf->render();
//$dompdf->stream();
$dompdf->stream("Receta.pdf", array('Attachment'=>0));
?>
