{% 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>Invoice No.</th>
        <th>Date</th>
        <th>Patient</th>
        <th>Company</th>
        <th>Branch</th>
        <th>Branch Address</th>
        <th>Amount</th>
        <th>Amount Paid</th>
        <th>Amount Refunded</th>
        <th>Balance</th>
        <th>Status</th>
        <th>Note</th>
    </tr>
    </thead>
    <tbody>
    {% set totalCount = 0 %}
    {% set totalAmt = 0 %}
    {% set totalPaid = 0 %}
    {% set totalRefunded = 0 %}
    {% set totalBalance = 0 %}
    {% for record in records %}
        {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
        {% set totalCount = totalCount + 1 %}
        {% set totalAmt = totalAmt + record.amtDue %}
        {% set totalPaid = totalPaid + record.amtPaid %}
        {% set totalRefunded = totalRefunded + record.amtRefunded %}
        {% set totalBalance = totalBalance + record.amtBalance %}
        <tr class="{{ trC }}">
            <td>{{ record.invoiceNo }}</td>
            <td>{{ record.billingDate }}</td>
            <td>{{ record.patient }}</td>
            <td>{{ record.companyDesc }}</td>
            <td>{{ record.healthFacility }}</td>
            <td>{{ record.healthFacilityAddress }}</td>
            <td class="text-right">{{ record.amtDue|number_format(2, '.', ',') }}</td>
            <td class="text-right">{{ record.amtPaid|number_format(2, '.', ',') }}</td>
            <td class="text-right">{{ record.amtRefunded|number_format(2, '.', ',') }}</td>
            <td class="text-right">{{ record.amtBalance|number_format(2, '.', ',') }}</td>
            <td>{{ record.billingStatus }}</td>
            <td>{{ record.note|raw }}</td>
        </tr>
    {% endfor %}
    <tr>
        <td><strong>Total:</strong></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td class="text-right"><strong>{{ totalAmt|number_format(2, '.', ',') }}</strong></td>
        <td class="text-right"><strong>{{ totalPaid|number_format(2, '.', ',') }}</strong></td>
        <td class="text-right"><strong>{{ totalRefunded|number_format(2, '.', ',') }}</strong></td>
        <td class="text-right"><strong>{{ totalBalance|number_format(2, '.', ',') }}</strong></td>
        <td></td>
        <td></td>
    </tr>
</table>
<div style="margin-bottom: 10px;">Total Record(s): {{ totalCount }}</div>
<div style="width: 100%;">
    <div style="width: 49.5%; float: left;">
        <h5 class="report-header">Summary</h5>
        <table class="report-data" width="100%" style="margin-bottom: 10px;">
            <thead class="header">
            <tr>
                <th width="33%">Branch Address</th>
                <th style="text-align: right;" width="33%">Count</th>
                <th style="text-align: right;" width="33%">Invoice</th>
            </tr>
            </thead>
            <tbody>
            {% set summaryTotal = 0 %}
            {% set summaryTotalAmtDue = 0 %}
            {% for record2 in records2.invoiceSummary %}
                {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                {% set summaryTotal = summaryTotal + record2.totalCount %}
                {% set summaryTotalAmtDue = summaryTotalAmtDue + record2.totalAmtDue %}
                <tr class="{{ trC }}">
                    <td>{{ record2.healthFacility }}</td>
                    <td style="text-align: right;">{{ record2.totalCount }}</td>
                    <td style="text-align: right;">{{ record2.totalAmtDue|number_format(2, '.', ',') }}</td>
                </tr>
            {% endfor %}
            <tr>
                <td></td>
                <td style="text-align: right;"><strong>Total: {{ summaryTotal }}</strong></td>
                <td style="text-align: right;"><strong>Total: {{ summaryTotalAmtDue|number_format(2, '.', ',') }}</strong></td>
            </tr>
            </tbody>
        </table>
    </div>
    <div style="width: 49.5%; float: right;">
        <h5 class="report-header">Financing Company Summary</h5>
        <table class="report-data" width="100%" style="margin-bottom: 10px;">
            <thead class="header">
            <tr>
                <th width="33%">Financing Company</th>
                <th style="text-align: right;" width="33%">Count</th>
                <th style="text-align: right;" width="33%">Invoice</th>
            </tr>
            </thead>
            <tbody>
            {% set summaryFinancingTotal = 0 %}
            {% set summaryFinancingTotalAmtDue = 0 %}
            {% for financingSummary in records2.financing %}
                {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                {% set summaryFinancingTotal = summaryFinancingTotal + financingSummary.totalCount %}
                {% set summaryFinancingTotalAmtDue = summaryFinancingTotalAmtDue + financingSummary.totalAmtDue %}
                <tr class="{{ trC }}">
                    <td>{{ financingSummary.healthFacility }}</td>
                    <td style="text-align: right;">{{ financingSummary.totalCount }}</td>
                    <td style="text-align: right;">{{ financingSummary.totalAmtDue|number_format(2, '.', ',') }}</td>
                </tr>
            {% endfor %}
            <tr>
                <td></td>
                <td style="text-align: right;"><strong>Total: {{ summaryFinancingTotal }}</strong></td>
                <td style="text-align: right;"><strong>Total: {{ summaryFinancingTotalAmtDue|number_format(2, '.', ',') }}</strong></td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<div style="width: 100%; float: left;">
    <h5 class="report-header">Long Term Summary</h5>
    <table class="report-data" width="100%">
        <thead class="header">
        <tr>
            <th width="33%">Branch Address</th>
            <th style="text-align: right;" width="33%">Count</th>
            <th style="text-align: right;" width="33%">Total Amount</th>
        </tr>
        </thead>
        <tbody>
        {% set longTermTotalCount = 0 %}
        {% set totalPrice = 0 %}
        {% for record3 in records3.longTerm %}
            {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
            {% set longTermTotalCount = longTermTotalCount + record3.longTermCount %}
            {% set totalPrice = totalPrice + record3.price %}
            <tr class="{{ trC }}">
                <td>{{ record3.billingBranch }}</td>
                <td style="text-align: right;">{{ record3.longTermCount }}</td>
                <td style="text-align: right;">{{ record3.price|number_format(2, '.', ',') }}</td>
            </tr>
        {% endfor %}
        <tr>
            <td></td>
            <td style="text-align: right;"><strong>Total: {{ longTermTotalCount }}</strong></td>
            <td style="text-align: right;"><strong>Total: {{ totalPrice|number_format(2, '.', ',') }}</strong></td>
        </tr>
        </tbody>
    </table>
</div>
<div style="width: 100%; float: left;">
    <h5 class="report-header">Rent to Own Summary</h5>
    <table class="report-data" width="100%">
        <thead class="header">
        <tr>
            <th width="33%">Branch Address</th>
            <th style="text-align: right;" width="33%">Count</th>
            <th style="text-align: right;" width="33%">Total Amount</th>
        </tr>
        </thead>
        <tbody>
        {% set rentToTotalCount = 0 %}
        {% set totalPrice = 0 %}
        {% for record4 in records3.rentToOwn %}
            {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
            {% set rentToTotalCount = rentToTotalCount + record4.rentToCount %}
            {% set totalPrice = totalPrice + record4.price %}
            <tr class="{{ trC }}">
                <td>{{ record4.billingBranch }}</td>
                <td style="text-align: right;">{{ record4.rentToCount }}</td>
                <td style="text-align: right;">{{ record4.price|number_format(2, '.', ',') }}</td>
            </tr>
        {% endfor %}
        <tr>
            <td></td>
            <td style="text-align: right;"><strong>Total: {{ rentToTotalCount }}</strong></td>
            <td style="text-align: right;"><strong>Total: {{ totalPrice|number_format(2, '.', ',') }}</strong></td>
        </tr>
        </tbody>
    </table>
</div>
<div style="width: 100%; float: left;">
    <h5 class="report-header">Accessory Summary</h5>
    <table class="report-data" width="100%">
        <thead class="header">
        <tr>
            <th width="33%">Branch Address</th>
            <th style="text-align: right;" width="33%">Count</th>
            <th style="text-align: right;" width="33%">Total Amount</th>
        </tr>
        </thead>
        <tbody>
        {% set accessoryTotalCount = 0 %}
        {% set totalPrice = 0 %}
        {% for record5 in records3.accessory %}
            {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
            {% set accessoryTotalCount = accessoryTotalCount + record5.accessoryCount %}
            {% set totalPrice = totalPrice + record5.price %}
            <tr class="{{ trC }}">
                <td>{{ record5.billingBranch }}</td>
                <td style="text-align: right;">{{ record5.accessoryCount }}</td>
                <td style="text-align: right;">{{ record5.price|number_format(2, '.', ',') }}</td>
            </tr>
        {% endfor %}
        <tr>
            <td></td>
            <td style="text-align: right;"><strong>Total: {{ accessoryTotalCount }}</strong></td>
            <td style="text-align: right;"><strong>Total: {{ totalPrice|number_format(2, '.', ',') }}</strong></td>
        </tr>
        </tbody>
    </table>
</div>
<div style="width: 100%; float: left;">
    <h5 class="report-header">CPAP Package Summary</h5>
    <table class="report-data" width="100%">
        <thead class="header">
        <tr>
            <th width="33%">Branch Address</th>
            <th style="text-align: right;" width="33%">Count</th>
            <th style="text-align: right;" width="33%">Total Amount</th>
        </tr>
        </thead>
        <tbody>
        {% set cpapPackageTotalCount = 0 %}
        {% set totalPrice = 0 %}
        {% for record6 in records3.cpapPackage %}
            {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
            {% set cpapPackageTotalCount = cpapPackageTotalCount + record6.cpapPackageCount %}
            {% set totalPrice = totalPrice + record6.price %}
            <tr class="{{ trC }}">
                <td>{{ record6.billingBranch }}</td>
                <td style="text-align: right;">{{ record6.cpapPackageCount }}</td>
                <td style="text-align: right;">{{ record6.price|number_format(2, '.', ',') }}</td>
            </tr>
        {% endfor %}
        <tr>
            <td></td>
            <td style="text-align: right;"><strong>Total: {{ cpapPackageTotalCount }}</strong></td>
            <td style="text-align: right;"><strong>Total: {{ totalPrice|number_format(2, '.', ',') }}</strong></td>
        </tr>
        </tbody>
    </table>
</div>
<div style="width: 100%; float: left;">
    <h5 class="report-header">Medical Supplies Summary</h5>
    <table class="report-data" width="100%">
        <thead class="header">
        <tr>
            <th width="33%">Branch Address</th>
            <th style="text-align: right;" width="33%">Count</th>
            <th style="text-align: right;" width="33%">Total Amount</th>
        </tr>
        </thead>
        <tbody>
        {% set medicalSuppliesTotalCount = 0 %}
        {% set totalPrice = 0 %}
        {% for record7 in records3.medicalSupplies %}
            {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
            {% set medicalSuppliesTotalCount = medicalSuppliesTotalCount + record7.medicalSuppliesCount %}
            {% set totalPrice = totalPrice + record7.price %}
            <tr class="{{ trC }}">
                <td>{{ record7.billingBranch }}</td>
                <td style="text-align: right;">{{ record7.medicalSuppliesCount }}</td>
                <td style="text-align: right;">{{ record7.price|number_format(2, '.', ',') }}</td>
            </tr>
        {% endfor %}
        <tr>
            <td></td>
            <td style="text-align: right;"><strong>Total: {{ medicalSuppliesTotalCount }}</strong></td>
            <td style="text-align: right;"><strong>Total: {{ totalPrice|number_format(2, '.', ',') }}</strong></td>
        </tr>
        </tbody>
    </table>
</div>
<div></div>
<div></div>
</body>
</html>