Update ProcesoAcabadoResource.php
This commit is contained in:
@@ -111,13 +111,47 @@ class ProcesoAcabadoResource extends Resource
|
||||
->label('Cantidad')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(1),
|
||||
->minValue(1)
|
||||
->live()
|
||||
->afterStateUpdated(function ($state, $set, $get) {
|
||||
// Validar que la suma no exceda el total disponible
|
||||
$total = (int) ($get('../../cantidad_enviada') ?? 0);
|
||||
$distribuciones = $get('../../distribucion_proveedores') ?? [];
|
||||
$suma = 0;
|
||||
foreach ($distribuciones as $dist) {
|
||||
$suma += (int) ($dist['cantidad'] ?? 0);
|
||||
}
|
||||
|
||||
if ($suma > $total) {
|
||||
throw \Illuminate\Validation\ValidationException::withMessages([
|
||||
'cantidad' => "La suma de las distribuciones ({$suma}) excede el total disponible ({$total})."
|
||||
]);
|
||||
}
|
||||
}),
|
||||
])
|
||||
->columns(2)
|
||||
->defaultItems(1)
|
||||
->addActionLabel('Agregar otro proveedor')
|
||||
->collapsible()
|
||||
->cloneable(),
|
||||
->cloneable()
|
||||
->live()
|
||||
->helperText(function ($get) {
|
||||
$total = (int) ($get('cantidad_enviada') ?? 0);
|
||||
$distribuciones = $get('distribucion_proveedores') ?? [];
|
||||
$suma = 0;
|
||||
foreach ($distribuciones as $dist) {
|
||||
$suma += (int) ($dist['cantidad'] ?? 0);
|
||||
}
|
||||
$restante = $total - $suma;
|
||||
|
||||
if ($restante < 0) {
|
||||
return "⚠️ Excede el total por " . abs($restante) . " unidades";
|
||||
} elseif ($restante > 0) {
|
||||
return "Faltan {$restante} unidades por distribuir";
|
||||
} else {
|
||||
return "✓ Total distribuido correctamente";
|
||||
}
|
||||
}),
|
||||
])
|
||||
->collapsed(fn ($get) => !$get('distribucion_proveedores')),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user