{% extends '@RxConnexion/Admin/global.html.twig' %}
{% block body %}
    <style>
        table {
            border-collapse: collapse;
        }
        table tr,
        table td {
            background-color: #ffffff;
        }
        table td {
            border: 1px solid #c0c0c0;
            padding: 2px 5px;
        }
        thead td{
            background: #ADD8E6 !important;
        }
        .total-border {
            border-bottom: 4px double #383838;
            border-top: 2px solid #383838;
        }
        .sub-total-border {
            border-bottom: 1px solid #383838;
            border-top: 2px solid #383838;
        }
        .border-bottom {
            border-bottom: 1px solid #383838;
        }
        .strong {
            font-weight: 600;
        }

        tbody tr:hover td {
            background: #F2F9F7 !important;
        }
    </style>
    <h5 class="report-header">{{ page_title }}</h5>
    {% for transfer in transfers %}
    <table width="100%">
        <thead class="">
        <tr>
            <td class="text-left" colspan="5" style="background: #1d4962!important; color: white;">
                <strong style="font-size: 1.1em;">From {{ transfer.branch_from }} To {{ transfer.branch_to }}</strong>
            </td>
        </tr>
        <tr>
            <td>Code</td>
            <td>Item</td>
            <td class="text-right">Quantity</td>
            <td class="text-right">Cost</td>
            <td class="text-right">Transfer Value</td>
        </tr>
        </thead>
        <tbody>
        {% set totalQty = 0 %}
        {% set totalAveCost = 0 %}
        {% set totalValue = 0 %}
        {% for item in transfer.items %}
            {% set totalQty = totalQty + item.quantity %}
            {% set totalAveCost = totalAveCost + item.ave_cost %}
            {% set totalValue = totalValue + (item.ave_cost * item.quantity) %}
            <tr>
                <td>{{ item.codes }}</td>
                <td>{{ item.description }}</td>
                <td class="text-right">
                    {#<a href="javascript:void(0)" class="open-ti-link">#}
                        {{ item.quantity|number_format(0) }}
                    {#</a>#}
                    <div class="transfer_nos" style="display: none;">
                        {% for transfer_inventory in transfer.transfer_inventories %}
                            <a href="{{ path('transfer_inventory_item', {transferInventory_id: transfer_inventory.id|base64Encode}) }}" target="_blank" style="display: block;">{{ transfer_inventory.transfer_no }}</a>
                        {% endfor %}
                    </div>
                </td>
                <td class="text-right">{{ item.ave_cost|number_format(2, '.', ',') }}</td>
                <td class="text-right">{{ (item.ave_cost * item.quantity)|number_format(2, '.', ',') }}</td>
            </tr>
        {% endfor %}
        </tbody>
        <tfoot>
        <tr>
            <td colspan="2" class="total-border">Total</td>
            <td class="text-right total-border">{{ totalQty }}</td>
            <td class="text-right total-border">{{ totalAveCost|number_format(2, '.', ',') }}</td>
            <td class="text-right total-border">{{ totalValue|number_format(2, '.', ',') }}</td>
        </tr>
        </tfoot>
    </table>
    <br>
    {% endfor %}
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script>
        //<![CDATA[
        jQ(document).ready(function(){
            report_preview.init();
            jQ('.open-ti-link').click(function () {
                jQ(this).next('.transfer_nos').toggle();
                /*let ids = jQ(this).data('ids').split(',');
                for (let i = 0; i < ids.length; i++) {
                    window.open(`${global.settings.url}/admin/transfer_inventory/item/index/${btoa(ids[i])}`, '_blank' );
                }*/
            });
        });
        //]]>
    </script>
{% endblock %}