KoolReport's Forum

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

My Footer Not Working #3149

Closed Hazim opened this topic on on Sep 20, 2023 - 2 comments

Hazim commented on Sep 20, 2023

Myreport.php

public $grossAmSum = 0;

public $commissionSum = 0;
public $tradeExpSum = 0;
public $netSum = 0;

function setup()
{

    $this->src("mysql")
        ->query("SELECT code, grossAm, commission, tradeExp, net FROM reits")
        ->pipe($this->dataStore("reits"));

    $this->dataStore("reits")->pipe(new CalculatedColumn([
        "total" => function ($row) {
            return $row["grossAm"] + $row["commission"] + $row["tradeExp"] + $row["net"];
        }
    ]));

    // Calculate the sums and store them in properties
    $this->grossAmSum = $this->dataStore("reits")->sum("grossAm");
    $this->commissionSum = $this->dataStore("reits")->sum("commission");
    $this->tradeExpSum = $this->dataStore("reits")->sum("tradeExp");
    $this->netSum = $this->dataStore("reits")->sum("net");
    }

}

MyReport.view.php

<?php

            Table::create([
                "dataSource" => $this->dataStore("reits"),
                "columns" => [
                    "code" => ["label" => "Code"],
                    "grossAm" => ["label" => "Gross Amount"],
                    "commission" => ["label" => "Commission"],
                    "tradeExp" => ["label" => "Trade Expenses"],
                    "net" => ["label" => "Net"]
                ],
                "footer" => [
                    "code" => ["label" => "Total"],
                    "grossAm" => ["label" => number_format($this->grossAmSum, 2)], 
                    "commission" => ["label" => number_format($this->commissionSum, 2)],
                    "tradeExp" => ["label" => number_format($this->tradeExpSum, 2)],
                    "net" => ["label" => number_format($this->netSum, 2)]
                ]
            ]);
        ?>

ReportController.php

public function index()
{
    $report = new MyReport;
    $report->run();

    return view("report", ["report" => $report]);
}
Sebastian Morales commented on Sep 20, 2023

I think it's just the "footer" setting structure is different. Pls refer to our Table's footer setting:

https://www.koolreport.com/docs/koolphp/table/#table-settings-aggregated-footer

    Table::create(array(
        ...
        "showFooter"=>"bottom",
        "columns"=>array(
            "amount"=>array(
                "footer"=>"sum"
            ),
            "sale"=>array(
                "footer"=>"avg",
                "footerText"=>"Avg Sale: @value",
            )
        ),
        ...
    ));
Hazim commented on Sep 20, 2023

Yes, you are absolutely right. We have to follow those format that are already set by dev. Thanks.

Table::create([

                "dataSource" => $this->dataStore("reits"),
                "showFooter"=>"bottom",
                "columns" => [
                    "code" => ["label" => "Code",
                        "footer"=>"Total"],
                    "grossAm" => ["label" => "Gross Amount",
                        "footer"=>"sum"],
                    "commission" => ["label" => "Commission",
                        "footer"=>"sum"],
                    "net" => ["label" => "Net",
                        "footer"=>"sum"],
                ]
            ]);

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
help needed
solved

Laravel