This commit is contained in:
Lizandro Guarnizo
2026-01-18 12:22:45 -05:00
parent 29c6567d27
commit 8b51227c32
2 changed files with 27 additions and 9 deletions
+23 -4
View File
@@ -74,12 +74,23 @@ class ConfeccionResource extends Resource
->minValue(1) ->minValue(1)
->maxValue(fn ($get) => $get('orden_produccion_id') ? \App\Models\OrdenProduccion::find($get('orden_produccion_id'))->cantidad_total : null) ->maxValue(fn ($get) => $get('orden_produccion_id') ? \App\Models\OrdenProduccion::find($get('orden_produccion_id'))->cantidad_total : null)
->helperText(fn ($get) => $get('orden_produccion_id') ? 'Máximo: ' . \App\Models\OrdenProduccion::find($get('orden_produccion_id'))->cantidad_total : 'Selecciona una Orden de Producción') ->helperText(fn ($get) => $get('orden_produccion_id') ? 'Máximo: ' . \App\Models\OrdenProduccion::find($get('orden_produccion_id'))->cantidad_total : 'Selecciona una Orden de Producción')
->reactive(), ->reactive()
->afterStateUpdated(function ($state, $set, $get) {
$valor = $get('valor_por_prenda') ?? 0;
$cantidad = $get('cantidad_recibida') ?? $state;
$set('total_pagar', $cantidad && $valor ? $cantidad * $valor : 0);
}),
DatePicker::make('fecha_recepcion'), DatePicker::make('fecha_recepcion'),
TextInput::make('cantidad_recibida') TextInput::make('cantidad_recibida')
->numeric(), ->numeric()
->reactive()
->afterStateUpdated(function ($state, $set, $get) {
$valor = $get('valor_por_prenda') ?? 0;
$cantidad = $state ?? $get('cantidad_enviada');
$set('total_pagar', $cantidad && $valor ? $cantidad * $valor : 0);
}),
TextInput::make('prendas_defectuosas') TextInput::make('prendas_defectuosas')
->numeric() ->numeric()
@@ -88,10 +99,18 @@ class ConfeccionResource extends Resource
TextInput::make('valor_por_prenda') TextInput::make('valor_por_prenda')
->numeric() ->numeric()
->prefix('$') ->prefix('$')
->required(), ->required()
->reactive()
->afterStateUpdated(function ($state, $set, $get) {
$cantidad = $get('cantidad_recibida') ?? $get('cantidad_enviada');
$set('total_pagar', $cantidad && $state ? $cantidad * $state : 0);
}),
TextInput::make('total_pagar') TextInput::make('total_pagar')
->prefix('$'), ->prefix('$')
->numeric()
->readOnly()
->default(0),
]) ])
->columns(2), ->columns(2),
]); ]);
+4 -5
View File
@@ -49,11 +49,10 @@ class Confeccion extends Model
} }
} }
// Total a pagar // Total a pagar: usa cantidad_recibida si existe, sino cantidad_enviada
if ($confeccion->cantidad_recibida !== null) { $cantidadBase = $confeccion->cantidad_recibida ?? $confeccion->cantidad_enviada ?? 0;
$confeccion->total_pagar = $valorUnitario = $confeccion->valor_por_prenda ?? 0;
$confeccion->cantidad_recibida * $confeccion->valor_por_prenda; $confeccion->total_pagar = $cantidadBase * $valorUnitario;
}
// Estado automático // Estado automático
if (! $confeccion->cantidad_recibida) { if (! $confeccion->cantidad_recibida) {