mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
1741 lines
72 KiB
PHP
Executable File
1741 lines
72 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Entities\Clientes\ClienteEntity;
|
|
use App\Entities\Configuracion\Imposicion;
|
|
use App\Entities\Pedidos\PedidoEntity;
|
|
use App\Entities\Presupuestos\PresupuestoEntity;
|
|
use App\Entities\Presupuestos\PresupuestoLineaEntity;
|
|
use App\Entities\Produccion\OrdenTrabajoEntity;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoDate;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoModel;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoTarea;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoUser;
|
|
use CodeIgniter\Config\BaseService;
|
|
use App\Entities\Configuracion\Maquina as MaquinaEntity;
|
|
use App\Entities\Produccion\OrdenTrabajoFileEntity;
|
|
use App\Entities\Produccion\OrdenTrabajoTareaEntity;
|
|
use App\Entities\Tarifas\Acabados\TarifaAcabadoEntity;
|
|
use App\Models\Configuracion\ConfigVariableModel;
|
|
use App\Models\Configuracion\MaquinaModel;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoFileModel;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoTareaProgressDate;
|
|
use App\Models\Pedidos\PedidoModel;
|
|
use App\Models\Usuarios\UserModel;
|
|
use CodeIgniter\Database\BaseBuilder;
|
|
use CodeIgniter\Database\BaseResult;
|
|
use CodeIgniter\Database\Exceptions\DatabaseException;
|
|
use CodeIgniter\HTTP\Files\UploadedFile;
|
|
use CodeIgniter\I18n\Time;
|
|
use Config\OrdenTrabajo;
|
|
use Exception;
|
|
|
|
/**
|
|
* Clase con las funcionalidades necesarias trabajar con las ordenes de trabajo.
|
|
*/
|
|
class ProductionService extends BaseService
|
|
{
|
|
/**
|
|
* Tipos de impresion para identificar linea de impresion plana/general
|
|
*
|
|
* @var array
|
|
*/
|
|
public array $TIPOS_PLANA = ['lp_bn', 'lp_color', 'lp_colorhq'];
|
|
/**
|
|
* Tipos de impresion para idenficiar si es rotativa
|
|
*
|
|
* @var array
|
|
*/
|
|
public array $TIPOS_ROTATIVA = ['lp_rot_bn', 'lp_rot_color'];
|
|
|
|
protected OrdenTrabajoModel $otModel;
|
|
|
|
protected OrdenTrabajoTarea $otTarea;
|
|
protected OrdenTrabajoDate $otDate;
|
|
protected OrdenTrabajoUser $otUser;
|
|
protected OrdenTrabajoEntity $ot;
|
|
protected OrdenTrabajoFileModel $otFileModel;
|
|
protected OrdenTrabajoTareaProgressDate $otTareaProgressDate;
|
|
protected PedidoModel $pedidoModel;
|
|
protected UserModel $userModel;
|
|
protected ConfigVariableModel $configVariableModel;
|
|
protected MaquinaEntity $defaultMaquinaCorte;
|
|
protected MaquinaModel $maquinaModel;
|
|
protected OrdenTrabajo $ordenTrabajoConfig;
|
|
|
|
|
|
/**
|
|
* Nombre de la maquina por defecto para realizar la tarea de corte.
|
|
*
|
|
* @var string 'HT-1000'
|
|
*/
|
|
protected string $defaultMaquinaCorteName = 'HT-1000';
|
|
/**
|
|
* Color del header en el formulario de orden de trabajo
|
|
*
|
|
* @var string
|
|
*/
|
|
public string $statusColor;
|
|
/**
|
|
* Valor límite del POD
|
|
*
|
|
* `$this->configVariableModel->getVariable('POD')->value;`
|
|
* @var integer
|
|
*/
|
|
protected int $podValue = 0;
|
|
/**
|
|
* Indica si es POD
|
|
*
|
|
* `tirada <= podValue`
|
|
* @var boolean
|
|
*/
|
|
protected bool $isPOD = false;
|
|
|
|
/**
|
|
* Indica si la orden de trabajo contiene gofrado
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isGofrado = false; //* CHECK DONE
|
|
/**
|
|
* Indica si la orden de trabajo contiene gofrado
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* TODO Hay que implementar un boolean en `lg_tarifa_acabado` para identificar
|
|
* @var boolean
|
|
*/
|
|
public bool $isGrapado = true; //TODO
|
|
/**
|
|
* Indica si la orden de trabajo contiene espiral
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* TODO Hay que implementar un boolean en `lg_tarifa_manipulado` para identificar
|
|
* DEFAULT true hasta implementacion
|
|
* @var boolean
|
|
*/
|
|
public bool $isEspiral = true; //TODO
|
|
/**
|
|
* Indica si la orden de trabajo contiene UVI
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isUVI = false; //* CHECK DONE
|
|
/**
|
|
* Indica si la orden de trabajo contiene plastificado
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* TODO Hay que implementar un boolean en `lg_tarifa_acabado` para identificar
|
|
* DEFAULT true hasta implementacion
|
|
* @var boolean
|
|
*/
|
|
public bool $isPlastificado = true; //TODO
|
|
/**
|
|
* Indica si la orden de trabajo contiene cubierta
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isCubierta = false; //* CHECK DONE
|
|
/**
|
|
* Indica si la impresion es en color
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isColor = false; //* CHECK DONE
|
|
/**
|
|
* Indica si la impresion es en bn
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isBN = false; //* CHECK DONE
|
|
/**
|
|
* Indica si hay una tarea de corte
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* ! Se añade por defecto siempre en una rotativa una tarea de corte
|
|
* @var boolean
|
|
*/
|
|
public bool $isCorte = false; //* CHECK DONE
|
|
/**
|
|
* Pedido Entity
|
|
*
|
|
* @var PedidoEntity
|
|
*/
|
|
protected PedidoEntity $pedido;
|
|
/**
|
|
* Presupuesto Entity
|
|
*
|
|
* @var PresupuestoEntity
|
|
*/
|
|
protected PresupuestoEntity $presupuesto;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->otModel = model(OrdenTrabajoModel::class);
|
|
$this->otDate = model(OrdenTrabajoDate::class);
|
|
$this->otTarea = model(OrdenTrabajoTarea::class);
|
|
$this->otUser = model(OrdenTrabajoUser::class);
|
|
$this->userModel = model(UserModel::class);
|
|
$this->otFileModel = model(OrdenTrabajoFileModel::class);
|
|
$this->pedidoModel = model(PedidoModel::class);
|
|
$this->otTareaProgressDate = model(OrdenTrabajoTareaProgressDate::class);
|
|
$this->ordenTrabajoConfig = config('OrdenTrabajo');
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["sin_imprimir"];
|
|
$this->configVariableModel = model(ConfigVariableModel::class);
|
|
$this->podValue = $this->configVariableModel->getVariable('POD')->value;
|
|
}
|
|
|
|
public function init(int $orden_trabajo_id): self
|
|
{
|
|
try {
|
|
$this->maquinaModel = model(MaquinaModel::class);
|
|
$this->otModel = model(OrdenTrabajoModel::class);
|
|
$this->ot = $this->otModel->find($orden_trabajo_id);
|
|
$pedido = $this->ot->pedido();
|
|
$this->setPedido($pedido);
|
|
$this->defaultMaquinaCorte = $this->maquinaModel->where('nombre', $this->defaultMaquinaCorteName)->first();
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["sin_imprimir"];
|
|
$this->updateProgress();
|
|
return $this;
|
|
} catch (\Throwable $th) {
|
|
throw $th;
|
|
}
|
|
}
|
|
/**
|
|
* Establece el pedido sobre el que se va a trabajar
|
|
*
|
|
* @param PedidoEntity $pedido
|
|
* @return self
|
|
*/
|
|
public function setPedido(PedidoEntity $pedido): self
|
|
{
|
|
$this->pedido = $pedido;
|
|
$this->presupuesto = $this->pedido->presupuesto();
|
|
$this->otModel = model(OrdenTrabajoModel::class);
|
|
$this->otDate = model(OrdenTrabajoDate::class);
|
|
$this->otTarea = model(OrdenTrabajoTarea::class);
|
|
$this->isPOD = $this->presupuesto->tirada <= $this->podValue;
|
|
return $this;
|
|
}
|
|
/**
|
|
* Devuelve la orden de trabajo.
|
|
*
|
|
* @return OrdenTrabajoEntity
|
|
*/
|
|
public function getOrdenTrabajo(): OrdenTrabajoEntity
|
|
{
|
|
return $this->ot;
|
|
}
|
|
|
|
/**
|
|
* Crea una instancia de la orden de trabajo
|
|
*
|
|
* @return self
|
|
*/
|
|
public function createOrdenTrabajo(): OrdenTrabajoEntity|DatabaseException
|
|
{
|
|
|
|
$auth_user = auth()->user();
|
|
$ot_exists = $this->pedido->orden_trabajo();
|
|
if ($ot_exists) {
|
|
return $ot_exists;
|
|
}
|
|
$data = [
|
|
"pedido_id" => $this->pedido->id,
|
|
"user_created_id" => $auth_user->id,
|
|
"user_updated_id" => $auth_user->id,
|
|
"total_tirada" => $this->pedido->total_tirada,
|
|
"total_precio" => $this->pedido->total_precio
|
|
];
|
|
$id = $this->otModel->insert($data);
|
|
$this->init($id);
|
|
$this->storeOrdenTrabajoUsers();
|
|
$this->storeOrdenTrabajoDates();
|
|
$this->storeAllTareas();
|
|
$this->updatePedidoEspera();
|
|
return $this->ot;
|
|
}
|
|
|
|
/**
|
|
* Inserta las fechas del pedido asociado a la orden de trabajo en `orden_trabajo_tareas`
|
|
*
|
|
* @param OrdenTrabajoEntity $ot
|
|
* @return integer|boolean|string ID
|
|
*/
|
|
protected function storeOrdenTrabajoDates(): int|bool|string
|
|
{
|
|
$fecha_encuadernado = Time::now()->addDays(2)->format("Y-m-d");
|
|
$fecha_entrega_real = Time::now()->addDays(5)->format("Y-m-d");
|
|
//$fecha_embalaje_at = Time::now()->addDays(4)->format("Y-m-d");
|
|
$data = [
|
|
"orden_trabajo_id" => $this->ot->id,
|
|
"fecha_encuadernado_at" => $fecha_encuadernado,
|
|
"fecha_entrega_real_at" => $fecha_entrega_real,
|
|
"fecha_impresion_at" => Time::now()->format("Y-m-d"),
|
|
//"embalaje_at" => $fecha_embalaje_at,
|
|
"fecha_entrega_externo" => $this->pedido->fecha_entrega_externo,
|
|
];
|
|
$otDateId = $this->otDate->insert($data);
|
|
$this->otDate->updateUserDateMap($this->ot->id, $data);
|
|
return $otDateId;
|
|
}
|
|
/**
|
|
* Crea un registro en `orden_trabajo_users`
|
|
*
|
|
* @return integer|boolean|string
|
|
*/
|
|
protected function storeOrdenTrabajoUsers(): int|bool|string
|
|
{
|
|
return $this->otUser->insert([
|
|
"orden_trabajo_id" => $this->ot->id,
|
|
]);
|
|
}
|
|
/**
|
|
* Crea un registro en `orden_trabajo_users` si no ha sido creado previamente
|
|
*
|
|
* @return integer|boolean|string
|
|
*/
|
|
public function reInsertOrdenTrabajoUsers(): int|bool|string
|
|
{
|
|
$status = false;
|
|
if ($this->otUser->where('orden_trabajo_id', $this->ot->id)->countAllResults() == 0) {
|
|
$status = $this->storeOrdenTrabajoUsers();
|
|
}
|
|
return $status;
|
|
}
|
|
/**
|
|
* Crea un registro en `orden_trabajo_dates` si no ha sido creado previamente
|
|
*
|
|
* @return integer|boolean|string
|
|
*/
|
|
public function reInsertOrdenTrabajoDates(): int|bool|string
|
|
{
|
|
$status = false;
|
|
if ($this->otDate->where('orden_trabajo_id', $this->ot->id)->countAllResults() == 0) {
|
|
$status = $this->storeOrdenTrabajoDates();
|
|
$this->resetAllTareas();
|
|
}
|
|
return $status;
|
|
}
|
|
/**
|
|
* General las correspondientes tareas de la orden de trabajo en la table `orden_trabajo_tareas`
|
|
*
|
|
* @return integer|boolean|string
|
|
*/
|
|
protected function storeAllTareas()
|
|
{
|
|
$this->storeOrdenTrabajoTareas();
|
|
$this->storeOrdenTrabajoAcabadoTareas();
|
|
$this->storeOrdenTrabajoManipuladoTareas();
|
|
// $this->storeOrdenTrabajoPreimpresionTareas();
|
|
$this->storeOrdenTrabajoEncuadernacionTareas();
|
|
// $this->storeOrdenTrabajoExtraTareas();
|
|
}
|
|
/**
|
|
* Regenera las tareas.
|
|
* !! Se eliminan las que hay previamente sin `softDelete`
|
|
*
|
|
* @return integer|boolean|string
|
|
*/
|
|
public function resetAllTareas(): BaseResult|bool
|
|
{
|
|
$r = $this->otTarea->where("orden_trabajo_id", $this->ot->id)->delete(purge: true);
|
|
$this->storeAllTareas();
|
|
return $r;
|
|
}
|
|
/**
|
|
* Inserta las tareas de la orden de trabajo.p
|
|
* Acepta como argumento una entidad de la orden de trabajo OrdenTrabajoEntity
|
|
*
|
|
*
|
|
* @return integer|boolean Numero de registro insertados o `FALSE` si error
|
|
*/
|
|
protected function storeOrdenTrabajoTareas(): int|bool
|
|
{
|
|
|
|
$p_lineas = $this->presupuesto->presupuestoLineas();
|
|
$ot_tareas = [];
|
|
|
|
foreach ($p_lineas as $key => $p_linea) {
|
|
$p_linea_maquina = $p_linea->maquina();
|
|
$nombre = $p_linea->get_nombre_tarea();
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_linea_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $nombre;
|
|
$ot_tareas["orden"] = $p_linea_maquina->orden_planning ?? 0;
|
|
$ot_tareas["maquina_id"] = $p_linea_maquina->id;
|
|
$ot_tareas["imposicion_id"] = null;
|
|
$ot_tareas["tiempo_estimado"] = $p_linea->horas_maquina * 3600;
|
|
$ot_tareas["tiempo_real"] = $p_linea->horas_maquina * 3600; //? Tiempo real se inserta manual?
|
|
$insert_query_result = $this->otTarea->insert($ot_tareas);
|
|
$ot_tareas = [];
|
|
$this->storeTareaCorte($p_linea);
|
|
}
|
|
return $insert_query_result;
|
|
}
|
|
/**
|
|
* Inserta una tarea de corte si la impresion es en `rotativa`
|
|
*
|
|
* @param PresupuestoLineaEntity $pLinea
|
|
* @return OrdenTrabajoTareaEntity|null
|
|
*/
|
|
protected function storeTareaCorte(PresupuestoLineaEntity $pLinea): ?OrdenTrabajoTareaEntity
|
|
{
|
|
$otCorte = null;
|
|
if ($pLinea->isRotativa()) {
|
|
$tareaId = $this->otTarea->insert([
|
|
'orden_trabajo_id' => $this->ot->id,
|
|
'presupuesto_linea_id' => $pLinea->id,
|
|
'nombre' => 'Corte',
|
|
'maquina_id' => $this->defaultMaquinaCorte->id,
|
|
'orden' => $this->defaultMaquinaCorte->orden_planning,
|
|
'tiempo_estimado' => $pLinea->rotativa_tiempo_corte * 60,
|
|
'tiempo_real' => $pLinea->rotativa_tiempo_corte * 60,
|
|
'is_corte' => true,
|
|
'tipo_corte' => "bobina",
|
|
]);
|
|
$otCorte = $this->otTarea->find($tareaId);
|
|
}
|
|
return $otCorte;
|
|
}
|
|
|
|
/**
|
|
* General las tareas de acabado segun las líneas de presupuesto_acabados
|
|
*
|
|
* @return boolean
|
|
*/
|
|
protected function storeOrdenTrabajoAcabadoTareas(): bool
|
|
{
|
|
$p_lineas = $this->presupuesto_lineas_acabado();
|
|
foreach ($p_lineas as $key => $p_linea) {
|
|
$p_linea_maquinas = $p_linea->maquinas();
|
|
$ot_tareas = [];
|
|
if (count($p_linea_maquinas) > 0) {
|
|
$linea_maquina = $p_linea_maquinas[0]; //Se obtiene la primera máquina aunque tenga varias
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_acabado_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre;
|
|
$ot_tareas["orden"] = $linea_maquina->orden_planning ?? 100;
|
|
$ot_tareas["maquina_id"] = $linea_maquina->id;
|
|
$ot_tareas["imposicion_id"] = null;
|
|
$this->otTarea->insert($ot_tareas);
|
|
$ot_tareas = [];
|
|
} else {
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_acabado_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
|
$ot_tareas["orden"] = 100;
|
|
$this->otTarea->insert($ot_tareas);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
/**
|
|
* General las tareas de acabado segun las líneas de presupuesto_manipulados
|
|
*
|
|
* @return boolean
|
|
*/
|
|
protected function storeOrdenTrabajoManipuladoTareas(): bool
|
|
{
|
|
$p_lineas = $this->presupuesto_lineas_manipulado();
|
|
foreach ($p_lineas as $key => $p_linea) {
|
|
$p_linea_maquinas = $p_linea->maquinas();
|
|
$ot_tareas = [];
|
|
if (count($p_linea_maquinas) > 0) {
|
|
$linea_maquina = $p_linea_maquinas[0]; //Se obtiene la primera máquina aunque tenga varias
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_manipulado_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre;
|
|
$ot_tareas["orden"] = $linea_maquina->orden_planning ?? 100;
|
|
$ot_tareas["maquina_id"] = $linea_maquina->id;
|
|
$ot_tareas["imposicion_id"] = null;
|
|
$this->otTarea->insert($ot_tareas);
|
|
$ot_tareas = [];
|
|
} else {
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_manipulado_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
|
$ot_tareas["orden"] = 100;
|
|
$this->otTarea->insert($ot_tareas);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
/**
|
|
* General las tareas de acabado segun las líneas de presupuesto_preimpresion
|
|
*
|
|
* @return boolean
|
|
*/
|
|
protected function storeOrdenTrabajoPreimpresionTareas(): bool
|
|
{
|
|
$p_lineas = $this->presupuesto_lineas_preimpresion();
|
|
foreach ($p_lineas as $key => $p_linea) {
|
|
$p_linea_maquinas = $p_linea->maquinas();
|
|
$ot_tareas = [];
|
|
if (count($p_linea_maquinas) > 0) {
|
|
$linea_maquina = $p_linea_maquinas[0]; //Se obtiene la primera máquina aunque tenga varias
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_preimpresion_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre;
|
|
$ot_tareas["orden"] = $linea_maquina->orden_planning ?? 100;
|
|
$ot_tareas["maquina_id"] = $linea_maquina->id;
|
|
$ot_tareas["imposicion_id"] = null;
|
|
$this->otTarea->insert($ot_tareas);
|
|
$ot_tareas = [];
|
|
} else {
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_preimpresion_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
|
$ot_tareas["orden"] = 100;
|
|
$this->otTarea->insert($ot_tareas);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
/**
|
|
* General las tareas de acabado segun las líneas de presupuesto_encuadernaciones
|
|
*
|
|
* @return boolean
|
|
*/
|
|
protected function storeOrdenTrabajoEncuadernacionTareas(): bool
|
|
{
|
|
$p_lineas = $this->presupuesto_lineas_encuadernaciones();
|
|
foreach ($p_lineas as $key => $p_linea) {
|
|
$p_linea_maquinas = $p_linea->maquinas();
|
|
$ot_tareas = [];
|
|
if (count($p_linea_maquinas) > 0) {
|
|
$linea_maquina = $p_linea_maquinas[0]; //Se obtiene la primera máquina aunque tenga varias
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_encuadernado_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre;
|
|
$ot_tareas["orden"] = $linea_maquina->orden_planning ?? 110;
|
|
$ot_tareas["maquina_id"] = $linea_maquina->id;
|
|
$ot_tareas["tiempo_estimado"] = $p_linea->tiempo;
|
|
$ot_tareas["tiempo_real"] = $p_linea->tiempo;
|
|
$ot_tareas["imposicion_id"] = null;
|
|
$this->otTarea->insert($ot_tareas);
|
|
$ot_tareas = [];
|
|
} else {
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_encuadernado_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
|
$ot_tareas["tiempo_estimado"] = $p_linea->tiempo;
|
|
$ot_tareas["tiempo_real"] = $p_linea->tiempo;
|
|
$ot_tareas["orden"] = 110;
|
|
$this->otTarea->insert($ot_tareas);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
protected function storeOrdenTrabajoExtraTareas(): bool
|
|
{
|
|
$p_lineas = $this->presupuesto_lineas_extras();
|
|
foreach ($p_lineas as $key => $p_linea) {
|
|
$p_linea_maquinas = $p_linea->maquinas();
|
|
$ot_tareas = [];
|
|
if (count($p_linea_maquinas) > 0) {
|
|
$linea_maquina = $p_linea_maquinas[0]; //Se obtiene la primera máquina aunque tenga varias
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_extra_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre;
|
|
$ot_tareas["orden"] = $linea_maquina->orden_planning ?? 0;
|
|
$ot_tareas["maquina_id"] = $linea_maquina->id;
|
|
$ot_tareas["imposicion_id"] = null;
|
|
$this->otTarea->insert($ot_tareas);
|
|
$ot_tareas = [];
|
|
} else {
|
|
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
|
$ot_tareas["presupuesto_extra_id"] = $p_linea->id;
|
|
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
|
|
|
$this->otTarea->insert($ot_tareas);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
public function getTareas(): array
|
|
{
|
|
$p_lineas_with_maquina = $this->getPresupuestoLineasWithMaquina();
|
|
$tareas = [];
|
|
$tarea = [];
|
|
foreach ($p_lineas_with_maquina as $key => $linea) {
|
|
$tarea["orden"] = $linea->maquina->orden_planning;
|
|
$tarea["maquina_tipo"] = $linea->maquina->tipo;
|
|
$tarea["maquina_nombre"] = $linea->maquina->nombre;
|
|
$tarea["nota"] = null;
|
|
$tareas[] = $tarea;
|
|
$tarea = [];
|
|
}
|
|
return ["tareas" => $tareas];
|
|
}
|
|
|
|
public function getPdf()
|
|
{
|
|
return view("themes/vuexy/pdfs/orden_trabajo", $this->getDataPdf());
|
|
}
|
|
/**
|
|
* Query para mostrar en datatable
|
|
*
|
|
* @return BaseBuilder
|
|
*/
|
|
public function taskDatatableQuery(): BaseBuilder
|
|
{
|
|
$q = $this->otModel->builder()->select([
|
|
"orden_trabajo_tareas.id",
|
|
"orden_trabajo_tareas.orden",
|
|
"orden_trabajo_tareas.nombre",
|
|
"lgmp.nombre as maquina_presupuesto_linea",
|
|
"orden_trabajo_tareas.maquina_id as maquina_tarea",
|
|
"lg_maquinas.nombre as maquina_nombre",
|
|
"lg_imposiciones.id as imposicion_id",
|
|
"CONCAT(lg_imposiciones.ancho,'x',lg_imposiciones.alto,'_',COALESCE(lg_imposiciones.unidades,'NULL'),'_',COALESCE(lg_imposiciones.orientacion,'NULL'),'_',COALESCE(lg_imposiciones.etiqueta,'')) as imposicion_name",
|
|
"orden_trabajo_tareas.tiempo_estimado",
|
|
"orden_trabajo_tareas.tiempo_real",
|
|
"orden_trabajo_tareas.comment",
|
|
"orden_trabajo_tareas.presupuesto_linea_id",
|
|
"presupuesto_linea.tipo",
|
|
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuesto_acabados", "presupuesto_acabados.id = orden_trabajo_tareas.presupuesto_acabado_id", "left")
|
|
->join("presupuesto_manipulados", "presupuesto_manipulados.id = orden_trabajo_tareas.presupuesto_manipulado_id", "left")
|
|
->join("presupuesto_preimpresiones", "presupuesto_preimpresiones.id = orden_trabajo_tareas.presupuesto_preimpresion_id", "left")
|
|
->join("presupuesto_encuadernaciones", "presupuesto_encuadernaciones.id = orden_trabajo_tareas.presupuesto_encuadernado_id", "left")
|
|
->join("presupuesto_serviciosExtra", "presupuesto_serviciosExtra.id = orden_trabajo_tareas.presupuesto_extra_id", "left")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->join("lg_maquinas as lgmp", "lgmp.id = presupuesto_linea.maquina_id", "left")
|
|
->join("lg_imposiciones", "lg_imposiciones.id = orden_trabajo_tareas.imposicion_id", "left")
|
|
->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->orderBy("orden_trabajo_tareas.orden", "ASC");
|
|
return $q;
|
|
}
|
|
/**
|
|
* Query para mostrar en datatable
|
|
*
|
|
* @return BaseBuilder
|
|
*/
|
|
public function planningRotativaQueryDatatable(): BaseBuilder
|
|
{
|
|
$q = $this->otModel->builder()->select([
|
|
"ordenes_trabajo.id as otId",
|
|
"orden_trabajo_dates.fecha_entrega_real_at",
|
|
"presupuestos.titulo as presupuesto_titulo",
|
|
"orden_trabajo_tareas.maquina_id",
|
|
"lg_maquinas.nombre as maquina_planning_nombre",
|
|
"ordenes_trabajo.total_tirada as ot_tirada",
|
|
"lg_papel_formato.ancho as papel_ancho",
|
|
"lg_papel_formato.alto as papel_alto",
|
|
"presupuesto_linea.rotativa_metros_total as metros",
|
|
"lg_papel_impresion.nombre as papel_impresion",
|
|
"presupuesto_linea.gramaje as papel_gramaje",
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("orden_trabajo_dates", "orden_trabajo_dates.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
|
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->join("lg_papel_impresion", "lg_papel_impresion.id = presupuesto_linea.papel_impresion_id", "left")
|
|
->join("lg_maquinas as lgmp", "lgmp.id = presupuesto_linea.maquina_id", "left")
|
|
->join("lg_imposiciones", "lg_imposiciones.id = orden_trabajo_tareas.imposicion_id", "left")
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_ROTATIVA)
|
|
->where('lg_maquinas.is_rotativa', true)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->orderBy("orden_trabajo_tareas.orden", "ASC")
|
|
->groupBy('ordenes_trabajo.id');
|
|
|
|
return $q;
|
|
}
|
|
/**
|
|
* Query para mostrar en datatable
|
|
*
|
|
* @return BaseBuilder
|
|
*/
|
|
public function planningPlanaQueryDatatable(): BaseBuilder
|
|
{
|
|
$q = $this->otModel->builder()->select([
|
|
"ordenes_trabajo.id as otId",
|
|
"orden_trabajo_dates.fecha_entrega_real_at",
|
|
"presupuestos.titulo as presupuesto_titulo",
|
|
"orden_trabajo_tareas.maquina_id",
|
|
"lg_maquinas.nombre as maquina_planning_nombre",
|
|
"lg_maquinas.padre_id as padre_id",
|
|
"ordenes_trabajo.total_tirada as ot_tirada",
|
|
"lg_papel_formato.ancho as papel_ancho",
|
|
"lg_papel_formato.alto as papel_alto",
|
|
"presupuesto_linea.pliegos_pedido as pliegosPedido",
|
|
// "JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_ancho') as maquina_ancho",
|
|
// "JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_alto') as maquina_alto",
|
|
"lg_papel_impresion.nombre as papel_impresion",
|
|
"presupuesto_linea.gramaje as papel_gramaje",
|
|
"SUM(orden_trabajo_tareas.tiempo_real) as tiempo_real_sum"
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("orden_trabajo_dates", "orden_trabajo_dates.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
|
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->join("lg_papel_impresion", "lg_papel_impresion.id = presupuesto_linea.papel_impresion_id", "left")
|
|
->join("lg_maquinas as lgmp", "lgmp.id = presupuesto_linea.maquina_id", "left")
|
|
->join("lg_imposiciones", "lg_imposiciones.id = orden_trabajo_tareas.imposicion_id", "left")
|
|
// ->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA)
|
|
->where('lg_maquinas.is_rotativa', false)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->orderBy("orden_trabajo_tareas.orden", "ASC")
|
|
->groupBy('ordenes_trabajo.id');
|
|
|
|
return $q;
|
|
}
|
|
/**
|
|
* Query para mostrar en datatable
|
|
*
|
|
* @return BaseBuilder
|
|
*/
|
|
public function costDatatableQuery(): BaseBuilder
|
|
{
|
|
$q = $this->otModel->builder()->select([
|
|
"orden_trabajo_tareas.id",
|
|
"orden_trabajo_tareas.orden",
|
|
"orden_trabajo_tareas.nombre",
|
|
"lgmp.nombre as maquina_presupuesto_linea",
|
|
"orden_trabajo_tareas.maquina_id as maquina_tarea",
|
|
|
|
"lg_maquinas.nombre as maquina_nombre",
|
|
"lg_imposiciones.id as imposicion_id",
|
|
"orden_trabajo_tareas.tiempo_estimado",
|
|
"orden_trabajo_tareas.tiempo_real"
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuesto_acabados", "presupuesto_acabados.id = orden_trabajo_tareas.presupuesto_acabado_id", "left")
|
|
->join("presupuesto_manipulados", "presupuesto_manipulados.id = orden_trabajo_tareas.presupuesto_manipulado_id", "left")
|
|
->join("presupuesto_preimpresiones", "presupuesto_preimpresiones.id = orden_trabajo_tareas.presupuesto_preimpresion_id", "left")
|
|
->join("presupuesto_encuadernaciones", "presupuesto_encuadernaciones.id = orden_trabajo_tareas.presupuesto_encuadernado_id", "left")
|
|
->join("presupuesto_serviciosExtra", "presupuesto_serviciosExtra.id = orden_trabajo_tareas.presupuesto_extra_id", "left")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->join("lg_maquinas as lgmp", "lgmp.id = presupuesto_linea.maquina_id", "left")
|
|
->join("lg_imposiciones", "lg_imposiciones.id = orden_trabajo_tareas.imposicion_id", "left")
|
|
->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->orderBy("orden_trabajo_tareas.orden", "ASC");
|
|
return $q;
|
|
}
|
|
public function papelGramajeDatatableQuery(): BaseBuilder
|
|
{
|
|
$q = $this->otModel->builder()->select([
|
|
"lg_papel_impresion.id as papelImpresionId",
|
|
"lg_papel_impresion.nombre as papelImpresionNombre",
|
|
"lg_papel_impresion.gramaje as papelImpresionGramaje",
|
|
"COUNT(orden_trabajo_tareas.id) as tareasCount",
|
|
"lg_papel_formato.ancho as papel_ancho",
|
|
"lg_papel_formato.alto as papel_alto",
|
|
// "CAST(JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_ancho') AS DOUBLE) as maquina_ancho",
|
|
// "CAST(JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_alto') AS DOUBLE) as maquina_alto",
|
|
"presupuesto_linea.rotativa_metros_total as metros",
|
|
"SUM(ordenes_trabajo.total_tirada) as totalTirada",
|
|
"SUM(orden_trabajo_tareas.tiempo_real) as tiempoReal"
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
|
->join("lg_papel_impresion", "presupuesto_linea.papel_impresion_id = lg_papel_impresion.id", "left")
|
|
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->where("orden_trabajo_tareas.presupuesto_linea_id IS NOT NULL", NULL, FALSE)
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_ROTATIVA)
|
|
->groupBy('lg_papel_impresion.id');
|
|
|
|
|
|
|
|
return $q;
|
|
}
|
|
public function papelPliegoDatatableQuery(): BaseBuilder
|
|
{
|
|
$q = $this->otModel->builder()->select([
|
|
"lg_papel_impresion.id as papelImpresionId",
|
|
"lg_papel_impresion.nombre as papelImpresionNombre",
|
|
"lg_papel_impresion.gramaje as papelImpresionGramaje",
|
|
"COUNT(orden_trabajo_tareas.id) as tareasCount",
|
|
"lg_papel_formato.ancho as papel_ancho",
|
|
"lg_papel_formato.alto as papel_alto",
|
|
"presupuesto_linea.pliegos_pedido as pliegosPedido",
|
|
"SUM(ordenes_trabajo.total_tirada) as totalTirada",
|
|
"SUM(orden_trabajo_tareas.tiempo_real) as tiempoReal"
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
|
->join("lg_papel_impresion", "presupuesto_linea.papel_impresion_id = lg_papel_impresion.id", "left")
|
|
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->where("orden_trabajo_tareas.presupuesto_linea_id IS NOT NULL", NULL, FALSE)
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA)
|
|
->groupBy('lg_papel_impresion.id');
|
|
|
|
|
|
|
|
return $q;
|
|
}
|
|
/**
|
|
* Get a summary from ot with the following structure
|
|
*
|
|
* @return array
|
|
* ```php
|
|
* [
|
|
* "ot" => OrdenTrabajoEntity
|
|
* "dates" => OrdenTrabajoDateEntity
|
|
* "tasks" => array<OrdenTrabajoTareaEntity>
|
|
* ];
|
|
* ```
|
|
*/
|
|
public function getSummary(): array
|
|
{
|
|
|
|
$summary = [
|
|
"ot" => $this->ot,
|
|
"pedido" => $this->pedido,
|
|
"presupuesto" => $this->presupuesto,
|
|
"dates" => $this->ot->dates(),
|
|
"user_dates" => $this->userDates(),
|
|
"tasks" => $this->ot->tareas(),
|
|
"acabados" => $this->presupuesto->acabados(),
|
|
"preimpresiones" => $this->presupuesto->preimpresiones(),
|
|
"manipulados" => $this->presupuesto->manipulados(),
|
|
"encuadernaciones" => $this->presupuesto->encuadernaciones(),
|
|
"impresion_interior_bn" => $this->getTareaImpresionInteriorBn(),
|
|
"impresion_interior_color" => $this->getTareaImpresionInteriorColor(),
|
|
"tareas_acabado" => $this->tareas_acabado(),
|
|
"tareas_manipulado" => $this->tareas_manipulado(),
|
|
"tareas_encuadernacion" => $this->tareas_encuadernacion(),
|
|
"tareas_preimpresion" => $this->tareas_preimpresion(),
|
|
"tareas_impresion" => $this->tareas_impresion(),
|
|
"tiempo_procesamiento" => $this->getTiempoProcesamientoHHMM(),
|
|
"statusColor" => $this->getOtColorStatus(),
|
|
];
|
|
return $summary;
|
|
}
|
|
public function getDataPdf()
|
|
{
|
|
$logistica_data = $this->logistica_data();
|
|
return [
|
|
"ot" => $this->ot,
|
|
"pedido" => $this->pedido,
|
|
"presupuesto" => $this->presupuesto,
|
|
"cliente" => $this->presupuesto->cliente(),
|
|
"ubicacion" => $this->pedido->ubicacion()->nombre,
|
|
"dates" => $this->ot->dates(),
|
|
"tasks" => $this->ot->tareas(),
|
|
"papel_formato" => $this->presupuesto->papel_formato(),
|
|
"acabados" => $this->presupuesto->acabados(),
|
|
"preimpresiones" => $this->presupuesto->preimpresiones(),
|
|
"manipulados" => $this->presupuesto->manipulados(),
|
|
"encuadernaciones" => $this->presupuesto->encuadernaciones(),
|
|
"linea_impresion" => $this->presupuesto->presupuestoLineaImpresion(),
|
|
"linea_cubierta" => $this->presupuesto->presupuestoLineaCubierta(),
|
|
"peso_unidad" => $logistica_data["peso_unidad"],
|
|
"peso_pedido" => $logistica_data["peso_pedido"],
|
|
"imposicion" => $this->getImposicionTareaImpresion(),
|
|
"tiempo_procesamiento" => $this->getTiempoProcesamientoHHMM(),
|
|
"tiempo_impresion" => $this->getTiempoTareasImpresionHHMM(),
|
|
"colors" => $this->getPdfColors(),
|
|
"isPOD" => $this->isPOD,
|
|
"uvi" => $this->getUVI()
|
|
|
|
];
|
|
}
|
|
public function getImposicionTareaImpresion(): ?Imposicion
|
|
{
|
|
$imposicion = null;
|
|
$impresionInteriorBnImposicion = $this->getTareaImpresionInteriorBn()?->imposicion();
|
|
$impresionInteriorColorImposicion = $this->getTareaImpresionInteriorColor()?->imposicion();
|
|
if ($impresionInteriorBnImposicion) {
|
|
$imposicion = $impresionInteriorBnImposicion;
|
|
}
|
|
if ($impresionInteriorColorImposicion) {
|
|
$imposicion = $impresionInteriorColorImposicion;
|
|
}
|
|
return $imposicion;
|
|
}
|
|
public function getTareaImpresionSobreCubierta(): ?OrdenTrabajoTareaEntity
|
|
{
|
|
$q = $this->otTarea->select('orden_trabajo_tareas.*')
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
|
->whereIn("presupuesto_linea.tipo", ["lp_sobrecubierta"])->first();
|
|
return $q;
|
|
}
|
|
public function getTareaImpresionCubierta(): ?OrdenTrabajoTareaEntity
|
|
{
|
|
$q = $this->otTarea->select('orden_trabajo_tareas.*')
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
|
->whereIn("presupuesto_linea.tipo", ["lp_cubierta"])->first();
|
|
return $q;
|
|
}
|
|
public function getTareaImpresionInteriorBn(): ?OrdenTrabajoTareaEntity
|
|
{
|
|
$q = $this->otTarea->select('orden_trabajo_tareas.*')
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
|
->whereIn("presupuesto_linea.tipo", ["lp_rot_bn", "lp_bn", "lp_bnhq"])->first();
|
|
return $q;
|
|
}
|
|
public function getTareaImpresionInteriorColor(): ?OrdenTrabajoTareaEntity
|
|
{
|
|
$q = $this->otTarea->select('orden_trabajo_tareas.*')
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
|
->whereIn("presupuesto_linea.tipo", ["lp_rot_color", "lp_color", "lp_colorhq"])->first();
|
|
return $q;
|
|
}
|
|
public function getPresupuestoLineaImpresion() {}
|
|
public function tareas_acabado(): array
|
|
{
|
|
$q = $this->otTarea->where("presupuesto_acabado_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
public function tareas_impresion(): array
|
|
{
|
|
$q = $this->otTarea->where("presupuesto_linea_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
public function tareas_encuadernacion(): array
|
|
{
|
|
$q = $this->otTarea->where("presupuesto_encuadernado_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
public function tareas_preimpresion(): array
|
|
{
|
|
$q = $this->otTarea->where("presupuesto_preimpresion_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
public function tareas_manipulado(): array
|
|
{
|
|
$q = $this->otTarea->where("presupuesto_manipulado_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
/**========================================================================
|
|
* UPDATES
|
|
*========================================================================**/
|
|
|
|
public function updateOrdenTrabajoTarea($tarea_id, $data): bool
|
|
{
|
|
if (isset($data['maquina_id'])) {
|
|
$maquina = model(MaquinaModel::class)->find($data['maquina_id']);
|
|
$data['orden'] = $maquina->orden_planning;
|
|
}
|
|
return $this->otTarea->update($tarea_id, $data);
|
|
}
|
|
public function storeOrdenTrabajoTareaProgressDate($data): bool
|
|
{
|
|
$data["action_at"] = Time::now()->format('Y-m-d H:i:s');
|
|
$data["action_user_id"] = auth()->user()->id;
|
|
$lastDate = $this->otTareaProgressDate->where('ot_tarea_id', $data['ot_tarea_id'])->orderBy('action_at', 'DESC')->first();
|
|
if ($lastDate) {
|
|
if ($lastDate->estado == $data['estado']) {
|
|
throw new Exception(lang('Produccion.duplicate_estado_tarea_progress'));
|
|
}
|
|
if ($lastDate->estado == 'F') {
|
|
throw new Exception(lang('Produccion.task_already_finished'));
|
|
}
|
|
}
|
|
return $this->otTareaProgressDate->insert($data);
|
|
}
|
|
public function getTareaLastState($tarea_id)
|
|
{
|
|
$lastDate = $this->otTareaProgressDate->where('ot_tarea_id', $tarea_id)->orderBy('action_at', 'DESC')->first();
|
|
return $lastDate->estado;
|
|
}
|
|
public function deleteOrdenTrabajoTareaProgressDates($orden_trabajo_tarea_id): bool
|
|
{
|
|
$response = false;
|
|
$data = ['ot_tarea_id' => $orden_trabajo_tarea_id, 'estado' => 'P'];
|
|
$data["action_at"] = Time::now()->format('Y-m-d H:i:s');
|
|
$data["action_user_id"] = auth()->user()->id;
|
|
$status = $this->otTareaProgressDate->where('ot_tarea_id', $orden_trabajo_tarea_id)->delete();
|
|
if ($status) {
|
|
$response = $this->storeOrdenTrabajoTareaProgressDate($data);
|
|
}
|
|
return $response;
|
|
}
|
|
public function updateOrdenTrabajoDate($data)
|
|
{
|
|
$result = [];
|
|
$otDate = $this->otDate->where('orden_trabajo_id', $this->ot->id)
|
|
->set($data['name'], $data[$data['name']])
|
|
->update();
|
|
$this->otDate->updateUserDateMap($this->ot->id, $data);
|
|
$ot_users = $this->ot->users();
|
|
if (isset($this->ordenTrabajoConfig->DATE_USER_MAPPING[$data["name"]])) {
|
|
$user_id = $ot_users->{$this->ordenTrabajoConfig->DATE_USER_MAPPING[$data["name"]]};
|
|
$user = $this->userModel->find($user_id);
|
|
if ($user_id) {
|
|
$result = ["user" => null, "status" => false];
|
|
}
|
|
$result = ["user" => $user, "status" => $otDate];
|
|
} else {
|
|
$result = ["user" => null, "status" => false];
|
|
}
|
|
$this->updateProgress();
|
|
return $result;
|
|
}
|
|
public function emptyOrdenTrabajoDate(int $orden_trabajo_id, string $dateName)
|
|
{
|
|
$status = $this->otDate->where('orden_trabajo_id', $orden_trabajo_id)
|
|
->set($dateName, null)
|
|
->update();
|
|
if (isset($this->ordenTrabajoConfig->DATE_USER_MAPPING[$dateName])) {
|
|
$this->otUser->where('orden_trabajo_id', $orden_trabajo_id)
|
|
->set($this->ordenTrabajoConfig->DATE_USER_MAPPING[$dateName], auth()->user()->id)
|
|
->update();
|
|
}
|
|
return $status;
|
|
}
|
|
public function updateOrdenTrabajoPedidoDate($data): array
|
|
{
|
|
$status = false;
|
|
$user = auth()->user();
|
|
$row = [];
|
|
$pedidoDatesUser = $this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO;
|
|
$attrPedido = $data["name"];
|
|
if (isset($pedidoDatesUser[$attrPedido])) {
|
|
$row[$attrPedido] = Time::createFromFormat("Y-m-d", $data[$attrPedido])->format('Y-m-d 00:00:00');
|
|
$attrUserPedido = $pedidoDatesUser[$attrPedido];
|
|
$row[$attrUserPedido] = $user->id;
|
|
$status = $this->pedidoModel->update($this->pedido->id, $row);
|
|
$this->updateProgress();
|
|
} else {
|
|
throw new Exception(lang('Produccion.errors.attr_not_exist', [$attrPedido]));
|
|
}
|
|
|
|
return [
|
|
"user" => $user,
|
|
"status" => $status
|
|
];
|
|
}
|
|
public function emptyOrdenTrabajoPedidoDate(string $dateName)
|
|
{
|
|
$status = false;
|
|
$user = auth()->user();
|
|
$row = [];
|
|
$pedidoDatesUser = $this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO;
|
|
if (isset($pedidoDatesUser[$dateName])) {
|
|
$attrUserPedido = $pedidoDatesUser[$dateName];
|
|
$row[$attrUserPedido] = $user->id;
|
|
$row[$dateName] = null;
|
|
$status = $this->pedidoModel->update($this->pedido->id, $row);
|
|
$this->updateProgress();
|
|
} else {
|
|
throw new Exception(lang('Produccion.errors.attr_not_exist', [$dateName]));
|
|
}
|
|
|
|
|
|
return $status;
|
|
}
|
|
public function updateOrdenTrabajo($data): bool
|
|
{
|
|
if (isset($data["is_pedido_espera"])) {
|
|
$data["pedido_espera_by"] = auth()->user()->id;
|
|
}
|
|
return $this->otModel->update($this->ot->id, $data);
|
|
}
|
|
public function updateOrdenTrabajoPedido($data)
|
|
{
|
|
if (isset($data["inaplazable"])) {
|
|
$data[$this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO["inaplazable"]] = auth()->user()->id;
|
|
}
|
|
return $this->pedidoModel->update($this->pedido->id, $data);
|
|
}
|
|
/**========================================================================
|
|
* RELATION METHODS
|
|
*========================================================================**/
|
|
/**
|
|
* Obtiene el pedido asociado a esta clase
|
|
*
|
|
* @return PedidoEntity
|
|
*/
|
|
public function getPedido(): PedidoEntity
|
|
{
|
|
return $this->pedido;
|
|
}
|
|
|
|
public function getCliente(): ClienteEntity
|
|
{
|
|
return $this->presupuesto->cliente();
|
|
}
|
|
|
|
|
|
public function getPresupuesto(): PresupuestoEntity
|
|
{
|
|
return $this->presupuesto;
|
|
}
|
|
/**
|
|
* Devuelve las lineas de presupuesto con la máquina asociada a cada una
|
|
*
|
|
* @return array<PresupuestoLineaEntity>
|
|
*/
|
|
protected function getPresupuestoLineasWithMaquina(): array
|
|
{
|
|
$presupuesto_lineas = $this->presupuesto->presupuestoLineas();
|
|
foreach ($presupuesto_lineas as $key => $linea) {
|
|
$linea->maquina = $linea->maquina();
|
|
}
|
|
return $presupuesto_lineas;
|
|
}
|
|
protected function presupuesto_lineas_acabado(): array
|
|
{
|
|
return $this->presupuesto->acabados();
|
|
}
|
|
protected function presupuesto_lineas_manipulado(): array
|
|
{
|
|
return $this->presupuesto->manipulados();
|
|
}
|
|
protected function presupuesto_lineas_preimpresion(): array
|
|
{
|
|
return $this->presupuesto->preimpresiones();
|
|
}
|
|
protected function presupuesto_lineas_encuadernaciones(): array
|
|
{
|
|
return $this->presupuesto->encuadernaciones();
|
|
}
|
|
protected function presupuesto_lineas_extras(): array
|
|
{
|
|
return $this->presupuesto->extras();
|
|
}
|
|
protected function logistica_data(): array
|
|
{
|
|
$presupuesto_lineas = $this->presupuesto->presupuestoLineas();
|
|
$peso = 0;
|
|
foreach ($presupuesto_lineas as $key => $linea) {
|
|
$peso += $linea->peso;
|
|
}
|
|
return [
|
|
"peso_unidad" => $peso,
|
|
"peso_pedido" => $peso * $this->ot->total_tirada
|
|
];
|
|
}
|
|
|
|
protected function actionButtonFilterTask(int $id)
|
|
{
|
|
return ["title" => lang('ot.filter_by_task'), 'id' => $id];
|
|
}
|
|
|
|
public function querySelectMaquinaPlanningRotativa($q)
|
|
{
|
|
$query = $this->otModel->builder()->select([
|
|
"orden_trabajo_tareas.maquina_id as id",
|
|
"lg_maquinas.nombre as name",
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_ROTATIVA)
|
|
->where('lg_maquinas.is_rotativa', true)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->orderBy("orden_trabajo_tareas.orden", "ASC");
|
|
if ($q) {
|
|
$query->like('lg_maquinas.nombre', $q);
|
|
}
|
|
return $query->get()->getResultArray();
|
|
}
|
|
public function querySelectMaquinaPlanningPlana($q)
|
|
{
|
|
$query = $this->otModel->builder()->select([
|
|
"orden_trabajo_tareas.maquina_id as id",
|
|
"lg_maquinas.nombre as name",
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA)
|
|
->where('lg_maquinas.is_rotativa', false)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->orderBy("orden_trabajo_tareas.orden", "ASC");
|
|
if ($q) {
|
|
$query->like('lg_maquinas.nombre', $q);
|
|
}
|
|
return $query->get()->getResultArray();
|
|
}
|
|
public function querySelectMaquinaPadrePlanningPlana($q)
|
|
{
|
|
$query = $this->otModel->builder()->select([
|
|
"mp.id as id",
|
|
"mp.nombre as name",
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->join("lg_maquinas mp", "mp.id = lg_maquinas.padre_id", "left")
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA)
|
|
->where('lg_maquinas.is_rotativa', false)
|
|
->where('mp.is_padre', 0)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->groupBy("mp.id");
|
|
if ($q) {
|
|
$query->like('lg_maquinas.nombre', $q);
|
|
}
|
|
return $query->get()->getResultArray();
|
|
}
|
|
public function querySelectPapelPlanningRot(string $q)
|
|
{
|
|
$query = $this->otModel->builder()->select([
|
|
"lg_papel_impresion.id",
|
|
"lg_papel_impresion.nombre as name",
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
|
->join("lg_papel_impresion", "presupuesto_linea.papel_impresion_id = lg_papel_impresion.id", "left")
|
|
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->where("orden_trabajo_tareas.presupuesto_linea_id IS NOT NULL", NULL, FALSE)
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_ROTATIVA)
|
|
->groupBy('lg_papel_impresion.id');
|
|
if ($q) {
|
|
$query->like('lg_papel_impresion.nombre', $q);
|
|
}
|
|
return $query->get()->getResultArray();
|
|
}
|
|
public function querySelectPapelPlanningPlana($q)
|
|
{
|
|
$query = $this->otModel->builder()->select([
|
|
"lg_papel_impresion.id",
|
|
"lg_papel_impresion.nombre as name",
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
|
->join("lg_papel_impresion", "presupuesto_linea.papel_impresion_id = lg_papel_impresion.id", "left")
|
|
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->where("orden_trabajo_tareas.presupuesto_linea_id IS NOT NULL", NULL, FALSE)
|
|
->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA)
|
|
->groupBy('lg_papel_impresion.id');
|
|
if ($q) {
|
|
$query->like('lg_papel_impresion.nombre', $q);
|
|
}
|
|
return $query->get()->getResultArray();
|
|
}
|
|
public function tareaUpdateMaquinaCorte($orden_trabajo_id): bool
|
|
{
|
|
$cvm = model(ConfigVariableModel::class);
|
|
$otTarea = $this->otTarea->where('orden_trabajo_id', $orden_trabajo_id)->where('is_corte', true)->first();
|
|
$toggleCorte = "bobina";
|
|
if ($otTarea->tipo_corte == "bobina") {
|
|
$maquina_id = $cvm->where('name', "id_maquina_guillotina_corte_ot_tarea")->first()["value"];
|
|
$toggleCorte = "guillotina";
|
|
} elseif ($otTarea->tipo_corte == "guillotina") {
|
|
$maquina_id = $cvm->where('name', "id_maquina_bobina_corte_ot_tarea")->first()["value"];
|
|
$toggleCorte = "bobina";
|
|
} else {
|
|
$maquina_id = null;
|
|
}
|
|
return $this->otTarea
|
|
->where('orden_trabajo_id', $orden_trabajo_id)
|
|
->where('is_corte', true)
|
|
->set(["maquina_id" => $maquina_id, "tipo_corte" => $toggleCorte])
|
|
->update();
|
|
}
|
|
public function ordenTrabajoTareaCorte(int $ot_id): ?string
|
|
{
|
|
return $this->otTarea->where('orden_trabajo_id', $ot_id)->where('is_corte', true)?->first()->tipo_corte ?? null;
|
|
}
|
|
|
|
public function getOtFiles(): array
|
|
{
|
|
$otFiles = $this->ot->files();
|
|
return $otFiles;
|
|
}
|
|
public function storeOtFiles(array $uploadFiles): array
|
|
{
|
|
$otFileEntities = [];
|
|
foreach ($uploadFiles as $uploadFile) {
|
|
$otFileEntities[] = $this->storeOtFile($uploadFile);
|
|
}
|
|
return $otFileEntities;
|
|
}
|
|
protected function storeOtFile(UploadedFile $file): ?OrdenTrabajoFileEntity
|
|
{
|
|
$result = null;
|
|
if ($this->ot) {
|
|
if ($file->isValid() && !$file->hasMoved()) {
|
|
$fullpath = $file->store('orden_trabajo/' . $this->ot->id);
|
|
$ot_file_id = $this->otFileModel->insert([
|
|
"orden_trabajo_id" => $this->ot->id,
|
|
"name" => $file->getClientName(),
|
|
"file_path" => WRITEPATH . 'uploads/' . $fullpath,
|
|
"upload_by" => auth()->user()->id
|
|
]);
|
|
$result = $this->otFileModel->find($ot_file_id);
|
|
}
|
|
return $result;
|
|
} else {
|
|
throw new Exception('No se ha especificado una orden de trabajo. Usa $this->producctionService->init($orden_trabajo_id)');
|
|
}
|
|
}
|
|
public function deleteOtFiles(?array $existingFiles): bool
|
|
{
|
|
helper('filesystem');
|
|
if ($this->ot) {
|
|
$otFiles = $this->ot->files();
|
|
|
|
foreach ($otFiles as $key => $file) {
|
|
$file_path = $file->file_path;
|
|
if ($existingFiles) {
|
|
if (!in_array($file->name, $existingFiles)) {
|
|
$this->otFileModel->delete($file->id);
|
|
unlink($file_path);
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
} else {
|
|
throw new Exception('No se ha especificado una orden de trabajo. Usa $this->producctionService->init($orden_trabajo_id)');
|
|
}
|
|
}
|
|
protected function updatePedidoEspera(): bool
|
|
{
|
|
$status = false;
|
|
$presupuestoFiles = $this->presupuesto->files();
|
|
if (count($presupuestoFiles) == 0) {
|
|
$status = $this->otModel->update($this->ot->id, ['is_pedido_espera' => true]);
|
|
}
|
|
return $status;
|
|
}
|
|
public function userDates(): array
|
|
{
|
|
$userDates = [];
|
|
foreach ($this->ordenTrabajoConfig->DATE_USER_MAPPING as $key => $value) {
|
|
$otUserEntity = $this->otUser->where("orden_trabajo_id", $this->ot->id)->first();
|
|
$userEntity = $otUserEntity->userBy($value);
|
|
if ($userEntity) {
|
|
$userDates[$key] = $userEntity->full_name;
|
|
} else {
|
|
$userDates[$key] = null;
|
|
}
|
|
}
|
|
return $userDates;
|
|
}
|
|
public function pedidoUserDates(): array
|
|
{
|
|
$pedidoUserDates = [];
|
|
foreach ($this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO as $key => $value) {
|
|
$userEntity = $this->pedido->userBy($value);
|
|
if ($userEntity) {
|
|
$pedidoUserDates[$key] = $userEntity->full_name;
|
|
} else {
|
|
$pedidoUserDates[$key] = null;
|
|
}
|
|
}
|
|
return $pedidoUserDates;
|
|
}
|
|
public function getTiempoProcesamientoHHMM(): ?string
|
|
{
|
|
$time_tareas_seconds = array_map(fn($q) => $q->tiempo_estimado ?? 0, $this->ot->tareas());
|
|
$seconds = array_sum($time_tareas_seconds);
|
|
return float_seconds_to_hhmm_string($seconds);
|
|
}
|
|
public function getTiempoTareasImpresionHHMM(): string
|
|
{
|
|
$tareas_impresion = $this->ot->tareas_impresion();
|
|
$tiempo_seconds = 0;
|
|
foreach ($tareas_impresion as $key => $tarea) {
|
|
if ($tarea->is_corte == false) {
|
|
$tiempo_seconds += $tarea->tiempo_estimado;
|
|
}
|
|
}
|
|
return float_seconds_to_hhmm_string($tiempo_seconds);
|
|
}
|
|
public function getUVI(): ?TarifaAcabadoEntity
|
|
{
|
|
$uvi = null;
|
|
$acabados = $this->presupuesto->acabados();
|
|
foreach ($acabados as $key => $acabado) {
|
|
if ($acabado->tarifa()->isUVI()) {
|
|
$uvi = $acabado->tarifa();
|
|
}
|
|
}
|
|
return $uvi;
|
|
}
|
|
public function updateProgress(): bool
|
|
{
|
|
$userDates = $this->ordenTrabajoConfig->DATE_USER_MAPPING;
|
|
$pedidoUserDates = $this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO;
|
|
|
|
$fill_dates = 0;
|
|
$status = false;
|
|
$total = count($userDates) + count($pedidoUserDates);
|
|
if ($this->ot->estado != "F") {
|
|
if ($this->ot->dates()) {
|
|
|
|
foreach ($userDates as $key => $value) {
|
|
if ($this->ot->dates()->{$key} != null) $fill_dates++;
|
|
}
|
|
foreach ($pedidoUserDates as $key => $value) {
|
|
if ($this->pedido->{$key} != null) $fill_dates++;
|
|
}
|
|
|
|
$progreso = (float) $fill_dates / $total * 100;
|
|
$status = $this->otModel->update($this->ot->id, ["progreso" => round($progreso, 2)]);
|
|
}
|
|
} else {
|
|
$status = $this->otModel->update($this->ot->id, ["progreso" => 100]);
|
|
}
|
|
return $status;
|
|
}
|
|
public function getOtColorStatus(): string
|
|
{
|
|
if ($this->ot->dates()) {
|
|
$this->updateColor();
|
|
}
|
|
return $this->statusColor;
|
|
}
|
|
protected function otSinImprimirColor()
|
|
{
|
|
if ($this->ot->dates()->sinImprimirStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["sin_imprimir"];
|
|
};
|
|
}
|
|
protected function otImpresionIntColor()
|
|
{
|
|
if ($this->ot->dates()->impresionInteriorStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["impreso_int"];
|
|
};
|
|
}
|
|
protected function otImpresionCubiertaColor()
|
|
{
|
|
if ($this->ot->dates()->impresionCubiertaStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["impreso_cub"];
|
|
};
|
|
}
|
|
protected function otPlastificadoColor()
|
|
{
|
|
if ($this->ot->dates()->plastificadoStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["plastificado"];
|
|
};
|
|
}
|
|
protected function otSolapaColor()
|
|
{
|
|
if ($this->ot->dates()->solapaStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["solapa"];
|
|
};
|
|
}
|
|
protected function otEncuadernadoColor()
|
|
{
|
|
if ($this->ot->dates()->encuadernadoStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["encuadernado"];
|
|
};
|
|
}
|
|
protected function otPreparadoColor()
|
|
{
|
|
if ($this->ot->dates()->preparacionInterioresStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["preparado"];
|
|
};
|
|
}
|
|
protected function otCorteColor()
|
|
{
|
|
if ($this->ot->dates()->corteStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["corte"];
|
|
};
|
|
}
|
|
protected function otCosidoColor()
|
|
{
|
|
if ($this->ot->dates()->cosidoStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["cosido"];
|
|
};
|
|
}
|
|
protected function otGrapadoColor()
|
|
{
|
|
if ($this->ot->dates()->grapadoStatus()) {
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["grapado"];
|
|
};
|
|
}
|
|
protected function updateColor()
|
|
{
|
|
$this->otSinImprimirColor();
|
|
$this->otImpresionIntColor();
|
|
$this->otCosidoColor();
|
|
$this->otImpresionCubiertaColor();
|
|
$this->otPlastificadoColor();
|
|
$this->otSolapaColor();
|
|
$this->otPreparadoColor();
|
|
$this->otGrapadoColor();
|
|
$this->otEncuadernadoColor();
|
|
$this->otCorteColor();
|
|
}
|
|
public function getEncuadernacionCode(): ?string
|
|
{
|
|
$code = "";
|
|
$encuadernaciones = $this->presupuesto->encuadernaciones();
|
|
if (isset($encuadernaciones[0])) {
|
|
$code = $encuadernaciones[0]->tarifa()->code;
|
|
}
|
|
return $code;
|
|
}
|
|
public function getEncuadernacionColor(): array
|
|
{
|
|
$color = $this->ordenTrabajoConfig->OT_ENCUADERNACION_COLOR["default"];
|
|
$encuadernacion_code = $this->getEncuadernacionCode();
|
|
if ($encuadernacion_code) {
|
|
if (isset($this->ordenTrabajoConfig->OT_ENCUADERNACION_COLOR[$encuadernacion_code])) {
|
|
$color = $this->ordenTrabajoConfig->OT_ENCUADERNACION_COLOR[$encuadernacion_code];
|
|
}
|
|
}
|
|
return $color;
|
|
}
|
|
public function getWeekDayColor(): array
|
|
{
|
|
$color = $this->ordenTrabajoConfig->OT_WEEK_COLOR_DAY[0];
|
|
if ($this->ot->pedido()->fecha_encuadernado) {
|
|
$week_day = Time::createFromFormat("Y-m-d H:i:s", $this->ot->pedido()->fecha_encuadernado)->getDayOfWeek();
|
|
$color = $this->ordenTrabajoConfig->OT_WEEK_COLOR_DAY[$week_day];
|
|
}
|
|
return $color;
|
|
}
|
|
public function getGeneralBackgroundColor()
|
|
{
|
|
$color = $this->ordenTrabajoConfig->OT_BACKGROUND_COLOR['default'];
|
|
$is_ferro_or_prototipo = ($this->presupuesto->ferro || $this->presupuesto->ferro_digital || $this->presupuesto->prototipo);
|
|
$color = $is_ferro_or_prototipo ? $this->ordenTrabajoConfig->OT_BACKGROUND_COLOR['ferro'] : $color;
|
|
$color = $this->isPOD ? $this->ordenTrabajoConfig->OT_BACKGROUND_COLOR['pod'] : $color;
|
|
$color = $this->pedido->inaplazable ? $this->ordenTrabajoConfig->OT_BACKGROUND_COLOR['inaplazable'] : $color;
|
|
return $color;
|
|
}
|
|
public function getPapelImpresionBackgroundColor()
|
|
{
|
|
$papel = $this->presupuesto->presupuestoLineaImpresion()->papel_generico();
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['default'];
|
|
$papel_code = $papel->code_ot;
|
|
if ($papel_code) {
|
|
if (strpos($papel_code, "BCLOF")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['blanco'];
|
|
}
|
|
if (strpos($papel_code, "AH") && $papel->code == "OFF2") {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['ahuesado'];
|
|
}
|
|
if (strpos($papel_code, "MARF")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['marfil'];
|
|
}
|
|
if (strpos($papel_code, "VOLAH")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['volumen_ahuesado'];
|
|
}
|
|
if ($papel_code == "EM") {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['estucado_mate'];
|
|
}
|
|
if ($papel_code == "CGE") {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['cartulina'];
|
|
}
|
|
}
|
|
|
|
return $color;
|
|
}
|
|
public function getPapelImpresionCubiertaBackgroundColor()
|
|
{
|
|
$papel = $this->presupuesto->presupuestoLineaCubierta()->papel_generico();
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['default'];
|
|
$papel_code = $papel->code_ot;
|
|
if ($papel_code) {
|
|
if (strpos($papel_code, "BCLOF")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['blanco'];
|
|
}
|
|
if (strpos($papel_code, "AH") && $papel->code == "OFF2") {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['ahuesado'];
|
|
}
|
|
if (strpos($papel_code, "MARF")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['marfil'];
|
|
}
|
|
if (strpos($papel_code, "VOLAH")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['volumen_ahuesado'];
|
|
}
|
|
if ($papel_code == "EM") {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['estucado_mate'];
|
|
}
|
|
if ($papel_code == "CGE") {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['cartulina'];
|
|
}
|
|
}
|
|
return $color;
|
|
}
|
|
public function getPlastificadoColor()
|
|
{
|
|
$acabados = $this->presupuesto->acabados();
|
|
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['default'];
|
|
foreach ($acabados as $key => $acabado) {
|
|
$tarifa_acabado = $acabado->tarifa();
|
|
if ($tarifa_acabado->code) {
|
|
$plastificado_code = $tarifa_acabado->code;
|
|
if ($plastificado_code == "BRIL") {
|
|
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['BRIL'];
|
|
}
|
|
if ($plastificado_code == "MATE") {
|
|
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['MATE'];
|
|
}
|
|
if ($plastificado_code == "ANTI") {
|
|
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['ANTIRAYADO'];
|
|
}
|
|
if ($plastificado_code == "SAND") {
|
|
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['SANDY'];
|
|
}
|
|
if ($plastificado_code == "GOF") {
|
|
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['GOFRADO'];
|
|
}
|
|
}
|
|
}
|
|
return $color;
|
|
}
|
|
public function getImpresionInteriorPPALColor()
|
|
{
|
|
$isRotativa = $this->presupuesto->presupuestoLineaImpresion()->isRotativa();
|
|
$color = $isRotativa ? $this->ordenTrabajoConfig->OT_IMPRESION_INTERIOR_PPAL_COLOR['ROTATIVA'] : $this->ordenTrabajoConfig->OT_IMPRESION_INTERIOR_PPAL_COLOR['GENERAL'];
|
|
$color = $this->isPOD ? $this->ordenTrabajoConfig->OT_IMPRESION_INTERIOR_PPAL_COLOR['POD'] : $color;
|
|
return $color;
|
|
}
|
|
public function getPdfColors(): array
|
|
{
|
|
return [
|
|
"general" => $this->getGeneralBackgroundColor(),
|
|
"week_day" => $this->getWeekDayColor(),
|
|
"ot" => $this->getEncuadernacionColor(),
|
|
"papel_interior" => $this->getPapelImpresionBackgroundColor(),
|
|
"papel_cubierta" => $this->getPapelImpresionCubiertaBackgroundColor(),
|
|
"plastificado" => $this->getPlastificadoColor(),
|
|
"impresion_interior_ppal" => $this->getImpresionInteriorPPALColor()
|
|
];
|
|
}
|
|
|
|
public function getFlags()
|
|
{
|
|
$this->color();
|
|
return [
|
|
"isGofrado" => $this->gofrado(),
|
|
"isEspiral" => $this->isEspiral,
|
|
"isUVI" => $this->uvi(),
|
|
"isPlastificado" => $this->isPlastificado,
|
|
"isCubierta" => $this->cubierta(),
|
|
"isColor" => $this->isColor,
|
|
"isBN" => $this->isBN,
|
|
"isCorte" => $this->corte(),
|
|
"isGrapado" => $this->isGrapado
|
|
];
|
|
}
|
|
public function gofrado(): bool
|
|
{
|
|
$flag = false;
|
|
$acabados = $this->presupuesto->acabados();
|
|
foreach ($acabados as $key => $acabado) {
|
|
$tarifa_acabado = $acabado->tarifa();
|
|
if ($tarifa_acabado->code) {
|
|
$plastificado_code = $tarifa_acabado->code;
|
|
if ($plastificado_code == "GOF") {
|
|
$flag = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$this->isGofrado = $flag;
|
|
return $this->isGofrado;
|
|
}
|
|
public function uvi(): bool
|
|
{
|
|
$flag = false;
|
|
$tarifa_acabado_uvi = $this->getUVI();
|
|
if ($tarifa_acabado_uvi) {
|
|
$flag = true;
|
|
}
|
|
$this->isUVI = $flag;
|
|
return $this->isUVI;
|
|
}
|
|
public function cubierta(): bool
|
|
{
|
|
$lineaCubierta = $this->presupuesto->presupuestoLineaCubierta();
|
|
if ($lineaCubierta) {
|
|
$this->isCubierta = true;
|
|
}
|
|
return $this->isCubierta;
|
|
}
|
|
public function color(): bool
|
|
{
|
|
$linea_impresion = $this->presupuesto->presupuestoLineaImpresion();
|
|
if ($linea_impresion) {
|
|
if ($linea_impresion->isColor()) {
|
|
$this->isColor = true;
|
|
$this->isBN = false;
|
|
} else {
|
|
$this->isColor = false;
|
|
$this->isBN = true;
|
|
}
|
|
}
|
|
return $this->isColor;
|
|
}
|
|
public function corte(): bool
|
|
{
|
|
$ot_tareas = $this->ot->tareas();
|
|
foreach ($ot_tareas as $key => $tarea) {
|
|
if ($tarea->is_corte) {
|
|
$this->isCorte = true;
|
|
break;
|
|
}
|
|
}
|
|
return $this->isCorte;
|
|
}
|
|
public function getFileBarCode()
|
|
{
|
|
return $this->ot->getBarCodeFile();
|
|
}
|
|
|
|
public function getMaquinaImpresionTareasList(int $maquina_id)
|
|
{
|
|
|
|
$q = $this->otModel->builder()->select([
|
|
"ordenes_trabajo.id as otId",
|
|
"orden_trabajo_tareas.id as ot_tarea_id",
|
|
"pedidos.fecha_impresion",
|
|
"orden_trabajo_tareas.nombre as tareaName",
|
|
"presupuestos.titulo as presupuesto_titulo",
|
|
"orden_trabajo_tareas.maquina_id",
|
|
"lg_papel_impresion.nombre as papel_impresion",
|
|
"presupuesto_linea.gramaje as papel_gramaje",
|
|
"tarea_progress.estado as tareaEstado"
|
|
])
|
|
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
|
// Obtener el ultimo estado de la tarea
|
|
->join(
|
|
'(SELECT ot_tarea_id, estado
|
|
FROM orden_trabajo_tarea_progress_dates
|
|
WHERE (ot_tarea_id, created_at) IN (
|
|
SELECT ot_tarea_id, MAX(created_at)
|
|
FROM orden_trabajo_tarea_progress_dates
|
|
GROUP BY ot_tarea_id
|
|
)
|
|
) as tarea_progress',
|
|
'tarea_progress.ot_tarea_id = orden_trabajo_tareas.id',
|
|
'left'
|
|
)
|
|
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
|
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
|
->join("pedidos", "pedidos.id = ordenes_trabajo.pedido_id", "right")
|
|
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->join("lg_papel_impresion", "lg_papel_impresion.id = presupuesto_linea.papel_impresion_id", "left")
|
|
->groupStart()
|
|
->orWhere('orden_trabajo_tareas.maquina_id', $maquina_id)
|
|
->orWhere('presupuesto_linea.maquina_id', $maquina_id)
|
|
->groupEnd()
|
|
// ->where('pedidos.fecha_impresion IS NOT NULL', null, false)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->where("tarea_progress.estado", 'P')
|
|
->orderBy("pedidos.fecha_impresion", "ASC")
|
|
->groupBy('orden_trabajo_tareas.nombre');
|
|
|
|
return $q;
|
|
}
|
|
public function buttonActionDatatableTareaList($id)
|
|
{
|
|
$url = route_to("viewProduccionMaquinistaTareaView", $id);
|
|
return "<a type='button' href='$url' class='maquina-btn btn btn-primary btn-md'><span class='ti ti-arrow-big-right'></span></a>";
|
|
}
|
|
}
|