mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
add chat direct
This commit is contained in:
@ -646,6 +646,8 @@ $routes->group('messages', ['namespace' => 'App\Controllers\Chat'], function ($r
|
||||
$routes->get('datatable/pedido', 'ChatController::datatable_pedido_messages', ['as' => 'getDatatablePedidoMessages']);
|
||||
$routes->get('datatable/factura', 'ChatController::datatable_factura_messages', ['as' => 'getDatatableFacturaMessages']);
|
||||
$routes->get('datatable/ots', 'ChatController::datatable_ot_messages', ['as' => 'getDatatableOtMessages']);
|
||||
$routes->get('datatable/direct', 'ChatController::datatable_direct_messages', ['as' => 'getDatatableDirectMessages']);
|
||||
|
||||
|
||||
$routes->post('direct', 'ChatController::store_new_direct_message', ['as' => 'storeNewDirectMessage']);
|
||||
$routes->post('direct/client', 'ChatController::store_new_direct_message_client', ['as' => 'storeNewDirectMessageClient']);
|
||||
|
||||
@ -363,14 +363,13 @@ class ChatController extends BaseController
|
||||
$query = $this->userModel->builder()->select(
|
||||
[
|
||||
"id",
|
||||
"CONCAT(first_name,' ',last_name,'(',username,')') as name"
|
||||
"CONCAT(first_name,' ',last_name) as name"
|
||||
]
|
||||
)
|
||||
->where("deleted_at", null)
|
||||
->whereNotIn("id", [auth()->user()->id]);
|
||||
if ($this->request->getGet("q")) {
|
||||
$query->groupStart()
|
||||
->orLike("users.username", $this->request->getGet("q"))
|
||||
->orLike("CONCAT(first_name,' ',last_name)", $this->request->getGet("q"))
|
||||
->groupEnd();
|
||||
}
|
||||
@ -538,6 +537,23 @@ class ChatController extends BaseController
|
||||
|
||||
->toJson(true);
|
||||
}
|
||||
public function datatable_direct_messages()
|
||||
{
|
||||
$auth_user_id = auth()->user()->id;
|
||||
$isAdmin = auth()->user()->inGroup('admin');
|
||||
$query = $this->chatModel->getQueryDatatableDirectMessages($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") : "")
|
||||
->edit("creator",fn($q) => $q->userId == $auth_user_id ? '<span class="badge text-bg-success w-100">'.lang("App.me").'</span>' : $q->creator)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId))
|
||||
->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')
|
||||
]])
|
||||
|
||||
->toJson(true);
|
||||
}
|
||||
public function get_notifications_not_viewed_from_message(int $chat_message_id)
|
||||
{
|
||||
$unviewedNotifications = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_message_id);
|
||||
@ -605,14 +621,13 @@ class ChatController extends BaseController
|
||||
$query = $this->userModel->builder()->select(
|
||||
[
|
||||
"id",
|
||||
"CONCAT(first_name,' ',last_name,'(',username,')') as name"
|
||||
"CONCAT(first_name,' ',last_name) as name"
|
||||
]
|
||||
)
|
||||
->where("deleted_at", null)
|
||||
->whereNotIn("id", $chat_users_id);
|
||||
if ($this->request->getGet("q")) {
|
||||
$query->groupStart()
|
||||
->orLike("users.username", $this->request->getGet("q"))
|
||||
->orLike("CONCAT(first_name,' ',last_name)", $this->request->getGet("q"))
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
@ -60,6 +60,7 @@ return [
|
||||
"subscribe_admin_chat_wrong" => "Tienes que seleccionar un usuario.",
|
||||
"help_select_chat_department_user" => "Solamente son listados los usuarios que pertenecen al personal. Los clientes no son listados, para añadirlos a la conversación se realiza desde la sección de mensajería de las diferentes secciones(presupuesto,pedido,factura ...)",
|
||||
"store_department" => "Crear departamento",
|
||||
"direct_messsages" => "Mensajes directos",
|
||||
"mail" => [
|
||||
"mail_subject" => "Nuevo mensaje"
|
||||
]
|
||||
|
||||
@ -136,7 +136,7 @@ class ChatModel extends Model
|
||||
$chatDeparmentModel = model(ChatDeparmentModel::class);
|
||||
$ot = $model->find($orden_trabajo_id);
|
||||
return $this->insert([
|
||||
"title" => "[OT]".$ot->id . "[" . $chatDeparmentModel->getDisplay($chat_department_id) . "]",
|
||||
"title" => "[OT]" . $ot->id . "[" . $chatDeparmentModel->getDisplay($chat_department_id) . "]",
|
||||
"orden_trabajo_id" => $orden_trabajo_id,
|
||||
"chat_department_id" => $chat_department_id
|
||||
]);
|
||||
@ -381,8 +381,7 @@ class ChatModel extends Model
|
||||
|
||||
$row->title = $row->facturaId;
|
||||
$rows_new[] = $row;
|
||||
}
|
||||
elseif ($row->ordenTrabajoId) {
|
||||
} elseif ($row->ordenTrabajoId) {
|
||||
// $row->model = $facturaModel->find($row->facturaId);
|
||||
$row->uri = "/chat/ot/" . $row->ordenTrabajoId . "#accordionChatOrdenTrabajo";
|
||||
$row->avatar = "OT";
|
||||
@ -439,8 +438,7 @@ class ChatModel extends Model
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
$row->title = $row->facturaId;
|
||||
$rows_new[] = $row;
|
||||
}
|
||||
elseif ($row->ordenTrabajoId) {
|
||||
} elseif ($row->ordenTrabajoId) {
|
||||
$row->uri = "/produccion/ordentrabajo/edit/" . $row->ordenTrabajoId . "#accordionChatOrdenTrabajo";
|
||||
$row->avatar = "OT";
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
@ -847,7 +845,7 @@ class ChatModel extends Model
|
||||
->join("users u", "u.id = cm.sender_id", 'left')
|
||||
->where("chats.presupuesto_id is NOT NULL", NULL, FALSE);
|
||||
|
||||
if (auth()->user()->inGroup("cliente-administrador","cliente")) {
|
||||
if (auth()->user()->inGroup("cliente-administrador", "cliente")) {
|
||||
$query->where('presupuestos.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
@ -878,7 +876,7 @@ class ChatModel extends Model
|
||||
->join("presupuestos", "presupuestos.id = pedidos_linea.presupuesto_id", 'left')
|
||||
->where("chats.pedido_id is NOT NULL", NULL, FALSE);
|
||||
|
||||
if (auth()->user()->inGroup("cliente-administrador","cliente")) {
|
||||
if (auth()->user()->inGroup("cliente-administrador", "cliente")) {
|
||||
$query->where('presupuestos.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
@ -908,10 +906,10 @@ class ChatModel extends Model
|
||||
->join("facturas", "facturas.id = chats.factura_id", "left")
|
||||
->where("chats.factura_id is NOT NULL", NULL, FALSE);
|
||||
|
||||
if (auth()->user()->inGroup("cliente-administrador","cliente")) {
|
||||
$query->where('facturas.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
if (auth()->user()->inGroup("cliente-administrador", "cliente")) {
|
||||
$query->where('facturas.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
return $query->groupBy('chatMessageId');
|
||||
}
|
||||
public function getQueryDatatableMessageOrdenTrabajo(int $user_id): BaseBuilder
|
||||
@ -938,10 +936,42 @@ class ChatModel extends Model
|
||||
->join("ordenes_trabajo", "ordenes_trabajo.id = chats.orden_trabajo_id", "left")
|
||||
->where("chats.orden_trabajo_id is NOT NULL", NULL, FALSE);
|
||||
|
||||
if (auth()->user()->inGroup("cliente-administrador","cliente")) {
|
||||
$query->where('facturas.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
if (auth()->user()->inGroup("cliente-administrador", "cliente")) {
|
||||
$query->where('facturas.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
return $query->groupBy('chatMessageId');
|
||||
}
|
||||
public function getQueryDatatableDirectMessages(): BaseBuilder
|
||||
{
|
||||
$query = $this->builder()
|
||||
->select([
|
||||
"chats.id",
|
||||
"cm.id as chatMessageId",
|
||||
"u.id as userId",
|
||||
"cm.message",
|
||||
"chats.created_at",
|
||||
"
|
||||
(
|
||||
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_messages cm", "chats.id = cm.chat_id", "left")
|
||||
->join("users u", "u.id = cm.sender_id", 'left')
|
||||
->where("chats.presupuesto_id", NULL)
|
||||
->where("chats.pedido_id", NULL)
|
||||
->where("chats.factura_id", NULL)
|
||||
->where("chats.orden_trabajo_id", NULL)
|
||||
->groupStart()
|
||||
->orWhere("cm.receiver_id",auth()->user()->id)
|
||||
->orWhere("cm.sender_id",auth()->user()->id)
|
||||
->groupEnd();
|
||||
|
||||
return $query->groupBy('chatMessageId');
|
||||
}
|
||||
public function createNewDirectChat(string $title, string $message, array $users)
|
||||
|
||||
@ -15,26 +15,33 @@ use Config\App;
|
||||
<div class="nav-tabs-shadow nav-align-top">
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<button type="button" class="nav-link active" role="tab" id="navs-top-align-all-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-all"><?=lang('App.global_all')?></button>
|
||||
<button type="button" class="nav-link active" role="tab" id="navs-top-align-all-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-all"><?= lang('App.global_all') ?></button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-presupuestos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-presupuestos"><?=lang('App.permisos_presupuestos')?></button>
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-direct-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-direct"><?= lang('Chat.direct_messsages') ?></button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-pedidos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-pedidos"><?=lang('App.permisos_pedidos')?></button>
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-presupuestos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-presupuestos"><?= lang('App.permisos_presupuestos') ?></button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-facturas-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-facturas"><?=lang('App.menu_facturas')?></button>
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-pedidos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-pedidos"><?= lang('App.permisos_pedidos') ?></button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-ot-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-ots"><?=lang('Produccion.ots')?></button>
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-facturas-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-facturas"><?= lang('App.menu_facturas') ?></button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-ot-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-ots"><?= lang('Produccion.ots') ?></button>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<div class="tab-content" id="message-datatables-container">
|
||||
<div class="tab-pane fade show active" id="navs-top-align-all">
|
||||
<div class="tab-pane fade show active" id="navs-top-align-all">
|
||||
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tableAllMessages"]) ?>
|
||||
</div>
|
||||
<div class="tab-pane fade show" id="navs-top-align-direct">
|
||||
<button class="btn-primary btn" id="btn-new-message"><span><?= lang('Chat.modal.new_message') ?></span></button>
|
||||
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tableDirectMessages"]) ?>
|
||||
</div>
|
||||
<div class="tab-pane fade show" id="navs-top-align-presupuestos">
|
||||
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tablePresupuestoMessages"]) ?>
|
||||
</div>
|
||||
@ -70,7 +77,8 @@ use Config\App;
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
<script type="module" src="<?= site_url('assets/js/safekat/pages/configuracion/messages/index.js') ?>">
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
< script src = "<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>" >
|
||||
</script>
|
||||
|
||||
</script>
|
||||
<?= $this->endSection() ?>
|
||||
Reference in New Issue
Block a user