Group sum summarie with query scope, not working

Hello, When i add a scope to summarie, and group my table, the group total is the same that the total when i dont add scope its working perfectly, but i dont have the sum i need (i have to scope it...). here my code: (when i remove the ->query it's work perfectly fine)
MoneyColumn::make("order_products_com")
->label(__("commission"))
->placeholder("0,00€")
->color('success')
->suffix('€')
->formatStateUsing(function (int $state) {
if ($state == 0) {
return self::formatDisplay(self::addZeros($state));
} else {
return self::formatDisplay($state);
}

})
->summarize(Sum::make()
->query(fn(QueryBuilder $query) => $query->where('order_product_is_com_payed', '=', 0))
->label(__("total commission"))
->formatStateUsing(function (int $state) {
if ($state == 0) {
return self::formatDisplay(self::addZeros($state));
} else {
return self::formatDisplay($state);
}

}),
),

MoneyColumn::make("order_product_sum_com_cancel")
->label(__("to_take"))
->color('danger')
->placeholder("0,00€")
->suffix('€')
->formatStateUsing(function (int $state) {
if ($state == 0) {
return self::formatDisplay(self::addZeros($state));
} else {
return self::formatDisplay($state);
}

})
->summarize(Sum::make()
->query(fn(QueryBuilder $query) => $query->where([
['order_product_is_com_payed', "=", 1],
['order_product_is_com_cancel', "=", 1]
]))
->label(__("total to take"))
->formatStateUsing(function (int $state) {
return self::formatDisplay($state);
}),
),
])
MoneyColumn::make("order_products_com")
->label(__("commission"))
->placeholder("0,00€")
->color('success')
->suffix('€')
->formatStateUsing(function (int $state) {
if ($state == 0) {
return self::formatDisplay(self::addZeros($state));
} else {
return self::formatDisplay($state);
}

})
->summarize(Sum::make()
->query(fn(QueryBuilder $query) => $query->where('order_product_is_com_payed', '=', 0))
->label(__("total commission"))
->formatStateUsing(function (int $state) {
if ($state == 0) {
return self::formatDisplay(self::addZeros($state));
} else {
return self::formatDisplay($state);
}

}),
),

MoneyColumn::make("order_product_sum_com_cancel")
->label(__("to_take"))
->color('danger')
->placeholder("0,00€")
->suffix('€')
->formatStateUsing(function (int $state) {
if ($state == 0) {
return self::formatDisplay(self::addZeros($state));
} else {
return self::formatDisplay($state);
}

})
->summarize(Sum::make()
->query(fn(QueryBuilder $query) => $query->where([
['order_product_is_com_payed', "=", 1],
['order_product_is_com_cancel', "=", 1]
]))
->label(__("total to take"))
->formatStateUsing(function (int $state) {
return self::formatDisplay($state);
}),
),
])
And i add a screenshot of what i get. If you have any idea how to get this working thanks you in advance.
No description
8 Replies
sandofgods
sandofgods3mo ago
bump bump
toeknee
toeknee3mo ago
Check your querries when scoped and none scoped?
sandofgods
sandofgods3mo ago
Without ->query () it's working perfectly, but it sum lines dont want to sum. The only difference between with or without scope is the condition added at the end.
toeknee
toeknee3mo ago
The fact it's working is not so important it's the queries that are ran if by ->query() it is skipping some other methods / magic hence checking the queries. But if the query is the same but the only difference is the Query additional where. the faults in your query logic Id say. IF you manually run the query does it return as expected in SQL?
sandofgods
sandofgods3mo ago
yes it return as expected, just it dosent group summaries it total summaries for all group. i just recheck to be sure If you see the screenshot, the total summaries is the amount i expect, but it should be different for the two group. so any idea? should i create a bug in filament github?
toeknee
toeknee3mo ago
IF you can recreate a reproduction repo then please do.
sandofgods
sandofgods3mo ago
Hello, Here the repo: https://github.com/ronylicha/bugfphp I have reproduce the bug of my two post here, this one about the group sum with scope not working, and the second one, when you check one or two and do bulk action, all the table got check and updated. What you have to do: update the .env with the db credential and db name
artisan migrate
artisan db:seed
artisan migrate
artisan db:seed
the admin credentials: admin@example.com//123456 Go to the commission dashboard and check the two things Please use the table filter to see the bug
GitHub
GitHub - ronylicha/bugfphp
Contribute to ronylicha/bugfphp development by creating an account on GitHub.
sandofgods
sandofgods3mo ago
bump