{% set userData = app.session.get('userData') %}
<style>
    form, select, label, input{
        font-size: 12px!important;
    }
</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-patientPayment">
    <div id="flash-messages-content-modal"></div>
    <div class="row max-width-initial">
        <div class="large-12 columns">
            <h5 class="subheader">Basic information</h5>
            {#<p class="form-hint-text">Enter basic information below</p>#}
            <div class="row max-width-initial">
                <div class="small-3 columns">
                    {% 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 patientPayment.patientBilling %}
                                    <input type="text" readonly value="{{ patientPayment.patientBilling ? patientPayment.patientBilling.invoiceNo|default(patientPayment.patientBilling.prevSysInvoiceNo) : patientPayment.patientBilling.prevSysInvoiceNo }} - {{ patientPayment.patientBilling.billingDateAsString }}  - {{ patientPayment.patientBilling.amountBalance }}">
                                {% else %}
                                    <input type="text" readonly value="{{ patientPayment.prevSysInvoiceNo ~ ' - ' ~ patientPayment.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.pay_date) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.pay_date) }}
                        </div>
                    </div>
                </div>
                <div class="small-3 columns">
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.pay_type) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.pay_type) }}
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.pay_type_for_print) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.pay_type_for_print) }}
                        </div>
                    </div>
                </div>
                <div class="columns small-3">
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.financingCompany) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.financingCompany) }}
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.new_invoice_no_for_financing) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.new_invoice_no_for_financing) }}
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.is_payment_plan) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.is_payment_plan) }}
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.payment_plan_type) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.payment_plan_type) }}
                        </div>
                    </div>
                </div>
                <div class="columns small-3">
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.start_date) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.start_date) }}
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.end_date) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.end_date) }}
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.payment_day) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.payment_day) }}
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.amortization_amount) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.amortization_amount) }}
                        </div>
                    </div>
                </div>
            </div>
            {#<div class="row">
                <div class="large-5 columns text-right">
                </div>
                <div class="large-7 columns">
                </div>
            </div>#}
        </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="patientPaymentPatientBillingBreakdownContainer">
                {% if patientPayment and patientPayment.patientPaymentBreakdowns %}
                <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">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 Pay</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for ppb in patientPayment.patientPaymentBreakdowns %}
                            {% 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 %}
                            <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" name="patientPaymentBreakdown[{{ loop.index0 }}][amount]" value="{{ ppb.amount|number_format(2, '.', ',') }}">
                                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][patient_billing_breakdown_id]" value="{{ pbb.id }}">
                                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][amount_paid]" value="{{ pbb.amountPaid }}">
                                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][amount_balance]" value="{{ pbb.amountBalance }}">
                                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][item]" value="{{ item }}">
                                    <input type="hidden" name="patientPaymentBreakdown[{{ loop.index0 }}][id]" value="{{ ppb.id }}">
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% endif %}
            </div>
        </div>
    </div>
    <hr>
    <div class="row max-width-initial">
        <div class="large-6 columns">
            <div class="row">
                <div class="columns small-4">
                    {{ form_label(form.note) }}
                </div>
                <div class="columns small-8">
                    {{ form_widget(form.note) }}
                </div>
            </div>
        </div>
        <div class="large-6 columns">
            <div class="row">
                <div class="columns small-4">
                    {{ form_label(form.amount) }}
                </div>
                <div class="columns small-8">
                    {{ form_widget(form.amount) }}
                </div>
            </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 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 ask-continue href-patient-payment-action" data-message="Are you sure you want to void this payment?" data-axn="v" style="background-color: red">Void</a>
                {% endif %}
                {% if form.action.vars.value|default('') == 'u' and patientPayment.paymentStatus|default('') == 'Pending' and (userData.type == 'Super Admin' or 'Admin Patient Payment Post' in userData.accesses) %}
                    <a href="javascript:void(0)" class="button ask-continue href-patient-payment-action" data-message="Are you sure you want to post this payment?" data-axn="p" style="background-color: green">Post</a>
                {% endif %}
                {#{% 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-payment-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 Payment Delete' in userData.accesses) %}
                    <a href="javascript:void(0)" class="ask-continue button alert href-patient-payment-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_widget(form.payment_status) }}
</form>