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]);
}