<?php
//============================================================+
// File name   : example_012.php
// Begin       : 2008-03-04
// Last Update : 2013-05-14
//
// Description : Example 012 for TCPDF class
//               Graphic Functions
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com LTD
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Graphic Functions
 * @author Nicola Asuni
 * @since 2008-03-04
 */
header("Content-Type:text/html;charset=utf-8");
// Incluir librerias de datos
include_once('../php_conexion.php');
include_once('../Class/funciones.php');
$idpac=$_GET['idpac'];
//$acumulado=0;
$queryinfpac=mysqli_query($conexion,"SELECT * FROM paciente WHERE idpaciente=$idpac ORDER BY idpaciente DESC LIMIT 1");
$datainfpac=mysqli_fetch_array($queryinfpac);
/*$querycaja=mysqli_query($conexion,"SELECT importe FROM caja WHERE idpaciente=$idpac");
while ($rowcaja=mysqli_fetch_array($querycaja)) {
    $acumulado+=$rowcaja['importe'];
}*/
$meses = array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
if ($datainfpac['tipodoc']=="dni"){
    $tipodoc="DNI";
}elseif ($datainfpac['tipodoc']=="ce") {
    $tipodoc="Carnet de extranjeria";
}elseif($datainfpac['tipodoc']=="pas") {
    $tipodoc="Pasaporte";
}

// Include the main TCPDF library (search for installation path).
require_once('../tcpdf/tcpdf.php');

// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file = 'logoumsomd.png';
        $this->Image($image_file, 12, 6, 45, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Position at 15 mm from bottom
        //$this->SetY(25);
        // Set font
        //$this->SetFont('times', 'BI', 20);
        // Title
        //$this->Cell(0, 10, 'Informe Citológico', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-10);
        // Set font
        $this->SetFont('helvetica', 'I', 10);
        // set color for background
		$this->SetFillColor(193, 274, 255);
        // Page number
        //$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
        $this->Cell(0, 5, 'CONSULTORIO: AV. MICAELA BASTIDAS Nº443 EDIFICIO EL ROBLE OF. Nº 801 TELF: 084-248494', 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

//establecer margenes
//$pdf->SetMargins(5,5,10);
$pdf->setHeaderMargin(10);
$pdf->SetFooterMargin(0);
$pdf->setPrintFooter(false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Jose HUiñapi');
$pdf->SetTitle('CONSENTIMIENTO INFORMADO');
$pdf->SetSubject('Paciente');
$pdf->SetKeywords('Consentimiento, PDF, Paciente');

// set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// disable header and footer
//$pdf->setPrintHeader(false);
//$pdf->setPrintFooter(false);

// CONJUNTO CABESERA Y PIE DE PAGINA

    $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', 'B', 16);
// add page
$pdf->AddPage('P','A4');

//ESTILOS PARA GRAFICOS
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '3,3,3,3', 'phase' => 10, 'color' => array(0, 0, 0));
$style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0));
$style3 = array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0));
$style4 = array('L' => 0,
                'T' => array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => array(100, 100, 255)),
                'R' => array('width' => 0.50, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => array(50, 50, 127)),
                'B' => array('width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10'));
$style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128));
$style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,10', 'color' => array(0, 128, 0));
$style7 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 128, 0));

//$txt = <<<EOD
//CONSULTORIO DE ANATOMIA PATOLOGICA Y CITOLOGIA
//EOD;

//$pdf->SetY(15);
//$pdf->Write(1, $txt, '', 0, 'C', true, 0, false, false, 0);

//Titulo
$pdf->Write(0, 'HOJA DE RUTA', '', 0, 'C', true, 0, false, false, 0);
$pdf->Write(0, 'EXAMEN MEDICO DE DESCARTE COVID-19', '', 0, 'C', true, 0, false, false, 0);
$pdf->Write(0, $datainfpac['empresa'], '', 0, 'C', true, 0, false, false, 0);

