Hi there!
PDF and image exports are working fine. Now I am trying to get the csv and excel export working. I'm getting an Exception("Call undefined csv() method") and I don't know exactly why. Can you please show me where my mistake is? My App (in parts):
class App extends Application
{
...
protected function export()
{
return ExportHandler::create()
->storage(dirname(__DIR__) . "/tmp")
->pdfEngine(
LocalExport::create()
->defaultConfig([
"format" => "A4",
"margin" => "1in",
"orientation" => "portrait"
])
)
->jpgEngine(
LocalExport::create()
)
->pngEngine(
LocalExport::create()
)
->csvEngine(
CSVEngine::create()
->defaultConfig([
"BOM" => false,
'useLocalTempFolder' => true,
])
)
->csvEngine(
XLSXEngine::create()
);
}
}
my Report.class
class SalesCommonReport extends KoolReport
{
use \koolreport\excel\CSVExportable;
use \koolreport\excel\ExcelExportable;
protected function settings()
{
return array(
'dataSources' => array(
'db' => array( ... )
)
);
}
protected function setup()
{
$p = $this->params;
$dateStart = date('Y-m-d').' 00:00:00';
$dateEnd = date('Y-m-d').' 23:59:59';
if(isset($p["dateRange"]) && is_array($p["dateRange"])) {
if(isset($p["dateRange"][0])) {
$dateStart = date('Y-m-d H:i:s', strtotime($p["dateRange"][0]));
}
if(isset($p["dateRange"][1])) {
$dateEnd = date('Y-m-d H:i:s', strtotime($p["dateRange"][1]));
}
}
...
$this->src('db')->query("
SELECT DISTINCT
...
")->pipe(
new CalculatedColumn(array(
...
))
)->pipe(
$this->dataStore('_salesCommonResult')
);
}
}
my widget
class SalesCommonResult extends KWidget
{
//protected $allowExport = false;
protected function dataSource()
{
$report = new SalesCommonReport(array(
"dateRange" => $this->sibling("VDateRangePicker")->value(),
));
return $report->run()->dataStore("_salesCommonResult");
}
protected function onCreated()
{
$this
->use(\koolreport\widgets\koolphp\Table::class)
->settings([
"cssClass"=>array(
"table"=>"table table-bordered table-sm"
),
"emptyValue" => "",
"tableSmall"=>true,
"showFooter"=>true,
"columns"=>array(
"articleName"=>array(
"label"=>"Artikel",
"footerText"=>"<b>Gesamt</b>",
),
...
"amountGross"=>array(
"label"=>"Brutto",
'valType' => 'float',
'type' => 'number',
"decimals"=>2,
"cssStyle"=>"text-align:right",
"footer"=>"sum",
"footerText"=>"<b>@value</b>"
)
),
'grouping' => array(
"groupName" => array(
"calculate"=>array(
"{sumAmountGross}"=>array("sum","amountGross")
),
"top"=>"<b>{groupName}</b>",
"bottom"=>'<td colspan="8"><b>Gesamt</b></td>
<td style="text-align:right"><b>{sumAmountGross}</b></td>'
),
),
]);
}
protected function fields() {
return array(
Text::create("Artikel")
->colName("articleName"),
...
Number::create("Brutto")
->colName("amountGross")
->decimals(2)
);
}
public function dataView()
{
$dataView = parent::dataView();
$fields = $this->fields();
return $dataView->fields($fields);
}
}
my board
class SalesCommonBoard extends Dashboard
{
protected function content()
{
return [
Row::create()->sub([
Panel::create()
->header("<b>".Lang::t("Filter options")."</b>")
->sub([
Row::create([
[
Html::label(Lang::t("Time period")),
VDateRangePicker::create(),
],
]),
Row::create([
Inline::create([
RequestResultButton::create()
->type("primary")
->icon("fa fa-eye")
->text(Lang::t("View"))
->laddaOnAction(true),
Dropdown::create("exporting")
->title("Export")
->type("success")
->icon("fa fa-file-download")
->items([
Dropdown::menuItem()
->text("PDF")
->icon("fa fa-file-pdf")
->onClick(
Client::widget("Result")->exportToPDF()
),
Dropdown::menuItem()
->text("Excel")
->icon("fa fa-file-excel")
->onClick(
Client::widget("Result")->exportToXLSX("SalesCommon")
),
Dropdown::menuItem()
->text("CSV")
->icon("fa fa-file-csv")
->onClick(
Client::widget("Result")->exportToCSV("SalesCommon")
),
Dropdown::menuItem()
->text("Image PNG")
->icon("fa fa-file-image")
->onClick(
Client::widget("Result")->exportToPNG()
),
Dropdown::menuItem()
->text("Image JPG")
->icon("fa fa-file-image")
->onClick(
Client::widget("Result")->exportToJPG()
),
]),
]),
]),
]),
]),
Row::create()->sub([
Panel::create()
->sub([
Row::create([
SalesCommonResult::create("Result")
->pdfExportable( [
"format"=>"A4",
"orientation"=>"landscape",
"zoom" => 0.5,
]
)
->pngExportable(true)
->jpgExportable(true)
->csvExportable(true)
->xlsxExportable(true)
]),
]),
]),
];
}
}
Thank you in advance