@@ -38,13 +38,11 @@ public static function form(Form $form): Form
3838 ->schema ([
3939 Components \Section::make ()
4040 ->columnSpan (['lg ' => fn (?Invoice $ obj ) => !$ obj ?->project ? 10 : 8 ])
41- ->columns (12 )
42- ->schema (self ::formFields ()),
41+ ->schema (self ::formFields (12 , false )),
4342 Components \Section::make ()
4443 ->heading (__ ('currentState ' ))
4544 ->hidden (fn (?Invoice $ obj ) => !$ obj ?->project)
4645 ->columnSpan (['lg ' => 2 ])
47- ->columns (2 )
4846 ->schema ([
4947 Components \Placeholder::make ('project ' )
5048 ->label (trans_choice ('project ' , 1 ))
@@ -129,8 +127,11 @@ public static function table(Table $table): Table
129127 Actions \EditAction::make ()->icon ('tabler-edit ' )->slideOver ()->modalWidth (MaxWidth::Large),
130128 Actions \ReplicateAction::make ()
131129 ->icon ('tabler-copy ' )
132- ->excludeAttributes (['invoiced_at ' , 'paid_at ' ])
133- ->form (self ::formFields ())
130+ ->beforeFormFilled (function (Invoice $ record ) {
131+ $ record ->invoiced_at = null ;
132+ $ record ->paid_at = null ;
133+ })
134+ ->form (self ::formFields (6 , false ))
134135 ->slideOver ()
135136 ->modalWidth (MaxWidth::ExtraLarge),
136137 Actions \Action::make ('pdf ' )
@@ -247,96 +248,98 @@ public static function getPluralModelLabel(): string
247248 /**
248249 * Return a list of components containing form fields
249250 */
250- public static function formFields (int $ columns = 12 ): array
251+ public static function formFields (int $ columns = 12 , bool $ useSection = true ): array
251252 {
252- return [
253- Components \Grid::make ($ columns )->schema ([
254- Components \Select::make ('project_id ' )
255- ->label (trans_choice ('project ' , 1 ))
256- ->columnSpan (6 )
257- ->relationship ('project ' , 'title ' )
258- ->getOptionLabelFromRecordUsing (fn (Project $ record ) => "{$ record ->title } ( {$ record ->client ->name }) " )
259- ->searchable ()
260- ->preload ()
261- ->suffixIcon ('tabler-package ' )
262- ->required (),
263- Components \Toggle::make ('transitory ' )
264- ->label (__ ('transitory ' ))
265- ->columnSpan (3 )
266- ->inline (false )
267- ->hintIcon ('tabler-info-circle ' , __ ('invoice.onlyTransitory ' )),
268- Components \Toggle::make ('undated ' )
269- ->label (__ ('undated ' ))
270- ->columnSpan (3 )
271- ->inline (false )
272- ->hintIcon ('tabler-info-circle ' , __ ('hidePositionsDate ' )),
273- Components \TextInput::make ('title ' )
274- ->label (__ ('title ' ))
275- ->columnSpan (6 )
276- ->required (),
277- Components \Textarea::make ('description ' )
278- ->label (__ ('description ' ))
279- ->columnSpan (6 )
280- ->autosize ()
281- ->maxLength (65535 ),
282- Components \TextInput::make ('price ' )
283- ->label (__ ('price ' ))
284- ->columnSpan (3 )
285- ->numeric ()
286- ->step (0.01 )
287- ->minValue (0.01 )
288- ->suffixIcon ('tabler-currency-euro ' )
289- ->required (),
290- Components \Select::make ('pricing_unit ' )
291- ->label (__ ('pricingUnit ' ))
292- ->columnSpan (3 )
293- ->options (PricingUnit::class)
294- ->suffixIcon ('tabler-clock-2 ' )
295- ->required (),
296- Components \TextInput::make ('discount ' )
297- ->label (__ ('discount ' ))
298- ->columnSpan (3 )
299- ->numeric ()
300- ->step (0.01 )
301- ->minValue (0.01 )
302- ->suffixIcon ('tabler-currency-euro ' )
303- ->helperText (__ ('priceBeforeTax ' )),
304- Components \TextInput::make ('deduction ' )
305- ->label (__ ('deduction ' ))
306- ->columnSpan (3 )
307- ->numeric ()
308- ->step (0.01 )
309- ->minValue (0.01 )
310- ->suffixIcon ('tabler-currency-euro ' )
311- ->helperText (__ ('priceAfterTax ' )),
312- Components \Toggle::make ('taxable ' )
313- ->label (__ ('taxable ' ))
314- ->columnSpan (3 )
315- ->inline (false )
316- ->default (true )
317- ->live (),
318- Components \TextInput::make ('vat_rate ' )
319- ->label (__ ('vatRate ' ))
320- ->columnSpan (3 )
321- ->numeric ()
322- ->step (0.01 )
323- ->minValue (0.01 )
324- ->default (0.19 )
325- ->suffixIcon ('tabler-receipt-tax ' )
326- ->hidden (fn (Get $ get ): bool => ! $ get ('taxable ' )),
327- Components \DatePicker::make ('invoiced_at ' )
328- ->label (__ ('invoicedAt ' ))
329- ->columnSpan (3 )
330- ->columnStart (7 )
331- ->weekStartsOnMonday ()
332- ->suffixIcon ('tabler-calendar-up ' ),
333- Components \DatePicker::make ('paid_at ' )
334- ->label (__ ('paidAt ' ))
335- ->columnSpan (3 )
336- ->weekStartsOnMonday ()
337- ->suffixIcon ('tabler-calendar-down ' ),
338- ])
253+ $ half = intval ($ columns / ($ columns > 6 ? 2 : 1 ));
254+ $ fields = [
255+ Components \Select::make ('project_id ' )
256+ ->label (trans_choice ('project ' , 1 ))
257+ ->relationship ('project ' , 'title ' )
258+ ->getOptionLabelFromRecordUsing (fn (Project $ record ) => "{$ record ->title } ( {$ record ->client ->name }) " )
259+ ->searchable ()
260+ ->preload ()
261+ ->suffixIcon ('tabler-package ' )
262+ ->required ()
263+ ->columnSpan ($ half ),
264+ Components \Toggle::make ('transitory ' )
265+ ->label (__ ('transitory ' ))
266+ ->inline (false )
267+ ->hintIcon ('tabler-info-circle ' , __ ('invoice.onlyTransitory ' ))
268+ ->columnSpan ($ half /2 ),
269+ Components \Toggle::make ('undated ' )
270+ ->label (__ ('undated ' ))
271+ ->inline (false )
272+ ->hintIcon ('tabler-info-circle ' , __ ('hidePositionsDate ' ))
273+ ->columnSpan ($ half /2 ),
274+ Components \TextInput::make ('title ' )
275+ ->label (__ ('title ' ))
276+ ->required ()
277+ ->columnSpan ($ half ),
278+ Components \Textarea::make ('description ' )
279+ ->label (__ ('description ' ))
280+ ->autosize ()
281+ ->maxLength (65535 )
282+ ->columnSpan ($ half ),
283+ Components \TextInput::make ('price ' )
284+ ->label (__ ('price ' ))
285+ ->numeric ()
286+ ->step (0.01 )
287+ ->minValue (0.01 )
288+ ->suffixIcon ('tabler-currency-euro ' )
289+ ->required ()
290+ ->columnSpan ($ half /2 ),
291+ Components \Select::make ('pricing_unit ' )
292+ ->label (__ ('pricingUnit ' ))
293+ ->options (PricingUnit::class)
294+ ->suffixIcon ('tabler-clock-2 ' )
295+ ->required ()
296+ ->columnSpan ($ half /2 ),
297+ Components \TextInput::make ('discount ' )
298+ ->label (__ ('discount ' ))
299+ ->numeric ()
300+ ->step (0.01 )
301+ ->minValue (0.01 )
302+ ->suffixIcon ('tabler-currency-euro ' )
303+ ->helperText (__ ('priceBeforeTax ' ))
304+ ->columnSpan ($ half /2 ),
305+ Components \TextInput::make ('deduction ' )
306+ ->label (__ ('deduction ' ))
307+ ->numeric ()
308+ ->step (0.01 )
309+ ->minValue (0.01 )
310+ ->suffixIcon ('tabler-currency-euro ' )
311+ ->helperText (__ ('priceAfterTax ' ))
312+ ->columnSpan ($ half /2 ),
313+ Components \Toggle::make ('taxable ' )
314+ ->label (__ ('taxable ' ))
315+ ->inline (false )
316+ ->default (true )
317+ ->live ()
318+ ->columnSpan ($ half /2 ),
319+ Components \TextInput::make ('vat_rate ' )
320+ ->label (__ ('vatRate ' ))
321+ ->numeric ()
322+ ->step (0.01 )
323+ ->minValue (0.01 )
324+ ->default (0.19 )
325+ ->suffixIcon ('tabler-receipt-tax ' )
326+ ->hidden (fn (Get $ get ): bool => ! $ get ('taxable ' ))
327+ ->columnSpan ($ half /2 ),
328+ Components \DatePicker::make ('invoiced_at ' )
329+ ->label (__ ('invoicedAt ' ))
330+ ->weekStartsOnMonday ()
331+ ->suffixIcon ('tabler-calendar-up ' )
332+ ->columnSpan ($ half /2 ),
333+ Components \DatePicker::make ('paid_at ' )
334+ ->label (__ ('paidAt ' ))
335+ ->weekStartsOnMonday ()
336+ ->suffixIcon ('tabler-calendar-down ' )
337+ ->columnSpan ($ half /2 ),
339338 ];
339+
340+ return $ useSection
341+ ? [Components \Section::make ()->columns ($ columns )->schema ($ fields )]
342+ : [Components \Grid::make ($ columns )->schema ($ fields )];
340343 }
341344
342345}
0 commit comments