{% set entity = person is defined ? person :  household %}

{% set actualResources = [] %}
{% set futureResources = [] %}
{% set pastResources   = [] %}

{% for r in resources %}
    {% if r.startDate|date('U') <= 'now'|date('U') %}
        {% if r.endDate is null or r.endDate|date('U') >= 'now'|date('U') %}
            {% set actualResources = actualResources|merge([ r ]) %}
        {% else %}
            {% set pastResources = pastResources|merge([ r ]) %}
        {% endif %}
    {% else %}
        {% set futureResources = futureResources|merge([ r ]) %}
    {% endif %}
{% endfor %}

{% set actualCharges = [] %}
{% set futureCharges = [] %}
{% set pastCharges   = [] %}

{% for c in charges %}
    {% if c.startDate|date('U') <= 'now'|date('U') %}
        {% if c.endDate is null or c.endDate|date('U') >= 'now'|date('U') %}
            {% set actualCharges = actualCharges|merge([ c ]) %}
        {% else %}
            {% set pastCharges = pastCharges|merge([ c ]) %}
        {% endif %}
    {% else %}
        {% set futureCharges = futureCharges|merge([ c ]) %}
    {% endif %}
{% endfor %}

<h3 class="subtitle">{{ 'Actual budget'|trans }}</h3>
{% if actualCharges|length > 0 or actualResources|length > 0 %}
    {% include '@ChillBudget/Budget/_current_budget.html.twig' with {
        'actualResources': actualResources,
        'actualCharges': actualCharges,
        'results': results,
        'entity': entity
    } %}
{% else %}
    <p><span class="chill-no-data-statement">{{ "There isn't any element recorded"|trans }}</span></p>
{% endif %}

{% if pastCharges|length > 0 or pastResources|length > 0 %}
    <h3 class="subtitle">{{ 'Past budget'|trans }}</h3>
    {% include '@ChillBudget/Budget/_past_budget.html.twig' with {
        'pastCharges': pastCharges,
        'pastResources': pastResources,
        'entity': entity
    } %}
{% endif %}

{% if futureCharges|length > 0 or futureResources|length > 0 %}
    <h3 class="subtitle">{{ 'Future budget'|trans }}</h3>
    {% include '@ChillBudget/Budget/_future_budget.html.twig' with {
        'futureResources': futureResources,
        'futureCharges': futureCharges,
        'entity': entity
    } %}
{% endif %}



