Kimai2: Custom pdf export - user display name on top of sheet

Created on 28 Aug 2020  路  7Comments  路  Source: kevinpapst/kimai2

Currently I am trying to edit one of the templates for exporting the weeks hours for a user to a pdf. From the dashboard, I go to Export, then set the Time Range and User.

Above the Period date I have:
`

{{ kimai_context.branding.company|raw }}

{{ 'label.user'|trans }}: {{ query.user.displayName }}

`

It is showing the company name and User: label, but not the selected users name. I am at a loss on exactly what to put instead of query.user.displayName. There's not much information on exporting to suggest what I'm looking for.

export support

All 7 comments

Export has multi-select for users, so {{ query.user }} is always empty.

I guess you have to use {{聽query.users.0.displayName }}

Thanks so much! That did the trick, I'll just have to remember to only export 1 users hours at a time. Trying to export 2 of them is only going to show the first users name.

I will likely add another plugin request to my list to make the user select field single select. Not sure if this is possible at the moment...

This is definitely not wanted and will be rejected. It took me quite a while to get to the point that almost all fields can be multi-select.

I understand your point. Would it be possible on the multi-select to pay for a custom template on the Summary and Full List for all the selected users separately?

Our work days go from Friday to the following Thursday, so I will have to select those days for each user individually to export. The only benefit is saving time really, but at some point someone else besides myself may end up using this system. Honestly it isn't that difficult to remove one user from the multi-select, add a different one, and export a separate sheet to print.

New exports can be added via custom plugin => so yes, a custom template is possible.

Is there a list of how to access the data anywhere? I would have never guessed how to get the users display name, but going off that logic, query.users.0.hourly_rate or query.users.0.hourlyRate or query.users.0.rate or query.users.0.rate_hourly should return that value for that user, but none of them are working...

I hate to keep asking tedious questions, so if there is a reference it would help.

Switch to dev mode (APP_ENV=dev in .env) and then add a {{ dump(query) }} and see all available fields immediately (does NOT work in PDF exports).

All available fields for the user can be seen here: https://github.com/kevinpapst/kimai2/blob/master/src/Entity/User.php (search for public function get). Then a function like public function getLanguage() is available in the template with user.language.

There is magic involved that is already documented here: https://twig.symfony.com

The hourly rate is a special field, which has no own accessor method, as it is used in only 1 or 2 places in Kimai.
You can grab it with {{ user.preferenceValue('hourly_rate') }} => calling the function getPreferenceValue().

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcgruenhage picture jcgruenhage  路  5Comments

trentks picture trentks  路  5Comments

derdeagle picture derdeagle  路  5Comments

gimmesomethinggood picture gimmesomethinggood  路  4Comments

MakhPeter picture MakhPeter  路  5Comments