{% 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>
<table class="report-data" width="100%">
    <thead class="header">
    <tr>
        <th>Payment Type</th>
        <th width="15%">Patient</th>
        <th>Invoice No.</th>
        <th>Billing Address</th>
        <th>Billing Branch</th>
        <th>Financing Company</th>
        <th>Pay Date</th>
        <th>Amount</th>
        <th>Status</th>
        <th colspan="2">Note</th>
    </tr>
    </thead>
    <tbody>
    {% set totalCount = 0 %}
    {% set totalAmount = 0 %}
    {% for record in records.payment %}
        {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
        {% set totalCount = totalCount + 1 %}
        {% set totalAmount = totalAmount + record.amount %}
        {% set breakdowns = record.patientPayment_breakdowns == '' ? [] : record.patientPayment_breakdowns|split('~') %}
        <tr class="{{ trC }}">
            <td class="{#toggle-sub-table#}">
                {{ record.pay_type }}
                {% if breakdowns|length > 0 %}
                    <div class="sub-table" style="display: none;">
                        <div class="row sub-table-header">
                            <div class="columns small-6"><strong>Item</strong></div>
                            <div class="columns small-6 text-right"><strong>Amount Paid</strong></div>
                        </div>
                        {% for pbb in breakdowns %}
                            {% set dt = pbb|split('|') %}
                            <div class="row">
                                <div class="small-8 columns">{{ dt[3]|default('') }}</div>
                                <div class="small-4 columns text-right">{{ dt[2]|default('') }}</div>
                            </div>
                        {% endfor %}
                    </div>
                {% endif %}
            </td>
            <td class="toggle-sub-table">{{ record.patientName }}</td>
            <td class="toggle-sub-table">{{ record.invoiceNo }}</td>
            <td class="toggle-sub-table">{{ record.branchAddress }}</td>
            <td class="toggle-sub-table">{{ record.billingBranch }}</td>
            <td class="toggle-sub-table">{{ record.financingCompany }}</td>
            <td class="toggle-sub-table">{{ record.pay_date }}</td>
            <td class="toggle-sub-table text-right">{{ record.amount|number_format(2, '.', ',') }}</td>
            <td class="toggle-sub-table">{{ record.payment_status }}</td>
            <td class="toggle-sub-table">{{ record.note|raw }}</td>
            <td class="toggle-sub-table text-right">{% if breakdowns|length > 0 %}<i class="fa fa-caret-down"></i>{% endif %}</td>
        </tr>
    {% endfor %}
    <tr>
        <td><strong>Total:</strong></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td class="text-right"><strong>{{ totalAmount|number_format(2, '.', ',') }}</strong></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</table>
<div>Total Record(s): {{ totalCount }}</div>
<div></div>
<div style="width: 100%;">
    <div style="width: 49%; float: left;">
        <h5 class="report-header">Payment Summary</h5>
        <table class="report-data" data-floathead="false" width="100%">
            <thead class="header">
            <tr>
                <th>Billing Branch</th>
                <th class="text-right">Transaction Count</th>
                <th class="text-right">Total Amount</th>
                {#<th class="text-right">Total Bill Due Amount</th>#}
                {#<th class="text-right">Total Bill Paid Amount</th>#}
                {#<th class="text-right">Total Bill Balance Amount</th>#}
            </tr>
            </thead>
            <tbody>
            {% set totalCount = 0 %}
            {% set totalAmt = 0 %}
            {% set totalTranCount = 0 %}
            {% for record in records.summary %}
                {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                {% set totalCount = totalCount + 1 %}
                {% set totalAmt = totalAmt + record.totalAmt %}
                {% set totalTranCount = totalTranCount + record.transactionCount %}
                <tr class="{{ trC }}">
                    <td>{{ record.billingBranch }}</td>
                    <td class="text-right">{{ record.transactionCount }}</td>
                    <td class="text-right">{{ record.totalAmt|number_format(2, '.', ',') }}</td>
                    {#<td class="text-right">{{ record.totalBillDueAmt|number_format(2, '.', ',') }}</td>#}
                    {#<td class="text-right">{{ record.totalBillPaidAmt|number_format(2, '.', ',') }}</td>#}
                    {#<td class="text-right">{{ record.totalBillBalAmt|number_format(2, '.', ',') }}</td>#}
                </tr>
            {% endfor %}
            <tr>
                <td><strong>Total:</strong></td>
                <td class="text-right"><strong>{{ totalTranCount }}</strong></td>
                <td class="text-right"><strong>{{ totalAmt|number_format(2, '.', ',') }}</strong></td>
                {#<td class="text-right">{{ record.totalBillDueAmt|number_format(2, '.', ',') }}</td>#}
                {#<td class="text-right">{{ record.totalBillPaidAmt|number_format(2, '.', ',') }}</td>#}
                {#<td class="text-right">{{ record.totalBillBalAmt|number_format(2, '.', ',') }}</td>#}
            </tr>
        </table>
    </div>
    <div style="width: 49%; float: right;">
        <h5 class="report-header">Breakdown</h5>
        <table class="report-data" data-floathead="false" width="100%">
            <thead class="header">
            <tr>
                <th>Payment Type</th>
                <th class="text-right">Transaction Count</th>
                <th class="text-right">Total Amount</th>
                {#<th class="text-right">Total Bill Due Amount</th>#}
                {#<th class="text-right">Total Bill Paid Amount</th>#}
                {#<th class="text-right">Total Bill Balance Amount</th>#}
            </tr>
            </thead>
            <tbody>
            {% set breakdown_totalCount = 0 %}
            {% set breakdown_totalAmt = 0 %}
            {% set breakdown_totalTranCount = 0 %}
            {% for record in records.breakdown %}
                {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                {% set breakdown_totalCount = breakdown_totalCount + 1 %}
                {% set breakdown_totalAmt = breakdown_totalAmt + record.totalAmt %}
                {% set breakdown_totalTranCount = breakdown_totalTranCount + record.transactionCount %}
                <tr class="{{ trC }}">
                    <td>{{ record.paymentType }}</td>
                    <td class="text-right">{{ record.transactionCount }}</td>
                    <td class="text-right">{{ record.totalAmt|number_format(2, '.', ',') }}</td>
                    {#<td class="text-right">{{ record.totalBillDueAmt|number_format(2, '.', ',') }}</td>#}
                    {#<td class="text-right">{{ record.totalBillPaidAmt|number_format(2, '.', ',') }}</td>#}
                    {#<td class="text-right">{{ record.totalBillBalAmt|number_format(2, '.', ',') }}</td>#}
                </tr>
            {% endfor %}
            <tr>
                <td><strong>Total:</strong></td>
                <td class="text-right"><strong>{{ breakdown_totalTranCount }}</strong></td>
                <td class="text-right"><strong>{{ breakdown_totalAmt|number_format(2, '.', ',') }}</strong></td>
                {#<td class="text-right">{{ record.totalBillDueAmt|number_format(2, '.', ',') }}</td>#}
                {#<td class="text-right">{{ record.totalBillPaidAmt|number_format(2, '.', ',') }}</td>#}
                {#<td class="text-right">{{ record.totalBillBalAmt|number_format(2, '.', ',') }}</td>#}
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>