Merge branch 'fix/listado_facturas_pedidos' into 'main'

arreglado

See merge request jjimenez/safekat!807
This commit is contained in:
2025-05-12 19:33:21 +00:00

View File

@ -27,9 +27,9 @@ class FacturaModel extends \App\Models\BaseModel
]; ];
const SORTABLE_PEDIDOS = [ const SORTABLE_PEDIDOS = [
1 => "t1.numero", 1 => "t1.id",
2 => "t2.nombre", 2 => "t1.numero",
3 => "t4.cantidad", 3 => "t4.ejemplares",
4 => "t2.nombre", 4 => "t2.nombre",
5 => "t1.estado", 5 => "t1.estado",
6 => "t1.fecha_factura_at", 6 => "t1.fecha_factura_at",
@ -166,9 +166,10 @@ class FacturaModel extends \App\Models\BaseModel
return !empty($result); return !empty($result);
} }
public function getSumatoriosFacturacionCliente($cliente_id = -1){ public function getSumatoriosFacturacionCliente($cliente_id = -1)
{
if($cliente_id == -1){ if ($cliente_id == -1) {
return [ return [
'total_facturacion' => 0, 'total_facturacion' => 0,
'total_pendiente' => 0 'total_pendiente' => 0
@ -253,7 +254,17 @@ class FacturaModel extends \App\Models\BaseModel
$builder->join("pedidos t6", "t5.pedido_id = t6.id", "left"); $builder->join("pedidos t6", "t5.pedido_id = t6.id", "left");
$builder->where("t1.deleted_at IS NULL"); $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 $builder->groupBy("t1.id"); // Agrupa por id de la factura