Generate XLSX reports from Costlocker API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Costlocker reports


Generate XLSX reports from Costlocker API.


  • PHP >= 7.0
  • composer
  • curl extension


git clone
cd reports
composer install
bin/console report --help
Custom mailer (gmail, ...)

By default mail() is used for sending e-mails. But you can define custom Swift_MailTransport in app/config.php.

cp app/config.default.php app/config.php
nano app/config.php
docker build --file .docker/Dockerfile --tag reports-costlocker ./
docker run --rm -it \
    --volume "./var/cache:/app/var/cache" \
    reports-costlocker bin/console

Available reports

All examples are using environment variable with url and api key.

CLI option Value Description
--host|<YOUR_API_KEY> Costlocker API url and API key of your organization
--email Report is saved in var/reports and send report to the email provided
--drive var/drive/example Local directory with Google Drive configuration
--drive-client var/drive/example Optional (shared) client configuration (client.json, token.json), --drive contains config.php and files.json
--monthStart previous month First month use for generating report
--monthEnd current month Last month for generating report
--currency CZK Currency used in XLSX report, supported currencies: CZK, EUR
--personsSettings <PATH_TO_CSV_FILE> Person positions and hours used for calculation, take a look at example
--filter=Developer Position Filter persons by their position
--cache Cache Costlocker responses (useful when you generate full Company report and reports filtered by position)
--format xls You could define different export types, by default only xls exporter is provided
Google drive configuration

You have to create an OAuth Client and copy configuration to selected directory.

File Description
client.json Google client registered via API console
files.json Internal database of mapped files, so the report is updated, use {} or [] in new directory
token.json Access token, you can download first token from
config.php Definition of drive folder and title for each report type

Changes are overwritten. If you want to keep e.g. one column for Notes you have to download existing file and copy the column.

$notes = csvToNotes($settings->googleDrive->downloadCsvFile());
$noteId = 'irrelevant costlocker id (e.g. billing id)';
echo $notes[$noteId] ?? '';

function csvToNotes($csv)
    if (!$csv) {
        return [];
    $parser = \KzykHys\CsvParser\CsvParser::fromString($csv, ['encoding' => 'utf-8']);
    $notes = [];
    foreach ($parser as $id => $line) {
        // skip header
        if ($id <= 1) {
        // note is in 15th column, Costlocker id in the following column
        if ($line[15]) {
            $notes[$line[16]] = $line[15];
    return $notes;


Are your employees profitable?

Detailed report

# monthly report for January and February 2017 saved in var/reports
bin/console report profitability --monthStart "2017-01" --monthEnd "2017-03" --host $COSTLOCKER_HOST --email "save"

Summary report

# summary report for year 2016 sent to mail
bin/console report profitability:summary --monthStart "2016-01" --monthEnd "2016-12" --host $COSTLOCKER_HOST --personsSettings tests/fixtures/persons.csv --email ""


Contributions from others would be very much appreciated! Send pull request/issue. Thanks!


Copyright (c) 2017, 2018 Costlocker SE. MIT Licensed, see LICENSE for details.