collapsed(); } /** * @throws \Exception */ public static function fields(?string $column = null): array { $column = $column && ! str_ends_with($column, '.') ? "$column." : $column; return [ Toggle::make($column.'instant_payment')->label(trans('fields.instant_payment')) ->hintAction(HelpModal::make('help.invoice-settings')) ->helperText(trans('fields.instant_payment_hint')) ->columnSpan(2) ->default(false) ->reactive() ->rules(['boolean', fn ($set, $get) => static function (string $attribute, $value, $fail) use ($set, $get, $column) { if ($value && blank($get('stripe_connect_account_id'))) { $set($column.'instant_payment', false); $fail(__('fields.instant_payment_error')); } }]), Select::make($column.'calc_due_days_from')->label(trans('fields.calc_due_days_from')) ->hintAction(HelpModal::make('help.invoice-settings')) ->helperText(trans('fields.calc_due_days_from_hint')) ->ruleInOptions() ->options(DueDaysFrom::options()) ->default(DueDaysFrom::defaultValue()) ->columnSpan(2) ->reactive() ->required() ->hiddenIfChecked($column.'instant_payment'), TextInput::make($column.'invoice_date_num_days')->label(trans('fields.invoice_date_num_days')) ->hintAction(HelpModal::make('help.invoice-settings')) ->helperText(trans('fields.invoice_date_num_days_hint')) ->numeric()->minValue(3)->maxValue(365) ->required() ->rules('integer') ->columnSpan([ 'default' => 2, 'md' => 1, ]) ->default(15) ->hiddenIfChecked($column.'instant_payment') ->visible(fn ($get): bool => $get($column.'calc_due_days_from') === DueDaysFrom::invoiceDate->value), TextInput::make($column.'before_start_num_days')->label(trans('fields.before_start_num_days')) ->hintAction(HelpModal::make('help.invoice-settings')) ->helperText(trans('fields.before_start_num_days_hint')) ->numeric()->minValue(0)->maxValue(365) ->required() ->rules('integer') ->columnSpan([ 'default' => 2, 'md' => 1, ]) ->default(50) ->hiddenIfChecked($column.'instant_payment') ->visible(fn ($get): bool => $get($column.'calc_due_days_from') === DueDaysFrom::beforeStart->value), TextInput::make($column.'breakpoint')->label(trans('fields.breakpoint')) ->helperText(trans('fields.breakpoint_hint')) ->hintAction(HelpModal::make('help.invoice-settings')) ->numeric()->minValue(1)->maxValue(365) ->required() ->rules("sometimes|integer|lt:data.{$column}before_start_num_days") ->columnSpan([ 'default' => 2, 'md' => 1, ]) ->default(20) ->hiddenIfChecked($column.'instant_payment'), Select::make($column.'currency')->label(trans('fields.currency')) ->helperText(trans('fields.currency_hint')) ->rule(Rule::in(['SEK', 'EUR', 'GBP', 'USD'])) ->options(['SEK' => 'SEK', 'EUR' => 'EUR', 'GBP' => 'GBP', 'USD' => 'USD']) ->default('SEK') ->columnSpan(2) ->required(), //->onSave(fn ($set, $state) => $set($column."currency_symbol", self::getCurrencySymbol($state))), Textarea::make($column.'invoice_note')->label(trans('fields.invoice_note')) ->helperText(trans('fields.invoice_note_hint')) ->nullable() ->columnSpan([ 'default' => 2, 'md' => 1, ]) ->maxLength(200), Textarea::make($column.'cred_note')->label(trans('fields.cred_note')) ->helperText(trans('fields.cred_note_hint')) ->nullable() ->columnSpan([ 'default' => 2, 'md' => 1, ]) ->maxLength(200), ]; } protected static function getCurrencySymbol(string $code): int { return match ($code) { 'EUR' => '€', 'GBP' => '£', 'USD' => '$', default => 'kr', }; } public static function factory(): static { return new static([ 'instant_payment' => fake()->boolean(), 'calc_due_days_from' => DueDaysFrom::defaultValue(), 'invoice_date_num_days' => fake()->randomElement([10, 15, 30]), 'before_start_num_days' => fake()->randomElement([30, 40, 50, 60]), 'breakpoint' => fake()->randomElement([5, 10, 15, 20, 30]), 'currency' => 'SEK', //'currency_symbol' => 'kr', 'invoice_note' => fake()->text(150), 'cred_note' => fake()->text(150), ]); } #[Pure] public static function castUsing(array $arguments): DefaultCast { return new DefaultCast(new static); } }