mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
message chat section
This commit is contained in:
@ -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`
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user