Merge branch 'fix/sk-33' into 'main'

Fix/sk 33

See merge request jjimenez/safekat!647
This commit is contained in:
Alvaro
2025-04-02 20:26:33 +00:00
17 changed files with 229 additions and 147 deletions

View File

@ -210,7 +210,6 @@ class ChatController extends BaseController
}
public function store_message($model)
{
$data = $this->request->getPost();
$chatMessageEntity = $this->chatService->storeChatMessage($data["chat_department_id"],$model,$data["model_id"],$data);
return $this->response->setJSON($chatMessageEntity);
@ -338,67 +337,25 @@ class ChatController extends BaseController
{
$pm = model(PresupuestoModel::class);
$p = $pm->find($presupuesto_id);
$query = $this->userModel->builder()->select(
[
"id",
"CONCAT(first_name,' ',last_name,'(',username,')') as name"
]
)
->where("deleted_at", null)
->whereNotIn("id", [auth()->user()->id])
->where("cliente_id", $p->cliente_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();
}
return $this->response->setJSON($query->get()->getResultObject());
$cm = model(ClienteModel::class);
$clienteContactos = $cm->querySelectClienteContacto($p->cliente_id,$this->request->getGet('q'));
return $this->response->setJSON($clienteContactos);
}
public function get_pedido_client_users(int $pedido_id)
{
$pm = model(PedidoModel::class);
$p = $pm->find($pedido_id);
$query = $this->userModel->builder()->select(
[
"id",
"CONCAT(first_name,' ',last_name,'(',username,')') as name"
]
)
->where("deleted_at", null)
->whereNotIn("id", [auth()->user()->id])
->where("cliente_id", $p->cliente()->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();
}
return $this->response->setJSON($query->get()->getResultObject());
$cm = model(ClienteModel::class);
$clienteContactos = $cm->querySelectClienteContacto($p->cliente()->id,$this->request->getGet('q'));
return $this->response->setJSON($clienteContactos);
}
public function get_factura_client_users(int $factura_id)
{
$fm = model(FacturaModel::class);
$f = $fm->find($factura_id);
$query = $this->userModel->builder()->select(
[
"id",
"CONCAT(first_name,' ',last_name,'(',username,')') as name"
]
)
->where("deleted_at", null)
->whereNotIn("id", [auth()->user()->id])
->where("cliente_id", $f->cliente_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();
}
return $this->response->setJSON($query->get()->getResultObject());
$cm = model(ClienteModel::class);
$clienteContactos = $cm->querySelectClienteContacto($f->cliente_id,$this->request->getGet('q'));
return $this->response->setJSON($clienteContactos);
}
public function store_hebra(string $model)
{

View File

@ -151,7 +151,7 @@ class Users extends \App\Controllers\GoBaseController
foreach ($chatDepartments as $chatDepartment) {
$this->chat_department_user_model->insert([
"user_id" => $id,
"chat_department_id" => $this->chat_department_model->where("name", $chatDepartment)->first()["id"]
"chat_department_id" => $this->chat_department_model->where("name", $chatDepartment)->first()->id
]);
}

View File

@ -1,6 +1,7 @@
<?php
namespace App\Entities\Clientes;
use App\Models\Clientes\ClienteModel;
use CodeIgniter\Entity;
class ClienteContactoEntity extends \CodeIgniter\Entity\Entity
@ -21,4 +22,14 @@ class ClienteContactoEntity extends \CodeIgniter\Entity\Entity
"cliente_id" => "int",
"is_deleted" => "int",
];
public function getFullName() : string
{
return trim(implode(" ",[$this->attributes['nombre'] ?? '',$this->attributes["apellidos"] ?? '']));
}
public function cliente() : ?ClienteEntity
{
$cm = model(ClienteModel::class);
return $cm->find($this->attributes["cliente_id"]);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Entities\Clientes;
use App\Entities\Usuarios\UserEntity;
use App\Models\Clientes\ClienteContactoModel;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Entity;
@ -71,9 +72,25 @@ class ClienteEntity extends \CodeIgniter\Entity\Entity
"user_update_id" => "int",
];
public function comercial() : UserEntity
public function comercial() : ?UserEntity
{
$m = model(UserModel::class);
return $m->find($this->attributes["comercial_id"]);
}
public function user() : ?UserEntity
{
$m = model(UserModel::class);
return $m->where("cliente_id",$this->attributes["id"])->first();
}
/**
* Devuelve un array con los contactos del cliente
*
* @return array<ClienteContactoEntity>
*/
public function contactos() : array
{
$m = model(ClienteContactoModel::class);
$clienteContactos = $m->where('cliente_id',$this->attributes['id'])->findAll();
return $clienteContactos ?? [];
}
}

