<?php
include_once '../../librerias/tcpdf/tcpdf.php';
include_once '../../conexion.php';

$sql = "select *,(select numero_letras(pres_total)) "
        . "as total_letra "
      . " from v_servicios_presupuesto where id_presu = " . 
        $_REQUEST ['vcod'] . " order by 1";
$rs = consultas::get_datos($sql);


// create new PDF document
$pdf = new TCPDF('P', 'mm', 'A4');
$pdf->SetMargins(15, 15, 18);
$pdf->SetTitle('PRESUPUESTO');
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);

$pdf->AddPage();

$pdf->Ln(5);
$pdf->SetFont('Times', 'B', 18);
$pdf->Cell(85, 1, 'FARMMEDI', 0, 0, 'C',null,null,1);
$pdf->SetFont('Times', 'B', 12);
$pdf->Cell(85, 1, 'SERVICIOS Y SEGURIDAD', 0, 0, 'C');
$pdf->Ln(10);
$pdf->SetFont('Times', '', 12);
$pdf->Cell(85, 1, 'Dirección: Calle Prof. Gauto c/ Gral. Aquino 325', 0, 0, 'C');
$pdf->Cell(85, 1, 'Presupuesto de Servicio', 0, 0, 'C');
$pdf->Ln(5);
$pdf->Cell(85, 1, 'Teléfono: (0971) 981011', 0, 0, 'C');
$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(50, 1, '   Nro: ', 0, 0, 'C');
$pdf->SetFont('Times', '', 10);
$pdf->Cell(70, 1, $rs[0]['id_presu'],0, 0,'L');
$pdf->SetFont('Times', '', 12);
$pdf->Ln(5);
//$pdf->Cell(85, 1, 'Timbrado N°: ' . '4308261', 0, 0, 'C');
//$pdf->Cell(50, 1, '   Factura N°: ', 0, 0, 'C');
//$pdf->SetFont('Times', '', 10);
//$pdf->Cell(70, 1, $rs[0]['com_nro_factura'],0, 0,'L');
$pdf->Ln(5);
//$pdf->Cell(85, 1, 'Vigencia: ' . '31-12-2020', 0, 0, 'C');


$style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0));

//cuadros de arriba
$pdf->RoundedRect(15, 12, 90, 42, 6.0, '1111', '', $style6, array(200, 200, 200));
$pdf->RoundedRect(105, 12, 87, 42, 6.0, '1111', '', $style6, array(200, 200, 200));
//cuadro de cabecera
$pdf->RoundedRect(15, 55, 177, 20, 5.0, '1111', '', $style6, array(200, 200, 200));

//datos de cabecera
$pdf->Ln(15);
//Fecha
$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(30, 1, '   FECHA: ', 0, 0, 'L');
$pdf->SetFont('Times', '', 10);
$pdf->Cell(/*1*/90, /*2*/1, /*3*/$rs[0]['pres_fecha'], /*4*/0, /*5*/1, /*6*/'L', /*7*/null, /*8*/null, /*9*/1, /*10*/null, /*11*/null, /*12*/null);
$pdf->Ln(3);
//nombre cliente
$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(30, 1, '   CLIENTE: ', 0, 0, 'L');
$pdf->SetFont('Times', '', 10);
$pdf->Cell(/*1*/90, /*2*/1, /*3*/$rs[0]['cliente'], /*4*/0, /*5*/0, /*6*/'L', /*7*/null, /*8*/null, /*9*/1, /*10*/null, /*11*/null, /*12*/null);


//cuadro de detalles
$pdf->RoundedRect(15, 75, 178, 155, 5.0, '1111', '', $style6, array(200, 200, 200));

$pdf->Ln(10);
$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(15, 1, '#', 0, 0, 'C');
$pdf->Cell(80, 1, 'Descripcion', 0, 0, 'L');
$pdf->Cell(15, 1, 'Cant.', 0, 0, 'C');
$pdf->Cell(25, 1, 'Precio Unit', 0, 0, 'R');
$pdf->Cell(20, 1, 'Subtotal', 0, 0, 'R');

$pdf->Ln(5);

$consultas = "select * from v_servicios_presupuesto_detalle where id_presu=".$_REQUEST ['vcod'];
$detalle = consultas::get_datos($consultas);

foreach ($detalle as $report) {
    $pdf->SetFont('Times', '', 10);
    $pdf->Cell(15, 1, $report['id_articulo'], 0, 0, 'C');
    $pdf->Cell(80, 1, /*3*/$report['art_descri'], 0, 0,'L',null,null,1,null,null,null);
    $pdf->Cell(15, 1,$report['cantidad'] , 0, 0, 'C');
    $pdf->Cell(22, 1, number_format(($report['precio_unit']),0,',','.'), 0, 0, 'R');
    $pdf->Cell(22, 1, number_format(($report['subtotal']),0,',','.'), 0, 0, 'R');
    $pdf->Ln(5);
}
$posicion = $pdf->GetY();
//cuadro de subtotales
$pdf->RoundedRect(15, 230, 177, 30, 4.0, '1111', '', $style6, array(200, 200, 200));

$pdf->SetFont('Times', 'B', 10);
$pdf->Text(18, 243, 'TOTAL GENERAL');
$pdf->SetFont('Times', '', 10);
$pdf->Text(165, 243, 'Gs. '.
        number_format(($rs[0]['pres_total']),0,',','.'));

$pdf->SetFont('Times', 'B', 10);
$pdf->Text(18, 251, 'TOTAL EN LETRAS');
$pdf->SetFont('Times', '', 10);
$pdf->Text(55, 251, 'Son Gs. '.
        ucfirst(strtolower ($rs[0]['total_letra'])));
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('presupuesto.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+

