revision ot v2

This commit is contained in:
amazuecos
2025-05-04 17:25:53 +02:00
parent db70c57fb3
commit fb7f2a28d9
30 changed files with 897 additions and 169 deletions

View File

@ -52,6 +52,7 @@ class ProductionService extends BaseService
*/
public array $TIPOS_ROTATIVA = ['lp_rot_bn', 'lp_rot_color'];
public array $OT_TAREA_STATUS_TITLE;
protected OrdenTrabajoModel $otModel;
protected OrdenTrabajoTarea $otTarea;
@ -211,6 +212,14 @@ class ProductionService extends BaseService
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["sin_imprimir"];
$this->configVariableModel = model(ConfigVariableModel::class);
$this->podValue = $this->configVariableModel->getVariable('POD')->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
@ -218,7 +227,11 @@ class ProductionService extends BaseService
try {
$this->maquinaModel = model(MaquinaModel::class);
$this->otModel = model(OrdenTrabajoModel::class);
$this->ot = $this->otModel->find($orden_trabajo_id);
$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();
@ -597,6 +610,12 @@ class ProductionService extends BaseService
}
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()
{
@ -994,9 +1013,9 @@ class ProductionService extends BaseService
$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 == $data['estado']) {
// throw new Exception(lang('Produccion.duplicate_estado_tarea_progress'));
// }
if ($lastDate->estado == 'F') {
throw new Exception(lang('Produccion.task_already_finished'));
}
@ -1907,7 +1926,9 @@ class ProductionService extends BaseService
"pedidos.fecha_impresion",
"orden_trabajo_tareas.nombre as tareaName",
"orden_trabajo_tareas.maquina_id",
"tarea_progress.estado as tareaEstado"
"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
@ -1929,7 +1950,6 @@ class ProductionService extends BaseService
// ->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)
->where("tarea_progress.estado", 'P')
->orderBy("pedidos.fecha_impresion", "ASC")
->groupBy('orden_trabajo_tareas.id');
@ -2110,7 +2130,7 @@ class ProductionService extends BaseService
$data[$tareasAcabado->id] = 'plastificado_at';
}
if ($tarifaAcabado->rectractilado) {
$data[$tareasAcabado->id] = 'rectractilado_at';
$data[$tareasAcabado->id] = 'retractilado_at';
}
if ($tarifaAcabado->estampado) {
$data[$tareasAcabado->id] = 'estampado_at';
@ -2132,7 +2152,7 @@ class ProductionService extends BaseService
$dateName = 'plastificado_at';
}
if ($tarifaAcabado->rectractilado) {
$dateName = 'rectractilado_at';
$dateName = 'retractilado_at';
}
if ($tarifaAcabado->plakene) {
$dateName = 'plakene_at';
@ -2190,4 +2210,23 @@ class ProductionService extends BaseService
}
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 ?? "",
];
}
}