modificado el listado. faltan los selects

This commit is contained in:
2025-03-20 22:26:48 +01:00
parent a1cef4eac3
commit af25237fa5
4 changed files with 387 additions and 434 deletions

View File

@ -2,7 +2,10 @@
namespace App\Models\Facturas;
class FacturaModel extends \App\Models\BaseModel {
use CodeIgniter\Database\BaseBuilder;
class FacturaModel extends \App\Models\BaseModel
{
protected $table = 'facturas';
@ -71,8 +74,8 @@ class FacturaModel extends \App\Models\BaseModel {
protected $updatedField = "updated_at";
public static $labelField = "id";
public function getResource(string $search = "", $cliente_id=-1)
public function getResource(string $search = "", $cliente_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
@ -88,16 +91,16 @@ class FacturaModel extends \App\Models\BaseModel {
$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->where("t1.deleted_at IS NULL");
if(auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) {
if (auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) {
$builder->where("t1.estado", "validada");
}
if($cliente_id != -1) {
if ($cliente_id != -1) {
$builder->where("t1.cliente_id", $cliente_id);
}
$builder->groupBy("t1.id"); // Agrupa por id de la factura
return empty($search)
@ -109,6 +112,35 @@ class FacturaModel extends \App\Models\BaseModel {
->groupEnd();
}
public function getDatatableQuery($cliente_id): BaseBuilder
{
$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,
t2.nombre AS cliente, 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,
GROUP_CONCAT(DISTINCT t4.nombre ORDER BY t4.nombre ASC SEPARATOR ', ') 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.vencimiento AS dias_vencimiento"
);
$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->where("t1.deleted_at", null);
$builder->where("t1.deleted_at IS NULL");
if (auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) {
$builder->where("t1.estado", "validada");
}
if ($cliente_id != -1) {
$builder->where("t1.cliente_id", $cliente_id);
}
return $builder;
}
/**
* Get resource data for creating PDFs.
@ -164,7 +196,7 @@ class FacturaModel extends \App\Models\BaseModel {
$builder->where("t6.id", $pedido_id);
$builder->groupBy("t1.id"); // Agrupa por id de la factura
return $builder;
}