View File

@ -30,6 +30,7 @@ class ClienteContactoModel extends \App\Models\BaseModel
protected $createdField = "created_at";
protected $updatedField = "updated_at";
protected $deletedField = 'deleted_at';
public static $labelField = "nombre";

View File

@ -287,8 +287,7 @@ class ClienteModel extends \App\Models\BaseModel
->select(
"t1.id AS id, t1.nombre AS nombre, t1.alias AS alias, t1.cif AS cif, t1.email AS email, t1.vencimiento AS vencimiento, t5.first_name AS comercial, t7.nombre AS forma_pago_id"
)
->where("is_deleted", 0);
;
->where("is_deleted", 0);;
$builder->join("users t5", "t1.comercial_id = t5.id", "left");
$builder->join("formas_pago t7", "t1.forma_pago_id = t7.id", "left");
@ -320,11 +319,11 @@ class ClienteModel extends \App\Models\BaseModel
->where("t1.id", $cliente_id);
$limite = $builder->get()->getResultObject();
if($limite){
if ($limite) {
$pendiente = $this->getPendienteCobro($cliente_id);
$credito_disponible = floatval($limite[0]->limite_credito) - $pendiente[0] - $pendiente[1] - floatval($total_pedido);
if($credito_disponible < 0)
if ($credito_disponible < 0)
return false;
return true;
}
@ -414,10 +413,9 @@ class ClienteModel extends \App\Models\BaseModel
return empty($search)
? $builder->get()->getResultObject()
: $builder
->groupStart()
->like("t1.nombre", $search)
->groupEnd()->get()->getResultObject();
->groupStart()
->like("t1.nombre", $search)
->groupEnd()->get()->getResultObject();
}
public function getPendienteCobro($cliente_id = -1)
@ -460,7 +458,6 @@ class ClienteModel extends \App\Models\BaseModel
} else {
return [0, round(floatval($pendiente_old), 2)];
}
}
private function getTotalPendienteOldERP($customer_id = -1)
@ -499,7 +496,8 @@ class ClienteModel extends \App\Models\BaseModel
}
}
public function getResumenPagos($cliente_id = -1){
public function getResumenPagos($cliente_id = -1)
{
$result = [];
$data = $this->db->table('facturas f')
@ -510,7 +508,7 @@ class ClienteModel extends \App\Models\BaseModel
->where('f.estado_pago', 'pendiente')
->get()
->getResultObject();
$result['total_facturas_sin_pagar'] =
$result['total_facturas_sin_pagar'] =
round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2);
$data = $this->db->table('facturas_pagos fp')
@ -523,7 +521,7 @@ class ClienteModel extends \App\Models\BaseModel
->where('f.deleted_at IS NULL')
->get()
->getResultObject();
$result['total_facturas_pagadas'] =
$result['total_facturas_pagadas'] =
round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2);
$data = $this->db->table('facturas f')
@ -537,7 +535,7 @@ class ClienteModel extends \App\Models\BaseModel
->where('fp.deleted_at IS NULL')
->get()
->getResultObject();
$result['total_facturas_vencidas'] =
$result['total_facturas_vencidas'] =
round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2);
// Subconsulta para verificar la existencia en facturas_lineas
@ -559,7 +557,7 @@ class ClienteModel extends \App\Models\BaseModel
->get()
->getResultObject();
$query = $this->db->getLastQuery();
$result['total_pedidos_produccion'] =
$result['total_pedidos_produccion'] =
round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2);
// Subconsulta para calcular el total de pedidos finalizados
@ -572,12 +570,12 @@ class ClienteModel extends \App\Models\BaseModel
->where("NOT EXISTS $subquery_facturas", null, false) // Implementación manual de NOT EXISTS
->get()
->getResultObject();
$result['total_pedidos_finalizados'] =
$result['total_pedidos_finalizados'] =
round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2);
$result['total_pendiente'] =
$result['total_pendiente'] =
$result['total_facturas_sin_pagar']
+ $result['total_pedidos_produccion']
+ $result['total_pedidos_produccion']
+ $result['total_pedidos_finalizados'];
$result['total_pendiente'] = round(floatval($result['total_pendiente']), 2);
@ -588,8 +586,28 @@ class ClienteModel extends \App\Models\BaseModel
->get()
->getResultObject()[0]->limite_credito;
$result['limite_credito'] = round(floatval($result['limite_credito']), 2);
$result['margen_disponible'] = round(floatval( $result['limite_credito']-$result['total_pendiente']), 2);
$result['margen_disponible'] = round(floatval($result['limite_credito'] - $result['total_pendiente']), 2);
return $result;
}
public function querySelectClienteContacto(int $cliente_id, string $q): array
{
$query = $this->builder()->select([
"cliente_contactos.id",
"CONCAT(COALESCE(cliente_contactos.nombre,''),' ',COALESCE(cliente_contactos.apellidos,'')) as name",
'cliente_contactos.cargo as description'
])
->join('cliente_contactos', 'cliente_contactos.cliente_id = clientes.id', 'left')
->where('cliente_contactos.deleted_at',null)
->where('cliente_contactos.email is NOT NULL',null,false)
->where('cliente_contactos.cliente_id', $cliente_id);
if ($q) {
$query->groupStart();
$query->orLike('name', $q);
$query->orLike('description', $q);
$query->groupEnd();
}
return $query->get()->getResultArray() ?? [];
}
}

