{% 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 class="report-header">{{ page_title }}</h2>
<table class="report-data" width="100%">
    <thead class="header">
    <tr>
        <th>Payer Type</th>
        <th>Patient</th>
        <th>Insurance</th>
        <th class="text-right">To Bill</th>
        <th class="text-right">Current</th>
        <th class="text-right">30 Days</th>
        <th class="text-right">60 Days</th>
        <th class="text-right">90 Days</th>
        <th class="text-right">120 Days</th>
        <th class="text-right">Credit</th>
        <th class="text-right">Amount</th>
    </tr>
    </thead>
    <tbody>
    {% set totalCount = 0 %}
    {% set totalCurrentBal = 0 %}
    {% set totalThirtyDays = 0 %}
    {% set totalSixtyDays = 0 %}
    {% set totalNinetyDays = 0 %}
    {% set totalOneTwentyDays = 0 %}
    {% set totalAmountBalance = 0 %}
    {% for record in records %}
        {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
        {% set totalCount = totalCount + 1 %}
        {% set totalCurrentBal = totalCurrentBal + record.currentBal|default(0) %}
        {% set totalThirtyDays = totalThirtyDays + record.thirtyDays|default(0) %}
        {% set totalSixtyDays = totalSixtyDays + record.sixtyDays|default(0) %}
        {% set totalNinetyDays = totalNinetyDays + record.ninetyDays|default(0) %}
        {% set totalOneTwentyDays = totalOneTwentyDays + record.oneTwentyDays|default(0) %}
        {% set totalAmountBalance = totalAmountBalance + record.amountBalance|default(0) %}
        <tr class="{{ trC }}">
            <td>{{ record.payerType }}</td>
            <td>{{ record.full_name }}</td>
            <td>{{ record.patientInsurance }}</td>
            {#<td>{{ record.billTo|default('0.00') }}</td>#}
            <td class="text-right">--</td>
            <td class="text-right">{{ record.currentBal|default('0.00') }}</td>
            <td class="text-right">{{ record.thirtyDays|default('0.00') }}</td>
            <td class="text-right">{{ record.sixtyDays|default('0.00') }}</td>
            <td class="text-right">{{ record.ninetyDays|default('0.00') }}</td>
            <td class="text-right">{{ record.oneTwentyDays|default('0.00') }}</td>
            <td class="text-right">--</td>
            <td class="text-right">{{ record.amountBalance }}</td>
        </tr>
    {% endfor %}
    <tr>
        <td><strong>Total:</strong></td>
        <td></td>
        <td></td>
        {#<td></td>#}
        <td class="text-right"><b>--</b></td>
        <td class="text-right"><b>{{ totalCurrentBal|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ totalThirtyDays|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ totalSixtyDays|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ totalNinetyDays|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ totalOneTwentyDays|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>--</b></td>
        <td class="text-right"><b>{{ totalAmountBalance|number_format(2, '.', ',') }}</b></td>
    </tr>
</table>
<div>Total Records: {{ totalCount }}</div>
<h2 class="report-header">AR Summary</h2>
<table class="report-data" width="100%">
    <thead class="header">
    <tr>
        <th>Branch</th>
        <th class="text-right">Current</th>
        <th class="text-right">30 Days</th>
        <th class="text-right">60 Days</th>
        <th class="text-right">90 Days</th>
        <th class="text-right">120 Days</th>
        <th class="text-right">Amount</th>
    </tr>
    </thead>
    <tbody>
    {% set sum_totalCurrentBal = 0 %}
    {% set sum_totalThirtyDays = 0 %}
    {% set sum_totalSixtyDays = 0 %}
    {% set sum_totalNinetyDays = 0 %}
    {% set sum_totalOneTwentyDays = 0 %}
    {% set sum_totalAmountBalance = 0 %}
    {% for record2 in records2 %}
        {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
        {% set sum_totalCurrentBal = sum_totalCurrentBal + record2.currentBal|default(0) %}
        {% set sum_totalThirtyDays = sum_totalThirtyDays + record2.thirtyDays|default(0) %}
        {% set sum_totalSixtyDays = sum_totalSixtyDays + record2.sixtyDays|default(0) %}
        {% set sum_totalNinetyDays = sum_totalNinetyDays + record2.ninetyDays|default(0) %}
        {% set sum_totalOneTwentyDays = sum_totalOneTwentyDays + record2.oneTwentyDays|default(0) %}
        {% set sum_totalAmountBalance = sum_totalAmountBalance + record2.amountBalance|default(0) %}
        <tr class="{{ trC }}">
            <td>{{ record2.healthFacility }}</td>
            <td class="text-right">{{ record2.currentBal|default('0.00') }}</td>
            <td class="text-right">{{ record2.thirtyDays|default('0.00') }}</td>
            <td class="text-right">{{ record2.sixtyDays|default('0.00') }}</td>
            <td class="text-right">{{ record2.ninetyDays|default('0.00') }}</td>
            <td class="text-right">{{ record2.oneTwentyDays|default('0.00') }}</td>
            <td class="text-right">{{ record2.amountBalance }}</td>
        </tr>
    {% endfor %}
    <tr>
        <td><strong>Total:</strong></td>
        <td class="text-right"><b>{{ sum_totalCurrentBal|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ sum_totalThirtyDays|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ sum_totalSixtyDays|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ sum_totalNinetyDays|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ sum_totalOneTwentyDays|number_format(2, '.', ',') }}</b></td>
        <td class="text-right"><b>{{ sum_totalAmountBalance|number_format(2, '.', ',') }}</b></td>
    </tr>
</table>
</body>
</html>