{% extends '@RxConnexion/Admin/global.html.twig' %}
{% block body %}
    <style>
        thead tr th {
            background-color: #969696;
            position: sticky;
            top: 0; /* Don't forget this, required for the stickiness */
        }

        tbody tr td:first-child {
            background-color: #bcbcbc;
        }

        tbody tr td {
        }

        tbody tr td small{
            margin-left: 5px;
        }

        tfoot tr{
            border-top: 1px solid #aaaaaa;
        }
    </style>
    <h3>{{ page_title }}
        <small>{{ dateFrom|replace('-', '/') }} - {{ dateTo|replace('-', '/') }}</small>
    </h3>

    {% for branch in branches %}
        <h4 style="background-color: #1397dd">{{ branch.name }}</h4>
        <table width="100%">
            <thead>
            <tr>
                <th width="200px">Activity/Services</th>
                {% for user in branch.users %}
                    <th>{{ user.name }}</th>
                {% endfor %}
                <th>Total</th>
            </tr>
            </thead>
            <tbody>
            {% for action in branch.actions %}
                <tr>
                    <td>{{ action.description }}</td>
                    {% for user in branch.users %}
                        {% for data in branch.data if data.user_id == user.id and data.action == action.description %}
                            <td>
                                {% if action.description not in ['Endorsements', 'Letters', 'Invoices', 'Payments'] %}
                                    <a href="{{ path('report_encounter_preview', {
                                        date_from:          dateFrom,
                                        date_to:            dateTo,
                                        company_id:         'null',
                                        branch_id:          branch.id,
                                        provider_id:        user.id,
                                        patient_id:         'null',
                                        encountertype_id:   data.details,
                                        encounter_status:   'Completed',
                                        user_id:            'null',
                                        status:             'null'
                                    }) }}" target="_blank">
                                        {{ data.total_count }}
                                    </a>
                                {% else %}
                                    {{ data.total_count }}
                                {% endif %}
                                <small>({{ (data.total_count / action.total * 100)|round(2) }}%)</small>
                            </td>
                        {% else %}
                            <td>0</td>
                        {% endfor %}
                    {% else %}
                        <td>0</td>
                    {% endfor %}
                    <td width="80px">{{ action.total }}</td>
                </tr>
            {% endfor %}
            </tbody>
            <tfoot>
                <tr>
                    <td>Total:</td>
                    {% for user in branch.users %}
                        {% set userTotal = 0 %}
                        {% for data in branch.data if data.user_id == user.id %}
                            {% set userTotal = userTotal + data.total_count %}
                        {% endfor %}
                        <td>{{ userTotal }} ({{ (userTotal / branch.total * 100)|round(2) }}%)</td>
                    {% endfor %}
                    <td>{{ branch.total }}</td>
                </tr>
            </tfoot>
        </table>
    {% endfor %}

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