public static function form(Form $form): Form { return $form ->schema([ ArticleForm::Schema ])->colums(3) }
class ArticleForm{ public static function schema():array { return [ Forms\Components\TextInput::make('name') ->label('Libellé') ->unique(ignoreRecord: true) ->required() ->maxLength(255), Forms\Components\TextInput::make('code') ->label('Code') ->required() ->unique(ignoreRecord: true) ->maxLength(255), Forms\Components\Textarea::make('description') ->label('Description') ->columnSpanFull(), ]; }}
Repeater::make('commandeItems') ->label('Articles') ->relationship('commandeItems') ->schema([ Forms\Components\Select::make('article_id') ->options(Article::all()->pluck('name', 'id')) ->searchable(), Forms\Components\TextInput::make('quantity') ->required() ->numeric(), Forms\Components\TextInput::make('unit_price_ht') ->required() ->numeric(), Forms\Components\Select::make('tva') ->required() ->enum(TvaEnum::class) ->options(TvaEnum::class), Forms\Components\Hidden::make('unit_price_ttc') ->required(), Forms\Components\TextInput::make('total_price_ht') ->readOnly() ->numeric(), Forms\Components\TextInput::make('total_price_ttc') ->readOnly() ->required() ->numeric(), ])
protected function mapCommandeItemsForForm(): array { if (!$this->commande || !$this->commande->commandeItems) { return []; } return $this->commande->commandeItems->map(function ($commandeItem) { return [ 'article_id' => $commandeItem->article_id, 'quantity' => $commandeItem->quantity, 'unit_price_ht' => $commandeItem->unit_price_ht, 'unit_price_ttc' => $commandeItem->unit_price_ttc, 'total_price_ht' => $commandeItem->total_price_ht, 'total_price_ttc' => $commandeItem->total_price_ttc, 'tva' => $commandeItem->tva, ]; })->toArray(); }
Tables\Columns\TextColumn::make('schools') ->badge() ->formatStateUsing(fn($state) => $state->commercial_name) ->color(fn(User $record, $state) => ($state->id == $record->current_school_id) ? 'success': 'primary') ->separator(',') ->sortable() ->searchable(),
public function currentSchool(): BelongsTo { return $this->belongsTo(School::class, 'current_school_id'); }