From bed3ade2217186daf0949ef936158193e269f136 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Fri, 14 May 2021 11:45:03 +0200 Subject: [PATCH] Improve progressbar values in report (#2569) --- templates/macros/progressbar.html.twig | 53 ++++++++++++++++++++++ templates/reporting/project_view.html.twig | 21 ++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/templates/macros/progressbar.html.twig b/templates/macros/progressbar.html.twig index 81ec49e8..c65b3106 100644 --- a/templates/macros/progressbar.html.twig +++ b/templates/macros/progressbar.html.twig @@ -1,3 +1,56 @@ +{% macro progressbar_full(options) %} + {% set max = options['max'] ?? 0 %} + {% set current = options['current'] ?? 0 %} + {% set open = options['open'] ?? null %} + {% set reverseColors = options['reverseColors'] ?? false %} + {% set formatter = options['format'] ?? null %} + {% set currency = options['currency'] ?? null %} + {% set percentDecimals = options['decimals'] ?? 1 %} + {% if formatter == 'duration' %} + {% set currentFormatted = current|duration %} + {% set maxFormatted = max|duration %} + {% set openFormatted = open is not null ? open|duration : null %} + {% elseif formatter == 'money' and currency is not null %} + {% set currentFormatted = current|money(currency) %} + {% set maxFormatted = max|money(currency) %} + {% set openFormatted = open is not null ? open|money(currency) : null %} + {% else %} + {% set currentFormatted = current %} + {% set maxFormatted = max %} + {% set openFormatted = open is not null ? open : null %} + {% endif %} + {% set percentReached = 0 %} + {% if max > 0 %} + {% set percentReached = (current / (max / 100)) %} + {% endif %} + {% set width = percentReached|number_format(1, '.', '') %} + + {% if width > 100 %} + {% set width = 100 %} + {% endif %} + +
+
+ + {{ currentFormatted }} + + + + {{ maxFormatted }} + + +
+
+
+
+ {% if open is not null and open > 0 %} + {{ 'stats.percentUsedLeft'|trans({'%percent%': percentReached|number_format(percentDecimals), '%left%': openFormatted}) }} + {% else %} + {{ 'stats.percentUsed'|trans({'%percent%': percentReached|number_format(percentDecimals)}) }} + {% endif %} +
+{% endmacro %} + {% macro progressbar(max, current, title, subTitle, reverseColors) %} {% set percentReached = 0 %} {% if max > 0 %} diff --git a/templates/reporting/project_view.html.twig b/templates/reporting/project_view.html.twig index e9303eeb..225ea1fa 100644 --- a/templates/reporting/project_view.html.twig +++ b/templates/reporting/project_view.html.twig @@ -14,6 +14,7 @@ 'budget': {'class': 'hidden-xs', 'title': 'label.budget'|trans}, 'stateDuration': {'class': 'hidden-sm hidden-xs text-center hw-min', 'title': 'label.not_exported'|trans}, 'stateMoney': {'class': 'hidden-sm hidden-xs text-center hw-min', 'title': 'label.not_invoiced'|trans}, + 'projectStart': {'class': 'hidden-md hidden-sm hidden-xs hidden text-center w-min', 'title': 'label.project_start'|trans}, 'projectEnd': {'class': 'hidden-md hidden-sm hidden-xs hidden text-center w-min', 'title': 'label.project_end'|trans}, 'comment': {'class': 'hidden-md hidden-sm hidden-xs hidden', 'title': 'label.comment'|trans}, 'actions': {'class': 'actions alwaysVisible'}, @@ -75,12 +76,27 @@ {{ entry.durationTotal|duration }} {% if project.timeBudget > 0 %} - {{ progress.progressbar(project.timeBudget, entry.billableDuration|default(0), entry.billableDuration|duration ~ ' / ' ~ project.timeBudget|duration, '') }} + {% set timeBudgetLeft = project.timeBudget - entry.billableDuration %} + {% set options = { + 'max': project.timeBudget|default(0), + 'current': entry.billableDuration|default(0), + 'open': timeBudgetLeft, + 'format': 'duration' + } %} + {{ progress.progressbar_full(options) }} {% endif %} {% if project.budget > 0 %} - {{ progress.progressbar(project.budget, entry.billableRate|default(0), entry.billableRate|money(currency) ~ ' / ' ~ project.budget|money(currency), '') }} + {% set budgetLeft = project.budget - entry.billableRate %} + {% set options = { + 'max': project.budget|default(0), + 'current': entry.billableRate|default(0), + 'open': budgetLeft, + 'format': 'money', + 'currency': currency + } %} + {{ progress.progressbar_full(options) }} {% endif %} @@ -101,6 +117,7 @@ {{ entry.notBilledRate|money(currency) }} {% endif %} + {% if project.start is not null %}{{ project.start|date_short }}{% endif %} {% if project.end is not null %}{{ project.end|date_short }}{% endif %} {{ project.comment }}