Skip to content

Commit

Permalink
Print PDF invoices - Pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev1nByte committed Jul 19, 2023
1 parent c3edcc4 commit 4ad9ea5
Showing 1 changed file with 208 additions and 6 deletions.
214 changes: 208 additions & 6 deletions extensions/tcpdf/pdf/factura.php
Expand Up @@ -3,6 +3,15 @@
require_once "../../../controllers/ventas.controlador.php";
require_once "../../../models/ventas.modelos.php";

require_once "../../../controllers/clientes.controlador.php";
require_once "../../../models/clientes.modelos.php";

require_once "../../../controllers/usuarios.controlador.php";
require_once "../../../models/usuarios.modelos.php";

require_once "../../../controllers/productos.controlador.php";
require_once "../../../models/productos.modelos.php";

class imprimirFactura{

public $codigo;
Expand All @@ -22,7 +31,19 @@ public function traerImpresionFactura(){
$impuesto = number_format($respuestaVenta["impuesto"],2);
$total = number_format($respuestaVenta["total"],2);

//TRAEMOS LA INFORMACIÓN DEL CLIENTE

$itemCliente = "id";
$valorCliente = $respuestaVenta["id_cliente"];

$respuestaCliente = ControladorClientes::ctrMostrarClientes($itemCliente, $valorCliente);

//TRAEMOS LA INFORMACIÓN DEL VENDEDOR

$itemVendedor = "id";
$valorVendedor = $respuestaVenta["id_vendedor"];

$respuestaVendedor = ControladorUsuarios::ctrMostrarUsuarios($itemVendedor, $valorVendedor);

require_once('tcpdf_include.php');

Expand All @@ -32,12 +53,14 @@ public function traerImpresionFactura(){

$pdf->AddPage();

// ---------------------------------------------------------

$bloque1 = <<<EOF
<table>
<tr>
<br>
<td style="width:150px"><img src="images/logo-negro-bloque.png"></td>
<td style="background-color:white; width:140px">
Expand All @@ -48,8 +71,7 @@ public function traerImpresionFactura(){
RUC: 10720312906
<br>
Dirección: Marco Jara II
Etapa<br> Mz D" Lt 38
Dirección: Calle Javier Prado N°21
</div>
Expand All @@ -69,7 +91,7 @@ public function traerImpresionFactura(){
</td>
<td style="background-color:white; width:110px; text-align:center; color:red"><br><br>FACTURA N.<br>$valorVenta</td>
<td style="background-color:white; width:110px; text-align:center; color:red"><br><br><b>FACTURA N.<br>$valorVenta</b></td>
</tr>
Expand All @@ -80,11 +102,192 @@ public function traerImpresionFactura(){
$pdf->writeHTML($bloque1, false, false, false, false, '');

// ---------------------------------------------------------

$bloque2 = <<<EOF
<table>
<tr>
<td style="width:540px"><img src="images/back.jpg"></td>
</tr>
</table>
<table style="font-size:10px; padding:5px 10px;">
<tr>
<td style="border: 1px solid #666; background-color:white; width:390px">
Cliente: $respuestaCliente[nombre]
</td>
<td style="border: 1px solid #666; background-color:white; width:150px; text-align:right">
Fecha: $fecha
</td>
</tr>
<tr>
<td style="border: 1px solid #666; background-color:white; width:540px">Vendedor: $respuestaVendedor[nombre]</td>
</tr>
<tr>
<td style="border-bottom: 1px solid #666; background-color:white; width:540px"></td>
</tr>
</table>
EOF;

$pdf->writeHTML($bloque2, false, false, false, false, '');

// ---------------------------------------------------------

$bloque3 = <<<EOF
<table style="font-size:10px; padding:5px 10px;">
<tr>
<td style="border: 1px solid #666; background-color:white; width:260px; text-align:center">Producto</td>
<td style="border: 1px solid #666; background-color:white; width:80px; text-align:center">Cantidad</td>
<td style="border: 1px solid #666; background-color:white; width:100px; text-align:center">Valor Unit.</td>
<td style="border: 1px solid #666; background-color:white; width:100px; text-align:center">Valor Total</td>
</tr>
</table>
EOF;

$pdf->writeHTML($bloque3, false, false, false, false, '');

// ---------------------------------------------------------

foreach ($productos as $key => $item) {

$itemProducto = "descripcion";
$valorProducto = $item["descripcion"];
$orden = null;

$respuestaProducto = ControladorProductos::ctrMostrarProductos($itemProducto, $valorProducto, $orden);

$valorUnitario = number_format($respuestaProducto["precio_venta"], 2);

$precioTotal = number_format($item["total"], 2);

$bloque4 = <<<EOF
<table style="font-size:10px; padding:5px 10px;">
<tr>
<td style="border: 1px solid #666; color:#333; background-color:white; width:260px; text-align:center">
$item[descripcion]
</td>
<td style="border: 1px solid #666; color:#333; background-color:white; width:80px; text-align:center">
$item[cantidad]
</td>
<td style="border: 1px solid #666; color:#333; background-color:white; width:100px; text-align:center">S/.
$valorUnitario
</td>
<td style="border: 1px solid #666; color:#333; background-color:white; width:100px; text-align:center">S/.
$precioTotal
</td>
</tr>
</table>
EOF;

$pdf->writeHTML($bloque4, false, false, false, false, '');

}

// ---------------------------------------------------------

$bloque5 = <<<EOF
<table style="font-size:10px; padding:5px 10px;">
<tr>
<td style="color:#333; background-color:white; width:340px; text-align:center"></td>
<td style="border-bottom: 1px solid #666; background-color:white; width:100px; text-align:center"></td>
<td style="border-bottom: 1px solid #666; color:#333; background-color:white; width:100px; text-align:center"></td>
</tr>
<tr>
<td style="border-right: 1px solid #666; color:#333; background-color:white; width:340px; text-align:center"></td>
<td style="border: 1px solid #666; background-color:white; width:100px; text-align:center">
Neto:
</td>
<td style="border: 1px solid #666; color:#333; background-color:white; width:100px; text-align:center">
S/. $neto
</td>
</tr>
<tr>
<td style="border-right: 1px solid #666; color:#333; background-color:white; width:340px; text-align:center"></td>
<td style="border: 1px solid #666; background-color:white; width:100px; text-align:center">
Impuesto:
</td>
<td style="border: 1px solid #666; color:#333; background-color:white; width:100px; text-align:center">
S/. $impuesto
</td>
</tr>
<tr>
<td style="border-right: 1px solid #666; color:#333; background-color:white; width:340px; text-align:center"></td>
<td style="border: 1px solid #666; background-color:white; width:100px; text-align:center">
<b>Total:</b>
</td>
<td style="border: 1px solid #666; color:#333; background-color:white; width:100px; text-align:center">
<b>S/. $total</b>
</td>
</tr>
</table>
EOF;

$pdf->writeHTML($bloque5, false, false, false, false, '');

// ---------------------------------------------------------

//SALIDA DEL ARCHIVO

$pdf->Output('factura.pdf');


}

}
Expand All @@ -93,5 +296,4 @@ public function traerImpresionFactura(){
$factura -> codigo = $_GET["codigo"];
$factura -> traerImpresionFactura();


?>

0 comments on commit 4ad9ea5

Please sign in to comment.