Subversion Repositories web.kimai2

Rev

Blame | Last modification | View Log | Download

{% 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 %}
    {% set transPercentOpen = options['trans_percent_open'] ?? 'stats.percentUsedLeft' %}
    {% set transPercentSpent = options['trans_percent_spent'] ?? 'stats.percentUsed' %}
    {% set outerClass = options['class'] ?? '' %}
    {% 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 %}

    <div class="progress-group {{ outerClass }}">
        <div class="progress-title">
            <span class="progress-text">
                {{ currentFormatted }}
            </span>
            <span class="progress-number text-end">
                <strong>
                    {{ maxFormatted }}
                </strong>
            </span>
        </div>
        <div class="progress">
            <div class="progress-bar {{ progressbar_color(percentReached, reverseColors) }}" role="progressbar" aria-valuenow="{{ width }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width }}%"></div>
        </div>
        {% if open is not null and open > 0 %}
            <small>{{ transPercentOpen|trans({'%percent%': percentReached|number_format(percentDecimals), '%left%': openFormatted}) }}</small>
        {% else %}
            <small>{{ transPercentSpent|trans({'%percent%': percentReached|number_format(percentDecimals)}) }}</small>
        {% endif %}
    </div>
{% endmacro %}

{% macro progressbar(max, current, title, subTitle, reverseColors) %}
    {% 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 %}

    <div class="progress-group">
        <div class="progress-title">
            <span class="progress-text">
                {{ title }}
                {% if percentReached >= 0 and subTitle is not empty %} &ndash; {{ percentReached|number_format(2) }}%{% endif %}
            </span>
            <span class="progress-number text-end">
                {% if percentReached >= 0 and subTitle is empty %}
                    {{ percentReached|number_format(2) }}%
                {% elseif subTitle is not empty %}
                    {{ subTitle }}
                {% endif %}
            </span>
        </div>
        <div class="progress">
            <div class="progress-bar {{ progressbar_color(percentReached, reverseColors) }}" role="progressbar" aria-valuenow="{{ width }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width }}%"></div>
        </div>
    </div>
{% endmacro %}

{% macro progressbar_small(max, current, leftValue, leftFormatted, reverseColors) %}
    {% 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 %}

    <div class="progress-group">
        <div class="progress progress-sm">
            <div class="progress-bar {{ progressbar_color(percentReached, reverseColors) }}" role="progressbar" aria-valuenow="{{ width }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width }}%"></div>
        </div>
        {% if leftValue is not null and leftValue > 0 %}
            <small>{{ 'stats.percentUsedLeft'|trans({'%percent%': percentReached|number_format(0), '%left%': leftFormatted}) }}</small>
        {% else %}
            <small>{{ 'stats.percentUsed'|trans({'%percent%': percentReached|number_format(0)}) }}</small>
        {% endif %}
    </div>
{% endmacro %}

{#
    @param \App\Model\BudgetStatisticModelInterface budgetStatisticModel
    @param string currency
#}
{% macro progressbar_budget(budgetStatisticModel, currency) %}
    {% if budgetStatisticModel.hasBudget() %}
        {% set options = {
            'max': budgetStatisticModel.getBudget(),
            'current': budgetStatisticModel.getBudgetSpent(),
            'open': (budgetStatisticModel.getBudgetOpen()),
            'format': 'money',
            'currency': currency,
        } %}
        {% if budgetStatisticModel.isMonthlyBudget() %}
            {% set options = options|merge({
                'trans_percent_open': 'stats.percentUsedLeft_month',
                'trans_percent_spent': 'stats.percentUsed_month',
            }) %}
        {% endif %}
        {{ _self.progressbar_full(options) }}
    {% endif %}
{% endmacro %}

{#
    @param \App\Model\BudgetStatisticModelInterface budgetStatisticModel
#}
{% macro progressbar_timebudget(budgetStatisticModel) %}
    {% if budgetStatisticModel.hasTimeBudget() %}
        {% set options = {
            'max': budgetStatisticModel.getTimeBudget(),
            'current': budgetStatisticModel.getTimeBudgetSpent(),
            'open': (budgetStatisticModel.getTimeBudgetOpen()),
            'format': 'duration',
        } %}
        {% if budgetStatisticModel.isMonthlyBudget() %}
            {% set options = options|merge({
                'trans_percent_open': 'stats.percentUsedLeft_month',
                'trans_percent_spent': 'stats.percentUsed_month',
            }) %}
        {% endif %}
        {{ _self.progressbar_full(options) }}
    {% endif %}
{% endmacro %}