style: Standardize anonymous function syntax and minor whitespace in Filament resources.

This commit is contained in:
Yoga Pangestu 2026-03-07 13:20:06 +07:00
parent 49387e7923
commit ad0cf1a535
3 changed files with 18 additions and 18 deletions

View File

@ -93,7 +93,7 @@ public static function configure(Schema $schema): Schema
$recalculateRemaining($get, $set); $recalculateRemaining($get, $set);
}) })
->currencyMask(thousandSeparator: '.', decimalSeparator: ',', precision: 2) ->currencyMask(thousandSeparator: '.', decimalSeparator: ',', precision: 2)
->formatStateUsing(fn($state) => $state === null ? null : (float) $state) ->formatStateUsing(fn ($state) => $state === null ? null : (float) $state)
->dehydrateStateUsing($unmaskQty), ->dehydrateStateUsing($unmaskQty),
TextInput::make('unit_price') TextInput::make('unit_price')
@ -129,7 +129,7 @@ public static function configure(Schema $schema): Schema
->required() ->required()
->live() ->live()
->formatStateUsing( ->formatStateUsing(
fn($state) => number_format((float) ($state ?? 0), 0, ',', '.') fn ($state) => number_format((float) ($state ?? 0), 0, ',', '.')
) )
->dehydrateStateUsing($unmaskMoney), ->dehydrateStateUsing($unmaskMoney),
@ -141,7 +141,7 @@ public static function configure(Schema $schema): Schema
->required() ->required()
->live() ->live()
->prefix('Rp') ->prefix('Rp')
->readOnly(fn(callable $get) => $get('is_paid')) ->readOnly(fn (callable $get) => $get('is_paid'))
->afterStateUpdated(function ($state, callable $get, callable $set) use ($recalculateRemaining, $unmaskMoney): void { ->afterStateUpdated(function ($state, callable $get, callable $set) use ($recalculateRemaining, $unmaskMoney): void {
$paidAmount = $unmaskMoney($state); $paidAmount = $unmaskMoney($state);
$totalAmount = $unmaskMoney($get('total_amount')); $totalAmount = $unmaskMoney($get('total_amount'));

View File

@ -37,7 +37,7 @@ public static function configure(Table $table): Table
TextColumn::make('quantity') TextColumn::make('quantity')
->label('Jumlah') ->label('Jumlah')
->getStateUsing(function ($record) { ->getStateUsing(function ($record) {
return str_replace('.', ',', (float) $record->quantity) . " {$record->unit?->alias}"; return str_replace('.', ',', (float) $record->quantity)." {$record->unit?->alias}";
}) })
->sortable(), ->sortable(),
@ -55,14 +55,14 @@ public static function configure(Table $table): Table
->label('Sudah Dibayar') ->label('Sudah Dibayar')
->money('IDR', decimalPlaces: 0) ->money('IDR', decimalPlaces: 0)
->sortable() ->sortable()
->color(fn($record) => $record->paid_amount >= $record->total_amount ? 'success' : 'warning'), ->color(fn ($record) => $record->paid_amount >= $record->total_amount ? 'success' : 'warning'),
TextColumn::make('remaining_amount') TextColumn::make('remaining_amount')
->label('Sisa') ->label('Sisa')
->getStateUsing(fn($record) => max(0, $record->total_amount - $record->paid_amount)) ->getStateUsing(fn ($record) => max(0, $record->total_amount - $record->paid_amount))
->money('IDR', decimalPlaces: 0) ->money('IDR', decimalPlaces: 0)
->sortable() ->sortable()
->color(fn($record) => $record->paid_amount >= $record->total_amount ? 'success' : 'danger'), ->color(fn ($record) => $record->paid_amount >= $record->total_amount ? 'success' : 'danger'),
IconColumn::make('is_paid') IconColumn::make('is_paid')
->label('Status') ->label('Status')
@ -87,24 +87,24 @@ public static function configure(Table $table): Table
->filters([ ->filters([
TrashedFilter::make() TrashedFilter::make()
->native(false) ->native(false)
->visible(fn(): bool => auth()->user()->hasRole(RoleEnum::DEVELOPER)), ->visible(fn (): bool => auth()->user()->hasRole(RoleEnum::DEVELOPER)),
]) ])
->recordActions([ ->recordActions([
Action::make('pelunasan') Action::make('pelunasan')
->label('Pelunasan') ->label('Pelunasan')
->icon(Heroicon::CurrencyDollar) ->icon(Heroicon::CurrencyDollar)
->color('success') ->color('success')
->visible(fn($record) => ! $record->is_paid) ->visible(fn ($record) => ! $record->is_paid)
->schema([ ->schema([
TextInput::make('amount') TextInput::make('amount')
->label('Jumlah yang dibayar') ->label('Jumlah yang dibayar')
->required() ->required()
->default(fn($record) => max(0, $record->total_amount - $record->paid_amount)) ->default(fn ($record) => max(0, $record->total_amount - $record->paid_amount))
->helperText(fn($record) => 'sisa: Rp ' . number_format(max(0, $record->total_amount - $record->paid_amount), 0, ',', '.')) ->helperText(fn ($record) => 'sisa: Rp '.number_format(max(0, $record->total_amount - $record->paid_amount), 0, ',', '.'))
->prefix('Rp') ->prefix('Rp')
->live() ->live()
->currencyMask(thousandSeparator: '.', decimalSeparator: ',', precision: 0) ->currencyMask(thousandSeparator: '.', decimalSeparator: ',', precision: 0)
->dehydrateStateUsing(fn($state) => (float) str()->replace(',', '.', str()->replace('.', '', (string) ($state ?? 0)))), ->dehydrateStateUsing(fn ($state) => (float) str()->replace(',', '.', str()->replace('.', '', (string) ($state ?? 0)))),
]) ])
->requiresConfirmation() ->requiresConfirmation()
->action(function (array $data, $record) { ->action(function (array $data, $record) {

View File

@ -58,7 +58,7 @@ public static function form(Schema $schema): Schema
->required() ->required()
->searchable() ->searchable()
->preload() ->preload()
->default(fn() => Warehouse::first()?->id), ->default(fn () => Warehouse::first()?->id),
Repeater::make('items') Repeater::make('items')
->label('Rincian Produksi') ->label('Rincian Produksi')
@ -77,7 +77,7 @@ public static function form(Schema $schema): Schema
->autocomplete(false) ->autocomplete(false)
->required() ->required()
->currencyMask(thousandSeparator: '.', decimalSeparator: ',', precision: 2) ->currencyMask(thousandSeparator: '.', decimalSeparator: ',', precision: 2)
->formatStateUsing(fn($state) => $state === null ? null : (float) $state) ->formatStateUsing(fn ($state) => $state === null ? null : (float) $state)
->dehydrateStateUsing(function ($state) { ->dehydrateStateUsing(function ($state) {
if (blank($state)) { if (blank($state)) {
return 0; return 0;
@ -131,11 +131,11 @@ public static function table(Table $table): Table
->orderBy('is_broken') ->orderBy('is_broken')
->with('unit') ->with('unit')
->get() ->get()
->map(fn($item) => str_replace('.', ',', (float) $item->quantity) . " {$item->unit?->alias}" . ($item->is_broken ? ' (Pecah)' : '')) ->map(fn ($item) => str_replace('.', ',', (float) $item->quantity)." {$item->unit?->alias}".($item->is_broken ? ' (Pecah)' : ''))
->toArray(); ->toArray();
}) })
->listWithLineBreaks() ->listWithLineBreaks()
->color(fn($state) => str_contains($state, '(Pecah)') ? 'danger' : 'success') ->color(fn ($state) => str_contains($state, '(Pecah)') ? 'danger' : 'success')
->placeholder('-'), ->placeholder('-'),
TextColumn::make('notes') TextColumn::make('notes')
@ -148,13 +148,13 @@ public static function table(Table $table): Table
->filters([ ->filters([
TrashedFilter::make() TrashedFilter::make()
->native(false) ->native(false)
->visible(fn(): bool => auth()->user()->hasRole(RoleEnum::DEVELOPER)), ->visible(fn (): bool => auth()->user()->hasRole(RoleEnum::DEVELOPER)),
]) ])
->recordActions([ ->recordActions([
EditAction::make() EditAction::make()
->label('Ubah') ->label('Ubah')
->modalWidth(Width::FourExtraLarge) ->modalWidth(Width::FourExtraLarge)
->modalHeading(fn(EggCollection $record): string => 'Ubah ' . $record->production_date->translatedFormat('l, d F Y H:i')), ->modalHeading(fn (EggCollection $record): string => 'Ubah '.$record->production_date->translatedFormat('l, d F Y H:i')),
DeleteAction::make(), DeleteAction::make(),