filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
17.42k stars 2.73k forks source link

Table with totalizer error - date group by month #13257

Closed rodrigodeniel closed 2 months ago

rodrigodeniel commented 2 months ago

Package

filament/filament

Package Version

v3.2.91

Laravel Version

v10.48.11

Livewire Version

v3.5.0

PHP Version

PHP 8.2.16

Problem description

The table presents a calculation error in the totalizer, when the date field is grouped by month/year. The example below shows the summary for the month of May adding only the last record. In this case I am using: ->configure([Table::$defaultDateDisplayFormat = 'F Y'])

image

Expected behavior

When not grouping, the sum is obtained correctly, but the grouping is by day/month/year //->configure([Table::$defaultDateDisplayFormat = 'F Y']) image

Steps to reproduce

This is the code used:

` public function table(Table $table): Table { return $table

        ->defaultGroup('DataVencimento')
        ->groupsOnly(false)
        ->groupingSettingsHidden()  
        ->groupingDirectionSettingHidden(false)
        ->groups([
            Group::make('DataVencimento')
                ->label('Vencimento')
                ->date()
                ->collapsible(true)
                ->titlePrefixedWithLabel(true)
                ,
        ])          
        ->configure([
            Table::$defaultDateDisplayFormat = 'F Y'
        ])
        ->defaultSort('DataVencimento', 'asc')          
        ->columns([
            Tables\Columns\TextColumn::make('CodigoVendaID')
                ->label('Venda'),
            Tables\Columns\TextColumn::make('loja.NomeLoja')
                ->label('Farmácia'),
            Tables\Columns\TextColumn::make('DataLancamento')
                ->label('Lançamento')
                ->searchable()
                ->datetime('d/m/Y')
                ->sortable(),
            Tables\Columns\TextColumn::make('Parcela'),
            Tables\Columns\TextColumn::make('DataVencimento')
                ->label('Vencimento')
                ->searchable()
                ->datetime('d/m/Y')
                ->sortable(),
            Tables\Columns\TextColumn::make('Saldo')
                ->label('Saldo')
                ->formatStateUsing(fn ($state): string => 'R$ ' . number_format((float) $state, 2, ',', '.'))
                ->summarize(
                    Sum::make()
                    ->label('Total:')
                    ->extraAttributes(['class' => 'font-bold'])
                    ->formatStateUsing(fn ($state): string => 'R$ ' . number_format((float) $state, 2, ',', '.')),
                )
                ,
        ])
        ->filters([
            //
        ])
        ->actions([
            //
        ]);
}`

Reproduction repository (issue will be closed if this is not valid)

https://github.com/rodrigodeniel/filament-table-error

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

zepfietje commented 2 months ago

Please create a complete reproduction repository that we can run locally, not just a single resource's files. 🙂