o
This commit is contained in:
@@ -41,7 +41,33 @@ class InventarioPrendaResource extends Resource
|
||||
->relationship('ordenProduccion', 'numero_orden')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
->reactive()
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, $set) {
|
||||
$remaining = 0;
|
||||
|
||||
if ($state) {
|
||||
// Total recibido hacia bodega desde acabados/traslados
|
||||
$total = \App\Models\TrasladoPrenda::where('orden_produccion_id', $state)
|
||||
->where('destino', 'bodega')
|
||||
->sum('cantidad_recibida');
|
||||
|
||||
// Ya asignado en otros inventarios
|
||||
$used = \App\Models\InventarioPrenda::where('orden_produccion_id', $state)->sum('cantidad_terminada');
|
||||
|
||||
$remaining = max(0, (int) $total - (int) $used);
|
||||
|
||||
// Colocar valores en formulario
|
||||
$set('cantidad_terminada', $remaining);
|
||||
$set('cantidad_disponible', $remaining);
|
||||
|
||||
// Si la OP tiene producto predeterminado, asignarlo como sugerencia
|
||||
$op = \App\Models\OrdenProduccion::find($state);
|
||||
if ($op && $op->producto_id) {
|
||||
$set('producto_id', $op->producto_id);
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
TextInput::make('cantidad_terminada')
|
||||
->numeric()
|
||||
|
||||
Reference in New Issue
Block a user