Preparada factura en PDF

This commit is contained in:
imnavajas
2024-08-16 15:44:45 +02:00
parent a8f8c4851a
commit ec8288e6e4
6 changed files with 664 additions and 0 deletions

View File

@ -54,6 +54,56 @@ class FacturaLineaModel extends \App\Models\BaseModel {
return $builder;
}
public function getResourceResumenIVAsForPdf($factura_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.iva,
ROUND(SUM(t1.base), 2) AS base,
ROUND(SUM(t1.total_iva), 2) AS total_iva,
ROUND(SUM(t1.total), 2) AS total"
)
->where("t1.factura_id", $factura_id)
->groupBy('t1.iva')
->orderBy('t1.iva', 'ASC'); // Ordena por iva en forma ascendente
return $builder;
}
/**
* Get resource data for creating PDFs.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResourceForPdf($factura_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.factura_id AS factura_id,
t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id,
t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.precio_unidad AS precio_unidad, t1.iva AS iva,
t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data, t2.pedido_id AS pedido_id,
t3.total_aceptado AS total_aceptado, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible,
t6.cantidad AS cantidad_albaran"
)
->join("pedidos_linea t2", "t2.id = t1.pedido_linea_impresion_id", "left")
->join("presupuestos t3", "t3.id = t2.presupuesto_id", "left")
->join("clientes t4", "t4.id = t3.cliente_id", "left")
->join("albaranes t5", "t5.pedido_id = t2.pedido_id", "left")
->join("albaranes_lineas t6", "t6.albaran_id = t5.id", "left")
->where("t1.factura_id", $factura_id)
->where("t1.deleted_at", null);
return $builder;
}
public function addFacturaPedidoLinea($factura_id, $pedido_linea_id, $cantidad)
{
$data = [

View File

@ -102,6 +102,40 @@ class FacturaModel extends \App\Models\BaseModel {
}
/**
* Get resource data for creating PDFs.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResourceForPdf($factura_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.numero AS numero, DATE_FORMAT(t1.fecha_factura_at, '%d/%m/%Y') AS fecha_factura_at,
t1.base AS base, t1.total AS total, t1.pendiente AS pendiente,
t1.creditoAsegurado AS creditoAsegurado, t1.estado AS estado, t1.estado_pago AS estado_pago,
t4.nombre AS forma_pago,
DATE_FORMAT(MIN(CASE WHEN t3.fecha_vencimiento_at != '0000-00-00 00:00:00' THEN t3.fecha_vencimiento_at ELSE NULL END), '%d/%m/%Y') AS vencimiento,
t2.nombre AS cliente, t2.direccion AS cliente_direccion, t2.ciudad AS cliente_ciudad,
t2.cp AS cliente_cp, t2.cif AS cliente_cif, t2.vencimiento AS dias_vencimiento, t2.ccc AS cliente_ccc,
t5.nombre AS cliente_pais"
);
$builder->join("clientes t2", "t2.id = t1.cliente_id", "left");
$builder->join("facturas_pagos t3", "t3.factura_id = t1.id", "left");
$builder->join("formas_pago t4", "t3.forma_pago_id = t4.id", "left");
$builder->join("lg_paises t5", "t2.pais_id = t5.id", "left");
$builder->where("t1.deleted_at IS NULL");
$builder->groupBy("t1.id"); // Agrupa por id de la factura
return $builder;
}
public function getResourcePedidos($pedido_id)
{
$builder = $this->db