Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -1,28 +1,50 @@
{% extends 'base.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% import "macros/toolbar.html.twig" as toolbar %}
{% import "macros/datatables.html.twig" as tables %}
{% set totalDuration = 0 %}
{% set totalRates = {} %}
{% if too_many is not same as (true) and preview_show and entries is not empty %}
{% for row in by_customer %}
{% set totalDuration = totalDuration + row.duration %}
{% set customerCurrency = row.customer.currency %}
{% if totalRates[customerCurrency] is not defined %}
{% set totalRates = totalRates|merge({(customerCurrency): 0.00}) %}
{% endif %}
{% set totalRates = totalRates|merge({(customerCurrency): totalRates[customerCurrency] + row.rate}) %}
{% endfor %}
{% endif %}
{% set columns = {
'avatar': {'class': 'text-nowrap w-avatar d-none d-md-table-cell', 'title': false, 'orderBy': false},
'date': {'class': 'alwaysVisible text-nowrap', 'orderBy': false},
'user': {'class': 'hidden-xs hidden-sm', 'orderBy': false},
'project': {'class': 'hidden-xs hidden-sm', 'orderBy': false},
'activity': {'class': 'hidden-xs hidden-sm hidden-md', 'orderBy': false},
'description': {'class': 'hidden-xs hidden-sm hidden-md timesheet-description', 'orderBy': false},
'unit_price': {'class': 'text-right hidden hidden-xs text-nowrap', 'orderBy': false},
'duration': {'class': 'text-right text-nowrap', 'orderBy': false},
'rate_internal': {'class': 'text-right hidden text-nowrap', 'orderBy': false},
'total_rate': {'class': 'text-right text-nowrap', 'orderBy': false},
'exported': {'class': 'alwaysVisible', 'orderBy': false},
'user': {'class': 'd-none', 'orderBy': false},
'project': {'class': 'd-none d-sm-table-cell', 'orderBy': false},
'activity': {'class': 'd-none', 'orderBy': false},
'description': {'class': 'd-none d-xl-table-cell timesheet-description', 'orderBy': false},
'unit_price': {'class': 'd-none text-nowrap text-end', 'orderBy': false},
'duration': {'class': 'text-end text-nowrap', 'orderBy': false},
'internalRate': {'class': 'text-end d-none text-nowrap', 'orderBy': false},
'total_rate': {'class': 'text-end text-nowrap', 'orderBy': false},
'actions': {'class': 'actions alwaysVisible', 'orderBy': false},
} %}
{% set tableName = 'export' %}
{% set editExported = is_granted('edit_exported_timesheet') %}
{% set showMarkAsExportedButton = false %}
{% set showToggleButton = false %}
{% if entries is not empty and form.markAsExported is defined %}
{% set showMarkAsExportedButton = form.exported.vars.value != constant('App\\Repository\\Query\\TimesheetQuery::STATE_EXPORTED') %}
{% set showToggleButton = preview_show and form.exported.vars.value != constant('App\\Repository\\Query\\TimesheetQuery::STATE_ALL') %}
{% endif %}
{% block page_title %}{{ 'export.title'|trans }}{% endblock %}
{% block page_actions %}
{% set event = actions(app.user, 'export', (preview_show ? 'preview' : 'index')) %}
{{ widgets.page_actions(event.actions) }}
{% block status %}
{% from "macros/status.html.twig" import status_duration, status_money %}
{{ status_duration(totalDuration|duration) }}
{% for totalCurrency, totalRate in totalRates %}
{{ status_money(totalRate|money(totalCurrency)) }}
{% endfor %}
{% endblock %}
{% block main_before %}
@@ -31,9 +53,9 @@
{% block main %}
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
{% embed '@theme/embeds/card.html.twig' %}
{% import "macros/search.html.twig" as search %}
{% form_theme form '@AdminLTE/layout/form-theme-horizontal.html.twig' %}
{% form_theme form 'form/horizontal.html.twig' %}
{% block box_title %}{{ 'export.filter'|trans }}{% endblock %}
{% block box_before %}{{ form_start(form) }}{% endblock %}
{% block box_body %}
@@ -69,28 +91,13 @@
{% if entries is empty %}
{{ widgets.nothing_found() }}
{% else %}
{% set totalDuration = 0 %}
{% set totalRates = {} %}
{% for row in by_customer %}
{% set totalDuration = totalDuration + row.duration %}
{% set customerCurrency = row.customer.currency %}
{% if totalRates[customerCurrency] is not defined %}
{% set totalRates = totalRates|merge({(customerCurrency): 0.00}) %}
{% endif %}
{% set totalRates = totalRates|merge({(customerCurrency): totalRates[customerCurrency] + row.rate}) %}
{% endfor %}
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
{% embed '@theme/embeds/card.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% block box_title %}
{{ 'button.preview'|trans }}: {{ 'export.title'|trans }}
{{ widgets.label(totalDuration|duration, 'gray') }}
{% for totalCurrency, totalRate in totalRates %}
{{ widgets.label(totalRate|money(totalCurrency), 'gray') }}
{% endfor %}
{{ 'preview'|trans }}
{% endblock %}
{% block box_body_class %}no-padding{% endblock %}
{% block box_attributes %}id="preview_export"{% endblock %}
{% block box_body_class %}p-0{% endblock %}
{% block box_footer %}
{% set buttons = {} %}
{% for button in renderer %}
@@ -102,44 +109,64 @@
{% set group = group|merge([button]) %}
{% set buttons = buttons|merge({(title): group}) %}
{% endfor %}
<div class="btn-group" id="export-buttons" role="group">
{% for group in buttons %}
{% set button = group.0 %}
{% set btnTitle = ('button.' ~ button.title)|trans %}
{% if btnTitle == ('button.' ~ button.title) %}
{% set btnTitle = button.title %}
{% endif %}
{% if group|length == 1 %}
<button type="button" id="export-{{ button.id }}-button" class="btn btn-success startExportBtn" data-type="{{ button.id }}">
{% if showMarkAsExportedButton %}
<div class="d-flex">
<div class="form-check form-switch">
<input type="checkbox" id="markAsExportedCheck" name="markAsExportedCheck" class="form-check-input" value="1" {% if form.markAsExported.vars.value == '1' %} checked="checked"{% endif %}>
<label class="form-check-label" for="markAsExportedCheck">{{ 'mark_as_exported'|trans }}</label>
</div>
</div>
{% endif %}
<div class="d-flex">
<div class="btn-group me-auto" id="export-buttons" role="group">
{% for group in buttons %}
{% set button = group.0 %}
{% set btnTitle = ('button.' ~ button.title)|trans %}
{% if btnTitle == ('button.' ~ button.title) %}
{% set btnTitle = button.title %}
{% endif %}
{% if group|length == 1 %}
<button type="button" id="export-{{ button.id }}-button" class="btn btn-success startExportBtn" data-type="{{ button.id }}">
{{ btnTitle }}
</button>
{% elseif group|length > 1 %}
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ btnTitle }} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
{% for button in group %}
{% elseif group|length > 1 %}
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ btnTitle }}
</button>
<div class="dropdown-menu">
{% for button in group %}
{% set btnTitle = (button.id)|trans({}, 'export') %}
{% if btnTitle == button.id %}
{% set btnTitle = button.id|split('.')|first|replace({'-': ' ', '_': ' '})|split(' ')|map(t => t|capitalize)|join(' ') %}
{% endif %}
<li><a href="#" class="startExportBtn" data-type="{{ button.id }}">{{ btnTitle }}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endfor %}
<a href="#" class="dropdown-item startExportBtn" data-type="{{ button.id }}">{{ btnTitle }}</a>
{% endfor %}
</div>
</div>
{% endif %}
{% endfor %}
</div>
{% if showToggleButton %}
<button id="toggle-button" class="btn ms-auto d-none d-sm-inline-flex">
{% if form.exported.vars.value == '5' %}
{{ icon('off', true) }}
{{ 'mark_as_exported'|trans }}
{% elseif form.exported.vars.value == '4' %}
{{ icon('on', true) }}
{{ 'mark_as_open'|trans }}
{% endif %}
</button>
{% endif %}
</div>
{% endblock %}
{% block box_body %}
<table class="table table-hover dataTable">
<thead>
<tr>
<th>{{ 'label.customer'|trans }}</th>
<th class="w-min text-right hidden-xs">{{ 'label.duration'|trans }}</th>
{# <th class="w-min text-right hidden-xs">{{ 'label.internalRate'|trans }}</th> #}
<th class="w-min text-right">{{ 'label.total_rate'|trans }}</th>
<th>{{ 'customer'|trans }}</th>
<th class="w-min text-end d-none d-sm-table-cell">{{ 'duration'|trans }}</th>
<th class="w-min text-end">{{ 'total_rate'|trans }}</th>
</tr>
</thead>
<tbody>
@@ -149,15 +176,10 @@
<td>
{{ widgets.label_customer(row.customer) }}
</td>
<td class="w-min text-right hidden-xs">
<td class="w-min text-end d-none d-sm-table-cell">
{{ row.duration|duration(decimal) }}
</td>
{#
<td class="w-min text-right hidden-xs">
{{ row.internalRate|money(currency) }}
</td>
#}
<td class="w-min text-right">
<td class="w-min text-end">
{{ row.rate|money(currency) }}
</td>
</tr>
@@ -172,7 +194,7 @@
{% set entries = entries|slice(0, preview_limit) %}
{% endif %}
{{ tables.datatable_header(tableName, columns, query, {}) }}
{{ tables.datatable_header(tableName, columns, query) }}
{% for entry in entries %}
{% set currency = entry.project.customer.currency %}
{% if entry.fixedRate is not null %}
@@ -181,6 +203,9 @@
{% set rate = entry.hourlyRate %}
{% endif %}
<tr>
<td class="{{ tables.data_table_column_class(tableName, columns, 'avatar') }}">
{{ widgets.user_avatar(entry.user) }}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'date') }}">
{{ entry.begin|date_short }}
</td>
@@ -206,27 +231,27 @@
<td class="{{ tables.data_table_column_class(tableName, columns, 'duration') }}" data-duration="{{ entry.duration }}">
{{ entry.duration|duration(decimal) }}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'rate_internal') }}">
<td class="{{ tables.data_table_column_class(tableName, columns, 'internalRate') }}">
{{ entry.internalRate|money(currency) }}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'total_rate') }}">
{{ entry.rate|money(currency) }}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'exported') }}">
<td class="{{ tables.data_table_column_class(tableName, columns, 'actions') }}">
{% if is_granted('edit_export', entry) %}
{% if entry.exported %}
{% if editExported %}
<button type="button" class="btn btn-default exportBtn active" data-toggle="button" aria-pressed="true" autocomplete="off"
data-exported-text="{{ 'entryState.exported'|trans }}" data-clean-text="{{ 'entryState.not_exported'|trans }}" data-timesheet="{{ entry.id }}">
{{ 'entryState.exported'|trans }}
</button>
<button type="button" class="btn btn-outline-secondary exportBtn active" data-toggle="button" aria-pressed="true"
data-exported-text="{{ 'entryState.exported'|trans }}" data-clean-text="{{ 'entryState.not_exported'|trans }}" data-timesheet="{{ entry.id }}">
{{ 'entryState.exported'|trans }}
</button>
{% else %}
{{ 'entryState.exported'|trans }}
{{ 'entryState.exported'|trans }}
{% endif %}
{% else %}
<button type="button" class="btn btn-default exportBtn" data-toggle="button" aria-pressed="false" autocomplete="off"
<button type="button" class="btn btn-light exportBtn" data-toggle="button" aria-pressed="false"
data-exported-text="{{ 'entryState.exported'|trans }}" data-clean-text="{{ 'entryState.not_exported'|trans }}" data-timesheet="{{ entry.id }}">
{{ 'entryState.not_exported'|trans }}
{{ 'entryState.not_exported'|trans }}
</button>
{% endif %}
{% else %}
@@ -253,125 +278,92 @@
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
function confirmToggleState(button)
function updateTimesheetExportState(node, id)
{
var ALERT = kimai.getPlugin('alert');
var message = '{{ 'export.clear_all'|trans }}';
var hasActive = true;
/** @type {KimaiAlert} */
const ALERT = kimai.getPlugin('alert');
/** @type {KimaiAPI} */
const API = kimai.getPlugin('api');
if (!jQuery('#export-toggle-button').hasClass('export-off')) {
message = '{{ 'export.mark_all'|trans }}';
hasActive = false;
}
ALERT.question(message, function(value) {
if (!value) {
return;
}
var btn = jQuery(button);
var exportButtons = jQuery('.exportBtn');
// disabling does not yet work...
if (exportButtons.length > 0) {
btn.addClass('disabled');
}
// ... as the clicks are asynchronous and the each comes back too early ...
exportButtons.each(function () {
if (hasActive === jQuery(this).hasClass('active')) {
jQuery(this).click();
}
});
// ... so the button is re-enabled immediately - that should be fixed in a future update
btn.removeClass('disabled');
if (btn.hasClass('export-off')) {
btn.removeClass('export-off');
btn.html('<i class="fas fa-toggle-off"></i>');
} else {
btn.addClass('export-off');
btn.html('<i class="fas fa-toggle-on"></i>');
}
});
}
function updateTimesheetExportState(button, id, exported)
{
var ALERT = kimai.getPlugin('alert');
// FIXME use Kimai API plugin
$.ajax({
url: '{{ path('export_timesheet', {id: '-s-'}) }}'.replace('-s-', id),
headers: {
'X-AUTH-SESSION': true,
'Content-Type':'application/json'
},
method: 'PATCH',
success: function(data) {
let isShowAll = jQuery('select#exported').val() === '{{ constant('App\\Repository\\Query\\TimesheetQuery::STATE_ALL') }}';
if (exported) {
{% if editExported %}
button.button('exported');
{% else %}
if (isShowAll) {
button.replaceWith('{{ 'entryState.exported'|trans }}');
}
{% endif %}
} else {
button.button('clean');
}
if (!isShowAll) {
button.closest('tr').hide('ease', function() {
jQuery(this).remove();
if(jQuery(this).closest('table').find('tbody tr:visible').length === 0) {
jQuery('#export-buttons button').prop('disabled', true);
}
});
}
}, error: function(jqXHR, textStatus, errorThrown) {
var message = 'An error occured';
if (jqXHR.responseJSON !== undefined) {
message = jqXHR.responseJSON.message;
if (jqXHR.responseJSON.errors !== undefined)
{
var errors = jqXHR.responseJSON.errors.errors;
for (var i = 0; i < errors.length; i++) {
message += ' / ' + errors[i];
}
}
}
ALERT.error('{{ 'action.update.error'|trans({}, 'flashmessages') }}', message);
button.button('reset');
if (exported) {
button.removeClass('active');
} else {
button.addClass('active');
API.patch(
'{{ path('export_timesheet', {id: 1}) }}'.replace('1', id),
{},
function(data) {
const table = node.closest('table')
const row = node.closest('tr');
row.remove();
const list = table.querySelectorAll('tbody tr');
if (list.length === 0) {
document.querySelector('form#export-form button.performSearch').click();
}
}
});
);
}
document.addEventListener('kimai.initialized', function() {
jQuery('body').on('click', '.exportBtn', function() {
var button = jQuery(this);
var id = button.attr('data-timesheet');
updateTimesheetExportState(button, id, !button.hasClass('active'));
});
document.addEventListener('click', function (event) {
const node = event.target;
if (node.matches('.exportBtn')) {
if (node.dataset['timesheet'] !== undefined) {
const id = node.dataset['timesheet'];
updateTimesheetExportState(node, id);
}
}
jQuery('#export-toggle-button').on('click', function () {
confirmToggleState(this);
});
{#
THE GROUP OF EXPORT BUTTONS FOR ALL FORMATS
Toggle the form, because by default it triggers the search
#}
if (node.matches('#export-buttons .startExportBtn')) {
document.getElementById('renderer').value = node.dataset['type'];
const form = document.getElementById("export-form");
const previousAction = form.action;
const previousMethod = form.method;
const previousTarget = form.target;
form.target = '_blank';
form.method = 'POST';
form.action = '{{ path('export_data') }}';
form.submit();
document.getElementById('renderer').value = '';
form.target = previousTarget;
form.method = previousMethod;
form.action = previousAction;
}
}, false);
jQuery('body').on('click', '#export-buttons .startExportBtn', function() {
jQuery('#renderer').val(jQuery(this).attr('data-type'));
var $form = jQuery("#export-form");
var prevAction = $form.attr('action');
var prevMethod = $form.attr('method');
$form.attr('target', '_blank').attr('method', 'POST').attr('action', '{{ path('export_data') }}');
$form.submit();
jQuery('#renderer').val('');
$form.removeAttr('target').attr('action', prevAction).attr('method', prevMethod);
});
{% if showMarkAsExportedButton %}
document.getElementById('markAsExportedCheck').addEventListener('change', function(event) {
document.getElementById('markAsExported').value = event.target.checked ? 1 : 0;
});
{% endif %}
});
{% if showToggleButton %}
function confirmToggleState(doExport)
{
let ALERT = kimai.getPlugin('alert');
let message = '{{ 'export.clear_all'|trans }}';
if (doExport) {
message = '{{ 'export.mark_all'|trans }}';
}
ALERT.question(message, function(value) {
if (!value) {
return;
}
[].slice.call(document.querySelectorAll('.exportBtn')).map(function (element) {
element.click();
});
document.getElementById('toggle-button').classList.add('d-none');
});
}
document.getElementById('toggle-button').addEventListener('click', function (event) {
confirmToggleState({% if form.exported.vars.value == '5' %}true{% else %}false{% endif %});
}, false);
{% endif %}
</script>
{% endblock %}

View File

@@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="{{ asset('bundles/tabler/tabler.css') }}">
{{ encore_entry_link_tags('app') }}
{{ encore_entry_script_tags('app') }}
{% block styles %}{% endblock %}
@@ -17,6 +18,8 @@
{% block export %}{% endblock %}
</section>
</div>
{% block javascripts %}{% endblock %}
{% block javascripts %}
<script src="{{ asset('bundles/tabler/tabler.js') }}"></script>
{% endblock %}
</body>
</html>

View File

@@ -18,61 +18,7 @@
<head>
{% block styles %}
<style>
body {
font-family: sans-serif;
font-size: 10pt;
margin: 0;
padding: 0;
}
p {
margin: 0;
}
table.items {
border: 0.1mm solid #000000;
width: 100%;
font-size: 9pt;
border-collapse: collapse;
}
td, th {
padding: 7px;
}
td {
vertical-align: top;
}
.items td {
border-left: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
.items tr.even {
background-color: #f5f5f5;
}
.items tr.summary {
background-color: #efefef;
}
.items tr.summary td {
font-weight: bold;
border-top: 0.1mm solid #000000;
border-bottom: 0.1mm solid #000000;
}
table thead th {
background-color: #ececec;
border: 0.1mm solid #000000;
font-weight: bold;
font-size: 10pt;
text-align: left;
}
.items td.totals {
font-weight: bold;
border: 0.1mm solid #000000;
}
.items .center,
.items td.duration,
.items td.cost {
text-align: center;
}
.text-nowrap {
white-space: nowrap;
}
{{ encore_entry_css_source('export-pdf')|raw }}
</style>
{% endblock %}
</head>
@@ -86,15 +32,15 @@
{{ 'export.page_of'|trans({'%page%': '{PAGENO}', '%pages%': '{nb}'}) }}
{% if not showUserColumn and query is defined and query.user %}
&ndash;
{{ 'label.user'|trans }}: {{ query.user.displayName }}
{{ 'user'|trans }}: {{ query.user.displayName }}
{% endif %}
</td>
<td align="right">
{% set company = config('theme.branding.company') %}
{% if company is not empty %}
{{ company|raw }} &ndash; {{ now|date_full }}
{{ company }} &ndash; {{ now|date_time }}
{% else %}
{{ 'export.date_copyright'|trans({'%date%': now|date_full, '%kimai%': '<a href="' ~ constant('App\\Constants::HOMEPAGE') ~ '">' ~ constant('App\\Constants::SOFTWARE') ~ '</a>'})|raw }}
{{ 'export.date_copyright'|trans({'%date%': now|date_time, '%kimai%': '<a href="' ~ constant('App\\Constants::HOMEPAGE') ~ '">' ~ constant('App\\Constants::SOFTWARE') ~ '</a>'})|raw }}
{% endif %}
</td>
</tr>
@@ -118,20 +64,20 @@ mpdf-->
<table class="items">
<thead>
<tr>
<th>{{ 'label.customer'|trans }}</th>
<th>{{ 'label.project'|trans }}</th>
<th>{{ 'customer'|trans }}</th>
<th>{{ 'project'|trans }}</th>
{% if showTimeBudget %}
<th class="center">{{ 'label.timeBudget'|trans }}</th>
<th class="center">{{ 'timeBudget'|trans }}</th>
{% endif %}
{% if showRateBudget %}
<th class="center">{{ 'label.budget'|trans }}</th>
<th class="center">{{ 'budget'|trans }}</th>
{% endif %}
<th class="center">{{ 'label.duration'|trans }}</th>
<th class="center">{{ 'duration'|trans }}</th>
{% if showRateColumn %}
{% if showInternalRate %}
<th class="center">{{ 'label.rate_internal'|trans }}</th>
<th class="center">{{ 'internalRate'|trans }}</th>
{% endif %}
<th class="center">{{ 'label.rate'|trans }}</th>
<th class="center">{{ 'rate'|trans }}</th>
{% endif %}
</tr>
</thead>
@@ -268,17 +214,17 @@ mpdf-->
<table class="items">
<thead>
<tr>
<th>{{ 'label.date'|trans }}</th>
<th>{{ 'date'|trans }}</th>
{% if showUserColumn %}
<th>{{ 'label.user'|trans }}</th>
<th>{{ 'user'|trans }}</th>
{% endif %}
<th>{{ 'label.description'|trans }}</th>
<th class="center">{{ 'label.duration'|trans }}</th>
<th>{{ 'description'|trans }}</th>
<th class="center">{{ 'duration'|trans }}</th>
{% if showRateColumn %}
{% if showInternalRate %}
<th class="center">{{ 'label.rate_internal'|trans }}</th>
<th class="center">{{ 'internalRate'|trans }}</th>
{% endif %}
<th class="center">{{ 'label.rate'|trans }}</th>
<th class="center">{{ 'rate'|trans }}</th>
{% endif %}
</tr>
</thead>

View File

@@ -3,7 +3,7 @@
{% import "macros/datatables.html.twig" as tables %}
{% import "macros/webloader.html.twig" as webloader %}
{% block document_title %}{{ 'export.title'|trans }}{% endblock %}
{% block document_title %}{{ 'export'|trans }}{% endblock %}
{% set storageItemName = 'kimai_html_export' %}
@@ -46,9 +46,9 @@
{% set columns = columns|merge({
'hourlyRate': false,
'fixedRate': false,
'duration': 'label.duration',
'rate_internal': 'label.rate_internal',
'rate': 'label.rate',
'duration': 'duration',
'internalRate': 'internalRate',
'rate': 'rate',
}) %}
{% block javascripts %}
@@ -57,20 +57,17 @@
let initialized = false;
document.addEventListener('kimai.initialized', function(event) {
const KIMAI = event.detail.kimai;
const DATES = KIMAI.getPlugin('date');
document.getElementById('duration-decimal').addEventListener('click', function(event) {
let spans = document.getElementsByClassName('duration-format');
for (let span of spans) {
let duration = span.dataset['duration'];
if (duration === undefined) {
continue;
}
var spans = document.getElementsByClassName('duration-format');
for (var span of spans) {
if (!event.target.checked) {
span.innerHTML = DATES.formatSeconds(duration);
if (span.dataset['duration'] !== undefined) {
span.innerHTML = span.dataset['duration'];
}
} else {
span.innerHTML = (new Intl.NumberFormat('{{ app.request.locale|replace({'_': '-'}) }}', {maximumFractionDigits: 2}).format(duration / 3600));
if (span.dataset['durationDecimal'] !== undefined) {
span.innerHTML = span.dataset['durationDecimal'];
}
}
}
saveVisibility();
@@ -122,8 +119,8 @@
}
saveVisibility();
});
document.getElementById('summary-rate-internal').addEventListener('click', function(event) {
let cells = document.getElementsByClassName('summary-rate-internal');
document.getElementById('summary-internalRate').addEventListener('click', function(event) {
let cells = document.getElementsByClassName('summary-internalRate');
for (let columnCell of cells) {
columnCell.style.display = event.target.checked ? 'table-cell' : 'none';
}
@@ -189,7 +186,7 @@
}
} catch (e) {
// ignore error in restoring
console.log('Failed to restore settings, clearing all up: ', e);
console.log('Failed to restore settings, removing invalid settings', e);
localStorage.removeItem('{{ storageItemName }}');
}
}
@@ -261,7 +258,6 @@
h3 { font-size: 18px; }
p, td { font-size: 11px; }
th, td.totals { font-size: 12px; }
table.table-bordered.dataTable { border-collapse: collapse!important; }
}
.items td.totals {
font-weight: bold;
@@ -272,7 +268,7 @@
.items th.cost,
.items td.cost,
.items th.column-rate,
.items th.column-rate_internal,
.items th.column-internalRate,
.items th.column-duration
{
text-align: right;
@@ -284,115 +280,113 @@
{% endblock %}
{% block export %}
<form class="form-inline no-print">
<div class="panel panel-default">
<div class="panel-heading">
{% set formItemClass = "d-inline-block w-auto text-nowrap me-2" %}
<form class="w-100 d-print-none row row-cards p-3">
<div class="card mb-1 p-0">
<div class="card-header">
{{ 'settings'|trans({}, 'actions') }}
</div>
<div class="panel-body">
<label class="control-label" for="duration-decimal">
<div class="card-body">
<label for="duration-decimal">
<input type="checkbox" id="duration-decimal" name="duration-decimal"{% if decimal%} checked="checked"{% endif %}>
{{ 'label.timesheet.export_decimal'|trans }}
{{ 'export_decimal'|trans }}
</label>
|
<label class="control-label" for="date-format">
{{ 'label.date'|trans }}:
<label for="date-format">
{{ 'date'|trans }}:
{% set demo_date = create_date('2020-01-01 20:00:00') %}
<select id="date-format" name="date-format">
<option value="time">{{ demo_date|date_time }}</option>
<option value="short">{{ demo_date|date_short }}</option>
<option value="full">{{ demo_date|date_full }}</option>
<option value="time">{{ demo_date|date_time }}</option>
</select>
</label>
|
<label class="control-label" for="begin-format">
{{ 'label.begin'|trans }}:
<label for="begin-format">
{{ 'begin'|trans }}:
{% set demo_date = create_date('2020-01-01 11:00:00') %}
<select id="begin-format" name="begin-format">
<option value="plain">{{ demo_date|date_format('H:i') }}</option>
<option value="time">{{ demo_date|date_time }}</option>
<option value="short">{{ demo_date|date_short }}</option>
<option value="full">{{ demo_date|date_full }}</option>
<option value="time">{{ demo_date|date_time }}</option>
</select>
</label>
|
<label class="control-label" for="end-format">
{{ 'label.end'|trans }}:
<label for="end-format">
{{ 'end'|trans }}:
{% set demo_date = create_date('2020-01-01 18:00:00') %}
<select id="end-format" name="end-format">
<option value="plain">{{ demo_date|date_format('H:i') }}</option>
<option value="time">{{ demo_date|date_time }}</option>
<option value="short">{{ demo_date|date_short }}</option>
<option value="full">{{ demo_date|date_full }}</option>
<option value="time">{{ demo_date|date_time }}</option>
</select>
</label>
<button type="reset" class="btn btn-primary pull-right" onclick="resetExport()">{{ 'action.reset'|trans }}</button>
<button type="reset" class="btn btn-primary btn-sm pull-right" onclick="resetExport()">{{ 'action.reset'|trans }}</button>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<label class="control-label" for="summary-show">
<div class="card mb-1 p-0">
<div class="card-header">
<label for="summary-show">
<input type="checkbox" id="summary-show" name="summary-show" checked="checked">
{{ 'export.summary'|trans }}
</label>
</div>
<div class="panel-body">
<div class="form-group">
<label class="control-label" for="summary-by-activities">
<div class="card-body w-100">
<div class="{{ formItemClass }}">
<label for="summary-by-activities">
<input type="checkbox" id="summary-by-activities" name="summary-by-activities">
{{ 'label.activity'|trans }}
{{ 'activity'|trans }}
</label>
</div>
<div class="form-group">
<label class="control-label" for="summary-timeBudget">
<div class="{{ formItemClass }}">
<label for="summary-timeBudget">
<input type="checkbox" id="summary-timeBudget" name="summary-timeBudget" checked>
{{ 'label.timeBudget'|trans }}
{{ 'timeBudget'|trans }}
</label>
</div>
<div class="form-group">
<label class="control-label" for="summary-budget">
<div class="{{ formItemClass }}">
<label for="summary-budget">
<input type="checkbox" id="summary-budget" name="summary-budget" checked>
{{ 'label.budget'|trans }}
{{ 'budget'|trans }}
</label>
</div>
<div class="form-group">
<label class="control-label" for="summary-duration">
<div class="{{ formItemClass }}">
<label for="summary-duration">
<input type="checkbox" id="summary-duration" name="summary-duration" checked>
{{ 'label.duration'|trans }}
{{ 'duration'|trans }}
</label>
</div>
<div class="form-group">
<label class="control-label" for="summary-rate-internal">
<input type="checkbox" id="summary-rate-internal" name="summary-rate-internal" checked>
{{ 'label.rate_internal'|trans }}
<div class="{{ formItemClass }}">
<label for="summary-internalRate">
<input type="checkbox" id="summary-internalRate" name="summary-internalRate" checked>
{{ 'internalRate'|trans }}
</label>
</div>
<div class="form-group">
<label class="control-label" for="summary-rate">
<div class="{{ formItemClass }}">
<label for="summary-rate">
<input type="checkbox" id="summary-rate" name="summary-rate" checked>
{{ 'label.rate'|trans }}
{{ 'rate'|trans }}
</label>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<div class="form-group">
<label class="control-label" for="records-show">
<div class="card mb-1 p-0">
<div class="card-header">
<div class="{{ formItemClass }}">
<label for="records-show">
<input type="checkbox" id="records-show" name="records-show" checked="checked">
{{ 'export.full_list'|trans }}
</label>
</div>
</div>
<div class="panel-body">
<div class="card-body">
{% for columnId, visibility in columns %}
<div class="form-group">
<label class="control-label" for="records-column-{{ columnId }}">
<div class="{{ formItemClass }}">
<label for="records-column-{{ columnId }}">
<input type="checkbox" class="column-visibility-changer" id="records-column-{{ columnId }}" name="{{ columnId }}" {% if visibility %}checked="checked"{% endif %}>
{{ columnTitles[columnId]|default('label.'~columnId)|trans }}
{{ columnTitles[columnId]|default(columnId)|trans }}
</label>
</div>
{% endfor %}
@@ -400,7 +394,7 @@
</div>
</form>
<div class="row">
<div class="row m-3">
<div class="col-xs-12">
<h2 id="doc-title" contenteditable="true" data-original="{{ 'export.document_title'|trans }}">{{ 'export.document_title'|trans }}</h2>
<p>
@@ -410,19 +404,21 @@
</div>
</div>
<div class="row" id="export-summary">
<div class="col-xs-12">
<h3 id="doc-summary" contenteditable="true" data-original="{{ 'export.summary'|trans }}">{{ 'export.summary'|trans }}</h3>
<table class="items table table-condensed table-bordered dataTable" id="summary-project">
<div class="row m-3" id="export-summary">
<div class="card p-0">
<div class="card-header">
<h3 class="card-title" id="doc-summary" contenteditable="true" data-original="{{ 'export.summary'|trans }}">{{ 'export.summary'|trans }}</h3>
</div>
<table class="items table table-sm table-bordered dataTable" id="summary-project">
<thead>
<tr>
<th>{{ 'label.customer'|trans }}</th>
<th>{{ 'label.project'|trans }}</th>
<th class="center export-timeBudget">{{ 'label.timeBudget'|trans }}</th>
<th class="center export-budget">{{ 'label.budget'|trans }}</th>
<th class="duration summary-duration">{{ 'label.duration'|trans }}</th>
<th class="cost summary-rate-internal">{{ 'label.rate_internal'|trans }}</th>
<th class="cost summary-rate">{{ 'label.rate'|trans }}</th>
<th>{{ 'customer'|trans }}</th>
<th>{{ 'project'|trans }}</th>
<th class="center export-timeBudget">{{ 'timeBudget'|trans }}</th>
<th class="center export-budget">{{ 'budget'|trans }}</th>
<th class="duration summary-duration">{{ 'duration'|trans }}</th>
<th class="cost summary-internalRate">{{ 'internalRate'|trans }}</th>
<th class="cost summary-rate">{{ 'rate'|trans }}</th>
</tr>
</thead>
<tbody>
@@ -437,14 +433,16 @@
{% set customerCurrency = summary.currency %}
{% endif %}
{% if customer is not same as(summary.customer) %}
{% set durationNormal = customerDuration|duration(false) %}
{% set durationDecimal = customerDuration|duration(true) %}
<tr class="summary">
<td colspan="2">&nbsp;</td>
<td class="export-timeBudget"></td>
<td class="export-budget"></td>
<td class="totals duration summary-duration">
<span class="duration-format" data-duration="{{ customerDuration }}">{{ customerDuration|duration(decimal) }}</span>
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
</td>
<td class="totals cost summary-rate-internal">{{ customerInternalRate|money(customerCurrency) }}</td>
<td class="totals cost summary-internalRate">{{ customerInternalRate|money(customerCurrency) }}</td>
<td class="totals cost summary-rate">{{ customerRate|money(customerCurrency) }}</td>
</tr>
{% set customerCurrency = summary.currency %}
@@ -458,7 +456,9 @@
<td>{{ summary.project }}</td>
<td class="center export-timeBudget">
{% if budgets[id] is defined and budgets[id].time_left > 0 %}
<span class="duration-format" data-duration="{{ budgets[id].time_left }}">{{ budgets[id].time_left|duration(decimal) }}</span>
{% set durationNormal = budgets[id].time_left|duration(false) %}
{% set durationDecimal = budgets[id].time_left|duration(true) %}
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
{% endif %}
</td>
<td class="center export-budget">
@@ -467,9 +467,11 @@
{% endif %}
</td>
<td class="duration summary-duration">
<span class="duration-format" data-duration="{{ summary.duration }}">{{ summary.duration|duration(decimal) }}</span>
{% set durationNormal = summary.duration|duration(false) %}
{% set durationDecimal = summary.duration|duration(true) %}
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
</td>
<td class="cost summary-rate-internal">{{ summary.rate_internal|money(summary.currency) }}</td>
<td class="cost summary-internalRate">{{ summary.rate_internal|money(summary.currency) }}</td>
<td class="cost summary-rate">{{ summary.rate|money(summary.currency) }}</td>
</tr>
{% set customerDuration = customerDuration + summary.duration %}
@@ -477,14 +479,16 @@
{% set customerInternalRate = customerInternalRate + summary.rate_internal %}
{% endfor %}
{% if customer is not same as(null) %}
{% set durationNormal = customerDuration|duration(false) %}
{% set durationDecimal = customerDuration|duration(true) %}
<tr class="summary">
<td colspan="2">&nbsp;</td>
<td class="export-timeBudget"></td>
<td class="export-budget"></td>
<td class="totals duration summary-duration">
<span class="duration-format" data-duration="{{ customerDuration }}">{{ customerDuration|duration(decimal) }}</span>
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
</td>
<td class="totals cost summary-rate-internal">{{ customerInternalRate|money(customerCurrency) }}</td>
<td class="totals cost summary-internalRate">{{ customerInternalRate|money(customerCurrency) }}</td>
<td class="totals cost summary-rate">{{ customerRate|money(customerCurrency) }}</td>
</tr>
{% endif %}
@@ -497,17 +501,17 @@
============================================
#}
<table class="items table table-condensed table-bordered dataTable" id="summary-activity" style="display:none">
<table class="items table table-sm table-bordered dataTable" id="summary-activity" style="display:none">
<thead>
<tr>
<th>{{ 'label.customer'|trans }}</th>
<th>{{ 'label.project'|trans }}</th>
<th>{{ 'label.activity'|trans }}</th>
<th class="center export-timeBudget">{{ 'label.timeBudget'|trans }}</th>
<th class="center export-budget">{{ 'label.budget'|trans }}</th>
<th class="duration summary-duration">{{ 'label.duration'|trans }}</th>
<th class="cost summary-rate-internal">{{ 'label.rate_internal'|trans }}</th>
<th class="cost summary-rate">{{ 'label.rate'|trans }}</th>
<th>{{ 'customer'|trans }}</th>
<th>{{ 'project'|trans }}</th>
<th>{{ 'activity'|trans }}</th>
<th class="center export-timeBudget">{{ 'timeBudget'|trans }}</th>
<th class="center export-budget">{{ 'budget'|trans }}</th>
<th class="duration summary-duration">{{ 'duration'|trans }}</th>
<th class="cost summary-internalRate">{{ 'internalRate'|trans }}</th>
<th class="cost summary-rate">{{ 'rate'|trans }}</th>
</tr>
</thead>
<tbody>
@@ -527,9 +531,11 @@
<td class="export-timeBudget"></td>
<td class="export-budget"></td>
<td class="totals duration summary-duration">
<span class="duration-format" data-duration="{{ customerDuration }}">{{ customerDuration|duration(decimal) }}</span>
{% set durationNormal = customerDuration|duration(false) %}
{% set durationDecimal = customerDuration|duration(true) %}
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
</td>
<td class="totals cost summary-rate-internal">{{ customerInternalRate|money(customerCurrency) }}</td>
<td class="totals cost summary-internalRate">{{ customerInternalRate|money(customerCurrency) }}</td>
<td class="totals cost summary-rate">{{ customerRate|money(customerCurrency) }}</td>
</tr>
{% set customerCurrency = summary.currency %}
@@ -546,7 +552,9 @@
{% if activity_budgets[id] is defined and activity_budgets[id][activityId] is defined %}
<td class="center export-timeBudget">
{% if activity_budgets[id][activityId].time_left > 0 %}
<span class="duration-format" data-duration="{{ activity_budgets[id][activityId].time_left }}">{{ activity_budgets[id][activityId].time_left|duration(decimal) }}</span>
{% set durationNormal = activity_budgets[id][activityId].time_left|duration(false) %}
{% set durationDecimal = activity_budgets[id][activityId].time_left|duration(true) %}
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
{% endif %}
</td>
<td class="center export-budget">
@@ -559,9 +567,11 @@
<td class="center export-budget"></td>
{% endif %}
<td class="duration summary-duration">
<span class="duration-format" data-duration="{{ activitySummary.duration }}">{{ activitySummary.duration|duration(decimal) }}</span>
{% set durationNormal = activitySummary.duration|duration(false) %}
{% set durationDecimal = activitySummary.duration|duration(true) %}
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
</td>
<td class="cost summary-rate-internal">{{ activitySummary.rate_internal|money(activitySummary.currency) }}</td>
<td class="cost summary-internalRate">{{ activitySummary.rate_internal|money(activitySummary.currency) }}</td>
<td class="cost summary-rate">{{ activitySummary.rate|money(activitySummary.currency) }}</td>
</tr>
{% endfor %}
@@ -575,9 +585,11 @@
<td class="export-timeBudget"></td>
<td class="export-budget"></td>
<td class="totals duration summary-duration">
<span class="duration-format" data-duration="{{ customerDuration }}">{{ customerDuration|duration(decimal) }}</span>
{% set durationNormal = customerDuration|duration(false) %}
{% set durationDecimal = customerDuration|duration(true) %}
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
</td>
<td class="totals cost summary-rate-internal">{{ customerInternalRate|money(customerCurrency) }}</td>
<td class="totals cost summary-internalRate">{{ customerInternalRate|money(customerCurrency) }}</td>
<td class="totals cost summary-rate">{{ customerRate|money(customerCurrency) }}</td>
</tr>
{% endif %}
@@ -586,18 +598,20 @@
</div>
</div>
<div class="row" id="export-records">
<div class="col-xs-12">
<h3 id="doc-records" contenteditable="true" data-original="{{ 'export.full_list'|trans }}">{{ 'export.full_list'|trans }}</h3>
<table class="items table table-condensed table-bordered dataTable">
<div class="row m-3" id="export-records">
<div class="card p-0">
<div class="card-header">
<h3 class="card-title" id="doc-records" contenteditable="true" data-original="{{ 'export.full_list'|trans }}">{{ 'export.full_list'|trans }}</h3>
</div>
<table class="items table table-sm table-bordered dataTable">
<thead>
<tr>
{% for columnId, visibility in columns %}
<th class="column column-{{ columnId }}" {% if not visibility %}style="display: none"{% endif %}>
{{ columnTitles[columnId]|default('label.'~columnId)|trans }}
</th>
{% endfor %}
</tr>
<tr>
{% for columnId, visibility in columns %}
<th class="column column-{{ columnId }}" {% if not visibility %}style="display: none"{% endif %}>
{{ columnTitles[columnId]|default(columnId)|trans }}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% set timeWorked = 0 %}
@@ -620,17 +634,17 @@
{% endif %}
<tr>
<td class="column-date text-nowrap" {% if not columns.date %}style="display: none"{% endif %}>
<span class="dateformat" data-short="{{ entry.begin|date_short }}" data-full="{{ entry.begin|date_full }}" data-time="{{ entry.begin|date_time }}">
<span class="dateformat" data-short="{{ entry.begin|date_short }}" data-full="{{ entry.begin|date_time }}" data-time="{{ entry.begin|date_time }}">
{{ entry.begin|date_time }}
</span>
</td>
<td class="column-begin text-nowrap" {% if not columns.begin %}style="display: none"{% endif %}>
<span class="beginformat" data-short="{{ entry.begin|date_short }}" data-full="{{ entry.begin|date_full }}" data-time="{{ entry.begin|date_time }}" data-plain="{{ entry.begin|date_format('H:i') }}">
<span class="beginformat" data-short="{{ entry.begin|date_short }}" data-full="{{ entry.begin|date_time }}" data-time="{{ entry.begin|date_time }}" data-plain="{{ entry.begin|date_format('H:i') }}">
{{ entry.begin|date_format('H:i') }}
</span>
</td>
<td class="column-end text-nowrap" {% if not columns.end %}style="display: none"{% endif %}>
<span class="endformat" data-short="{{ entry.end|date_short }}" data-full="{{ entry.end|date_full }}" data-time="{{ entry.end|date_time }}" data-plain="{{ entry.end|date_format('H:i') }}">
<span class="endformat" data-short="{{ entry.end|date_short }}" data-full="{{ entry.end|date_time }}" data-time="{{ entry.end|date_time }}" data-plain="{{ entry.end|date_format('H:i') }}">
{{ entry.end|date_format('H:i') }}
</span>
</td>
@@ -701,9 +715,11 @@
{{ entry.fixedRate|money(entry.project.customer.currency) }}
</td>
<td class="duration column-duration text-nowrap" {% if not columns.duration %}style="display: none"{% endif %}>
<span class="duration-format" data-duration="{{ entry.duration }}">{{ entry.duration|duration(decimal) }}</span>
{% set durationNormal = entry.duration|duration(false) %}
{% set durationDecimal = entry.duration|duration(true) %}
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
</td>
<td class="cost column-rate_internal text-nowrap" {% if not columns.rate_internal %}style="display: none"{% endif %}>
<td class="cost column-internalRate text-nowrap" {% if not columns.internalRate %}style="display: none"{% endif %}>
{% if entry.internalRate is defined %}
{{ entry.internalRate|money(entry.project.customer.currency) }}
{% else %}
@@ -718,14 +734,16 @@
{# leave in tbody instead of adding it to tfoot, as tfoot will be repeated on each page when printing #}
<tr>
{% for id, visibility in columns %}
{% if id not in ['duration', 'rate', 'rate_internal'] %}
{% if id not in ['duration', 'rate', 'internalRate'] %}
<th class="column-{{ id }}" {% if not visibility %}style="display: none"{% endif %}></th>
{% endif %}
{% endfor %}
<th class="text-nowrap column-duration">
<span class="duration-format" data-duration="{{ timeWorked }}">{{- timeWorked|duration(decimal) -}}</span>
{% set durationNormal = timeWorked|duration(false) %}
{% set durationDecimal = timeWorked|duration(true) %}
<span class="duration-format" data-duration-decimal="{{ durationDecimal }}" data-duration="{{ durationNormal }}">{{ decimal ? durationDecimal : durationNormal }}</span>
</th>
<th class="text-nowrap column-rate_internal">
<th class="text-nowrap column-internalRate">
{%- if currency is not null and currency is not same as(false) %}
{{ rateInternalTotal|money(currency) }}
{% else %}