mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
157 lines
4.9 KiB
PHP
157 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace App\Entities\Produccion;
|
|
|
|
use App\Entities\Pedidos\PedidoEntity;
|
|
use App\Entities\Usuarios\UserEntity;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoDate;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoFileModel;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoTarea;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoUser;
|
|
use App\Models\Pedidos\PedidoModel;
|
|
use App\Models\Usuarios\UserModel;
|
|
|
|
use CodeIgniter\Entity\Entity;
|
|
use Picqer\Barcode\Renderers\PngRenderer;
|
|
use Picqer\Barcode\Types\TypeCode128;
|
|
|
|
class OrdenTrabajoEntity extends Entity
|
|
{
|
|
protected $attributes = [
|
|
"pedido_id" => null,
|
|
"user_created_id" => null,
|
|
"user_updated_id" => null,
|
|
"fecha_entrega_warning" => null,
|
|
"fecha_entrega_warning_revised" => null,
|
|
"total_tirada" => null,
|
|
"total_precio" => null,
|
|
"tipo_entrada" => "out",
|
|
"progreso" => 0.00,
|
|
"estado" => "I",
|
|
"comentarios" => null,
|
|
"revisar_formato" => null,
|
|
"revisar_lomo" => null,
|
|
"revisar_solapa" => null,
|
|
"revisar_isbn" => null,
|
|
"revisar_codigo_barras" => null,
|
|
"realizar_imposicion" => null,
|
|
"enviar_impresion" => null,
|
|
"portada_path" => null,
|
|
"is_pedido_espera" => null,
|
|
"pedido_espera_by" => null,
|
|
];
|
|
protected $casts = [
|
|
"pedido_id" => "integer",
|
|
"user_created_id" => "integer",
|
|
"user_updated_id" => "?integer",
|
|
"fecha_entrega_warning" => "bool",
|
|
"fecha_entrega_warning_revised" => "bool",
|
|
"total_tirada" => "float",
|
|
"total_precio" => "float",
|
|
"tipo_entrada" => "string",
|
|
"progreso" => "float",
|
|
"estado" => "string",
|
|
"comentarios" => "string",
|
|
"revisar_formato" => "bool",
|
|
"revisar_lomo" => "bool",
|
|
"revisar_solapa" => "bool",
|
|
"revisar_isbn" => "bool",
|
|
"revisar_codigo_barras" => "bool",
|
|
"realizar_imposicion" => "bool",
|
|
"enviar_impresion" => "bool",
|
|
"portada_path" => "string",
|
|
"is_pedido_espera" => "bool",
|
|
];
|
|
|
|
|
|
/**
|
|
* Devuelve las tareas de la orden de trabajo.
|
|
*
|
|
* @return array<OrdenTrabajoTarea>
|
|
*/
|
|
public function tareas(): array
|
|
{
|
|
$m = model(OrdenTrabajoTarea::class);
|
|
return $m->where("orden_trabajo_id", $this->attributes["id"])->findAll();
|
|
}
|
|
public function tareas_impresion() : array
|
|
{
|
|
$m = model(OrdenTrabajoTarea::class);
|
|
return $m->where("orden_trabajo_id", $this->attributes["id"])->where("presupuesto_linea_id IS NOT NULL", NULL, FALSE)->findAll() ?? [];
|
|
}
|
|
/**
|
|
* Devuelve el pedido de la orden de trabajo
|
|
*
|
|
* @return PedidoEntity
|
|
*/
|
|
public function pedido(): ?PedidoEntity
|
|
{
|
|
$m = model(PedidoModel::class);
|
|
return $m->find($this->attributes["pedido_id"]);
|
|
}
|
|
public function dates(): ?OrdenTrabajoDateEntity
|
|
{
|
|
$m = model(OrdenTrabajoDate::class);
|
|
return $m->where('orden_trabajo_id', $this->attributes["id"])->first();
|
|
}
|
|
public function users(): ?OrdenTrabajoUserEntity
|
|
{
|
|
$m = model(OrdenTrabajoUser::class);
|
|
return $m->where('orden_trabajo_id', $this->attributes["id"])->first();
|
|
}
|
|
|
|
/**
|
|
* Almacena en la tabla `orden_trabajo_dates` las fechas correspondientes del pedido.
|
|
* Se almacenan en una tabla externa porque puede haber modificaciones de estas fechas
|
|
* en la orden del trabajo, pero en el pedido quedarán fijas.
|
|
*
|
|
* @todo Falta implementacion
|
|
* @return boolean
|
|
*/
|
|
public function storeDates($data): self
|
|
{
|
|
$ot_dates = new OrdenTrabajoDateEntity();
|
|
$this->attributes["dates"] = $ot_dates->fill($data);
|
|
return $this;
|
|
}
|
|
public function getBarCode(): string
|
|
{
|
|
$barcode = new TypeCode128();
|
|
$renderer = new PngRenderer();
|
|
$barcodeData = $barcode->getBarcode($this->pedido()->presupuesto()->id);
|
|
return base64_encode($renderer->render($barcodeData, 200, 50));
|
|
}
|
|
public function files(): array
|
|
{
|
|
$m = model(OrdenTrabajoFileModel::class);
|
|
return $m->where('orden_trabajo_id', $this->attributes['id'])->findAll() ?? [];
|
|
}
|
|
public function pedidoEsperaBy(): ?UserEntity
|
|
{
|
|
$m = model(UserModel::class);
|
|
if ($this->attributes['pedido_espera_by']) {
|
|
return $m->findById($this->attributes['pedido_espera_by']);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
public function getPedidoEsperaBy(): ?UserEntity
|
|
{
|
|
return $this->pedidoEsperaBy();
|
|
}
|
|
public function getFullPath(): ?string
|
|
{
|
|
helper('filesystem');
|
|
$path = WRITEPATH . 'uploads/' . $this->attributes["portada_path"];
|
|
$portada_path = null;
|
|
if ($path) {
|
|
if (file_exists($path)) {
|
|
$portada_path = $path;
|
|
} else {
|
|
$portada_path = null;
|
|
}
|
|
}
|
|
return $portada_path;
|
|
}
|
|
}
|