summarize time interval

Hi. I have a "hours" field in my database, containig time user works in a task My column is: TextColumn::make('hours') ->label('Duración') ->time() ->summarize(Sum::make()->label('Tiempo trabajado')) ->sortable(), But "total" is not calculated ok. how can I calculate correct time sum?
No description
No description
Solution:
just use the original hours column is enough
No description
Jump to solution
23 Replies
PabloZagni
PabloZagniOP14mo ago
Anyone?
Saade
Saade14mo ago
Use a custom summarizer with a custom query, something like:
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `hours` ) ) ) AS totalhours
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `hours` ) ) ) AS totalhours
PabloZagni
PabloZagniOP14mo ago
https://filamentphp.com/docs/3.x/tables/summaries Custom summaries are "using" a query... don't know how to implement it
No description
Saade
Saade14mo ago
$query->raw()?
PabloZagni
PabloZagniOP14mo ago
but, how to apply to filtered records?
PabloZagni
PabloZagniOP14mo ago
I've done it for a basic table, but don't know how to do it in filament
No description
PabloZagni
PabloZagniOP14mo ago
Anyone?
toeknee
toeknee14mo ago
using $query->sum() ?
awsqed
awsqed14mo ago
$query->sum(DB::raw('TIME_TO_SEC(hours)'))
$query->sum(DB::raw('TIME_TO_SEC(hours)'))
then combine with your logic to convert from seconds to H:i:s
PabloZagni
PabloZagniOP14mo ago
I had to create a column "seconds" = TIME_TO_SEC(hours) but when I summarize, it give me sum(seconds), I need to formar it H:i:s now, theres no formatUsing func to Summarize
toeknee
toeknee14mo ago
Can you provide the code you are using?
PabloZagni
PabloZagniOP14mo ago
No description
PabloZagni
PabloZagniOP14mo ago
No description
toeknee
toeknee14mo ago
so as above see: https://filamentphp.com/docs/3.x/tables/summaries#custom-summaries you can format the display for you. As you are summing duration this is a time which needs diving by 60 etc.
PabloZagni
PabloZagniOP14mo ago
This doesn't work
No description
Solution
awsqed
awsqed14mo ago
just use the original hours column is enough
No description
PabloZagni
PabloZagniOP14mo ago
Thanks for your answer!! Is this Filament 2 ? I'm trying to implement and I get errors Sum <> Summarizer Builder <> QueryBuilder...
awsqed
awsqed14mo ago
its filament 3 QueryBuilder = Illuminate\Database\Query\Builder
PabloZagni
PabloZagniOP14mo ago
Done!!!!
No description
PabloZagni
PabloZagniOP14mo ago
No description
PabloZagni
PabloZagniOP14mo ago
Thanks!!! I coulnd't find the right sintax!
awsqed
awsqed14mo ago
youre welcome
Want results from more Discord servers?
Add your server