{% set userData = app.session.get('userData') %}
<style>
    form, select, label, input{
        font-size: 12px!important;
    }
    .amt-text-align {
        text-align: right;
    }
</style>
<h5>{{ page_title }}</h5>
{#<form method="POST" id="form-patientPayment-void">
    {% if form.action.vars.value|default('') == 'u' and patientPayment.paymentStatus|default('') != 'Void' and (userData.type == 'Super Admin' or 'Admin Patient Payment Void' in userData.accesses) %}
        <a href="javascript:void(0)" class="button href-patient-payment-void-action" data-axn="{{ form.action.vars.value }}" style="background-color: grey">Void</a>
        <input type="hidden" value="{{ form.id.vars.value|default('') }}" name="patientPayment[id]"/>
        <input type="hidden" value="{{ form.action.vars.value }}" name="patientPayment[action]"/>
    {% endif %}
</form>#}
<form method="POST" id="form-patientRefund">
    <div id="flash-messages-content-modal"></div>
    <div class="row max-width-initial">
        <div class="row max-width-initial">
            <div class="large-6 columns">
                <h5 class="subheader">Basic information</h5>
                <p class="form-hint-text">Enter basic information below</p>
                {% if  form.action.vars.value|default('') != 'u'  %}
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.patientBilling) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.patientBilling) }}
                        </div>
                    </div>
                {% else %}
                    <div class="row">
                        <div class="large-5 columns text-right">
                            <label class="required middle required">Invoice No.</label>
                        </div>
                        <div class="large-7 columns">
                            {% if patientRefund.patientBilling %}
                                <input type="text" readonly value="{{ patientRefund.patientBilling ? patientRefund.patientBilling.invoiceNo|default(patientRefund.patientBilling.prevSysInvoiceNo) : patientRefund.patientBilling.prevSysInvoiceNo }} - {{ patientRefund.patientBilling.billingDateAsString }}  - {{ patientRefund.patientBilling.amountBalance }}">
                            {% else %}
                                <input type="text" readonly value="{{ patientRefund.prevSysInvoiceNo ~ ' - ' ~ patientRefund.prevSysInvoiceBranch }}">
                            {% endif %}
                            {{ form_widget(form.patientBilling, {attr: {class: 'hide'}}) }}
                        </div>
                    </div>
                    {#<input type="hidden" name="patientPayment[patientBilling]" value="{{ patientPayment.patientBilling.id }}">#}
                {% endif %}

                <div class="row">
                    <div class="large-5 columns text-right">
                        {{ form_label(form.refund_date) }}
                    </div>
                    <div class="large-7 columns">
                        {{ form_widget(form.refund_date) }}
                    </div>
                </div>
            </div>
            <div class="large-6 columns">
                <h5 class="subheader">Other Information</h5>
                <p class="form-hint-text">Enter other information below</p>
                {{ form_label(form.note) }}
                {{ form_widget(form.note) }}
            </div>
        </div>
        <hr>
        <div class="row max-width-initial">
            <div class="columns small-12">
                <h5 class="subheader">Breakdown</h5>
                {#<p class="form-hint-text">Enter other information below</p>#}
                <div id="patientRefundPatientBillingBreakdownContainer">
                    {% if patientRefund and patientRefund.patientRefundBreakdowns %}
                        <table id="patientRefundPatientBillingBreakdownDatalist" width="100%">
                            <thead>
                            <tr>
                                <th>Item</th>
                                <th class="text-right">Qty</th>
                                <th class="text-right">Amt</th>
                                <th class="text-right">Total 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>
                            {% for ppb in patientRefund.patientRefundBreakdowns %}
                                {% set pbb = ppb.patientBillingBreakdown %}
                                {% 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" name="patientRefundBreakdown[{{ loop.index0 }}][amount]" value="{{ ppb.amount|number_format(2, '.', ',') }}">
                                            <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][patient_billing_breakdown_id]" value="{{ pbb.id }}">
                                            <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][amount_paid]" value="{{ pbb.amountPaid }}">
                                            <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][amount_balance]" value="{{ pbb.amountBalance }}">
                                            <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][item]" value="{{ item }}">
                                            <input type="hidden" name="patientRefundBreakdown[{{ loop.index0 }}][id]" value="{{ ppb.id }}">
                                        </td>
                                    </tr>
                                {#{% endif %}#}
                            {% endfor %}
                            </tbody>
                        </table>
                    {% endif %}
                </div>
            </div>
        </div>
        <hr>
        <div class="row">
            <div class="large-5 columns text-right">
                {{ form_label(form.amount) }}
            </div>
            <div class="large-7 columns">
                {{ form_widget(form.amount) }}
            </div>
        </div>
    </div>
    <hr>
    <div class="row-max-width-initial">
        <div class="small-12 columns no-padding-right">
            <div class="button-container text-right">

                {#{% if action == 'n' and (userData.type == 'Super Admin' or 'Admin Patient Payment New' in userData.accesses) %}#}
                    <a href="javascript:void(0)" class="button just-continue href-patient-billing-refund-action" data-axn="{{ form.action.vars.value }}"
                       data-message="Are you sure you want to save this information?"
                       style="margin-left: 10px; margin-right: 0;"
                    >Save</a>
                {#{% endif %}#}
                {% if form.action.vars.value == 'u' and (userData.type == 'Super Admin' or 'Admin Patient Billing Refund Delete' in userData.accesses) %}
                    <a href="javascript:void(0)" class="ask-continue button alert href-patient-billing-refund-action" data-axn="d"
                       data-message="Are you sure you want to delete this record?"
                       style="margin-left: 10px; margin-right: 0;"
                    >Delete</a>
                {% endif %}
                <a href="javascript:void(0)" class="button secondary" data-close style="margin-left: 10px; margin-right: 0;">Close</a>
            </div>
        </div>
    </div>
    {{ form_widget(form.action) }}
    {{ form_widget(form.id) }}
    {{ form_widget(form.patient) }}
    {{ form_widget(form._token) }}
</form>