add all message datatable and alertboxes instead of toast

This commit is contained in:
amazuecos
2025-03-25 20:14:07 +01:00
parent 20db840bf9
commit d15bbb42f1
10 changed files with 62 additions and 41 deletions

View File

@ -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
{