send direct message to client users from presupuesto,facturas or pedido forms

This commit is contained in:
amazuecos
2024-12-15 17:57:22 +01:00
parent 7998e2424e
commit 4cacf28d49
12 changed files with 288 additions and 12 deletions

View File

@ -10,6 +10,9 @@ use App\Models\Chat\ChatModel;
use App\Models\ChatNotification;
use App\Models\ChatUser;
use App\Models\Clientes\ClienteModel;
use App\Models\Facturas\FacturaModel;
use App\Models\Pedidos\PedidoModel;
use App\Models\Presupuestos\PresupuestoModel;
use App\Models\Usuarios\UserModel;
use App\Services\MessageService;
use CodeIgniter\HTTP\ResponseInterface;
@ -396,6 +399,72 @@ class ChatController extends BaseController
return $this->response->setJSON($query->get()->getResultObject());
}
public function get_presupuesto_client_users(int $presupuesto_id)
{
$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());
}
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());
}
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());
}
public function store_hebra_presupuesto()
{
$auth_user = auth()->user();