{% extends '@RxConnexion/Admin/content.html.twig' %}
{% block content %}
    <div class="row max-width-initial">
        <div class="small-12 columns">
            <nav aria-label="You are here:" role="navigation">
                <ul class="breadcrumbs">
                    <li><a href="{{ path('transfer_inventory') }}">Transfer Inventory</a></li>
                    <li>
                        <span class="show-for-sr">Current: </span> Details
                    </li>
                </ul>
            </nav>
            <div class="content-detail-container" style="position:relative;">
                {% if transferInventory.status in ['New', 'Rejected'] and ('Super Admin' == userData.type or 'Admin Transfer Inventory Update' in userData.accesses) %}
                <div style="position: absolute; right: 10px">
                    <a href="{{ path('transfer_inventory_form', {action: 'u', 'id': transferInventory_id}) }}" class="href-new-action"><i class="fa fa-edit"></i></a>
                </div>
                {% endif %}
                <div class="row max-width-initial">
                    <div class="large-6 columns">
                        <div class="page-detail-header">Transfer Details</div>
                        <div class="page-detail">SRS No.: <span>{{ transferInventory.transferNo }}</span></div>
                        <div class="page-detail">Date: <span>{{ transferInventory.transferDateAsString }}</span></div>
                        <div class="page-detail">Origin: <span>{{ transferInventory.originAsString }}</span></div>
                        <div class="page-detail">Destination: <span>{{ transferInventory.destinationAsString }}</span></div>
                        {#<div class="page-detail">Department: <span>{{ transferInventory.department.description|default('') }}</span></div>#}
                        <div class="page-detail">Requested By: <span>{{ transferInventory.accountUser.fullName }}</span></div>
                        <div class="page-detail">Status: <span>{{ transferInventory.status }}</span></div>
                    </div>
                    <div class="large-6 columns">
                        <div class="page-detail-header">Other Details</div>
                        <div class="page-detail">Notes: <span>{{ transferInventory.note }}</span></div>
                        {#<div class="page-detail">Approver(s): <span>{{ statusApproval.approvalUsersByApprovalUserDepartment(transferInventory.department.id)|default('')|raw }}</span></div>#}
                    </div>
                </div>
            </div>
            <div class="content-container has-loading">
                <div class="content-container-content hide">
                    <div class="text-right button-container">
                        {% if transferInventory.status == 'New' or transferInventory.status == 'Rejected' %}
                            {% if userData.type == 'Super Admin' or 'Admin Transfer Inventory Item Send' in userData.accesses %}
                                <a href="javascript:void(0)" class="button small" id="href-transferInventory-send" data-open="send-ask-modal" style="margin: 0 0 10px 10px;">Send</a>
                            {% endif %}
                        {#{% elseif transferInventory.status == 'Approved' and transferInventory.transferInventoryDeliveries.count > 0 %}#}
                        {% elseif transferInventory.transferInventoryDeliveries.count > 0 and transferInventory.status != 'Completed' %}
                            {% if userData.type == 'Super Admin' or 'Admin Transfer Inventory Item Receive' in userData.accesses %}
                                <a href="javascript:void(0)" class="button small" id="href-transferInventoryItemDelivery-formAll" style="margin: 0 0 10px 10px;">Receive Items</a>
                            {% endif %}
                        {% endif %}
                        {#{% if transferInventory.status == 'Approved' and (userData.type == 'Super Admin' or 'Admin Transfer Inventory Print' in userData.accesses) %}#}
                        {% if (userData.type == 'Super Admin' or 'Admin Transfer Inventory Print' in userData.accesses) %}
                            <a href="{{ path('transfer_inventory_print', {id: transferInventory_id}) }}" class="button secondary small" style="margin: 0 0 10px 10px;">Print</a>
                        {% endif %}
                    </div>
                    <ul class="tabs custom-tabs" data-tabs id="transfer-inventory-tabs">
                        {% if (userData.type == 'Super Admin' or 'Admin Transfer Inventory Item' in userData.accesses) and (transferInventory.branchFrom.id != transferInventory.branchTo.id) %}
                            <li class="tabs-title is-active"><a href="#panel-inventory" aria-selected="true">Items Requested</a></li>
                        {% endif %}
                        {#<li class="tabs-title"><a href="#panel-reference-mr" aria-selected="false">Reference PRs</a></li>#}
                        {% if transferInventory.status in ['Approved', 'For Receiving', 'Completed']  %}
                            {% if (userData.type == 'Super Admin' or 'Admin Transfer Inventory Delivery' in userData.accesses) and (transferInventory.branchFrom.id != transferInventory.branchTo.id) %}
                                <li class="tabs-title"><a href="#panel-delivery" aria-selected="false">Delivery</a></li>
                            {% endif %}
                        {% endif %}
                        {#{% if transferInventory.status in ['Approved', 'Completed'] and transferInventory.transferInventoryDeliveries.count > 0 %}#}
                        {% if (userData.type == 'Super Admin' or 'Admin Transfer Inventory Receiving' in userData.accesses) and (transferInventory.branchFrom.id != transferInventory.branchTo.id) %}
                            {% if transferInventory.transferInventoryDeliveries.count > 0 %}
                                <li class="tabs-title"><a href="#panel-receiving" aria-selected="false">Receiving</a></li>
                            {% endif %}
                        {% endif %}
                        {#<li class="tabs-title"><a href="#panel-status" aria-selected="false">Approval</a></li>#}
                    </ul>
                    <div class="tabs-content custom-tabs-content" data-tabs-content="transfer-inventory-tabs">
                        <div class="tabs-panel is-active" id="panel-inventory">
                                {#{% if transferInventory.status in ['New', 'Rejected'] and (userData.type == 'Super Admin' or 'Admin Transfer Inventory Item New' in userData.accesses) %}
                                <div class="text-right">
                                    #}{#<a href="javascript:void(0)" class="href-new-action href-transferInventoryItem-form" data-action="n" data-id="0" style="margin: 0 0 10px 10px;">Add Item</a>#}{#
                                    <a href="javascript:void(0)" class="href-new-action" data-open="modal-add-item" style="margin: 0 0 10px 10px;">Add Item</a>
                                </div>
                            {% endif %}#}
                                {#{% if canApproveByUser and transferInventory.status not in ['Approved', 'Completed', 'Rejected'] and (userData.type == 'Super Admin' or 'Admin Transfer Inventory Item New' in userData.accesses) %}#}
                                {% if transferInventory.status not in ['Approved', 'Completed', 'Rejected'] and (userData.type == 'Super Admin' or 'Admin Transfer Inventory Item New' in userData.accesses) and (userIsReceivingBranch == false or transferInventory.accountUser.id == userData.id) %}
                                    <div class="text-right">
                                        <a href="javascript:void(0)" class="href-new-action" id="item-table-modal" data-open="modal-add-item" style="margin: 0 0 10px 10px;">Add/Update Items</a>
                                    </div>
                                {% endif %}
                            <form id="form-transferInvItem" method="POST">
                                <table class="display responsive" id="transferInventoryItem-datalist" width="100%">
                                    <thead>
                                    <tr>
                                        <th>Item</th>
                                        {#<th>Location</th>#}
                                        <th class="text-right">Qty Requested</th>
                                        <th>Serial No/s</th>
                                        <th class="text-right">Qty Approved</th>
                                        <th class="text-right">Qty Delivered</th>
                                        <th class="text-right">Qty Received</th>
                                        <th>Notes</th>
                                        <th>Consumable</th>
                                        <th class="text-center">Action</th>
                                    </tr>
                                    </thead>
                                    <tbody></tbody>
                                </table>
                            </form>
                            <br/>
                            {#<h5>Reference Purchase Requests</h5>#}
                            {#<table class="display responsive" id="materialRequisition-datalist" width="100%">#}
                                {#<thead>#}
                                {#<tr>#}
                                    {#<th>Control No.</th>#}
                                    {#<th>Request Date</th>#}
                                    {#<th>Branch</th>#}
                                    {#<th>Department</th>#}
                                    {#<th>Purpose</th>#}
                                    {#<th>Specific Purpose</th>#}
                                    {#<th>Requested By</th>#}
                                    {#<th>Status</th>#}
                                    {#<th>No. of Items</th>#}
                                {#</tr>#}
                                {#</thead>#}
                                {#<tbody>#}
                                {#{% for timr in transferInventory.transferInventoryMatReqs %}#}
                                    {#{% set mr = timr.materialRequisition %}#}
                                    {#<tr>#}
                                        {#<td><a target="_blank" href="{{ path('material_requisition_view', {materialRequisition_id: mr.idEncoded}) }}">{{ mr.materialRequisitionNo }}</a></td>#}
                                        {#<td>{{ mr.requestDateAsString }}</td>#}
                                        {#<td>{{ mr.branch.description }}</td>#}
                                        {#<td>{{ mr.department.description }}</td>#}
                                        {#<td>{{ mr.purpose.description }}</td>#}
                                        {#<td>{{ mr.specificPurpose }}</td>#}
                                        {#<td>{{ mr.user.fullName }}</td>#}
                                        {#<td>{{ mr.status }}</td>#}
                                        {#<td>{{ mr.materialRequisitionItems.count }}</td>#}
                                    {#</tr>#}
                                {#{% endfor %}#}
                                {#</tbody>#}
                            {#</table>#}
                        </div>
                        {#<div class="tabs-panel" id="panel-reference-mr">
                            <table class="display responsive" id="materialRequisition-datalist" width="100%">
                                <thead>
                                <tr>
                                    <th>Control No.</th>
                                    <th>Request Date</th>
                                    <th>Branch</th>
                                    <th>Department</th>
                                    <th>Purpose</th>
                                    <th>Specific Purpose</th>
                                    <th>Requested By</th>
                                    <th>Status</th>
                                    <th>No. of Items</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for timr in transferInventory.transferInventoryMatReqs %}
                                    {% set mr = timr.materialRequisition %}
                                    <tr>
                                        <td><a target="_blank" href="{{ path('material_requisition_view', {materialRequisition_id: mr.idEncoded}) }}">{{ mr.materialRequisitionNo }}</a></td>
                                        <td>{{ mr.requestDateAsString }}</td>
                                        <td>{{ mr.branch.description }}</td>
                                        <td>{{ mr.department.description }}</td>
                                        <td>{{ mr.purpose.description }}</td>
                                        <td>{{ mr.specificPurpose }}</td>
                                        <td>{{ mr.user.fullName }}</td>
                                        <td>{{ mr.status }}</td>
                                        <td>{{ mr.materialRequisitionItems.count }}</td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>#}
                        {#{% if transferInventory.status in ['Approved', 'For Receiving', 'Completed'] %}#}
                            <div class="tabs-panel" id="panel-delivery">
                                {#{% if transferInventory.status in ['New', 'Rejected'] and (userData.type == 'Super Admin' or 'Admin Transfer Inventory Item New' in userData.accesses) %}#}
                                {% if userData.type == 'Super Admin' or 'Admin Transfer Inventory Delivery New' in userData.accesses %}
                                    <div class="text-right">
                                        <a href="javascript:void(0)" class="href-new-action href-transferInventoryDelivery-form" data-action="n" data-id="0" style="margin: 0 0 10px 10px;">Add Delivery</a>
                                    </div>
                                {% endif %}
                                <table class="display responsive" id="transferInventoryDelivery-datalist" width="100%">
                                    <thead>
                                    <tr>
                                        <th>DR No.</th>
                                        <th>DR Date</th>
                                        {#<th class="text-right">No. of Items</th>#}
                                        <th>Notes</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                        {#{% endif %}#}
                        {#{% if transferInventory.status in ['Approved', 'Completed'] and transferInventory.transferInventoryDeliveries.count > 0 %}#}
                        {% if transferInventory.transferInventoryDeliveries.count > 0 %}
                        <div class="tabs-panel" id="panel-receiving">
                            <table class="display responsive" id="transferInventoryItemDelivery-datalist" width="100%">
                                <thead>
                                <tr>
                                    <th>Item</th>
                                    {#<th>Location</th>#}
                                    <th>Receive Date</th>
                                    <th class="text-right">Quantity</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                        {% endif %}
                        {#<div class="tabs-panel" id="panel-status">#}
                            {#{% if canApproveByUser and transferInventory.status not in ['Approved', 'Completed'] %}#}
                                {#<form method="POST" action="{{ path('transfer_inventory_status_approval') }}">#}
                                    {#<input type="hidden" name="transferInventory_id" value="{{ transferInventory_id }}" />#}
                                    {#<input type="hidden" class="form-action" name="action" />#}
                                    {#<div class="row max-width-initial">#}
                                        {#<div class="small-12 columns">#}
                                            {#<label>Notes</label>#}
                                            {#<textarea name="notes" placeholder="Enter your notes here"></textarea>#}
                                        {#</div>#}
                                        {#<div class="small-12 columns">#}
                                            {#<div class="button-container">#}
                                                {#<button type="submit" class="button ask-continue no-margin-bottom" name="action" value="approve"#}
                                                        {#data-message="Are you sure you want to approve this request?"#}
                                                {#>Approve</button>#}
                                                {#<button type="submit" class="button alert ask-continue no-margin-bottom" name="action" value="reject"#}
                                                        {#data-message="Are you sure you want to reject this request?"#}
                                                {#>Reject</button>#}
                                            {#</div>#}
                                        {#</div>#}
                                    {#</div>#}
                                {#</form>#}
                                {#<hr class="max-width-initial">#}
                            {#{% endif %}#}
                            {#<h5>History</h5>#}
                            {#<table class="display response" id="transferInventoryStatusHistory-datalist" width="100%">#}
                                {#<thead>#}
                                {#<tr>#}
                                    {#<th>Date / Time</th>#}
                                    {#<th>Status</th>#}
                                    {#<th>Approval</th>#}
                                    {#<th>User</th>#}
                                    {#<th>Notes</th>#}
                                {#</tr>#}
                                {#</thead>#}
                                {#<tbody>#}
                                {#{% for ctr in transferInventory.approvalbatchno..0 %}#}
                                    {#{% for transferInventoryStatus in transferInventory.transferinventorystatuses %}#}
                                        {#{% if transferInventoryStatus.batchno == ctr and (transferInventoryStatus.approvaldescription == 'Approved' or transferInventoryStatus.approvaldescription == 'Rejected') %}#}
                                            {#<tr>#}
                                                {#<td>{{ transferInventoryStatus.updatedat|date('m/d/Y h:i:s A') }}</td>#}
                                                {#<td>{{ transferInventoryStatus.status }}</td>#}
                                                {#<td>{{ transferInventoryStatus.approvaldescription }}</td>#}
                                                {#<td>{{ transferInventoryStatus.user.fullname }} - {{ transferInventoryStatus.user.type }}</td>#}
                                                {#<td>{{ transferInventoryStatus.note }}</td>#}
                                            {#</tr>#}
                                        {#{% endif %}#}
                                    {#{% endfor %}#}
                                {#{% endfor %}#}
                                {#</tbody>#}
                            {#</table>#}
                        {#</div>#}
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="reveal large" id="modal" data-reveal data-close-on-esc="false" data-close-on-click="false">
        <div id="modal-content"></div>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="reveal small" id="send-ask-modal" data-reveal data-close-on-esc="false" data-close-on-click="false">
        <h4>Are you sure you want to continue?</h4>
        <hr class="max-width-initial">
        <div class="button-container text-right">
            <a href="javascript:void(0);" id="btn-send-ask-modal-continue" data-action="" class="button">&nbsp;&nbsp;Yes&nbsp;&nbsp;</a>
            <a href="javascript:void(0);" class="button secondary no-margin-right" data-close>Cancel</a>
        </div>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="reveal large" id="modal-add-item" data-reveal data-close-on-esc="false" data-close-on-click="false">
        <h5 class="reveal-draggable-header">Items Request for Transfer</h5>
        <div class="row max-width-initial hide">
            <div class="large-6 columns no-padding-left">
                <label>Category</label>
                <select id="addItemFormFilter-itemCategory">
                    <option value=""></option>
                    {% for ic in itemCategories %}
                        <option value="{{ ic.id }}">{{ ic.description }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>
        <table class="display responsive" id="item-datalist" width="100%">
            <thead>
            <tr>
                <th>Item</th>
                {#<th>Current Quantity</th>#}
                <th>Request for Transfer Quantity</th>
                <th>Serial No/s</th>
                <th>Notes</th>
                {#<th>Is Consumable</th>#}
                <th>Action</th>
            </tr>
            </thead>
            <tbody></tbody>
        </table>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script language="javascript">
        //<![CDATA[
        transferInventoryItem.settings.transferInventory_id = '{{ transferInventory_id }}';
        transferInventoryItem.settings.ajaxUrl = '{{ path('transfer_inventory_item_ajax_list') }}';
        transferInventoryItem.settings.ajaxUrlDelivery = '{{ path('transfer_inventory_delivery_ajax_list') }}';
        transferInventoryItem.settings.ajaxUrlItemDelivery = '{{ path('transfer_inventory_item_delivery_ajax_list') }}';
        transferInventoryItem.settings.formUrl = '{{ path('transfer_inventory_item_form') }}';
        transferInventoryItem.settings.formActionUrl = '{{ path('transfer_inventory_item_form_action') }}';
        transferInventoryItem.settings.doAddUrl = '{{ path('transfer_inventory_item_do_add') }}';
        transferInventoryItem.settings.doRemoveUrl = '{{ path('transfer_inventory_item_do_remove') }}';
        transferInventoryItem.settings.formUrlDelivery = '{{ path('transfer_inventory_delivery_form') }}';
        transferInventoryItem.settings.formActionUrlDelivery = '{{ path('transfer_inventory_delivery_form_action') }}';
        transferInventoryItem.settings.sendUrl = '{{ path('transfer_inventory_send') }}';
        transferInventoryItem.settings.inventory_autocomplete_url = '{{ path('inventory_autocomplete') }}';
        transferInventoryItem.settings.branch_id = '{{ transferInventory.branchfrom.idencoded }}';
        transferInventoryItem.settings.branchTo_id = '{{ transferInventory.branchTo.idencoded }}';
        transferInventoryItem.settings.ajaxUrlItem = '{{ path('item_ajax_list_transfer_inventory') }}';
        transferInventoryItem.settings.transferInventoryItemDeliveryFormAll_url = '{{ path('transfer_inventory_item_delivery_form_all') }}';
        transferInventoryItem.settings.transferInventoryItemDeliveryFormAllAction_url = '{{ path('transfer_inventory_item_delivery_form_all_action') }}';
        transferInventoryItem.settings.transferInventoryItemDeliveryForm_url = '{{ path('transfer_inventory_item_delivery_form') }}';
        transferInventoryItem.settings.transferInventoryItemDeliveryFormAction_url = '{{ path('transfer_inventory_item_delivery_form_action') }}';
        transferInventoryItem.settings.canApprove = '{{ canApproveByUser and transferInventory.status not in ['Approved', 'Completed'] }}';
        transferInventoryItem.settings.itemIdQtys = '{{ itemIdQtys|json_encode|raw }}';
        jQ(document).ready(transferInventoryItem.init);
        //]]>
    </script>
{% endblock %}