up
This commit is contained in:
+13
-25
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user