View File

@ -6,6 +6,7 @@ use App\Controllers\Configuracion\ConfigVariables;
use App\Entities\Chat\ChatEntity;
use App\Entities\Chat\ChatMessageEntity;
use App\Entities\Chat\ChatNotificationEntity;
use App\Entities\Clientes\ClienteContactoEntity;
use App\Entities\Usuarios\UserEntity;
use App\Models\Chat\ChatDeparmentModel;
use App\Models\Chat\ChatDeparmentUserModel;
@ -13,11 +14,13 @@ use App\Models\Chat\ChatMessageModel;
use App\Models\Chat\ChatModel;
use App\Models\ChatNotification;
use App\Models\ChatUser;
use App\Models\Clientes\ClienteContactoModel;
use App\Models\Configuracion\ConfigVariableModel;
use App\Models\Presupuestos\PresupuestoModel;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Config\BaseService;
use App\Services\EmailService;
use Exception;
class ChatService extends BaseService
{
@ -31,6 +34,7 @@ class ChatService extends BaseService
protected PresupuestoModel $presupuestoModel;
protected ChatDeparmentModel $chatDepartmentModel;
protected ChatDeparmentUserModel $chatDepartmentUserModel;
protected ClienteContactoModel $clienteContactoModel;
protected ConfigVariableModel $configVariables;
protected array $modelFkMap = [
"presupuesto" => "presupuesto_id",
@ -43,6 +47,7 @@ class ChatService extends BaseService
$this->emailService = service('emailService'); // Usar el servicio de email de Safekat y no el de CI4
$this->userModel = model(UserModel::class);
$this->chatModel = model(ChatModel::class);
$this->clienteContactoModel = model(ClienteContactoModel::class);
$this->chatMessageModel = model(ChatMessageModel::class);
$this->chatNotificationModel = model(ChatNotification::class);
$this->chatDepartmentUserModel = model(ChatDeparmentUserModel::class);
@ -64,13 +69,19 @@ class ChatService extends BaseService
$this->chatEntity = $this->chatModel->find($chatId);
}
if ($data["client"]) {
$cliente_in_department = $this->chatDepartmentUserModel
->where('chat_department_id', $chatDepartmentId)
->where('user_id', $data['client'])
->where($this->modelFkMap[$model], $modelId)
->first();
if ($cliente_in_department == null) {
$this->chatDepartmentUserModel->insert(['chat_department_id' => $chatDepartmentId, 'user_id' => $data['client'], $this->modelFkMap[$model] => $modelId]);
$cliente_contacto = $this->clienteContactoModel->find($data["client"]);
if ($cliente_contacto) {
$userClienteContacto = $cliente_contacto->cliente()->user();
if ($userClienteContacto) {
$cliente_in_department = $this->chatDepartmentUserModel
->where('chat_department_id', $chatDepartmentId)
->where('user_id', $userClienteContacto->id)
->where($this->modelFkMap[$model], $modelId)
->first();
if ($cliente_in_department == null) {
$this->chatDepartmentUserModel->insert(['chat_department_id' => $chatDepartmentId, 'user_id' => $userClienteContacto->id, $this->modelFkMap[$model] => $modelId]);
}
}
}
}
$userAdminDepartment = $this->chatDepartmentUserModel
@ -91,9 +102,9 @@ class ChatService extends BaseService
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $this->chatEntity->id, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
$chatMessageEntity = $this->chatMessageModel->find($chat_message_id);
if ($data["client"]) {
$userClient = $this->userModel->find($data['client']);
if ($userClient) {
$this->sendMessageNotificationEmail($chatMessageEntity, $userClient);
$cliente_contacto = $this->clienteContactoModel->find($data["client"]);
if ($cliente_contacto) {
$this->sendMessageNotificationToClienteContacto($chatMessageEntity, $cliente_contacto);
}
}
return $chatMessageEntity;
@ -156,6 +167,7 @@ class ChatService extends BaseService
);
return true;
}
public function getHebras(string $model, int $modelId): array
{
$chats = $this->chatModel->where('chat_department_id', null)
@ -195,6 +207,23 @@ class ChatService extends BaseService
]);
return $this->emailService->send($subject, $message, $toEmail);
}
public function sendMessageNotificationToClienteContacto(ChatMessageEntity $chatMessageEntity, ClienteContactoEntity $clienteContacto): bool
{
$users = auth()->getProvider();
$toEmail = $clienteContacto->email;
$subject = '[Safekat]' . lang('Chat.mail.mail_subject') . ' - ' . $chatMessageEntity->chat()->title;
$message = view('themes/vuexy/mail/messageNotificationClienteContacto', [
"header" => lang('Chat.mail.mail_subject'),
"contacto" => $clienteContacto,
"data" => $chatMessageEntity,
]);
if ($toEmail) {
return $this->emailService->send($subject, $message, $toEmail);
} else {
throw new Exception('Cliente contacto no tiene email');
}
}
}

