feat:chat modules

This commit is contained in:
amazuecos
2024-09-25 17:42:55 +00:00
parent 2fc9af9db4
commit c651db61ff
16 changed files with 808 additions and 382 deletions

View File

@ -98,4 +98,26 @@ class ChatDeparmentModel extends Model
}
return $departments;
}
public function getChatDepartmentUsers(int $chat_deparment_id)
{
$result = $this->db->table('chat_departments')
->select(
[
"users.*"
]
)
->join(
"chat_department_users",
"chat_department_users.chat_department_id = chat_departments.id",
'left'
)
->join(
"users",
"chat_department_users.user_id = users.id",
'left'
)->where("chat_departments.id",$chat_deparment_id)
->get()->getResultObject();
return $result;
}
}

View File

@ -47,4 +47,12 @@ class ChatDeparmentUserModel extends Model
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function getChatDepartmentUser(int $user_id)
{
return $this->db->table($this->table." t1")
->select("chat_departments.*")
->join("chat_departments","t1.chat_department_id = chat_departments.id","left")
->where("t1.user_id",$user_id)->get()->getResultObject();
}
}

View File

@ -2,7 +2,7 @@
namespace App\Models\Chat;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Model;
use stdClass;
@ -192,5 +192,74 @@ class ChatModel extends Model
->get()->getResultObject();
return $query;
}
public function getClienteChatPedidos(array $pedidos) : array
{
$results = $this->db->table("chats")
->select([
"chats.id as chatId",
"chats.pedido_id as pedidoId",
"chats.chat_department_id as chatDepartmentId",
"chat_departments.display as chatDisplay",
"pedidos.id as title"
])
->join("chat_departments","chat_departments.id = chats.chat_department_id","left")
->join("pedidos","pedidos.id = chats.pedido_id","left")
->join("chat_messages","pedidos.id = chats.pedido_id","left")
->whereNotIn("chat_messages.sender_id",[auth()->user()->id])
->whereIn("pedidos.id",$pedidos)
->get()->getResultObject();
$chatMessageModel = model(ChatMessageModel::class);
foreach ($results as $row) {
$row->messages = $chatMessageModel->get_chat_messages($row->chatId);
}
return $results;
}
public function getClienteChatFacturas(array $facturas) : array
{
$results = $this->db->table("chats")
->select([
"chats.id as chatId",
"chats.factura_id as facturaId",
"chats.chat_department_id as chatDepartmentId",
"chat_departments.display as chatDisplay",
"facturas.numero as title"
])
->join("chat_departments","chat_departments.id = chats.chat_department_id","left")
->join("facturas","facturas.id = chats.factura_id","left")
->join("chat_messages","chats.id = chat_messages.chat_id","left")
->whereNotIn("chat_messages.sender_id",[auth()->user()->id])
->whereIn("facturas.id",$facturas)
->get()->getResultObject();
$chatMessageModel = model(ChatMessageModel::class);
foreach ($results as $row) {
$row->messages = $chatMessageModel->get_chat_messages($row->chatId);
}
return $results;
}
public function getClienteChatPresupuestos(array $presupuestos) : array
{
$results = $this->db->table("chats")
->select([
"chats.id as chatId",
"chats.presupuesto_id as presupuestoId",
"chats.chat_department_id as chatDepartmentId",
"chat_departments.display as chatDisplay",
"presupuestos.titulo as title"
])
->join("chat_departments","chat_departments.id = chats.chat_department_id","left")
->join("presupuestos","presupuestos.id = chats.presupuesto_id","left")
->join("chat_messages","chats.id = chat_messages.chat_id","left")
->whereNotIn("chat_messages.sender_id",[auth()->user()->id])
->whereIn("presupuestos.id",$presupuestos)
->get()->getResultObject();
$chatMessageModel = model(ChatMessageModel::class);
foreach ($results as $row) {
$row->messages = $chatMessageModel->get_chat_messages($row->chatId);
}
return $results;
}
}

View File

@ -332,4 +332,39 @@ class ClienteModel extends \App\Models\BaseModel
return $builder->get()->getResultArray();
}
public function getClienteDataPresupuestoPedidoFactura(int $cliente_id) : array
{
$query = $this->db
->table($this->table." t1")
->select([
"t1.id as clienteId",
"presupuestos.id as presupuestoId",
"pedidos.id as pedidoId",
"presupuesto_estados.estado as presupuestoEstado",
"facturas_pedidos_lineas.factura_id as facturaId",
])
->join("presupuestos","t1.id = presupuestos.cliente_id","left")
->join("presupuesto_estados","presupuestos.estado_id = presupuesto_estados.id","left")
->join("pedidos_linea","presupuestos.id = pedidos_linea.presupuesto_id","left")
->join("pedidos","pedidos.id = pedidos_linea.pedido_id","left")
->join("facturas_pedidos_lineas","facturas_pedidos_lineas.pedido_linea_id = pedidos_linea.id","left")
->where("t1.id",$cliente_id);
$data = $query->get()->getResultObject();
$facturas = [];
$presupuestos = [];
$pedidos = [];
$result = [];
foreach ($data as $row) {
$facturas[] = $row->facturaId;
$presupuestos[] = $row->presupuestoId;
$pedidos[] = $row->pedidoId;
}
$result["facturas"] = array_unique(array_filter($facturas));
$result["presupuestos"] = array_unique(array_filter($presupuestos));
$result["pedidos"] = array_unique(array_filter($pedidos));
return $result;
}
}