Merge branch 'feat/ot-messages' into feat/sk-38+messages+dates

This commit is contained in:
amazuecos
2025-04-15 01:32:20 +02:00
17 changed files with 445 additions and 14 deletions

View File

@ -36,7 +36,9 @@ class ChatDepartmentEntity extends Entity
$chatDepartmentUsers = $m->where('chat_department_id',$this->attributes['id'])
->where('pedido_id',null)
->where('factura_id',null)
->where('presupuesto_id',null)->findAll();
->where('presupuesto_id',null)
->where('orden_trabajo_id',null)
->findAll();
return $chatDepartmentUsers;
}
/**
@ -62,6 +64,9 @@ class ChatDepartmentEntity extends Entity
case 'factura':
$m->where('pedido_id',$modelFkId);
break;
case 'ot':
$m->where('orden_trabajo_id',$modelFkId);
break;
default:
break;
}

View File

@ -20,6 +20,7 @@ class ChatDepartmentUserEntity extends Entity
"pedido_id" => null,
"factura_id" => null,
"presupuesto_id" => null,
"orden_trabajo_id" => null,
];
@ -29,6 +30,7 @@ class ChatDepartmentUserEntity extends Entity
"pedido_id" => "?integer",
"factura_id" => "?integer",
"presupuesto_id" => "?integer",
"orden_trabajo_id" => "?integer",
];
public function user() : ?UserEntity

View File

@ -5,11 +5,13 @@ namespace App\Entities\Chat;
use App\Entities\Facturas\FacturaEntity;
use App\Entities\Pedidos\PedidoEntity;
use App\Entities\Presupuestos\PresupuestoEntity;
use App\Entities\Produccion\OrdenTrabajoEntity;
use App\Entities\Usuarios\UserEntity;
use App\Models\Chat\ChatDeparmentModel;
use App\Models\Chat\ChatMessageModel;
use App\Models\ChatUser;
use App\Models\Facturas\FacturaModel;
use App\Models\OrdenTrabajo\OrdenTrabajoModel;
use App\Models\Pedidos\PedidoModel;
use App\Models\Presupuestos\PresupuestoModel;
use App\Models\Usuarios\UserModel;
@ -25,6 +27,7 @@ class ChatEntity extends Entity
"pedido_id" => null,
"presupuesto_id" => null,
"factura_id" => null,
"orden_trabajo_id" => null,
"title" => null
];
@ -34,6 +37,7 @@ class ChatEntity extends Entity
"pedido_id" => "?integer",
"presupuesto_id" => "?integer",
"factura_id" => "?integer",
"orden_trabajo_id" => "?integer",
"title" => "string"
];
@ -71,6 +75,11 @@ class ChatEntity extends Entity
$m = model(FacturaEntity::class);
return $m->find($this->attributes['factura_id']);
}
public function orden_trabajo(): ?OrdenTrabajoEntity
{
$m = model(OrdenTrabajoModel::class);
return $m->find($this->attributes['orden_trabajo_id']);
}
public function messages(): ?array
{
$m = model(ChatMessageModel::class);
@ -100,12 +109,14 @@ class ChatEntity extends Entity
$models = [
"presupuesto_id" => model(PresupuestoModel::class),
"pedido_id" => model(PedidoModel::class),
"factura_id" => model(FacturaModel::class)
"factura_id" => model(FacturaModel::class),
"orden_trabajo_id" => model(OrdenTrabajoModel::class),
];
$fks = [
"presupuesto_id" => $this->attributes["presupuesto_id"],
"pedido_id" => $this->attributes["pedido_id"],
"factura_id" => $this->attributes["factura_id"],
"orden_trabajo_id" => $this->attributes["orden_trabajo"],
];
foreach ($fks as $key => $fk) {
if ($fk) {
@ -123,6 +134,7 @@ class ChatEntity extends Entity
"presupuesto" => $this->attributes["presupuesto_id"],
"pedido" => $this->attributes["pedido_id"],
"factura" => $this->attributes["factura_id"],
"ot" => $this->attributes["orden_trabajo_id"],
];
foreach ($fks as $key => $fk) {
if ($fk) {