{% trans_default_domain 'core' %}

<div class="row">
    <div class="col-md-12">

        <h3>{% trans %}abstract_invoice.form.items{% endtrans %}</h3>

        <table id="invoice-like-items" class="table table-condensed table-striped align-middle">
            <thead>
            <tr>
                <th></th>
                {# CAMPO CODIGO DEL PRODUCTO
                {% if bundle_exists('SiwappProductBundle') %}
                <th class="col-md-1 cell-align-center">Cod.</th>
                {% endif %}
                #}
                <th class="">{% trans %}item.form.description{% endtrans %}</th>
                <th class="col-md-1 cell-align-center">{% trans %}item.form.quantity{% endtrans %}</th>
                <th class="col-md-2 cell-align-center">{% trans %}item.form.unitary_cost{% endtrans %}</th>
                <th class="col-md-1 cell-align-center">{% trans %}item.form.discount{% endtrans %}</th>
                <th class="col-md-2 cell-align-left">{% trans %}item.form.taxes{% endtrans %}</th>
                <th class="cell-align-right">{% trans %}item.form.total{% endtrans %}</th>
            </tr>
            </thead>
            <tbody data-prototype="{{ include('Item/edit.html.twig', { 'form': form.items.vars.prototype, 'currency': currency })|e }}">
            {% for item in form.items %}
            {{ include('Item/edit.html.twig', { 'form': item, 'entity': item.vars.value, 'currency': currency }) }}
            {% endfor %}

            {# TODO: Action buttons: add/remove items, taxes, sort... #}
            </tbody>
        </table>

    </div>
</div>

<div class="row totals">
    <div class="col-md-6">

        <button type="button" id="invoice-like-add-item" class="btn btn-primary"><span
                class="glyphicon glyphicon-plus glyphicon-white"></span>&nbsp;{% trans %}
            abstract_invoice.form.item_add{% endtrans %}
        </button>


        <script type="text/javascript">
            $('#invoice-like-add-item').on('click', function (event) {
                event.preventDefault();
                var collectionHolder = $('#invoice-like-items tbody');
                var prototype = collectionHolder.attr('data-prototype');
                form = prototype.replace(/__name__/g, collectionHolder.children().length);
                collectionHolder.append(form);
                addProductNameAutocomplete('{{ path('product_autocomplete_reference') }}');
                addInvoiceItemDescriptionAutocomplete('{{ path('item_autocomplete_description') }}');
            });

        </script>


    </div>
    <div class="col-md-4 col-md-offset-2">
        <table id="invoice-like-totals" class="table table-condensed table-striped">
            <tbody>
            <tr>
                <th class="cell-size-large">SubTotal</th>
                <td class="cell-align-right base-amount">{{ entity.baseiva|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr class="invoice-base-iva5-row"{% if entity.base_iva5 is null or entity.base_iva5 == 0 %} style="display:none;"{% endif %}>
                <th>SubTotal IVA 5%</th>
                <td class="cell-align-right invoice-base-iva5">{{ entity.base_iva5|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr class="invoice-base-iva8-row"{% if entity.base_iva8 is null or entity.base_iva8 == 0 %} style="display:none;"{% endif %}>
                <th>SubTotal IVA 8%</th>
                <td class="cell-align-right invoice-base-iva8">{{ entity.base_iva8|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr class="invoice-base-ivacod6-row"{% if entity.base_ivacod6 is null or entity.base_ivacod6 == 0 %} style="display:none;"{% endif %}>
                <th>No Objeto de Impuesto</th>
                <td class="cell-align-right invoice-base-ivacod6">{{ entity.base_ivacod6|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr class="invoice-base-ivacod7-row"{% if entity.base_ivacod7 is null or entity.base_ivacod7 == 0 %} style="display:none;"{% endif %}>
                <th>Exento de IVA</th>
                <td class="cell-align-right invoice-base-ivacod7">{{ entity.base_ivacod7|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr class="invoice-base-cero-row"{% if entity.basecero is null or entity.basecero == 0 %} style="display:none;"{% endif %}>
                <th>SubTotal 0 %</th>
                <td class="cell-align-right invoice-base-cero">{{ entity.basecero|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr>
                <th class="cell-size-large">Descuento</th>
                <td class="cell-align-right discount-amount">{{ entity.discountAmount|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr>
                <th>IVA</th>
                <td class="cell-align-right tax-amount">{{ entity.valorIva|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>

            <tr class="invoice-valor-iva5-row"{% if entity.valor_iva5 is null or entity.valor_iva5 == 0 %} style="display:none;"{% endif %}>
                <th>IVA 5%</th>
                <td class="cell-align-right invoice-valor-iva5">{{ entity.valor_iva5|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr class="invoice-valor-iva8-row"{% if entity.valor_iva8 is null or entity.valor_iva8 == 0 %} style="display:none;"{% endif %}>
                <th>IVA 8%</th>
                <td class="cell-align-right invoice-valor-iva8">{{ entity.valor_iva8|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            <tr>
                <th>{% trans with {'%currency%': currency} %}abstract_invoice.form.total{% endtrans %}</th>
                <input type="hidden" id="invoice_tt_aux" value="{{ entity.grossAmount }}">
                <td class="cell-align-right gross-amount"
                    style="font-weight: bold; font-size: 18px;">{{ entity.grossAmount|localizedcurrency(currency, app.request.locale) }}</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<div class="row">
    <div class="col-md-9">

        <h3>Detalle Forma de Pago</h3>

        <table id="invoice-like-itemspagos" class="table table-condensed table-striped align-middle">
            <thead>
            <tr>
                <th></th>
                <th class="col-md-6 cell-align-center">Forma Pago</th>
                <th class="col-md-2 cell-align-center">Valor</th>
                <th class="col-md-2 cell-align-center">Tiempo</th>
                <th class="col-md-1 cell-align-center">Plazo</th>
            </tr>
            </thead>
            <tbody data-prototype="{{ include('Item/editpago.html.twig', { 'form': form.pagos.vars.prototype, 'currency': currency })|e }}">
            {% for item in form.pagos %}
            {{ include('Item/editpago.html.twig', { 'form': item, 'entity': item.vars.value, 'currency': currency }) }}
            {% endfor %}

            {# TODO: Action buttons: add/remove items, taxes, sort... #}
            </tbody>
        </table>

    </div>

</div>
