{% extends '@RxConnexion/Admin/content.html.twig' %}
{% block content %}
    <div class="row max-width-initial">
        <div class="large-12 columns">
            <nav aria-label="You are here:" role="navigation">
                <ul class="breadcrumbs">
                    <li><a href="{{ path('material_requisition_purchase_invoice') }}">Purchase Invoice</a></li>
                    <li><a href="{{ path('material_requisition_purchase_invoice_view', {id: purchaseInvoice_id}) }}">Details</a></li>
                    <li>
                        <span class="show-for-sr">Current: </span> Payment Form
                    </li>
                </ul>
            </nav>
            {% set purchaseOrderBreakdown = purchaseInvoice.purchaseOrderbreakdown %}
            {% set purchaseOrder = purchaseOrderBreakdown.purchaseOrder %}
            {% set materialRequisition = purchaseOrder.materialRequisition %}
            {%
                include '@RxConnexion/MaterialRequisition/purchase_invoice_overview.html.twig' with
                {
                    purchaseInvoice: purchaseInvoice,
                    purchaseOrderBreakdown: purchaseOrderBreakdown,
                    purchaseOrder: purchaseOrder,
                    materialRequisition: materialRequisition
                }
            %}
            <form method="POST" action="{{ path('material_requisition_purchase_invoice_payment_form', {purchaseInvoice_id: purchaseInvoice_id, action: action, id: id }) }}">
                <div class="row max-width-initial">
                    <div class="large-6 columns">
                        <h5>Basic Information</h5>
                        <p class="form-hint-text">Enter basic information below</p>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.payment_date) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.payment_date) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.payment_method) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.payment_method) }}
                            </div>
                        </div>
                        <div class="row check-type-fields {{ form.payment_method.vars.value != 'Check' ? 'hide' : '' }}">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.check_no) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.check_no) }}
                            </div>
                        </div>
                        <div class="row check-type-fields {{ form.payment_method.vars.value != 'Check' ? 'hide' : '' }}">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.check_date) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.check_date) }}
                            </div>
                        </div>
                        <div class="row check-type-fields {{ form.payment_method.vars.value != 'Check' ? 'hide' : '' }}">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.bank_description) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.bank_description) }}
                                {{ form_widget(form.bank) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.amount) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.amount) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.wh_tax_amount) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.wh_tax_amount) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.remark) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.remark) }}
                            </div>
                        </div>
                    </div>
                    <div class="large-6 columns">
                        {#<h5>Debit Accounts Breakdown</h5>
                        <p class="form-hint-text red">NOTE*** Credit account will be automatically recorded by the system based on the selected payment method.</p>
                        <p class="form-hint-text">Enter debit accounts & amounts breakdown below (Only those fields with value will be saved)</p>
                        <div id="dr-acct-cont">
                            <div class="row max-width-initial">
                                <div class="large-8 columns text-center">
                                    Debit Account
                                </div>
                                <div class="large-4 columns text-center">
                                    Amount
                                </div>
                            </div>
                            {% if otherForm.drAccounts is defined %}
                                {% for dr in otherForm.drAccounts %}
                                    <div class="row max-width-initial">
                                        <div class="large-8 columns">
                                            <input type="hidden"
                                                   name="otherForm[drAccounts][{{ loop.index0 }}][slId]"
                                                   value="{{ dr.slId }}"
                                            />
                                            <input type="text"
                                                   name="otherForm[drAccounts][{{ loop.index0 }}][slDesc]"
                                                   class="txt-dr-sl-desc"
                                                   data-idx="{{ loop.index0 }}"
                                                   value="{{ dr.slDesc }}"
                                            />
                                        </div>
                                        <div class="large-4 columns">
                                            <input type="text"
                                                   name="otherForm[drAccounts][{{ loop.index0 }}][amt]"
                                                   class="txt-dr-amt"
                                                   data-idx="{{ loop.index0 }}"
                                                   value="{{ dr.amt }}"
                                            />
                                        </div>
                                    </div>
                                {% endfor %}
                            {% elseif 'u' == action %}
                                {% for tje in purchaseInvoicePayment.transactionLinkReverse.transaction.transactionJournalEntries if tje.debitAmount > 0 %}
                                    {% set slAccount = tje.subsidiaryLedgerAccount %}
                                    <div class="row max-width-initial">
                                        <div class="large-8 columns">
                                            <input type="hidden"
                                                   name="otherForm[drAccounts][{{ loop.index0 }}][slId]"
                                                   value="{{ slAccount.id }}"
                                            />
                                            <input type="text"
                                                   name="otherForm[drAccounts][{{ loop.index0 }}][slDesc]"
                                                   class="txt-dr-sl-desc"
                                                   data-idx="{{ loop.index0 }}"
                                                   value="{{ slAccount.nameAndCode }}"
                                            />
                                        </div>
                                        <div class="large-4 columns">
                                            <input type="text"
                                                   name="otherForm[drAccounts][{{ loop.index0 }}][amt]"
                                                   class="txt-dr-amt"
                                                   data-idx="{{ loop.index0 }}"
                                                   value="{{ tje.debitAmount }}"
                                            />
                                        </div>
                                    </div>
                                {% endfor %}
                            {% else %}
                                <div class="row max-width-initial">
                                    <div class="large-8 columns">
                                        <input type="hidden"
                                               name="otherForm[drAccounts][0][slId]"
                                        />
                                        <input type="text"
                                               name="otherForm[drAccounts][0][slDesc]"
                                               class="txt-dr-sl-desc"
                                               data-idx="0"
                                        />
                                    </div>
                                    <div class="large-4 columns">
                                        <input type="text"
                                               name="otherForm[drAccounts][0][amt]"
                                               class="txt-dr-amt"
                                               data-idx="0"
                                        />
                                    </div>
                                </div>
                            {% endif %}
                        </div>
                        <div class="text-right">
                            <a href="javascript:void(0)" class="href-new-action" id="href-add-dr-acct"><i class="fa fa-plus-circle"></i> Add Account</a>
                        </div>#}
                    </div>
                    <div class="small-12 columns">
                        <hr class="max-width-initial">
                        <div class="button-container">
                            {#{% if action == 'u' %}
                                <a href="{{ path('transaction_print_voucher', {id: purchaseInvoicePayment.transactionLink.transaction.idEncoded}) }}" class="button">Print Voucher</a>
                            {% endif %}#}
                            <button type="submit" class="button just-continue" name="action" value="{{ action }}"
                                    data-message="Are you sure you want to save this information?"
                            >Save</button>
                            {% if action == 'u' and (userData.type == 'Super Admin' or 'Admin Purchase Invoice Payment Delete' in userData.accesses) %}
                                <button type="submit" class="ask-continue button alert" name="action" value="d"
                                        data-message="Are you sure you want to delete this record?"
                                >Delete</button>
                            {% endif %}
                            <a href="{{ path('material_requisition_purchase_invoice_view', {id: purchaseInvoice_id}) }}" class="button secondary">Back</a>
                        </div>
                    </div>
                </div>
                {{ form_widget(form.purchaseInvoice) }}
                {{ form_widget(form.action) }}
                {{ form_widget(form.id) }}
                {{ form_widget(form._token) }}
            </form>
        </div>
    </div>
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script>
        //<![CDATA[
        purchaseInvoicePayment_form.settings.bank_autocomplete_url = '{{ path('bank_autocomplete') }}';
        {#purchaseInvoicePayment_form.settings.slAccount_autocomplete_url = '{{ path('subsidiary_ledger_account_autocomplete') }}';#}
        purchaseInvoicePayment_form.settings.vatRate = '{{ purchaseInvoice.purchaseOrderBreakdown.purchaseOrder.vatRate }}';
        purchaseInvoicePayment_form.settings.whTaxRate = '{{ purchaseInvoice.purchaseOrderBreakdown.purchaseOrder.whTaxRate }}';
        jQ(document).ready(purchaseInvoicePayment_form.init);
        //]]>
    </script>
{% endblock %}