I need to print what I have on the grid, it only shows me one invoice

0

<?php

include '../../fpdf/rotation.php';
include("../../fpdf/barcode.inc.php");
require_once('../../procesos/base.php');

//error_reporting(0);
class PDF extends PDF_Rotate {

    var $widths;
    var $aligns;

    function SetWidths($w) {
        $this->widths = $w;
    }

    function Header() {

        $this->AddFont('Amble-Regular', '', 'Amble-Regular.php');
        $this->SetFont('Amble-Regular', '', 7);
        $fecha = date('Y-m-d', time());
        $this->SetY(2);
        $this->Cell(15, 4, 'Generado: ' . $fecha, 0, 0, 'C', 0);
        $this->Cell(122, 4, 'MEGAMACK', 0, 0, 'R', 0);
        $this->Ln(7);
        $this->SetX(13);
        // $this->RotatedImage('../../fpdf/logo.fw.png', 50, 150, 100, 80, 45);                            
        $this->SetX(0);
    }

    function Footer() {
        $this->SetY(-10);
        $this->SetFont('Arial', 'I', 7);
        $this->Cell(0, 10, 'Pag. ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
    }

    function RotatedImage($file, $x, $y, $w, $h, $angle) {
        $this->Rotate($angle, $x, $y);
        $this->Image($file, $x, $y, $w, $h);
        $this->Rotate(0);
    }

}
if (isset($_GET['id'])) {

    $id = $_GET['id'];
    unset($id);
    $datos_recuperados = array();
    foreach ($_GET as $key1 => $value1) {
        $datos_recuperados[$key1] = $value1;
    }
    if (count($datos_recuperados) > 0) {
        foreach ($datos_recuperados as $key1 => $value1) {
        }
        $arr2 = (explode(',', $value1));
        foreach($arr2 as $posicion=>$value1)
    {
            generarPDF($value1);
             }
    }
}



function generarPDF($valor) {
        conectarse();
//    for ($i = 0; $i <= count($valor); $i ++) {

    $consulta = pg_query("select * from empresa left join factura_venta on empresa.id_empresa  = factura_venta.id_empresa left join clientes on factura_venta.id_cliente=clientes.id_cliente left join tipo_documento on tipo_documento.id_tdocu=clientes.id_tdocu where factura_venta.id_factura_venta='" . $valor . "' ");
    while ($row = pg_fetch_row($consulta)) {
        $ruc = $row[2];
        $numeroAutorizacion = $row[35];
        $fechaEmision = $row[30];
        $date = new DateTime($fechaEmision);
        $fechaEmision = $date->format('d/m/Y');
        $claveAcceso = $row[51];
        $razonSocial = $row[1];
        $nombreComercial = $row[16];
        $direcionMatriz = $row[7];
        $direccionEstablecimiento = $row[3];
        $nroContribuyente = $row[19];
        $obligado = $row[17];
        $contribuyente = $row[58];
        $identificacion = $row[57];
        $direcion = $row[60];
        $telefono = $row[61];
        $email = $row[65];
        $secuencial = $row[29];
        $ip = $secuencial;
        $iparr = split("\-", $ip);
        $secuencial = $iparr[2];
        $establecimiento = $row[21];
        $puntoEmision = $row[22];
        $fechaAut = $row[36];
        $codigo = $row[73];

        $num_serie_guia = $row[54];
        if ($num_serie_guia != "000000000") {
            $num_serie_guia = $row[54];
        } else {
            $num_serie_guia = "";
        }


        $consulta_ambiente = pg_query("select nombre_ambi from ambiente  ");
        while ($row = pg_fetch_row($consulta_ambiente)) {
            $nombre_ambi = $row[0];
        }
        $ambiente = $nombre_ambi;
        $consulta_emision = pg_query("select nombre_temision from tipo_emision  ");
        while ($row = pg_fetch_row($consulta_emision)) {
            $nombre_emi = $row[0];
        }
        $emision = $nombre_emi;

//          $imagen = $row[13];
    }




//       $consulta_ambiente = pg_query("select nombre_ambi from ambiente  ");
//          while ($row = pg_fetch_row($consulta_ambiente)) {
//                        $ambiente = $row[0];
//                    }

    $consulta_emision = pg_query("select nombre_temision from tipo_emision  ");
    while ($row = pg_fetch_row($consulta_emision)) {
        $emision = $row[0];
    }

//      $ceros = 9;
//      $temp = '';
//      $tam = $ceros - strlen($secuencial);
//      for ($i = 0; $i < $tam; $i++) {                 
//          $temp = $temp .'0';        
//      }
//      $secuencial = $temp .''. $secuencial;

    $pdf = new PDF('P', 'mm', 'A5');
    $pdf->AddPage();
    $pdf->SetMargins(10, 0, 0, 0);
    $pdf->AliasNbPages();
    $pdf->SetAutoPageBreak(true, 20);
    $pdf->AddFont('Amble-Regular', '', 'Amble-Regular.php');
    $pdf->SetFont('Amble-Regular', '', 7);

//      $logo = $imagen;
    //$pdf->Rect(1, 3, 81, 20 ,1, 'D');
    $pdf->Image('C:\xampp\htdocs\syswebfe\images\logo.png', 11, 5, -290); // Img Empresa 
    //$pdf->Rect(1, 24, 81, 53 , 'D'); // 2 datos personales
    $pdf->Text(5, 39, 'RUC:' . $ruc); // ruc            
    $pdf->Text(91, 23, utf8_decode("FACTURA")); // Tipo comprobante
    $pdf->Text(91, 26, 'No. ' . $establecimiento . '-' . $puntoEmision . '-' . $secuencial); // Secuencial
    $pdf->Text(91, 29, utf8_decode('NÚMERO DE AUTORIZACIÓN')); // N° Autorizacion
    //$pdf->SetY(40);
    //$pdf->SetX(107);  
    $pdf->Text(91, 32, $numeroAutorizacion); // N° Autorización     
    $pdf->Text(91, 35, utf8_decode('FECHA Y HORA DE AUTORIZACIÓN')); // fecha y hora de autorizacion
    $pdf->Text(91, 38, $fechaAut); //FECHA
    $pdf->Text(91, 41, utf8_decode('AMBIENTE: ' . $ambiente)); // Ambiente
    $pdf->Text(91, 44, utf8_decode('EMISIÓN: ' . $emision)); // Tipo de emision
    $pdf->Text(91, 5, utf8_decode('CLAVE DE ACCESO: ')); // Clave de acceso
    $code_number = $claveAcceso; // Código de barras        
    new barCodeGenrator($code_number, 1, 'temp.gif', 470, 60, true); /// img codigo barras  
    $pdf->Image('temp.gif', 68, 9, 80, 15);

    //$pdf->Rect(87, 3, 102, 90 , 'D'); //Datos Empresa  
    //$pdf->SetX(50);
    //$pdf->SetY(20);
    $pdf->Text(5, 36, $razonSocial); // Razon Social Empresa    
    //$pdf->SetY(56);
    //$pdf->SetX(4);    
    //$pdf->SetY(66);   
    //$pdf->SetX(4);    
    $pdf->Text(5, 45, 'Matriz: ' . $direccionEstablecimiento); // Direccion Matriz  
    //$pdf->SetY(76);   
    //$pdf->SetX(4);    
//      $pdf->Text(5, 45, 'Sucursal: '.$direccionEstablecimiento);// Direccion Establecimiento  
    $pdf->Text(5, 42, utf8_decode('Obligado a llevar Contabilidad: ' . $obligado)); // Obligado a llevar contabilidad
    //$pdf->Rect(3, 101, 205, 20 , 'D'); // INFO TRIBUTARIA              
    //$pdf->SetY(101);
    //$pdf->SetX(3);
    $pdf->Text(5, 48, utf8_decode('Cliente: ' . $contribuyente)); // Nombre cliente 
    $pdf->Text(91, 48, utf8_decode('RUC / CI: ' . $identificacion)); // Ruc cliente
    $pdf->Text(5, 51, utf8_decode('Fecha de Emisión: ' . $fechaEmision)); //fecha de emision cliente
    $pdf->Text(91, 51, utf8_decode('Guía de Remisión: ' . $num_serie_guia)); //guia remision 
    // detalles factura
    $pdf->SetFont('Amble-Regular', '', 7);
    $pdf->SetY(53);
    $pdf->SetX(5);
    $pdf->multiCell(30, 5, utf8_decode('Cod. Principal'), 1);
    //$pdf->SetY(64);
    //$pdf->SetX(21);
    //$pdf->multiCell(20, 5, utf8_decode('Cod. Auxiliar'),1 );
    $pdf->SetY(53);
    $pdf->SetX(35);
    $pdf->multiCell(10, 5, utf8_decode('Cant.'), 1);
    $pdf->SetY(53);
    $pdf->SetX(45);
    $pdf->multiCell(64, 5, utf8_decode('Descripción'), 1);
    $pdf->SetY(53);
    $pdf->SetX(109);
    $pdf->multiCell(12, 5, utf8_decode('Precio U.'), 1);
    $pdf->SetY(53);
    $pdf->SetX(121);
    $pdf->multiCell(10, 5, utf8_decode('Dcto %'), 1);
    $pdf->SetY(53);
    $pdf->SetX(131);
    $pdf->multiCell(15, 5, utf8_decode('Subtotal'), 1);

    $x = 58;
    $y = 3;

    $resultado = pg_query("select P.codigo,P.cod_barras, P.articulo, D.cantidad, D.precio_venta, D.descuento_producto, F.tarifa12 from factura_venta F,detalle_factura_venta D  , productos P where  d.cod_productos =P.cod_productos   and D.id_factura_venta = F.id_factura_venta  AND   F.id_factura_venta = '" . $valor . "'");

    while ($row = pg_fetch_row($resultado)) {
        $codigo = utf8_decode($row[0]);
//          $codigoAuxiliar = utf8_decode($row[1]);
        $codigoAuxiliar = '';
        $descripcion = utf8_decode($row[2]);
        $cantidad = $row[3];
        $tarifa12 = 0;
        $tarifa12 = $row[4];

        $precio = number_format($row[4], 2, '.', '');
        ;
        $descuento = $row[5];
        $tarifa12 = $tarifa12 * $cantidad;
        $Descucaltres = 0;
        $desc = 0;
        $desc = $row[5];
        $valcien = 100;
        $Descucaltres = ($tarifa12 / $valcien) * $desc;
        $tarifa12sin = $tarifa12 - $Descucaltres;
        $total = number_format($tarifa12sin, 3, '.', '');

        $pdf->SetY($x);
        $pdf->SetX(5);

        $pdf->multiCell(40, 6, substr($codigo, 0, 18), 1);

        //$pdf->SetY($x);
        //$pdf->SetX(23);
        //if(strlen($codigoAuxiliar) > 19)
        //  $tam = 5;
        //else
        //  $tam = 10;  
        //$pdf->multiCell(20, $tam, $codigoAuxiliar,1);

        $pdf->SetY($x);
        $pdf->SetX(35);
        if (strlen($cantidad) > 10)
            $tam = 3;
        else
            $tam = 6;
        $pdf->multiCell(10, $tam, $cantidad, 1);

        $pdf->SetY($x);
        $pdf->SetX(45);
        if (strlen($descripcion) > 50)
            $tam = 3;
        else
            $tam = 6;
        $pdf->multiCell(64, $tam, $descripcion, 1);

        $pdf->SetY($x);
        $pdf->SetX(109);
        if (strlen($precio) > 10)
            $tam = 3;
        else
            $tam = 6;
        $pdf->multiCell(12, $tam, $precio, 1);

        $pdf->SetY($x);
        $pdf->SetX(121);
        if (strlen($descuento) > 15)
            $tam = 3;
        else
            $tam = 6;
        $pdf->multiCell(10, $tam, $descuento, 1);

        $pdf->SetY($x);
        $pdf->SetX(131);
        if (strlen($total) > 10)
            $tam = 3;
        else
            $tam = 6;
        $pdf->multiCell(15, $tam, $total, 1);
        $x = $x + 6;
    }

    // pie de pagina            
    if ($pdf->getY() <= 220) {
        $pdf->Ln(3);
        $pdf->SetX(5);
        $pdf->Rect($pdf->GetX(), $pdf->GetY(), 86, 18, 'D'); ////3 INFO ADICIONAL      
        $y = $pdf->GetY();
        $x = $pdf->GetX();
        $y1 = $pdf->GetY();
        $x1 = $pdf->GetX();
        $pdf->Text($x + 1, $y + 4, utf8_decode('INFORMACIÓN ADICIONAL')); //informacion         
        $pdf->SetY($y + 5);
        $pdf->SetX($x);
        $pdf->multiCell(100, 5, utf8_decode("Dirección:" . $direcion), 0);
        $pdf->SetY($y + 8);
        $pdf->SetX($x);
        $pdf->multiCell(100, 8, utf8_decode("Teléfono: " . $telefono), 0);
        $pdf->SetY($y + 11);
        $pdf->SetX($x);
        $pdf->multiCell(100, 11, utf8_decode("Email: " . $email), 0);

        $resultado = pg_query("SELECT F.tarifa12, F.tarifa0, F.tarifa0, F.iva_venta, F.descuento_venta, F.total_venta FROM factura_venta f WHERE id_factura_venta = '" . $valor . "'");
        while ($row = pg_fetch_row($resultado)) {
            $subtotal = $row[0];
            $tarifa = $row[0];
            $tarifa0 = $row[2];
            $iva = $row[3];
            $descuento = $row[4];

            $total = number_format($row[5], 2, ',', '.');
        }

        $pdf->Ln(1);
        $pdf->SetX(105);
        $x1 = $x1 + 104;
        $pdf->SetY($y1);
        $pdf->SetX($x1);
        $pdf->multiCell(22, 6, utf8_decode("Subtotal 12 %"), 1);
        $pdf->SetY($y1);
        $pdf->SetX($x1 + 22);
        $pdf->multiCell(15, 6, number_format($tarifa, 2, '.', ''), 1);
        $pdf->SetY($y1 + 6);
        $pdf->SetX($x1);
        $pdf->multiCell(22, 6, utf8_decode("Subtotal IVA 0 %"), 1);
        $pdf->SetY($y1 + 6);
        $pdf->SetX($x1 + 22);
        $pdf->multiCell(15, 6, number_format($tarifa0, 2, '.', ''), 1);
        $pdf->SetY($y1 + 12);
        $pdf->SetX($x1);
        $pdf->multiCell(22, 6, utf8_decode("Descuento"), 1);
        $pdf->SetY($y1 + 12);
        $pdf->SetX($x1 + 22);
        $pdf->multiCell(15, 6, number_format($descuento, 2, '.', ''), 1);
        $pdf->SetY($y1 + 18);
        $pdf->SetX($x1);
        $pdf->multiCell(22, 6, utf8_decode("IVA 12 %"), 1);
        $pdf->SetY($y1 + 18);
        $pdf->SetX($x1 + 22);
        $pdf->multiCell(15, 6, number_format($iva, 2, '.', ''), 1);
        $pdf->SetY($y1 + 24);
        $pdf->SetX($x1);
        $pdf->multiCell(22, 6, utf8_decode("PROPINA"), 1);
        $pdf->SetY($y1 + 24);
        $pdf->SetX($x1 + 22);
        $pdf->multiCell(15, 6, utf8_decode("0.00"), 1);
        $pdf->SetY($y1 + 30);
        $pdf->SetX($x1);
        $pdf->multiCell(22, 6, utf8_decode("TOTAL"), 1);
        $pdf->SetY($y1 + 30);
        $pdf->SetX($x1 + 22);
        $pdf->multiCell(15, 6, ($total), 1);

        // FORMAS DE PAGO               
        $resultado = pg_query("SELECT P.codigo, P.descripcion FROM factura_venta F, forma_pagos P WHERE F.id_forma_pago = P.id_forma_pago AND F.id_factura_venta = '" . $valor . "'");
        while ($row = pg_fetch_row($resultado)) {
            $codigovalor = $row[0];
            $valo0 = $row[1];
        }
        $pdf->Ln(-10);
        $pdf->SetX(5);

        $pdf->Rect($pdf->GetX(), $pdf->GetY(), 86, 10, 'D'); ////3 INFO ADICIONAL      
        $y = $pdf->GetY();
        $x = $pdf->GetX();
        $y1 = $pdf->GetY();
        $x1 = $pdf->GetX();

        $pdf->Text($x + 1, $y + 3, utf8_decode('FORMA DE PAGO')); //informacion         
        $pdf->SetY($y + 6);
        $pdf->SetX($x);
        $pdf->Text($x + 1, $y + 8, utf8_decode($codigovalor . '  ' . $valo0)); //informacion        
        $pdf->SetY($y + 6);
        $pdf->SetX($x);
        $pdf->Text($x + 70, $y + 3, utf8_decode("VALOR:"));
        $pdf->SetY($y + 10);
        $pdf->SetX($x);
        $pdf->Text($x + 70, $y + 8, utf8_decode($total)); //informacion 
    } else {

    }
    $pdf->SetY(190);
    $pdf->SetX(3);
    $pdf->Cell(60, 5, "__________________________________________", 0, 0, 'C', 0);
    $pdf->Cell(82, 5, "__________________________________________", 0, 1, 'C', 0);
    $pdf->SetX(3);
    $pdf->Cell(60, 5, "ENTREGE CONFORME", 0, 0, 'C', 0);
    $pdf->Cell(82, 5, "RECIBI CONFORME", 0, 1, 'C', 0);
    if (isset($_GET['id'])) {
        $pdf->Output();
    } else {
        $pdf_file_contents = $pdf->Output("", "S");
        return $pdf_file_contents;
    }
    // $pdf->Output();      
}

//}


?>
    
asked by Carlos Darwin Gonzalez O. 09.07.2018 в 22:46
source

1 answer

0

Your problem is in this part of the code:

if (count($datos_recuperados) > 0) {
    foreach ($datos_recuperados as $key1 => $value1) {
    }
    $arr2 = (explode(',', $value1));
    foreach($arr2 as $posicion=>$value1)
{
        generarPDF($value1);
         }
}

In the first foreach, you are closing with a key before explode . That is why the variable $value1 keeps the last value of the iteration. The solution is simply to remove the extra key.

    
answered by 09.07.2018 в 23:03