mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
2377 lines
95 KiB
PHP
Executable File
2377 lines
95 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\FestivoModel;
|
|
use App\Models\Configuracion\MaquinaModel;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoFileModel;
|
|
use App\Models\OrdenTrabajo\OrdenTrabajoTareaProgressDate;
|
|
use App\Models\Pedidos\PedidoModel;
|
|
use App\Models\Presupuestos\PresupuestoAcabadosModel;
|
|
use App\Models\Presupuestos\PresupuestoEncuadernacionesModel;
|
|
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'];
|
|
|
|
public array $OT_TAREA_STATUS_TITLE;
|
|
protected OrdenTrabajoModel $otModel;
|
|
|
|
protected OrdenTrabajoTarea $otTarea;
|
|
protected OrdenTrabajoDate $otDate;
|
|
protected OrdenTrabajoUser $otUser;
|
|
protected OrdenTrabajoEntity $ot;
|
|
protected OrdenTrabajoFileModel $otFileModel;
|
|
protected FestivoModel $festivoModel;
|
|
protected OrdenTrabajoTareaProgressDate $otTareaProgressDate;
|
|
protected PedidoModel $pedidoModel;
|
|
protected UserModel $userModel;
|
|
protected ConfigVariableModel $configVariableModel;
|
|
protected MaquinaEntity $defaultMaquinaCorte;
|
|
protected MaquinaModel $maquinaModel;
|
|
protected OrdenTrabajo $ordenTrabajoConfig;
|
|
protected PresupuestoAcabadosModel $presupuestoAcabadoModel;
|
|
protected PresupuestoEncuadernacionesModel $presupuestoEncuadernacionModel;
|
|
|
|
|
|
/**
|
|
* 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;
|
|
public int $guillotinaMaquinaId;
|
|
/**
|
|
* Valor límite del POD
|
|
*
|
|
* `$this->configVariableModel->getVariable('POD')->value;`
|
|
* @var integer
|
|
*/
|
|
protected int $podValue = 0;
|
|
/**
|
|
* Indica si es POD
|
|
*
|
|
* `tirada <= podValue`
|
|
* @var boolean
|
|
*/
|
|
public 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 plastificado
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isPlastificado = false; //* CHECK DONE
|
|
/**
|
|
* Indica si la orden de trabajo contiene retractilado
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isRetractilado = false; //* CHECK DONE
|
|
/**
|
|
* Indica si la orden de trabajo contiene gofrado
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isPlakene = false; //* CHECK DONE
|
|
/**
|
|
* Indica si la orden de trabajo contiene gofrado
|
|
* Se usa para mostrar la fecha correspondiente en la vista
|
|
* @var boolean
|
|
*/
|
|
public bool $isEstampado = false; //* CHECK DONE
|
|
/**
|
|
* Indica si la orden de trabajo contiene cosido
|
|
* Se usa para mostrar la fecha correspondiente en la vista y pliegos
|
|
* @var boolean
|
|
*/
|
|
public bool $isCosido = 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_manipulado` para identificar
|
|
* @var boolean
|
|
*/
|
|
public bool $isGrapado = false; //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 = false; //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 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->maquinaModel = model(MaquinaModel::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->festivoModel = model(FestivoModel::class);
|
|
$this->ordenTrabajoConfig = config('OrdenTrabajo');
|
|
$this->presupuestoAcabadoModel = model(PresupuestoAcabadosModel::class);
|
|
$this->presupuestoEncuadernacionModel = model(PresupuestoEncuadernacionesModel::class);
|
|
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["sin_imprimir"];
|
|
$this->configVariableModel = model(ConfigVariableModel::class);
|
|
$this->podValue = $this->configVariableModel->getVariable('POD')->value;
|
|
$this->guillotinaMaquinaId = $this->configVariableModel->getVariable('maquina_guillotina_id_default')->value;
|
|
$this->OT_TAREA_STATUS_TITLE = [
|
|
"P" => lang('Produccion.tarea_estados.P'),
|
|
"F" => lang('Produccion.tarea_estados.F'),
|
|
"S" => lang('Produccion.tarea_estados.S'),
|
|
"I" => lang('Produccion.tarea_estados.I'),
|
|
"E" => lang('Produccion.tarea_estados.E'),
|
|
"D" => lang('Produccion.tarea_estados.D'),
|
|
];
|
|
}
|
|
|
|
public function init(int $orden_trabajo_id): self
|
|
{
|
|
try {
|
|
$ot = $this->otModel->find($orden_trabajo_id);
|
|
if ($ot == null) {
|
|
throw new Exception(lang('Produccion.errors.ot_not_found', ['ot_id' => $orden_trabajo_id]));
|
|
}
|
|
$this->ot = $ot;
|
|
$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(bool $imported = false): 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,
|
|
"preimpresion_revisada" => $imported
|
|
];
|
|
$id = $this->otModel->insert($data);
|
|
$this->init($id);
|
|
$this->storeOrdenTrabajoUsers();
|
|
$this->storeOrdenTrabajoDates();
|
|
$this->storeAllTareas();
|
|
try {
|
|
$this->updatePodDates();
|
|
} catch (\Throwable $th) {
|
|
}
|
|
$this->updatePedidoEspera();
|
|
return $this->ot;
|
|
}
|
|
|
|
/**
|
|
* Inserta las fechas del pedido asociado a la orden de trabajo en `orden_trabajo_tareas`
|
|
* Si el pedido es POD las fechas se insertan automaticamente usando `createDatesForPOD` y
|
|
* en base a las variables :
|
|
* - pod_impresion_dias_tras_confirmacion [fecha_impresion_at]
|
|
* - pod_encuadernacion_dias_tras_confirmacion [fecha_encuadernacion]
|
|
* - pod_entrega_real_dias_tras_confirmacion [fecha_impresion_at]
|
|
* - pod_embalaje_dias_tras_confirmacion [fecha_impresion_at]
|
|
*
|
|
* @param OrdenTrabajoEntity $ot
|
|
* @return integer|boolean|string ID
|
|
*/
|
|
protected function storeOrdenTrabajoDates(): int|bool|string
|
|
{
|
|
$otDateId = $this->otDate->insert(["orden_trabajo_id" => $this->ot->id]);
|
|
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->storeTareaCorteFinal();
|
|
|
|
// $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"] = 0;
|
|
$insert_query_result = $this->otTarea->insert($ot_tareas);
|
|
$ot_tareas = [];
|
|
$this->storeTareaCorteBloque($p_linea);
|
|
$this->storeTareaCorte($p_linea);
|
|
}
|
|
return $insert_query_result;
|
|
}
|
|
/**
|
|
* Inserta una tarea de corte si la impresion es en `rotativa`
|
|
*
|
|
* @return OrdenTrabajoTareaEntity|null
|
|
*/
|
|
protected function storeTareaCorteFinal(): ?OrdenTrabajoTareaEntity
|
|
{
|
|
|
|
$presupuestoLineaImpresion = $this->presupuesto->presupuestoLineaImpresion();
|
|
$data = [
|
|
'orden_trabajo_id' => $this->ot->id,
|
|
'presupuesto_linea_id' => $presupuestoLineaImpresion->id,
|
|
'nombre' => lang('Produccion.end_cut'),
|
|
'maquina_id' => $this->defaultMaquinaCorte->id,
|
|
'orden' => $this->defaultMaquinaCorte->orden_planning,
|
|
'tiempo_estimado' => 0,
|
|
'tiempo_real' => 0,
|
|
'is_corte' => true,
|
|
'tipo_corte' => "bobina",
|
|
];
|
|
$tareaId = $this->otTarea->insert($data);
|
|
$otCorte = $this->otTarea->find($tareaId);
|
|
return $otCorte;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
$presupuestoTipo = $this->presupuesto->tipo_presupuesto()->codigo;
|
|
$isRusticaFresado = str_contains($presupuestoTipo, "Fresado");
|
|
$data = [
|
|
'orden_trabajo_id' => $this->ot->id,
|
|
'presupuesto_linea_id' => $pLinea->id,
|
|
'nombre' => 'Corte',
|
|
'maquina_id' => $this->guillotinaMaquinaId,
|
|
'orden' => $pLinea->maquina()->orden_planning + 1,
|
|
'tiempo_estimado' => $pLinea->rotativa_tiempo_corte * 60,
|
|
'tiempo_real' => 0,
|
|
'is_corte' => true,
|
|
'tipo_corte' => "prep",
|
|
];
|
|
if ($pLinea->isCubierta()) {
|
|
$data['nombre'] = lang('Produccion.cover_cut');
|
|
$tareaId = $this->otTarea->insert($data);
|
|
$otCorte = $this->otTarea->find($tareaId);
|
|
}
|
|
if ($pLinea->isImpresionInteriorPlana() || $pLinea->isRotativa()) {
|
|
$data['nombre'] = lang('Produccion.interior_cut');
|
|
//* Si es rustica fresado y rotativa no se añade preparación de interior en guillotina
|
|
if (!$isRusticaFresado && !$pLinea->isRotativa()) {
|
|
$tareaId = $this->otTarea->insert($data);
|
|
$otCorte = $this->otTarea->find($tareaId);
|
|
return $otCorte;
|
|
}
|
|
}
|
|
return $otCorte;
|
|
}
|
|
|
|
/**
|
|
* Inserta una tarea de corte a bloque
|
|
* Se añade después de una tarea de impresión interior en rotativa.
|
|
*
|
|
*
|
|
* @param PresupuestoLineaEntity $pLinea
|
|
* @return OrdenTrabajoTareaEntity|null
|
|
*/
|
|
protected function storeTareaCorteBloque(PresupuestoLineaEntity $pLinea)
|
|
{
|
|
$otCorte = null;
|
|
$name = $this->cosido() ? lang('Produccion.hunkeler') : lang('Produccion.tecnau');
|
|
if ($pLinea->isRotativa()) {
|
|
$tareaId = $this->otTarea->insert([
|
|
'orden_trabajo_id' => $this->ot->id,
|
|
'presupuesto_linea_id' => $pLinea->id,
|
|
'nombre' => $name,
|
|
'maquina_id' => $this->defaultMaquinaCorte->id,
|
|
'orden' => $pLinea->maquina()->orden_planning + 1,
|
|
'tiempo_estimado' => $pLinea->rotativa_tiempo_corte * 60,
|
|
'tiempo_real' => 0,
|
|
'is_corte' => true,
|
|
'tipo_corte' => "bloque",
|
|
]);
|
|
$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 getTareasWithMaquina(int $maquina_id, ?array $tareaEstados = null): ?array
|
|
{
|
|
return $this->otModel->queryMaquinaTareas($maquina_id, $tareaEstados)
|
|
->where('ordenes_trabajo.id', $this->ot->id)
|
|
->get()->getResult(OrdenTrabajoTareaEntity::class);
|
|
}
|
|
|
|
public function getPdf()
|
|
{
|
|
return view("themes/vuexy/pdfs/orden_trabajo", $this->getDataPdf());
|
|
}
|
|
public function getPdfContent()
|
|
{
|
|
return view("themes/vuexy/pdfs/orden_trabajo_view", $this->getDataPdf());
|
|
}
|
|
public function getFerroPdf()
|
|
{
|
|
return view("themes/vuexy/pdfs/ferro", $this->getDataPdf());
|
|
}
|
|
public function getPrototipoPdf()
|
|
{
|
|
return view("themes/vuexy/pdfs/prototipo", $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",
|
|
"orden_trabajo_tareas.presupuesto_acabado_id",
|
|
"orden_trabajo_tareas.presupuesto_manipulado_id",
|
|
"orden_trabajo_tareas.presupuesto_preimpresion_id",
|
|
"orden_trabajo_tareas.presupuesto_encuadernado_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('lg_maquinas.tipo', 'impresion')
|
|
->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('lg_maquinas.tipo', 'impresion')
|
|
->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;
|
|
}
|
|
public function maquinaPlanaDatatableQuery()
|
|
{
|
|
$q = $this->otModel->builder()->select([
|
|
"lg_maquinas.nombre as maquinaNombre",
|
|
"lg_maquinas.id as maquinaId",
|
|
"COUNT(orden_trabajo_tareas.id) as tareasCount",
|
|
"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_maquinas', "lg_maquinas.id = orden_trabajo_tareas.maquina_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)
|
|
->where('lg_maquinas.tipo', 'impresion')
|
|
// ->where('lg_maquinas.padre_id', 0)
|
|
->groupBy('lg_maquinas.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->getTiempoProcesamientoHHMMSS(),
|
|
"tiempo_total" => $this->getTiempoTotalTareas(),
|
|
"statusColor" => $this->getOtColorStatus(),
|
|
"tareaCosido" => $this->getTareaCosido(),
|
|
];
|
|
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(),
|
|
"encuadernacionCode" => $this->getEncuadernacionCode(),
|
|
"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->getTiempoProcesamientoHHMMSS(),
|
|
"tiempo_impresion" => $this->getTiempoTareasImpresionHHMMSS(),
|
|
"colors" => $this->getPdfColors(),
|
|
"isPOD" => $this->isPOD,
|
|
"uvi" => $this->getUVI(),
|
|
"flags" => $this->getFlags(),
|
|
"tareaCosido" => $this->getTareaCosido(),
|
|
"plakene_tipo" => $this->plakene_tipo()
|
|
];
|
|
}
|
|
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('orden_trabajo_id', $this->ot->id)->where("presupuesto_acabado_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
public function tareas_impresion(): array
|
|
{
|
|
$q = $this->otTarea->where('orden_trabajo_id', $this->ot->id)->where("presupuesto_linea_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
public function tareas_encuadernacion(): array
|
|
{
|
|
$q = $this->otTarea->where('orden_trabajo_id', $this->ot->id)->where("presupuesto_encuadernado_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
public function tareas_preimpresion(): array
|
|
{
|
|
$q = $this->otTarea->where('orden_trabajo_id', $this->ot->id)->where("presupuesto_preimpresion_id IS NOT NULL", NULL, FALSE)->findAll();
|
|
return $q;
|
|
}
|
|
public function tareas_manipulado(): array
|
|
{
|
|
$q = $this->otTarea->where('orden_trabajo_id', $this->ot->id)->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 updateOrdenTrabajoTareaPliegos($data_pliegos): bool
|
|
{
|
|
$flag = false;
|
|
$tareas = $this->ot->tareas();
|
|
foreach ($tareas as $key => $tarea) {
|
|
if ($tarea->isCosido()) {
|
|
$flag = $this->otTarea->update($tarea->id, $data_pliegos);
|
|
break;
|
|
}
|
|
}
|
|
return $flag;
|
|
}
|
|
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'));
|
|
}
|
|
}
|
|
if (isset($data['estado'])) {
|
|
if ($data['estado'] == 'F') {
|
|
$tareaEntity = $this->otTarea->find($data['ot_tarea_id']);
|
|
$this->init($tareaEntity->orden_trabajo_id);
|
|
$dateName = $this->getOrdenTrabajoTareaDate($tareaEntity);
|
|
$dataDate = [
|
|
'name' => $dateName,
|
|
];
|
|
$dataDate[$dateName] = Time::now()->format('Y-m-d');
|
|
$this->updateOrdenTrabajoDate($dataDate);
|
|
}
|
|
}
|
|
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) {
|
|
$tareaEntity = $this->otTarea->find($orden_trabajo_tarea_id);
|
|
$this->init($tareaEntity->orden_trabajo_id);
|
|
$dateName = $this->getOrdenTrabajoTareaDate($tareaEntity);
|
|
$this->emptyOrdenTrabajoDate($this->ot->id, $dateName);
|
|
$tareaEntity->tiempo_real = 0;
|
|
$tareaEntity->click_init = 0;
|
|
$tareaEntity->click_end = 0;
|
|
$this->otTarea->save($tareaEntity);
|
|
}
|
|
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 updateOrdenTrabajoData($data)
|
|
{
|
|
$result = $this->otModel->where('id', $this->ot->id)
|
|
->set($data['name'], $data[$data['name']])
|
|
->update();
|
|
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;
|
|
}
|
|
if (isset($data["preimpresion_revisada"])) {
|
|
$data["preimpresion_revisada_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")
|
|
->groupBy('lg_maquinas.id');
|
|
if ($q) {
|
|
$query->like('lg_maquinas.nombre', $q);
|
|
}
|
|
return $query->get()->getResultArray();
|
|
}
|
|
public function querySelectMaquinaPlanningPlana($q, ?string $padreId)
|
|
{
|
|
$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")
|
|
->groupBy('lg_maquinas.id');
|
|
if ($q) {
|
|
$query->like('lg_maquinas.nombre', $q);
|
|
}
|
|
if ($padreId) {
|
|
$query->where('lg_maquinas.padre_id', $padreId);
|
|
}
|
|
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")
|
|
->where('lg_maquinas.is_rotativa', false)
|
|
->where('lg_maquinas.is_padre !=', 0)
|
|
->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, ?string $maquinaId)
|
|
{
|
|
$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);
|
|
}
|
|
if ($maquinaId) {
|
|
$query->where('orden_trabajo_tareas.maquina_id', $maquinaId);
|
|
}
|
|
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)->whereIn('tipo_corte', ['bobina', 'guillotina'])->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 getTiempoEstimadoTotalTareasSeconds(): int
|
|
{
|
|
try {
|
|
$time_tareas_seconds = array_map(fn($q) => $q->tiempo_estimado ?? 0, $this->ot->tareas());
|
|
$seconds = array_sum($time_tareas_seconds);
|
|
return $seconds;
|
|
} catch (\Throwable $th) {
|
|
return 0;
|
|
}
|
|
}
|
|
public function getTiempoProcesamientoHHMMSS(): ?string
|
|
{
|
|
try {
|
|
$time_tareas_seconds = array_map(fn($q) => $q->tiempo_estimado ?? 0, $this->ot->tareas());
|
|
$seconds = array_sum($time_tareas_seconds);
|
|
return float_seconds_to_hhmmss_string($seconds);
|
|
} catch (\Throwable $th) {
|
|
return '00:00:00';
|
|
}
|
|
}
|
|
public function getTiempoTareasImpresionHHMMSS(): string
|
|
{
|
|
try {
|
|
$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_hhmmss_string($tiempo_seconds);
|
|
} catch (\Throwable $th) {
|
|
return '00:00';
|
|
}
|
|
}
|
|
public function getTiempoTotalTareas(): string
|
|
{
|
|
try {
|
|
$tareas = $this->ot->tareas();
|
|
$tiempo_seconds = 0;
|
|
foreach ($tareas as $key => $tarea) {
|
|
if ($tarea->tiempo_real) {
|
|
$tiempo_seconds += $tarea->tiempo_real;
|
|
}
|
|
}
|
|
return float_seconds_to_hhmm_string($tiempo_seconds);
|
|
} catch (\Throwable $th) {
|
|
return '00:00';
|
|
}
|
|
}
|
|
public function getUVI(): ?TarifaAcabadoEntity
|
|
{
|
|
$uvi = null;
|
|
$acabados = $this->presupuesto->acabados();
|
|
foreach ($acabados as $key => $acabado) {
|
|
if ($acabado->tarifa()->uvi) {
|
|
$uvi = $acabado->tarifa();
|
|
}
|
|
}
|
|
return $uvi;
|
|
}
|
|
|
|
public function updateProgress(): bool
|
|
{
|
|
$progress = $this->getOtProgress();
|
|
if ($this->ot->estado != "F") {
|
|
$status = $this->otModel->update($this->ot->id, ["progreso" => round($progress, 2)]);
|
|
} else {
|
|
$status = $this->otModel->update($this->ot->id, ["progreso" => 100]);
|
|
}
|
|
return $status;
|
|
}
|
|
public function getOtProgress()
|
|
{
|
|
$datesWithTime = $this->getOrdenTrabajoTareaDatesWithTiempoEstimado();
|
|
$tiempo_estimado_total = $this->getTiempoEstimadoTotalTareasSeconds();
|
|
$progress = 0;
|
|
$otDates = $this->ot->dates();
|
|
foreach ($datesWithTime as $key => $dateWithTime) {
|
|
["date" => $date, "tiempo_estimado" => $tiempo_estimado] = $dateWithTime;
|
|
try {
|
|
if ($otDates->{$date}) {
|
|
$progress += $tiempo_estimado / $tiempo_estimado_total * 100;
|
|
}
|
|
} catch (\Throwable $th) {
|
|
//throw $th;
|
|
$progress += 0;
|
|
}
|
|
}
|
|
return $progress;
|
|
}
|
|
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();
|
|
foreach ($encuadernaciones as $key => $value) {
|
|
$code = $value->tarifa()->code;
|
|
if ($code) {
|
|
break;
|
|
}
|
|
}
|
|
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()
|
|
{
|
|
if ($this->presupuesto->presupuestoLineaImpresion()) {
|
|
|
|
$papel = $this->presupuesto->presupuestoLineaImpresion()->papel_generico();
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['default'];
|
|
$papel_code = $papel->code_ot;
|
|
if ($papel_code) {
|
|
if (str_contains($papel_code, "BCLOF")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['blanco'];
|
|
}
|
|
if (str_contains($papel_code, "AH")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['ahuesado'];
|
|
}
|
|
if (str_contains($papel_code, "MARF")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['marfil'];
|
|
}
|
|
if (str_contains($papel_code, "VOLAH")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['volumen_ahuesado'];
|
|
}
|
|
if (str_contains($papel_code, "EM")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['estucado_mate'];
|
|
}
|
|
if (str_contains($papel->nombre, "CARTULINA")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['cartulina'];
|
|
}
|
|
}
|
|
|
|
return $color;
|
|
} else {
|
|
return $this->ordenTrabajoConfig->OT_PAPEL_COLOR['blanco'];
|
|
}
|
|
}
|
|
public function getPapelImpresionCubiertaBackgroundColor()
|
|
{
|
|
if ($this->presupuesto->presupuestoLineaCubierta()) {
|
|
|
|
$papel = $this->presupuesto->presupuestoLineaCubierta()->papel_generico();
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['default'];
|
|
$papel_code = $papel->code_ot;
|
|
if ($papel_code) {
|
|
if (str_contains($papel_code, "BCLOF")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['blanco'];
|
|
}
|
|
if (str_contains($papel_code, "AH")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['ahuesado'];
|
|
}
|
|
if (str_contains($papel_code, "MARF")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['marfil'];
|
|
}
|
|
if (str_contains($papel_code, "VOLAH")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['volumen_ahuesado'];
|
|
}
|
|
if (str_contains($papel_code, "EM")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['estucado_mate'];
|
|
}
|
|
if (str_contains($papel->nombre, "CARTULINA")) {
|
|
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['cartulina'];
|
|
}
|
|
}
|
|
return $color;
|
|
} else {
|
|
return $this->ordenTrabajoConfig->OT_PAPEL_COLOR['blanco'];
|
|
}
|
|
}
|
|
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) {
|
|
if ($tarifa_acabado->plastificado) {
|
|
if (isset($this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR[$tarifa_acabado->plastificado_tipo])) {
|
|
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR[$tarifa_acabado->plastificado_tipo];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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, //TODO
|
|
"isPlastificado" => $this->plastificado(),
|
|
"isPlakene" => $this->plakene(),
|
|
"isEstampado" => $this->estampado(),
|
|
"isRetractilado" => $this->retractilado(),
|
|
"isUVI" => $this->uvi(),
|
|
"isCubierta" => $this->cubierta(),
|
|
"isSobrecubierta" => $this->sobreCubierta(),
|
|
"isGuarda" => $this->guarda(),
|
|
"isColor" => $this->isColor,
|
|
"isBN" => $this->isBN,
|
|
"isCorte" => $this->corte(),
|
|
"isGrapado" => $this->isGrapado,
|
|
"isCosido" => $this->cosido(),
|
|
];
|
|
}
|
|
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 plakene(): bool
|
|
{
|
|
$flag = false;
|
|
$acabados = $this->presupuesto->acabados();
|
|
foreach ($acabados as $key => $acabado) {
|
|
$tarifa_acabado = $acabado->tarifa();
|
|
if ($tarifa_acabado->plakene) {
|
|
$flag = true;
|
|
break;
|
|
}
|
|
}
|
|
$this->isPlakene = $flag;
|
|
return $this->isPlakene;
|
|
}
|
|
public function retractilado(): bool
|
|
{
|
|
$flag = false;
|
|
$acabados = $this->presupuesto->acabados();
|
|
foreach ($acabados as $key => $acabado) {
|
|
$tarifa_acabado = $acabado->tarifa();
|
|
if ($tarifa_acabado->rectractilado) {
|
|
$flag = true;
|
|
break;
|
|
}
|
|
}
|
|
$this->isRetractilado = $flag;
|
|
return $this->isRetractilado;
|
|
}
|
|
public function plakene_tipo(): ?string
|
|
{
|
|
$tipo = "";
|
|
$acabados = $this->presupuesto->acabados();
|
|
foreach ($acabados as $key => $acabado) {
|
|
$tarifa_acabado = $acabado->tarifa();
|
|
if ($tarifa_acabado->plakene) {
|
|
$tipo = $tarifa_acabado->plakene_tipo;
|
|
break;
|
|
}
|
|
}
|
|
return $tipo;
|
|
}
|
|
public function plastificado(): bool
|
|
{
|
|
$flag = false;
|
|
$acabados = $this->presupuesto->acabados();
|
|
foreach ($acabados as $key => $acabado) {
|
|
$tarifa_acabado = $acabado->tarifa();
|
|
if ($tarifa_acabado->plastificado) {
|
|
$flag = true;
|
|
break;
|
|
}
|
|
}
|
|
$this->isPlastificado = $flag;
|
|
return $this->isPlastificado;
|
|
}
|
|
public function estampado(): bool
|
|
{
|
|
$flag = false;
|
|
$acabados = $this->presupuesto->acabados();
|
|
foreach ($acabados as $key => $acabado) {
|
|
$tarifa_acabado = $acabado->tarifa();
|
|
if ($tarifa_acabado->estampado) {
|
|
$flag = true;
|
|
break;
|
|
}
|
|
}
|
|
$this->isEstampado = $flag;
|
|
return $this->isEstampado;
|
|
}
|
|
public function cosido(): bool
|
|
{
|
|
$flag = false;
|
|
$encuadernaciones = $this->presupuesto->encuadernaciones();
|
|
foreach ($encuadernaciones as $key => $encuadernacion) {
|
|
$tarifaEncuadernacionEntity = $encuadernacion->tarifa();
|
|
if ($tarifaEncuadernacionEntity->isCosido()) {
|
|
$flag = true;
|
|
break;
|
|
}
|
|
}
|
|
$this->isCosido = $flag;
|
|
return $this->isCosido;
|
|
}
|
|
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 sobreCubierta(): bool
|
|
{
|
|
$flag = false;
|
|
$lineaCubierta = $this->presupuesto->presupuestoLineaSobreCubierta();
|
|
if ($lineaCubierta) {
|
|
$flag = true;
|
|
}
|
|
return $flag;
|
|
}
|
|
public function guarda(): bool
|
|
{
|
|
$flag = false;
|
|
$lineaCubierta = $this->presupuesto->presupuestoLineaGuarda();
|
|
if ($lineaCubierta) {
|
|
$flag = true;
|
|
}
|
|
return $flag;
|
|
}
|
|
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",
|
|
"orden_trabajo_tareas.maquina_id",
|
|
"tarea_progress.estado as tareaEstado",
|
|
"tarea_progress.estado",
|
|
|
|
])
|
|
->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("pedidos", "pedidos.id = ordenes_trabajo.pedido_id", "right")
|
|
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
|
->where('orden_trabajo_tareas.maquina_id', $maquina_id)
|
|
// ->where('pedidos.fecha_impresion IS NOT NULL', null, false) //! Dejar comentado por ahora
|
|
->where('ordenes_trabajo.preimpresion_revisada', true)
|
|
->where("orden_trabajo_tareas.deleted_at", null)
|
|
->orderBy("pedidos.fecha_impresion", "ASC")
|
|
->groupBy('orden_trabajo_tareas.id');
|
|
|
|
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>";
|
|
}
|
|
public function getTareaCosido(): ?OrdenTrabajoTareaEntity
|
|
{
|
|
$tareaCosido = null;
|
|
$tareas = $this->ot->tareas();
|
|
foreach ($tareas as $key => $tarea) {
|
|
if ($tarea->isCosido()) {
|
|
$tareaCosido = $tarea;
|
|
break;
|
|
}
|
|
}
|
|
return $tareaCosido;
|
|
}
|
|
public function createDatesForPOD(): array
|
|
{
|
|
$podDates = [
|
|
'fecha_encuadernado' => null,
|
|
'fecha_entrega_real' => null,
|
|
'fecha_embalaje' => null,
|
|
'fecha_impresion' => null,
|
|
];
|
|
try {
|
|
$impresionDays = $this->configVariableModel->getVariable('pod_impresion_dias_tras_confirmacion')->value;
|
|
$encuadernadoDays = $this->configVariableModel->getVariable('pod_encuadernacion_dias_tras_confirmacion')->value;
|
|
$entregaRealDays = $this->configVariableModel->getVariable('pod_entrega_real_dias_tras_confirmacion')->value;
|
|
$embalajeDays = $this->configVariableModel->getVariable('pod_embalaje_dias_tras_confirmacion')->value;
|
|
$totalDays = array_sum([$impresionDays, $encuadernadoDays, $entregaRealDays, $embalajeDays]);
|
|
$dates = $this->generateWorkdaysFromToday($totalDays);
|
|
for ($i = 0; $i < count($dates); $i++) {
|
|
if ($i == $impresionDays) {
|
|
$podDates['fecha_impresion'] = $dates[$i];
|
|
}
|
|
if ($i == $encuadernadoDays) {
|
|
$podDates['fecha_encuadernado'] = $dates[$i];
|
|
}
|
|
if ($i == $entregaRealDays) {
|
|
$podDates['fecha_entrega_real'] = $dates[$i];
|
|
}
|
|
if ($i == $embalajeDays) {
|
|
$podDates['fecha_embalaje'] = $dates[$i];
|
|
}
|
|
}
|
|
return $podDates;
|
|
} catch (\Throwable $th) {
|
|
return ["error" => $th->getMessage()];
|
|
}
|
|
}
|
|
/**
|
|
* Devuelve un array con la longitud `$count` con las fechas que corresponde con días laborales.
|
|
* Menos fines de semana y festivos.
|
|
*
|
|
* @param integer $count
|
|
* @return array <str,YYYY-MM-DD>
|
|
*/
|
|
public function generateWorkdaysFromToday(int $count): array
|
|
{
|
|
$current = Time::now();
|
|
$workdays = [];
|
|
|
|
while (count($workdays) < $count) {
|
|
$dayOfWeek = $current->format('N'); // 1 (Lunes) to 7 (Domingo)
|
|
|
|
if ($dayOfWeek < 6) { // Lunes a Viernes
|
|
$date = $current->format('Y-m-d 00:00:00');
|
|
if ($this->festivoModel->isFestivo($date) == false) {
|
|
$workdays[] = $date;
|
|
}
|
|
}
|
|
|
|
$current = $current->addDays(1);
|
|
}
|
|
|
|
return $workdays;
|
|
}
|
|
public function updatePodDates(): bool
|
|
{
|
|
$dates = $this->createDatesForPOD();
|
|
return $this->pedidoModel->update($this->pedido->id, $dates);
|
|
}
|
|
public function getProveedorTarea($tarea_id)
|
|
{
|
|
$proveedor = null;
|
|
$tareaEntity = $this->otTarea->find($tarea_id);
|
|
if ($tareaEntity) {
|
|
$proveedorEncuadernado = $tareaEntity->presupuesto_encuadernacion();
|
|
$proveedorAcabado = $tareaEntity->presupuesto_acabado();
|
|
if ($proveedorEncuadernado) {
|
|
$proveedor = $proveedorEncuadernado->proveedor();
|
|
} elseif ($proveedorAcabado) {
|
|
$proveedor = $proveedorAcabado->proveedor();
|
|
} else {
|
|
$proveedor = null;
|
|
}
|
|
}
|
|
return ["tarea" => $tareaEntity, "proveedor" => $proveedor];
|
|
}
|
|
public function updateProveedorLinea($tarea_id, $proveedor_id)
|
|
{
|
|
$status = false;
|
|
$tareaEntity = $this->otTarea->find($tarea_id);
|
|
$presupuestoEncuadernado = $tareaEntity->presupuesto_encuadernacion();
|
|
$presupuestoAcabado = $tareaEntity->presupuesto_acabado();
|
|
if ($presupuestoEncuadernado) {
|
|
$status = $this->presupuestoEncuadernacionModel->update($presupuestoEncuadernado->id, ['proveedor_id' => $proveedor_id]);
|
|
} elseif ($presupuestoAcabado) {
|
|
$status = $this->presupuestoAcabadoModel->update($presupuestoAcabado->id, ['proveedor_id' => $proveedor_id]);
|
|
} else {
|
|
$status = null;
|
|
}
|
|
return $status;
|
|
}
|
|
public function otTareaImpresionWithDates()
|
|
{
|
|
$tareasImpresion = $this->ot->tareas_impresion();
|
|
$data = [];
|
|
foreach ($tareasImpresion as $key => $tareaImpresion) {
|
|
if ($tareaImpresion->is_corte) {
|
|
$data[$tareaImpresion->id] = 'corte_at';
|
|
continue;
|
|
}
|
|
$presupuestoLineaEntity = $tareaImpresion->presupuesto_linea();
|
|
if ($presupuestoLineaEntity) {
|
|
if ($presupuestoLineaEntity->isGuarda()) {
|
|
$data[$tareaImpresion->id] = 'guarda_at';
|
|
} elseif ($presupuestoLineaEntity->isCubierta()) {
|
|
$data[$tareaImpresion->id] = 'cubierta_at';
|
|
} elseif ($presupuestoLineaEntity->isColor()) {
|
|
$data[$tareaImpresion->id] = 'interior_color_at';
|
|
} elseif ($presupuestoLineaEntity->isBN()) {
|
|
$data[$tareaImpresion->id] = 'interior_bn_at';
|
|
} elseif ($presupuestoLineaEntity->isSobreCubierta()) {
|
|
$data[$tareaImpresion->id] = 'sobrecubierta_at';
|
|
}
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
public function tareaImpresionDate($tarea): string
|
|
{
|
|
|
|
$dateName = "";
|
|
$presupuestoLineaEntity = $tarea->presupuesto_linea();
|
|
if ($presupuestoLineaEntity) {
|
|
if ($presupuestoLineaEntity->isGuarda()) {
|
|
$dateName = 'guarda_at';
|
|
} elseif ($presupuestoLineaEntity->isCubierta()) {
|
|
$dateName = 'cubierta_at';
|
|
} elseif ($presupuestoLineaEntity->isColor()) {
|
|
$dateName = 'interior_color_at';
|
|
} elseif ($presupuestoLineaEntity->isBN()) {
|
|
$dateName = 'interior_bn_at';
|
|
} elseif ($presupuestoLineaEntity->isSobreCubierta()) {
|
|
$dateName = 'sobrecubierta_at';
|
|
}
|
|
if ($tarea->is_corte) {
|
|
$dateName = 'corte_at';
|
|
}
|
|
}
|
|
return $dateName;
|
|
}
|
|
public function otTareaAcabadoWithDates()
|
|
{
|
|
$tareasAcabado = $this->ot->tareas_acabado();
|
|
$data = [];
|
|
foreach ($tareasAcabado as $key => $tareasAcabado) {
|
|
$tarifaAcabado = $tareasAcabado->presupuesto_acabado()?->tarifa();
|
|
if ($tarifaAcabado) {
|
|
if ($tarifaAcabado->plastificado) {
|
|
$data[$tareasAcabado->id] = 'plastificado_at';
|
|
}
|
|
if ($tarifaAcabado->rectractilado) {
|
|
$data[$tareasAcabado->id] = 'retractilado_at';
|
|
}
|
|
if ($tarifaAcabado->estampado) {
|
|
$data[$tareasAcabado->id] = 'estampado_at';
|
|
}
|
|
if ($tarifaAcabado->uvi) {
|
|
$data[$tareasAcabado->id] = 'uvi_at';
|
|
}
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
public function tareaAcabadoDate($tarea): string
|
|
{
|
|
|
|
$dateName = "";
|
|
$tarifaAcabado = $tarea->presupuesto_acabado()?->tarifa();;
|
|
if ($tarifaAcabado) {
|
|
if ($tarifaAcabado->plastificado) {
|
|
$dateName = 'plastificado_at';
|
|
}
|
|
if ($tarifaAcabado->rectractilado) {
|
|
$dateName = 'retractilado_at';
|
|
}
|
|
if ($tarifaAcabado->plakene) {
|
|
$dateName = 'plakene_at';
|
|
}
|
|
if ($tarifaAcabado->estampado) {
|
|
$dateName = 'estampado_at';
|
|
}
|
|
if ($tarifaAcabado->uvi) {
|
|
$dateName = 'uvi_at';
|
|
}
|
|
}
|
|
return $dateName;
|
|
}
|
|
public function otTareaEncuadernadoWithDates()
|
|
{
|
|
$tareas = $this->ot->tareas_encuadernado();
|
|
$data = [];
|
|
foreach ($tareas as $key => $tarea) {
|
|
$data[$tarea->id] = "encuadernacion_at";
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function otTareaManipuladooWithDates()
|
|
{
|
|
$tareas = $this->ot->tareas_manipulado();
|
|
$data = [];
|
|
foreach ($tareas as $key => $tarea) {
|
|
$data[$tarea->id] = "entrada_manipulado_at";
|
|
}
|
|
return $data;
|
|
}
|
|
public function getOrdenTrabajoTareaDatesWithTiempoEstimado(): array
|
|
{
|
|
$dates = [];
|
|
foreach ($this->ot->tareas() as $key => $tarea) {
|
|
$dates[$tarea->id]["date"] = $this->getOrdenTrabajoTareaDate($tarea);
|
|
$dates[$tarea->id]["tiempo_estimado"] = $tarea->tiempo_estimado;
|
|
}
|
|
return $dates;
|
|
}
|
|
public function getOrdenTrabajoTareaDates(): array
|
|
{
|
|
$dates = [];
|
|
foreach ($this->ot->tareas() as $key => $tarea) {
|
|
$dates[] = $this->getOrdenTrabajoTareaDate($tarea);
|
|
}
|
|
return array_unique($dates);
|
|
}
|
|
public function getOrdenTrabajoTareaDate(OrdenTrabajoTareaEntity $tarea): ?string
|
|
{
|
|
$dateName = null;
|
|
if ($tarea->isImpresion()) {
|
|
$dateName = $this->tareaImpresionDate($tarea);
|
|
}
|
|
if ($tarea->isAcabado()) {
|
|
$dateName = $this->tareaAcabadoDate($tarea);
|
|
}
|
|
if ($tarea->isManipulado()) {
|
|
$dateName = "entrada_manipulado_at";
|
|
}
|
|
if ($tarea->isEncuadernado()) {
|
|
$dateName = "encuadernacion_at";
|
|
}
|
|
return $dateName;
|
|
}
|
|
public function getTitleTareaEstado($tarea_id): array
|
|
{
|
|
$estadoTitle = $this->OT_TAREA_STATUS_TITLE["P"];
|
|
$estadoColor = $this->ordenTrabajoConfig->OT_TAREA_STATUS_COLOR['P'];
|
|
$userName = null;
|
|
$progressDateEntity = $this->otTarea->find($tarea_id)->lastState();
|
|
if ($progressDateEntity) {
|
|
if (isset($this->OT_TAREA_STATUS_TITLE[$progressDateEntity->estado])) {
|
|
$estadoTitle = $this->OT_TAREA_STATUS_TITLE[$progressDateEntity->estado];
|
|
$estadoColor = $this->ordenTrabajoConfig->OT_TAREA_STATUS_COLOR[$progressDateEntity->estado];
|
|
$userName = $progressDateEntity->user()->fullName();
|
|
}
|
|
}
|
|
return [
|
|
"title" => $estadoTitle,
|
|
"color" => $estadoColor,
|
|
"userName" => $userName ?? "",
|
|
];
|
|
}
|
|
}
|