mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
242 lines
7.7 KiB
PHP
Executable File
242 lines
7.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Entities\Produccion;
|
|
|
|
use App\Entities\Configuracion\Imposicion;
|
|
use App\Entities\Configuracion\Maquina;
|
|
use App\Entities\Presupuestos\PresupuestoAcabadosEntity;
|
|
use App\Entities\Presupuestos\PresupuestoEncuadernacionesEntity;
|
|
use App\Entities\Presupuestos\PresupuestoLineaEntity;
|
|
use App\Entities\Presupuestos\PresupuestoManipuladosEntity;
|
|
use App\Models\Configuracion\ImposicionModel;
|
|
use App\Models\Configuracion\MaquinaModel;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoModel;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoTareaProgressDate;
|
|
use App\Models\Presupuestos\PresupuestoAcabadosModel;
|
|
use App\Models\Presupuestos\PresupuestoEncuadernacionesModel;
|
|
use App\Models\Presupuestos\PresupuestoLineaModel;
|
|
use App\Models\Presupuestos\PresupuestoManipuladosModel;
|
|
use CodeIgniter\Entity\Entity;
|
|
use CodeIgniter\I18n\Time;
|
|
|
|
class OrdenTrabajoTareaEntity extends Entity
|
|
{
|
|
protected $attributes = [
|
|
"id" => null,
|
|
"orden_trabajo_id" => null,
|
|
"presupuesto_linea_id" => null,
|
|
"presupuesto_acabado_id" => null,
|
|
"presupuesto_preimpresion_id" => null,
|
|
"presupuesto_encuadernado_id" => null,
|
|
"presupuesto_extra_id" => null,
|
|
"presupuesto_manipulado_id" => null,
|
|
"nombre" => null,
|
|
"orden" => null,
|
|
"maquina_id" => null,
|
|
"imposicion_id" => null,
|
|
"tiempo_estimado" => null,
|
|
"tiempo_real" => null,
|
|
"is_corte" => null,
|
|
"tipo_corte" => null,
|
|
"comment" => null,
|
|
"click_init" => null,
|
|
"click_end" => null,
|
|
"pliego_1" => null,
|
|
"pliego_1_total" => null,
|
|
"pliego_2" => null,
|
|
"pliego_2_total" => null,
|
|
];
|
|
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
|
protected $casts = [
|
|
"id" => "integer",
|
|
"orden_trabajo_id" => "integer",
|
|
"presupuesto_linea_id" => "?integer",
|
|
"nombre" => "string",
|
|
"orden" => "integer",
|
|
"maquina_id" => "?integer",
|
|
"imposicion_id" => "?integer",
|
|
"tiempo_estimado" => "?float",
|
|
"tiempo_real" => "?float",
|
|
"is_corte" => "boolean",
|
|
"tipo_corte" => "string",
|
|
"comment" => "?string",
|
|
"click_init" => "integer",
|
|
"click_end" => "integer",
|
|
"pliego_1" => "integer",
|
|
"pliego_1_total" => "integer",
|
|
"pliego_2" => "integer",
|
|
"pliego_2_total" => "integer",
|
|
];
|
|
|
|
/**
|
|
* Orden de trabajo de la tarea
|
|
*
|
|
* @return OrdenTrabajoEntity
|
|
*/
|
|
public function orden_trabajo(): OrdenTrabajoEntity
|
|
{
|
|
$m = model(OrdenTrabajoModel::class);
|
|
return $m->find($this->attributes["orden_trabajo_id"]);
|
|
}
|
|
/**
|
|
* Tarea orden de trabajo con orden de trabajo
|
|
*
|
|
* @return self
|
|
*/
|
|
public function withOrdenTrabajo(): self
|
|
{
|
|
$this->attributes["orden_trabajo"] = $this->orden_trabajo();
|
|
return $this;
|
|
}
|
|
/**
|
|
* Devuelve la maquina actual de esta tarea
|
|
*
|
|
* @return Maquina
|
|
*/
|
|
public function maquina_actual(): Maquina
|
|
{
|
|
$m = model(MaquinaModel::class);
|
|
return $m->find($this->attributes["maquina_id"]);
|
|
}
|
|
/**
|
|
* Devuelve el presupuesto linea origen de esta tarea
|
|
*
|
|
* @return PresupuestoLineaEntity
|
|
*/
|
|
public function presupuesto_linea(): ?PresupuestoLineaEntity
|
|
{
|
|
$presupuesto_linea = null;
|
|
$m = model(PresupuestoLineaModel::class);
|
|
if ($this->attributes['presupuesto_linea_id']) {
|
|
|
|
$presupuesto_linea = $m->find($this->attributes["presupuesto_linea_id"]);
|
|
}
|
|
return $presupuesto_linea;
|
|
}
|
|
/**
|
|
* Devuelve la maquina original del presupuesto linea
|
|
*
|
|
* @return Maquina
|
|
*/
|
|
public function maquina_presupuesto_linea(): Maquina
|
|
{
|
|
return $this->presupuesto_linea()?->maquina();
|
|
}
|
|
/**
|
|
* Devuelve el presupuesto acabado origen de esta tarea
|
|
*
|
|
* @return PresupuestoAcabadosEntity
|
|
*/
|
|
public function presupuesto_acabado(): ?PresupuestoAcabadosEntity
|
|
{
|
|
$presupuesto_acabado = null;
|
|
$m = model(PresupuestoAcabadosModel::class);
|
|
if ($this->attributes["presupuesto_acabado_id"]) {
|
|
$presupuesto_acabado = $m->find($this->attributes["presupuesto_acabado_id"]);
|
|
}
|
|
return $presupuesto_acabado;
|
|
}
|
|
/**
|
|
* Devuelve el presupuesto enducadernacion origen de esta tarea
|
|
*
|
|
* @return PresupuestoEncuadernacionesEntity
|
|
*/
|
|
public function presupuesto_encuadernacion(): ?PresupuestoEncuadernacionesEntity
|
|
{
|
|
$presupuesto_encuadernacion = null;
|
|
$m = model(PresupuestoEncuadernacionesModel::class);
|
|
if ($this->attributes["presupuesto_encuadernado_id"]) {
|
|
$presupuesto_encuadernacion = $m->find($this->attributes["presupuesto_encuadernado_id"]);
|
|
}
|
|
return $presupuesto_encuadernacion;
|
|
}
|
|
/**
|
|
* Devuelve el presupuesto acabado origen de esta tarea
|
|
*
|
|
* @return ?PresupuestoManipuladosEntity
|
|
*/
|
|
public function presupuesto_manipulado(): ?PresupuestoManipuladosEntity
|
|
{
|
|
$m = model(PresupuestoManipuladosModel::class);
|
|
$p = null;
|
|
if ($this->attributes['presupuesto_manipulado_id']) {
|
|
$p = $m->find($this->attributes["presupuesto_manipulado_id"]);
|
|
}
|
|
return $p;
|
|
}
|
|
public function imposicion(): ?Imposicion
|
|
{
|
|
$m = model(ImposicionModel::class);
|
|
$imposicion = null;
|
|
if ($this->attributes["imposicion_id"]) {
|
|
$imposicion = $m->find($this->attributes["imposicion_id"]);
|
|
}
|
|
return $imposicion;
|
|
}
|
|
public function progress_dates(): array
|
|
{
|
|
$m = model(OrdenTrabajoTareaProgressDate::class);
|
|
return $m->where('ot_tarea_id', $this->attributes["id"])->findAll() ?? [];
|
|
}
|
|
public function lastState() : ?OrdenTrabajoTareaProgressDateEntity
|
|
{
|
|
$m = model(OrdenTrabajoTareaProgressDate::class);
|
|
$progressDates = $m->where('ot_tarea_id', $this->attributes["id"])->orderBy('action_at', 'DESC')->first();
|
|
return $progressDates;
|
|
}
|
|
public function tiempo_trabajado()
|
|
{
|
|
$dates = $this->progress_dates();
|
|
$intervals = [];
|
|
$init = null;
|
|
$end = null;
|
|
foreach ($dates as $key => $date) {
|
|
if ($date->estado == "I") {
|
|
if ($date->action_at) {
|
|
$init = Time::createFromFormat('Y-m-d H:i:s', $date->action_at);
|
|
}
|
|
}
|
|
if ($date->estado == "S" || $date->estado == "F") {
|
|
if ($date->action_at && $init) {
|
|
$end = Time::createFromFormat('Y-m-d H:i:s', $date->action_at);
|
|
$intervals[] = $init->difference($end)->getSeconds();
|
|
}
|
|
}
|
|
}
|
|
return array_sum($intervals);
|
|
}
|
|
public function getClickTarea(): int
|
|
{
|
|
return $this->attributes['click_end'] - $this->attributes['click_init'];
|
|
}
|
|
public function isCosido(): bool
|
|
{
|
|
$isTareaCosido = false;
|
|
$pm = $this->presupuesto_manipulado();
|
|
if ($pm) {
|
|
$isTareaCosido = $pm->tarifa()->isCosido();
|
|
}
|
|
return $isTareaCosido;
|
|
}
|
|
public function isImpresion() : bool
|
|
{
|
|
return $this->attributes['presupuesto_linea_id'] != null;
|
|
}
|
|
public function isAcabado() : bool
|
|
{
|
|
return $this->attributes['presupuesto_acabado_id'] != null;
|
|
}
|
|
public function isManipulado() : bool
|
|
{
|
|
return $this->attributes['presupuesto_manipulado_id'] != null;
|
|
}
|
|
public function isEncuadernado() : bool
|
|
{
|
|
return $this->attributes['presupuesto_encuadernado_id'] != null;
|
|
}
|
|
public function isCorte() : bool
|
|
{
|
|
return $this->attributes['is_corte'];
|
|
}
|
|
}
|