{% set absUrl = app.request.getSchemeAndHttpHost() ~ app.request.baseUrl|replace({'/app_dev.php': ''}) %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="{{ absUrl ~ asset('bundles/rxconnexion/admin/css/report/report_wkpdf.css') }}" />
</head>
<body>
<h2><strong>{{ page_title }}</strong></h2>
{% for record in records %}
    <div>
        <h4 style="background-color: #4ccfdd"><strong style="color: #0a0a0a;">{{ record.description }}</strong></h4>
    </div>
    <table>
        <thead>
        <tr>
            <th style="background-color: #b2b2b2"><span style="color: #000000">Activity/Services</span></th>
            {% for provider in record.providers %}
                <th style="background-color: #b2b2b2"><span style="color: #000000">{{ provider.name }}</span></th>
            {% endfor %}
            <th style="background-color: #b2b2b2"><span style="color: #000000">Total</span></th>
        </tr>
        </thead>
        <tbody>

        {% set subTotal = 0 %}
        {% for chartType in record.chartTypes %}

            {% set total_activity = 0 %}
            {% set percentage = 0 %}
            {% set count = null %}

            {% for pv in record.providers %}
                {% for prr in chartType.providers if prr.id == pv.id %}
                    {% set count = count + prr.count %}
                {% endfor %}
            {% endfor %}

            <tr>
                <td style="background-color: #b2b2b2"><span style="color: #000000">{{ chartType.description }}</span></td>
                {% for provider in record.providers %}
                    {% set hasTD = false %}
                    {% for pr in chartType.providers if pr.id == provider.id %}
                        {% set percentage = ((pr.count/count)|round(2))  *100  %}
                        {% set hasTD = true %}
                        {% set total_activity = total_activity + pr.count %}
                        <td>{{ pr.count }} ({{ percentage|round~'%' }})</td>
                        {% set subTotal = subTotal + pr.count %}
                    {% endfor %}
                    {% if not hasTD %}
                        <td>0</td>
                    {% endif %}
                {% endfor %}
                <td><strong>{{ total_activity }}</strong></td>
            </tr>
        {% endfor %}
        <tr style="border-top: 1px solid #aaaaaa;">
            <td><b>Total:</b></td>
            {% for provider in record.providers  %}
                {% set totalPercentage = null %}
                {% set total_prov = 0 %}
                {% for chartType in record.chartTypes  %}
                    {% for pr in chartType.providers if pr.id == provider.id  %}
                        {% set total_prov = total_prov + pr.count %}
                        {% set totalPercentage = (total_prov / subTotal) * 100 %}
                    {% endfor %}
                {% endfor %}
                <td><strong>{{ total_prov }} ({{ totalPercentage|round~'%' }})</strong></td>
            {% endfor %}
            <td><strong style="font-size: 15px">{{ subTotal }}</strong></td>
        </tr>
        </tbody>
    </table>
{% endfor %}

</body>
</html>