From 3dd9f8f7e33fccaa27b8e3874f0df0ec7ef3902b Mon Sep 17 00:00:00 2001 From: amazuecos Date: Wed, 23 Oct 2024 05:48:06 +0000 Subject: [PATCH] fix notification chat error cuando cliente no tiene facturas asociadas --- ci4/app/Models/Chat/ChatModel.php | 39 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/ci4/app/Models/Chat/ChatModel.php b/ci4/app/Models/Chat/ChatModel.php index 7405f3b9..07f34ed2 100644 --- a/ci4/app/Models/Chat/ChatModel.php +++ b/ci4/app/Models/Chat/ChatModel.php @@ -199,7 +199,7 @@ class ChatModel extends Model } public function getClienteChatPedidos(array $pedidos) : array { - $results = $this->db->table("chats") + $q = $this->db->table("chats") ->select([ "chats.id as chatId", "chats.pedido_id as pedidoId", @@ -208,10 +208,13 @@ class ChatModel extends Model "pedidos.id as title" ]) ->join("chat_departments","chat_departments.id = chats.chat_department_id","left") - ->join("pedidos","pedidos.id = chats.pedido_id","left") - ->whereIn("pedidos.id",$pedidos) - ->where("chats.chat_department_id is NOT NULL",NULL,FALSE) - ->get()->getResultObject(); + ->join("pedidos","pedidos.id = chats.pedido_id","left"); + if(count($pedidos)>0){ + $q->whereIn("pedidos.id",$pedidos); + }else{ + return []; + } + $results = $q->get()->getResultObject(); $chatMessageModel = model(ChatMessageModel::class); $count = 0; foreach ($results as $row) { @@ -227,7 +230,7 @@ class ChatModel extends Model } public function getClienteChatFacturas(array $facturas) : array { - $results = $this->db->table("chats") + $q = $this->db->table("chats") ->select([ "chats.id as chatId", "chats.factura_id as facturaId", @@ -236,10 +239,13 @@ class ChatModel extends Model "facturas.numero as title" ]) ->join("chat_departments","chat_departments.id = chats.chat_department_id","left") - ->join("facturas","facturas.id = chats.factura_id","left") - ->whereIn("facturas.id",$facturas) - ->where("chats.chat_department_id is NOT NULL",NULL,FALSE) - ->get()->getResultObject(); + ->join("facturas","facturas.id = chats.factura_id","left"); + if(count($facturas)>0){ + $q->whereIn("facturas.id",$facturas); + }else{ + return []; + } + $results = $q->get()->getResultObject(); $chatMessageModel = model(ChatMessageModel::class); $count = 0; foreach ($results as $row) { @@ -255,7 +261,7 @@ class ChatModel extends Model } public function getClienteChatPresupuestos(array $presupuestos) : array { - $results = $this->db->table("chats") + $q = $this->db->table("chats") ->select([ "chats.id as chatId", "chats.presupuesto_id as presupuestoId", @@ -264,10 +270,13 @@ class ChatModel extends Model "presupuestos.titulo as title" ]) ->join("chat_departments","chat_departments.id = chats.chat_department_id","left") - ->join("presupuestos","presupuestos.id = chats.presupuesto_id","left") - ->whereIn("presupuestos.id",$presupuestos) - ->where("chats.chat_department_id is NOT NULL",NULL,FALSE) - ->get()->getResultObject(); + ->join("presupuestos","presupuestos.id = chats.presupuesto_id","left"); + if(count($presupuestos)>0){ + $q->whereIn("presupuestos.id",$presupuestos); + }else{ + return []; + } + $results = $q->get()->getResultObject(); $chatMessageModel = model(ChatMessageModel::class); $count = 0; foreach ($results as $row) {