up
This commit is contained in:
@@ -52,14 +52,29 @@ class ConfeccionResource extends Resource
|
||||
->relationship('ordenProduccion', 'numero_orden')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
->reactive()
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, $set) {
|
||||
if ($state) {
|
||||
$orden = \App\Models\OrdenProduccion::find($state);
|
||||
if ($orden) {
|
||||
$set('cantidad_enviada', $orden->cantidad_total);
|
||||
$set('fecha_envio', now()->toDateString());
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
DatePicker::make('fecha_envio')
|
||||
->required(),
|
||||
->required()
|
||||
->default(now()),
|
||||
|
||||
TextInput::make('cantidad_enviada')
|
||||
->numeric()
|
||||
->required(),
|
||||
->required()
|
||||
->minValue(1)
|
||||
->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')
|
||||
->reactive(),
|
||||
|
||||
DatePicker::make('fecha_recepcion'),
|
||||
|
||||
|
||||
@@ -34,6 +34,21 @@ class Confeccion extends Model
|
||||
protected static function booted()
|
||||
{
|
||||
static::saving(function ($confeccion) {
|
||||
// Establecer fecha de envío por defecto si no se proporcionó
|
||||
if (! $confeccion->fecha_envio) {
|
||||
$confeccion->fecha_envio = now();
|
||||
}
|
||||
|
||||
// Validación: cantidad_enviada no puede exceder la cantidad total de la OP
|
||||
if ($confeccion->cantidad_enviada !== null && $confeccion->orden_produccion_id) {
|
||||
$orden = \App\Models\OrdenProduccion::find($confeccion->orden_produccion_id);
|
||||
if ($orden && $confeccion->cantidad_enviada > $orden->cantidad_total) {
|
||||
throw \Illuminate\Validation\ValidationException::withMessages([
|
||||
'cantidad_enviada' => 'La cantidad enviada no puede exceder la cantidad total de la Orden de Producción (' . $orden->cantidad_total . ').',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Total a pagar
|
||||
if ($confeccion->cantidad_recibida !== null) {
|
||||
$confeccion->total_pagar =
|
||||
@@ -41,7 +56,7 @@ class Confeccion extends Model
|
||||
}
|
||||
|
||||
// Estado automático
|
||||
if (!$confeccion->cantidad_recibida) {
|
||||
if (! $confeccion->cantidad_recibida) {
|
||||
$confeccion->estado = 'pendiente';
|
||||
} elseif ($confeccion->cantidad_recibida < $confeccion->cantidad_enviada) {
|
||||
$confeccion->estado = 'parcial';
|
||||
|
||||
Reference in New Issue
Block a user