{% extends '@RxConnexion/Admin/global.html.twig' %}
{% block body %}
    <style>
        .row > .columns:first-child{
            padding-left: 0;
        }
        .row > .columns:last-child{
            padding-right: 0;
        }
        .void .report-header{
            background-color: #b17272;
        }
    </style>
    <h5 class="report-header">{{ page_title }}</h5>
    <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 class="text-right">Amount</th>
            <th class="text-right">Amount Paid</th>
            <th class="text-right">Amount Refunded</th>
            <th class="text-right">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_forTotal %}
            {% set totalPaid = totalPaid + record.amtPaid_forTotal %}
            {% set totalRefunded = totalRefunded + record.amtRefunded_forTotal %}
            {% set totalBalance = totalBalance + record.amtBalance_forTotal %}
            <tr class="{{ trC }}">
                <td><a href="{{ path('patient_detail', {patient_id : record.patientId|base64Encode, tab:'b', invoiceNo:record.invoiceNo}) }}" target="_blank">{{ record.invoiceNo }}</a></td>
                <td>{{ record.billingDate }}</td>
                <td><a href="{{ path('patient_detail', {patient_id : record.patientId|base64Encode, tab:'b'}) }}" target="_blank">{{ record.patient }}</a></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 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 financingSummary %}
                    {% 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;">
        <div style="width: 49.5%; float: left;">
            <h5 class="report-header">Payment Summary</h5>
            <table class="report-data" width="100%" style="margin-bottom: 10px;">
                <thead class="header">
                <tr>
                    <th>Billing Branch</th>
                    <th class="text-right">Transaction Count</th>
                    <th class="text-right">Total Amount</th>
                </tr>
                </thead>
                <tbody>
                {% set totalCount = 0 %}
                {% set totalPaymentAmount = 0 %}
                {% for ps in paymentSummary %}
                    {% set totalCount = totalCount + ps.count %}
                    {% set totalPaymentAmount = totalPaymentAmount + ps.totalPaymentAmount %}
                    <tr>
                        <td>{{ ps.healthFacilityAddress }} {#{{ ps.invoice_nos|join(' , ') }}#}</td>
                        <td class="text-right">{{ ps.count }}</td>
                        <td class="text-right">{{ ps.totalPaymentAmount|number_format(2, '.', ',') }}</td>
                    </tr>
                {% endfor %}
                </tbody>
                <tfoot>
                <tr>
                    <td>Total:</td>
                    <td class="text-right">{{ totalCount }}</td>
                    <td class="text-right">{{ totalPaymentAmount|number_format(2, '.', ',') }}</td>
                </tr>
                </tfoot>
            </table>
        </div>
        <div style="width: 49.5%; float: right;">
            <h5 class="report-header">Payment Type 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>
                </tr>
                </thead>
                <tbody>
                {% set breakdown_totalCount = 0 %}
                {% set breakdown_totalAmt = 0 %}
                {% set breakdown_totalTranCount = 0 %}
                {% for record in paymentBreakdown %}
                    {% 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 }} {#{{ record.invoices|join(' , ') }}#}</td>
                        <td class="text-right">{{ record.transactionCount }}</td>
                        <td class="text-right">{{ record.totalAmt|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>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div class="row max-width-initial">
        <div class="columns large-8">
            <h5 class="report-header">Long Term Summary</h5>
            <table class="report-data" width="100%">
                <thead class="header">
                <tr>
                    <th width="20%">Branch Address</th>
                    <th style="text-align: right;">Count</th>
                    <th style="text-align: right;">Total Sales</th>
                    <th style="text-align: right;">Total Cost</th>
                    <th style="text-align: right;">Net</th>
                </tr>
                </thead>
                <tbody>
                {% set longTermTotalCount = 0 %}
                {% set totalPrice = 0 %}
                {% set totalCost = 0 %}
                {% for record3 in longTermSummary %}
                    {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                    {% set longTermTotalCount = longTermTotalCount + record3.longTermCount %}
                    {% set totalPrice = totalPrice + record3.price %}
                    {% set totalCost = totalCost + record3.cost %}
                    <tr class="{{ trC }}">
                        <td>{{ record3.billingBranch }}</td>
                        <td style="text-align: right;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record3.billingBranchId, term: 'long_term',  item_type : 'null' }) }}" target="_blank">{{ record3.longTermCount }}</a></td>
                        <td style="text-align: right;">{{ record3.price|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ record3.cost|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ (record3.price - record3.cost)|number_format(2, '.', ',') }}</td>
                    </tr>
                {% endfor %}
                <tr>
                    <td><strong>Total</strong></td>
                    <td style="text-align: right;"><strong>{{ longTermTotalCount }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalPrice|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalCost|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ (totalPrice - totalCost)|number_format(2, '.', ',') }}</strong></td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="void columns large-4">
            <h5 class="report-header">Long Term Summary (Void / Returned)</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 longTermSummary_void %}
                    {% 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;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record3.billingBranchId, term: 'long_term',  item_type : 'null' }) }}" target="_blank">{{ record3.longTermCount }}</a></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>
    <div class="row max-width-initial">
        <div class="columns large-8">
            <h5 class="report-header">Rent to Own Summary</h5>
            <table class="report-data" width="100%">
                <thead class="header">
                <tr>
                    <th width="20%">Branch Address</th>
                    <th style="text-align: right;">Count</th>
                    <th style="text-align: right;">Total Sales</th>
                    <th style="text-align: right;">Total Cost</th>
                    <th style="text-align: right;">Net</th>
                </tr>
                </thead>
                <tbody>
                {% set rentToTotalCount = 0 %}
                {% set totalPrice = 0 %}
                {% set totalCost = 0 %}
                {% for record4 in rentToOwnSummary %}
                    {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                    {% set rentToTotalCount = rentToTotalCount + record4.rentToCount %}
                    {% set totalPrice = totalPrice + record4.price %}
                    {% set totalCost = totalCost + record4.cost %}
                    <tr class="{{ trC }}">
                        <td>{{ record4.billingBranch }}</td>
                        <td style="text-align: right;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record4.billingBranchId, term: 'rent_to_own',  item_type : 'null' }) }}" target="_blank">{{ record4.rentToCount }}</a></td>
                        <td style="text-align: right;">{{ record4.price|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ record4.cost|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ (record4.cost - record4.cost)|number_format(2, '.', ',') }}</td>
                    </tr>
                {% endfor %}
                <tr>
                    <td><strong>Total</strong></td>
                    <td style="text-align: right;"><strong>{{ rentToTotalCount }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalPrice|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalCost|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ (totalPrice - totalCost)|number_format(2, '.', ',') }}</strong></td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="void columns large-4">
            <h5 class="report-header">Rent to Own Summary (Void / Returned)</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 rentToOwnSummary_void %}
                    {% 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;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record4.billingBranchId, term: 'rent_to_own',  item_type : 'null' }) }}" target="_blank">{{ record4.rentToCount }}</a></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>
    <div class="row max-width-initial">
        <div class="columns large-8">
            <h5 class="report-header">Accessory Summary</h5>
            <table class="report-data" width="100%">
                <thead class="header">
                <tr>
                    <th width="20%">Branch Address</th>
                    <th style="text-align: right;">Count</th>
                    <th style="text-align: right;">Total Sales</th>
                    <th style="text-align: right;">Total Cost</th>
                    <th style="text-align: right;">Net</th>
                </tr>
                </thead>
                <tbody>
                {% set accessoryTotalCount = 0 %}
                {% set totalPrice = 0 %}
                {% set totalCost = 0 %}
                {% for record5 in accessorySummary %}
                    {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                    {% set accessoryTotalCount = accessoryTotalCount + record5.accessoryCount %}
                    {% set totalPrice = totalPrice + record5.price %}
                    {% set totalCost = totalCost + record5.cost %}
                    <tr class="{{ trC }}">
                        <td>{{ record5.billingBranch }}</td>
                        <td style="text-align: right;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record5.billingBranchId, term: 'null',  item_type : 'accessory' }) }}" target="_blank">{{ record5.accessoryCount }}</a></td>
                        <td style="text-align: right;">{{ record5.price|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ record5.cost|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ (record5.price - record5.cost)|number_format(2, '.', ',') }}</td>
                    </tr>
                {% endfor %}
                <tr>
                    <td><strong>Total</strong></td>
                    <td style="text-align: right;"><strong>{{ accessoryTotalCount }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalPrice|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalCost|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ (totalPrice - totalCost)|number_format(2, '.', ',') }}</strong></td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="void columns large-4">
            <h5 class="report-header">Accessory Summary (Void / Returned)</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 accessorySummary_void %}
                    {% 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;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record5.billingBranchId, term: 'null',  item_type : 'accessory' }) }}" target="_blank">{{ record5.accessoryCount }}</a></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>
    <div class="row max-width-initial">
        <div class="columns large-8">
            <h5 class="report-header">CPAP Package Summary</h5>
            <table class="report-data" width="100%">
                <thead class="header">
                <tr>
                    <th width="20%">Branch Address</th>
                    <th style="text-align: right;">Count</th>
                    <th style="text-align: right;">Total Sales</th>
                    <th style="text-align: right;">Total Cost</th>
                    <th style="text-align: right;">Net</th>
                </tr>
                </thead>
                <tbody>
                {% set cpapPackageTotalCount = 0 %}
                {% set totalPrice = 0 %}
                {% set totalCost = 0 %}
                {% for record6 in cpapPackageSummary %}
                    {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                    {% set cpapPackageTotalCount = cpapPackageTotalCount + record6.cpapPackageCount %}
                    {% set totalPrice = totalPrice + record6.price %}
                    {% set totalCost = totalCost + record6.cost %}
                    <tr class="{{ trC }}">
                        <td>{{ record6.billingBranch }}</td>
                        <td style="text-align: right;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record6.billingBranchId, term: 'null',  item_type : 'cpap_package' }) }}" target="_blank">{{ record6.cpapPackageCount }}</a></td>
                        <td style="text-align: right;">{{ record6.price|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ record6.cost|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ (record6.price - record6.cost)|number_format(2, '.', ',') }}</td>
                    </tr>
                {% endfor %}
                <tr>
                    <td><strong>Total</strong></td>
                    <td style="text-align: right;"><strong>{{ cpapPackageTotalCount }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalPrice|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalCost|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ (totalPrice - totalCost)|number_format(2, '.', ',') }}</strong></td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="void columns large-4">
            <h5 class="report-header">CPAP Package Summary (Void / Returned)</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 cpapPackageSummary_void %}
                    {% 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;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record6.billingBranchId, term: 'null',  item_type : 'cpap_package' }) }}" target="_blank">{{ record6.cpapPackageCount }}</a></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>
    <div class="row max-width-initial">
        <div class="columns large-8">
            <h5 class="report-header">Medical Supplies Summary</h5>
            <table class="report-data" width="100%">
                <thead class="header">
                <tr>
                    <th width="20%">Branch Address</th>
                    <th style="text-align: right;">Count</th>
                    <th style="text-align: right;">Total Sales</th>
                    <th style="text-align: right;">Total Cost</th>
                    <th style="text-align: right;">Net</th>
                </tr>
                </thead>
                <tbody>
                {% set medicalSuppliesTotalCount = 0 %}
                {% set totalPrice = 0 %}
                {% set totalCost = 0 %}
                {% for record7 in medicalSuppliesSummary %}
                    {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                    {% set medicalSuppliesTotalCount = medicalSuppliesTotalCount + record7.medicalSuppliesCount %}
                    {% set totalPrice = totalPrice + record7.price %}
                    {% set totalCost = totalCost + record7.cost %}
                    <tr class="{{ trC }}">
                        <td>{{ record7.billingBranch }}</td>
                        <td style="text-align: right;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record7.billingBranchId, term: 'null',  item_type : 'medical_supplies' }) }}" target="_blank">{{ record7.medicalSuppliesCount }}</a></td>
                        <td style="text-align: right;">{{ record7.price|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ record7.cost|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ (record7.price - record7.cost)|number_format(2, '.', ',') }}</td>
                    </tr>
                {% endfor %}
                <tr>
                    <td><strong>Total</strong></td>
                    <td style="text-align: right;"><strong>{{ medicalSuppliesTotalCount }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalPrice|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalCost|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ (totalPrice - totalCost)|number_format(2, '.', ',') }}</strong></td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="void columns large-4">
            <h5 class="report-header">Medical Supplies Summary (Void / Returned)</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 medicalSuppliesSummary_void %}
                    {% 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;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record7.billingBranchId, term: 'null',  item_type : 'medical_supplies' }) }}" target="_blank">{{ record7.medicalSuppliesCount }}</a></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 class="row max-width-initial">
        <div class="columns large-8">
            <h5 class="report-header">Part of CPAP Package Summary</h5>
            <table class="report-data" width="100%">
                <thead class="header">
                <tr>
                    <th width="20%">Branch Address</th>
                    <th style="text-align: right;">Count</th>
                    <th style="text-align: right;">Total Sales</th>
                    <th style="text-align: right;">Total Cost</th>
                    <th style="text-align: right;">Net</th>
                </tr>
                </thead>
                <tbody>
                {% set partOfCpapPackageTotalCount = 0 %}
                {% set totalPrice = 0 %}
                {% set totalCost = 0 %}
                {% for record7 in partOfCpapPackageSummary %}
                    {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                    {% set partOfCpapPackageTotalCount = partOfCpapPackageTotalCount + record7.partOfCpapPackageCount %}
                    {% set totalPrice = totalPrice + record7.price %}
                    {% set totalCost = totalCost + record7.cost %}
                    <tr class="{{ trC }}">
                        <td>{{ record7.billingBranch }}</td>
                        <td style="text-align: right;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record7.billingBranchId, term: 'null',  item_type : 'Part of CPAP Package' }) }}" target="_blank">{{ record7.partOfCpapPackageCount }}</a></td>
                        <td style="text-align: right;">{{ record7.price|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ record7.cost|number_format(2, '.', ',') }}</td>
                        <td style="text-align: right;">{{ (record7.price - record7.cost)|number_format(2, '.', ',') }}</td>
                    </tr>
                {% endfor %}
                <tr>
                    <td><strong>Total</strong></td>
                    <td style="text-align: right;"><strong>{{ partOfCpapPackageTotalCount }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalPrice|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ totalCost|number_format(2, '.', ',') }}</strong></td>
                    <td style="text-align: right;"><strong>{{ (totalPrice - totalCost)|number_format(2, '.', ',') }}</strong></td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="void columns large-4">
            <h5 class="report-header">Part of CPAP Package Summary (Void / Returned)</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 partOfCpapPackageTotalCount = 0 %}
                {% set totalPrice = 0 %}
                {% for record7 in partOfCpapPackageSummary_void %}
                    {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
                    {% set partOfCpapPackageTotalCount = partOfCpapPackageTotalCount + record7.partOfCpapPackageCount %}
                    {% set totalPrice = totalPrice + record7.price %}
                    <tr class="{{ trC }}">
                        <td>{{ record7.billingBranch }}</td>
                        <td style="text-align: right;"><a href="{{ path('report_invoice_itemised_preview', {date_from: dateFrom, date_to: dateTo, patient: 'null', company: 'null', branch: 'null', branchAddress: record7.billingBranchId, term: 'null',  item_type : 'medical_supplies' }) }}" target="_blank">{{ record7.partOfCpapPackageCount }}</a></td>
                        <td style="text-align: right;">{{ record7.price|number_format(2, '.', ',') }}</td>
                    </tr>
                {% endfor %}
                <tr>
                    <td></td>
                    <td style="text-align: right;"><strong>Total: {{ partOfCpapPackageTotalCount }}</strong></td>
                    <td style="text-align: right;"><strong>Total: {{ totalPrice|number_format(2, '.', ',') }}</strong></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div></div>
    <div></div>

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