<?php

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

$sqlcompras = "select *,(select numero_letras(notc_monto)) "
        . "as total_letra "
        . " from v_factura_ncredito where cod_notc = " .
        $_REQUEST ['vcod'] . " order by 1";
$rscompras = consultas::get_datos($sqlcompras);


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

$pdf->AddPage();

$pdf->Ln(5);
$pdf->SetFont('Times', 'B', 18);
$pdf->Cell(85, 1, 'ZAPATERIA SANABRIA', 0, 0, 'C', null, null, 1);

$pdf->SetFont('Times', 'B', 12);
$pdf->Cell(85, 1, 'VENTAS Y SERVICIO INTEGRAL', 0, 0, 'C');
$pdf->Ln(10);

$pdf->SetFont('Times', '', 12);
$pdf->Cell(85, 1, 'Dirección: Santa Clara c/ Bariloche', 0, 0, 'C');
$pdf->Cell(85, 1, 'NOTA DE CREDITO', 0, 0, 'C');
$pdf->Ln(5);
$pdf->Cell(85, 1, 'Teléfono: 0982 420 860', 0, 0, 'C');
$pdf->SetFont('Times', '', 10);
$pdf->Cell(50, 1, '   Numero: ', 0, 0, 'C');
$pdf->SetFont('Times', '', 10);
$pdf->Cell(70, 1, $rscompras[0]['notc_numero'], 0, 0, 'L');

$pdf->SetFont('Times', '', 12);
$pdf->Ln(5);
$pdf->Cell(85, 1, 'Timbrado N°: ' . '1', 0, 0, 'C');
//$pdf->Cell(50, 1, '   Factura N°: ', 0, 0, 'C');
//$pdf->SetFont('Times', '', 10);
//$pdf->Cell(70, 1, $rscompras[0]['nro_factura'],0, 0,'L');
$pdf->Ln(5);
$pdf->Cell(85, 1, 'Vigencia: ' . '27-10-2021', 0, 0, 'C');


$style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0));
//$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 255)));
//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(90, 1, $rscompras[0]['fecha1'], 0, 0, 'L', null, null, 1, null, null, null);

//motivo
$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(13, 1, '   MOTIVO: ', 0, 0, 'R');
$pdf->SetFont('Times', '', 10);
$pdf->Cell(80, 1, $rscompras[0]['mot_descri'], 0, 0, 'l');

$pdf->Ln(8);

//nombre cliente
$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(30, 1, '   CLIENTE: ', 0, 0, 'L');
$pdf->SetFont('Times', '', 10);
$pdf->Cell(90, 1, $rscompras[0]['cliente'], 0, 0, 'L', null, null, 1, null, null, null);

$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(20, 1, '   FACTURA N°: ', 0, 0, 'R');
$pdf->SetFont('Times', '', 10);
$pdf->Cell(80, 1, $rscompras[0]['nro_factura'], 0, 0, 'l');


//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(30, 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, 'IVA 5', 0, 0, 'R');
$pdf->Cell(20, 1, 'IVA 10', 0, 0, 'R');
$pdf->Cell(20, 1, 'Exentas', 0, 0, 'R');
$pdf->Cell(20, 1, 'Subtotal', 0, 0, 'R');
$pdf->Ln(5);

$consultas = "select * from v_factura_ncredito_detalle where cod_notc=" . $_REQUEST ['vcod'];
$detcompras = consultas::get_datos($consultas);

foreach ($detcompras as $report) {
    $pdf->SetFont('Times', '', 10);
    $pdf->Cell(15, 1, $report['id_articulo'], 0, 0, 'C');
    $pdf->Cell(30, 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(18, 1, number_format(($report['iva5']), 0, ',', '.'), 0, 0, 'R');
    $pdf->Cell(23, 1, number_format(($report['iva10']), 0, ',', '.'), 0, 0, 'R');
    $pdf->Cell(17, 1, number_format(($report['exentas']), 0, ',', '.'), 0, 0, 'R');
    $pdf->Cell(23, 1, number_format(($report['subtotal']), 0, ',', '.'), 0, 0, 'R');
}
$posicion = $pdf->GetY();
$pdf->Line(190, 230, 15, $posicion);


//cuadro de subtotales
$pdf->RoundedRect(15, 230, 177, 30, 4.0, '1111', '', $style6, array(200, 200, 200));



$pdf->SetFont('Times', '', 10);
$pdf->Text(18, 235, 'TOTAL IVA');
$pdf->SetFont('Times', '', 10);
$pdf->Text(130, 235, 'Gs. ' .number_format(($rscompras[0]['notc_totiva']), 0, ',', '.'));

$pdf->SetFont('Times', 'B', 10);
$pdf->Text(18, 243, 'TOTAL GENERAL');
$pdf->SetFont('Times', '', 10);
$pdf->Text(165, 243, 'Gs. ' . number_format(($rscompras[0]['notc_monto']), 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($rscompras[0]['total_letra'])));
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('factura.pdf', 'I');

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

