193 lines
7.0 KiB
PHP
193 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\OrdenProduccionResource\Pages;
|
|
use App\Filament\Resources\OrdenProduccionResource\RelationManagers;
|
|
use App\Models\OrdenProduccion;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Filament\Forms\Components\{
|
|
TextInput,
|
|
Select,
|
|
DatePicker,
|
|
Section,
|
|
View
|
|
};
|
|
use Filament\Tables\Columns\{
|
|
TextColumn,
|
|
BadgeColumn
|
|
};
|
|
|
|
class OrdenProduccionResource extends Resource
|
|
{
|
|
protected static ?string $model = OrdenProduccion::class;
|
|
|
|
protected static ?string $navigationGroup = 'Gestión';
|
|
protected static ?int $navigationSort = 2;
|
|
protected static ?string $navigationIcon = 'heroicon-o-clipboard-document-list';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Section::make('Datos de la Orden')
|
|
->schema([
|
|
Select::make('producto_id')
|
|
->label('Producto (opcional)')
|
|
->relationship('producto', 'nombre')
|
|
->searchable()
|
|
->preload()
|
|
->nullable()
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, $set) {
|
|
if ($state) {
|
|
$prod = \App\Models\Producto::find($state);
|
|
if ($prod) {
|
|
$set('prenda_modelo', $prod->nombre);
|
|
}
|
|
}
|
|
})
|
|
->helperText('Si seleccionas un producto, se completará automáticamente el campo Prenda / Modelo.'),
|
|
|
|
TextInput::make('prenda_modelo')
|
|
->label('Prenda / Modelo')
|
|
->required()
|
|
->maxLength(255),
|
|
|
|
TextInput::make('cantidad_total')
|
|
->numeric()
|
|
->required()
|
|
->minValue(1),
|
|
|
|
Select::make('tela_id')
|
|
->label('Tela asociada')
|
|
->options(fn () => \App\Models\Tela::where('metros_disponibles', '>', 0)->pluck('codigo', 'id')->toArray())
|
|
->searchable()
|
|
->preload()
|
|
->reactive()
|
|
->afterStateUpdated(function ($state, $set, $get) {
|
|
if ($state) {
|
|
$tela = \App\Models\Tela::find($state);
|
|
$available = $tela ? (float) $tela->metros_disponibles : 0;
|
|
|
|
if (! $get('metros_requeridos') || $get('metros_requeridos') > $available) {
|
|
$set('metros_requeridos', $available);
|
|
}
|
|
} else {
|
|
$set('metros_requeridos', 0);
|
|
}
|
|
})
|
|
->nullable(),
|
|
|
|
|
|
|
|
TextInput::make('metros_requeridos')
|
|
->label('Metros requeridos')
|
|
->numeric()
|
|
->required()
|
|
->minValue(0)
|
|
->reactive()
|
|
->helperText(fn ($get) => $get('tela_id') ? 'Saldo disponible: ' . (\App\Models\Tela::find($get('tela_id'))->metros_disponibles ?? 0) . ' m' : 'Selecciona una tela')
|
|
->default(0),
|
|
|
|
DatePicker::make('fecha_inicio')
|
|
->required()
|
|
->default(now()),
|
|
|
|
DatePicker::make('fecha_entrega_estimada')
|
|
->required(),
|
|
])
|
|
->columns(2),
|
|
|
|
Section::make('Proceso')
|
|
->schema([
|
|
View::make('filament.orden_produccion.timeline')
|
|
->columnSpanFull(),
|
|
])
|
|
->columnSpanFull(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('numero_orden')
|
|
->label('OP')
|
|
->sortable(),
|
|
|
|
TextColumn::make('prenda_modelo')
|
|
->searchable(),
|
|
|
|
TextColumn::make('referencia')
|
|
->searchable(),
|
|
|
|
TextColumn::make('cantidad_total')
|
|
->label('Cantidad'),
|
|
|
|
TextColumn::make('tela.codigo')
|
|
->label('Tela')
|
|
->toggleable(),
|
|
|
|
BadgeColumn::make('estado')
|
|
->colors([
|
|
'warning' => 'en_corte',
|
|
'info' => 'en_confeccion',
|
|
'primary' => 'en_tintoreria',
|
|
'secondary' => 'en_acabados',
|
|
'success' => 'finalizada',
|
|
])
|
|
->formatStateUsing(fn($state) => match ($state) {
|
|
'en_corte' => 'En corte',
|
|
'en_confeccion' => 'En confección',
|
|
'en_tintoreria' => 'En tintorería',
|
|
'en_acabados' => 'En acabados',
|
|
'finalizada' => 'Finalizada',
|
|
}),
|
|
|
|
TextColumn::make('fecha_entrega_estimada')
|
|
->date(),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
// Tables\Actions\Action::make('avanzar')
|
|
// ->label('Avanzar estado')
|
|
// ->icon('heroicon-o-arrow-right')
|
|
// ->requiresConfirmation()
|
|
// ->visible(fn($record) => $record->estado !== 'finalizada')
|
|
// ->action(fn($record) => $record->avanzarEstado()),
|
|
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationManagers\TrasladosRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListOrdenProduccions::route('/'),
|
|
'create' => Pages\CreateOrdenProduccion::route('/create'),
|
|
'edit' => Pages\EditOrdenProduccion::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|