View File

@ -1,6 +1,6 @@
<div class="col-md-12" id="chat-factura" data-id="<?= $modelId ?>">
<div class="container-xxl flex-grow-1 container-p-y" id="chat-factura" data-id="<?= $modelId ?>">
<div class="app-chat card overflow-hidden">
<div class="app-chat card overflow-hidden border">
<div class="row g-0">
<!-- Chat & Contacts -->
@ -26,7 +26,7 @@
</div>
<hr class="container-m-nx m-0" />
<div class="sidebar-body">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<div class="mb-0 px-4 pt-3 pb-2">
<select class="form-control chat-search-client"></select>
</div>
@ -68,7 +68,7 @@
</div>
<div class="d-flex align-items-center">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
@ -121,7 +121,7 @@
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
<div class="message-actions d-flex align-items-center">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>

View File

@ -13,19 +13,19 @@
<div class="nav-align-top">
<ul class="nav nav-pills mb-4" role="tablist">
<li class="nav-item">
<button type="button" class="nav-link <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button>
<button type="button" class="nav-link <?=!auth()->user()->inGroup('cliente-editor','cliente') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button>
</li>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<li class="nav-item">
<button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?=lang('Chat.messages_internal')?></button>
</li>
<?php } ?>
</ul>
<div class="tab-content">
<div class="tab-pane fade <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<div class="tab-pane fade <?=!auth()->user()->inGroup('cliente-editor','cliente') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<?= view("themes/vuexy/components/chat_factura", data: ["modelId" => $modelId,"type" => "factura"]) ?>
</div>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel">
<?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId,"type" => "factura"]) ?>
</div>

View File

@ -13,19 +13,19 @@
<div class="nav-align-top">
<ul class="nav nav-pills mb-4" role="tablist">
<li class="nav-item">
<button type="button" class="nav-link <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button>
<button type="button" class="nav-link <?=!auth()->user()->inGroup('cliente-editor','cliente') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button>
</li>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<li class="nav-item">
<button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?=lang('Chat.messages_internal')?></button>
</li>
<?php } ?>
</ul>
<div class="tab-content">
<div class="tab-pane fade <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<div class="tab-pane fade <?=!auth()->user()->inGroup('cliente-editor','cliente') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<?= view("themes/vuexy/components/chat_pedido", data: ["modelId" => $modelId, "type" => "pedido"]) ?>
</div>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel">
<?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId, "type" => "pedido"]) ?>
</div>

