{% set userData = app.session.get('userData') %}
<style>
    {% if form.action.vars.value == 'n' %}
        .payer_type_choice_financing{
            display: none;
        }
    {% endif %}

    form,select, label{
        font-size: 12px;
    }
    input[type=text] {
        font-size: 13px;
    }
    label {
        text-align: left;
    }
</style>
<form method="POST" id="form-patientRental">
    <div id="flash-messages-content-modal"></div>
    <div class="row max-width-initial">
        <div class="large-12 columns" style="margin-bottom: 10px;">
            <h5 class="subheader">Basic information</h5>
            {#<p class="form-hint-text">Enter basic information below</p>#}
            <div style="width: 100%">
                <div style="width: 25%; float: left; text-align: left; margin-right:7px;">
                    <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 {{ form.action.vars.value == 'u' ? '' : 'hide' }}">#}
                        {#<div class="large-5 columns text-right">#}
                            {#{{ form_label(form.invoice_no) }}#}
                        {#</div>#}
                        {#<div class="large-7 columns">#}
                            {#<input type="text" name="patientRental[invoice_no]" readonly value="{{ patientRental.invoiceNo ? patientRental.invoiceNo : '' }}">#}
                        {#</div>#}
                    {#</div>#}
                </div>
                <div style="width: 24%; float: left; text-align: left; margin-right:7px;">
                    <div class="row">
                        <div class="large-5 columns text-right">
                            {{ form_label(form.serial_no) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.serial_no) }}
                        </div>
                    </div>
                    {% if form.action.vars.value|default('') != 'u' %}
                        <div class="row">
                            <div class="large-5 columns text-right">
                                {{ form_label(form.payer_type) }}
                            </div>
                            <div class="large-7 columns">
                                {{ form_widget(form.payer_type) }}
                            </div>
                        </div>
                    {% else %}
                        <div class="row">
                            <div class="large-5 columns text-right">
                                <label class="required middle required">Payer Type</label>
                            </div>
                            <div class="large-7 columns">
                                {% if patientRental.payerType is null or patientRental.payerType == '' %}
                                    {{ form_widget(form.payer_type) }}
                                {% else %}
                                    {{ form_widget(form.payer_type, {attr: {class: 'hide'}}) }}
                                    <input type="text" readonly value="{{ patientRental.payerType }}" >
                                {% endif %}
                            </div>
                        </div>
                    {% endif %}
                    <div class="row {{ patientRental.payerType != constant('RxConnexionBundle\\Entity\\PatientBillingEntity::PAYER_TYPE_INSURANCE') ? 'hide' : '' }}"  id="patientRentalForm-patientInsurance-container">
                        <div class="large-5 columns text-right">
                            {{ form_widget(form.patientInsurance) }}
                            {{ form_label(form.patientInsurance_insurance_description) }}
                        </div>
                        <div class="large-7 columns">
                            {{ form_widget(form.patientInsurance_insurance_description) }}
                        </div>
                    </div>
                </div>
                <div style="width: 24%; float: right; text-align: right; margin-right:7px;">
                    <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 style="width: 24%; float: right; text-align: right ; margin-right:7px;">
                    {#{% if patientBilling.healthFacility.id|default('') == '' %}#}
                    <div class="row">
                        <div class="large-6 columns text-right">
                            {{ form_label(form.healthFacility_desc) }}
                        </div>
                        <div class="large-6 columns">
                            {{ form_widget(form.healthFacility_desc) }}
                            {{ form_widget(form.healthFacility) }}
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-6 columns text-right">
                            {{ form_label(form.healthFacilityRentalForAddress_desc) }}
                        </div>
                        <div class="large-6 columns">
                            {{ form_widget(form.healthFacilityRentalForAddress_desc) }}
                            {{ form_widget(form.healthFacilityRentalForAddress) }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <hr>
        <div class="large-12 columns">
            <div class="row max-width-initial">
                <div class="large-6 columns">
                    <h5>Breakdown</h5>
                </div>
                <div class="large-6 columns">
                    <div class="large-6 columns">

                    </div>
                    <div class="large-7 columns">
                        {% if form.action.vars.value|default('') != 'u' %}
                       <div style="float: left">
                               <select class="input-group-field" style="height: 2.5375rem;" id="dropdown-rental-breakdown-type">
                                   <option value="{{ constant('RxConnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_CHART_PROCEDURE') }}">Encounter Procedure</option>
                                   <option value="{{ constant('RxConnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_ITEM') }}" selected>Item</option>
                                   <option value="{{ constant('RxConnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_OTHER') }}">Other</option>
                               </select>
                               {#<span class="input-group-label">Type</span>#}

                       </div>
                        <div style="float: right">
                           <input type="button" class="button secondary" value="Add Breakdown"
                                  id="btn-rental-add-breakdown"
                                  style="background-color: #e6e6e6; color: #0a0a0a; border: 1px solid #cacaca;" />
                       </div>
                        {% endif %}
                    </div>
                </div>
            </div>
            <table width="100%">
                <thead>
                <tr>
                    <th style="font-weight: 500;">Type</th>
                    <th style="font-weight: 500;" colspan="3">Details</th>
                    <th class="term_header" style="font-weight: 500;" >Term</th>
                    <th class="item_type_header" style="font-weight: 500;" >Item Type</th>
                    <th style="font-weight: 500;" class="text-right">Quantity</th>
                    <th style="font-weight: 500;" class="text-right">Price</th>
                    <th style="font-weight: 500;" class="text-right">Amount</th>
                    <th></th>
                </tr>
                </thead>
                <tbody id="tbody-rental-breakdown">
                {% set colspan_ret = 8 %}
                {% for pbb_form in form.patientBillingBreakdowns %}
                        <tr>
                            <td>{{ pbb_form.vars.value.type }}</td>
                            {% if constant('RxConnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_ITEM') != pbb_form.vars.value.type and constant('RxConnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_OTHER') != pbb_form.vars.value.type %}
                                <td>
                                    <input type="text"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][patientChart_chartNo]"
                                           value="{{ pbb_form.vars.value.patientChart.idAndChartDateAndChartType|default('') }}"
                                           class="pb_pbb_patientChart_chartNo"
                                           placeholder="Encounter"
                                           readonly
                                    />
                                    <input type="hidden"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][patientChart]"
                                           value="{{ pbb_form.vars.value.patientChart.id|default('') }}"
                                           class="pb_pbb_patientChart"
                                           readonly
                                    />
                                </td>
                            {% endif %}
                            {% if constant('RxConnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_CHART_PROCEDURE') == pbb_form.vars.value.type %}
                                <td>
                                    <input type="text"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][chartProcedure_description]"
                                           value="{{ pbb_form.vars.value.chartProcedure.description }}"
                                           class="pb_pbb_chartProcedure_description"
                                           placeholder="Procedure"
                                           readonly
                                    />
                                    <input type="hidden"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][chartProcedure]"
                                           value="{{ pbb_form.vars.value.chartProcedure.id }}"
                                           class="pb_pbb_chartProcedure"
                                           readonly
                                    />
                                </td>
                            {% elseif constant('RxConnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_ITEM') == pbb_form.vars.value.type %}
                                <td width="140px;">
                                    <input type="text"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][itemCategory_desc]"
                                           value="{{ pbb_form.vars.value.item.itemSubCategory.itemCategory.description|default('') }}"
                                           class="pb_pbb_itemCategory_desc"
                                           placeholder="Item Subcategory"
                                           style="width: 100%; float: left;"
                                           readonly
                                    />
                                    <input type="hidden"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][itemCategory]"
                                           value="{{ pbb_form.vars.value.item.itemSubCategory.itemCategory.id|default('') }}"
                                           class="pb_pbb_itemCategory"
                                           readonly
                                    />
                                </td>
                                <td width="90px;">
                                    <input type="text"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][serialNumber]"
                                           value="{{ pbb_form.vars.value.serial_number|default('') }}"
                                           class="pb_pbb_item_serial_number"
                                           placeholder="Serial No."
                                           style="width: 100%; float: left;"
                                           readonly
                                    />
                                </td>
                                <td width="250px;">
                                    <input type="text"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][item_description]"
                                           value="{{ pbb_form.vars.value.item.description|default('') }}"
                                           class="pb_pbb_item_description"
                                           placeholder="Item"
                                           style="width: 100%; float: left;"
                                           readonly
                                    />
                                    <input type="hidden"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][item]"
                                           value="{{ pbb_form.vars.value.item.id|default('') }}"
                                           class="pb_pbb_item"
                                           readonly
                                    />
                                </td>
                                <td>
                                    <select name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][term]" id="">
                                        <option value="{{ pbb_form.vars.value.term == '' ? '' : '' }}" {{ pbb_form.vars.value.term == '' ? 'selected' : '' }}></option>
                                        {#<option value="{{ pbb_form.vars.value.term == 'Warranty' ? 'Warranty' : '' }}" {{ pbb_form.vars.value.term == 'Warranty' ? 'selected' : '' }}>Warranty</option>#}
                                        <option value="{{ pbb_form.vars.value.term == 'Long Term Rental' ? 'Long Term Rental' : '' }}" {{ pbb_form.vars.value.term == 'Long Term Rental' ? 'selected' : '' }}>Long Term Rental</option>
                                    </select>
                                    <input type="hidden"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][term]"
                                           value="{{ pbb_form.vars.value.term|default }}"
                                           class=""
                                           style="width: 50px; float: right;"
                                           readonly
                                    />
                                </td>
                            {% else %}
                                {#<td>
                                    <input type="text"
                                           name="patientBilling[patientBillingBreakdowns][{{ loop.index0 }}][tranDateForOther]"
                                           value="{{ pbb_form.vars.value.tranDateForOther }}"
                                           class="pb_pbb_tranDateForOther"
                                           placeholder="MM-DD-YYYY"
                                    />
                                </td>#}
                                <td colspan="5">
                                    <input type="text"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][description]"
                                           value="{{ pbb_form.vars.value.description }}"
                                           class="pb_pbb_description"
                                           placeholder="Description"
                                           readonly
                                    />
                                </td>
                            {% endif %}
                            {% if constant('RxConnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_ITEM') == pbb_form.vars.value.type %}
                                <td>
                                    <select name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][item_type]" id="">
                                        <option value="{{ pbb_form.vars.value.itemType == '' ? '' : '' }}" {{ pbb_form.vars.value.itemType == '' ? 'selected' : '' }}></option>
                                        <option value="{{ pbb_form.vars.value.itemType == 'Accessory' ? 'Accessory' : '' }}" {{ pbb_form.vars.value.itemType == 'Accessory' ? 'selected' : '' }}>Accessory</option>
                                        <option value="{{ pbb_form.vars.value.itemType == 'CPAP Package' ? 'CPAP Package' : '' }}" {{ pbb_form.vars.value.itemType == 'CPAP Package' ? 'selected' : '' }}>CPAP Package</option>
                                        <option value="{{ pbb_form.vars.value.itemType == 'Medical Supplies' ? 'Medical Supplies' : '' }}" {{ pbb_form.vars.value.itemType == 'Medical Supplies' ? 'selected' : '' }}>CPAP Package</option>
                                    </select>
                                    <input type="hidden"
                                           name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][item_type]"
                                           value="{{ pbb_form.vars.value.itemType|default }}"
                                           class=""
                                           style="width: 50px; float: right;"
                                           readonly
                                    />
                                </td>
                            {% endif %}
                            <td style="clear: both;">
                                <input type="text"
                                       name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][quantity]"
                                       value="{{ pbb_form.vars.value.quantity }}"
                                       class="pb_pbb_quantity txt-rental-for-computation"
                                       style="width: 50px; float: right;"
                                       readonly
                                />
                            </td>
                            <td style="clear: both;">
                                <input type="text"
                                       name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][price]"
                                       value="{{ pbb_form.vars.value.price }}"
                                       class="pb_pbb_price txt-rental-for-computation"
                                       style="width: 75px; float: right;"
                                       readonly
                                />
                            </td>
                            <td class="text-right pb_pbb_amount_td">{{ pbb_form.amount.vars.value|number_format(2, '.', ',') }}</td>
                            <td>
                                <a href="javascript:void(0)" class="btn-rental-remove-breakdown {{ form.action.vars.value|default('') == 'u' ? 'hide' : '' }}">X</a>
                                <input type="hidden"
                                       name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][amount]"
                                       class="pb_pbb_amount"
                                       value="{{ pbb_form.amount.vars.value }}"
                                       readonly
                                />
                                <input type="hidden"
                                       name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][type]"
                                       class="pb_pbb_type"
                                       value="{{ pbb_form.type.vars.value }}"
                                       readonly
                                />
                                <input type="hidden"
                                       name="patientRental[patientBillingBreakdowns][{{ loop.index0 }}][id]"
                                       class="pb_pbb_id"
                                       value="{{ pbb_form.id.vars.value }}"
                                       readonly
                                />
                            </td>
                        </tr>
                {% endfor %}
                <tr>
                    <td colspan="{{ colspan_ret }}" class="text-right">Total Amount Due:</td>
                    <td class="text-right" id="td-rental-amount-due">{{ form.amount_due.vars.value|number_format(2, '.', ',') }}</td>
                    <td></td>
                </tr>
                </tbody>
            </table>
        </div>
        {% if patientRental.patientPayments|length > 0 %}
            <div class="large-12 columns">
                <h5 class="subheader">Payments</h5>
                <table width="100%">
                    <thead>
                    <tr>
                        <th style="font-weight: 500;">Payment Date</th>
                        <th style="font-weight: 500;">Payment Type</th>
                        <th style="font-weight: 500;">Status</th>
                        <th style="font-weight: 500;">Amount</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for patientPayment in patientRental.patientPayments %}
                        <tr>
                            <td>{{ patientPayment.payDateAsString }}</td>
                            <td>{{ patientPayment.payType }}</td>
                            <td>{{ patientPayment.paymentStatus }}</td>
                            <td>{{ patientPayment.amount }}</td>
                        </tr>
                    {% endfor %}
                    <tr>
                        <td colspan="3" class="text-right" style="padding-right: 54px;">Total Amount Paid:</td>
                        <td id="td-rental-amount-due">{{ patientRental.amountPaid|number_format(2, '.', ',') }}</td>
                    </tr>
                    </tbody>
                </table>
            </div>
        {% endif %}
        <div class="row max-width-initial">
            <div class="large-12 columns">
                <div class="large-6 columns">
                    {{ form_label(form.note) }}
                    {{ form_widget(form.note) }}
                </div>
                <div class="large-6 columns">
                </div>
            </div>
        </div>
        {% if form.action.vars.value|default('') == 'u' == 'u' %}
            <div class="large-12 columns">
                <div class="row max-width-initial">
                    <div class="large-6 columns">
                        <table width="100%">
                            <thead>
                            <tr>
                                <th style="font-weight: 500;">Updated</th>
                                <th style="font-weight: 500;">Created</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>{{ patientRental.updatedAt|date('m/d/Y') }} [ {{ patientRental.updatedBy|default('') }} ]</td>
                                <td>{{ patientRental.createdAt|date('m/d/Y') }} [ {{ patientRental.createdBy|default('') }} ]</td>
                            </tr>
                            </tbody>
                        </table>
                        <table width="100%">
                            <thead>
                            <tr>
                                <th style="font-weight: 500;">Notes</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>{{ patientRental.note }} [ {{ patientRental.updatedBy|default('') }} ]</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        {% endif %}
    </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 == 'n' or patientRental.patient.fullName == 'Mismatched Invoice' or  patientRental.healthFacility.description|default('') == '' or  patientRental.healthFacilityRentalForAddress.description|default('') == '' %}
                    <a href="javascript:void(0)" class="button just-continue href-patient-rental-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 Rental Update' in userData.accesses) %}
                    <a href="javascript:void(0)" class="button just-continue href-patient-rental-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>
                    <a href="javascript:void(0)" class="ask-continue button alert href-patient-rental-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.amount_due) }}
    {{ form_widget(form.action) }}
    {{ form_widget(form.id) }}
    {{ form_widget(form.patient) }}
    {{ form_widget(form._token) }}
</form>