This commit is contained in:
Lizandro Guarnizo
2026-01-18 11:21:19 -05:00
parent 18c43fe06f
commit 33688d297c
21 changed files with 958 additions and 14 deletions
+31 -3
View File
@@ -39,14 +39,42 @@ class Tintoreria extends Model
}
});
// Cuando vuelve de tintorería → avanzar OP
static::updated(function ($tintoreria) {
$createTrasladoFn = function ($tintoreria) {
if ($tintoreria->cantidad_recibida !== null) {
// Evitar duplicados
$exists = \App\Models\TrasladoPrenda::where('referencia_type', self::class)
->where('referencia_id', $tintoreria->id)
->exists();
if (! $exists) {
// Mapear "perdidas" a prendas_defectuosas en el traslado
$payload = [
'prendas_defectuosas' => $tintoreria->perdidas ?? 0,
];
$destino = 'acabados';
\App\Models\TrasladoPrenda::crearDesdeReferencia(
$tintoreria,
'tintoreria',
$destino,
$payload
);
// Avanzar la OP al cerrar el paso
$tintoreria->ordenProduccion?->avanzarEstado();
}
}
if (
$tintoreria->fecha_recepcion &&
$tintoreria->cantidad_recibida !== null
) {
$tintoreria->ordenProduccion?->avanzarEstado();
}
});
};
static::updated($createTrasladoFn);
static::saved($createTrasladoFn);
}
}