Tema: fpdf y mysql
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/02/2009, 16:02
fevimo
 
Fecha de Ingreso: septiembre-2008
Mensajes: 27
Antigüedad: 15 años, 7 meses
Puntos: 0
fpdf y mysql

Tengo una pagina que saca sus datos de una tabla mysql para que me cree una factura en pdf; para esto uso la clase FPDF.-A esta pagina le paso, a traves de un formulario los id de los registros que quiero facturar en pdfp.Si le dijo que me pase los registros del uno al cinco, la salida la hace perfectamente la primera factura las demás no las saca, le he dado mil vueltas y no consigo que me haga lo que quiero.-El objetivo es crear un fichero que recoga las distintas facturas y las imprima.-
Os incluyo el script que trasnforma en pdf para que le echeis un vistazo:
Código php:
Ver original
  1. <?php
  2. define('FPDF_FONTPATH','font/');
  3. require_once('clases/fpdf.php');
  4. require_once("conectar.php");
  5. require_once("comunes.php");
  6.  
  7. $pdf=new PDF();
  8. $pdf->Open();
  9. $pdf->AddPage();
  10.  
  11.  
  12. $pdf->Ln(60);
  13.  
  14.  
  15. $consulta = "Select * from factura2,empresas where id_factura between '$id_factura' and '$id_factura2' and factura2.id_empresas=empresas.id_empresas";
  16. $results = mysql_query($consulta, $conexion);
  17. $row=mysql_fetch_array($results);
  18. $contador=0;
  19. while ($contador < mysql_num_rows($results)) {
  20. $contador++;   
  21.    
  22.  
  23.  
  24.     $pdf->Cell(110);
  25.     $pdf->Cell(80,4,"",'',0,'C');
  26.     $pdf->Ln(4);
  27.    
  28.     $pdf->SetFillColor(255,255,255);
  29.     $pdf->SetTextColor(0);
  30.     $pdf->SetDrawColor(0,0,0);
  31.     $pdf->SetLineWidth(.2);
  32.     $pdf->SetFont('Arial','B',8);  
  33.    
  34.  
  35.  
  36.     $pdf->Cell(110);
  37.     $pdf->Cell(80,4,"",'LRT',0,'L',1);
  38.     $pdf->Ln(4);
  39.    
  40.     $pdf->Cell(110);
  41.     $pdf->Cell(80,4,$row["nombre"],'LR',0,'L',1);
  42.     $pdf->Ln(4);
  43.  
  44.     $pdf->Cell(110);
  45.     $pdf->Cell(80,4,$row["domicilio"],'LR',0,'L',1);
  46.     $pdf->Ln(4);
  47.  
  48.  
  49.     $pdf->Cell(110);
  50.     $pdf->Cell(80,4,$row["cp"] . "  " . $row["poblacion"] . "  (" . $row["provincia"] . ")",'LR',0,'L',1);
  51.     $pdf->Ln(4);       
  52.    
  53.    
  54.     $pdf->Cell(110);
  55.     $pdf->Cell(80,4,"",'LRB',0,'L',1);
  56.     $pdf->Ln(10);                  
  57.  
  58.     $pdf->SetFillColor(255,191,116);
  59.     $pdf->SetTextColor(0);
  60.     $pdf->SetDrawColor(0,0,0);
  61.     $pdf->SetLineWidth(.2);
  62.     $pdf->SetFont('Arial','B',6);
  63.    
  64.     $pdf->Cell(80);
  65.     $pdf->Cell(30,4,"CIF",1,0,'C',1);
  66.     $pdf->Cell(30,4,"Cod. Cliente",1,0,'C',1);
  67.     $pdf->Cell(30,4,"Fecha",1,0,'C',1);
  68.     $pdf->Cell(20,4,"Núm. Factura",1,0,'C',1);
  69.     $pdf->Ln(4);
  70.    
  71.    
  72.     $pdf->SetFillColor(255,255,255);
  73.     $pdf->SetTextColor(0);
  74.     $pdf->SetDrawColor(0,0,0);
  75.     $pdf->SetLineWidth(.2);
  76.     $pdf->SetFont('Arial','',6);
  77.     $pdf->Cell(80);
  78.    
  79.    
  80.     $pdf->Cell(30,4,$row["cif"],1,0,'C',1);
  81.     $pdf->Cell(30,4,$row["id_empresas"],1,0,'C',1);
  82.     $pdf->Cell(30,4,$row["fecha"],1,0,'C',1);  
  83.     $pdf->Cell(20,4,$row["id_factura"],1,0,'C',1);     
  84.    
  85.    
  86.    
  87.     $pdf->Ln(10);
  88.     $pdf->SetFillColor(255,255,255);
  89.     $pdf->SetTextColor(0);
  90.     $pdf->SetDrawColor(0,0,0);
  91.     $pdf->SetLineWidth(.2);
  92.     $pdf->SetFont('Arial','B',6);
  93.     $pdf->Cell(80);
  94.     $pdf->Cell(30,4,"DATOS DEL CURSO",1,0,'C',1);                  
  95.  
  96.     $pdf->Ln(10);
  97.  
  98.     $pdf->SetFillColor(255,191,116);
  99.     $pdf->SetTextColor(0);
  100.     $pdf->SetDrawColor(0,0,0);
  101.     $pdf->SetLineWidth(.2);
  102.     $pdf->SetFont('Arial','B',6);
  103.    
  104.    
  105.    
  106.     $pdf->Cell(31);
  107.     $pdf->Cell(20,4, "Acción",1,0,'C',1);
  108.     $pdf->Cell(50,4,"Nombre del curso",1,0,'C',1);
  109.     $pdf->Cell(20,4,"Tipo de curso",1,0,'C',1);
  110.     $pdf->Cell(25,4,"Fecha de inicio",1,0,'C',1);
  111.     $pdf->Cell(30,4, "Fecha de finalizacion",1,0,'C',1);
  112.     $pdf->Cell(15,4, "Alumnos",1,0,'C',1);
  113.    
  114.    
  115.     $pdf->Ln(4);
  116.    
  117.    
  118.     $pdf->SetFillColor(255,255,255);
  119.     $pdf->SetTextColor(0);
  120.     $pdf->SetDrawColor(0,0,0);
  121.     $pdf->SetLineWidth(.2);
  122.     $pdf->SetFont('Arial','',6);
  123.    
  124.     $pdf->Cell(31);
  125.     $pdf->Cell(20,4,$row["accion"],1,0,'C',1);
  126.     $pdf->Cell(50,4,$row["nombrecur"],1,0,'C',1);
  127.     $pdf->Cell(20,4,$row["tipo"],1,0,'C',1);   
  128.     $pdf->Cell(25,4,$row["inicio"],1,0,'C',1);     
  129.     $pdf->Cell(30,4,$row["finalizacion"],1,0,'C',1);
  130.     $pdf->Cell(15,4,$row["alumnos"],1,0,'C',1);
  131.     //ahora mostramos las lneas de la factura
  132.    
  133.     $pdf->Ln(15);  
  134.    
  135.     $pdf->SetFillColor(255,191,116);
  136.     $pdf->SetTextColor(0);
  137.     $pdf->SetDrawColor(0,0,0);
  138.     $pdf->SetLineWidth(.2);
  139.     $pdf->SetFont('Arial','B',6);
  140.     $pdf->Cell(30);
  141.     $pdf->Cell(160,4,"Factura",1,0,'C',1);
  142.    
  143.     $pdf->Ln(4);    
  144.     $pdf->Cell(30);
  145.     $pdf->SetFillColor(255,191,116);
  146.     $pdf->SetTextColor(0);
  147.     $pdf->SetDrawColor(0,0,0);
  148.     $pdf->SetLineWidth(.2);
  149.     $pdf->SetFont('Arial','B',6);
  150.     $pdf->Cell(20,4, "Acción",1,0,'C',1);
  151.     $pdf->Cell(70,4,"Descripción",1,0,'C',1);
  152.     $pdf->Cell(70,4, "Importe",1,0,'C',1);
  153.    
  154.     $pdf->Ln(4);
  155.     $pdf->Cell(30);
  156.     $pdf->SetFillColor(255,255,255);
  157.     $pdf->SetTextColor(0);
  158.     $pdf->SetDrawColor(0,0,0);
  159.     $pdf->SetLineWidth(.2);
  160.     $pdf->SetFont('Arial','B',6);
  161.     $pdf->cell(20,4,$row["accion"],1,0,'L',1);
  162.     $pdf->cell(70,4,'Costes de impartición',1,0,'L');
  163.     $pdf->Cell(70,4,$row["imparticion"],1,0,'C');  
  164.    
  165.      
  166.     $pdf->Ln(4);
  167.     $pdf->Cell(30);
  168.     $pdf->SetFillColor(255,255,255);
  169.     $pdf->SetTextColor(0);
  170.     $pdf->SetDrawColor(0,0,0);
  171.     $pdf->SetLineWidth(.2);
  172.     $pdf->SetFont('Arial','B',6);
  173.     $pdf->cell(20,4,'',1,0,'L',1);
  174.     $pdf->cell(70,4,'Costes asociados',1,0,'L');
  175.     $pdf->Cell(70,4,$row["asociados"],1,0,'C');
  176.    
  177.     $pdf->Ln(4);
  178.     $pdf->Cell(30,30);
  179.     $pdf->SetFillColor(255,255,255);
  180.     $pdf->SetTextColor(0);
  181.     $pdf->SetDrawColor(0,0,0);
  182.     $pdf->SetLineWidth(.2);
  183.     $pdf->SetFont('Arial','B',6);
  184.     $pdf->cell(20,4,'',1,0,'L',1);
  185.     $pdf->cell(70,4,'',1,0,'L');
  186.     $pdf->Cell(70,4,'',1,0,'C');
  187.    
  188.    
  189.    
  190.    
  191.    
  192.     $pdf->Ln(4);
  193.     $pdf->Cell(30);
  194.     $pdf->SetFillColor(255,255,255);
  195.     $pdf->SetTextColor(0);
  196.     $pdf->SetDrawColor(0,0,0);
  197.     $pdf->SetLineWidth(.2);
  198.     $pdf->SetFont('Arial','B',6);
  199.     $pdf->cell(20,4,'',1,0,'L',1);
  200.     $pdf->cell(70,4,'Importe total',1,0,'L');
  201.     $pdf->Cell(70,4,$row["bonificar"],1,0,'C');
  202.    
  203.  
  204. $pdf->Ln(4);    
  205.     $pdf->Cell(120);
  206.     $pdf->SetFillColor(255,191,116);
  207.     $pdf->SetTextColor(0);
  208.     $pdf->SetDrawColor(0,0,0);
  209.     $pdf->SetLineWidth(.2);
  210.     $pdf->SetFont('Arial','B',6);
  211.     $pdf->Cell(70,4, "Importe a bonificar",1,0,'C',1);
  212.    
  213. $pdf->Ln(4);
  214.     $pdf->Cell(120);
  215.     $pdf->SetFillColor(255,255,255);
  216.     $pdf->SetTextColor(0);
  217.     $pdf->SetDrawColor(0,0,0);
  218.     $pdf->SetLineWidth(.2);
  219.     $pdf->SetFont('Arial','',6);
  220.    
  221.    
  222.     $pdf->Cell(70,4,$row["bonificar"],1,0,'C');
  223.    
  224.     $pdf->Ln(4);
  225.     $pdf->Ln(20);      
  226.     $pdf->Cell(66);
  227.    
  228.     $pdf->SetFillColor(255,191,116);
  229.     $pdf->SetTextColor(0);
  230.     $pdf->SetDrawColor(0,0,0);
  231.     $pdf->SetLineWidth(.2);
  232.     $pdf->SetFont('Arial','B',8);
  233.    
  234.     $pdf->Cell(30,4,"Base imponible",1,0,'C',1);
  235.     $pdf->Cell(30,4,"Cuota IVA",1,0,'C',1);
  236.     $pdf->Cell(30,4,"IVA",1,0,'C',1);  
  237.     $pdf->Cell(35,4,"TOTAL EUROS",1,0,'C',1);
  238.    
  239.     $pdf->SetFillColor(255,255,255);
  240.     $pdf->SetTextColor(0);
  241.     $pdf->SetDrawColor(0,0,0);
  242.     $pdf->SetLineWidth(.2);
  243.     $pdf->SetFont('Arial','',6);
  244.     $pdf->Ln(4);
  245.     $pdf->Cell(66);
  246.    
  247.    
  248.     $pdf->Cell(30,4,$row["bonificar"],1,0,'C',1);
  249.     $pdf->Cell(30,4,'16%',1,0,'C',1);
  250.     $pdf->Cell(30,4,'0.00',1,0,'C',1); 
  251.     $pdf->Cell(35,4,$row["bonificar"],1,0,'C',1);
  252.     $pdf->Ln(4);
  253.     $pdf->Cell(110);
  254. $pdf->Ln(10);
  255. $pdf->Output();
  256. }
  257. ?>
El script funciona bien, por lo que le puede servir a alguno de vosotros tenga un pequeño negocio y pueda sacar las facturas una a una.
Sé que es un poco largo, pero espero que podais darme alguna solución.-
Muchas gracias

Última edición por GatorV; 04/02/2009 a las 19:04