mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
namespace App\Entities\Pedidos;
|
|
|
|
use App\Entities\Presupuestos\PresupuestoEntity;
|
|
use App\Entities\Produccion\OrdenTrabajoEntity;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoModel;
|
|
use App\Entities\Clientes\ClienteEntity;
|
|
use App\Entities\Configuracion\UbicacionesEntity;
|
|
use App\Models\Clientes\ClienteModel;
|
|
use App\Models\Pedidos\PedidoLineaModel;
|
|
use App\Models\Presupuestos\PresupuestoModel;
|
|
use CodeIgniter\Entity;
|
|
|
|
class PedidoEntity extends \CodeIgniter\Entity\Entity
|
|
{
|
|
protected $attributes = [
|
|
"id" => null,
|
|
"total_precio" => null,
|
|
"total_tirada" => null,
|
|
"estado" => null,
|
|
"inaplazable" => null,
|
|
"user_created_id" => null,
|
|
"user_updated_id" => null,
|
|
"user_validated_id" => null,
|
|
"fecha_entrega_real" => null,
|
|
"fecha_impresion" => null,
|
|
"fecha_encuadernado" => null,
|
|
"fecha_entrega_externo" => null,
|
|
"fecha_entrega_real_change_user_id" => null,
|
|
"fecha_impresion_change_user_id" => null,
|
|
"fecha_encuadernado_change_user_id" => null,
|
|
"fecha_entrega_change_externo_user_id" => null,
|
|
"inaplazable_change_user_id" => null,
|
|
"created_at" => null,
|
|
"updated_at" => null,
|
|
"validated_at" => null,
|
|
];
|
|
|
|
|
|
protected $casts = [
|
|
"total_precio" => "float",
|
|
"total_tirada" => "float",
|
|
];
|
|
/**
|
|
* Devuelve la entidad `PedidoEntity` con sus relaciones
|
|
*
|
|
* @return self
|
|
*/
|
|
public function withAllRelations() : self
|
|
{
|
|
$this->attributes["pedido_lineas"] = $this->lineas();
|
|
$this->attributes["presupuesto"] = $this->presupuesto();
|
|
|
|
return $this;
|
|
}
|
|
public function lineas(): array
|
|
{
|
|
$q = model(PedidoLineaModel::class);
|
|
$q->where("pedido_id",$this->attributes["id"]);
|
|
return $q->findAll();
|
|
}
|
|
public function ubicacion(): ?UbicacionesEntity
|
|
{
|
|
$lineas = $this->lineas();
|
|
$ubicacion = null;
|
|
foreach ($lineas as $key => $linea) {
|
|
$ubicacion = $linea->ubicacion();
|
|
}
|
|
return $ubicacion;
|
|
}
|
|
public function presupuesto() : PresupuestoEntity
|
|
{
|
|
$q = model(PedidoLineaModel::class);
|
|
$p = model(PresupuestoModel::class);
|
|
$presupuesto_id = $q->where("pedido_id",$this->attributes["id"])->first()->presupuesto_id;
|
|
return $p->find($presupuesto_id);
|
|
}
|
|
public function orden_trabajo() : ?OrdenTrabajoEntity
|
|
{
|
|
$m = model(OrdenTrabajoModel::class);
|
|
return $m->where("pedido_id",$this->attributes["id"])->first();
|
|
}
|
|
|
|
|
|
public function cliente() : ?ClienteEntity
|
|
{
|
|
$m = model(ClienteModel::class);
|
|
$pl = model(PedidoLineaModel::class);
|
|
$pm = model(PresupuestoModel::class);
|
|
$pedido_linea = $pl->where('pedido_id',$this->attributes["id"])->first();
|
|
$pre = $pm->find($pedido_linea->presupuesto_id);
|
|
return $m->find($pre->cliente_id);
|
|
}
|
|
}
|