From 565ef7f170cc11f0901d67b8ff324e1f11630861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Mon, 12 May 2025 21:32:59 +0200 Subject: [PATCH] arreglado --- ci4/app/Models/Facturas/FacturaModel.php | 29 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/ci4/app/Models/Facturas/FacturaModel.php b/ci4/app/Models/Facturas/FacturaModel.php index 7c2c8142..1cfbddb0 100755 --- a/ci4/app/Models/Facturas/FacturaModel.php +++ b/ci4/app/Models/Facturas/FacturaModel.php @@ -27,9 +27,9 @@ class FacturaModel extends \App\Models\BaseModel ]; const SORTABLE_PEDIDOS = [ - 1 => "t1.numero", - 2 => "t2.nombre", - 3 => "t4.cantidad", + 1 => "t1.id", + 2 => "t1.numero", + 3 => "t4.ejemplares", 4 => "t2.nombre", 5 => "t1.estado", 6 => "t1.fecha_factura_at", @@ -129,7 +129,7 @@ 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", null); if (auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) { @@ -140,7 +140,7 @@ class FacturaModel extends \App\Models\BaseModel $builder->where("t1.cliente_id", $cliente_id); } - $builder->groupBy("t1.id"); + $builder->groupBy("t1.id"); //$query = $builder->getCompiledSelect(); return $builder; } @@ -166,9 +166,10 @@ class FacturaModel extends \App\Models\BaseModel return !empty($result); } - public function getSumatoriosFacturacionCliente($cliente_id = -1){ + public function getSumatoriosFacturacionCliente($cliente_id = -1) + { - if($cliente_id == -1){ + if ($cliente_id == -1) { return [ 'total_facturacion' => 0, 'total_pendiente' => 0 @@ -183,7 +184,7 @@ class FacturaModel extends \App\Models\BaseModel ->where('f.estado', 'validada') ->get() ->getResultObject(); - $result['total_facturacion'] = + $result['total_facturacion'] = round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2); $data = $this->db->table('facturas f') @@ -253,7 +254,17 @@ class FacturaModel extends \App\Models\BaseModel $builder->join("pedidos t6", "t5.pedido_id = t6.id", "left"); $builder->where("t1.deleted_at IS NULL"); - $builder->where("t6.id", $pedido_id); + $builder->groupStart() + ->where("t6.id", $pedido_id) + ->orWhere("t1.factura_rectificada_id IN ( + SELECT f.numero + FROM facturas f + JOIN facturas_pedidos_lineas fpl ON f.id = fpl.factura_id + JOIN pedidos_linea pl ON fpl.pedido_linea_id = pl.id + JOIN pedidos p ON pl.pedido_id = p.id + WHERE p.id = {$pedido_id} + )") + ->groupEnd(); $builder->groupBy("t1.id"); // Agrupa por id de la factura