View File

@ -13,19 +13,19 @@
<div class="nav-align-top">
<ul class="nav nav-pills mb-4" role="tablist">
<li class="nav-item">
<button type="button" class="nav-link <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button>
</li>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
<li class="nav-item">
<button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?=lang('Chat.messages_internal')?></button>
<button type="button" class="nav-link <?= !auth()->user()->inGroup('cliente-editor','cliente') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?= lang('Chat.messages_client') ?></button>
</li>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<li class="nav-item">
<button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?= lang('Chat.messages_internal') ?></button>
</li>
<?php } ?>
</ul>
<div class="tab-content">
<div class="tab-pane fade <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<div class="tab-pane fade <?= !auth()->user()->inGroup('cliente-editor','cliente') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<?= view("themes/vuexy/components/chat_presupuesto", data: ["modelId" => $modelId, "type" => "presupuesto"]) ?>
</div>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel">
<?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId, "type" => "presupuesto"]) ?>
</div>

View File

@ -1,6 +1,6 @@
<div class="col-md-12" id="chat-pedido" data-id="<?= $modelId ?>">
<div class="container-xxl flex-grow-1 container-p-y" id="chat-pedido" data-id="<?= $modelId ?>">
<div class="app-chat card overflow-hidden">
<div class="app-chat card overflow-hidden border">
<div class="row g-0">
<!-- Chat & Contacts -->
@ -27,7 +27,7 @@
<hr class="container-m-nx m-0" />
<div class="sidebar-body">
<div class="chat-contact-list-item-title">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<div class="mb-0 px-4 pt-3 pb-2">
<select class="form-control chat-search-client"></select>
</div>
@ -67,7 +67,7 @@
</div>
<div class="d-flex align-items-center">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
@ -118,7 +118,7 @@
<input class="form-control message-input border-0 me-3 shadow-none"
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
<div class="message-actions d-flex align-items-center">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>

View File

@ -1,4 +1,4 @@
<div class="col-md-12" id="chat-presupuesto" data-id="<?= $modelId ?>">
<div class="container-xxl flex-grow-1 container-p-y" id="chat-presupuesto" data-id="<?= $modelId ?>">
<div class="app-chat card overflow-hidden border">
<div class="row g-0">
@ -26,7 +26,7 @@
<hr class="container-m-nx m-0" />
<div class="sidebar-body">
<div class="chat-contact-list-item-title">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<div class="mb-0 px-4 pt-3 pb-2">
<select class="form-control chat-search-client"></select>
</div>
@ -69,7 +69,7 @@
</div>
<div class="d-flex align-items-center">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
@ -96,7 +96,7 @@
</div>
</div>
</div>
<div class="chat-history-body bg-body ">
<div class="chat-history-body bg-body">
<div class="d-flex justify-content-center chat-loader">
<div class="sk-wave sk-primary ">
<div class="sk-wave-rect"></div>
@ -117,7 +117,7 @@
<input class="form-control message-input border-0 me-3 shadow-none"
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
<div class="message-actions d-flex align-items-center">
<?php if (auth()->user()->inGroup('admin')): ?>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')): ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>

View File

