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.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.ci
.circleci
.docker
app
bin
src
tests
var
.dockerignore
.gitignore
.phpqa.yml
CHANGELOG.md
LICENSE
README.md
composer.json
composer.lock
phpunit.xml.dist

README.md

Costlocker reports

CircleCI

Generate XLSX reports from Costlocker API.

Requirements

  • PHP >= 7.0
  • composer
  • curl extension

Installation

git clone https://github.com/costlocker/reports.git
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
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.

COSTLOCKER_HOST="https://new.costlocker.com|<YOUR_API_KEY>"
Options
CLI option Value Description
--host https://new.costlocker.com|<YOUR_API_KEY> Costlocker API url and API key of your organization
--email john@example.com 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 https://developers.google.com/oauthplayground
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) {
            continue;
        }
        // note is in 15th column, Costlocker id in the following column
        if ($line[15]) {
            $notes[$line[16]] = $line[15];
        }
    }
    return $notes;
}

Profitability

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 "john@example.com"

Contributing

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

License

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