diff --git a/ci4/app/Controllers/Chat/ChatController.php b/ci4/app/Controllers/Chat/ChatController.php index b54ec909..8a716f12 100644 --- a/ci4/app/Controllers/Chat/ChatController.php +++ b/ci4/app/Controllers/Chat/ChatController.php @@ -443,16 +443,17 @@ class ChatController extends BaseController { $auth_user_id = auth()->user()->id; $isAdmin = auth()->user()->inGroup('admin'); - $query = $this->chatModel->getQueryDatatable($auth_user_id); + $query = $this->chatModel->getQueryDatatable(); return DataTable::of($query) ->edit('created_at', fn($q) => Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i")) ->edit('updated_at', fn($q) => Time::createFromFormat('Y-m-d H:i:s', $q->updated_at)->format("d/m/Y H:i")) - ->add("creator", fn($q) => $this->chatModel->getChatFirstUser($q->id)->userFullName) + ->edit("creator",fn($q) => $q->userId == $auth_user_id ? ''.lang("App.me").'' : $q->creator) ->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id)) ->add("action", fn($q) => [ "type" => "direct", "modelId" => $q->id, "isAdmin" => $isAdmin, + "chatMessageId" => $q->chatMessageId, "lang" => [ "view_chat" => lang('Chat.view_chat'), "view_by_alt_message" => lang('Chat.view_by_alt_message') diff --git a/ci4/app/Language/es/App.php b/ci4/app/Language/es/App.php index 0704f891..db627a10 100755 --- a/ci4/app/Language/es/App.php +++ b/ci4/app/Language/es/App.php @@ -35,6 +35,7 @@ return [ "global_next" => "Siguiente", "global_save_file" => "Guardar ficheros", "global_upload_files" => "Subir ficheros", + "global_all" => "Todos", // LOGIN - Index "login_title" => "Iniciar sesión en su cuenta", "login_email" => "Correo Electrónico", diff --git a/ci4/app/Models/Chat/ChatModel.php b/ci4/app/Models/Chat/ChatModel.php index 3106560f..ddc06bcc 100644 --- a/ci4/app/Models/Chat/ChatModel.php +++ b/ci4/app/Models/Chat/ChatModel.php @@ -712,30 +712,39 @@ class ChatModel extends Model ->get()->getResultArray(); return $q; } - public function getQueryDatatable(int $user_id): BaseBuilder + public function getQueryDatatable(): BaseBuilder { $query = $this->builder() ->select([ "chats.id", + "cm.id as chatMessageId", + "u.id as userId", + "cm.message", "chats.created_at", - "cm.updated_at", - "chats.title", + " + ( + SELECT cm2.updated_at + FROM chat_messages cm2 + WHERE cm2.chat_id = chats.id + ORDER BY cm2.updated_at DESC LIMIT 1 + ) as updated_at", + "CONCAT(u.first_name,' ',u.last_name) as creator", + "chats.title as title", ]) - ->join("chat_users", "chat_users.chat_id = chats.id", "left") + ->join("presupuestos", "presupuestos.id = chats.presupuesto_id", 'left') ->join("chat_messages cm", "chats.id = cm.chat_id", "left") - ->where("chat_department_id", null) - ->where("pedido_id", null) - ->where("presupuesto_id", null) - ->where("factura_id", null) - ->where("chat_users.user_id", $user_id) - ->where("cm.updated_at = ( - SELECT cm2.updated_at - FROM chat_messages cm2 - WHERE cm2.chat_id = chats.id - ORDER BY cm2.updated_at DESC LIMIT 1 - )"); + ->join("users u", "u.id = cm.sender_id", 'left') + ->groupStart() + ->orWhere("chats.presupuesto_id is NOT NULL", NULL, FALSE) + ->orWhere("chats.pedido_id is NOT NULL", NULL, FALSE) + ->orWhere("chats.factura_id is NOT NULL", NULL, FALSE) + ->groupEnd(); - return $query; + if (auth()->user()->inGroup("admin") == false) { + $query->where('presupuestos.cliente_id', auth()->user()->cliente_id) + ->where("chats.chat_department_id is NOT NULL", NULL, FALSE); + } + return $query->groupBy('chatMessageId'); } public function getQueryDatatableMessagePresupuesto(int $user_id): BaseBuilder { diff --git a/ci4/app/Views/themes/vuexy/components/forms/chat_department.php b/ci4/app/Views/themes/vuexy/components/forms/chat_department.php index 07ff5bee..472219f6 100644 --- a/ci4/app/Views/themes/vuexy/components/forms/chat_department.php +++ b/ci4/app/Views/themes/vuexy/components/forms/chat_department.php @@ -14,7 +14,6 @@ -

diff --git a/ci4/app/Views/themes/vuexy/form/configuracion/messages/editChatDepartmentForm.php b/ci4/app/Views/themes/vuexy/form/configuracion/messages/editChatDepartmentForm.php index 1e7d0b05..3f8316d8 100644 --- a/ci4/app/Views/themes/vuexy/form/configuracion/messages/editChatDepartmentForm.php +++ b/ci4/app/Views/themes/vuexy/form/configuracion/messages/editChatDepartmentForm.php @@ -8,13 +8,13 @@
-

display ?>

+ "chatDepartmentForm", "entity" => $chat_department]) ?>
@@ -35,4 +35,4 @@ - endSection() ?> \ No newline at end of file + endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php b/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php index 3ef4954e..ef184ed5 100644 --- a/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php +++ b/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php @@ -1,3 +1,7 @@ + include('themes/_commonPartialsBs/select2bs5') ?> include('themes/_commonPartialsBs/datatables') ?> include('themes/_commonPartialsBs/_confirm2delete') ?> @@ -10,23 +14,25 @@