{% extends 'reporting/layout.html.twig' %} {% import "macros/charts.html.twig" as charts %} {% import "macros/widgets.html.twig" as widgets %} {% block report_title %}{{ 'report_project_details'|trans({}, 'reporting') }}{% endblock %} {% set tableName = tableName|default('project_details_reporting') %} {% set tableId = 'project-details-form' %} {% set showMoneyBudget = project_details is not null and is_granted('budget', project_details.project) %} {% set showTimeBudget = project_details is not null and is_granted('time', project_details.project) %} {% set view_revenue = project_details is not null and is_granted('view_rate_other_timesheet') %} {% set see_users = is_granted('view_other_timesheet') or is_granted('view_other_reporting') %} {% block stylesheets %} {{ parent() }} {{ encore_entry_link_tags('chart') }} {% endblock %} {% block head %} {{ parent() }} {{ encore_entry_script_tags('chart') }} {% endblock %} {% block javascripts %} {{ parent() }} {% set options = {'label': 'duration', 'title': 'name', 'legend': 'false'} %} {% if view_revenue %} {% set options = options|merge({'footer': 'rate'}) %} {% endif %} {{ charts.doughnut_javascript(options) }} {{ charts.bar_javascript({'legend': 'false'}) }} {% endblock %} {% block report %} {% set hasData = project is not null and project_view is not null %} {% embed '@AdminLTE/Widgets/box-widget.html.twig' %} {% import "macros/widgets.html.twig" as widgets %} {% block box_before %} {{ form_start(form, {'attr': {'class': 'form-inline form-reporting', 'id': tableId}}) }} {% endblock %} {% block box_after %} {{ form_end(form) }} {% endblock %} {% block box_title %} {{ form_widget(form) }} {% endblock %} {% block box_body %}{% endblock %} {% block box_body_class %}hidden{% endblock %} {% endembed %} {% if not hasData %} {{ widgets.nothing_found() }} {% endif %} {% if hasData %} {{ _self.project_details(project, project_view, project_details, showMoneyBudget, showTimeBudget, view_revenue, see_users) }} {% set currency = project.customer.currency %} {%- for yearStat in project_details.years|reverse %} {% set year = yearStat.year %} {{ _self.duration_stat(year, year, year, month_names(), yearStat, project_details.getYearActivities(year), project_details.userYears(year), currency, view_revenue, see_users) }} {% endfor %} {% endif %} {% endblock %} {% macro duration_stat(id, title, year, labels, yearStat, activities, users, currency, view_revenue, see_users) %} {% set rates = [] %} {% set durations = [] %} {% set chartPrefix = 'chart' ~ id %} {% for monthNumber in 1..12 %} {% set rate = 0 %} {% set duration = 0 %} {% set month = yearStat.month(monthNumber) %} {% if month is not null %} {% set rate = month.totalRate %} {% set duration = month.totalDuration %} {% endif %} {% set durations = durations|merge([{'label': duration|duration, 'value': duration|chart_duration}]) %} {% set rates = rates|merge([{'label': rate|money(currency), 'value': rate}]) %} {% endfor -%} {% endmacro %} {% macro user_tab(year, userYearStats) %}
{% for monthName in month_names() %} {% endfor %} {% set yearTotal = 0 %} {% for userYearStat in userYearStats|sort((a, b) => b.duration <=> a.duration) %} {% set user = userYearStat.user %} {% set userYear = userYearStat.year %} {% set userTotal = userYearStat.duration %} {% set yearTotal = yearTotal + userTotal %} {% for monthNumber in 1..12 %} {% set month = userYear.getMonth(monthNumber) %} {% endfor %} {% endfor %} {% for monthNumber in 1..12 %} {% set total = 0 %} {% for userYearStat in userYearStats %} {% set month = userYearStat.year.getMonth(monthNumber) %} {% if month is not null %} {% set total = total + month.duration %} {% endif %} {% endfor %} {% endfor %}
{{ 'label.username'|trans }} {{ monthName }}
{{ widgets.label_dot(user.displayName, user.color) }} {{ userTotal|duration }} {% if month is not null %} {{ month.totalDuration|duration }} {% endif %}
{{ yearTotal|duration }} {{ total|duration }}
{% endmacro %} {# activities = array totalDuration = int currency = string chartPrefix = string view_revenue = boolean #} {% macro activity_tab(activities, totalDuration, currency, chartPrefix, view_revenue) %} {% set dataset = [] %} {% set labels = [] %}
{% for stat in activities|sort((a, b) => b.duration <=> a.duration) %} {% set dataset = dataset|merge([{'value': stat.duration, 'name': stat.name, 'color': stat.activity.color|colorize(stat.activity.name), 'duration': stat.duration|duration, 'rate': stat.rate|money(currency)}]) %} {% set percentage = 0 %} {% if totalDuration > 0 and stat.duration > 0 %} {% set percentage = (100 / (totalDuration / stat.duration)) %} {% endif %} {% if view_revenue %} {% endif %} {% endfor %}
{{ widgets.label_activity(stat.activity, {'inherit': false, 'random': true}) }} {{ stat.duration|duration }}{{ stat.rate|money(currency) }}{{ percentage|number_format(1) }} %
{% set chartOptions = {'height': (dataset|length > 12 ? '600px' : '300px'), 'legend': {'position': (dataset|length > 12 ? 'top' : 'right')}, 'renderEvent': 'render.' ~ chartPrefix ~ 'Activity'} %} {{ charts.doughnut_chart(chartPrefix ~ 'Activity', labels, dataset, chartOptions) }}
{% endmacro %} {# project = Project project_view = ProjectViewModel project_details = ProjectDetailsModel #} {% macro project_details(project, project_view, project_details, showMoneyBudget, showTimeBudget, view_revenue, see_users) %} {% set activities = project_details.activities %} {% set years = project_details.years %} {% import "macros/progressbar.html.twig" as progress %} {% import "macros/widgets.html.twig" as widgets %} {% import "macros/charts.html.twig" as charts %} {% set currency = project.customer.currency %} {% set chartPrefix = 'project' ~ project.id %} {%- set labels = [] %} {% set rates = [] %} {% set durations = [] %} {% for year in years %} {% set labels = labels|merge([year.year]) %} {% set rates = rates|merge([{'label': year.rate|money(currency), 'value': year.rate}]) %} {% set durations = durations|merge([{'label': year.duration|duration, 'value': year.duration|chart_duration}]) %} {% endfor -%} {% endmacro %}