update progress based on task time and task date

This commit is contained in:
amazuecos
2025-05-06 08:30:01 +02:00
parent aac8ab24be
commit 30c5b06d3d

View File

@ -228,8 +228,8 @@ class ProductionService extends BaseService
$this->maquinaModel = model(MaquinaModel::class); $this->maquinaModel = model(MaquinaModel::class);
$this->otModel = model(OrdenTrabajoModel::class); $this->otModel = model(OrdenTrabajoModel::class);
$ot = $this->otModel->find($orden_trabajo_id); $ot = $this->otModel->find($orden_trabajo_id);
if($ot == null){ if ($ot == null) {
throw new Exception(lang('Produccion.errors.ot_not_found',['ot_id' => $orden_trabajo_id])); throw new Exception(lang('Produccion.errors.ot_not_found', ['ot_id' => $orden_trabajo_id]));
} }
$this->ot = $ot; $this->ot = $ot;
$pedido = $this->ot->pedido(); $pedido = $this->ot->pedido();
@ -610,11 +610,11 @@ class ProductionService extends BaseService
} }
return ["tareas" => $tareas]; return ["tareas" => $tareas];
} }
public function getTareasWithMaquina(int $maquina_id,?array $tareaEstados = null) : ?array public function getTareasWithMaquina(int $maquina_id, ?array $tareaEstados = null): ?array
{ {
return $this->otModel->queryMaquinaTareas($maquina_id, $tareaEstados) return $this->otModel->queryMaquinaTareas($maquina_id, $tareaEstados)
->where('ordenes_trabajo.id', $this->ot->id) ->where('ordenes_trabajo.id', $this->ot->id)
->get()->getResult(OrdenTrabajoTareaEntity::class); ->get()->getResult(OrdenTrabajoTareaEntity::class);
} }
public function getPdf() public function getPdf()
@ -1439,6 +1439,16 @@ class ProductionService extends BaseService
} }
return $pedidoUserDates; 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 public function getTiempoProcesamientoHHMMSS(): ?string
{ {
try { try {
@ -1490,33 +1500,31 @@ class ProductionService extends BaseService
} }
return $uvi; return $uvi;
} }
//TODO ACTUALIZAR
public function updateProgress(): bool public function updateProgress(): bool
{ {
$userDates = $this->ordenTrabajoConfig->DATE_USER_MAPPING; $progress = $this->getOtProgress();
$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->estado != "F") {
if ($this->ot->dates()) { $status = $this->otModel->update($this->ot->id, ["progreso" => round($progress, 2)]);
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 { } else {
$status = $this->otModel->update($this->ot->id, ["progreso" => 100]); $status = $this->otModel->update($this->ot->id, ["progreso" => 100]);
} }
return $status; 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;
if ($otDates->{$date}) {
$progress += $tiempo_estimado / $tiempo_estimado_total * 100;
}
}
return $progress;
}
public function getOtColorStatus(): string public function getOtColorStatus(): string
{ {
if ($this->ot->dates()) { if ($this->ot->dates()) {
@ -2194,6 +2202,15 @@ class ProductionService extends BaseService
} }
return $data; 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 public function getOrdenTrabajoTareaDates(): array
{ {
$dates = []; $dates = [];