mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
113 lines
3.5 KiB
PHP
113 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Entities\Produccion;
|
|
|
|
use App\Controllers\Produccion\Ordentrabajo;
|
|
use App\Database\Migrations\OrdenTrabajoDatesTable;
|
|
use App\Entities\Pedidos\PedidoEntity;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoDate;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoTarea;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoUser;
|
|
use App\Models\Pedidos\PedidoModel;
|
|
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" => false,
|
|
"fecha_entrega_warning_revised" => false,
|
|
"total_tirada" => null,
|
|
"total_precio" => null,
|
|
"tipo_entrada" => "out",
|
|
"progreso" => 0.00,
|
|
"estado" => "I",
|
|
"comentarios" => null,
|
|
"revisar_formato" => false,
|
|
"revisar_lomo" => false,
|
|
"revisar_solapa" => false,
|
|
"revisar_isbn" => false,
|
|
"revisar_codigo_barras" => false,
|
|
"realizar_imposicion" => false,
|
|
"enviar_impresion" => false,
|
|
];
|
|
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",
|
|
];
|
|
|
|
|
|
/**
|
|
* 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();
|
|
}
|
|
/**
|
|
* 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));
|
|
}
|
|
}
|