@ -15,14 +15,16 @@ const chatContactsBody = $('.app-chat-contacts .sidebar-body'),
if (chatContactsBody.length) {
new PerfectScrollbar(chatContactsBody[0], {
wheelPropagation: false,
suppressScrollX: true
suppressScrollX: true,
scrollingThreshold : 200,
});
}
if (chatHistoryBody.length) {
new PerfectScrollbar(chatHistoryBody[0], {
new PerfectScrollbar(document.querySelector('.chat-history-body'), {
wheelPropagation: false,
suppressScrollX: true
suppressScrollX: true,
scrollingThreshold : 200,
});
}

View File

@ -0,0 +1,29 @@
<?= $this->extend('themes/vuexy/mail/mail_layout') ?>
<?= $this->section('content'); ?>
<div class="card email-card-last mx-sm-4 mx-3 mt-4">
<div class="card-header d-flex flex-wrap">
<h6 class="m-0"><?= $data->chat()->title ?></h6>
</div>
<div class="card-header d-flex justify-content-between align-items-center flex-wrap">
<div class="d-flex align-items-center mb-sm-0 mb-3">
<img src="https://gravatar.com/avatar/<?= md5($contacto->email) ?>s=40" alt="user-avatar" class="flex-shrink-0 rounded-circle me-3" height="30" width="30">
<div class="flex-grow-1 ms-1">
<h6 class="m-0"><?= $contacto->full_name?></h6>
</div>
</div>
<div class="d-flex align-items-center">
<p class="mb-0 me-3 text-muted"><?= $data->created_at ?></p>
</div>
</div>
<div class="card-body">
<div class="chat-message chat-message">
<div class="chat-message-wrapper flex-grow-1">
<p><?= $data->message ?></p>
</div>
</div>
</div>
</div>
<?= $this->endSection() ?>

View File

@ -68,12 +68,16 @@ class Chat {
}
if (this.chatHistoryBody[0]) {
console.log("History body");
this.scrollbarChatHistory = new PerfectScrollbar(this.chatHistoryBody[0], {
wheelPropagation: false,
suppressScrollX: true,
});
}
if (this.chatHistoryBody.length) {
this.chatHistoryBody.scrollTop(0,this.chatHistoryBody[0].scrollHeight);
}
}
initDirectMessage() {
@ -112,9 +116,22 @@ class Chat {
setInterval(this._handleReloadChatDirectMessages.bind(this), 10000)
}
initSelectClient() {
this.selectClientUser = new ClassSelect(this.selectItem, `/chat/direct/client/users/select/${this.chatType}/${this.modelId}`, "Seleccione contacto", true)
this.selectClientUser = new ClassSelect(
this.selectItem, `/chat/direct/client/users/select/${this.chatType}/${this.modelId}`,
"Seleccione contacto", true)
this.selectClientUser.config.templateResult = (state) => {
let $state = $(`
<div class="d-flex flex-column justify-content-start align-items-start gap-1">
<span class="item-text">${state.text}</span>
<span class="badge text-bg-secondary">${state.desc ?? ''}</span>
</div>`)
console.log(state)
return $state;
}
this.selectClientUser.init()
this.selectItem.on('change', () => {
console.log(this.selectClientUser.getVal(),this.selectClientUser.getText())
if (this.selectClientUser.getVal()) {
this.sendBtnMessageDepartment.attr('disabled', null)
} else {
@ -135,7 +152,7 @@ class Chat {
this._handleGetChatList()
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this))
this.scrollbarChatHistory.update()
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
this.initSelectClient()
// setInterval(this._getChatMessage.bind(this), 10000)
@ -302,7 +319,7 @@ class Chat {
null,
null,
(data) => {
},
null
@ -364,7 +381,7 @@ class Chat {
<div class="chat-message-text">
<p class="mb-0">${chatMessage?.message}</p>
</div>
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
<small>${chatMessage?.user?.first_name + " " + chatMessage?.user?.last_name}</small>
</div>
@ -821,7 +838,7 @@ class Chat {
}
const addInternalNotification = (e) => {
const addInternalNotification = (e) => {
let numberOfMessages = e.unreadMessages
if (numberOfMessages > 0) {
$("#chat-notification-list").append(
@ -841,7 +858,7 @@ const addInternalNotification = (e) => {
)
}
}
const addDepartmentNotification = (e) => {
const addDepartmentNotification = (e) => {
let numberOfMessages = e.unreadMessages
if (numberOfMessages > 0) {
$("#chat-notification-list").append(
@ -862,8 +879,7 @@ const addDepartmentNotification = (e) => {
}
}
const addNotificationsToDom = (data) =>
{
const addNotificationsToDom = (data) => {
$("#chat-notification-list").empty()
if (data.totalMessages > 0) {
$("#chat-message-notification-title").addClass("d-none")
@ -874,11 +890,13 @@ const addNotificationsToDom = (data) =>
$("#chat-notification-number").addClass("d-none")
$("#chat-notification-number").text(0)
}
data.departmentNotifications?.map( e => {
addDepartmentNotification(e)}
data.departmentNotifications?.map(e => {
addDepartmentNotification(e)
}
)
data.internalNotifications?.map(e => {
addInternalNotification(e)}
addInternalNotification(e)
}
)
}

View File

@ -1,13 +1,13 @@
.app-chat {
position: relative;
height: calc(100vh - 11.5rem) !important;
height: calc(75vh - 11.5rem) !important;
}
a.send-msg-btn {
color: white
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat {
height: calc(100vh - 20rem - 2.2rem) !important;
height: calc(75vh - 20rem - 2.2rem) !important;
}
}
@media (max-width: 992px) {
@ -28,14 +28,14 @@ a.send-msg-btn {
.app-chat .app-chat-contacts {
position: absolute;
left: calc(-21rem - 1rem);
height: calc(100vh - 11.5rem);
height: calc(75vh - 11.5rem);
width: 21rem;
flex-basis: 21rem;
transition: all 0.25s ease;
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-contacts {
height: calc(100vh - 20rem - 2.2rem);
height: calc(75vh - 20rem - 2.2rem);
}
}
@media (min-width: 992px) {
@ -47,17 +47,17 @@ a.send-msg-btn {
left: 0rem;
}
.app-chat .app-chat-contacts .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 3.9rem);
height: calc(calc(100vh - 11.5rem) - 3.5rem);
height: calc(calc(75vh - 11.5rem) - 3.9rem);
height: calc(calc(75vh - 11.5rem) - 3.5rem);
}
@media (min-width: 992px) {
.layout-horizontal .app-chat .app-chat-contacts .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 5rem + calc(2.2rem / 2));
height: calc(calc(75vh - 11.5rem) - 5rem + calc(2.2rem / 2));
}
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-contacts .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 5rem - 2.2rem);
height: calc(calc(75vh - 11.5rem) - 5rem - 2.2rem);
}
}
@ -90,14 +90,14 @@ a.send-msg-btn {
top: 0;
left: calc(-21rem - 1rem);
width: 21rem;
height: calc(100vh - 11.5rem);
height: calc(75vh - 11.5rem);
opacity: 0;
z-index: 5;
transition: all 0.25s ease;
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-sidebar-left {
height: calc(100vh - 20rem - 2.2rem);
height: calc(75vh - 20rem - 2.2rem);
}
}
.app-chat .app-chat-sidebar-left.show {
@ -105,21 +105,21 @@ a.send-msg-btn {
opacity: 1;
}
.app-chat .app-chat-sidebar-left .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 11.5rem);
height: calc(calc(75vh - 11.5rem) - 11.5rem);
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-sidebar-left .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 10.9rem - 2.2rem);
height: calc(calc(75vh - 11.5rem) - 10.9rem - 2.2rem);
}
}
.app-chat .app-chat-history {
position: relative;
height: calc(100vh - 11.5rem);
height: calc(75vh - 11.5rem);
transition: all 0.25s ease;
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-history {
height: calc(100vh - 20rem - 2.2rem);
height: calc(75vh - 20rem - 2.2rem);
}
}
.app-chat .app-chat-history .chat-history-header {
@ -129,13 +129,13 @@ a.send-msg-btn {
margin-bottom: 0.1rem;
}
.app-chat .app-chat-history .chat-history-body {
height: calc(100vh - 20.5rem);
height: calc(75vh - 20.5rem);
padding: 2rem 1.5rem;
overflow: hidden;
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-history .chat-history-body {
height: calc(100vh - 20.5rem - 2.2rem);
height: calc(75vh - 20.5rem - 2.2rem);
}
}
.app-chat .app-chat-history .chat-history-body .chat-history .chat-message {
@ -175,14 +175,14 @@ a.send-msg-btn {
top: 0;
right: calc(-21rem - 1rem);
width: 21rem;
height: calc(100vh - 11.5rem);
height: calc(75vh - 11.5rem);
opacity: 0;
z-index: 5;
transition: all 0.25s ease;
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-sidebar-right {
height: calc(100vh - 20rem - 2.2rem);
height: calc(75vh - 20rem - 2.2rem);
}
}
.app-chat .app-chat-sidebar-right.show {
@ -190,11 +190,11 @@ a.send-msg-btn {
right: 0;
}
.app-chat .app-chat-sidebar-right .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 11.75rem);
height: calc(calc(75vh - 11.5rem) - 11.75rem);
}
@media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-sidebar-right .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 11.1rem - 2.2rem);
height: calc(calc(75vh - 11.5rem) - 11.1rem - 2.2rem);
}
}