diff --git a/app/Filament/Resources/ProductionCalendarResource.php b/app/Filament/Resources/ProductionCalendarResource.php new file mode 100644 index 00000000..f2a85965 --- /dev/null +++ b/app/Filament/Resources/ProductionCalendarResource.php @@ -0,0 +1,131 @@ +schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant') + ->reactive() + ->relationship('plant', 'name') + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) + ->required(), + Forms\Components\TextInput::make('working_days') + ->label('Working Days'), + Forms\Components\TextInput::make('leave_dates') + ->label('Leave Dates'), + Forms\Components\Hidden::make('created_by') + ->label('Created By') + ->default(Filament::auth()->user()?->name), + Forms\Components\Hidden::make('updated_by') + ->label('Updated By') + ->default(Filament::auth()->user()?->name), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('No.') + ->label('No.') + ->getStateUsing(function ($record, $livewire, $column, $rowLoop) { + $paginator = $livewire->getTableRecords(); + $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; + $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; + + return ($currentPage - 1) * $perPage + $rowLoop->iteration; + }), + Tables\Columns\TextColumn::make('plant.name') + ->label('Plant') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('working_days') + ->label('Working Days') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('leave_dates') + ->label('Leave Dates') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('deleted_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + Tables\Filters\TrashedFilter::make(), + ]) + ->actions([ + Tables\Actions\ViewAction::make(), + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\ForceDeleteBulkAction::make(), + Tables\Actions\RestoreBulkAction::make(), + ]), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListProductionCalendars::route('/'), + 'create' => Pages\CreateProductionCalendar::route('/create'), + 'view' => Pages\ViewProductionCalendar::route('/{record}'), + 'edit' => Pages\EditProductionCalendar::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/ProductionCalendarResource/Pages/CreateProductionCalendar.php b/app/Filament/Resources/ProductionCalendarResource/Pages/CreateProductionCalendar.php new file mode 100644 index 00000000..4b76c064 --- /dev/null +++ b/app/Filament/Resources/ProductionCalendarResource/Pages/CreateProductionCalendar.php @@ -0,0 +1,12 @@ +