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:
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user