Budget graph in project details (#3406)
* do not copy description if restarting via calendar * added support to display negative durations * fix charts for larger numbers
This commit is contained in:
86
templates/project/charts.html.twig
Normal file
86
templates/project/charts.html.twig
Normal file
@@ -0,0 +1,86 @@
|
||||
{# project \App\Entity\Project #}
|
||||
{# details \App\Reporting\ProjectDetails\ProjectDetailsModel #}
|
||||
{% macro project_budget(project, details, prefix) %}
|
||||
{% set chartPrefix = (prefix is null ? random() : prefix) ~ 'Budget' %}
|
||||
{% set chart = is_granted('budget', project) %}
|
||||
{% set showMoneyBudget = is_granted('budget', project) and project.hasBudget() %}
|
||||
{% set showTimeBudget = is_granted('time', project) and project.hasTimeBudget() %}
|
||||
{% if showMoneyBudget or showTimeBudget %}
|
||||
{% from "macros/charts.html.twig" import bar_chart %}
|
||||
{% set currency = project.customer.currency %}
|
||||
{% if project.isMonthlyBudget() %}
|
||||
<h4>
|
||||
{%- if showMoneyBudget %}{{ 'label.budget'|trans }}{% else %}{{ 'label.timeBudget'|trans }}{% endif -%}
|
||||
: {{ 'label.budgetType_month'|trans }}
|
||||
</h4>
|
||||
{% set chartData = [] %}
|
||||
{% set chartLabels = [] %}
|
||||
{# year \App\Model\Statistic\Year #}
|
||||
{% for year in details.years %}
|
||||
{# month \App\Model\Statistic\Month #}
|
||||
{% for month in year.months %}
|
||||
{% set monthDate = date(year.year ~ '-' ~ month.month ~ '-01 00:00:00') %}
|
||||
{% if project.end is null or monthDate < project.end %}
|
||||
{% set totalBudget = project.getTimeBudget() - month.billableDuration %}
|
||||
{% set projectBudget = project.getTimeBudget() %}
|
||||
{% if showMoneyBudget %}
|
||||
{% set totalBudget = project.getBudget() - month.billableRate %}
|
||||
{% set projectBudget = project.getBudget() %}
|
||||
{% endif %}
|
||||
{% set chartLabels = chartLabels|merge([monthDate|month_name ~ ' ' ~ year.year]) %}
|
||||
{% set chartValue = {
|
||||
'label': (showMoneyBudget ? totalBudget|money(currency) : totalBudget|duration),
|
||||
'value': '' ~ (showMoneyBudget ? totalBudget|chart_money : totalBudget|chart_duration),
|
||||
} %}
|
||||
{% if totalBudget < 0 %}
|
||||
{% set chartValue = chartValue|merge({'color': 'red'}) %}
|
||||
{% endif %}
|
||||
{% if totalBudget == projectBudget %}
|
||||
{% set chartValue = chartValue|merge({'color': 'green'}) %}
|
||||
{% endif %}
|
||||
{% set chartData = chartData|merge([chartValue]) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{{ bar_chart(chartPrefix, chartLabels, [chartData], {'height': '300px', 'renderEvent': 'render.' ~ chartPrefix}) }}
|
||||
{% else %}
|
||||
<h4>
|
||||
{%- if showMoneyBudget %}{{ 'label.budget'|trans }}{% else %}{{ 'label.timeBudget'|trans }}{% endif -%}
|
||||
</h4>
|
||||
{% set chartData = [] %}
|
||||
{% set chartLabels = [] %}
|
||||
{% if showMoneyBudget %}
|
||||
{% set totalBudget = project.getBudget() %}
|
||||
{% else %}
|
||||
{% set totalBudget = project.getTimeBudget() %}
|
||||
{% endif %}
|
||||
{# year \App\Model\Statistic\Year #}
|
||||
{% for year in details.years %}
|
||||
{# month \App\Model\Statistic\Month #}
|
||||
{% for month in year.months %}
|
||||
{% set monthDate = date(year.year ~ '-' ~ month.month ~ '-01') %}
|
||||
{% if project.end is null or monthDate < project.end %}
|
||||
{% if showMoneyBudget %}
|
||||
{% set totalBudget = totalBudget - month.billableRate %}
|
||||
{% else %}
|
||||
{% set totalBudget = totalBudget - month.billableDuration %}
|
||||
{% endif %}
|
||||
{% set chartLabels = chartLabels|merge([monthDate|month_name ~ ' ' ~ year.year]) %}
|
||||
{% set chartValue = {
|
||||
'label': (showMoneyBudget ? totalBudget|money(currency) : totalBudget|duration),
|
||||
'value': (showMoneyBudget ? totalBudget|chart_money : totalBudget|chart_duration),
|
||||
} %}
|
||||
{# line chart do not support coloring negative areas #}
|
||||
{#
|
||||
{% if totalBudget < 0 %}
|
||||
{% set chartValue = chartValue|merge({'color': 'red'}) %}
|
||||
{% endif %}
|
||||
#}
|
||||
{% set chartData = chartData|merge([chartValue]) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{{ bar_chart(chartPrefix, chartLabels, [chartData], {'height': '300px', 'renderEvent': 'render.' ~ chartPrefix, 'type': 'line'}) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
@@ -34,6 +34,9 @@
|
||||
jQuery('#{{ tableId }}').on('change', function(ev) {
|
||||
jQuery(this).submit();
|
||||
});
|
||||
{% if project is not null %}
|
||||
renderChart('project{{ project.id }}Budget');
|
||||
{% endif %}
|
||||
});
|
||||
|
||||
jQuery('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||
@@ -296,6 +299,14 @@
|
||||
{{ widgets.label_customer(project.customer) }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr {{ widgets.project_row_attr(project) }}>
|
||||
<th class="w-min">
|
||||
{{ 'label.project'|trans }}
|
||||
</th>
|
||||
<td>
|
||||
{{ widgets.label_project(project) }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-min">
|
||||
{{ 'stats.durationTotal'|trans }}
|
||||
@@ -309,11 +320,13 @@
|
||||
</th>
|
||||
<td>{{ project_view.rateTotal|money(currency) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-min">
|
||||
{{ 'label.billable'|trans }}
|
||||
</th>
|
||||
<td>{{ project_view.billableRate|money(currency) }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<table class="table table-hover dataTable">
|
||||
<tr>
|
||||
<th class="w-min">
|
||||
{{ 'label.last_record'|trans }}
|
||||
@@ -352,13 +365,19 @@
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
{% if (showMoneyBudget and project.hasBudget()) or (showTimeBudget and project.hasTimeBudget()) %}
|
||||
{% from "project/charts.html.twig" import project_budget %}
|
||||
{{ project_budget(project, project_details, chartPrefix) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% if (showMoneyBudget and project.budget > 0) or (showTimeBudget and project.timeBudget > 0) %}
|
||||
{% if (showMoneyBudget and project.hasBudget()) or (showTimeBudget and project.hasTimeBudget()) %}
|
||||
{% set budgetStats = project_details.budgetStatisticModel %}
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<table class="table table-hover dataTable">
|
||||
{% if showTimeBudget and project.timeBudget > 0 %}
|
||||
{% if showTimeBudget and project.hasTimeBudget() %}
|
||||
<tr>
|
||||
<th class="w-min">
|
||||
{{ 'label.timeBudget'|trans }}
|
||||
@@ -371,7 +390,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if showMoneyBudget and project.budget > 0 %}
|
||||
{% if showMoneyBudget and project.hasBudget() %}
|
||||
<tr>
|
||||
<th class="w-min">
|
||||
{{ 'label.budget'|trans }}
|
||||
|
||||
Reference in New Issue
Block a user