Summarizer with money stored as cents

Hello, I would like to use a summarizer in my application, but I store the values that I would like to summarize in the database as cents. Then the average values do not fit.
TextColumn::make('total')
->label(__('Total'))
->money('EUR')
->searchable()
->sortable()
->summarize([
Average::make()
->money('EUR'),
Range::make()
->money('EUR'),
]),
TextColumn::make('total')
->label(__('Total'))
->money('EUR')
->searchable()
->sortable()
->summarize([
Average::make()
->money('EUR'),
Range::make()
->money('EUR'),
]),
4 Replies
Trauma Zombie
Trauma ZombieOP2y ago
I found one solution for average:
Summarizer::make()
->label(__('Average'))
->using(fn (Builder $query) => $query->avg('total') / 100)
->money('EUR'),
Summarizer::make()
->label(__('Average'))
->using(fn (Builder $query) => $query->avg('total') / 100)
->money('EUR'),
But I am not sure how to do that for range.
Dan Harrin
Dan Harrin2y ago
for range, return an array from using(), first value is min and second is max
Trauma Zombie
Trauma ZombieOP2y ago
Really thank you. Here is the solution:
Summarizer::make()
->label(__('Average'))
->using(fn (Builder $query) => $query->avg('total') / 100)
->money('EUR'),

Range::make()
->label(__('Range'))
->using(fn (Builder $query) => [$query->min('total') / 100, $query->max('total') / 100])
->money('EUR'),
Summarizer::make()
->label(__('Average'))
->using(fn (Builder $query) => $query->avg('total') / 100)
->money('EUR'),

Range::make()
->label(__('Range'))
->using(fn (Builder $query) => [$query->min('total') / 100, $query->max('total') / 100])
->money('EUR'),
I really love v3. It looks amazing. 😍
Dan Harrin
Dan Harrin2y ago
you’re welcome!
Want results from more Discord servers?
Add your server