Hi,
I am trying to do implement custom footer logic however I am getting the following error:
Error
Object of class Closure could not be converted to string
at vendor/koolreport/excel/TableBuilder.php:331
327▕ $fValue = null;
328▕ if ($pos === 'footer') {
329▕ $colMeta = $this->colMetas[$colKey];
330▕ $fValue = "";
➜ 331▕ $method = strtolower((string) Util::get($colMeta, "footer"));
332▕ if (in_array($method, ["sum", "avg", "min", "max", "mode"])) {
333▕ $fValue = Util::formatValue($this->ds->$method($colKey), $colMeta);
334▕ }
335▕ $footerText = Util::get($colMeta, "footerText");
+5 vendor frames
I have followed the guide here:
https://www.koolreport.com/docs/koolphp/table/#:~:text=If%20you%20need%20more%20custom,parameter%20which%20is%20the%20DataStore%20.
and here:
https://www.koolreport.com/forum/topics/2986
sample code:
$data = $this->dataStore('Datastore');
Table::create(array(
"dataSource" => $data,
"columns" => [
"date" => ["type" => "string", "label" => "Date"],
"account_name" => ["type" => "string", "label" => "Account Name"],
"total_transactions" => [
"type" => "number",
"label" => "Total Transactions",
"footer" => "sum",
"footerText" => "Total: @value"
],
"total_nsf_transactions" => [
"type" => "number",
"label" => "Total NSF Transactions",
"footer" => "sum",
"footerText" => "Total: @value"
],
"failure_rate_count" => [
"label" => "Failure Rate (Count)",
"type" => "number",
"footer" => function ($data) {
$FailuresCount = $data['total_nsf_transactions'] ?? 0;
$totalTransactions = $data['total_transactions'] ?? 1;
return ($FailuresCount / $totalTransactions) * 100;
},
"footerText" => "Rate: @value%"
],
....
]
)
)
I believe I have narrowed the issue down to the footer (failure_rate_count) calling a function as footer that "sum" works (total_transactions and total_nsf_transactions).
It looks to me it is expecting either "sum", "avg", "min", "max" or "mode" according to the exception message?
thanks