up
This commit is contained in:
@@ -14,9 +14,10 @@ use Filament\Forms\Components\DatePicker;
|
||||
class PrensillaResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Prensilla::class;
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationGroup = 'Producción';
|
||||
protected static bool $shouldRegisterNavigation = false; // Ocultar del menú
|
||||
protected static ?string $navigationIcon = 'heroicon-o-scissors';
|
||||
protected static ?string $navigationGroup = 'Gestión';
|
||||
protected static ?string $navigationLabel = 'Prensillas';
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
@@ -26,28 +27,112 @@ class PrensillaResource extends Resource
|
||||
public static function form(Forms\Form $form): Forms\Form
|
||||
{
|
||||
return $form->schema([
|
||||
Select::make('proveedor_id')->relationship('proveedor', 'nombre', fn(\Illuminate\Database\Eloquent\Builder $q) => $q->where('categoria', 'empleado'))->searchable()->preload()->nullable(),
|
||||
Select::make('orden_produccion_id')->relationship('ordenProduccion', 'numero_orden')->searchable()->preload()->required(),
|
||||
DatePicker::make('fecha_envio')->default(now()),
|
||||
TextInput::make('cantidad_enviada')->numeric()->required()->minValue(1),
|
||||
DatePicker::make('fecha_recepcion'),
|
||||
TextInput::make('cantidad_recibida')->numeric()->nullable(),
|
||||
TextInput::make('perdidas')->numeric()->default(0),
|
||||
Select::make('orden_produccion_id')
|
||||
->label('Orden de Producción')
|
||||
->options(function () {
|
||||
return \App\Models\OrdenProduccion::whereHas('ojales', function ($q) {
|
||||
$q->where('terminada', true);
|
||||
})->get()->mapWithKeys(function ($op) {
|
||||
$ojalesTerminados = \App\Models\Ojal::where('orden_produccion_id', $op->id)
|
||||
->where('terminada', true)
|
||||
->sum('cantidad_enviada');
|
||||
$yaEnviado = \App\Models\Prensilla::where('orden_produccion_id', $op->id)
|
||||
->sum('cantidad_enviada');
|
||||
$disponible = $ojalesTerminados - $yaEnviado;
|
||||
if ($disponible > 0) {
|
||||
return [$op->id => "{$op->numero_orden} - {$op->referencia} (Disponible: {$disponible})"];
|
||||
}
|
||||
return [];
|
||||
})->filter();
|
||||
})
|
||||
->searchable()
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, $set) {
|
||||
if ($state) {
|
||||
$op = \App\Models\OrdenProduccion::find($state);
|
||||
if ($op) {
|
||||
$ojalesTerminados = \App\Models\Ojal::where('orden_produccion_id', $state)
|
||||
->where('terminada', true)
|
||||
->sum('cantidad_enviada');
|
||||
$yaEnviado = \App\Models\Prensilla::where('orden_produccion_id', $state)
|
||||
->sum('cantidad_enviada');
|
||||
$cantidadDisponible = $ojalesTerminados - $yaEnviado;
|
||||
$set('cantidad_enviada', max(0, $cantidadDisponible));
|
||||
$set('prenda_nombre_info', $op->prenda_modelo ?? 'Sin especificar');
|
||||
}
|
||||
}
|
||||
})->helperText('⚠️ Solo se muestran órdenes con Ojales terminados disponibles'),
|
||||
|
||||
TextInput::make('prenda_nombre_info')
|
||||
->label('Prenda')
|
||||
->disabled()
|
||||
->dehydrated(false)
|
||||
->visible(fn ($get) => $get('orden_produccion_id') !== null),
|
||||
|
||||
Select::make('proveedor_id')
|
||||
->label('Empleado Responsable')
|
||||
->options(fn() => \App\Models\Proveedor::where('categoria', 'empleado')->pluck('nombre', 'id'))
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->helperText('Selecciona el empleado responsable del proceso'),
|
||||
|
||||
TextInput::make('cantidad_enviada')
|
||||
->label('Cantidad')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(1),
|
||||
|
||||
Forms\Components\Checkbox::make('terminada')
|
||||
->label('Marcar como terminado')
|
||||
->helperText('✓ Al terminar Prensillas, las prendas quedarán disponibles para Tintorería')
|
||||
->reactive(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
return $table->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('#'),
|
||||
Tables\Columns\TextColumn::make('proveedor.nombre')->label('Proveedor'),
|
||||
Tables\Columns\TextColumn::make('ordenProduccion.numero_orden')->label('OP'),
|
||||
Tables\Columns\TextColumn::make('cantidad_enviada'),
|
||||
Tables\Columns\TextColumn::make('cantidad_recibida'),
|
||||
Tables\Columns\TextColumn::make('perdidas'),
|
||||
Tables\Columns\TextColumn::make('fecha_envio')->date(),
|
||||
Tables\Columns\TextColumn::make('fecha_recepcion')->date(),
|
||||
])->defaultSort('created_at', 'desc');
|
||||
Tables\Columns\TextColumn::make('ordenProduccion.numero_orden')
|
||||
->label('OP')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('ordenProduccion.referencia')
|
||||
->label('Referencia')
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('ordenProduccion.prenda_modelo')
|
||||
->label('Prenda')
|
||||
->searchable()
|
||||
->limit(30)
|
||||
->toggleable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('proveedor.nombre')
|
||||
->label('Empleado')
|
||||
->searchable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('cantidad_enviada')
|
||||
->label('Cantidad'),
|
||||
|
||||
Tables\Columns\IconColumn::make('terminada')
|
||||
->label('Terminado')
|
||||
->boolean(),
|
||||
|
||||
Tables\Columns\TextColumn::make('fecha_envio')
|
||||
->date()
|
||||
->sortable(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('terminada')
|
||||
->options([
|
||||
'1' => 'Terminados',
|
||||
'0' => 'En proceso',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
|
||||
Reference in New Issue
Block a user