Hi David
I am tweaking a working example, SalesByCustomer.php with the minimum code:
SalesByCustomer.php:
<?php
require_once "../../vendor/koolphp/koolreport/koolreport/autoload.php";
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;
use \koolreport\processes\CopyColumn;
use \koolreport\processes\OnlyColumn;
class SalesByCustomer extends \koolreport\KoolReport
{
use \koolreport\export\Exportable; // <--------------------------------------------------this
function settings()
{
return array(
"assets"=>array(
"path"=>"C:\\AL\\BASE\\reportes\\reportes\\assets",
"url"=>"assets",
),
"dataSources"=>array(
"sales"=>array(
"class"=>'\koolreport\datasources\CSVDataSource',
"filePath"=>"customer_product_dollarsales2.csv",
"fieldSeparator"=>";"
),
)
);
}
function setup()
{
$this->src('sales')
->pipe(new Group(array(
"by"=>"customerName",
"sum"=>"dollar_sales"
)))
->pipe(new Sort(array(
"dollar_sales"=>"desc"
)))
->pipe(new Limit(array(10)))
->pipe($this->dataStore('sales_by_customer'));
}
}
index.php
<?php
require_once "SalesByCustomer.php";
$salesbycustomer = new SalesByCustomer;
$salesbycustomer->run()->export()->pdf(array( //<---this
"format"=>"A4", //<---this
"orientation"=>"portrait" //<---this
))->toBrowser("myfile.pdf"); //<---this
?>
<!DOCTYPE html>
<html>
<head>
<title>Sales By Customer Report</title>
<link rel="stylesheet" href="../assets/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="../assets/bootstrap/css/bootstrap-theme.min.css" />
<link rel="stylesheet" href="../assets/css/example.css" />
</head>
<body>
<div class="container box-container">
<?php $salesbycustomer->render();?>
</div>
</body>
</html>
Console php development server console messages:
Browser render page: