The export module allows you to export filtered timesheet data into several formats.
There are a couple of differences in these two Kimai modules, the most important ones:
So giving a user the permission to export data allows to see most time related data in Kimai (like customer, projects, activities, rates, time worked per user and more).
Invoices and exports share the export state, which is used to mark timesheet records as processed. These records cannot be edited any longer by regular users and are excluded by default from further invoices and exports.
You need to tick the checkbox before creating the export, to automatically set the export state on all filtered timesheet records.
For further information read the timesheet documentation.
Since Kimai 1.9 you can add templates for PDF and HTML exports.
Export documents are searched in two locations:
var/export/
- does not exist by default, please create it when you add a new templatetemplates/export/renderer/
- don’t change files in here, will be overwritten with te next updateBe aware of the following rules:
.html.twig
.pdf.twig
var/export/default.html.twig
and templates/export/renderer/default.html.twig
will lead to unpredictable resultsacme-export.html.twig
var/export/
, as this directory is not shipped with Kimai and not touched during updateskimai.export.documents
if you want to add additional template source directorieskimai.export.defaults
to an empty array / nullAfter you created a new or updated an existing template, you have to clear the cache to see the results:
bin/console kimai:reload --env=prod
FTP users: please have a look at this documentation.
If you are running an older version of Kimai (before 1.8) you have to use:
bin/console cache:clear --env=prod
bin/console cache:warmup --env=prod
Please copy & paste one of default templates to var/export/
as starting point and rename it afterwards.
You can translate the button for your template, by adding its name to the export translation file, eg. translations/export.en.xlf
.
Internally for each template a new ExportRenderer service is registered, called exporter_renderer.filename_EXT_twig
(see ExportServiceCompilerPass
).
Since 1.13 you can customize the following values from within your PDF templates:
filename
{{- pdfContext.setOption('format', 'A4-L') -}}
{{- pdfContext.setOption('filename', 'Timesheets_' ~ filenamePrefix|default('') ~ (query.customers|length == 1 ? query.customers.0.name|replace({' ': '-'}) ~ '_' : '') ~ query.begin|date_format('Y_m') ~ '.pdf') -}}
The variable name (here format
and filename
) must be one of the mPDF construtor options, ConfigVariables or FontVariables.
An export renderer is a class implementing App\Export\RendererInterface
and it is responsible to convert an array of
Timesheet
objects into a downloadable/printable document.
Every export renderer class will be automatically available when refreshing the application cache, thanks to the
ExportServiceCompilerPass.
Each renderer is represented by a “button” below the datatable on the export screen.
A simple example, which only shows the IDs of the included timesheet records could look like this:
use App\Entity\Timesheet;
use App\Export\RendererInterface;
use App\Repository\Query\TimesheetQuery;
use Symfony\Component\HttpFoundation\Response;
final class TimesheetIdRenderer implements RendererInterface
{
public function render(array $timesheets, TimesheetQuery $query): Response
{
$ids = array_map(function(Timesheet $timesheet) {
return $timesheet->getId();
}, $timesheets);
$response = new Response();
$response->setContent(sprintf('Included IDs: %s', implode(', ', $ids)));
return $response;
}
public function getId(): string
{
return 'ext_array_dump';
}
public function getIcon(): string
{
return 'fas fa-file-code';
}
public function getTitle(): string
{
return 'Show IDs';
}
}
All you need to do is to register it as a service in the Symfony DI container.
Feature available since 1.6
Timesheet exporter (implementing the interface App\Export\TimesheetExportInterface
) are almost the same as export renderer,
except that they don’t have the methods getIcon()
and getTitle()
.
If you already wrote an export renderer, all you need to add is the second interface and you can export the filtered data from the user and admin timesheet screen.
Be aware, that you should add more permission (eg. view_rate_own_timesheet
) checks to these renderer, as they are available for every user!