KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Excel export: Custom footer help #3379

Open Alexandra Yusov opened this topic on on Nov 16 - 2 comments

Alexandra Yusov commented on Nov 16

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

Sebastian Morales commented on Nov 18

So far, excel/Table widget has only supported fixed aggregations such as "sum", "avg", etc and not anonymous function in footer like core/Table widget does yet. We will let you know when this functionality is available and send you an updated version of Excel package.

Sebastian Morales commented on Nov 18

Pls send us an email to support@koolreport.com and mention this topic, we will send you a development version of Excel package that solves this issue.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None