PHP - ticket_iterar_productos

 
Vista:

ticket_iterar_productos

Publicado por karolina (10 intervenciones) el 10/01/2020 00:48:52
Hola Buenas noches, requiero el aporte de este foro. Realice un pdf para generar ticket de compra, utilice un ciclo for. pero resulta que la consulta no me muestra los productos completos solo la primera fila, entonces tuve que crear un tipo de arreglo como el que esta en el código, pero tengo que incluir cada posición. Lo que quiero es que me muestre todas las filas sin tener que iterarlas una a una.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<? require_once('Connections/sinveck.php');
 
 
include "fpdf/fpdf.php";
 
$result = mysql_query("SELECT id FROM ventas order by id DESC LIMIT 1");
 
$objetoPAGO=mysql_fetch_object($result);
$objetoPAGO->id;
 
$id_venta = $resultado === false ? 1 : $objetoPAGO->id;
 
mysql_select_db($database_sinveck, $sinveck);
$strsql = "SELECT v.id,v.fecha, v.CEDULA, v.NOMBRE_CLIENTE, p.PRODUCTO, p.PRECIO_VENTA, p.quantity, v.total, v.porcentaje, v.total_t, v.ID_PAGO
FROM ventas v left join productos_vendidos p on v.id = p.id_venta where v.id = '".$id_venta."' ";
$query = mysql_query($strsql);
 
 
$pdf = new FPDF($orientation='P',$unit='mm', array(45,350));  // EJE X y  Y
$pdf->AddPage();
$pdf->SetFont('Arial','B',6);    //Letra Arial, negrita (Bold), tam. 20
$textypos = 5;
$pdf->setY(2);
$pdf->Cell(5,$textypos,"DKEY SYSTEMS F.P");
 
$pdf->SetFont('Arial','',4);    //Letra Arial, negrita (Bold), tam. 20
 
$textypos+=8;
$pdf->setX(2);
$pdf->Cell(5,$textypos,'DIRECCION FISCAL');
$textypos+=3;
$pdf->setX(2);
$pdf->Cell(5,$textypos,' ');
$textypos+=3;
$pdf->setX(2);
$pdf->Cell(5,$textypos,'  ');
$textypos+=3;
$pdf->setX(2);
 
$pdf->Cell(5,$textypos,'  ');
$textypos+=8;
$pdf->setX(2);
for ($i=0; $i < count($query);$i++) {
 
 
 while($row=mysql_fetch_assoc($query)){
 
     $id[]= $row['id'];
     $PRODUCTO[] = $row['PRODUCTO'];
	 $PRECIO_VENTA[] =$row['PRECIO_VENTA'];
	  	 $quantity[] =$row['quantity'];
		 $fecha[] =$row['fecha'];
     $total[]= $row['total'];
     $porcentaje[] = $row['porcentaje'];
	 $total_t[] =$row['total_t'];
 
 
}
$pdf->Cell(5,$textypos,"Factura Nro: ".strtoupper(substr($id[0], 0,18)));
$textypos+=3;
$pdf->setX(2);
 
 
$pdf->Cell(5,$textypos,"Fecha: ".strtoupper(substr($fecha[0], 0,18)));
$textypos+=3;
$pdf->setX(2);
$pdf->Cell(5,$textypos,'-----------------------------------------------------------------------------');
$textypos+=6;
$pdf->setX(2);
$pdf->Cell(5,$textypos,'CANT.       ARTICULO                  PRECIO             TOTAL');
$off = $textypos+4;
 
 
$pdf->setX(2);
$pdf->Cell(5,$off,$quantity[0]);
$pdf->setX(6);
 
$pdf->Cell(35,$off, strtoupper(substr($PRODUCTO[0], 0,18)) );
$pdf->setX(24);
$pdf->Cell(11, $off,"" .number_format($PRECIO_VENTA['0'],2,".",","),0,0,"R " );
$pdf->setX(32);
$pdf->Cell(11,$off,"" .number_format($quantity[0]*$PRECIO_VENTA[0],2,".",","),0,0,"R ");
 
$off+=4;
 
$textypos=$off+4;
$pdf->setX(2);
$pdf->Cell(5,$off,$quantity[1]);
$pdf->setX(6);
 
$pdf->Cell(35,$off, strtoupper(substr($PRODUCTO[1], 0,18)) );
$pdf->setX(24);
$pdf->Cell(11, $off,"" .number_format($PRECIO_VENTA['1'],2,".",","),0,0,"R " );
$pdf->setX(32);
$pdf->Cell(11,$off,"" .number_format($quantity[1]*$PRECIO_VENTA[1],2,".",","),0,0,"R ");
 
$off+=4;
 
$textypos=$off+5;
$pdf->setX(2);
$pdf->Cell(5,$off,$quantity[2]);
$pdf->setX(6);
 
$pdf->Cell(35,$off, strtoupper(substr($PRODUCTO[2], 0,18)) );
$pdf->setX(24);
$pdf->Cell(11, $off,"" .number_format($PRECIO_VENTA['2'],2,".",","),0,0,"R " );
$pdf->setX(32);
$pdf->Cell(11,$off,"" .number_format($quantity[2]*$PRECIO_VENTA[2],2,".",","),0,0,"R ");
 $pdf->setX(2);
 $pdf->Cell(5,$textypos,'-----------------------------------------------------------------------------');
 
 $pdf->setX(2);
$pdf->Cell(5,$textypos+6,"SUBTOTAL:  "    .number_format($total[0],2,".",","),0,0,"R " );
 
$pdf->setX(2);
$pdf->Cell(5,$textypos+11,"IVA:    " .number_format($porcentaje[0],2,".",","),0,0,"R " );
 
$pdf->setX(2);
$pdf->Cell(5,$textypos+16,"FACTURADO:  "    .number_format($total_t[0],2,".",","),0,0,"R " );
}
 
$pdf->setX(2);
$pdf->Cell(5,$textypos+21,'GRACIAS POR TU COMPRA...!! ');
 
$pdf->output();
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder