{% set userData = app.session.get('userData') %}

<table id="patientPaymentPatientBillingBreakdownDatalist" width="100%">
    <thead>
    <tr>
        <th>Item</th>
        <th class="text-right">Qty</th>
        <th class="text-right">Amount</th>
        <th class="text-right">Amount Covered</th>
        <th class="text-right">Amount Paid</th>
        <th class="text-right">Balance</th>
        <th class="text-right" width="200">Amount to Pay</th>
    </tr>
    </thead>
    <tbody>
        {% if patientBilling %}
        {% for pbb in patientBilling.patientBillingBreakdowns %}
            {% set isReturn = pbb.status == constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::STATUS_RETURN') ? true : false %}
            {% if pbb.type == constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_CHART_PROCEDURE') %}
                {% set item = pbb.patientChart.idAndChartDateAndChartType|default('') %}
            {% elseif pbb.type == constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_ITEM') %}
                {% set item = pbb.item.description|default('') %}
            {% elseif pbb.type == constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_OTHER') %}
                {% set item = pbb.description %}
            {% else %}
                {% set item = '' %}
            {% endif %}
            <tr {{ isReturn == true ? 'style="text-decoration: line-through;cursor:help;color:#666" title="This Invoice Item is returned" ' }} >
                <td>{{ item }}</td>
                <td class="text-right">{{ pbb.quantity }}</td>
                <td class="text-right">{{ pbb.amount|number_format(2, '.', ',') }}</td>
                <td class="text-right">{{ pbb.amountCovered|number_format(2, '.', ',') }}</td>
                <td class="text-right">{{ pbb.amountPaid|number_format(2, '.', ',') }}</td>
                <td class="text-right">{{ pbb.amountBalance|number_format(2, '.', ',') }}</td>
                <td>
                    <input {{ isReturn == true ? 'readonly' : '' }} type="text" class="amount input-small text-right patientPaymentBreakdown_amount {{ patientBilling.billingStatus == 'Pending Payment' and pbb.amountBalance != 0 ? '' : 'hide' }}" name="patientPaymentBreakdown[{{ loop.index0 }}][amount]">
                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][patient_billing_breakdown_id]" value="{{ pbb.id }}">
                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][amount_balance]" value="{{ pbb.amountBalance }}">
                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][amount_paid]" value="{{ pbb.amountPaid }}">
                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][item]" value="{{ item }}">
                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][id]">
                </td>
            </tr>
        {% endfor %}
            <tr>
                <td style="border: solid 1px red">Total Remaining Balance is : <strong>{{ patientBilling.amountBalance|number_format(2, '.', ',') }}</strong></td>
            </tr>
    {% endif %}
    </tbody>
</table>