Summarize Sum do not work when using ->state()
Why summarize is not working?
Adding
I get:
Thanks.
Tables\Columns\TextColumn::make('Price Sum + VAT')
->label('Price Sum + VAT')
->state(function (Booking $record): int {
$dealsPriceSum = $record->deals->sum('price');
$vat = $record->vat;
$totalSum = $dealsPriceSum + ($dealsPriceSum * $vat / 100);
return $totalSum;
})
->wrapHeader()
->alignment(Alignment::End)
->money('gbp', divideBy: 100)
->searchable(isIndividual: true)
->sortable()
->toggleable(),
Tables\Columns\TextColumn::make('Price Sum + VAT')
->label('Price Sum + VAT')
->state(function (Booking $record): int {
$dealsPriceSum = $record->deals->sum('price');
$vat = $record->vat;
$totalSum = $dealsPriceSum + ($dealsPriceSum * $vat / 100);
return $totalSum;
})
->wrapHeader()
->alignment(Alignment::End)
->money('gbp', divideBy: 100)
->searchable(isIndividual: true)
->sortable()
->toggleable(),
->summarize(Sum::make())
->summarize(Sum::make())
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Sum + VAT) as "FwZmbsGj3ZnDrmtk" from (select `bookings`.*, (select count(*) fro' at line 1
SELECT
sum(bookings.deals_count) AS "gJMaXg3YF2Y1Elu1",
sum(bookings.Price Sum + VAT) AS "FwZmbsGj3ZnDrmtk"
FROM
(
SELECT
`bookings`.*,
(
SELECT
count(*)
FROM
`deals`
WHERE
`bookings`.`id` = `deals`.`booking_id`
) AS `deals_count`
FROM
`bookings`
) AS `bookings`
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Sum + VAT) as "FwZmbsGj3ZnDrmtk" from (select `bookings`.*, (select count(*) fro' at line 1
SELECT
sum(bookings.deals_count) AS "gJMaXg3YF2Y1Elu1",
sum(bookings.Price Sum + VAT) AS "FwZmbsGj3ZnDrmtk"
FROM
(
SELECT
`bookings`.*,
(
SELECT
count(*)
FROM
`deals`
WHERE
`bookings`.`id` = `deals`.`booking_id`
) AS `deals_count`
FROM
`bookings`
) AS `bookings`
1 Reply
Maybe try this : https://filamentphp.com/docs/3.x/tables/summaries#custom-summaries
Because it will not use state it will sum from database.