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

<table id="patientRefundPatientBillingBreakdownDatalist" 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 Refund</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 %}

            {#{% if pbb.amountBalance == 0.00 or pbb.amountBalance == '0.00' %}#}
                <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 patientRefundBreakdown_amount {{pbb.amountPaid != 0 ? '' : 'hide' }}" name="patientRefundBreakdown[{{ loop.index0 }}][amount]">
                        <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][patient_billing_breakdown_id]" value="{{ pbb.id }}">
                        <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][amount_balance]" value="{{ pbb.amountBalance }}">
                        <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][amount_paid]" value="{{ pbb.amountPaid }}">
                        <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][item]" value="{{ item }}">
                        <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][id]">
                    </td>
                </tr>
            {#{% endif %}#}

        {% endfor %}
        <tr>
            <td style="border: solid 1px red">Total Amount Paid is : <strong>{{ patientBilling.amountPaid|number_format(2, '.', ',') }}</strong></td>
        </tr>
    {% endif %}
    </tbody>
</table>