    {% extends '@RxConnexion/Admin/global.html.twig' %}
{% block body %}
    <h3 class="report-header"><strong>{{ page_title }}</strong> From: {{ dateFrom }} To: {{ dateTo }}</h3>

    {% for record in records %}
        <div>
            <h4 style="background-color: #1397dd"><strong style="color: #0a0a0a;">{{ record.description }}</strong></h4>
        </div>
        <table>
            <thead>
                <tr>
                    <th style="background-color: #969696"><span style="color: #000000">Activity/Services</span></th>
                    {% for provider in record.providers %}
                        <th style="background-color: #969696"><span style="color: #000000">{{ provider.name }}</span></th>
                    {% endfor %}
                    <th style="background-color: #969696"><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: #bcbcbc"><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><a href="{{ path('report_encounter_preview', {date_from:dateFrom, date_to:dateTo, company_id:'null', branch_id:record.id, provider_id:provider.id, patient_id:'null', encountertype_id:chartType.id, encounter_status:'Completed', user_id:'null', status:'null' }) }}" target="_blank">{{ pr.count }}</a> ({{ 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 %}

    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script>
        //<![CDATA[
        jQ(document).ready(function(){
            report_preview.init();
        });
        //]]>
    </script>
{% endblock %}