From 2e767889ef88dd36d03ad5640fd0247666af690f Mon Sep 17 00:00:00 2001 From: amazuecos Date: Fri, 29 Nov 2024 22:05:50 +0100 Subject: [PATCH] message chat section --- ci4/app/Config/Routes.php | 11 ++ ci4/app/Controllers/Chat/ChatController.php | 146 ++++++++++++++++-- ci4/app/Language/es/Chat.php | 6 +- ci4/app/Models/Chat/ChatDeparmentModel.php | 19 ++- ci4/app/Models/Chat/ChatModel.php | 105 ++++++++++++- ci4/app/Services/MessageService.php | 14 ++ .../themes/vuexy/components/chat_factura.php | 12 +- .../themes/vuexy/components/chat_pedido.php | 4 +- .../vuexy/components/chat_presupuesto.php | 14 +- .../modals/modalNewDirectMessage.php | 8 +- .../components/tables/messages_table.php | 15 ++ .../vuexy/form/mensajes/mensajesView.php | 65 ++++---- .../form/mensajes/messageChatFactura.php | 30 ++++ .../form/mensajes/messageChatInternal.php | 28 ++++ .../vuexy/form/mensajes/messageChatPedido.php | 27 ++++ .../form/mensajes/messageChatPresupuesto.php | 27 ++++ .../Views/themes/vuexy/main/defaultlayout.php | 12 -- httpdocs/assets/js/safekat/components/chat.js | 7 +- .../datatables/MessagesDatatable.js | 73 +++++++-- .../configuracion/messages/messagePage.js | 51 +++++- .../pages/messages/facturaMessagePage.js | 9 ++ .../pages/messages/internalMessagePage.js | 10 ++ .../pages/messages/pedidoMessagePage.js | 9 ++ .../pages/messages/presupuestoMessagePage.js | 18 +++ 24 files changed, 615 insertions(+), 105 deletions(-) create mode 100644 ci4/app/Services/MessageService.php create mode 100644 ci4/app/Views/themes/vuexy/components/tables/messages_table.php create mode 100644 ci4/app/Views/themes/vuexy/form/mensajes/messageChatFactura.php create mode 100644 ci4/app/Views/themes/vuexy/form/mensajes/messageChatInternal.php create mode 100644 ci4/app/Views/themes/vuexy/form/mensajes/messageChatPedido.php create mode 100644 ci4/app/Views/themes/vuexy/form/mensajes/messageChatPresupuesto.php create mode 100644 httpdocs/assets/js/safekat/pages/messages/facturaMessagePage.js create mode 100644 httpdocs/assets/js/safekat/pages/messages/internalMessagePage.js create mode 100644 httpdocs/assets/js/safekat/pages/messages/pedidoMessagePage.js create mode 100644 httpdocs/assets/js/safekat/pages/messages/presupuestoMessagePage.js diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 9e77842c..f3ff7612 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -763,12 +763,22 @@ $routes->group('mensajes', ['namespace' => 'App\Controllers\Mensajeria'], functi }); $routes->group('messages', ['namespace' => 'App\Controllers\Chat'], function ($routes) { $routes->get('datatable', 'ChatController::datatable_messages', ['as' => 'getDatatableMessages']); + $routes->get('datatable/presupuesto', 'ChatController::datatable_presupuesto_messages', ['as' => 'getDatatablePresupuestoMessages']); + $routes->get('datatable/pedido', 'ChatController::datatable_pedido_messages', ['as' => 'getDatatablePedidoMessages']); + $routes->get('datatable/factura', 'ChatController::datatable_factura_messages', ['as' => 'getDatatableFacturaMessages']); + $routes->post('direct', 'ChatController::store_new_direct_message', ['as' => 'storeNewDirectMessage']); + $routes->post('direct/client', 'ChatController::store_new_direct_message_client', ['as' => 'storeNewDirectMessageClient']); + }); $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($routes) { $routes->get('direct/(:num)', 'ChatController::get_chat_direct_view/$1', ['as' => 'getChatDirectView']); + $routes->get('presupuesto/(:num)', 'ChatController::get_chat_presupuesto_view/$1', ['as' => 'getChatPresupuestoView']); + $routes->get('pedido/(:num)', 'ChatController::get_chat_pedido_view/$1', ['as' => 'getChatPedidoView']); + $routes->get('factura/(:num)', 'ChatController::get_chat_factura_view/$1', ['as' => 'getChatFacturaView']); + $routes->get('direct/conversation/(:num)', 'ChatController::get_chat_direct/$1', ['as' => 'getChatDirect']); $routes->get('direct/users/select/(:num)', 'ChatController::get_chat_direct_select_users/$1', ['as' => 'getChatDirectSelectUsers']); $routes->get('direct/users/(:num)', 'ChatController::get_chat_direct_users', ['as' => 'getChatDirectUsers']); @@ -779,6 +789,7 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route $routes->get('departments', 'ChatController::get_chat_departments', ['as' => 'getChatDepartments']); + $routes->get('departments/select', 'ChatController::get_chat_department_select', ['as' => 'getChatDepartmentSelect']); $routes->get('department/presupuesto/(:num)/(:num)', 'ChatController::get_chat_presupuesto/$1/$2', ['as' => 'getChatPresupuesto']); $routes->get('department/pedido/(:num)/(:num)', 'ChatController::get_chat_pedido/$1/$2', ['as' => 'getChatPedido']); $routes->get('department/factura/(:num)/(:num)', 'ChatController::get_chat_factura/$1/$2', ['as' => 'getChatFactura']); diff --git a/ci4/app/Controllers/Chat/ChatController.php b/ci4/app/Controllers/Chat/ChatController.php index 1712a73e..3526b6da 100644 --- a/ci4/app/Controllers/Chat/ChatController.php +++ b/ci4/app/Controllers/Chat/ChatController.php @@ -29,7 +29,7 @@ class ChatController extends BaseController protected ClienteModel $clienteModel; protected ChatUser $chatUserModel; protected ChatNotification $chatNotificationModel; - + protected array $viewData; protected static $viewPath = 'themes/vuexy/form/mensajes/'; @@ -57,6 +57,10 @@ class ChatController extends BaseController $data = $this->chatDeparmentModel->getChatDepartments(); return $this->response->setJSON($data); } + public function get_chat_department_select(){ + $query = $this->chatDeparmentModel->getChatDepartmentSelect($this->request->getGet("q")); + return $this->response->setJSON($query->get()->getResultObject()); + } public function get_chat_presupuesto(int $chat_department_id, int $presupuesto_id) { @@ -122,6 +126,62 @@ class ChatController extends BaseController return view(static::$viewPath . 'messageChat', $this->viewData); } + public function get_chat_presupuesto_view($chat_id) + { + $chat = $this->chatModel->find($chat_id); + $this->viewData['breadcrumb'] = [ + ['title' => lang("Chat.chat"), 'route' => route_to("mensajeriaView"), 'active' => false], + ['title' => $chat->title, 'route' => 'javascript:void(0);', 'active' => true] + ]; + $this->viewData["modelId"] = $chat->presupuesto_id; + $this->viewData["type"] = "presupuesto"; + $auth_user = auth()->user(); + $this->chatModel->setAsViewedChatUserNotifications($chat_id, $auth_user->id); + $this->chatModel->setAsUnviewedChatUserMessages($chat_id, $auth_user->id); + + if($chat->chat_department_id){ + return view(static::$viewPath . 'messageChatPresupuesto', $this->viewData); + }else{ + return view(static::$viewPath . 'messageChatInternal', $this->viewData); + } + } + public function get_chat_pedido_view($chat_id) + { + $chat = $this->chatModel->find($chat_id); + $this->viewData['breadcrumb'] = [ + ['title' => lang("Chat.chat"), 'route' => route_to("mensajeriaView"), 'active' => false], + ['title' => $chat->title, 'route' => 'javascript:void(0);', 'active' => true] + ]; + $this->viewData["modelId"] = $chat->pedido_id; + $this->viewData["type"] = "pedido"; + $auth_user = auth()->user(); + $this->chatModel->setAsViewedChatUserNotifications($chat_id, $auth_user->id); + $this->chatModel->setAsUnviewedChatUserMessages($chat_id, $auth_user->id); + if($chat->chat_department_id ){ + return view(static::$viewPath . 'messageChatPedido', $this->viewData); + }else{ + return view(static::$viewPath . 'messageChatInternal', $this->viewData); + } + } + public function get_chat_factura_view($chat_id) + { + $chat = $this->chatModel->find($chat_id); + $this->viewData['breadcrumb'] = [ + ['title' => lang("Chat.chat"), 'route' => route_to("mensajeriaView"), 'active' => false], + ['title' => $chat->title, 'route' => 'javascript:void(0);', 'active' => true] + ]; + $this->viewData["modelId"] = $chat->factura_id; + $this->viewData["type"] = "factura"; + $auth_user = auth()->user(); + $this->chatModel->setAsViewedChatUserNotifications($chat_id, $auth_user->id); + $this->chatModel->setAsUnviewedChatUserMessages($chat_id, $auth_user->id); + + if($chat->chat_department_id){ + return view(static::$viewPath . 'messageChatFactura', $this->viewData); + }else{ + return view(static::$viewPath . 'messageChatInternal', $this->viewData); + } + } public function get_chat(int $chat_id) { @@ -144,8 +204,8 @@ class ChatController extends BaseController $dataResponse = $this->chatMessageModel->find($chat_message_id); $chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]); foreach ($chatDepartmentUsers as $user) { - if($user->id != auth()->user()->id){ - $this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id,"user_id"=> $user->id]); + if ($user->id != auth()->user()->id) { + $this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]); } } return $this->response->setJSON($dataResponse); @@ -165,8 +225,8 @@ class ChatController extends BaseController $dataResponse = $this->chatMessageModel->find($chat_message_id); $chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]); foreach ($chatDepartmentUsers as $user) { - if($user->id != auth()->user()->id){ - $this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id,"user_id"=> $user->id]); + if ($user->id != auth()->user()->id) { + $this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]); } } return $this->response->setJSON($dataResponse); @@ -186,8 +246,8 @@ class ChatController extends BaseController $dataResponse = $this->chatMessageModel->find($chat_message_id); $chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]); foreach ($chatDepartmentUsers as $user) { - if($user->id != auth()->user()->id){ - $this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id,"user_id"=> $user->id]); + if ($user->id != auth()->user()->id) { + $this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]); } } return $this->response->setJSON($dataResponse); @@ -338,6 +398,7 @@ class ChatController extends BaseController } public function store_hebra_presupuesto() { + $auth_user = auth()->user(); $bodyData = $this->request->getPost(); $chat_id = $this->chatModel->insert([ "presupuesto_id" => $bodyData["modelId"], @@ -346,9 +407,10 @@ class ChatController extends BaseController $chatMessageId = $this->chatMessageModel->insert([ "chat_id" => $chat_id, "message" => $bodyData["message"], - "sender_id" => auth()->user()->id + "sender_id" => $auth_user->id ]); if (isset($bodyData["users"])) { + $bodyData["users"][] = $auth_user->id; $chatUserData = array_map(fn($x) => ["user_id" => $x, "chat_id" => $chat_id], $bodyData["users"]); $this->chatUserModel->insertBatch($chatUserData); foreach ($bodyData["users"] as $userId) { @@ -494,7 +556,45 @@ class ChatController extends BaseController ->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) ->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id)) - ->add("action", fn($q) => $q->id) + ->add("action", fn($q) => ["type" => "direct","modelId" => $q->id]) + ->toJson(true); + } + public function datatable_presupuesto_messages() + { + $auth_user_id = auth()->user()->id; + $query = $this->chatModel->getQueryDatatableMessagePresupuesto($auth_user_id); + return DataTable::of($query) + ->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "") + ->edit('updated_at', fn($q) => $q->updated_at ? 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) + ->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id)) + ->add("action", fn($q) => ["type" => "presupuesto","modelId" => $q->id]) + ->toJson(true); + } + public function datatable_pedido_messages() + { + $auth_user_id = auth()->user()->id; + $query = $this->chatModel->getQueryDatatableMessagePedido($auth_user_id); + return DataTable::of($query) + ->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "") + ->edit('updated_at', fn($q) => $q->updated_at ? 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) + ->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id)) + ->add("action", fn($q) => ["type" => "pedido","modelId" => $q->id]) + + ->toJson(true); + } + public function datatable_factura_messages() + { + $auth_user_id = auth()->user()->id; + $query = $this->chatModel->getQueryDatatableMessageFactura($auth_user_id); + return DataTable::of($query) + ->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "") + ->edit('updated_at', fn($q) => $q->updated_at ? 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) + ->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id)) + ->add("action", fn($q) => ["type" => "factura","modelId" => $q->id]) + ->toJson(true); } public function store_new_direct_message() @@ -516,6 +616,28 @@ class ChatController extends BaseController $this->chatModel->createNewDirectChat(...$bodyData); return $this->response->setJSON(["message" => lang("Chat.new_message_ok"), "status" => true]); } + public function store_new_direct_message_client() + { + $bodyData = $this->request->getPost(); + $rules = [ + "title" => "required|string", + "message" => "required|string", + "chat_department_id" => "required", + + ]; + if (!$this->validate($rules)) { + return $this->response->setStatusCode(400)->setJSON([ + 'message' => lang('App.global_alert_save_error'), + 'status' => 'error', + 'errors' => $this->validator->getErrors(), + ]); + } + $users = $this->chatDeparmentModel->getChatDepartmentUsers($bodyData["chat_department_id"]); + $bodyData["users"] = array_map(fn($q) => $q->id,$users); + dd(1); + $this->chatModel->createNewDirectChat(...$bodyData); + return $this->response->setJSON(["message" => lang("Chat.new_message_ok"), "status" => true]); + } public function get_chat_direct($chat_id) { $chatData = $this->chatModel->getChatDirect($chat_id); @@ -570,9 +692,9 @@ class ChatController extends BaseController $message = $this->chatMessageModel->get_chat_message($chat_message_id); return $this->response->setJSON($message); } - public function update_chat_direct_message_unread($chat_id){ - $this->chatModel->setAsUnviewedChatUserNotifications($chat_id,auth()->user()->id); + public function update_chat_direct_message_unread($chat_id) + { + $this->chatModel->setAsUnviewedChatUserNotifications($chat_id, auth()->user()->id); return $this->response->setJSON(["message" => "ok", "status" => true]); } - } diff --git a/ci4/app/Language/es/Chat.php b/ci4/app/Language/es/Chat.php index 9900a19c..1aca873e 100644 --- a/ci4/app/Language/es/Chat.php +++ b/ci4/app/Language/es/Chat.php @@ -3,6 +3,7 @@ return [ "chat" => "Mensajería", "messages" => "Mensajes", + "message" => "Mensaje", "modal" => [ "new_hebra" => "Nuevo hilo", "title" => "Título", @@ -21,10 +22,11 @@ return [ ], "new_message_ok" => "Mensaje enviado correctamente", "participants" => "Participantes", + "choose_department" => "Elige un departamento", "new_participant" => "Añadir nuevos participantes", "write_message_placeholder" => "Escriba aquí su mensaje...", "add_notification" => "Notificación", "check_as_unviewed" => "Marcar como no leídos", - "add_notification_message" => "Envía a los usuarios añadidos una notificación con los mensajes presentes en el chat." - + "add_notification_message" => "Envía a los usuarios añadidos una notificación con los mensajes presentes en el chat.", + "chat_title_presupuesto" => 'Presupuesto[{title,string,0}][{id}]' ]; \ No newline at end of file diff --git a/ci4/app/Models/Chat/ChatDeparmentModel.php b/ci4/app/Models/Chat/ChatDeparmentModel.php index 8f60babe..1681f814 100644 --- a/ci4/app/Models/Chat/ChatDeparmentModel.php +++ b/ci4/app/Models/Chat/ChatDeparmentModel.php @@ -10,7 +10,7 @@ class ChatDeparmentModel extends Model protected $table = 'chat_departments'; protected $primaryKey = 'id'; protected $useAutoIncrement = true; - protected $returnType = 'array'; + protected $returnType = 'object'; protected $useSoftDeletes = false; protected $protectFields = true; protected $allowedFields = [ @@ -126,4 +126,21 @@ class ChatDeparmentModel extends Model ->get()->getResultObject(); return $result; } + public function getDisplay(int $chat_deparment_id) : string + { + return $this->find($chat_deparment_id)->display; + } + public function getChatDepartmentSelect(string $query = null) + { + $q = $this->builder()->select([ + "id", + "display as name", + "description" + ]); + if($query){ + $q->orLike("display",$query) + ->orLike("name",$query); + } + return $q; + } } diff --git a/ci4/app/Models/Chat/ChatModel.php b/ci4/app/Models/Chat/ChatModel.php index 1862f609..78628011 100644 --- a/ci4/app/Models/Chat/ChatModel.php +++ b/ci4/app/Models/Chat/ChatModel.php @@ -88,7 +88,11 @@ class ChatModel extends Model public function createChatPresupuesto(int $chat_department_id, int $presupuesto_id): int { + $model = model(PresupuestoModel::class); + $chatDeparmentModel = model(ChatDeparmentModel::class); + $presupuesto = $model->find($presupuesto_id); return $this->insert([ + "title" => $presupuesto->titulo."[".$chatDeparmentModel->getDisplay($chat_department_id)."]", "presupuesto_id" => $presupuesto_id, "chat_department_id" => $chat_department_id ]); @@ -96,7 +100,11 @@ class ChatModel extends Model public function createChatPedido(int $chat_department_id, int $pedido_id): int { + $model = model(PedidoModel::class); + $chatDeparmentModel = model(ChatDeparmentModel::class); + $pedido = $model->getPedidoClientePresupuesto($pedido_id); return $this->insert([ + "title" => "Pedido ".$pedido->titulo."[".$chatDeparmentModel->getDisplay($chat_department_id)."]", "pedido_id" => $pedido_id, "chat_department_id" => $chat_department_id ]); @@ -104,7 +112,12 @@ class ChatModel extends Model public function createChatFactura(int $chat_department_id, int $factura_id): int { + + $model = model(FacturaModel::class); + $chatDeparmentModel = model(ChatDeparmentModel::class); + $factura = $model->find($factura_id); return $this->insert([ + "title" => "Factura ".$factura->numero."[".$chatDeparmentModel->getDisplay($chat_department_id)."]", "factura_id" => $factura_id, "chat_department_id" => $chat_department_id ]); @@ -370,6 +383,7 @@ class ChatModel extends Model $q = $this->db->table("chats") ->select([ "chats.id as chatId", + "chats.chat_department_id as chatDepartmentId", "chats.pedido_id as pedidoId", "chats.presupuesto_id as presupuestoId", "chats.factura_id as facturaId", @@ -390,10 +404,13 @@ class ChatModel extends Model $row->uri = "/presupuestocliente/edit/" . $row->presupuestoId; }else{ $row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId; - } $row->title = $row->presupuestoId; - $row->chatDisplay = $row->model->titulo; + if($row->chatDepartmentId){ + $row->chatDisplay = $row->model->titulo; + }else{ + $row->chatDisplay .="[INTERNAL]"; + } $row->avatar = "PRE"; $row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId); $rows_new[] = $row; @@ -401,6 +418,9 @@ class ChatModel extends Model $row->model = $pedidoModel->find($row->pedidoId); $row->uri = "/pedidos/edit/" . $row->pedidoId; $row->title = $row->pedidoId; + if($row->chatDepartmentId){ + $row->chatDisplay .= "[INTERNAL]"; + } $row->avatar = "P"; $row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId); $rows_new[] = $row; @@ -408,6 +428,9 @@ class ChatModel extends Model $row->model = $facturaModel->find($row->facturaId); $row->uri = "/facturas/edit/" . $row->facturaId; $row->avatar = "F"; + if($row->chatDepartmentId){ + $row->chatDisplay .= "[INTERNAL]"; + } $row->title = $row->facturaId; $row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId); $rows_new[] = $row; @@ -465,7 +488,8 @@ class ChatModel extends Model ->where("chats.presupuesto_id", $presupuesto_id); $data["chatId"] = $chat_id; $data["messages"] = $query->get()->getResultObject(); - $data["chatTitle"] = $this->find($chat_id)->title; + $data["chatTitle"] = "Presupuesto"."[".$presupuesto_id."] - "; + $data["chatTitle"].= $this->find($chat_id)->title; $data["users"] = $this->getChatUsers($chat_id); return $data; } @@ -485,7 +509,8 @@ class ChatModel extends Model ->where("chats.pedido_id", $pedido_id); $data["chatId"] = $chat_id; $data["messages"] = $query->get()->getResultObject(); - $data["chatTitle"] = $this->find($chat_id)->title; + $data["chatTitle"] = "Pedido"."[".$pedido_id."] - "; + $data["chatTitle"].= $this->find($chat_id)->title; $data["users"] = $this->getChatUsers($chat_id); return $data; } @@ -505,7 +530,8 @@ class ChatModel extends Model ->where("chats.factura_id", $factura_id); $data["chatId"] = $chat_id; $data["messages"] = $query->get()->getResultObject(); - $data["chatTitle"] = $this->find($chat_id)->title; + $data["chatTitle"] = "Factura"."[".$factura_id."] - "; + $data["chatTitle"].= $this->find($chat_id)->title; $data["users"] = $this->getChatUsers($chat_id); return $data; } @@ -680,9 +706,73 @@ class ChatModel extends Model ->where("pedido_id", null) ->where("presupuesto_id", null) ->where("factura_id", null) - ->where("title is NOT NULL", NULL, FALSE) ->where("chat_users.user_id",$user_id) - ->orderBy("created_at", "DESC"); + ->orderBy("created_at", "DESC") + ->groupBy("chats.id"); + + return $query; + } + public function getQueryDatatableMessagePresupuesto(int $user_id): BaseBuilder + { + $query = $this->builder() + ->select([ + "chats.id", + "chats.created_at", + "chats.updated_at", + "chats.title", + ]) + ->join("chat_users","chats.id = chat_users.chat_id","left") + ->join("presupuestos","presupuestos.id = chats.presupuesto_id",'left') + ->where("presupuesto_id is NOT NULL", NULL, FALSE) + ->groupBy("chats.id"); + if(auth()->user()->inGroup("admin") == false){ + $query->where('presupuestos.cliente_id',auth()->user()->cliente_id) + ->where("chat_department_id is NOT NULL",NULL,FALSE); + } + $query->orderBy("created_at", "DESC"); + return $query; + } + public function getQueryDatatableMessagePedido(int $user_id): BaseBuilder + { + $query = $this->builder() + ->select([ + "chats.id", + "chats.created_at", + "chats.updated_at", + "chats.title", + ]) + ->join("chat_users","chat_users.chat_id = chats.id","left") + ->join("pedidos_linea","pedidos_linea.pedido_id = chats.pedido_id",'left') + ->join("presupuestos","presupuestos.id = pedidos_linea.presupuesto_id",'left') + ->where("chats.pedido_id is NOT NULL", NULL, FALSE) + ->groupBy("chats.id"); + if(auth()->user()->inGroup("admin") == false){ + $query->where('presupuestos.cliente_id',auth()->user()->cliente_id) + ->where("chat_department_id is NOT NULL",NULL,FALSE); + } + $query->orderBy("created_at", "DESC"); + return $query; + } + public function getQueryDatatableMessageFactura(int $user_id): BaseBuilder + { + $query = $this->builder() + ->select([ + "chats.id", + "chats.created_at", + "chats.updated_at", + "chats.title", + ]) + ->join("chat_users","chat_users.chat_id = chats.id","left") + ->join("facturas","facturas.id = chats.factura_id","left") + ->where("chats.factura_id is NOT NULL", NULL, FALSE) + ->groupBy("chats.id"); + if(auth()->user()->inGroup("admin") == false){ + if(auth()->user()->inGroup("admin") == false){ + $query->where('facturas.cliente_id',auth()->user()->cliente_id) + ->where("chat_department_id is NOT NULL",NULL,FALSE); + } + } + $query->orderBy("created_at", "DESC"); return $query; } public function createNewDirectChat(string $title, string $message, array $users) @@ -704,6 +794,7 @@ class ChatModel extends Model $chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user_id]); } } + /** * Obtain users and messages from `chat_id` * diff --git a/ci4/app/Services/MessageService.php b/ci4/app/Services/MessageService.php new file mode 100644 index 00000000..8202257d --- /dev/null +++ b/ci4/app/Services/MessageService.php @@ -0,0 +1,14 @@ + diff --git a/ci4/app/Views/themes/vuexy/components/chat_pedido.php b/ci4/app/Views/themes/vuexy/components/chat_pedido.php index 8f6c3f89..64cb9c3c 100644 --- a/ci4/app/Views/themes/vuexy/components/chat_pedido.php +++ b/ci4/app/Views/themes/vuexy/components/chat_pedido.php @@ -32,9 +32,7 @@ diff --git a/ci4/app/Views/themes/vuexy/components/chat_presupuesto.php b/ci4/app/Views/themes/vuexy/components/chat_presupuesto.php index 0645bb2a..76c30928 100644 --- a/ci4/app/Views/themes/vuexy/components/chat_presupuesto.php +++ b/ci4/app/Views/themes/vuexy/components/chat_presupuesto.php @@ -30,18 +30,8 @@ diff --git a/ci4/app/Views/themes/vuexy/components/modals/modalNewDirectMessage.php b/ci4/app/Views/themes/vuexy/components/modals/modalNewDirectMessage.php index b0f416c5..87709867 100644 --- a/ci4/app/Views/themes/vuexy/components/modals/modalNewDirectMessage.php +++ b/ci4/app/Views/themes/vuexy/components/modals/modalNewDirectMessage.php @@ -28,13 +28,19 @@ + + diff --git a/ci4/app/Views/themes/vuexy/components/tables/messages_table.php b/ci4/app/Views/themes/vuexy/components/tables/messages_table.php new file mode 100644 index 00000000..22456941 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/components/tables/messages_table.php @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +
\ 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 db220a0c..2288d375 100644 --- a/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php +++ b/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php @@ -8,43 +8,48 @@
+ - +
-
diff --git a/ci4/app/Views/themes/vuexy/form/mensajes/messageChatFactura.php b/ci4/app/Views/themes/vuexy/form/mensajes/messageChatFactura.php new file mode 100644 index 00000000..ff05265c --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/mensajes/messageChatFactura.php @@ -0,0 +1,30 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/vuexy/main/defaultlayout') ?> + + +section('content'); ?> + +
+ + + $modelId]) ?> + +
+ + +endSection() ?> +section('css') ?> + + + + + +endSection() ?> +section("additionalExternalJs") ?> + + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/mensajes/messageChatInternal.php b/ci4/app/Views/themes/vuexy/form/mensajes/messageChatInternal.php new file mode 100644 index 00000000..0152bb79 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/mensajes/messageChatInternal.php @@ -0,0 +1,28 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/vuexy/main/defaultlayout') ?> + + +section('content'); ?> + +
+ $modelId, "type" => $type]) ?> +
+ + +endSection() ?> +section('css') ?> + + + + + +endSection() ?> +section("additionalExternalJs") ?> + + + + + +endSection() ?> diff --git a/ci4/app/Views/themes/vuexy/form/mensajes/messageChatPedido.php b/ci4/app/Views/themes/vuexy/form/mensajes/messageChatPedido.php new file mode 100644 index 00000000..db0e52d1 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/mensajes/messageChatPedido.php @@ -0,0 +1,27 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/vuexy/main/defaultlayout') ?> + + +section('content'); ?> + +
+ $modelId]) ?> +
+ + +endSection() ?> +section('css') ?> + + + + + +endSection() ?> +section("additionalExternalJs") ?> + + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/mensajes/messageChatPresupuesto.php b/ci4/app/Views/themes/vuexy/form/mensajes/messageChatPresupuesto.php new file mode 100644 index 00000000..8eda11d4 --- /dev/null +++ b/ci4/app/Views/themes/vuexy/form/mensajes/messageChatPresupuesto.php @@ -0,0 +1,27 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/vuexy/main/defaultlayout') ?> + + +section('content'); ?> + +
+ $modelId]) ?> +
+ + +endSection() ?> +section('css') ?> + + + + + +endSection() ?> +section("additionalExternalJs") ?> + + + + +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/main/defaultlayout.php b/ci4/app/Views/themes/vuexy/main/defaultlayout.php index fb1927cd..40358745 100644 --- a/ci4/app/Views/themes/vuexy/main/defaultlayout.php +++ b/ci4/app/Views/themes/vuexy/main/defaultlayout.php @@ -147,18 +147,6 @@ $picture = "/assets/img/default-user.png"; - -