This commit is contained in:
lizandrogd
2026-01-19 18:24:35 -05:00
parent edcd51e651
commit 084b644714
10 changed files with 412 additions and 66 deletions
+13 -25
View File
@@ -64,35 +64,23 @@ class Confeccion extends Model
}
});
// Crear traslado cuando la confección tenga recepción (en creación y en actualización)
$createTrasladoFn = function ($confeccion) {
if ($confeccion->cantidad_recibida !== null) {
// Evitar duplicados
$exists = \App\Models\TrasladoPrenda::where('referencia_type', self::class)
->where('referencia_id', $confeccion->id)
->exists();
/* Recepciones polimórficas */
public function recepciones()
{
return $this->morphMany(\App\Models\Recepcion::class, 'referencia');
}
if (! $exists) {
$destino = 'tintoreria';
// Cuantas faltan por recibir
public function getFaltantesAttribute()
{
return max(0, (int)($this->cantidad_enviada ?? 0) - (int)($this->cantidad_recibida ?? 0));
}
\App\Models\TrasladoPrenda::crearDesdeReferencia(
$confeccion,
'confeccion',
$destino
);
// Marcar el paso como terminado y avanzar la OP incluso si fue parcial
$confeccion->ordenProduccion?->avanzarEstado();
}
}
// Mantener el comportamiento anterior: si está completo, también avanzamos (por seguridad)
// Mantener avance de OP cuando la confección se completa
static::saved(function ($confeccion) {
if ($confeccion->estado === 'completo') {
$confeccion->ordenProduccion?->avanzarEstado();
}
};
static::updated($createTrasladoFn);
static::saved($createTrasladoFn);
});
}
}