$pdf->SetFont('times', 'B', 12);
//Cuerpo
$html='<table border="1"><tr><td style="width:15%"> NOMBRES:</td><td colspan="2" style="width:55%"> <b>'.$datainfpac['apepaterno'].' '.$datainfpac['apematerno'].' '.$datainfpac['nombre'].'</b></td><td style="width:15%"> EDAD:</td><td style="width:15%"> <b>'.calculaedad($datainfpac['fechanac']).' años</b></td></tr><tr><td> PUESTO:</td><td colspan="4"> <b>'.$datainfpac['puesto'].'</b></td></tr><tr><td> Fecha:</td><td> <b>'.$datainfpac['fecha'].'</b></td><td> DNI:</td><td colspan="2"> <b>'.$datainfpac['numdoc'].'</b></td></tr><tr><td> Telefono:</td><td> <b>'.$datainfpac['telefono'].'</b></td><td> Fecha de nacimiento:</td><td colspan="2"> <b>'.$datainfpac['fechanac'].'</b></td></tr><tr><td> Correo electronico:</td><td colspan="4"> <b>'.$datainfpac['email'].'</b></td></tr><tr><td> Direccion:</td><td colspan="4"> <b>'.$datainfpac['direccion'].'</b></td></tr><tr><td colspan="5"></td></tr><tr><td colspan="2"> SERVICIO</td><td> Méd/Espec/Téc</td><td> Inicio</td><td> Fin</td></tr><tr><td colspan="2"> LABORATORIO:</td><td></td><td></td><td></td></tr><tr><td colspan="5"> SERVICIO CON PUEBA COVID-19</td></tr><tr><td colspan="2"> MEDICINA:</td><td></td><td></td><td></td></tr><tr><td colspan="5"> EVALUACION MEDICA</td></tr><tr><td colspan="5" style="text-align:center;"> TRIAJE</td></tr><tr><td> Peso:</td><td> Talla:</td><td colspan="2"> Indice de masa corporal (IMC)</td><td></td></tr><tr><td colspan="5"> IMC: Normal de 18.5 a &lt; 25, Bajo peso &lt; 18.5, Sobrepeso de 25 a &lt; 30, Obesidad &gt; =30</td></tr><tr><td rowspan="2"> Perimetro toraxico</td><td> Inspiración</td><td></td><td> FR</td><td></td></tr><tr><td> Espiracion</td><td></td><td> T°</td><td></td></tr><tr><td rowspan="3"> Perímetro abdominal</td><td> Cintura</td><td></td><td> Sat O2</td><td></td></tr><tr><td> Cadera</td><td></td><td> FC</td><td></td></tr><tr><td > Abdomen</td><td></td><td> PA</td><td></td></tr></table>';

$pdf->SetFont('times', '', 14);
$pdf->writeHTML($html, true, 0, true, true);

// set cell padding
/*$pdf->setCellPaddings(0, 0, 0, 0);

// set cell margins
$pdf->setCellMargins(0, 1, 0, 1);
$pdf->SetFillColor(255,255,255);
$pdf->SetTextColor(0,0,0);
//TITULO
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->SetXY(0, 10);
$pdf->MultiCell(0, 3, 'CONSULTORIO DE ANATOMIA PATOLOGICA Y CITOLOGICA', 0, 'C', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetXY(0, 15);
$pdf->MultiCell(140, 3, 'Dr. David Acurio Zárate', 0, 'C', 1, 0, '', '', true, 0, true, true, 40, 'T');


$pdf->SetXY(13, 45);
$pdf->MultiCell(40, 3, 'FECHA: ', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
$pdf->MultiCell(100, 3, ': '.$datainfpac['fechareg'].' | '.date("g:i a"), 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->MultiCell(28, 3, 'Codigo Nº', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
$pdf->Cell(20, 0, ': '.str_pad($datainfpac['codpaciente'], 6, "0", STR_PAD_LEFT), 0, 1, 'L', 0, '', 1);

//DATOS DEL PACIENTE
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->SetXY(13, 55);
$pdf->MultiCell(40, 3, 'CLIENTE', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
$pdf->MultiCell(100, 3, ': '.$datainfpac['apepaterno'].' '.$datainfpac['apematerno'].' '.$datainfpac['nombres'], 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->MultiCell(28, 3, $tipodoc, 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
$pdf->MultiCell(25, 3, ': '.$datainfpac['numdoc'], 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(13, 65);
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->MultiCell(40, 3, 'DIRECCION', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
$pdf->MultiCell(140, 3, ': '.$datainfpac['direccion'], 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');

//DATOS DE EXAMEN
$pdf->SetXY(13, 85);
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->MultiCell(40, 3, 'FECHA DE ENTREGA', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
$pdf->MultiCell(140, 3, ': '.$datainfpac['fechaentrega'], 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(13, 95);
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->MultiCell(40, 3, 'TOTAL', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
$pdf->MultiCell(140, 3, ': S/.'.sprintf("%01.2f",$datainfpac['precioexamen']), 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(13, 105);
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->MultiCell(40, 3, 'A CUENTA', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
$pdf->MultiCell(140, 3, ': S/.'.sprintf("%01.2f",$acumulado), 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(13, 115);
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->MultiCell(40, 3, 'SALDO', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 10);
if ($acumulado!=0) {
    $saldo=sprintf("%01.2f",($datainfpac['precioexamen']-$acumulado));
}else{
    $saldo=sprintf("%01.2f",0);
}
$pdf->MultiCell(140, 3, ': S/.'.$saldo, 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(13, 125);
$pdf->SetFont('helvetica', 'BI', 10);
$pdf->MultiCell(185, 3, 'USUARIO', 0, 'R', 1, 0, '', '', true, 0, true, true, 40, 'T');

//PIE DE PAGINA
$pdf->SetFont('helvetica', 'I', 10);
$pdf->SetXY(13, 135);
$pdf->MultiCell(180, 3, 'CONSULTORIO: AV. MICAELA BASTIDAS Nº443 EDIFICIO EL ROBLE OF. Nº 801 TELF: 084-248494', 0, 'C', 1, 0, '', '', true, 0, true, true, 40, 'T');
//LINEA
$pdf->Line(5, 148, 205, 148, $style);*/

mysqli_close($conexion);
// ---------------------------------------------------------
// move pointer to last page
$pdf->lastPage();

//Close and output PDF document
$pdf->Output($datainfpac['numdoc'].'-'.$datainfpac['apepaterno'].' '.$datainfpac['apematerno'].' '.$datainfpac['nombre'].'.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+
?>
